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 main(): """ Main function that starts everything """ if is_wayland() and gdk_backend().lower() != 'x11' and not is_wayland_compatibility_on(): warn = """ [!] Looks like you are in Wayland session Please run Ulauncher with env var GDK_BACKEND set to 'x11' like this: GDK_BACKEND=x11 ulauncher """ print(warn, file=sys.stderr) sys.exit(1) # start DBus loop DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() instance = bus.request_name(DBUS_SERVICE) if instance != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER: toggle_window = dbus.SessionBus().get_object(DBUS_SERVICE, DBUS_PATH).get_dbus_method("toggle_window") toggle_window() return _create_dirs() options = get_options() setup_logging(options) logger = logging.getLogger('ulauncher') logger.info('Ulauncher version %s' % get_version()) logger.info("GTK+ %s.%s.%s" % (Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version())) logger.info("Is Wayland: %s" % is_wayland()) logger.info("Wayland compatibility: %s" % ('on' if is_wayland_compatibility_on() else 'off')) # log uncaught exceptions def except_hook(exctype, value, tb): logger.error("Uncaught exception", exc_info=(exctype, value, tb)) sys.excepthook = except_hook window = UlauncherWindow.get_instance() UlauncherDbusService(window) if not options.hide_window: window.show() if Settings.get_instance().get_property('show-indicator-icon'): AppIndicator.get_instance().show() # workaround to make Ctrl+C quiting the app signal_handler = SignalHandler(window) gtk_thread = run_async(Gtk.main)() try: while gtk_thread.is_alive() and not signal_handler.killed(): time.sleep(0.5) except KeyboardInterrupt: logger.warn('On KeyboardInterrupt') finally: Gtk.main_quit()
def main(): """ Main function that starts everything """ # start DBus loop DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() instance = bus.request_name(DBUS_SERVICE) if instance != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER: print( "DBus name already taken. Ulauncher is probably backgrounded. Did you mean `ulauncher-toggle`?", file=sys.stderr) toggle_window = dbus.SessionBus().get_object( DBUS_SERVICE, DBUS_PATH).get_dbus_method("toggle_window") toggle_window() return _create_dirs() options = get_options() setup_logging(options) logger = logging.getLogger('ulauncher') logger.info('Ulauncher version %s', get_version()) logger.info('Extension API version %s', api_version) logger.info("GTK+ %s.%s.%s", Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version()) logger.info("Is Wayland: %s", is_wayland()) logger.info("Wayland compatibility: %s", ('on' if is_wayland_compatibility_on() else 'off')) # log uncaught exceptions def except_hook(exctype, value, tb): logger.error("Uncaught exception", exc_info=(exctype, value, tb)) sys.excepthook = except_hook window = UlauncherWindow.get_instance() UlauncherDbusService(window) if not options.hide_window: window.show() if Settings.get_instance().get_property('show-indicator-icon'): AppIndicator.get_instance().show() # workaround to make Ctrl+C quitting the app signal_handler = SignalHandler(window) gtk_thread = run_async(Gtk.main)() try: while gtk_thread.is_alive() and not signal_handler.killed(): time.sleep(0.5) except KeyboardInterrupt: logger.warning('On KeyboardInterrupt') finally: Gtk.main_quit()
def main(): """ Main function that starts everything """ # start DBus loop DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() instance = bus.request_name(DBUS_SERVICE) if instance != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER: print("Ulauncher is already running") show_window = dbus.SessionBus().get_object( DBUS_SERVICE, DBUS_PATH).get_dbus_method("show_window") show_window() return _create_dirs() options = get_options() setup_logging(options) logger = logging.getLogger('ulauncher') logger.info('Ulauncher version %s' % get_version()) logger.info("GTK+ %s.%s.%s" % (Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version())) # log uncaught exceptions def except_hook(exctype, value, tb): logger.error("Uncaught exception", exc_info=(exctype, value, tb)) sys.excepthook = except_hook window = UlauncherWindow.get_instance() UlauncherDbusService(window) if not options.hide_window: window.show() if Settings.get_instance().get_property('show-indicator-icon'): AppIndicator.get_instance().show() # workaround to make Ctrl+C quiting the app app_killer = GracefulAppKiller() gtk_thread = run_async(Gtk.main)() try: while gtk_thread.is_alive() and not app_killer.killed(): time.sleep(0.5) except KeyboardInterrupt: logger.warn('On KeyboardInterrupt') finally: Gtk.main_quit()
def prefs_set_show_indicator_icon(self, url_params): show_indicator = self._get_bool(url_params['query']['value']) logger.info('Set show-indicator-icon to %s', show_indicator) self.settings.set_property('show-indicator-icon', show_indicator) self.settings.save_to_file() indicator = AppIndicator.get_instance() GLib.idle_add(indicator.switch, show_indicator)
def on_show_indicator_icon_notify(self, widget, event): if event.name == 'active': show_indicator = widget.get_active() self.settings.set_property('show-indicator-icon', show_indicator) indicator = AppIndicator.get_instance() indicator.show() if show_indicator else indicator.hide() self.settings.save_to_file()
def prefs_set_show_indicator_icon(self, url_params): show_indicator = self._get_bool(url_params['query']['value']) logger.info('Set show-indicator-icon to %s' % show_indicator) self.settings.set_property('show-indicator-icon', show_indicator) self.settings.save_to_file() indicator = AppIndicator.get_instance() GLib.idle_add(indicator.switch, show_indicator)
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 main(): _create_dirs() options = parse_options() set_up_logging(options) logger = logging.getLogger('ulauncher') logger.info('Ulauncher version: %s' % get_version()) # start DBus loop DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() instance = bus.request_name(DBUS_SERVICE) if instance != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER: logger.debug("Getting the existing instance...") show_window = dbus.SessionBus().get_object( DBUS_SERVICE, DBUS_PATH).get_dbus_method("show_window") show_window() else: logger.debug("Starting a new instance...") window = UlauncherWindow.get_instance() UlauncherDbusService(window) if not options.hide_window: window.show() if Settings.get_instance().get_property('show-indicator-icon'): AppIndicator.get_instance().show() @run_async def run_main(): Gtk.main() main_thread = run_main() # workaround to make Ctrl+C quiting the app try: while main_thread.is_alive(): time.sleep(1) except KeyboardInterrupt: logger.info('On KeyboardInterrupt') Gtk.main_quit() main_thread.join() sys.exit(0)
def prefs_set(self, query): property = query['property'] value = query['value'] # This setting is not stored to the config if property == 'autostart-enabled': self.prefs_set_autostart(value) return self.settings.set_property(property, value) if property == 'show-indicator-icon': # pylint: disable=import-outside-toplevel from ulauncher.ui.windows.UlauncherWindow import UlauncherWindow ulauncher_window = UlauncherWindow.get_instance() GLib.idle_add(AppIndicator.get_instance(ulauncher_window).switch, value) if property == 'theme-name': self.prefs_apply_theme()
def main(): """ Main function that starts everything """ if is_wayland( ) and gdk_backend().lower() != 'x11' and not is_wayland_compatibility_on(): warn = """ [!] Looks like you are in Wayland session Please run Ulauncher with env var GDK_BACKEND set to 'x11' like this: GDK_BACKEND=x11 ulauncher """ print(warn, file=sys.stderr) sys.exit(1) # start DBus loop DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() instance = bus.request_name(DBUS_SERVICE) if instance != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER: toggle_window = dbus.SessionBus().get_object( DBUS_SERVICE, DBUS_PATH).get_dbus_method("toggle_window") toggle_window() return _create_dirs() options = get_options() setup_logging(options) logger = logging.getLogger('ulauncher') logger.info('Ulauncher version %s' % get_version()) logger.info("GTK+ %s.%s.%s" % (Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version())) logger.info("Is Wayland: %s" % is_wayland()) logger.info("Wayland compatibility: %s" % ('on' if is_wayland_compatibility_on() else 'off')) # log uncaught exceptions def except_hook(exctype, value, tb): logger.error("Uncaught exception", exc_info=(exctype, value, tb)) sys.excepthook = except_hook window = UlauncherWindow.get_instance() UlauncherDbusService(window) if not options.hide_window: window.show() if Settings.get_instance().get_property('show-indicator-icon'): AppIndicator.get_instance().show() # workaround to make Ctrl+C quiting the app signal_handler = SignalHandler(window) gtk_thread = run_async(Gtk.main)() try: while gtk_thread.is_alive() and not signal_handler.killed(): time.sleep(0.5) except KeyboardInterrupt: logger.warn('On KeyboardInterrupt') finally: Gtk.main_quit()
def toggle_appindicator(self, enable): if not self.appindicator: self.appindicator = AppIndicator(self) self.appindicator.switch(enable)
class UlauncherApp(Gtk.Application): # Gtk.Applications check if the app is already registered and if so, # new instances sends the signals to the registered one # So all methods except __init__ runs on the main app settings = Settings.get_instance() window = None # type: UlauncherWindow appindicator = None # type: AppIndicator _current_accel_name = None def __init__(self, *args, **kwargs): super().__init__( *args, application_id="net.launchpad.ulauncher", flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE, **kwargs ) self.connect("startup", self.setup) # runs only once on the main instance def do_before_emit(self, data): query = data.lookup_value("query", GLib.VariantType("s")) if query: self.window.initial_query = query.unpack() def do_activate(self, *args, **kwargs): self.window.show_window() def do_command_line(self, *args, **kwargs): # This is where we handle "--no-window" which we need to get from the remote call # All other aguments are persistent and handled in config.get_options() parser = argparse.ArgumentParser(prog='gui') parser.add_argument("--no-window", action="store_true") args, _ = parser.parse_known_args(args[0].get_arguments()[1:]) if not args.no_window: self.activate() return 0 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 toggle_appindicator(self, enable): if not self.appindicator: self.appindicator = AppIndicator(self) self.appindicator.switch(enable) def bind_hotkey(self, accel_name): if not IS_X11 or 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, lambda _: self.window.show_window()) self._current_accel_name = accel_name if FIRST_RUN: display_name = Gtk.accelerator_get_label(*Gtk.accelerator_parse(accel_name)) show_notification("Ulauncher", f"Hotkey is set to {display_name}") def show_preferences(self, page=None): self.window.hide() if not str or not isinstance(page, str): page = 'preferences' PreferencesWindow(application=self).show(page=page)