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 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 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 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()