def _setup_actions(self): """ Creates the main window actions. """ # Show/hide callable objects self.toggle_callable_action = \ QtGui.QAction("Show routine attributes", self, checkable=True, statusTip = "Shows/hides attributes that are routings (functions, methods, etc)") self.toggle_callable_action.toggled.connect(self.toggle_callables) # Show/hide special attributes self.toggle_special_attribute_action = \ QtGui.QAction("Show __special__ attributes", self, checkable=True, statusTip = "Shows or hides __special__ attributes") self.toggle_special_attribute_action.toggled.connect(self.toggle_special_attributes)
def createToolbars(self): toolbarsettings = windowsoptions['mainwindow']['toolbarsettings'] self.toolbar = QtGui.QToolBar(self) self.toolbar.setMovable(toolbarsettings['movable']) self.toolbar.setVisible(toolbarsettings['visual']) self.addToolBar(toolbarsettings['dockArea'], self.toolbar) for toolbar in toolbarsettings['toolbars']: setattr( self, '%sAction' % toolbar['trigger'], QtGui.QAction( QtGui.QIcon(QtGui.QPixmap(toolbar['icon'])), '%s%s' % (toolbar['name'], toolbar['name_zh']), self ) ) if hasattr(self, 'action%s' % toolbar['trigger']): action = getattr(self, '%sAction' % toolbar['trigger']) action.setShortcut(QtGui.QKeySequence(toolbar['shortcut'])) action.setToolTip(toolbar['tooltip']) self.toolbar.addAction(action) action.triggered.connect( getattr(self, 'action%s' % toolbar['trigger']) ) self.toolbar.widgetForAction(action).setObjectName(toolbar['id']) else: action = getattr(self, '%sAction' % toolbar['trigger']) action.setShortcut(QtGui.QKeySequence(toolbar['shortcut'])) action.setToolTip(toolbar['tooltip']) self.toolbar.addAction(action) action.triggered.connect( getattr(self, 'actionNotImplement') ) self.toolbar.widgetForAction(action).setObjectName(toolbar['id'])
def createMenus(self): menusettings = windowsoptions['mainwindow']['menusettings'] menubar = self.menuBar() menubar.setVisible(menusettings['visual']) for menu in menusettings['menus']: setattr( self, '%smenu' % menu['name'], menubar.addMenu(u'%s%s' % (menu['name'], menu['name_zh'])) ) submenu = getattr(self, '%smenu' % menu['name']) for menuaction in menu['actions']: setattr( self, '%sAction' % menuaction['trigger'], QtGui.QAction( QtGui.QIcon(QtGui.QPixmap(menuaction['icon'])), '%s%s' % (menuaction['name'], menuaction['name_zh']), self ) ) if hasattr(self, 'action%s' % menuaction['trigger']): action = getattr(self, '%sAction' % menuaction['trigger']) action.setShortcut(QtGui.QKeySequence(menuaction['shortcut'])) submenu.addAction(action) action.triggered.connect( getattr(self, 'action%s' % menuaction['trigger']) ) else: action = getattr(self, '%sAction' % menuaction['trigger']) action.setShortcut(QtGui.QKeySequence(menuaction['shortcut'])) submenu.addAction(action) action.triggered.connect( getattr(self, 'actionNotImplement') )
def add_header_context_menu(self, checked=None, checkable=None, enabled=None): """ Adds the context menu from using header information checked can be a header_name -> boolean dictionary. If given, headers with the key name will get the checked value from the dictionary. The corresponding column will be hidden if checked is False. checkable can be a header_name -> boolean dictionary. If given, headers with the key name will get the checkable value from the dictionary. enabled can be a header_name -> boolean dictionary. If given, headers with the key name will get the enabled value from the dictionary. """ checked = checked if checked is not None else {} checkable = checkable if checkable is not None else {} enabled = enabled if enabled is not None else {} horizontal_header = self._horizontal_header() horizontal_header.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) self.toggle_column_actions_group = QtGui.QActionGroup(self) self.toggle_column_actions_group.setExclusive(False) self.__toggle_functions = [] # for keeping references for col in range(horizontal_header.count()): column_label = self.model().headerData(col, Qt.Horizontal, Qt.DisplayRole) logger.debug("Adding: col {}: {}".format(col, column_label)) action = QtGui.QAction( "Show {} column".format(column_label), self.toggle_column_actions_group, checkable=checkable.get(column_label, True), enabled=enabled.get(column_label, True), toolTip="Shows or hides the {} column".format(column_label)) func = self.__make_show_column_function(col) self.__toggle_functions.append(func) # keep reference horizontal_header.addAction(action) is_checked = checked.get( column_label, not horizontal_header.isSectionHidden(col)) horizontal_header.setSectionHidden(col, not is_checked) action.setChecked(is_checked) action.toggled.connect(func)