root/ossiedev/trunk/tools/wavedash/src/ComponentModel.py @ 10143

Revision 10143, 7.8 KB (checked in by Snyder.Jason, 3 years ago)

added setPanel and getPanel methods

Line 
1from xml.dom import minidom
2from xml.dom.minidom import Node
3from PropertyModel import Property
4from PropertyWidgets import WidgetContainer
5import sys
6
7class ComponentEvent:
8    """ serves as a call back object for methods of ComponentListener
9    interface"""
10   
11    def __init__(self,type):
12        self.component = None
13        self.type = type
14    def getSource(self):
15        return self.component
16    def getEventType(self):
17        return self.type
18
19class ComponentListener:
20    """ An abstract class acting as an interface to update the views about the
21    changes happening in ComponentModel. All classes wish to interface with
22    Component model must inherit this class and can implement their
23    own logic by overriding the methods of this class """
24   
25    def componentStateChanged(self, cEvent):
26        pass
27    def componentHidden(self, cEvent):
28        pass
29    def componentShown(self, cEvent):
30        pass
31   
32class Component:
33    """ The Model class for Component objects. Encapsulates the
34    components' attributes and methods """
35     
36    def __init__(self, parent, id, name, pos, spd_file, controller, visible = True):
37        self.id = id
38        self.parent = parent
39        self.name = str(name)
40        self.position = pos
41        self.spdFile = str(spd_file)
42        self.controller = controller
43        self.visible = visible
44        self.properties = []
45        self.buildProperties(controller)
46   
47    def __str__(self):
48        return "Component: %s, pos: %d, parent: %s" % (self.name, self.position, self.parent.getName())
49   
50    def getName(self):
51        return self.name
52   
53    def getPosition(self):
54        return self.position
55   
56    def setPosition(self, newPos):
57        self.position = newPos
58   
59    def getPanel(self):
60        return self.panel
61   
62    def setPanel(self, newPanel):
63        self.panel = newPanel
64       
65    def setPosition(self, newPos):
66        self.position = newPos
67   
68    def hide(self):
69        self.visible = False
70   
71    def show(self):
72      self.visible = True
73   
74    def isVisible(self):
75        return self.visible
76   
77    def getParent(self):
78        return self.parent
79   
80    def getAllProperties(self):
81        plist = self.properties[0:]
82        return plist
83   
84    def findPropertyByName(self, name):
85        for prop in self.properties:
86            if prop.name == name:
87                return prop
88   
89    def findPropertyByID(self, id):
90        for prp in self.properties:
91            if prp.id == id:
92                return prp
93   
94    def updatePropertyState(self, pName, visible):
95        property = self.findPropertyByName(pName)
96        if property.isVisible() == visible:
97            return False
98        if visible:
99            property.show()
100        else:
101            property.hide()
102        return True
103   
104    def queryProperties(self):
105        #This method queries the list of properties and their values of a component,
106        #update the values to the property objects in the model.
107        utilRef = self.controller.getUtilRef()
108        newPrpList = []
109        newPrpList = utilRef.query(self.parent.getName(), self.name, newPrpList)
110        #newPrpList is a lsit of corba objects of type
111        #ossie.cf.CF.DataType(id='DCE:a337c5f0-8245-11dc-860f-00123f63025f',
112        #                    value=CORBA.Any(CORBA.TC_short, 2502))
113        if newPrpList is None:
114            return
115        for newprp in newPrpList:
116            prpRef = self.findPropertyByID(newprp.id)
117            if (prpRef is not None):
118                if prpRef.corbaObj is None:
119                    prpRef.corbaObj = newprp
120                else:
121                    prpRef.setValue(newprp.value._v)
122           
123       # print newPrpList
124        return
125   
126    def configureProperty(self, pName, newVal):
127        prpRef = self.findPropertyByName(pName)
128        #storing the old value in a temp varaible to revert the changes if configure() fails.
129        curVal = prpRef.getValue()
130        prpRef.setValue(newVal)
131        #configure() method expects the argument to be passed as a LIST object.
132        #hence convert the corbaObj to a list
133        prpList = [prpRef.corbaObj]
134        utilRef = self.controller.getUtilRef()
135       
136        status = utilRef.configure(self.parent.getName(), self.name, prpList)
137       
138        if status is False:
139            prpRef.setValue(curVal)
140        return status
141       
142    def buildProperties(self, controller):
143        #Read the path of prf file from spd file of the component
144        spddom = controller.getDOM(self.spdFile)
145       
146        prfnode = spddom.getElementsByTagName('propertyfile')[0]
147       
148        # propertyfile tag is of type
149        # <propertyfile type = "PRF">
150        #    <localfile name = <path of prf file> />
151        # </propertyfile>
152       
153        # Extracting the path of the prf file from childNodes[1], i.e. <localfile> tag
154        # the file name may be written in unicode format. convert to string for internal use
155        prf_file = str(prfnode.childNodes[1].attributes['name'].value)
156               
157        #Now parsing .prf file to build property model
158        prfdom = controller.getDOM(prf_file)
159        if prfdom is None:
160            print "buildProperties(): Failed to create DOM for PRF file for ", self.parent.getName(), "/", self.name
161            sys.exit(-1)
162       
163        prpNode = prfdom.getElementsByTagName('properties')[0]
164        prpList = prpNode.childNodes
165       
166        try:
167            for prp in prpList:
168                if ( prp.nodeType != Node.ELEMENT_NODE or str(prp.tagName) == 'description' ):
169                    continue
170                #populate property fields and create the property object
171               
172                id = prp.attributes['id'].value
173                name = prp.attributes['name'].value
174                type = (str(prp.tagName), str(prp.attributes['type'].value))
175                mode = prp.attributes['mode'].value
176               
177                desc = ''
178                value = None
179                range = (0,10000)
180                actionType = ''
181                kindType = ''
182               
183                #Iterate through children of <simple> tag to update desc, value and kindType
184                for child in prp.childNodes:
185                    if (child.nodeType == Node.ELEMENT_NODE):
186                        if (child.tagName == 'description'):
187                            desc = child.firstChild.data
188                        elif (child.tagName == 'value'):
189                            value = child.firstChild.data
190                        elif (child.tagName == 'kind'):
191                            kindType = child.attributes['kindtype'].value
192                        elif (child.tagName == 'range'):
193                            min = child.childNodes[1].firstChild.data
194                            max = child.childNodes[3].firstChild.data
195                            range = (min, max)
196                        elif (child.tagName == 'action'):
197                            actionType = child.attributes['type'].value
198               
199               
200                widget = controller.getDefaultWidget(type)
201                newProp = Property(self, id, name, type, mode, desc, value,
202                                   range, kindType, actionType, widget, prf_file)
203                self.properties.append(newProp)
204        except:
205            print "Error in reading PRF files for ", self.parent.getName(), "/", self.name
206            errorMsg = sys.exc_info()
207            print errorMsg
208            sys.exit(-1)
209           
210    def changePropWidget(self, property, newWidgetType):
211        prpRef = self.findPropertyByName(property)
212        curWidget = prpRef.getWidget()
213        if curWidget.type == newWidgetType:
214            return None
215        newWidget = self.controller.getWidgetByType(newWidgetType)
216        prpRef.widget = newWidget
217        return prpRef
218       
219   
220    def fireModelChange(self, event):
221        pass
Note: See TracBrowser for help on using the browser.