当前位置: 首页>>代码示例>>Python>>正文


Python Gtk.ActionGroup方法代码示例

本文整理汇总了Python中gi.repository.Gtk.ActionGroup方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.ActionGroup方法的具体用法?Python Gtk.ActionGroup怎么用?Python Gtk.ActionGroup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gi.repository.Gtk的用法示例。


在下文中一共展示了Gtk.ActionGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def __init__(self, shell, group_name):
        """
        constructor
        :param shell: `RBShell`
        :param group_name: `str` unique name for the object to create
        """
        self.group_name = group_name
        self.shell = shell

        self._actions = {}

        if is_rb3(self.shell):
            self.actiongroup = Gio.SimpleActionGroup()
        else:
            self.actiongroup = Gtk.ActionGroup(group_name)
            uim = self.shell.props.ui_manager
            uim.insert_action_group(self.actiongroup) 
开发者ID:fossfreedom,项目名称:alternative-toolbar,代码行数:19,代码来源:alttoolbar_rb3compat.py

示例2: get_actiongroup

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def get_actiongroup(self):
		actions = []
		for tool in self._manager:
			icon = tool.icon
			if '/' in icon or '\\' in icon:
				# Assume icon is a file path - need to add it in order to make it loadable
				icon = 'zim-custom-tool' + tool.key
				try:
					pixbuf = tool.get_pixbuf(Gtk.IconSize.LARGE_TOOLBAR)
					self._iconfactory.add(icon, Gtk.IconSet(pixbuf=pixbuf))
				except Exception:
					logger.exception('Got exception while loading application icons')
					icon = None

			actions.append(
				(tool.key, icon, tool.name, '', tool.comment, self._action_handler)
			)

		group = Gtk.ActionGroup('custom_tools')
		group.add_actions(actions)
		return group 
开发者ID:zim-desktop-wiki,项目名称:zim-desktop-wiki,代码行数:23,代码来源:customtools.py

示例3: init

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def init(self):
        """
        Constructs the GUI, consisting of a text area, and
        an Import and Clear buttons.
        """
        from gi.repository import Gtk
        # GUI setup:
        self.set_tooltip(_("Enter text to import and then click\n"
                           "the Import button at bottom"))
        # create
        self.import_text = Gtk.TextView()
        self.import_text.set_wrap_mode(Gtk.WrapMode.NONE)
        self.import_text.set_editable(True)
        import_button = Gtk.Button()
        clear_button = Gtk.Button()
        # layout
        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.add(self.import_text)
        buttonbox = Gtk.HButtonBox()
        buttonbox.set_layout(Gtk.ButtonBoxStyle.SPREAD)
        buttonbox.pack_start(clear_button, False, False, 0)
        buttonbox.pack_start(import_button, False, False, 0)
        vbox = Gtk.VBox()
        vbox.pack_start(scrolled_window, True, True, 0)
        vbox.pack_start(buttonbox, False, False, 0)
        scrolled_window = self.gui.get_container_widget()
        for widget in scrolled_window.get_children():
            widget.destroy()
        scrolled_window.add_with_viewport(vbox)
        scrolled_window.get_children()[0].set_shadow_type(Gtk.ShadowType.NONE)
        # bindings
        actiongroup = Gtk.ActionGroup('GrampletImportActions')
        actiongroup.add_actions([
            ('import', None, _("_Import"), '<Alt>i', None, self.run),
            ('clear', Gtk.STOCK_CLEAR, None, None, None, self.clear)])
        import_button.set_related_action(actiongroup.get_action('import'))
        clear_button.set_related_action(actiongroup.get_action('clear'))
        # show
        vbox.show_all() 
开发者ID:gramps-project,项目名称:addons-source,代码行数:41,代码来源:ImportGramplet.py

示例4: _define_actions_fw_bw

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def _define_actions_fw_bw(self):
        """
        prepare the forward and backward buttons.
        add the Backward action to handle the Backward button
        accel doesn't work in webkit and gtkmozembed !
        we must do that ...
        """
        self.back_action = Gtk.ActionGroup(name=self.title + '/Back')
        self.back_action.add_actions([
            ('Back', Gtk.STOCK_GO_BACK, _("_Back"),
             "<ALT>Left", _("Go to the previous page in the history"),
             self.go_back)
            ])
        self._add_action_group(self.back_action)
        # add the Forward action to handle the Forward button
        self.forward_action = Gtk.ActionGroup(name=self.title + '/Forward')
        self.forward_action.add_actions([
            ('Forward', Gtk.STOCK_GO_FORWARD, _("_Forward"),
             "<ALT>Right", _("Go to the next page in the history"),
             self.go_forward)
            ])
        self._add_action_group(self.forward_action)
        # add the Refresh action to handle the Refresh button
        self._add_action('Refresh', Gtk.STOCK_REFRESH, _("_Refresh"),
                          callback=self.refresh,
                          accel="<Ctl>R",
                          tip=_("Stop and reload the page.")) 
开发者ID:gramps-project,项目名称:addons-source,代码行数:29,代码来源:htmlview.py

示例5: remove_actions

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def remove_actions(self):
        """
        utility function to remove all actions associated with the ActionGroup
        """
        for action in self.actiongroup.list_actions():
            self.actiongroup.remove_action(action) 
开发者ID:fossfreedom,项目名称:alternative-toolbar,代码行数:8,代码来源:alttoolbar_rb3compat.py

示例6: get_action

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def get_action(self, action_name):
        """
        utility function to obtain the Action from the ActionGroup

        :param action_name: `str` is the Action unique name
        """
        return self._actions[action_name] 
开发者ID:fossfreedom,项目名称:alternative-toolbar,代码行数:9,代码来源:alttoolbar_rb3compat.py

示例7: add_action_with_accel

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def add_action_with_accel(self, func, action_name, accel, **args):
        """
        Creates an Action with an accelerator and adds it to the ActionGroup

        :param func: function callback used when user activates the action
        :param action_name: `str` unique name to associate with an action
        :param accel: `str` accelerator
        :param args: dict of arguments - this is passed to the function
        callback

        Notes:
        see notes for add_action
        """
        args['accel'] = accel
        return self.add_action(func, action_name, **args) 
开发者ID:fossfreedom,项目名称:alternative-toolbar,代码行数:17,代码来源:alttoolbar_rb3compat.py

示例8: insert_action_group

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def insert_action_group(self, action_group):
            """
            Adds an ActionGroup to the ApplicationShell

            :param action_group: `ActionGroup` to add
            """
            self._action_groups[action_group.name] = action_group 
开发者ID:fossfreedom,项目名称:alternative-toolbar,代码行数:9,代码来源:alttoolbar_rb3compat.py

示例9: __init__

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def __init__(self):
        GObject.GObject.__init__(self)

        # XDotWidget
        xdotwidget = self.xdotwidget = xdot.DotWidget()
        # Toolbar
        uimanager = Gtk.UIManager()
        actiongroup = Gtk.ActionGroup('Actions')
        actiongroup.add_actions((
            ('ZoomIn', Gtk.STOCK_ZOOM_IN, None, None, None, self.xdotwidget.on_zoom_in),
            ('ZoomOut', Gtk.STOCK_ZOOM_OUT, None, None, None, self.xdotwidget.on_zoom_out),
            ('ZoomFit', Gtk.STOCK_ZOOM_FIT, None, None, None, self.xdotwidget.on_zoom_fit),
            ('Zoom100', Gtk.STOCK_ZOOM_100, None, None, None, self.xdotwidget.on_zoom_100),
        ))
        uimanager.insert_action_group(actiongroup, 0)
        uimanager.add_ui_from_string(self.ui)
        toolbar = uimanager.get_widget('/ToolBar')
        toolbar.set_icon_size(Gtk.IconSize.SMALL_TOOLBAR)
        toolbar.set_style(Gtk.ToolbarStyle.ICONS)
        toolbar.set_show_arrow(False)
        label = self.label = Gtk.Label()
        hbox = Gtk.HBox(False, 5)
        hbox.pack_start(toolbar, False, True, 0)
        hbox.pack_start(label, False, True, 0)
        self.pack_start(hbox, False, True, 0)
        self.pack_start(xdotwidget, True, True, 0) 
开发者ID:inguma,项目名称:bokken,代码行数:28,代码来源:bindiff.py

示例10: get_gtk_actiongroup

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
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 
开发者ID:zim-desktop-wiki,项目名称:zim-desktop-wiki,代码行数:35,代码来源:actions.py

示例11: get_actiongroup

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
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 
开发者ID:zim-desktop-wiki,项目名称:zim-desktop-wiki,代码行数:10,代码来源:insertedobjects.py

示例12: on_tray_popup_menu

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
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, None, None, button, activate_time) 
开发者ID:jendrikseipp,项目名称:rednotebook,代码行数:43,代码来源:main_window.py

示例13: add_app_menuitems

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def add_app_menuitems(self, ui_string, group_name, menu='tools'):
            """
            utility function to add application menu items.

            For RB2.99 all application menu items are added to the "tools"
            section of the application menu. All Actions are assumed to be of
            action_type "app".

            For RB2.98 or less, it is added however the UI_MANAGER string
            is defined.

            :param ui_string: `str` is the Gtk UI definition.  There is not an
            equivalent UI definition in RB2.99 but we can parse out menu items
            since this string is in XML format

            :param group_name: `str` unique name of the ActionGroup to add menu
            items to
            :param menu: `str` RB2.99 menu section to add to - nominally either
              'tools' or 'view'
            """
            if is_rb3(self.shell):
                root = ET.fromstring(ui_string)
                for elem in root.findall(".//menuitem"):
                    action_name = elem.attrib['action']

                    group = self._action_groups[group_name]
                    act = group.get_action(action_name)

                    item = Gio.MenuItem()
                    item.set_detailed_action('app.' + action_name)
                    item.set_label(act.label)
                    item.set_attribute_value("accel", GLib.Variant("s",
                                                                   act.accel))
                    app = Gio.Application.get_default()
                    index = menu + action_name
                    app.add_plugin_menu_item(menu,
                                             index, item)
                    self._uids[index] = menu
            else:
                uim = self.shell.props.ui_manager
                self._uids.append(uim.add_ui_from_string(ui_string))
                uim.ensure_update() 
开发者ID:fossfreedom,项目名称:alternative-toolbar,代码行数:44,代码来源:alttoolbar_rb3compat.py

示例14: add_browser_menuitems

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
def add_browser_menuitems(self, ui_string, group_name):
            """
            utility function to add popup menu items to existing browser popups

            For RB2.99 all menu items are are assumed to be of action_type
            "win".

            For RB2.98 or less, it is added however the UI_MANAGER string
            is defined.

            :param ui_string: `str` is the Gtk UI definition.  There is not an
            equivalent UI definition in RB2.99 but we can parse out menu items
            since this string is in XML format

            :param group_name: `str` unique name of the ActionGroup to add menu
            items to
            """
            if is_rb3(self.shell):
                root = ET.fromstring(ui_string)
                for elem in root.findall("./popup"):
                    popup_name = elem.attrib['name']

                    menuelem = elem.find('.//menuitem')
                    action_name = menuelem.attrib['action']

                    group = self._action_groups[group_name]
                    act = group.get_action(action_name)

                    item = Gio.MenuItem()
                    item.set_detailed_action('win.' + action_name)
                    item.set_label(act.label)
                    app = Gio.Application.get_default()

                    if popup_name == 'QueuePlaylistViewPopup':
                        plugin_type = 'queue-popup'
                    elif popup_name == 'BrowserSourceViewPopup':
                        plugin_type = 'browser-popup'
                    elif popup_name == 'PlaylistViewPopup':
                        plugin_type = 'playlist-popup'
                    elif popup_name == 'PodcastViewPopup':
                        plugin_type = 'podcast-episode-popup'
                    else:
                        print("unknown type %s" % plugin_type)

                    index = plugin_type + action_name
                    app.add_plugin_menu_item(plugin_type, index, item)
                    self._uids[index] = plugin_type
            else:
                uim = self.shell.props.ui_manager
                self._uids.append(uim.add_ui_from_string(ui_string))
                uim.ensure_update() 
开发者ID:fossfreedom,项目名称:alternative-toolbar,代码行数:53,代码来源:alttoolbar_rb3compat.py

示例15: _get_context_menu

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ActionGroup [as 别名]
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 
开发者ID:jendrikseipp,项目名称:rednotebook,代码行数:56,代码来源:categories.py


注:本文中的gi.repository.Gtk.ActionGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。