本文整理汇总了Python中gi.repository.Gtk.accelerator_parse方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.accelerator_parse方法的具体用法?Python Gtk.accelerator_parse怎么用?Python Gtk.accelerator_parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.accelerator_parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __set_callbacks
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def __set_callbacks(self):
"""Define the widget callbacks"""
# Set the callbacks
self.ti_bt.connect('clicked', self.on_ti_bt_clicked)
self.tis_selection_changed_hid = \
self.tag_icon_selector.connect('selection-changed', self.on_tis_selection_changed)
self.tn_entry_clicked_hid = \
self.tn_entry.connect('changed', self.on_tn_entry_changed)
self.tn_cb_clicked_hid = \
self.tn_cb.connect('clicked', self.on_tn_cb_clicked)
# FIXME
self.tc_cc_colsel.connect('color-changed', self.on_tc_colsel_changed)
self.tc_cc_colsel.connect('color-added', self.on_tc_colsel_added)
# self.tc_cc_colsel.connect('color-activated',
# self.on_tc_colsel_activated)
self.connect('delete-event', self.on_close)
# allow fast closing by Escape key
agr = Gtk.AccelGroup()
self.add_accel_group(agr)
key, modifier = Gtk.accelerator_parse('Escape')
agr.connect(key, modifier, Gtk.AccelFlags.VISIBLE, self.on_close)
示例2: _setup_accels
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def _setup_accels(self):
"""Setup accels."""
self._accels = Gtk.AccelGroup()
self.add_accel_group(self._accels)
key, mod = Gtk.accelerator_parse("Escape")
self._accels.connect(key, mod, Gtk.AccelFlags.VISIBLE,
self._close_window)
key, mod = Gtk.accelerator_parse("Return")
self._accels.connect(key, mod, Gtk.AccelFlags.VISIBLE,
self._do_select)
key, mod = Gtk.accelerator_parse("<Control>F")
self._accels.connect(key, mod, Gtk.AccelFlags.VISIBLE,
self._toggle_search)
示例3: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def __init__(config):
super(Config, config).__init__()
# populate values first from the default config file, then from the proper one
config.read(util.get_default_config())
config.load_window_layouts()
all_commands = dict(config.items('shortcuts')).keys()
config.read(config.path_to_config(True))
config.upgrade()
config.load_window_layouts()
for command in all_commands:
parsed = {Gtk.accelerator_parse(l) for l in config.get('shortcuts', command).split()}
if (0, 0) in parsed:
logger.warning('Failed parsing 1 or more shortcuts for ' + command)
parsed.remove((0, 0))
config.shortcuts.update({s: command for s in parsed})
示例4: set_shortcuts
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def set_shortcuts(self):
"""
This method actually is not responsible for the Ctrl-C etc. actions
"""
self.accel_group = self.builder.get_object("accelgroup1")
self.main_frame.add_accel_group(self.accel_group)
self.main_frame.connect("key-press-event", self._on_key_press_event)
shortcuts = [
(self.back_one_day_button, "clicked", "<Ctrl>Page_Up"),
(self.today_button, "clicked", "<Alt>Home"),
(self.forward_one_day_button, "clicked", "<Ctrl>Page_Down"),
]
for button, signal, shortcut in shortcuts:
(keyval, mod) = Gtk.accelerator_parse(shortcut)
button.add_accelerator(
signal, self.accel_group, keyval, mod, Gtk.AccelFlags.VISIBLE
)
示例5: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def __init__(self, text, title="Epoptes", markup=True,
icon_name="dialog-information"):
super().__init__(title=title, icon_name=icon_name)
self.set_position(Gtk.WindowPosition.CENTER)
grid = Gtk.Grid(column_spacing=10, row_spacing=10, margin=10)
self.add(grid)
image = Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.DIALOG)
grid.add(image)
# Always load the plain text first in case the markup parsing fails
label = Gtk.Label(
label=text, selectable=True, hexpand=True, vexpand=True,
halign=Gtk.Align.START, valign=Gtk.Align.START)
if markup:
label.set_markup(text)
grid.add(label)
button = Gtk.Button.new_from_stock(Gtk.STOCK_CLOSE)
button.set_hexpand(False)
button.set_halign(Gtk.Align.END)
button.connect("clicked", Gtk.main_quit)
grid.attach(button, 1, 1, 2, 1)
self.set_focus_child(button)
accelgroup = Gtk.AccelGroup()
key, modifier = Gtk.accelerator_parse('Escape')
accelgroup.connect(
key, modifier, Gtk.AccelFlags.VISIBLE, Gtk.main_quit)
self.add_accel_group(accelgroup)
示例6: _create_accel_group
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def _create_accel_group(self):
self._accel_group = Gtk.AccelGroup()
shortcut = self._gsettings.get_string(GSETTINGS_KEYBINDINGS)
key, mod = Gtk.accelerator_parse(shortcut)
self._accel_group.connect(key, mod, Gtk.AccelFlags.VISIBLE,
self._open_terminal)
示例7: create_menu_item
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def create_menu_item(label_text="", icon_code=constants.BUTTON_COPY, callback=None, callback_args=(),
accel_code=None, accel_group=None):
menu_item = Gtk.MenuItem()
menu_item.set_label(label_text)
set_icon_and_text_box_of_menu_item(menu_item, icon_code)
if callback is not None:
menu_item.connect("activate", callback, *callback_args)
if accel_code is not None and accel_group is not None:
key, mod = Gtk.accelerator_parse(accel_code)
menu_item.add_accelerator("activate", accel_group, key, mod, Gtk.AccelFlags.VISIBLE)
return menu_item
示例8: is_event_of_key_string
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def is_event_of_key_string(event, key_string):
"""Condition check if key string represent the key value of handed event and whether the event is of right type
The function checks for constructed event tuple that are generated by the rafcon.gui.shortcut_manager.ShortcutManager.
:param tuple event: Event tuple generated by the ShortcutManager
:param str key_string: Key string parsed to a key value and for condition check
"""
return len(event) >= 2 and not isinstance(event[1], Gdk.ModifierType) and event[0] == Gtk.accelerator_parse(key_string)[0]
示例9: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def __init__(self, top_window):
View.__init__(self)
self.win = top_window['main_window']
self.insert_accelerators = {'new': Gtk.accelerator_parse('<control>N'),
'open': Gtk.accelerator_parse('<control>O'),
'save': Gtk.accelerator_parse('<control>S'),
# 'save_as': Gtk.accelerator_parse('<shift><control>S'), # no default accelerator insert
'quit': Gtk.accelerator_parse('<control>Q'),
'cut': Gtk.accelerator_parse('<control>X'),
'copy': Gtk.accelerator_parse('<control>C'),
'paste': Gtk.accelerator_parse('<control>V'),
# 'delete': Gtk.accelerator_parse('Delete'), # no default accelerator insert
# 'undo': Gtk.accelerator_parse('<control>Z'), # no default accelerator insert
# 'redo': Gtk.accelerator_parse('<control>Y'), # no default accelerator insert
}
self.sub_menu_open_recently = Gtk.Menu()
self['open_recent'].set_submenu(self.sub_menu_open_recently)
# Gtk TODO: Unfortunately does not help against not showing Accel Keys
# self.win.add_accel_group(self['accelgroup1'])
for menu_item_name in self.buttons:
# set icon
self.set_menu_item_icon(menu_item_name, self.buttons[menu_item_name])
# set accelerator if in shortcuts dictionary with menu_item_name == key
if menu_item_name in global_gui_config.get_config_value('SHORTCUTS'):
shortcuts = global_gui_config.get_config_value('SHORTCUTS')[menu_item_name]
if shortcuts:
main_shortcut = shortcuts[0] if isinstance(shortcuts, list) else shortcuts
self.set_menu_item_accelerator(menu_item_name, main_shortcut)
for sub_menu_name in self.sub_menus:
sub_menu = self[sub_menu_name]
sub_menu.set_reserve_toggle_size(False)
示例10: set_menu_item_accelerator
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def set_menu_item_accelerator(self, menu_item_name, accel_code, remove_old=False):
menu_item = self[menu_item_name]
# the accelerator group is not defined any more in the glade file
if remove_old:
if menu_item_name in self.insert_accelerators:
key, mod = self.insert_accelerators[menu_item_name]
menu_item.remove_accelerator(self['accelgroup1'], key, mod)
key, mod = Gtk.accelerator_parse(accel_code)
menu_item.add_accelerator("activate", self['accelgroup1'], key, mod, Gtk.AccelFlags.VISIBLE)
self.insert_accelerators[menu_item_name] = (key, mod)
示例11: register_shortcuts
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def register_shortcuts(self):
for action in self.__action_to_shortcuts:
# Make sure, all shortcuts are in a list
shortcuts = self.__action_to_shortcuts[action]
if not isinstance(shortcuts, list):
shortcuts = [shortcuts]
self.__action_to_shortcuts[action] = shortcuts
# Now register the shortcuts in the window to trigger the shortcut signal
for shortcut in shortcuts:
keyval, modifier_mask = Gtk.accelerator_parse(shortcut)
if keyval == 0 and modifier_mask == 0: # No valid shortcut
logger.warning("No valid shortcut for shortcut %s" % str(shortcut))
continue
callback = partial(self.__on_shortcut, action) # Bind the action to the callback function
self.accel_group.connect(keyval, modifier_mask, Gtk.AccelFlags.VISIBLE, callback)
示例12: _action_tooltip
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def _action_tooltip(self, action, tooltip):
action_id = action.get_id()
accels = self.get_application().get_accels_for_action(action_id)
if accels:
key, mods = Gtk.accelerator_parse(accels[0])
tooltip += ' ({})'.format(Gtk.accelerator_get_label(key, mods))
return tooltip
示例13: do_activate
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def do_activate(self):
self.connection_manager = ConnectionManager(self)
self.config = config.load()
self.config.connect('notify::ui-dark-theme', self.on_use_dark_theme)
self.on_use_dark_theme()
self.action_groups = {}
accel_group = Gtk.AccelGroup()
commands = self.config.get_commands()
for group_key in commands:
group = Gio.SimpleActionGroup()
self.action_groups[group_key] = group
data = commands[group_key]
for action_key in data['actions']:
action_data = data['actions'][action_key]
action = Gio.SimpleAction.new(
'{}_{}'.format(group_key, action_key), None)
callback = partial(self._generic_callback,
group_key, action_data['callback'],
action_data.get('args', ()))
action.connect('activate', callback)
group.insert(action)
key, mod = Gtk.accelerator_parse(action_data['shortcut'])
accel_group.connect(key, mod, Gtk.AccelFlags.VISIBLE, callback)
self.add_action(action)
if self.win is None:
self.win = MainWindow(self)
statefile = os.path.join(
xdg.BaseDirectory.save_config_path('runsqlrun'), 'state')
if os.path.isfile(statefile):
with open(statefile) as f:
state = json.load(f)
self.win.restore_state(state)
self.win.add_accel_group(accel_group)
self.win.present()
示例14: _get_modifier_mask
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def _get_modifier_mask():
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
x, mod = Gtk.accelerator_parse('<Primary>')
return mod
示例15: runTest
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import accelerator_parse [as 别名]
def runTest(self):
for accelerator in ( # Ctrl-A or Command-A
"<Control>a",
"<Meta>a",
"<Primary>A",
"<primary>A",
"<PRIMARY>a"
):
#~ print(">>", accelerator, accelerator)
keyval, mod = Gtk.accelerator_parse(accelerator)
self.assertEqual(keyval, 97)
self.assertIn(mod, (Gdk.ModifierType.CONTROL_MASK, Gdk.ModifierType.META_MASK))