Python gi.repository.Gtk.Application() Examples

The following are 30 code examples of gi.repository.Gtk.Application(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gtk , or try the search function .
Example #1
Source File: test_gireactor.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def test_cantRegisterAfterRun(self):
        """
        It is not possible to register a C{Application} after the reactor has
        already started.
        """
        reactor = gireactor.GIReactor(useGtk=False)
        self.addCleanup(self.unbuildReactor, reactor)
        app = Gio.Application(
            application_id='com.twistedmatrix.trial.gireactor',
            flags=Gio.ApplicationFlags.FLAGS_NONE)

        def tryRegister():
            exc = self.assertRaises(ReactorAlreadyRunning,
                                    reactor.registerGApplication, app)
            self.assertEqual(exc.args[0],
                             "Can't register application after reactor was started.")
            reactor.stop()
        reactor.callLater(0, tryRegister)
        ReactorBuilder.runReactor(self, reactor) 
Example #2
Source File: settsmanager.py    From AutomaThemely with GNU General Public License v3.0 6 votes vote down vote up
def do_startup(self):
        Gtk.Application.do_startup(self)
        self.builder = Gtk.Builder()
        self.builder.add_from_file(get_resource('manager_gui.glade'))
        self.builder.set_application(self)
        self.builder.connect_signals(self)

        # This does not get initialized until needed
        self.extras = dict()

        self.system_themes = envspecific.get_installed_themes(self.us_se['desktop_environment'])

        self.listen_changes = False
        self.saved_settings = False
        self.entries_error = list()
        self.changed = list()

        #   Override the quit menu
        action = Gio.SimpleAction.new("quit", None)
        action.connect("activate", self.on_confirm_exit)
        self.add_action(action)

    # noinspection PyAttributeOutsideInit 
Example #3
Source File: Main.py    From pychess with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, log_viewer, purge_recent, chess_file, ics_host, ics_port, loop, splash, version_check):
        Gtk.Application.__init__(self,
                                 application_id="org.pychess",
                                 flags=Gio.ApplicationFlags.NON_UNIQUE)
        self.loop = loop

        if ics_host:
            ICLogon.host = ics_host
        if ics_port:
            ICLogon.port = ics_port

        self.log_viewer = log_viewer
        self.purge_recent = purge_recent
        self.chess_file = chess_file
        self.window = None
        self.splash = splash
        self.version_check = version_check 
Example #4
Source File: application.py    From gtg with GNU General Public License v3.0 6 votes vote down vote up
def do_activate(self):
        """Callback when launched from the desktop."""

        # Browser (still hidden)
        if not self.browser:
            self.browser = MainWindow(self.req, self)

        if self.props.application_id == 'org.gnome.GTGDevel':
            self.browser.get_style_context().add_class('devel')

        self.init_actions()
        self.init_plugin_engine()
        self.browser.present()
        self.open_uri_list()

        log.debug("Application activation finished") 
Example #5
Source File: main.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, application, window):
		utilities.assert_arg_type(application, Gtk.Application, arg_pos=1)
		utilities.assert_arg_type(window, MainAppWindow, arg_pos=2)
		super(MainMenuBar, self).__init__(application)
		self.window = weakref.proxy(window)
		self._add_accelerators()
		graphs_menu_item = self.gtk_builder_get('menuitem_tools_create_graph')
		if graphs.has_matplotlib:
			graphs_submenu = Gtk.Menu.new()
			for graph_name in graphs.get_graphs():
				graph = graphs.get_graph(graph_name)
				menu_item = Gtk.MenuItem.new_with_label(graph.name_human)
				menu_item.connect('activate', self.signal_activate_tools_show_campaign_graph, graph_name)
				graphs_submenu.append(menu_item)
			graphs_menu_item.set_submenu(graphs_submenu)
			graphs_menu_item.show_all()
		else:
			graphs_menu_item.set_sensitive(False) 
Example #6
Source File: plugin_manager.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, application, plugin_id):
		"""
		:param application: The parent application for this object.
		:type application: :py:class:`Gtk.Application`
		:param str plugin_id: The identifier of this plugin.
		"""
		super(PluginDocumentationWindow, self).__init__(application)
		plugin_path = self.application.plugin_manager.get_plugin_path(plugin_id)
		if plugin_path is None:
			raise FileNotFoundError(errno.ENOENT, "could not find the data path for plugin '{0}'".format(plugin_id))
		md_file = os.path.join(plugin_path, 'README.md')
		if md_file is None or not os.path.isfile(md_file):
			self.window.destroy()
			raise FileNotFoundError(errno.ENOENT, "plugin '{0}' has no documentation".format(plugin_id), md_file)
		self._md_file = md_file
		self._plugin = self.application.plugin_manager[plugin_id]
		self.refresh()
		self.webview.connect('key-press-event', self.signal_key_press_event)
		self.webview.connect('open-remote-uri', self.signal_webview_open_remote_uri)
		self.window.set_title('Plugin Documentation') 
Example #7
Source File: exception.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, application, exc_info=None, error_uid=None):
		"""
		:param application: The parent application for this object.
		:type application: :py:class:`Gtk.Application`
		:param tuple exc_info: The exception information as provided by :py:func:`sys.exc_info`.
		:param str error_uid: An optional unique identifier for the exception that can be provided for tracking purposes.
		"""
		super(ExceptionDialog, self).__init__(application)
		self.error_description = self.gtk_builder_get('label_error_description')
		self.error_details = self.gtk_builder_get('textview_error_details')
		self.error_details.modify_font(Pango.FontDescription('monospace 9'))
		self.exc_info = exc_info or sys.exc_info()
		self.error_uid = error_uid
		linkbutton = self.gobjects['linkbutton_github_issues']
		linkbutton.set_label('Project Issue Tracker')
		linkbutton.connect('activate-link', lambda _: utilities.open_uri(linkbutton.get_property('uri'))) 
Example #8
Source File: app.py    From vimiv with MIT License 6 votes vote down vote up
def __init__(self, running_tests=False):
        """Create the Gtk.Application and connect the activate signal.

        Args:
            running_tests: If True, running from test suite. Do not show pop-up
                windows and do not parse user configuration files.
        """
        # Init application and set default values
        app_id = "org.vimiv" + str(time()).replace(".", "")
        super(Vimiv, self).__init__(application_id=app_id)
        self.set_flags(Gio.ApplicationFlags.HANDLES_OPEN)
        self.connect("activate", self.activate_vimiv)
        self._paths = []
        self._index = 0
        self._widgets = {}
        self.debug = False
        self._tmpdir = None
        self.running_tests = running_tests
        # Set up all commandline options
        self._init_commandline_options() 
Example #9
Source File: test_gireactor.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def test_cantRegisterAfterRun(self):
        """
        It is not possible to register a C{Application} after the reactor has
        already started.
        """
        reactor = gireactor.GIReactor(useGtk=False)
        self.addCleanup(self.unbuildReactor, reactor)
        app = Gio.Application(
            application_id='com.twistedmatrix.trial.gireactor',
            flags=Gio.ApplicationFlags.FLAGS_NONE)

        def tryRegister():
            exc = self.assertRaises(ReactorAlreadyRunning,
                                    reactor.registerGApplication, app)
            self.assertEqual(exc.args[0],
                             "Can't register application after reactor was started.")
            reactor.stop()
        reactor.callLater(0, tryRegister)
        ReactorBuilder.runReactor(self, reactor) 
Example #10
Source File: __main__.py    From HydraPaper with GNU General Public License v3.0 6 votes vote down vote up
def do_command_line(self, args):
        """
        GTK.Application command line handler
        called if Gio.ApplicationFlags.HANDLES_COMMAND_LINE is set.
        must call the self.do_activate() to get the application up and running.
        """
        Gtk.Application.do_command_line(self, args)  # call the default commandline handler
        # make a command line parser
        parser = argparse.ArgumentParser(prog='gui')
        # add a -c/--color option
        parser.add_argument('-q', '--quit-after-init', dest='quit_after_init', action='store_true', help='initialize application (e.g. for macros initialization on system startup) and quit')
        # parse the command line stored in args, but skip the first element (the filename)
        self.args = parser.parse_args(args.get_arguments()[1:])
        # call the main program do_activate() to start up the app
        self.do_activate()
        return 0 
Example #11
Source File: __main__.py    From razerCommander with GNU General Public License v3.0 6 votes vote down vote up
def do_command_line(self, args):
        '''
        GTK.Application command line handler
        called if Gio.ApplicationFlags.HANDLES_COMMAND_LINE is set.
        must call the self.do_activate() to get the application up and running.
        '''
        Gtk.Application.do_command_line(self, args)  # call the default commandline handler
        # make a command line parser
        parser = argparse.ArgumentParser(prog='gui')
        # add a -c/--color option
        parser.add_argument('-q', '--quit-after-init', dest='quit_after_init', action='store_true', help='initialize application (e.g. for macros initialization on system startup) and quit')
        # parse the command line stored in args, but skip the first element (the filename)
        self.args = parser.parse_args(args.get_arguments()[1:])
        # call the main program do_activate() to start up the app
        self.do_activate()
        return 0 
Example #12
Source File: main.py    From mLauncher with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
		Gtk.Application.__init__(self, application_id="com.gabmus.mlauncher", flags=Gio.ApplicationFlags.FLAGS_NONE)


		builder.get_object("aboutdialog").connect("delete-event", lambda *_: builder.get_object("aboutdialog").hide() or True)
		self.connect("activate", self.activateCb) 
Example #13
Source File: app.py    From runsqlrun with MIT License 5 votes vote down vote up
def __init__(self, args):
        super(Application, self).__init__(
            application_id='org.runsqlrun',
            flags=Gio.ApplicationFlags.FLAGS_NONE)
        self.args = args
        self.win = None 
Example #14
Source File: main.py    From mLauncher with GNU General Public License v3.0 5 votes vote down vote up
def do_startup(self):
	# start the application
		Gtk.Application.do_startup(self) 
Example #15
Source File: gtk.py    From bups with MIT License 5 votes vote down vote up
def do_startup(self):
		Gtk.Application.do_startup(self) 
Example #16
Source File: application.py    From Apostrophe with GNU General Public License v3.0 5 votes vote down vote up
def on_preview_mode(self, action, value):
        action.set_state(value)
        self.settings.set_string("preview-mode", value.get_string())

# ~ if __name__ == "__main__":
    # ~ app = Application()
    # ~ app.run(sys.argv) 
Example #17
Source File: __main__.py    From HydraPaper with GNU General Public License v3.0 5 votes vote down vote up
def main():
    application = Application()

    try:
        ret = application.run(sys.argv)
    except SystemExit as e:
        ret = e.code

    sys.exit(ret) 
Example #18
Source File: settsmanager.py    From AutomaThemely with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, us_se):
        super().__init__(application_id="com.github.c2n14.automathemely",
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.main_window = None
        self.us_se = us_se

    #       BASIC Gtk.Application FUNCTIONS
    # noinspection PyAttributeOutsideInit 
Example #19
Source File: settsmanager.py    From AutomaThemely with GNU General Public License v3.0 5 votes vote down vote up
def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

        #   Dump file
        if self.changed and self.saved_settings:
            with open(get_local('user_settings.json'), 'w') as file:
                json.dump(self.us_se, file, indent=4)
            exit_message = 'Successfully saved settings'
        else:
            exit_message = 'No changes were made'

        logger.info(exit_message)

    #      MISC
    # Called on primary activation 
Example #20
Source File: gtk.py    From bups with MIT License 5 votes vote down vote up
def __init__(self):
		Gtk.Application.__init__(self) 
Example #21
Source File: main.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
def main(version):
	app = Application(version)
	return app.run(sys.argv)

################################################################################ 
Example #22
Source File: colors_list.py    From oomox with GNU General Public License v3.0 5 votes vote down vote up
def get_fuzzy_ancestor(self, desired_class):
        potential_ancestor = self.get_parent()
        while not isinstance(potential_ancestor, desired_class):
            potential_ancestor = potential_ancestor.get_parent()
            if isinstance(potential_ancestor, Gtk.Application):
                break
        else:
            return potential_ancestor 
Example #23
Source File: main.py    From oomox with GNU General Public License v3.0 5 votes vote down vote up
def do_startup(self):  # pylint: disable=arguments-differ

        Gtk.Application.do_startup(self)

        quit_action = Gio.SimpleAction.new(
            AppActions.quit, None
        )
        quit_action.connect("activate", self._on_quit)
        self.add_action(quit_action)

        def set_accels_for_action(action, accels):
            self.set_accels_for_action(action.get_id(), accels)

        set_accels_for_action(AppActions.quit, ["<Primary>Q"])

        set_accels_for_action(WindowActions.import_menu, ["<Primary>M"])
        set_accels_for_action(WindowActions.clone, ["<Shift><Primary>S"])
        set_accels_for_action(WindowActions.save, ["<Primary>S"])
        set_accels_for_action(WindowActions.rename, ["F2"])
        set_accels_for_action(WindowActions.remove, ["<Primary>Delete"])
        set_accels_for_action(WindowActions.export_theme, ["<Primary>E"])
        set_accels_for_action(WindowActions.export_icons, ["<Primary>I"])
        set_accels_for_action(WindowActions.export_menu, ["<Primary>O"])
        set_accels_for_action(WindowActions.export_terminal, ["<Primary>X"])
        set_accels_for_action(WindowActions.menu, ["F10"])
        set_accels_for_action(WindowActions.show_help, ["<Primary>question"]) 
Example #24
Source File: main.py    From dynamic-wallpaper-editor with GNU General Public License v3.0 5 votes vote down vote up
def main(version):
	app = Application(version)
	return app.run(sys.argv)

################################################################################ 
Example #25
Source File: main.py    From hazzy with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        Gtk.Application.__init__(self)

        # Get the XML file path
        self.xml_file = ini_info.get_xml_file()

        self.settings = Gtk.Settings.get_default()
        self.set_gtk_theme('Adwaita')

        log_time('done initializing') 
Example #26
Source File: test_gireactor.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_noQuit(self):
        """
        Older versions of PyGObject lack C{Application.quit}, and so won't
        allow registration.
        """
        reactor = gireactor.GIReactor(useGtk=False)
        self.addCleanup(self.unbuildReactor, reactor)
        # An app with no "quit" method:
        app = object()
        exc = self.assertRaises(RuntimeError, reactor.registerGApplication, app)
        self.assertTrue(exc.args[0].startswith(
                "Application registration is not")) 
Example #27
Source File: test_gireactor.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_portable(self):
        """
        L{gireactor.PortableGIReactor} doesn't support application
        registration at this time.
        """
        reactor = gireactor.PortableGIReactor()
        self.addCleanup(self.unbuildReactor, reactor)
        app = Gio.Application(
            application_id='com.twistedmatrix.trial.gireactor',
            flags=Gio.ApplicationFlags.FLAGS_NONE)
        self.assertRaises(NotImplementedError,
                          reactor.registerGApplication, app) 
Example #28
Source File: test_gireactor.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_gtkApplicationActivate(self):
        """
        L{Gtk.Application} instances can be registered with a gtk3reactor.
        """
        reactor = gtk3reactor.Gtk3Reactor()
        self.addCleanup(self.unbuildReactor, reactor)
        app = Gtk.Application(
            application_id='com.twistedmatrix.trial.gtk3reactor',
            flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.runReactor(app, reactor) 
Example #29
Source File: test_gireactor.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_gApplicationActivate(self):
        """
        L{Gio.Application} instances can be registered with a gireactor.
        """
        reactor = gireactor.GIReactor(useGtk=False)
        self.addCleanup(self.unbuildReactor, reactor)
        app = Gio.Application(
            application_id='com.twistedmatrix.trial.gireactor',
            flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.runReactor(app, reactor) 
Example #30
Source File: app.py    From syncthing-gtk with GNU General Public License v2.0 5 votes vote down vote up
def quit(self, *a):
		if self.process != None:
			if IS_WINDOWS:
				# Always kill subprocess on windows
				self.process.kill()
				self.process = None
			elif self.config["autokill_daemon"] == 2:	# Ask
				d = Gtk.MessageDialog(
					self["window"],
					Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
					Gtk.MessageType.INFO, 0,
					"%s\n%s" % (
						_("Exiting."),
						_("Shutdown Syncthing daemon as well?")
						)
					)
				d.add_button("gtk-yes",	RESPONSE_SLAIN_DAEMON)
				d.add_button("gtk-no",	RESPONSE_SPARE_DAEMON)
				cb = Gtk.CheckButton(_("Always do same; Don't show this window again"))
				d.get_content_area().pack_end(cb, False, False, 2)
				d.connect("response", self.cb_kill_daemon_response, cb)
				d.show_all()
				return
			elif self.config["autokill_daemon"] == 1: # Yes
				self.process.terminate()
				self.process = None
		Gtk.Application.quit(self)