Exemplo n.º 1
0
def bind_id_to_menu(mlist, win, pid=None):
    if pid not in mlist:
        return
    
    for m in mlist[pid]:
        order, idname, caption, kind, func, message = m
        if mlist.has_key(idname):
            id = Id.makeid(win, idname)
            bind_id_to_menu(mlist, win, idname)
        else:
            if kind == wx.ITEM_SEPARATOR:
                pass
            else:
                id = Id.makeid(win, idname)
Exemplo n.º 2
0
def insertmenu(mlist, insertmlist, sortedmenukey, win, accel=None, imagelist=None):
#    debug.info('[makemenu] Inserting dynamic menu...')
#    makemenu.printmenu(insertmlist)
    
    keys = sortedmenukey[:]
    while len(keys) > 0:
        key = keys[0]
        if key == None:
            for     order, idname, caption, kind, func, message in insertmlist[key]:
                id = Id.makeid(win, idname)
                menu = makemenu.makesubmenu(insertmlist, win, idname, accel, imagelist)
                makemenu.setmenutext(win, accel)
                win.menubar.Insert(findpos(mlist, key, idname), menu, caption)
                win.menuitems[idname] = menu
            removekey(insertmlist, keys, key)
        else:
            menu = win.menuitems[key]
            for     order, idname, caption, kind, func, message in insertmlist[key]:
                pos = findpos(mlist, key, idname)
                if insertmlist.has_key(idname): #submenu
                    id = Id.makeid(win, idname)
                    submenu = makemenu.makesubmenu(mlist, win, idname, accel, imagelist)
                    menu.InsertMenu(pos, id, caption, submenu)
                    win.menuitems[idname] = submenu
                else:
                    if kind == wx.ITEM_SEPARATOR:
                        menu.InsertSeparator(pos)
                    else:
                        id = Id.makeid(win, idname)
                        mitem = wx.MenuItem(menu, id, caption, message, kind)
                        if imagelist and makemenu.disableimage == False:
                            imagename = imagelist.get(idname, '')
                            if imagename:
                                image = common.getpngimage(imagename)
                                if kind == wx.ITEM_CHECK:
                                    mitem.SetBitmaps(image)
                                else:
                                    mitem.SetBitmap(image)
                        menu.InsertItem(pos, mitem)
                        win.menuitems[idname] = mitem

                    if kind in (wx.ITEM_NORMAL, wx.ITEM_CHECK, wx.ITEM_RADIO):
                        if func:
                            try:
                                f = getattr(win, func)
                                wx.EVT_MENU(win, id, f)
                            except:
                                debug.error("[makemenu] Can't find function [%s] in class %s" % (func, win.__class__.__name__))
            removekey(insertmlist, keys, key)
Exemplo n.º 3
0
def makesubmenu(mlist, win, pid, accel=None, imagelist=None):
    menu = wx.Menu()
    if not mlist.has_key(pid):
        return menu
    for m in mlist[pid]:
        order, idname, caption, kind, func, message = m
        if mlist.has_key(idname):
            id = Id.makeid(win, idname)
            submenu = makesubmenu(mlist, win, idname, accel, imagelist)
            menu.AppendMenu(id, caption, submenu)
            win.menuitems[idname] = submenu
        else:
            if kind == wx.ITEM_SEPARATOR:
                menu.AppendSeparator()
            else:
                id = Id.makeid(win, idname)
                if accel and accel.has_key(idname):
                    caption = caption.split('\t')[0]
                    mitem = wx.MenuItem(menu, id, caption, message, kind)
                    #mitem.SetText(caption + '\t' + accel[idname][0])
                else:
                    pos = caption.find('\t')
                    if pos > -1:
                        a, b = caption.split('\t')
                        #caption = a + '\t' + b.replace('+', ',')
                    mitem = wx.MenuItem(menu, id, caption, message, kind)
                if imagelist and disableimage == False:
                    imagename = imagelist.get(idname, '')
                    if imagename:
                        image = common.getpngimage(imagename)
                        if kind == wx.ITEM_CHECK:
                            mitem.SetBitmaps(image)
                        else:
                            mitem.SetBitmap(image)
#                else:
#                    print 'nobitmap'
#                    if wx.Platform == '__WXMSW__':
#                        mitem.SetBitmap(common.getpngimage('images/empty.gif'))
                menu.AppendItem(mitem)
                win.menuitems[idname] = mitem

            if kind in (wx.ITEM_NORMAL, wx.ITEM_CHECK, wx.ITEM_RADIO):
                if func:
                    try:
                        f = getattr(win, func)
                        wx.EVT_MENU(win, id, f)
                    except:
                        debug.error("[makemenu] Can't find function [%s] in class %s" % (func, win.__class__.__name__))
    return menu
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
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()
Exemplo n.º 9
0
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()
Exemplo n.º 10
0
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