Пример #1
0
    def createCtrl(self):
        """ Creates all widgets for a given resource.

        It creates all widget for all attributes in the given resource.
        """
        self.sizer = wx.FlexGridSizer(rows=len(config.getResourceAttrs(self.resource)), cols=2, hgap=5, vgap=10)
        self.lbl, self.ctrl = {}, {}
        for attr in config.getResourceAttrs(self.resource):
            if config.getResourceAttrEnable(attr):
                attrName = config.getResourceAttrName(attr)
                self.lbl[attrName], self.ctrl[attrName] = self.addCtrlFromResource(attr)
        return self.sizer
Пример #2
0
    def getData(self):
        """ Return data to be displayed in a log window.

        It returns a string with information to be displayed in edit/remove
        widget.
        """
        result  = '[%s] ' % config.getResourceTag(self._resource)
        result += '%s ' % self.name
        for data in [data for data in config.getResourceAttrs(self._resource) if data['name'] not in ('name', )]:
            if config.getResourceAttrEnable(data):
                result += '%s ' % getattr(self, data['name'], None)
        return result
Пример #3
0
    def getYamlDict(self):
        """ Return dictionary to be YAMLed.

        It returns the dictionary to be used to generate YAML data.
        """
        classId = config.getResourceId(self._resource)
        yamlData = {classId: {}, }
        yamlData[classId][self.name] = {}
        for attr in [attr for attr in config.getResourceAttrs(self._resource) if not config.isAttrTheAttrName(attr)]:
            attrName = config.getResourceAttrName(attr)
            if config.getResourceAttrEnable(attr):
                yamlData[classId][self.name][attrName] = getattr(self, attrName, None)
        return yamlData
Пример #4
0
    def addCtrlFromResource(self, attr, index=None):
        """ Create a new control widget in the dialog.

        It process data from a new entry and it creates the proper widget for
        that. Data is coming from the resource.attribute entry.
        """
        attrName = config.getResourceAttrName(attr)
        dispName = config.getResourceAttrDisplay(attr)
        attrType = config.getResourceAttrType(attr)
        attrDim  = config.getResourceAttrDim(attr)
        attrDeps = config.getResourceAttrDeps(attr)
        lbl, ctrl = [], []
        if attrType in (config.RES_TYPE_SINGLE, ):
            lbl, ctrl = self.addLabelTextCtrlEntry(self.sizer,
                                                   '%s: ' % dispName,
                                                   fieldName=attrName if index is None else (attrName, index),
                                                   data=attrDeps)
            self.Bind(wx.EVT_TEXT, self.OnTextCtrlAction, ctrl)
        elif attrType in (config.RES_TYPE_LIST, ):
            lbl, ctrl = self.addLabelChoiceEntry(self.sizer,
                                                 '%s: ' % dispName,
                                                 choices=config.getResourceAttrValues(attr)(self),
                                                 initSel=config.getResourceAttrDefault(attr)(self),
                                                 fieldName=attrName if index is None else (attrName, index),
                                                 data=attrDeps)
        elif attrType in (config.RES_TYPE_SINGLE_ARRAY, ):
            for i in xrange(attrDim):
                lbl, aCtrl = self.addLabelTextCtrlEntry(self.sizer,
                                                        '%s [%s]: ' % (dispName, i),
                                                        attrName if index is None else (attrName, index),
                                                        data=attrDeps)
                ctrl.append(aCtrl)
                self.Bind(wx.EVT_TEXT, self.OnTextCtrlAction, aCtrl)
        elif attrType in (config.RES_TYPE_LIST_ARRAY, ):
            for i in xrange(attrDim):
                lbl, aCtrl = self.addLabelChoiceEntry(self.sizer,
                                                      '%s [%s]: ' % (dispName, i),
                                                      choices=config.getResourceAttrValues(attr)(self),
                                                      initSel=config.getResourceAttrDefault(attr)(self),
                                                      fieldName=attrName if index is None else (attrName, index),
                                                      data=attrDeps)
                self.ctrl.append(aCtrl)
        elif attrType in (config.RES_TYPE_GROUP, ):
            for i in xrange(attrDim):
                lbl.append({})
                ctrl.append({})
                for childAttr in [aAttr for aAttr in config.getResourceAttrValues(attr) if config.getResourceAttrEnable(aAttr)]:
                    childAttrName = config.getResourceAttrName(childAttr)
                    lbl[i][childAttrName], ctrl[i][childAttrName] = self.addCtrlFromResource(childAttr, i)
        return (lbl, ctrl)