def makeaccelerator(m, accellist, editoraccellist): debug.info('[makemenu] makeaccelerator...') for itementry in m.values(): for order, idname, caption, kind, func, message in itementry: pos = caption.find('\t') if pos>= 0: accel = caption[pos+1:] if accel.startswith('E='): #editor shortcut if editoraccellist.has_key(idname): accelkey = editoraccellist[idname][0] else: accelkey = accel[2:] editoraccellist[idname] = (accelkey, func) else: if accellist.has_key(idname): accelkey = accellist[idname][0] else: accelkey = accel accellist[idname] = (accelkey, func) else: if idname: accelkey = '' accellist[idname] = (accelkey, func) if idname: debug.info('\t%s [%s]' % (idname, accelkey))
def DoCreateResource(self): debug.info("[Resource] class %s 's object..." % self.GetName()) # Now create the object if issubclass(self.winclass, wx.Dialog): obj = self.winclass( self.parentwin, self.GetID(), self.GetText("title"), self.GetPosition(), self.GetSize(), self.GetStyle() ) elif issubclass(self.winclass, wx.Frame): obj = self.winclass( self.parentwin, self.GetID(), self.GetText("title"), self.GetPosition(), self.GetSize(), self.GetStyle() ) elif issubclass(self, winclass, wx.Panel): obj = self.winclass( self.parentwin, self.GetID(), self.GetPosition(), self.GetSize(), self.GetStyle(), self.GetName() ) # These two things should be done in either case: # Set standard window attributes self.SetupWindow(obj) # Create any child windows of this node self.CreateChildren(obj) # Create IDs for id in self.ids: setattr(obj, id, XRCID(id)) setattr(obj, "obj_" + id, self.parentwin.FindWindowById(XRCID(id))) # Call object init obj.init(*self.args, **self.kwargs) self.obj = obj return obj
def makepopmenu(win, popmenu, imagelist=None): win.menuitems = {} mlist = mergemenu(popmenu) debug.info('[makemenu] Popmenu Menu listing...') printmenu(mlist, imagelist) menu = makesubmenu(mlist, win, None, None, imagelist) return menu
def inserttoolbar(win, oldtoollist, toollist, toolbaritems): if len(toollist) == 0: return tl = oldtoollist[:] newtl = toollist[:] newtl.sort() tl.extend(newtl) tl.sort() debug.info('[insert tools] toolbar list...') for v in newtl: i = tl.index(v) order, name = v if name == '|': win.toolbar.InsertSeparator(i) debug.info('\t%d -' % order) else: style = toolbaritems[name][0] if style == 10: #custom control, so others will be a function, it'll should be defined as #func(mainframe, toolbar) func = toolbaritems[name][1] obj = func(win, win.toolbar) debug.info('\t%d %s' % (order, 'call func...' + repr(func))) win.toolbar.InsertControl(i, obj) else: style, idname, imagefile, shorttext, longtext, func = toolbaritems[ name] debug.info('\t%d %s' % (order, idname)) image = common.getpngimage(imagefile) id = Id.makeid(win, idname) if style == wx.ITEM_NORMAL: win.toolbar.InsertSimpleTool(i, id, image, shorttext, longtext) elif style == wx.ITEM_CHECK: win.toolbar.InsertTool(i, id, image, isToggle=True, shortHelpString=shorttext, longHelpString=longtext) # elif style == wx.ITEM_RADIO: # win.toolbar.InsertRadioTool(i, id, image, shortHelp=shorttext, longHelp=longtext) else: raise EUnknowStyleType if func: try: f = getattr(win, func) wx.EVT_TOOL(win, id, f) except: debug.info( "[maketoolbar] Can't find function [%s] in class %s" % (func, win.__class__.__name__)) win.toolbar.Realize()
def inserttoolbar(win, oldtoollist, toollist, toolbaritems): if len(toollist) == 0: return tl = oldtoollist[:] newtl = toollist[:] newtl.sort() tl.extend(newtl) tl.sort() debug.info("[insert tools] toolbar list...") for v in newtl: i = tl.index(v) order, name = v if name == "|": win.toolbar.InsertSeparator(i) debug.info("\t%d -" % order) else: style = toolbaritems[name][0] if style == 10: # custom control, so others will be a function, it'll should be defined as # func(mainframe, toolbar) func = toolbaritems[name][1] obj = func(win, win.toolbar) debug.info("\t%d %s" % (order, "call func..." + repr(func))) win.toolbar.InsertControl(i, obj) else: style, idname, imagefile, shorttext, longtext, func = toolbaritems[name] debug.info("\t%d %s" % (order, idname)) image = common.getpngimage(imagefile) id = Id.makeid(win, idname) if style == wx.ITEM_NORMAL: win.toolbar.InsertSimpleTool(i, id, image, shorttext, longtext) elif style == wx.ITEM_CHECK: win.toolbar.InsertTool( i, id, image, isToggle=True, shortHelpString=shorttext, longHelpString=longtext ) # elif style == wx.ITEM_RADIO: # win.toolbar.InsertRadioTool(i, id, image, shortHelp=shorttext, longHelp=longtext) else: raise EUnknowStyleType if func: try: f = getattr(win, func) wx.EVT_TOOL(win, id, f) except: debug.info( "[maketoolbar] Can't find function [%s] in class %s" % (func, win.__class__.__name__) ) win.toolbar.Realize()
def initaccelerator(win, acceleratorlist): ikey = 0 accelist = [] debug.info('[accelerator] listing ...') for idname, value in acceleratorlist.items(): keys, func = value if not keys: continue debug.info('%s\t%s' % (keys, idname)) f, ikey = create_key(keys) id = Id.makeid(win, idname) accelist.append((f, ikey, id)) aTable = wx.AcceleratorTable(accelist) win.SetAcceleratorTable(aTable)
def DoCreateResource(self): debug.info("[Resource] class %s 's object..." % self.GetName()) # Now create the object if issubclass(self.winclass, wx.Dialog): obj = self.winclass(self.parentwin, self.GetID(), self.GetText('title'), self.GetPosition(), self.GetSize(), self.GetStyle() ) elif issubclass(self.winclass, wx.Frame): obj = self.winclass(self.parentwin, self.GetID(), self.GetText('title'), self.GetPosition(), self.GetSize(), self.GetStyle() ) elif issubclass(self,winclass, wx.Panel): obj = self.winclass(self.parentwin, self.GetID(), self.GetPosition(), self.GetSize(), self.GetStyle(), self.GetName(), ) # These two things should be done in either case: # Set standard window attributes self.SetupWindow(obj) # Create any child windows of this node self.CreateChildren(obj) # Create IDs for id in self.ids: setattr(obj, id, XRCID(id)) setattr(obj, 'obj_'+id, self.parentwin.FindWindowById(XRCID(id))) # Call object init obj.init(*self.args, **self.kwargs) self.obj = obj return obj
def printmenu(m, imagelist=None): if not DEBUG: return debug.info('[makemenu] Menu listing...') if m.has_key(None): for order, idname, caption, kind, func, message in m[None]: debug.info('\t%s %s\t"%s"' % (order, idname, caption)) if m.has_key(idname): printsubmenu(m, '\t ', idname) if imagelist and (disableimage == False): debug.info('[makemenu] Image list...') for idname, filename in imagelist.items(): debug.info('\t%s\t%s' % (idname, filename))
def makemenu(win, menulist, accel=None, editoraccel=None, imagelist=None): menuBar = wx.MenuBar() win.menuitems = {} mlist = mergemenu(menulist) debug.info('[makemenu] Main Menu listing...') printmenu(mlist, imagelist) makeaccelerator(mlist, accel, editoraccel) a = {} a.update(accel) a.update(editoraccel) menuBar.Freeze() for m in mlist[None]: order, idname, caption, kind, func, message = m id = Id.makeid(win, idname) menu = makesubmenu(mlist, win, idname, a, imagelist) menuBar.Append(menu, caption) win.menuitems[idname] = menu menuBar.Thaw() return menuBar
def addtools(win, toolbar, toollist, toolbaritems): #judge image size by the first item of the toolbar item list imagefile = toolbaritems.values()[0][2] image = common.getpngimage(imagefile) size = wx.Size(image.GetWidth(), image.GetHeight()) toolbar.SetToolBitmapSize(size) toollist.sort() debug.info('[addtools] toolbar list...') for order, name in toollist: if name == '|': toolbar.AddSeparator() debug.info('\t%d -' % order) else: style = toolbaritems[name][0] if style == 10: #custom control, so others will be a function, it'll should be defined as #func(mainframe, toolbar) func = toolbaritems[name][1] obj = func(win, toolbar) debug.info('\t%d %s' % (order, 'call func...' + repr(func))) toolbar.AddControl(obj) else: style, idname, imagefile, shorttext, longtext, func = toolbaritems[ name] debug.info('\t%d %s' % (order, idname)) image = common.getpngimage(imagefile) id = Id.makeid(win, idname) if style == wx.ITEM_NORMAL: toolbar.AddSimpleTool(id, image, shorttext, longtext) elif style == wx.ITEM_CHECK: toolbar.AddCheckTool(id, image, shortHelp=shorttext, longHelp=longtext) # elif style == wx.ITEM_RADIO: # toolbar.AddRadioTool(id, image, shortHelp=shorttext, longHelp=longtext) else: raise EUnknowStyleType if func: try: f = getattr(win, func) wx.EVT_TOOL(win, id, f) except: error.info( "[addtools] Can't find function [%s] in class %s" % (func, win.__class__.__name__)) toolbar.Realize()
def initmixin(self): debug.info('[Mixin] Dealing class [%s]' % self.__class__.__name__) if self.__class__.__name__ == 'Mixin': #don't dealing Mixin class itself return if hasattr(self.__class__, '__mixinflag__'): if self.__class__.__mixinflag__ >= 1: #having executed mixin return else: self.__class__.__mixinflag__ = 1 else: setattr(self.__class__, '__mixinflag__', 1) if not self.__mixinname__: debug.warn('[Mixin] The class [%s] has not a mixinname defined' % self.__class__.__name__) return if not __mixins_funcs_time_set__.has_key(self.__mixinname__): __mixins_funcs_time_set__[self.__mixinname__] = {} if __mixinset__.has_key(self.__mixinname__): debug.info('[Mixin] Mixinning class [%s]' % self.__class__.__name__) mixins, plugins = __mixinset__[self.__mixinname__] items = {} for name, value in mixins.items(): if not value[0]: setProperty(self.__class__, name, value[1], self) else: items[name] = value[1] mixins_funcs_time = __mixins_funcs_time_set__[self.__mixinname__] setattr(self.__class__, '__mixins__', items) setattr(self.__class__, '__plugins__', plugins) setattr(self.__class__, '__mixins_funcs_time__', mixins_funcs_time) else: setattr(self.__class__, '__mixins__', {}) setattr(self.__class__, '__plugins__', {}) setattr(self.__class__, '__mixins_funcs_time__', {}) setattr(self.__class__, '__one_plugins__', {})
def addtools(win, toolbar, toollist, toolbaritems): #judge image size by the first item of the toolbar item list imagefile = toolbaritems.values()[0][2] image = common.getpngimage(imagefile) size = wx.Size(image.GetWidth(), image.GetHeight()) toolbar.SetToolBitmapSize(size) toollist.sort() debug.info('[addtools] toolbar list...') for order, name in toollist: if name == '|': toolbar.AddSeparator() debug.info('\t%d -' % order) else: style = toolbaritems[name][0] if style == 10: #custom control, so others will be a function, it'll should be defined as #func(mainframe, toolbar) func = toolbaritems[name][1] obj = func(win, toolbar) debug.info('\t%d %s' % (order, 'call func...' + repr(func))) toolbar.AddControl(obj) else: style, idname, imagefile, shorttext, longtext, func = toolbaritems[name] debug.info('\t%d %s' % (order, idname)) image = common.getpngimage(imagefile) id = Id.makeid(win, idname) if style == wx.ITEM_NORMAL: toolbar.AddSimpleTool(id, image, shorttext, longtext) elif style == wx.ITEM_CHECK: toolbar.AddCheckTool(id, image, shortHelp=shorttext, longHelp=longtext) # elif style == wx.ITEM_RADIO: # toolbar.AddRadioTool(id, image, shortHelp=shorttext, longHelp=longtext) else: raise EUnknowStyleType if func: try: f = getattr(win, func) wx.EVT_TOOL(win, id, f) except: error.info("[addtools] Can't find function [%s] in class %s" % (func, win.__class__.__name__)) toolbar.Realize()
def printMixin(): debug.info("[Mixin] Printing mixin set...") for name, value in __mixinset__.items(): mixins, plugins = value debug.info("\tname=%s" % name) debug.info("\t |----mixin") keys = mixins.keys() keys.sort() for k in keys: t, f = mixins[k] if callable(f): debug.info("\t |%s\t%s.%s" % (k, f.__module__, f.__name__)) else: debug.info("\t |%s %s" % (k, f)) debug.info("\t |----plugin") keys = plugins.keys() keys.sort() for k in keys: debug.info("\t |%s" % k) for nice, f in plugins[k]: if callable(f): debug.info("\t\t %d %s.%s" % (nice, f.__module__, f.__name__)) else: debug.info("\t\t %d %s" % (nice, f))
def CanHandle(self, node): id = node.GetPropVal('name', '') if id: self.ids.append(id) debug.info("\t%s\t%s" % (node.GetPropVal('class', ''), id)) return self.IsOfClass(node, self.classname)
def CanHandle(self, node): id = node.GetPropVal("name", "") if id: self.ids.append(id) debug.info("\t%s\t%s" % (node.GetPropVal("class", ""), id)) return self.IsOfClass(node, self.classname)
def printsubmenu(m, space,idname): if not DEBUG: return for order, idname, caption, kind, func, message in m[idname]: debug.info('%s%s %s\t"%s"' % (space, order, idname, caption)) if m.has_key(idname): printsubmenu(m, space + ' ', idname)