⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 panel.py

📁 用python写的ide开发环境,巨强大,不过需要wxpython的支持
💻 PY
📖 第 1 页 / 共 2 页
字号:
            # Find place to put new element: first present element after param            found = False            if xxx.hasStyle:                 paramStyles = xxx.allParams + xxx.styles            else:                paramStyles = xxx.allParams             for p in paramStyles[paramStyles.index(param) + 1:]:                # Content params don't have same type                if xxx.params.has_key(p) and p != 'content':                    found = True                    break            if found:                nextTextElem = xxx.params[p].node                objElem.insertBefore(elem, nextTextElem)            else:                objElem.appendChild(elem)        else:            # Remove parameter            xxx.params[param].remove()            del xxx.params[param]            w.SetValue('')            w.SetModified(False)        # mark as not changed            w.Enable(False)        # Set modified flag (provokes undo storing is necessary)        panel.SetModified(True)    def Apply(self):        xxx = self.xxx        if self.controlName:            name = self.controlName.GetValue()            if xxx.name != name:                xxx.name = name                xxx.node.setAttribute('name', name)        for param, w in self.controls.items():            if w.modified:                paramObj = xxx.params[param]                value = w.GetValue()                if param in xxx.specials:                    xxx.setSpecial(param, value)                else:                    paramObj.update(value)                    # Save current state    def SaveState(self):        self.origChecks = map(lambda i: (i[0], i[1].GetValue()), self.checks.items())        self.origControls = map(lambda i: (i[0], i[1].GetValue(), i[1].enabled),                            self.controls.items())        if self.controlName:            self.origName = self.controlName.GetValue()    # Return original values    def GetState(self):        if self.controlName:            return (self.origChecks, self.origControls, self.origName)        else:            return (self.origChecks, self.origControls)    # Set values from undo data    def SetState(self, state):        for k,v in state[0]:            self.checks[k].SetValue(v)        for k,v,e in state[1]:            self.controls[k].SetValue(v)            self.controls[k].Enable(e)            # Set all states to modified            if e and k in self.xxx.params: self.controls[k].modified = True                    if self.controlName:            self.controlName.SetValue(state[2])################################################################################# Panel for displaying propertiesclass PropPage(ParamPage):    renameDict = {'orient':'orientation', 'option':'proportion',                  'usenotebooksizer':'usesizer', 'dontattachtoframe':'dontattach',                  }    def __init__(self, parent, label, xxx):        ParamPage.__init__(self, parent, xxx)        self.box = wx.StaticBox(self, -1, label)        #self.box.SetFont(g.labelFont())        topSizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)        sizer = wx.FlexGridSizer(len(xxx.allParams), 2, 1, 5)        sizer.AddGrowableCol(1)        if xxx.hasName:            label = wx.StaticText(self, -1, 'XML ID:', size=self.labelSize)            control = ParamText(self, 'XML_name', 200)            sizer.AddMany([ (label, 0, wx.ALIGN_CENTER_VERTICAL),                            (control, 0, wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.GROW, 10) ])            self.controlName = control        for param in xxx.allParams:            present = xxx.params.has_key(param)            sParam = self.renameDict.get(param, param)            if param in xxx.required:                if isinstance(xxx, xxxComment):                    label = None                else:                    label = wx.StaticText(self, paramIDs[param], sParam,                                          size = self.labelSize, name = param)            else:                label = wx.CheckBox(self, paramIDs[param], sParam,                                   size = self.labelSize, name = param)                self.checks[param] = label            try:                typeClass = xxx.paramDict[param]            except KeyError:                try:                    # Standart type                    typeClass = paramDict[param]                except KeyError:                    # Default                    typeClass = ParamText            control = typeClass(self, param)            control.Enable(present)            # Comment has only one parameter            if isinstance(xxx, xxxComment):                # Bind char event to check Enter key                control.text.Bind(wx.EVT_CHAR, self.OnEnter)                sizer.Add(control, 0, wx.ALIGN_CENTER_VERTICAL | wx.GROW)            else:                sizer.AddMany([ (label, 0, wx.ALIGN_CENTER_VERTICAL),                                (control, 0, wx.ALIGN_CENTER_VERTICAL | wx.GROW) ])            self.controls[param] = control        topSizer.Add(sizer, 1, wx.ALL | wx.EXPAND, 3)        self.SetSizer(topSizer)        topSizer.Fit(self)            def SetValues(self, xxx):        self.xxx = xxx        self.origChecks = []        self.origControls = []        # Set values, checkboxes to False, disable defaults        if xxx.hasName:            self.controlName.SetValue(xxx.name)            self.origName = xxx.name        for param in xxx.allParams:            w = self.controls[param]            w.modified = False            try:                value = xxx.params[param].value()                w.Enable(True)                w.SetValue(value)                if not param in xxx.required:                    self.checks[param].SetValue(True)                    self.origChecks.append((param, True))                self.origControls.append((param, value, True))            except KeyError:                # Optional param not present in xxx - set empty value                self.checks[param].SetValue(False)                w.SetValue('')                w.Enable(False)                self.origChecks.append((param, False))                self.origControls.append((param, '', False))    # This is called only for comment now    def OnEnter(self, evt):        if evt.GetKeyCode() == 13:            g.tree.Apply(self.xxx, g.tree.selection)        else:            evt.Skip()################################################################################# Style notebook pageclass StylePage(ParamPage):    renameDict = {'fg':'foreground', 'bg':'background'}    def __init__(self, parent, label, xxx):        ParamPage.__init__(self, parent, xxx)        box = wx.StaticBox(self, -1, label)        #box.SetFont(g.labelFont())        topSizer = wx.StaticBoxSizer(box, wx.VERTICAL)        sizer = wx.FlexGridSizer(len(xxx.styles), 2, 1, 5)        sizer.AddGrowableCol(1)        for param in xxx.styles:            present = xxx.params.has_key(param)            sParam = self.renameDict.get(param, param)            check = wx.CheckBox(self, paramIDs[param],                                sParam, size = self.labelSize, name = param)            check.SetValue(present)            control = paramDict[param](self, name = param)            control.Enable(present)            sizer.AddMany([ (check, 0, wx.ALIGN_CENTER_VERTICAL),                            (control, 0, wx.ALIGN_CENTER_VERTICAL | wx.GROW) ])            self.checks[param] = check            self.controls[param] = control        topSizer.Add(sizer, 1, wx.ALL | wx.EXPAND, 3)        self.SetAutoLayout(True)        self.SetSizer(topSizer)        topSizer.Fit(self)            # Set data for a cahced page    def SetValues(self, xxx):        self.xxx = xxx        self.origChecks = []        self.origControls = []        for param in xxx.styles:            present = xxx.params.has_key(param)            check = self.checks[param]            check.SetValue(present)            w = self.controls[param]            w.modified = False            if present:                value = xxx.params[param].value()            else:                value = ''            w.SetValue(value)            w.Enable(present)            self.origChecks.append((param, present))            self.origControls.append((param, value, present))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -