コード例 #1
0
ファイル: configDialog.py プロジェクト: jrecuero/automat
    def getSelectionFromResource(self, attr, ctrl):
        """ Get the data entered for a given attribute.

        It returns the dialog values entered by the user for the given
        attribute.
        """
        dicta    = []
        attrName = config.getResourceAttrName(attr)
        attrType = config.getResourceAttrType(attr)
        attrDim  = config.getResourceAttrDim(attr)
        if attrName not in ctrl:
            return
        if attrType in (config.RES_TYPE_SINGLE, ):
            dicta = str(ctrl[attrName].GetValue())
        elif attrType in (config.RES_TYPE_LIST, ):
            dicta = config.getResourceAttrValues(attr)(self)[ctrl[attrName].GetSelection()]
        elif attrType in (config.RES_TYPE_SINGLE_ARRAY, ):
            for index in xrange(attrDim):
                dicta.append(str(ctrl[attrName][index].GetValue()))
        elif attrType in (config.RES_TYPE_LIST_ARRAY, ):
            for index in xrange(attrDim):
                dicta.append(config.getResourceAttrValues(attr)(self)[ctrl[attrName][index].GetSelection()])
        elif attrType in (config.RES_TYPE_GROUP, ):
            for index in xrange(attrDim):
                dicta.append({})
                for childAttr in config.getResourceAttrValues(attr):
                    childAttrName = config.getResourceAttrName(childAttr)
                    dicta[index][childAttrName] = self.getSelectionFromResource(childAttr, self.ctrl[attrName][index])
        return dicta
コード例 #2
0
ファイル: configDialog.py プロジェクト: jrecuero/automat
    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)
コード例 #3
0
ファイル: configDialog.py プロジェクト: jrecuero/automat
    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
コード例 #4
0
ファイル: configDialog.py プロジェクト: jrecuero/automat
    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
コード例 #5
0
ファイル: configDialog.py プロジェクト: jrecuero/automat
    def createNewCtrl(self, attr):
        """ Create a new control on the fly.

        It creates a new control when dialog has been already created and
        populated
        """
        attrName = config.getResourceAttrName(attr)
        if not hasattr(self.lbl, attrName) and not hasattr(self.ctrl, attrName):
            self.lbl[attrName], self.ctrl[attrName] = self.addCtrlFromResource(attr)
            self.sizer.Layout()
            self.Fit()
            self.Refresh()
            self.Update()
コード例 #6
0
ファイル: configDialog.py プロジェクト: jrecuero/automat
    def removeNewCtrl(self, attr):
        """ Remove a new control on the fly.

        It removes a new control that was created when the dialog was already
        created and populated.
        """
        attrName = config.getResourceAttrName(attr)
        if attrName in self.lbl and attrName in self.ctrl:
            self.sizer.Remove(self.lbl[attrName])
            self.sizer.Remove(self.ctrl[attrName])
            self.lbl[attrName].Destroy()
            self.ctrl[attrName].Destroy()
            del self.lbl[attrName]
            del self.ctrl[attrName]
            self.sizer.Layout()
            self.Fit()
コード例 #7
0
ファイル: configDialog.py プロジェクト: jrecuero/automat
    def GetSelection(self):
        """ Collect all dialog input data.

        It collects all information entered in the dialog for every widget and
        it creates an instance that contain that data to be used for YAML code
        generation.
        """
        # This will be the new way to pass the data retrieved from the dialog.
        dictToEntity = {}
        for attr in config.getResourceAttrs(self.resource):
            attrName = config.getResourceAttrName(attr)
            dictToEntity[attrName] = self.getSelectionFromResource(attr, self.ctrl)

        entity = Entity(copy.deepcopy(self.resource), dictToEntity)
        # After selection has been returned, return all attributes and
        # attribute dependencies to default values.
        self.disableAllAttributes()
        self.disableAllAtributeDependencies()
        return entity