def __init__(self): UI.__init__(self) self.toolkit = "GTK3" window = Gtk.Window() self.window = window self.window.set_title(self.window_title) self.window.set_icon_name(self.window_icon) self.window.set_default_size(self.window_size_w, self.window_size_h) self.window.connect("destroy", self.destroy) self.window.connect("check-resize", self.on_resize) window_scrolled = Gtk.ScrolledWindow() self.window.add(window_scrolled) self.window_box = Gtk.VBox() window_scrolled.add(self.window_box) self.header_bar = Gtk.HeaderBar() self.content_ui_vbox = Gtk.VBox() self.window_box.pack_start(self.content_ui_vbox, True, True, 0) self.menu_button = Gtk.MenuButton() self.action_group = Gtk.ActionGroup("actions") self.theme = Gtk.IconTheme.get_default() # Function to launch at startup self.generate_view() self.build_toolbar() self.draw_ui()
def __init__(self): super().__init__(title="Menu Example") self.set_default_size(200, 200) action_group = Gtk.ActionGroup("my_actions") self.add_file_menu_actions(action_group) self.add_edit_menu_actions(action_group) self.add_choices_menu_actions(action_group) uimanager = self.create_ui_manager() uimanager.insert_action_group(action_group) menubar = uimanager.get_widget("/MenuBar") box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) box.pack_start(menubar, False, False, 0) toolbar = uimanager.get_widget("/ToolBar") box.pack_start(toolbar, False, False, 0) eventbox = Gtk.EventBox() eventbox.connect("button-press-event", self.on_button_press_event) box.pack_start(eventbox, True, True, 0) label = Gtk.Label("Right-click to see the popup menu.") eventbox.add(label) self.popup = uimanager.get_widget("/PopupMenu") self.add(box)
def insert_controls(self, in_repo=True): """Insert the controls defined in self.toolbar_ui_string into the toolbar""" _gd.DEBUG('Inserting controls..') # Get the Gtk.UIManager manager = self._window.get_ui_manager() # Create ActionGroup for repo control items self._action_group = Gtk.ActionGroup("GititPluginActions") if in_repo: self._action_group.add_actions([ ("GitCommit", Gtk.STOCK_APPLY, _("Commit"), None, _("Opens the Git GUI to perform commit."), self._git.commit) ]) toolbar_ui_items = """ <toolitem name="GitCommit" action="GitCommit"/>""" else: self._action_group.add_actions([ ("GitInit", Gtk.STOCK_DND, _("Initialize"), None, _("Initialize a new repository."), self._git.init) ]) toolbar_ui_items = """ <toolitem name="GitInit" action="GitInit"/>""" # Insert the action group manager.insert_action_group(self._action_group, -1) toolbar_ui_str = self.toolbar_ui_open + toolbar_ui_items + self.toolbar_ui_close # Merge the UI self._ui_id = manager.add_ui_from_string(toolbar_ui_str)
def create_menu(self): action_group = Gtk.ActionGroup(name="context-menu") action = Gtk.Action(name="MateMenuPrefs", label=_("Preferences"), tooltip=None, icon_name="preferences-system") action.connect("activate", self.showPreferences) action_group.add_action(action) action = Gtk.Action(name="MateMenuEdit", label=_("Edit menu"), tooltip=None, stock_id=Gtk.STOCK_EDIT) action.connect("activate", self.showMenuEditor) action_group.add_action(action) action = Gtk.Action(name="MateMenuReload", label=_("Reload plugins"), tooltip=None, icon_name="view-refresh") action.connect("activate", self.mainwin.RegenPlugins) action_group.add_action(action) action = Gtk.Action(name="MateMenuAbout", label=_("About"), tooltip=None, icon_name="help-about") action.connect("activate", self.showAboutDialog) action_group.add_action(action) action_group.set_translation_domain("mate-menu") xml = os.path.join(self.data_path, "popup.xml") self.applet.setup_menu_from_file(xml, action_group)
def add_desktop_menu(self): action_group = Gtk.ActionGroup("menu_actions") action_filemenu = Gtk.Action("FileMenu", "File", None, None) action_group.add_action(action_filemenu) action_new = Gtk.Action("FileCapture", "_Capture", "Capture a pixel colour", Gtk.STOCK_NEW) action_new.connect("activate", self.grab) action_group.add_action_with_accel(action_new, None) action_filequit = Gtk.Action("FileQuit", None, None, Gtk.STOCK_QUIT) action_filequit.connect("activate", lambda a: self.app.quit()) action_group.add_action(action_filequit) action_group.add_actions([("HelpMenu", None, "Help"), ("HelpAbout", None, "About", None, None, self.show_about_dialog)]) uimanager = Gtk.UIManager() uimanager.add_ui_from_string(""" <ui> <menubar name='MenuBar'> <menu action='FileMenu'> <menuitem action='FileCapture' /> <menuitem action='FileQuit' /> </menu> <menu action='HelpMenu'> <menuitem action='HelpAbout' /> </menu> </menubar> </ui>""") accelgroup = uimanager.get_accel_group() self.w.add_accel_group(accelgroup) uimanager.insert_action_group(action_group) menubar = uimanager.get_widget("/MenuBar") box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) box.pack_start(menubar, False, False, 0) self.vb.pack_start(box, False, False, 0)
def do_activate(self): self.shell = self.object self.sp = self.shell.props.shell_player self.db = self.shell.get_property('db') self.file = "" self.basepath = 'file://' + os.path.split( rb.find_plugin_file(self, "AlbumArtSearch.py"))[0] self.load_templates() self.current_artist = None self.current_album = None self.current_song = None self.current_location = None self.visible = False self.mode = self.MODE_FOLDER self.init_gui() self.connect_signals() self.action = ('ToggleAlbumArtSearch', Gtk.STOCK_DND_MULTIPLE, _('Album Art'), None, _('Change the visibility of album art search pane'), self.toggle_visibility, False) self.action_group = Gtk.ActionGroup('AlbumArtSearchActions') self.action_group.add_toggle_actions([self.action]) uim = self.shell.props.ui_manager uim.insert_action_group(self.action_group, -1) self.ui_id = uim.add_ui_from_string(albumart_search_ui) uim.ensure_update()
def _add_sale_menus(self, sale_app): uimanager = sale_app.uimanager ui_string = """ <ui> <menubar name="menubar"> <placeholder name="ExtraMenubarPH"> <menu action="OpticalMenu"> <menuitem action="OpticalPreSale"/> <menuitem action="OpticalMedicSaleItems"/> <menuitem action="OpticalMedicSearch"/> </menu> </placeholder> </menubar> </ui> """ group = get_accels('plugin.optical') ag = Gtk.ActionGroup('OpticalSalesActions') ag.add_actions([ ('OpticalMenu', None, _(u'Optical')), ('OpticalPreSale', None, _(u'Sale with work order...'), group.get('pre_sale'), None, self._on_OpticalPreSale__activate), ('OpticalMedicSearch', None, _(u'Medics...'), group.get('search_medics'), None, self._on_MedicsSearch__activate), ('OpticalMedicSaleItems', None, _(u'Medics sold items...'), None, None, self._on_MedicSaleItems__activate), ]) uimanager.insert_action_group(ag, 0) self._app_ui[('sales', uimanager)] = uimanager.add_ui_from_string(ui_string)
def _build_popup_ui(self): """ Create actions and ui of context menu """ from ..plug.quick import create_quickreport_menu self.popupmanager = Gtk.UIManager() #add custom actions (ui_top, action_groups) = self._top_contextmenu() for action in action_groups : self.popupmanager.insert_action_group(action, -1) #see which quick reports are available now: ui_qr = '' if self.QR_CATEGORY > -1 : (ui_qr, reportactions) = create_quickreport_menu(self.QR_CATEGORY, self.dbstate, self.uistate, self.obj.get_handle()) self.report_action = Gtk.ActionGroup(name="/PersonReport") self.report_action.add_actions(reportactions) self.report_action.set_visible(True) self.popupmanager.insert_action_group(self.report_action, -1) popupui = ''' <ui> <popup name="Popup">''' + ui_top + ''' <separator/>''' + ui_qr + ''' </popup> </ui>''' self.popupmanager.add_ui_from_string(popupui)
def menu_compile(menu_name, menu_list): objs["ag"] = Gtk.ActionGroup("my_actions") for item in menu_list: menu_item = Gtk.MenuItem(item[0]) menu_item.connect("button-press-event", item[1]) objs[menu_name].append(menu_item) menu_item.show()
def on_tray_popup_menu(self, status_icon, button, activate_time): ''' Called when the user right-clicks the tray icon ''' tray_menu_xml = ''' <ui> <popup action="TrayMenu"> <menuitem action="Show"/> <menuitem action="Quit"/> </popup> </ui>''' # Create an ActionGroup actiongroup = Gtk.ActionGroup('TrayActionGroup') # Create actions actiongroup.add_actions([ ('Show', Gtk.STOCK_MEDIA_PLAY, _('Show RedNotebook'), None, None, lambda widget: self.show()), ('Quit', Gtk.STOCK_QUIT, None, None, None, self.on_quit_activate), ]) # Add the actiongroup to the uimanager self.uimanager.insert_action_group(actiongroup, 0) # Add a UI description self.uimanager.add_ui_from_string(tray_menu_xml) # Create a Menu menu = self.uimanager.get_widget('/TrayMenu') menu.popup(None, None, Gtk.status_icon_position_menu, button, activate_time, status_icon)
def __init__(self): Gtk.Window.__init__(self, title="Treeview Filter Demo") self.set_border_width(10) self.grid = Gtk.Grid() self.grid.set_column_homogeneous(True) self.grid.set_row_homogeneous(True) self.add(self.grid) self.create_model() tv = Gtk.TreeView(model=self.model) tv.set_rules_hint(True) tv.set_search_column(1) tv.columns_autosize() #tv.set_headers_clickable(False) tv.connect("button-press-event", self.on_button_press_event) self.grid.add(tv) self.add_columns(tv) self.treeview = tv action_group = Gtk.ActionGroup("my_actions") self.add_popup_actions(action_group) self.add_popup_title_actions(action_group) uimanager = self.create_ui_manager() uimanager.insert_action_group(action_group) self.popup = uimanager.get_widget("/PopupMenu") self.popuptitle = uimanager.get_widget("/PopupTitleMenu")
def get_gtk_actiongroup(obj): '''Return a C{Gtk.ActionGroup} for an object using L{Action} objects as attributes. Defines the attribute C{obj.actiongroup} if it does not yet exist. This method can only be used when gtk is available ''' from gi.repository import Gtk if hasattr(obj, 'actiongroup') \ and obj.actiongroup is not None: return obj.actiongroup obj.actiongroup = Gtk.ActionGroup(obj.__class__.__name__) for name, action in get_actions(obj): if isinstance(action, RadioAction): obj.actiongroup.add_radio_actions(action._entries) gaction = obj.actiongroup.get_action(action._entries[0][0]) gaction.connect('changed', action.do_changed, obj) if not obj in action._proxies: action._proxies[obj] = [] action._proxies[obj].append(gaction) if obj in action._state: key = action._state[obj] gtk_radioaction_set_current(gaction, key) else: _gtk_add_action_with_accel(obj, obj.actiongroup, action, action._attr, action._accel) if action._alt_accel: _gtk_add_action_with_accel(obj, obj.actiongroup, action, action._alt_attr, action._alt_accel) return obj.actiongroup
def define_actions(self): """ Required define_actions function for PageView. Builds the action group information required. We extend beyond the normal here, since we want to have more than one action group for the PersonView. Most PageViews really won't care about this. """ NavigationView.define_actions(self) self.edit_action = Gtk.ActionGroup(name=self.title + '/ChangeOrder') self.edit_action.add_actions([ ('Add', Gtk.STOCK_ADD, _("_Add..."), "<PRIMARY>Insert", self.ADD_MSG, self.add), ('Remove', Gtk.STOCK_REMOVE, _("_Remove"), "<PRIMARY>Delete", self.DEL_MSG, self.remove), ('Merge', 'gramps-merge', _('_Merge...'), None, self.MERGE_MSG, self.merge), ('ExportTab', None, _('Export View...'), None, None, self.export), ]) self._add_action_group(self.edit_action) self._add_action('Edit', Gtk.STOCK_EDIT, _("action|_Edit..."), accel="<PRIMARY>Return", tip=self.EDIT_MSG, callback=self.edit)
def view_changed(self, cat_num, view_num): """ Called when a Gramps view is changed. """ self.active_cat = cat_num self.active_view = view_num # Add buttons to the menu for the different view in the category uimanager = self.viewmanager.uimanager if self.cat_view_group: if self.cat_view_group in uimanager.get_action_groups(): uimanager.remove_action_group(self.cat_view_group) list(map(uimanager.remove_ui, self.merge_ids)) if cat_num in self.ui_category: self.cat_view_group = Gtk.ActionGroup(name='viewmenu') self.cat_view_group.add_radio_actions( self.view_toggle_actions[cat_num], value=view_num, on_change=self.cb_view_clicked, user_data=cat_num) self.cat_view_group.set_sensitive(True) uimanager.insert_action_group(self.cat_view_group, 1) mergeid = uimanager.add_ui_from_string(self.ui_category[cat_num]) self.merge_ids.append(mergeid) # Call the view_changed method for the active sidebar try: sidebar = self.pages[self.notebook.get_current_page()][1] except IndexError: return sidebar.view_changed(cat_num, view_num)
def setup_action_groups (self): self.actionGroup = Gtk.ActionGroup(name='RecipeEmailerActionGroup') self.actionGroup.add_actions([ ('EmailRecipes',None,_('Email recipes'), None,_('Email all selected recipes (or all recipes if no recipes are selected'),self.email_selected), ]) self.action_groups.append(self.actionGroup)
def create_menu(self): menu_file = "popup-without-edit.xml" action_group = Gtk.ActionGroup(name="context-menu") action = Gtk.Action(name="MintMenuPrefs", label=_("Preferences"), tooltip=None) action.connect("activate", self.showPreferences) action_group.add_action(action) if os.path.exists("/usr/bin/menulibre") or os.path.exists( "/usr/bin/mozo"): action = Gtk.Action(name="MintMenuEdit", label=_("Edit menu"), tooltip=None) action.connect("activate", self.showMenuEditor) action_group.add_action(action) menu_file = "popup.xml" action = Gtk.Action(name="MintMenuReload", label=_("Reload plugins"), tooltip=None) action.connect("activate", self.mainwin.RegenPlugins) action_group.add_action(action) action = Gtk.Action(name="MintMenuAbout", label=_("About"), tooltip=None) action.connect("activate", self.showAboutDialog) action_group.add_action(action) action_group.set_translation_domain("mintmenu") xml = os.path.join(os.path.join(os.path.dirname(__file__)), menu_file) self.applet.setup_menu_from_file(xml, action_group)
def _insert_menu(self): # Get the GtkUIManager manager = self.window.get_ui_manager() # Create a new action group self._action_group = Gtk.ActionGroup("XedTextSizePluginActions") self._action_group.add_actions([ ("LargerTextAction", None, _("_Larger Text"), "<Ctrl>equal", None, self.on_larger_text_activate), ("SmallerTextAction", None, _("S_maller Text"), "<Ctrl>minus", None, self.on_smaller_text_activate), ("NormalSizeAction", None, _("_Normal size"), "<Ctrl>0", None, self.on_normal_size_activate) ]) # Insert the action group manager.insert_action_group(self._action_group) self._ui_id = manager.new_merge_id() manager.add_ui(self._ui_id, MENU_PATH, "LargerTextAction", "LargerTextAction", Gtk.UIManagerItemType.MENUITEM, False) manager.add_ui(self._ui_id, MENU_PATH, "SmallerTextAction", "SmallerTextAction", Gtk.UIManagerItemType.MENUITEM, False) manager.add_ui(self._ui_id, MENU_PATH, "NormalSizeAction", "NormalSizeAction", Gtk.UIManagerItemType.MENUITEM, False)
def create_menu(self): action_group = Gtk.ActionGroup(name="context-menu") action = Gtk.Action(name="MintMenuPrefs", label=_("Preferences"), tooltip=None, stock_id="gtk-preferences") action.connect("activate", self.showPreferences) action_group.add_action(action) action = Gtk.Action(name="MintMenuEdit", label=_("Edit menu"), tooltip=None, stock_id="gtk-edit") action.connect("activate", self.showMenuEditor) action_group.add_action(action) action = Gtk.Action(name="MintMenuReload", label=_("Reload plugins"), tooltip=None, stock_id="gtk-refresh") action.connect("activate", self.mainwin.RegenPlugins) action_group.add_action(action) action = Gtk.Action(name="MintMenuAbout", label=_("About"), tooltip=None, stock_id="gtk-about") action.connect("activate", self.showAboutDialog) action_group.add_action(action) action_group.set_translation_domain("mintmenu") xml = os.path.join(os.path.join(os.path.dirname(__file__)), "popup.xml") self.applet.setup_menu_from_file(xml, action_group)
def create_menu_box(window, fileentry) -> Gtk.Box: """Create application menu from XML structure""" xmlmenustructure = """ <ui> <menubar name='MenuBar'> <menu action='FileMenu'> <menuitem action='open' /> <menuitem action='save' /> <!--<menuitem action='reload' />--> <menuitem action='quit' /> </menu> <menu action='LanguageMenu'> <menuitem name="en_EN" action='en_EN' /> <menuitem name="de_DE" action='de_DE' /> <menuitem name="ru_RU" action='ru_RU' /> <menuitem name="id_ID" action='id_ID' /> </menu> </menubar> </ui> """ uimanager = Gtk.UIManager() uimanager.add_ui_from_string(xmlmenustructure) actiongroup = Gtk.ActionGroup("actions") add_menu_actions(window, fileentry, actiongroup) uimanager.insert_action_group(actiongroup) menubar = uimanager.get_widget("/MenuBar") menubox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) menubox.pack_start(menubar, False, False, 0) return menubox
def get_actiongroup(self): actions = [('insert_' + obj.name, obj.verb_icon, obj.label, '', None, self._action_handler) for obj in self.insertedobjects.values()] group = Gtk.ActionGroup('inserted_objects') group.add_actions(actions) return group
def _add_services_menus(self, services_app): uimanager = services_app.uimanager ui_string = """ <ui> <menubar name="menubar"> <placeholder name="AppMenubarPH"> <menu action="OrderMenu"> <separator/> <menuitem action="OpticalDetails"/> </menu> </placeholder> </menubar> <popup name="ServicesSelection"> <placeholder name="ServicesSelectionPH"> <separator/> <menuitem action="OpticalDetails"/> </placeholder> </popup> </ui> """ ag = Gtk.ActionGroup('OpticalServicesActions') ag.add_actions([ ('OpticalDetails', None, _(u'Edit optical details...'), None, None, self._on_OpticalDetails__activate), ]) uimanager.insert_action_group(ag, 0) self._app_ui[('services', uimanager)] = uimanager.add_ui_from_string(ui_string) services_app.search.connect( 'result-selection-changed', self._on_ServicesApp__result_selection_changed, uimanager)
def _get_context_menu(self): context_menu_xml = """ <ui> <popup action="ContextMenu"> <menuitem action="ChangeEntry"/> <menuitem action="AddEntry"/> <menuitem action="Delete"/> </popup> </ui>""" uimanager = self.main_window.uimanager # Create an ActionGroup actiongroup = Gtk.ActionGroup('ContextMenuActionGroup') # Create actions actiongroup.add_actions([ ('ChangeEntry', Gtk.STOCK_EDIT, _('Change this text'), None, None, self._on_change_entry_clicked), ('AddEntry', None, _('Add a new entry'), None, None, self._on_add_entry_clicked), ('Delete', Gtk.STOCK_DELETE, _('Delete this entry'), None, None, self._on_delete_entry_clicked), ]) # Add the actiongroup to the uimanager uimanager.insert_action_group(actiongroup, 0) # Add a UI description uimanager.add_ui_from_string(context_menu_xml) # Create a Menu menu = uimanager.get_widget('/ContextMenu') return menu
def do_activate(self): ## TODO : Maybe have to check the filetype ? # Store data in the window object windowdata = dict() self.window.reStPreviewData = windowdata scrolled_window = Gtk.ScrolledWindow() scrolled_window.set_property("hscrollbar-policy", Gtk.PolicyType.AUTOMATIC) scrolled_window.set_property("vscrollbar-policy", Gtk.PolicyType.AUTOMATIC) scrolled_window.set_property("shadow-type", Gtk.ShadowType.IN) html_view = WebKit.WebView() html_view.load_string("%s\n<p>reStructuredText Viewer</p>\n%s" % (START_HTML, END_HTML), 'text/html', 'utf8', '') #scrolled_window.set_hadjustment(html_view.get_hadjustment()) #scrolled_window.set_vadjustment(html_view.get_vadjustment()) scrolled_window.add(html_view) scrolled_window.show_all() bottom = self.window.get_bottom_panel() image = Gtk.Image() image.set_from_icon_name("gnome-mime-text-html", Gtk.IconSize.MENU) bottom.add_item(scrolled_window, "rest-preview", "reStructuredText Preview", image) windowdata["bottom_panel"] = scrolled_window windowdata["html_doc"] = html_view manager = self.window.get_ui_manager() ## Added later self._action_group = Gtk.ActionGroup("reStPluginActions") self._action_group.add_actions([("preview", None, _("reStructuredText Preview"), "<Control><Shift>R", _("reStructuredText Preview"), self.on_update_preview), ("table", None, _("Create table"), None, _("Create a reStructuredText table"), self.on_create_table), ("sourcecode", None, _("Paste Code"), None, _("Paste source code"), self.on_paste_code), ("--> HTML", None, _("--> HTML"), None, _("Save as HTML document"), self.on_html), ("--> LaTeX", None, _("--> LaTeX"), None, _("Save as LaTeX document"), self.on_latex), ("--> LibreOffice", None, _("--> LibreOffice"), None, _("Save as LibreOffice ODF"), self.on_libreoffice), ]) # Insert the action group manager.insert_action_group(self._action_group, -1) # Merge the UI self._ui_id = manager.add_ui_from_string(ui_str)
def insert_menu_item(self, window): manager = self.window.get_ui_manager() self.action_group = Gtk.ActionGroup("PluginActions") # Create an action for the "Run in python" menu option # and set it to call the "run_document_in_python" function. action_toggle = Gtk.Action( name="ToggleSplitView", label="Toggle Split View", tooltip="Create a split view of the current document", stock_id=Gtk.STOCK_DND_MULTIPLE) action_toggle.connect("activate", self.toggle) # Add the action with Ctrl + F5 as its keyboard shortcut. self.action_group.add_action_with_accel(action_toggle, "<Ctrl><Shift>T") # Add the action for toggling the orientation self.action_group.add_action(self.action_toggle_orientation) # Add the action group. manager.insert_action_group(self.action_group, -1) # Add the item to the "Views" menu. self.ui_id = manager.add_ui_from_string(ui_string)
def __init__(self, uistate, state, fileopen): self.action_group = Gtk.ActionGroup(name='RecentFiles') self.active = DISABLED self.uistate = uistate self.uimanager = uistate.uimanager self.fileopen = fileopen self.state = state
def do_activate(self): data = dict() shell = self.object manager = shell.props.ui_manager data['action_group'] = Gtk.ActionGroup( name='PythonConsolePluginActions') action = Gtk.Action(name='PythonConsole', label=_("_Python Console"), tooltip=_("Show Rhythmbox's python console"), stock_id='gnome-mime-text-x-python') action.connect('activate', self.show_console, shell) data['action_group'].add_action(action) action = Gtk.Action( name='PythonDebugger', label=_("Python Debugger"), tooltip=_("Enable remote python debugging with rpdb2"), stock_id=None) if have_rpdb2: action.connect('activate', self.enable_debugging, shell) else: action.set_visible(False) data['action_group'].add_action(action) manager.insert_action_group(data['action_group'], 0) data['ui_id'] = manager.add_ui_from_string(ui_str) manager.ensure_update() shell.set_data('PythonConsolePluginInfo', data)
def get_gtk_actiongroup(obj): '''Return a C{Gtk.ActionGroup} for an object using L{Action} objects as attributes. Defines the attribute C{obj.actiongroup} if it does not yet exist. This method can only be used when gtk is available ''' assert Gtk is not None if hasattr(obj, 'actiongroup') \ and obj.actiongroup is not None: return obj.actiongroup obj.actiongroup = Gtk.ActionGroup(obj.__class__.__name__) for name, action in get_actions(obj): if isinstance(action, RadioActionMethod): obj.actiongroup.add_radio_actions(action._entries) gtkaction = obj.actiongroup.get_action(action._entries[0][0]) action._connect_gtkaction(gtkaction) else: _gtk_add_action_with_accel(obj, obj.actiongroup, action, action._attr, action._accel) if action._alt_accel: _gtk_add_action_with_accel(obj, obj.actiongroup, action, action._alt_attr, action._alt_accel) return obj.actiongroup
def do_activate(self): ui_manager = self.window.get_ui_manager() self.action_group = Gtk.ActionGroup(name='PythonConsole') self.action_group.add_actions([('PythonConsole', None, \ _('P_ython Console'), None, None, self.console_cb)], self.window) ui_manager.insert_action_group(self.action_group, 0) self.ui_id = ui_manager.add_ui_from_string(_UI_STR)
def __init__(self): Gtk.Window.__init__(self, title='genxword-gtk') self.set_default_size(650, 600) self.set_default_icon_name('genxword-gtk') self.saveformat = '' self.mixwords = False self.gsize = False self.default_lang = _('Across/Down').split('/') self.grid = Gtk.Grid() self.add(self.grid) self.grid.set_border_width(6) self.grid.set_row_spacing(6) self.grid.set_column_spacing(6) action_group = Gtk.ActionGroup('gui_actions') self.add_actions(action_group) uimanager = self.create_ui_manager() uimanager.insert_action_group(action_group) menubar = uimanager.get_widget('/MenuBar') self.grid.attach(menubar, 0, 0, 6, 1) toolbar = uimanager.get_widget('/ToolBar') self.grid.attach(toolbar, 0, 1, 6, 1) self.notebk() self.save_buttons() self.option_buttons() self.list_clickable_buttons(uimanager) self.set_sensitivities(True)
def _insert_ui_items(self): # Get the GtkUIManager self._manager = self._window.get_ui_manager() # Create a new action group self._action_group = Gtk.ActionGroup("PluginActions") ## LEFT IN AS AN EXAMPLE: ## Create a toggle action (the classic way) ... #self._toggle_linebreak_action = Gtk.ToggleAction(name="ToggleTextWrap", label="Text Wrap", tooltip="Toggle Current Text Wrap Setting", stock_id=Gtk.STOCK_EXECUTE) #self._toggle_linebreak_action = Gtk.ToggleAction(name="ToggleTextWrap", label="Text Wrap", tooltip="Toggle Current Text Wrap Setting", file="gtk-execute.png") ## connect my callback function to the action ... #self._toggle_linebreak_action.connect("activate", self.on_toggle_linebreak) ## and add the action with Ctrl+Shift+L as its keyboard shortcut #self._action_group.add_action_with_accel(self._toggle_linebreak_action, "<Ctrl><Shift>B") ## END OF EXAMPLE CODE # Create a toggle action (convenience way: see 16.1.2.2. in PyGTK Manual) #Gtk.STOCK_INSERT_CROSS_REFERENCE #Gtk.STOCK_INSERT-CROSS-REFERENCE #Gtk.STOCK_INSERT_FOOTNOTE #None self._action_group.add_toggle_actions([ ("ToggleTextWrap", Gtk.STOCK_OK, _("Text Wrap"), "<Ctrl><Shift>B", _("Toggle Current Text Wrap Setting"), self.on_toggle_linebreak, self._initial_toggle_state) ]) # Insert the action group self._manager.insert_action_group(self._action_group, -1) # Add my item to the "Views" menu and to the Toolbar self._ui_id = self._manager.add_ui_from_string(ui_str) # Debug merged ui if self._DEBUG: print(self._manager.get_ui())