def launch_application(app_info, files=(), uris=(), paths=(), track=True, activate=True, desktop_file=None, screen=None): """ Launch @app_rec correctly, using a startup notification you may pass in either a list of Gio.Files in @files, or a list of @uris or @paths if @track, it is a user-level application if @activate, activate rather than start a new version @app_rec is either an GAppInfo or (GAppInfo, desktop_file_path) tuple Raises SpawnError on failed program start. """ assert app_info if paths: files = [Gio.File.new_for_path(p) for p in paths] if uris: files = [Gio.File.new_for_uri(p) for p in uris] svc = GetApplicationsMatcherService() app_id = application_id(app_info, desktop_file) if activate and svc.application_is_running(app_id): svc.application_to_front(app_id) return True # An launch callback closure for the @app_id def application_launch_callback(argv, pid, notify_id, files, timestamp): is_terminal = terminal.is_known_terminal_executable(argv[0]) if not is_terminal: svc.launched_application(app_id, pid) if track: launch_callback = application_launch_callback else: launch_callback = None try: desktop_launch.launch_app_info(app_info, files, timestamp=uievents.current_event_time(), desktop_file=desktop_file, launch_cb=launch_callback, screen=screen) except SpawnError: raise return True
def launch_application(app_info, files=(), uris=(), paths=(), track=True, activate=True, desktop_file=None): """ Launch @app_rec correctly, using a startup notification you may pass in either a list of gio.Files in @files, or a list of @uris or @paths if @track, it is a user-level application if @activate, activate rather than start a new version @app_rec is either an GAppInfo or (GAppInfo, desktop_file_path) tuple Raises LaunchError on failed program start. """ assert app_info from gio import File from glib import GError if paths: files = [File(p) for p in paths] if uris: files = [File(p) for p in uris] svc = GetApplicationsMatcherService() app_id = application_id(app_info, desktop_file) if activate and svc.application_is_running(app_id): svc.application_to_front(app_id) return True # An launch callback closure for the @app_id def application_launch_callback(argv, pid, notify_id, files, timestamp): pretty.print_debug(__name__, "Launched", argv, pid, notify_id, files) is_terminal = terminal.is_known_terminal_executable(argv[0]) pretty.print_debug(__name__, argv, "is terminal:", is_terminal) if not is_terminal: svc.launched_application(app_id, pid) if track: launch_callback = application_launch_callback else: launch_callback = None try: desktop_launch.launch_app_info(app_info, files, timestamp=_current_event_time(), desktop_file=desktop_file, launch_cb=launch_callback) except desktop_launch.SpawnError as exc: raise LaunchError(unicode(exc)) return True
def launch_application(app_info, files=(), uris=(), paths=(), track=True, activate=True, desktop_file=None, screen=None): """ Launch @app_rec correctly, using a startup notification you may pass in either a list of gio.Files in @files, or a list of @uris or @paths if @track, it is a user-level application if @activate, activate rather than start a new version @app_rec is either an GAppInfo or (GAppInfo, desktop_file_path) tuple Raises SpawnError on failed program start. """ assert app_info if paths: files = [gio.File(p) for p in paths] if uris: files = [gio.File(p) for p in uris] svc = GetApplicationsMatcherService() app_id = application_id(app_info, desktop_file) if activate and svc.application_is_running(app_id): svc.application_to_front(app_id) return True # An launch callback closure for the @app_id def application_launch_callback(argv, pid, notify_id, files, timestamp): is_terminal = terminal.is_known_terminal_executable(argv[0]) if not is_terminal: svc.launched_application(app_id, pid) if track: launch_callback = application_launch_callback else: launch_callback = None try: desktop_launch.launch_app_info(app_info, files, timestamp=uievents.current_event_time(), desktop_file=desktop_file, launch_cb=launch_callback, screen=screen) except SpawnError: raise return True