Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ActionObject used to hold on to the callback for a QAction:
- class ActionObject(object):
- def __init__(self, owner, command):
- action = QtGui.QAction(command.name, owner)
- self.action = action
- self.command = command
- action.setShortcut(command.shortcut)
- action.setStatusTip(command.name)
- QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), self.triggered)
- def triggered(self):
- print("got triggered " + self.command.id + " " + repr(checked))
- Command object used to hold on to miscellaneous command information, and manufacture actions:
- class Command(object):
- def __init__(self, menu, name, prio, id, shortcut=None, icon=None):
- self.menu = menu
- self.name = name
- self.prio = prio
- self.id = id
- self.shortcut = shortcut
- self.icon = icon
- def makeAction(self, owner):
- ao = ActionObject(owner, self)
- return ao.action
- Function that populates a menu bar given a list of command objects:
- menubar = None
- def build(frame, commands):
- global menubar
- menubar = frame.menuBar()
- for i in ['File', 'Edit', 'Project', 'View', 'Other']:
- menu = menubar.addMenu(i)
- last = 0
- for j in commands:
- if j.menu == i:
- if int(j.prio) > last+1:
- menu.addSeparator()
- last = int(j.prio)
- menu.addAction(j.makeAction(frame))
- "frame" is a QMainWindow, and "commands" is a list of Command objects.
- Yes, I know that the menus get created, what with them actually showing up in the window and whatnot...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement