我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用gtk.Action()。
def update_recent_files(self): i = 0 for fname in self._get_recent_list(): action_name = "recent%i" % i path = "/MenuBar/file/recent" old_action = self.menu_ag.get_action(action_name) if old_action: self.menu_ag.remove_action(old_action) file_basename = os.path.basename(fname).replace("_", "__") action = gtk.Action( action_name, "_%i. %s" % (i + 1, file_basename), _("Open recent file {name}").format(name=fname), "") action.connect("activate", lambda a, f: self.do_open(f), fname) mid = self.menu_uim.new_merge_id() self.menu_uim.add_ui(mid, path, action_name, action_name, gtk.UI_MANAGER_MENUITEM, False) self.menu_ag.add_action(action) i += 1
def setup_extra_hotkeys(self): accelg = self.menu_uim.get_accel_group() def memedit(a): self.get_current_editorset().editors["memedit"].hotkey(a) actions = [ # ("action_name", "key", function) ] for name, key, fn in actions: a = gtk.Action(name, name, name, "") a.connect("activate", fn) self.menu_ag.add_action_with_accel(a, key) a.set_accel_group(accelg) a.connect_accelerator()
def _add_stock_action(self, name, label=None, tooltip=None, stock=None): act = gtk.Action(name, label, tooltip, stock) self.action_group.add_action_with_accel(act, None) act.set_accel_group(self.accel_group) act.connect_accelerator() self.actions[name] = act # _add_stock_action()
def __init__(self, *args, **kw): gtk.Action.__init__(self, *args, **kw) self.set_tool_item_type(gtk.ToolItem)
def update_stock_configs(self): stock_dir = platform.get_platform().config_file("stock_configs") if not os.path.isdir(stock_dir): try: os.mkdir(stock_dir) except Exception, e: LOG.error("Unable to create directory: %s" % stock_dir) return if not self.copy_shipped_stock_configs(stock_dir): return def _do_import_action(config): name = os.path.splitext(os.path.basename(config))[0] action_name = "stock-%i" % configs.index(config) path = "/MenuBar/radio/stock" action = gtk.Action(action_name, name, _("Import stock " "configuration {name}").format(name=name), "") action.connect("activate", self.import_stock_config, config) mid = self.menu_uim.new_merge_id() mid = self.menu_uim.add_ui(mid, path, action_name, action_name, gtk.UI_MANAGER_MENUITEM, False) self.menu_ag.add_action(action) def _do_open_action(config): name = os.path.splitext(os.path.basename(config))[0] action_name = "openstock-%i" % configs.index(config) path = "/MenuBar/file/openstock" action = gtk.Action(action_name, name, _("Open stock " "configuration {name}").format(name=name), "") action.connect("activate", lambda a, c: self.do_open(c), config) mid = self.menu_uim.new_merge_id() mid = self.menu_uim.add_ui(mid, path, action_name, action_name, gtk.UI_MANAGER_MENUITEM, False) self.menu_ag.add_action(action) configs = glob(os.path.join(stock_dir, "*.csv")) for config in configs: _do_import_action(config) _do_open_action(config)