def add_core_actions(self): """ Adds all core *GuiPy* actions to the top-level menubar, which are not related to any plugin or widget. """ # Create dict of actions actions = {'File': [], 'View': [], 'Help': []} # FILE MENU # Add quit action to file menu quit_act = GW.QAction(self, '&Quit', shortcut=QG.QKeySequence.Quit, statustip="Quit %s" % (APP_NAME), triggered=self.close, role=GW.QAction.QuitRole) actions['File'].append(quit_act) # HELP MENU # Add config action to help menu config_act = GW.QAction(self, CONFIG.config_dialog.NAME, shortcut=QG.QKeySequence.Preferences, statustip="Open %s configuration window" % (APP_NAME), triggered=CONFIG.config_dialog, role=GW.QAction.PreferencesRole) actions['Help'].append(config_act) actions['Help'].append(None) # Add about action to help menu about_act = GW.QAction(self, '&About...', statustip="About %s" % (APP_NAME), triggered=self.about, role=GW.QAction.AboutRole) actions['Help'].append(about_act) # Add aboutQt action to help menu aboutqt_act = GW.QAction(self, 'About &Qt...', statustip="About Qt framework", triggered=QW.QApplication.aboutQt, role=GW.QAction.AboutQtRole) actions['Help'].append(aboutqt_act) # Add all actions to the top-level menu self.add_menu_actions(actions)
def _init_toolbar(self): # Create pointer in figure manager to this toolbar self.canvas.manager.toolbar = self # Store the base dir for images for NavigationToolbar2QT self.basedir = str(cbook._get_data_path('images')) # Determine what icon color to use background_color = self.palette().color(self.backgroundRole()) foreground_color = self.palette().color(self.foregroundRole()) icon_color = (foreground_color if background_color.value() < 128 else None) # Create list of info for the toolbuttons button_info = [ ('Home', 'Reset to original view', 'home', 'home'), ('Back', 'Back to previous view', 'back', 'back'), ('Forward', 'Forward to next view', 'forward', 'forward'), (None, None, None, None), ('Pan', 'Pan with left button, zoom with right', 'move', 'pan'), ('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'), (None, None, None, None), ('Options', 'Add, remove, and edit figure elements', 'qt4_editor_options', 'options'), ('Save', 'Save the figure', 'filesave', 'save_figure') ] # Loop over all items in button_info and create the actions for text, tooltip, image_file, func in button_info: # If text is None, a separator is required if text is None: self.addSeparator() # Else, create an action else: # Create action action = GW.QAction(self, text, tooltip=tooltip, icon=self._icon(image_file + '.png', icon_color), triggered=getattr(self, func)) self.addAction(action) # Add action to self._actions self._actions[func] = action # Make zoom and pan checkable if func in ['zoom', 'pan']: action.setCheckable(True) # Add separator self.addSeparator() # Add a label that contains the coordinates of the figure coord_label = GW.QLabel('') coord_label.setSizePolicy(QW.QSizePolicy.Expanding, QW.QSizePolicy.Ignored) self.addWidget(coord_label) self.status_message.connect(coord_label.setText)
def create_vertical_header_context_menu(self): # Create context menu menu = GW.QMenu('V_Header', parent=self) # Add insert_above action to menu insert_above_act = GW.QAction( self, "Insert row above", statustip="Insert a new row above this one", triggered=self.insert_rows) menu.addAction(insert_above_act) # Add insert_below action to menu insert_below_act = GW.QAction( self, "Insert row below", statustip="Insert a new row below this one", triggered=self.insert_rows_after) menu.addAction(insert_below_act) # Add remove action to menu remove_act = GW.QAction(self, "Remove row", statustip="Remove this row", triggered=self.remove_rows) menu.addAction(remove_act) # Add clear action to menu clear_act = GW.QAction(self, "Clear row", statustip="Clear this row", triggered=self.clear_rows) menu.addAction(clear_act) # Add hide action to menu hide_act = GW.QAction(self, "Hide row", statustip="Hide this row", triggered=self.hide_rows) # menu.addAction(hide_act) # Set last requested row to 0 self._last_context_row = 0 # Save made menu as an attribute self.v_header_menu = menu
def create_horizontal_header_context_menu(self): # Create context menu menu = GW.QMenu('H_Header', parent=self) # Add insert_above action to menu insert_above_act = GW.QAction( self, "Insert column left", statustip="Insert a new column left of this one", triggered=self.insert_cols) menu.addAction(insert_above_act) # Add insert_below action to menu insert_below_act = GW.QAction( self, "Insert column right", statustip="Insert a new column right of this one", triggered=self.insert_cols_after) menu.addAction(insert_below_act) # Add remove action to menu remove_act = GW.QAction(self, "Remove column", statustip="Remove this column", triggered=self.remove_cols) menu.addAction(remove_act) # Add clear action to menu clear_act = GW.QAction(self, "Clear column", statustip="Clear this column", triggered=self.clear_cols) menu.addAction(clear_act) # Add hide action to menu hide_act = GW.QAction(self, "Hide column", statustip="Hide this column", triggered=self.hide_cols) # menu.addAction(hide_act) # Set last requested col to 0 self._last_context_col = 0 # Save made menu as an attribute self.h_header_menu = menu
def add_actions(self): # Initialize empty action lists for this plugin self.MENU_ACTIONS = { **GP.BasePluginWidget.MENU_ACTIONS, 'File/New': []} # Add new figure action to file/new menu # TODO: Should shortcut be CTRL+F? Might clash with expectations new_tab_act = GW.QAction( self, '&Figure', shortcut=QC.Qt.CTRL + QC.Qt.Key_F, tooltip="New figure", triggered=self.add_tab, role=GW.QAction.ApplicationSpecificRole) self.MENU_ACTIONS['File/New'].append(new_tab_act)
def add_actions(self): # Initialize empty action lists for this plugin self.MENU_ACTIONS = { **GP.BasePluginWidget.MENU_ACTIONS, 'File': [], 'File/New': [] } self.TOOLBAR_ACTIONS = { **GP.BasePluginWidget.TOOLBAR_ACTIONS, 'File': [] } # Add new tab action to file/new menu new_tab_act = GW.QAction(self, 'Data &table', shortcut=QC.Qt.CTRL + QC.Qt.Key_T, tooltip="New data table", triggered=self.add_tab, role=GW.QAction.ApplicationSpecificRole) self.MENU_ACTIONS['File/New'].append(new_tab_act) self.MENU_ACTIONS['File/New'].append(self.add_tab) # Add open tabs action to file menu/toolbar open_tabs_act = GW.QAction(self, '&Open...', shortcut=QC.Qt.CTRL + QC.Qt.Key_O, tooltip="Open data table", triggered=self.open_tabs, role=GW.QAction.ApplicationSpecificRole) open_tabs_act.setEnabled(False) self.MENU_ACTIONS['File'].append(open_tabs_act) self.TOOLBAR_ACTIONS['File'].append(open_tabs_act) # Add import tabs action to file menu/toolbar import_tabs_act = GW.QAction(self, '&Import...', shortcut=QC.Qt.CTRL + QC.Qt.Key_I, tooltip="Import data tables", triggered=self.import_tabs, role=GW.QAction.ApplicationSpecificRole) self.MENU_ACTIONS['File'].append(import_tabs_act) self.TOOLBAR_ACTIONS['File'].append(import_tabs_act) # Add separator to file menu self.MENU_ACTIONS['File'].append(None) # Add save tab action to file menu/toolbar save_tab_act = GW.QAction(self, '&Save', shortcut=QC.Qt.CTRL + QC.Qt.Key_S, tooltip="Save current data table", triggered=self.save_tab, role=GW.QAction.ApplicationSpecificRole) save_tab_act.setEnabled(False) self.MENU_ACTIONS['File'].append(save_tab_act) self.TOOLBAR_ACTIONS['File'].append(save_tab_act) # Add save_as tab action to file menu save_as_tab_act = GW.QAction(self, 'Save &as...', shortcut=QC.Qt.CTRL + QC.Qt.SHIFT + QC.Qt.Key_S, tooltip="Save current data table as...", triggered=self.save_as_tab, role=GW.QAction.ApplicationSpecificRole) save_as_tab_act.setEnabled(False) self.MENU_ACTIONS['File'].append(save_as_tab_act) # Add save_all tab action to file menu/toolbar save_all_tabs_act = GW.QAction(self, 'Sav&e all', shortcut=QC.Qt.CTRL + QC.Qt.ALT + QC.Qt.Key_S, tooltip="Save all data tables", triggered=self.save_all_tabs, role=GW.QAction.ApplicationSpecificRole) save_all_tabs_act.setEnabled(False) self.MENU_ACTIONS['File'].append(save_all_tabs_act) self.TOOLBAR_ACTIONS['File'].append(save_all_tabs_act) # Add export tab action to file menu/toolbar export_tab_act = GW.QAction(self, '&Export...', shortcut=QC.Qt.CTRL + QC.Qt.Key_E, tooltip="Export current data table", triggered=self.export_tab, role=GW.QAction.ApplicationSpecificRole) self.MENU_ACTIONS['File'].append(export_tab_act) self.TOOLBAR_ACTIONS['File'].append(export_tab_act) # Add separator to file menu self.MENU_ACTIONS['File'].append(None)