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'])
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)
def setup(self, _): self.hold() # Keep the app running even without a window self.window = window = UlauncherWindow.get_instance() window.set_application(self) window.set_keep_above(True) window.position_window() window.init_theme() # this will trigger to show frequent apps if necessary window.show_results([]) if self.settings.get_property('show-indicator-icon'): self.appindicator = AppIndicator(self) self.appindicator.switch(True) if IS_X11: # bind hotkey Keybinder.init() accel_name = self.settings.get_property('hotkey-show-app') # bind in the main thread GLib.idle_add(self.bind_hotkey, accel_name) ExtensionServer.get_instance().start() time.sleep(0.01) ExtensionRunner.get_instance().run_all()
def finish_initializing(self, builder): """ Set up the main window """ super(UlauncherWindow, self).finish_initializing(builder) self.results_nav = None self.builder = builder self.window = self.get_widget('ulauncher_window') self.input = self.get_widget('input') self.prefs_btn = self.get_widget('prefs_btn') self.result_box = builder.get_object("result_box") self.input.connect('changed', self.on_input_changed) self.prefs_btn.connect('clicked', self.on_mnu_preferences_activate) self.set_keep_above(True) self.AboutDialog = AboutUlauncherDialog self.PreferencesDialog = PreferencesUlauncherDialog self.position_window() self.init_styles() # bind hotkey Keybinder.init() accel_name = Settings.get_instance().get_property('hotkey-show-app') # bind in the main thread GLib.idle_add(self.bind_show_app_hotkey, accel_name) start_app_watcher()
def __init__(self, config_files): super(Klemmbrett, self).__init__() self._clipboard = _gtk.Clipboard.get(_gdk.SELECTION_CLIPBOARD) self._primary = _gtk.Clipboard.get(_gdk.SELECTION_PRIMARY) self.config = _config.Config() self.config.read(config_files) _keybinder.init() # configure klemmbrett self._plugins = dict() self._load_plugins() self._sync = _util.humanbool( self.config.get('klemmbrett', 'sync', True)) self.selection = None self._clipboard.connect('owner-change', self._clipboard_owner_changed) self._primary.connect('owner-change', self._clipboard_owner_changed) try: _notify.init("Klemmbrett") except _dbus.exceptions.DBusException: _log.error( "Could not register with notification interface, notifications will not work properly", exc_info=True)
def __init__(self): # =>public window props Gtk.Window.__init__(self, title="Kimia-Dict (V " + glob.VERSION + ")" # type_hint=Gdk.WindowTypeHint.TOOLBAR ) self.set_default_size(800, 500) self.set_icon_from_file("./assets/img/logo.png") self.set_position(Gtk.WindowPosition.CENTER) #=>connect to destory main window # self.connect("destroy", self.on_destroy) self.connect("delete_event", self.on_delete) #=>connect to key events of main window self.connect("key-press-event", self.on_key_press_event) # =>set toolbar MainBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) MainToolbar = menu.ToolBar() MainBox.pack_start(MainToolbar, False, False, 0) # =>set search box MainSearch = search.SearchBox() MainBox.pack_start(MainSearch, False, False, 10) # =>set content sw = Gtk.ScrolledWindow() mcontent = search.content sw.add_with_viewport(mcontent) MainBox.pack_start(sw, True, True, 0) # =>add MainBox to main window self.add(MainBox) # =>init keybinder Keybinder.init() # =>handle global shortuct by 'shortcut_callback' Keybinder.bind(glob.KEYDISPLAY, self.show_shortcut_callback, "keystring %s (user data)" % glob.KEYDISPLAY) # =>show all widgets and window self.show_all()
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_settings = Gtk.MenuItem(_("Settings")) self.menuitem_settings.set_sensitive(True) self.menuitem_settings.connect("activate", self.on_menuitem_settings_activate) self.menuitem_separator1 = Gtk.SeparatorMenuItem() 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_separator2 = Gtk.SeparatorMenuItem() self.menuitem_quit = Gtk.MenuItem(_("Quit")) self.menuitem_quit.connect("activate", self.on_menuitem_quit_activate) self.menu.append(self.menuitem_settings) self.menu.append(self.menuitem_separator1) self.menu.append(self.menuitem_start) self.menu.append(self.menuitem_pause) self.menu.append(self.menuitem_finish) self.menu.append(self.menuitem_separator2) 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() Keybinder.bind("<Super><Ctrl>R", self.cb_hotkeys, "start-request") Keybinder.bind("<Super><Ctrl>F", self.cb_hotkeys, "stop-request") Keybinder.bind("<Super><Ctrl>P", self.cb_hotkeys, "pause-request") Keybinder.bind("<Super><Ctrl>W", self.cb_hotkeys, "show-request") Keybinder.bind("<Super><Ctrl>Q", self.cb_hotkeys, "quit-request") self.recording = False except ImportError: logger.info("Unable to import Keybinder, hotkeys not available.")
def _init_keys(self): Keybinder.init() def bind_toggle_key(self, key): self.bind_toggle_key(key) return False # to not be called again. GLib.idle_add(bind_toggle_key, self, catapult.conf.toggle_key)
def run_keybinder(callback): Keybinder.init() Keybinder.bind('<Ctrl><Alt>space', callback) try: GLib.MainLoop().run() except KeyboardInterrupt: GLib.MainLoop().quit()
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
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 ")
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)
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 ")
def __init__(self): self.recorder = Recorder() keybinder.init() keybinder.bind('<Control>Escape', self.callback, None) self.overlay = Overlay() self.overlay.connect('trigger', lambda *args: self.start_recording(*self.overlay.get_selection())) self.overlay.show_all()
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.")
def __init__(self): self.indicator = appindicator.Indicator.new(APPINDICATOR_ID, self.get_current_state_icon(), appindicator.IndicatorCategory.SYSTEM_SERVICES) self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE) self.indicator.set_menu(self.build_menu()) self.update_mic_state() Notify.init(APPINDICATOR_ID) Keybinder.init() Keybinder.set_use_cooked_accelerators(False) Keybinder.bind(keystr, self.callback_toggle_mic, "keystring %s (user data)" % keystr) print ("Press '" + keystr + "' to toggle microphone mute")
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
def __init__(self): self.indicator = AppIndicator3.Indicator.new( 'tasker', 'tasker', AppIndicator3.IndicatorCategory.APPLICATION_STATUS) Keybinder.init() self.load_preferences() self.indicator.set_menu(self.build_menu()) self.indicator.set_label('', '') self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) self.set_icon(True) self.load_todos() Gtk.main()
def __init__(self): self.app = "xkb-indicator" self.indicator = appindicator.Indicator.new( self.app, "ibus-keyboard", category=appindicator.IndicatorCategory.OTHER) self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE) self.indicator.set_menu(self.build_menu()) self.indicator.set_label(label(), self.app) Keybinder.bind("<Alt>space", self.toggle) Keybinder.init()
def plugin_main(app, fullpath): import gi gi.require_version('Notify', '0.7') gi.require_version('Keybinder', '3.0') from gi.repository import Keybinder, Notify global notification notification = Notify.Notification() Keybinder.init() Keybinder.bind("<Ctrl><Alt>v", lambda *a: grab_notify(app)) Keybinder.bind("<Ctrl><Alt>m", lambda *a: notifier(app)) Notify.init("anubad") notification.set_icon_from_pixbuf(app.pixbuf_logo)
def __init__(self, player): self.player = player self.logger = logging.getLogger('KeyboardClient') try: import gi gi.require_version('Keybinder', '3.0') from gi.repository import Keybinder Keybinder.init() Keybinder.bind('XF86AudioPlay', self._on_XF86AudioPlay) Keybinder.bind('XF86AudioNext', self._on_XF86AudioNext) Keybinder.bind('XF86AudioPrev', self._on_XF86AudioPrev) except ValueError: self.logger.warning( 'Keybinder is needed on Linux for MediaKey binding')
def __init__(self): self.bound_keys = [] self.workarea = Workarea() self.callable_actions = dict self.__define_callable_actions() notify2.init("Azulejo") Keybinder.init() Keybinder.bind("<Super>y", WindowTools.print_window_info, None) Keybinder.bind("<Super>c", self.switch_config_files, None) self.bind_keys(configuration.get_config_data_first_time()) Gtk.main()
def finish_initializing(self, builder): """Called while initializing this instance in __new__ finish_initializing should be called after parsing the UI definition and creating a UlauncherWindow object with it in order to finish initializing the start of the new UlauncherWindow instance. """ # Get a reference to the builder and set up the signals. self.builder = builder self.ui = builder.get_ui(self, True) self.PreferencesDialog = None # class self.preferences_dialog = None # instance self.results_nav = None self.window = self.ui['ulauncher_window'] self.window_body = self.ui['body'] self.input = self.ui['input'] self.prefs_btn = self.ui['prefs_btn'] self.result_box = self.ui["result_box"] self.input.connect('changed', self.on_input_changed) self.prefs_btn.connect('clicked', self.on_mnu_preferences_activate) self.set_keep_above(True) self.PreferencesDialog = PreferencesUlauncherDialog self.settings = Settings.get_instance() self.fix_window_width() self.position_window() self.init_theme() # this will trigger to show frequent apps if necessary self.show_results([]) if not is_wayland_compatibility_on(): # bind hotkey Keybinder.init() accel_name = self.settings.get_property('hotkey-show-app') # bind in the main thread GLib.idle_add(self.bind_show_app_hotkey, accel_name) start_app_watcher() ExtensionServer.get_instance().start() time.sleep(0.01) ExtensionRunner.get_instance().run_all() if not get_options().no_extensions: ExtensionDownloader.get_instance().download_missing()
def start_daemon(self): Keybinder.init() self.set_accelerator() css.load_css() emojis.init() self.activated = True # The first time the app launches, open the picker and show the # guide if not user_data.load_shown_welcome(): self.create_picker_window(True) user_data.update_shown_welcome() # Run the main gtk event loop - this prevents the app from quitting Gtk.main()
def finish_initializing(self, builder): """Called while initializing this instance in __new__ finish_initializing should be called after parsing the UI definition and creating a UlauncherWindow object with it in order to finish initializing the start of the new UlauncherWindow instance. """ # Get a reference to the builder and set up the signals. self.builder = builder self.ui = builder.get_ui(self, True) self.PreferencesDialog = None # class self.preferences_dialog = None # instance self.results_nav = None self.window = self.ui['ulauncher_window'] self.input = self.ui['input'] self.prefs_btn = self.ui['prefs_btn'] self.result_box = self.ui["result_box"] self.input.connect('changed', self.on_input_changed) self.prefs_btn.connect('clicked', self.on_mnu_preferences_activate) self.set_keep_above(True) self.PreferencesDialog = PreferencesUlauncherDialog self.settings = Settings.get_instance() self.fix_window_width() self.position_window() self.init_theme() # this will trigger to show frequent apps if necessary self.show_results([]) if not is_wayland_compatibility_on(): # bind hotkey Keybinder.init() accel_name = self.settings.get_property('hotkey-show-app') # bind in the main thread GLib.idle_add(self.bind_show_app_hotkey, accel_name) start_app_watcher() ExtensionServer.get_instance().start() time.sleep(0.01) ExtensionRunner.get_instance().run_all() ExtensionDownloader.get_instance().download_missing()
def __init__(self, hook): self.hook = hook self.indicator = AppIndicator3.Indicator.new( "tasker", "tasker", AppIndicator3.IndicatorCategory.APPLICATION_STATUS, ) Keybinder.init() self.tracking = False self.load_preferences() self.indicator.set_menu(self.build_menu()) self.indicator.set_label("", "") self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) self.set_icon() self.load_todos() self.hook.after_init_indicator() Gtk.main()
def __init__(self): Gtk.Window.__init__(self, type=Gtk.WindowType.TOPLEVEL) Keybinder.init() # Deactivating WM keybindings keybindings = Gio.Settings.new('org.gnome.desktop.wm.keybindings') wm_hotkey = lambda t: keybindings.get_value(t)[0] if wm_hotkey('switch-input-source') or wm_hotkey('switch-input-source-backward'): self.show_message("Unity-Kbd-Switcher is going to deactivate the following WM keybindings\n" + "You can set them later in settings if you'll decide to discontinue using.\n" + "\n" + "switch-input-source: " + wm_hotkey('switch-input-source') + "\n" + "switch-input-source-backward: " + wm_hotkey('switch-input-source-backward') + "\n") keybindings.set_value('switch-input-source', GLib.Variant('as', [''])) keybindings.set_value('switch-input-source-backward', GLib.Variant('as', [''])) # Initializing GSettings self.source_settings = Gio.Settings.new('org.gnome.desktop.input-sources') self.source_settings.connect("changed::current", self.on_current_changed) self.source_settings.connect("changed::sources", self.on_sources_changed) # Loading config rc = "%s/.kbdrc" % os.getenv("HOME") if not os.path.isfile(rc): self.generate_default_rc(rc) keymap = {} execfile(rc) self.keymap = keymap self.current_layout = None self.on_sources_changed(None, None) self.on_current_changed(None, None) # Binding global hotkeys for key in self.keymap.keys(): print "Binding %s" % key if not Keybinder.bind(key, self.on_global_key_activated, None): self.show_message("Could not bind '%s'" % key) # Usual Gtk Stuff self.connect("destroy", Gtk.main_quit) self.connect("delete_event", Gtk.main_quit) signal.signal(signal.SIGINT, signal.SIG_DFL) internals.app = self Gtk.main()
def finish_initializing(self, ui): # pylint: disable=attribute-defined-outside-init self.ui = ui self.preferences = None # instance self.results_nav = None self.window_body = self.ui['body'] self.input = self.ui['input'] self.prefs_btn = self.ui['prefs_btn'] self.result_box = self.ui["result_box"] self.scroll_container = self.ui["result_box_scroll_container"] self.input.connect('changed', self.on_input_changed) self.prefs_btn.connect('clicked', self.on_mnu_preferences_activate) self.set_keep_above(True) self.settings = Settings.get_instance() self.fix_window_width() self.position_window() self.init_theme() # this will trigger to show frequent apps if necessary self.show_results([]) self.connect('button-press-event', self.mouse_down_event) self.connect('button-release-event', self.mouse_up_event) self.connect('motion_notify_event', self.mouse_move_event) if self.settings.get_property('show-indicator-icon'): AppIndicator.get_instance(self).show() if IS_X11: # bind hotkey Keybinder.init() accel_name = self.settings.get_property('hotkey-show-app') # bind in the main thread GLib.idle_add(self.bind_hotkey, accel_name) ExtensionServer.get_instance().start() time.sleep(0.01) ExtensionRunner.get_instance().run_all() if not get_options().no_extensions: ExtensionDownloader.get_instance().download_missing()
def bind_keybinder(self): try: import gi gi.require_version('Keybinder', '3.0') # Gdk needed for Keybinder from gi.repository import Keybinder, Gdk Keybinder.init() except: return False Keybinder.bind('XF86AudioPlay', self.window.playpause, None) Keybinder.bind('XF86AudioStop', self.window.user_pause, None) Keybinder.bind('XF86AudioNext', self.window.next_song, None) Keybinder.bind('XF86AudioPrev', self.window.bring_to_top, None) logging.info("Bound media keys with keybinder") self.method = 'keybinder' return True
def bind_keybinder(self): try: import gi gi.require_version('Keybinder', '3.0') # Gdk needed for Keybinder from gi.repository import Keybinder Keybinder.init() except (ValueError, ImportError): return False Keybinder.bind('XF86AudioPlay', self.window.playpause, None) Keybinder.bind('XF86AudioStop', self.window.user_pause, None) Keybinder.bind('XF86AudioNext', self.window.next_song, None) Keybinder.bind('XF86AudioPrev', self.window.bring_to_top, None) logging.info("Bound media keys with keybinder") self.method = 'keybinder' return True
def __init__(self): assert self.__class__.instance is None, 'Can be created only once!' self.hotkeys = {} self.config = None self.play_pause = EventHook() self.next = EventHook() self.prev = EventHook() if IS_INIT: Keybinder.init() self.initialize() threading.Thread(target=Gtk.main).start() else: NotificationArea.notify( 'Could not import Keybinder and Gtk. Error was: "{}"\n' 'Global shortcuts will not work.'.format(ERROR))
def __init__(self): self._x_hotkeys = {} self._hotkeys = self._parse_hotkeys() self.config = None self.play_pause = EventHook() self.next = EventHook() self.prev = EventHook() if IS_INIT: Keybinder.init() self.initialize() threading.Thread(target=Gtk.main).start() else: logger.debug("Not loading the global shortcuts.") notification_area.notify( ERROR_MESSAGE + ", this means the global shortcuts will not work.\n" + "You can check the log for more details.")
def __init__(self): GObject.GObject.__init__(self) self.bound = False self.prevbinding = None keybinder.init() # Set and retreive global keybinding from GSettings glipper.GSETTINGS.connect( "changed::" + glipper.GSETTINGS_KEY_COMBINATION, lambda x, y, z=None: self.on_config_key_combination()) self.key_combination = glipper.GSETTINGS.get_string( glipper.GSETTINGS_KEY_COMBINATION) if self.key_combination == None: # This is for uninstalled cases, the real default is in the schema self.key_combination = "<Ctrl><Alt>C" self.bind()
def on_startup(self, app): ''' This method handles the startup signal. As per GNOME guidelines this is where most of the work to create the window should be done. ''' self.create_directories() self.settings = Gio.Settings(schema=self.schema_id + '.preferences') self.win_settings = Gio.Settings(schema=self.schema_id + '.window') self.width = self.win_settings['width'] self.height = self.win_settings['height'] self.general_settings = self.settings.get_child('general') self.set_autostart(self.general_settings['autostart']) self.closehide = self.general_settings['closehide'] self.about_dialog = None self.preferences_dialog = None logging.basicConfig(filename=self.log_file, level=logging.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') self.window = Gtk.ApplicationWindow(application=app) self.window.connect('size-allocate', self.on_size_allocate) self.window.connect('delete-event', self.on_window_delete) self.window.set_title(self.title) self.window.set_default_size(self.width, self.height) self.window.set_position(Gtk.WindowPosition.MOUSE) self.window.set_titlebar(HeaderBar(self)) # We need to set the icon here as a backup, the gnome system monitor # for instance, and for whatever reason, doesn't choose the right icon # sometimes, particularly after hiding the window, and showing again. self.window.set_icon_name(self.icon) self.main_view = MainView(self) self.window.add(self.main_view) self.add_actions() builder = Gtk.Builder.new_from_file(self.gui_ui) app_menu = builder.get_object('app_menu') self.set_app_menu(app_menu) Keybinder.init() shortcuts = self.settings.get_child('shortcuts') Keybinder.bind(shortcuts['app-show'], self.on_show)
def init_keybinder(player): try: import gi gi.require_version("Keybinder", "3.0") from gi.repository import Keybinder except (ValueError, ImportError): return False Keybinder.init() signals = { "XF86AudioPrev": "prev", "XF86AudioNext": "next", "XF86AudioStop": "stop", "XF86AudioPlay": "play" } for sig, action in signals.items(): Keybinder.bind(sig, make_keybinder_cb(player, action), None) return True
def add_global_shortcut(self): ''' This method adds a global shortcut, the shortcut used to show the application. ''' shortcuts = self.settings.get_child('shortcuts') if platform.system() == 'Windows': self.modifiers = { Gdk.ModifierType.SHIFT_MASK: ['VK_SHIFT'], Gdk.ModifierType.CONTROL_MASK: ['VK_CONTROL'], Gdk.ModifierType.MOD1_MASK: ['VK_MENU'], Gdk.ModifierType.SUPER_MASK: ['VK_LWIN', 'VK_RWIN'] } hook_manager = pyHook.HookManager() hook_manager.KeyDown = self.on_keyboard_event self.set_hotkey(shortcuts['app-show']) hook_manager.HookKeyboard() else: Keybinder.init() Keybinder.bind(shortcuts['app-show'], self.on_show)
def main(): # Catch SIGINT signal signal.signal(signal.SIGINT, signal.SIG_DFL) # Load the configuration with defaults config = Config() # Create the window and set attributes win = NimblestWindow(config) win.connect("delete-event", Gtk.main_quit) win.set_position(Gtk.WindowPosition.CENTER) win.set_keep_above(True) win.set_skip_taskbar_hint(True) win.set_decorated(False) # Set the hotkey Keybinder.init() if not Keybinder.bind(config.hotkey, win.hotkey, None): print("Could not bind the hotkey:", config.hotkey) exit() Gtk.main()
def add_global_shortcut(self): ''' This method adds a global shortcut, the shortcut used to show the application. ''' shortcuts = self.settings.get_child('shortcuts') if platform.system() == 'Windows': self.modifiers = {Gdk.ModifierType.SHIFT_MASK: ['VK_SHIFT'], Gdk.ModifierType.CONTROL_MASK: ['VK_CONTROL'], Gdk.ModifierType.MOD1_MASK: ['VK_MENU'], Gdk.ModifierType.SUPER_MASK: ['VK_LWIN', 'VK_RWIN']} hook_manager = pyHook.HookManager() hook_manager.KeyDown = self.on_keyboard_event self.set_hotkey(shortcuts['app-show']) hook_manager.HookKeyboard() else: Keybinder.init() Keybinder.bind(shortcuts['app-show'], self.on_show)
def __init__(self): self.builder = Gtk.Builder() self.builder.add_from_file(UI_FILE) self.builder.connect_signals(self) Keybinder.init() Keybinder.bind("<Ctrl>T", self.on_shortcut_pressed, True) Keybinder.bind("<Ctrl>W", self.on_shortcut_pressed, True) Keybinder.bind("<Ctrl>Q", self.on_shortcut_pressed, True) Keybinder.bind("<Ctrl>L", self.on_shortcut_pressed, True) self.btn_back = self.builder.get_object('bar-btn-back') self.btn_forward = self.builder.get_object('bar-btn-forward') self.urlbar = self.builder.get_object('bar-urlbar') self.settings = self.builder.get_object('bar-settings') self.tabcontainer = self.builder.get_object('tabcontainer') self.browser = self.builder.get_object('browser') self.browser.show_all() self.tab_append()
def __init__(self): self.display = display.Display() Keybinder.init() Keybinder.bind("<Ctrl>9", self.on_snippets_activated) menu = Gtk.Menu() item = Gtk.MenuItem() item.set_label("Editor") item.connect("activate", self.on_editor_activated) item.show() menu.append(item) item = Gtk.MenuItem() item.set_label("Exit") item.connect("activate", Gtk.main_quit) item.show() menu.append(item) self.status_icon = AppIndicator3.Indicator.new( "linux-snippets", "onboard-mono", AppIndicator3.IndicatorCategory.APPLICATION_STATUS ) self.status_icon.set_icon_theme_path(os.getcwd()+"/res/") self.status_icon.set_icon("icon") self.status_icon.set_status(AppIndicator3.IndicatorStatus.ACTIVE) self.status_icon.set_menu(menu) self.editor = e_w.EditorWindow() self.editor.connect("delete-event", self.on_window_deleted) self.snippets = sn_w.SnippetsWindow(self.on_snippets_completed) self.snippets.connect("delete-event", self.on_window_deleted)
def run(self): # self.win = Gtk.Window() self.win = Gtk.Window(type=Gtk.WindowType.POPUP) self.win.set_border_width(1) width = 400 relative_top = 0.25 self.win.set_size_request(width, -1) self.win.move( (Gdk.Screen.get_default().width() / 2) - width / 2, Gdk.Screen.get_default().height() * relative_top, ) self.win.connect("delete-event", Gtk.main_quit) self.win.connect("show", self.handle_show) self.win.set_type_hint(Gdk.WindowTypeHint.UTILITY) self.win.set_resizable(False) self.win.set_decorated(False) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) vbox.set_homogeneous(False) self.win.add(vbox) self.entry = Gtk.Entry() self.entry.override_font( Pango.FontDescription.from_string(self.config["entry_font"])) self.entry.connect("key-press-event", self.handle_key_press) self.entry.connect("changed", self.handle_input) vbox.pack_start(self.entry, False, True, 0) self.store = Gtk.ListStore(GdkPixbuf.Pixbuf, str, object) self.tree = Gtk.TreeView(self.store) self.tree.override_font(Pango.FontDescription.from_string(self.config["name_font"])) self.tree.set_headers_visible(False) self.tree.get_selection().set_mode(Gtk.SelectionMode.BROWSE) self.content_renderer = Gtk.CellRendererText() content_column = Gtk.TreeViewColumn("Name", self.content_renderer, markup=1) self.icon_renderer = Gtk.CellRendererPixbuf() icon_column = Gtk.TreeViewColumn("Icon", self.icon_renderer, pixbuf=0) self.tree.append_column(icon_column) self.tree.append_column(content_column) self.tree.set_search_column(-1) def handle_selection_changed(selection): tree_iter = selection.get_selected()[1] if not tree_iter: return self.tree.scroll_to_cell(self.store.get_path(tree_iter)) self.tree.get_selection().connect("changed", handle_selection_changed) self.scrolled = Gtk.ScrolledWindow() self.scrolled.set_policy(Gtk.PolicyType.ALWAYS, Gtk.PolicyType.AUTOMATIC) self.scrolled.add(self.tree) vbox.pack_start(self.scrolled, False, False, 0) signal.signal(signal.SIGINT, signal.SIG_DFL) accel_group = Gtk.AccelGroup() def connect_accel(accel, func): accel_group.connect(accel[0], accel[1], 0, func) def connection_multiple_accels(accels, func): for accel in accels: connect_accel(accel, func) hide_accel = Gtk.accelerator_parse("Escape") connect_accel(hide_accel, self.hide) quit_accel = Gtk.accelerator_parse("<Ctrl>q") connect_accel(quit_accel, Gtk.main_quit) launch_accel = Gtk.accelerator_parse("Return") connect_accel(launch_accel, self.launch_choice) Keybinder.init() Keybinder.bind(self.config["show_binding"], self.show, None) self.win.add_accel_group(accel_group) self.win.show_all() self.scrolled.hide() # Gdk.keyboard_grab(self.win.get_window(), False, Gdk.CURRENT_TIME) Gtk.main()
example-gi-py3.py Looked at a pull request that was built for py2.x, but overwrote the original py instead of making a separate example. I wouldn't have accepted that pull request either. The keybinder.init() part wasn't in the original example. [email protected] public domain """ import gi gi.require_version('Gtk', '3.0') gi.require_version('Keybinder', '3.0') from gi.repository import Gtk from gi.repository import Keybinder def callback(keystr, user_data): print ("Handling", user_data) print ("Event time:", Keybinder.get_current_event_time()) Gtk.main_quit() if __name__ == '__main__': keystr = "<Ctrl><Alt>M" Keybinder.init() Keybinder.bind(keystr, callback, "keystring %s (user data)" % keystr) print ("Press", keystr, "to handle keybinding and quit") Gtk.main()
def run(self): keybinder.init() me = lib.singleton.SingleInstance() self.handleKeys() self.startIndicator() gtk.main()
def bind_key(self): key_bind_hide = "Menu" Keybinder.init() Keybinder.bind(key_bind_hide, self.hide_app, "key_bind_hide: %s" % key_bind_hide)
def __init__(self): Keybinder.init()
def run(queue): keystr = "<Ctrl><Alt>z" Keybinder.init() assert Keybinder.bind(keystr, _on_shortcut, queue) debug('keybinder active') Gtk.main()
def init_key_binding(self): Keybinder.init() Keybinder.bind(show_keystr, self.show) Keybinder.bind(hide_keystr, self.hide) Keybinder.bind(take_photo_keystr, write_photo)
from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GLib import threading from gi.repository import GObject import datetime from gecoc import gecolib from gi.repository import Notify Notify.init('GECO') import keyring try: from gi.repository import Keybinder as keybinder keybinder.init() except: keybinder = None __version__ = '1.0' IMG = 'glade' SECONDS = 600 CONFFILE = 'geco.conf' def remove_text(button): alignment = button.get_children()[0] hbox = alignment.get_children()[0] image, label = hbox.get_children() image.show()
def __init__(self): def load_schema(): return Gio.SettingsSchemaSource.new_from_directory( SCHEMA_DIR, Gio.SettingsSchemaSource.get_default(), False ) try: schema_source = load_schema() except GLib.Error: # pylint: disable=catching-non-exception log.exception("Unable to load the GLib schema, try to compile it") try_to_compile_glib_schemas() schema_source = load_schema() self.settings = Settings(schema_source) super(Guake, self).__init__(gladefile('guake.glade')) select_gtk_theme(self.settings) patch_gtk_theme(self.get_widget("window-root").get_style_context(), self.settings) self.add_callbacks(self) log.info('Guake Terminal %s', guake_version()) log.info('VTE %s', vte_version()) log.info('Gtk %s', gtk_version()) self.hidden = True self.forceHide = False # trayicon! Using SVG handles better different OS trays # img = pixmapfile('guake-tray.svg') # trayicon! img = pixmapfile('guake-tray.png') try: import appindicator except ImportError: self.tray_icon = Gtk.StatusIcon() self.tray_icon.set_from_file(img) self.tray_icon.set_tooltip_text(_("Guake Terminal")) self.tray_icon.connect('popup-menu', self.show_menu) self.tray_icon.connect('activate', self.show_hide) else: # TODO PORT test this on a system with app indicator self.tray_icon = appindicator.Indicator( _("guake-indicator"), _("guake-tray"), appindicator.CATEGORY_OTHER ) self.tray_icon.set_icon(img) self.tray_icon.set_status(appindicator.STATUS_ACTIVE) menu = self.get_widget('tray-menu') show = Gtk.MenuItem(_('Show')) show.set_sensitive(True) show.connect('activate', self.show_hide) show.show() menu.prepend(show) self.tray_icon.set_menu(menu) # important widgets self.window = self.get_widget('window-root') self.window.set_keep_above(True) self.mainframe = self.get_widget('mainframe') self.mainframe.remove(self.get_widget('notebook-teminals')) # Workspace tracking self.notebook_manager = NotebookManager( self.window, self.mainframe, self.settings.general.get_boolean('workspace-specific-tab-sets'), self.terminal_spawned, self.page_deleted ) self.notebook_manager.connect('notebook-created', self.notebook_created) self.notebook_manager.set_workspace(0) self.set_tab_position() # check and set ARGB for real transparency color = self.window.get_style_context().get_background_color(Gtk.StateFlags.NORMAL) self.window.set_app_paintable(True) def draw_callback(widget, cr): if widget.transparency: cr.set_source_rgba(color.red, color.green, color.blue, 1) else: cr.set_source_rgb(0, 0, 0) cr.set_operator(cairo.OPERATOR_SOURCE) cr.paint() cr.set_operator(cairo.OPERATOR_OVER) screen = self.window.get_screen() visual = screen.get_rgba_visual() if visual and screen.is_composited(): self.window.set_visual(visual) self.window.transparency = True else: log.warn('System doesn\'t support transparency') self.window.transparency = False self.window.set_visual(screen.get_system_visual()) self.window.connect('draw', draw_callback) # Debounce accel_search_terminal self.prev_accel_search_terminal_time = 0.0 # holds the timestamp of the losefocus event self.losefocus_time = 0 # holds the timestamp of the previous show/hide action self.prev_showhide_time = 0 # Controls the transparency state needed for function accel_toggle_transparency self.transparency_toggled = False # store the default window title to reset it when update is not wanted self.default_window_title = self.window.get_title() self.abbreviate = False self.window.connect('focus-out-event', self.on_window_losefocus) # Handling the delete-event of the main window to avoid # problems when closing it. def destroy(*args): self.hide() return True def window_event(*args): return self.window_event(*args) self.window.connect('delete-event', destroy) self.window.connect('window-state-event', window_event) # this line is important to resize the main window and make it # smaller. # TODO PORT do we still need this? # self.window.set_geometry_hints(min_width=1, min_height=1) # special trick to avoid the "lost guake on Ubuntu 'Show Desktop'" problem. # DOCK makes the window foundable after having being "lost" after "Show # Desktop" self.window.set_type_hint(Gdk.WindowTypeHint.DOCK) # Restore back to normal behavior self.window.set_type_hint(Gdk.WindowTypeHint.NORMAL) # loading and setting up configuration stuff GSettingHandler(self) Keybinder.init() self.hotkeys = Keybinder Keybindings(self) self.load_config() if self.settings.general.get_boolean('start-fullscreen'): self.fullscreen() refresh_user_start(self.settings) # Restore tabs when startup if self.settings.general.get_boolean('restore-tabs-startup'): self.restore_tabs(suppress_notify=True) # Pop-up that shows that guake is working properly (if not # unset in the preferences windows) if self.settings.general.get_boolean('use-popup'): key = self.settings.keybindingsGlobal.get_string('show-hide') keyval, mask = Gtk.accelerator_parse(key) label = Gtk.accelerator_get_label(keyval, mask) filename = pixmapfile('guake-notification.png') notifier.showMessage( _("Guake Terminal"), _("Guake is now running,\n" "press <b>{!s}</b> to use it.").format(xml_escape(label)), filename ) log.info("Guake initialized")
def __init__(self, fullscreen): """Create a new anaconda main window. :param bool fullscreen: if True, fullscreen the window, if false maximize """ Gtk.Window.__init__(self) # Hide the titlebar when maximized if the window manager allows it. # This makes anaconda look full-screenish but without covering parts # needed to interact with the window manager, like the GNOME top bar. self.set_hide_titlebar_when_maximized(True) # The Anaconda and Initial Setup windows might sometimes get decorated with # a titlebar which contains the __init__.py header text by default. # As all Anaconda and Initial Setup usually have a very distinct title text # inside the window, the titlebar text is redundant and should be disabled. self.set_title(_(WINDOW_TITLE_TEXT)) # Set the icon used in the taskbar of window managers that have a taskbar # The "anaconda" icon is part of fedora-logos self.set_icon_name("anaconda") # Treat an attempt to close the window the same as hitting quit self.connect("delete-event", self._on_delete_event) # Create a black, 50% opacity pixel that will be scaled to fit the lightbox overlay # The confusing list of unnamed parameters is: # bytes, colorspace (there is no other colorspace), has-alpha, # bits-per-sample (has to be 8), width, height, # rowstride (bytes between row starts, but we only have one row) self._transparent_base = GdkPixbuf.Pixbuf.new_from_bytes(GLib.Bytes.new([0, 0, 0, 127]), GdkPixbuf.Colorspace.RGB, True, 8, 1, 1, 1) # Contain everything in an overlay so the window can be overlayed with the transparency # for the lightbox effect self._overlay = Gtk.Overlay() self._overlay_img = None self._overlay.connect("get-child-position", self._on_overlay_get_child_position) self._overlay_depth = 0 # Create a stack and a list of what's been added to the stack # Double the stack transition duration since the default 200ms is too # quick to get the point across self._stack = Gtk.Stack(transition_duration=400) self._stack_contents = set() # Create an accel group for the F12 accelerators added after window transitions self._accel_group = Gtk.AccelGroup() self.add_accel_group(self._accel_group) # Make the window big if fullscreen: self.fullscreen() else: self.maximize() self._overlay.add(self._stack) self.add(self._overlay) self.show_all() self._current_action = None # Help button mnemonics handling self._mnemonic_signal = None # we have a sensible initial value, just in case self._saved_help_button_label = _("Help!") # Apply the initial language attributes self._language = None self.reapply_language() # Keybinder from GI needs to be initialized before use Keybinder.init() Keybinder.bind("<Shift>Print", self._handle_print_screen, []) self._screenshot_index = 0