本文整理汇总了Python中gi.repository.Keybinder类的典型用法代码示例。如果您正苦于以下问题:Python Keybinder类的具体用法?Python Keybinder怎么用?Python Keybinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Keybinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bind_key
def bind_key(keystr, keybinding_target=KEYBINDING_DEFAULT):
"""
Bind @keystr, unbinding any previous key for @keybinding_target.
If @keystr is a false value, any previous key will be unbound.
"""
keybinding_target = int(keybinding_target)
if Keybinder is None:
return False
def callback(keystr):
return GetKeyboundObject()._keybinding(keybinding_target)
if not _is_sane_keybinding(keystr):
pretty.print_error(__name__, "Refusing to bind key", repr(keystr))
return False
succ = True
if keystr:
try:
succ = Keybinder.bind(keystr, callback)
pretty.print_debug(__name__, "binding", repr(keystr))
GetKeyboundObject().emit_bound_key_changed(keystr, True)
except KeyError as exc:
pretty.print_error(__name__, exc)
succ = False
if succ:
old_keystr = get_currently_bound_key(keybinding_target)
if old_keystr and old_keystr != keystr:
Keybinder.unbind(old_keystr)
pretty.print_debug(__name__, "unbinding", repr(old_keystr))
GetKeyboundObject().emit_bound_key_changed(old_keystr, False)
_register_bound_key(keystr, keybinding_target)
return succ
示例2: unbinder
def unbinder(self, items):
for keystring in items:
try:
Keybinder.unbind(items[keystring])
except:
pass
HotKeysConfig.binded = False
示例3: cancel
def cancel(self):
if not self._callback:
return
for keystring in self._worked:
Keybinder.unbind(keystring)
del self._worked[:]
self._callback = None
示例4: init_keybinder
def init_keybinder(self, config):
"""Initialise keybinder and bind some keys (toggle, copy, paste)"""
Keybinder.init()
Keybinder.set_use_cooked_accelerators(False)
self.bind_all_key(config['key_toggle_visibility'],
config['key_copy_to_clipboard'],
config['key_paste_from_clipboard'])
示例5: _enable
def _enable(eventname, exaile, eventdata):
global initialized
if not initialized:
Keybinder.init()
initialized = True
for k in KEYS:
Keybinder.bind(k, on_media_key, exaile)
示例6: bind_key
def bind_key(cls):
Keybinder.init()
shortcut = MetaData.get_snapshoot_shortcut()
if Keybinder.bind(shortcut,cls.callback,""):
if cls.old_key_shortcut is not None:
Keybinder.unbind(cls.old_key_shortcut)
cls.old_key_shortcut = shortcut
else:
logging.error("Bind shortcut key failed ")
示例7: on_exaile_loaded
def on_exaile_loaded(self):
if not self.__exaile:
return # Plugin has been disabled in the meantime
Keybinder.init()
for k in KEYS:
if not Keybinder.bind(k, on_media_key, self.__exaile):
LOGGER.warning("Failed to set key binding using Keybinder.")
self.__exaile.plugins.disable_plugin(__name__)
return
示例8: __init__
def __init__(self, superkey='<Super>'):
self.montab = MonTab()
self.super = superkey
nmons = self.montab.screen.get_n_monitors()
self.monkeys = [chr(ord('1') + n) for n in range(nmons)]
Keybinder.init()
Keybinder.set_use_cooked_accelerators(False)
示例9: __init__
def __init__(self, silent=False):
super(KazamSuperIndicator, self).__init__()
self.blink_icon = BLINK_STOP_ICON
self.blink_state = False
self.blink_mode = BLINK_SLOW
self.recording = False
self.silent = silent
logger.debug("Indicatior silent: {0}".format(self.silent))
self.menu = Gtk.Menu()
self.menuitem_start = Gtk.MenuItem(_("Start recording"))
self.menuitem_start.set_sensitive(True)
self.menuitem_start.connect("activate", self.on_menuitem_start_activate)
self.menuitem_pause = Gtk.CheckMenuItem(_("Pause recording"))
self.menuitem_pause.set_sensitive(False)
self.menuitem_pause.connect("toggled", self.on_menuitem_pause_activate)
self.menuitem_finish = Gtk.MenuItem(_("Finish recording"))
self.menuitem_finish.set_sensitive(False)
self.menuitem_finish.connect("activate", self.on_menuitem_finish_activate)
self.menuitem_separator = Gtk.SeparatorMenuItem()
self.menuitem_quit = Gtk.MenuItem(_("Quit"))
self.menuitem_quit.connect("activate", self.on_menuitem_quit_activate)
self.menu.append(self.menuitem_start)
self.menu.append(self.menuitem_pause)
self.menu.append(self.menuitem_finish)
self.menu.append(self.menuitem_separator)
self.menu.append(self.menuitem_quit)
self.menu.show_all()
#
# Setup keybindings - Hardcore way
#
try:
from gi.repository import Keybinder
logger.debug("Trying to bind hotkeys.")
Keybinder.init()
# 2015-10-10, Joshua Chen
# configure the shortcut keys
Keybinder.bind("<Ctrl><Shift>F1", self.cb_hotkeys, "start-request")
Keybinder.bind("<Ctrl><Shift>F12", self.cb_hotkeys, "stop-request")
Keybinder.bind("<Ctrl><Shift>F8", self.cb_hotkeys, "pause-request")
# Keybinder.bind("<Ctrl>W", self.cb_hotkeys, "show-request")
Keybinder.bind("<Ctrl><Shift>F11", self.cb_hotkeys, "quit-request")
self.recording = False
except ImportError:
logger.info("Unable to import Keybinder, hotkeys not available.")
示例10: bind
def bind(binding, func, *args, **kwargs):
"""Wrapper for keybinder.bind() allowing kwargs."""
def run(_, __): func(*args, **kwargs)
try:
Keybinder.unbind(binding)
except:
pass
success = Keybinder.bind(binding, run, None)
if not success:
print "Error binding '%s'" % binding
示例11: set_app_show
def set_app_show(self, new):
'''
This is a specific method to set just the show accelerator.
We use the value from gsettings to first unbind the current
key, so in the process of changing the hotkey, we expect the
API user to first call this method and later change gsettings.
'''
if platform.system() == 'Windows':
self.app.set_hotkey(new)
else:
Keybinder.unbind(self.shortcuts['app-show'])
Keybinder.bind(new, self.app.on_show)
示例12: __init__
def __init__(self, data):
"""Create a new UIObject instance, including loading its uiFile and
all UI-related objects.
Instance attributes:
data -- An instance of a pykickstart Handler object. The Hub
never directly uses this instance. Instead, it passes
it down into Spokes when they are created and applied.
The Hub simply stores this instance so it doesn't need
to be passed by the user.
skipTo -- If this attribute is set to something other than None,
it must be the name of a class (as a string). Then,
the interface will skip to the first instance of that
class in the action list instead of going on to
whatever the next action is normally.
Note that actions may only skip ahead, never backwards.
Also, standalone spokes may not skip to an individual
spoke off a hub. They can only skip to the hub
itself.
"""
common.UIObject.__init__(self, data)
if self.__class__ is GUIObject:
raise TypeError("GUIObject is an abstract class")
self.skipTo = None
self.applyOnSkip = False
self.builder = Gtk.Builder()
self.builder.set_translation_domain(self.translationDomain)
self._window = None
if self.builderObjects:
self.builder.add_objects_from_file(self._findUIFile(), self.builderObjects)
else:
self.builder.add_from_file(self._findUIFile())
self.builder.connect_signals(self)
# Keybinder from GI needs to be initialized before use
Keybinder.init()
Keybinder.bind("<Shift>Print", self._handlePrntScreen, [])
self._automaticEntry = False
self._autostepRunning = False
self._autostepDone = False
self._autostepDoneCallback = None
# this indicates if the screen is the last spoke to be processed for a hub
self.lastAutostepSpoke = False
示例13: bind_show_app_hotkey
def bind_show_app_hotkey(self, accel_name):
if is_wayland_compatibility_on():
return
if self._current_accel_name == accel_name:
return
if self._current_accel_name:
Keybinder.unbind(self._current_accel_name)
self._current_accel_name = None
logger.info("Trying to bind app hotkey: %s" % accel_name)
Keybinder.bind(accel_name, self.toggle_window)
self._current_accel_name = accel_name
self.notify_hotkey_change(accel_name)
示例14: hide_app
def hide_app(self, key_bind_hide, user_data):
self.last_event_time = Keybinder.get_current_event_time()
print("Event time:", self.last_event_time)
self.wnck.force_update()
self.active_workspace = self.wnck.get_active_workspace()
# print("Workspaces:", self.wnck.get_workspaces())
# print("Active workspace:", self.active_workspace)
# print("Last active workspace:", self.last_active_workspace)
#
if self.is_present:
print("Hiding app")
if self.parent.is_drop_down:
self.hide()
else:
self.iconify()
self.is_present = False
else:
print("Showing app")
if self.parent.is_drop_down:
if self.last_active_workspace != self.active_workspace:
self.last_active_workspace = self.active_workspace
self.hide()
self.show()
# self.present()
# self.set_icon_from_file(config.file_program_icon)
self.present_with_time(self.last_event_time)
self.main_box.active_term.grab_focus()
self.is_present = True
示例15: register_callbacks
def register_callbacks(self):
"""Connect the GTK+ signals we care about"""
self.connect('key-press-event', self.on_key_press)
self.connect('button-press-event', self.on_button_press)
self.connect('delete_event', self.on_delete_event)
self.connect('destroy', self.on_destroy_event)
self.connect('window-state-event', self.on_window_state_changed)
self.connect('focus-out-event', self.on_focus_out)
self.connect('focus-in-event', self.on_focus_in)
# Attempt to grab a global hotkey for hiding the window.
# If we fail, we'll never hide the window, iconifying instead.
if self.config['keybindings']['hide_window'] != None:
if display_manager() == 'X11':
try:
self.hidebound = Keybinder.bind(
self.config['keybindings']['hide_window'].replace('<Shift>',''),
self.on_hide_window)
except (KeyError, NameError):
pass
if not self.hidebound:
err('Unable to bind hide_window key, another instance/window has it.')
self.hidefunc = self.iconify
else:
self.hidefunc = self.hide