def definePlugins(self, pluginlist, actions, menuname): """Create menu items and actions for plugins. pluginlist: list of plugin classes actions: dict of actions to add new actions to menuname: string giving prefix for new menu entries (inside actions) """ menu = [] for pluginkls in pluginlist: def loaddialog(pluginkls=pluginkls): """Load plugin dialog""" handlePlugin(self, self.document, pluginkls) actname = menuname + '.' + '.'.join(pluginkls.name) text = pluginkls.menu[-1] if pluginkls.has_parameters: text += '...' actions[actname] = utils.makeAction( self, pluginkls.description_short, text, loaddialog) # build up menu from tuple of names menulook = menu namebuild = [menuname] for cmpt in pluginkls.menu[:-1]: namebuild.append(cmpt) name = '.'.join(namebuild) for c in menulook: if c[0] == name: menulook = c[2] break else: menulook.append( [name, cmpt, []] ) menulook = menulook[-1][2] menulook.append(actname) return menu
def _constructToolbarMenu(self): """Add items to edit/add graph toolbar and menu.""" iconsize = setting.settingdb['toolbar_size'] self.addtoolbar.setIconSize( qt4.QSize(iconsize, iconsize) ) self.edittoolbar.setIconSize( qt4.QSize(iconsize, iconsize) ) self.addslots = {} self.vzactions = actions = self.parent.vzactions for widgettype in ('page', 'grid', 'graph', 'axis', 'xy', 'bar', 'fit', 'function', 'boxplot', 'image', 'contour', 'vectorfield', 'key', 'label', 'colorbar', 'rect', 'ellipse', 'imagefile', 'line', 'polygon', 'polar', 'ternary', 'nonorthpoint', 'nonorthfunc'): wc = document.thefactory.getWidgetClass(widgettype) slot = utils.BoundCaller(self.slotMakeWidgetButton, wc) self.addslots[wc] = slot actionname = 'add.' + widgettype actions[actionname] = utils.makeAction( self, wc.description, 'Add %s' % widgettype, slot, icon='button_%s' % widgettype) a = utils.makeAction actions.update({ 'edit.cut': a(self, 'Cut the selected item', 'Cu&t', self.slotWidgetCut, icon='veusz-edit-cut', key='Ctrl+X'), 'edit.copy': a(self, 'Copy the selected item', '&Copy', self.slotWidgetCopy, icon='kde-edit-copy', key='Ctrl+C'), 'edit.paste': a(self, 'Paste item from the clipboard', '&Paste', self.slotWidgetPaste, icon='kde-edit-paste', key='Ctrl+V'), 'edit.moveup': a(self, 'Move the selected item up', 'Move &up', utils.BoundCaller(self.slotWidgetMove, -1), icon='kde-go-up'), 'edit.movedown': a(self, 'Move the selected item down', 'Move d&own', utils.BoundCaller(self.slotWidgetMove, 1), icon='kde-go-down'), 'edit.delete': a(self, 'Remove the selected item', '&Delete', self.slotWidgetDelete, icon='kde-edit-delete'), 'edit.rename': a(self, 'Renames the selected item', '&Rename', self.slotWidgetRename, icon='kde-edit-rename'), 'add.shapemenu': a(self, 'Add a shape to the plot', 'Shape', self.slotShowShapeMenu, icon='veusz-shape-menu'), }) # add actions to menus for adding widgets and editing addact = [('add.'+w) for w in ('page', 'grid', 'graph', 'axis', 'xy', 'nonorthpoint', 'bar', 'fit', 'function', 'nonorthfunc', 'boxplot', 'image', 'contour', 'vectorfield', 'key', 'label', 'colorbar', 'polar', 'ternary')] menuitems = [ ('insert', '', addact + [ ['insert.shape', 'Add shape', ['add.rect', 'add.ellipse', 'add.line', 'add.imagefile', 'add.polygon'] ]]), ('edit', '', [ 'edit.cut', 'edit.copy', 'edit.paste', 'edit.moveup', 'edit.movedown', 'edit.delete', 'edit.rename' ]), ] utils.constructMenus( self.parent.menuBar(), self.parent.menus, menuitems, actions ) # create shape toolbar button # attach menu to insert shape button actions['add.shapemenu'].setMenu(self.parent.menus['insert.shape']) # add actions to toolbar to create widgets utils.addToolbarActions(self.addtoolbar, actions, addact + ['add.shapemenu']) # add action to toolbar for editing utils.addToolbarActions(self.edittoolbar, actions, ('edit.cut', 'edit.copy', 'edit.paste', 'edit.moveup', 'edit.movedown', 'edit.delete', 'edit.rename')) self.connect( self.parent.menus['edit.select'], qt4.SIGNAL('aboutToShow()'), self.updateSelectMenu )
def _constructToolbarMenu(self): """Add items to edit/add graph toolbar and menu.""" iconsize = setting.settingdb['toolbar_size'] self.addtoolbar.setIconSize( qt4.QSize(iconsize, iconsize) ) self.edittoolbar.setIconSize( qt4.QSize(iconsize, iconsize) ) self.addslots = {} self.vzactions = actions = self.parentwin.vzactions for widgettype in ('page', 'grid', 'graph', 'axis', 'xy', 'bar', 'fit', 'function', 'boxplot', 'image', 'contour', 'vectorfield', 'key', 'label', 'colorbar', 'rect', 'ellipse', 'imagefile', 'line', 'polygon', 'polar', 'ternary', 'nonorthpoint', 'nonorthfunc'): wc = document.thefactory.getWidgetClass(widgettype) slot = utils.BoundCaller(self.slotMakeWidgetButton, wc) self.addslots[wc] = slot actionname = 'add.' + widgettype actions[actionname] = utils.makeAction( self, wc.description, _('Add %s') % widgettype, slot, icon='button_%s' % widgettype) a = utils.makeAction actions.update({ 'edit.cut': a(self, _('Cut the selected widget'), _('Cu&t'), self.slotWidgetCut, icon='veusz-edit-cut', key='Ctrl+X'), 'edit.copy': a(self, _('Copy the selected widget'), _('&Copy'), self.slotWidgetCopy, icon='kde-edit-copy', key='Ctrl+C'), 'edit.paste': a(self, _('Paste widget from the clipboard'), _('&Paste'), self.slotWidgetPaste, icon='kde-edit-paste', key='Ctrl+V'), 'edit.moveup': a(self, _('Move the selected widget up'), _('Move &up'), utils.BoundCaller(self.slotWidgetMove, -1), icon='kde-go-up'), 'edit.movedown': a(self, _('Move the selected widget down'), _('Move d&own'), utils.BoundCaller(self.slotWidgetMove, 1), icon='kde-go-down'), 'edit.delete': a(self, _('Remove the selected widget'), _('&Delete'), self.slotWidgetDelete, icon='kde-edit-delete'), 'edit.rename': a(self, _('Renames the selected widget'), _('&Rename'), self.slotWidgetRename, icon='kde-edit-rename'), 'add.shapemenu': a(self, _('Add a shape to the plot'), _('Shape'), self.slotShowShapeMenu, icon='veusz-shape-menu'), }) # add actions to menus for adding widgets and editing addact = [('add.'+w) for w in ('page', 'grid', 'graph', 'axis', 'xy', 'nonorthpoint', 'bar', 'fit', 'function', 'nonorthfunc', 'boxplot', 'image', 'contour', 'vectorfield', 'key', 'label', 'colorbar', 'polar', 'ternary')] menuitems = [ ('insert', '', addact + [ ['insert.shape', 'Add shape', ['add.rect', 'add.ellipse', 'add.line', 'add.imagefile', 'add.polygon'] ]]), ('edit', '', [ 'edit.cut', 'edit.copy', 'edit.paste', 'edit.moveup', 'edit.movedown', 'edit.delete', 'edit.rename' ]), ] utils.constructMenus( self.parentwin.menuBar(), self.parentwin.menus, menuitems, actions ) # create shape toolbar button # attach menu to insert shape button actions['add.shapemenu'].setMenu(self.parentwin.menus['insert.shape']) # add actions to toolbar to create widgets utils.addToolbarActions(self.addtoolbar, actions, addact + ['add.shapemenu']) # add action to toolbar for editing utils.addToolbarActions(self.edittoolbar, actions, ('edit.cut', 'edit.copy', 'edit.paste', 'edit.moveup', 'edit.movedown', 'edit.delete', 'edit.rename')) self.connect( self.parentwin.menus['edit.select'], qt4.SIGNAL('aboutToShow()'), self.updateSelectMenu )