diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2020-03-26 23:17:07 +0100 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2020-03-26 23:17:07 +0100 |
commit | 5e745a2faa5f2780e4ebcd42ea0105bdd9c8bd57 (patch) | |
tree | d63642c99532a29cfa654614e168e6811fdc5031 | |
parent | fc1ad7466c03192073197edb3dd5eddbc3fcbf20 (diff) | |
download | d-feet-5e745a2faa5f2780e4ebcd42ea0105bdd9c8bd57.tar.gz |
DFeetApp: add --version
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
-rw-r--r-- | src/dfeet/application.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/dfeet/application.py b/src/dfeet/application.py index 920f67b..7f4f44a 100644 --- a/src/dfeet/application.py +++ b/src/dfeet/application.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import print_function -from gi.repository import Gtk, Gio, GObject, Gdk +from gi.repository import Gtk, Gio, GObject, Gdk, GLib from dfeet.window import DFeetWindow import gettext import os @@ -9,6 +9,20 @@ import os _ = gettext.gettext +def make_option(long_name, short_name=None, flags=0, arg=GLib.OptionArg.NONE, + arg_data=None, description=None, arg_description=None): + # surely something like this should exist inside PyGObject itself?! + option = GLib.OptionEntry() + option.long_name = long_name.lstrip('-') + option.short_name = 0 if not short_name else short_name.lstrip('-') + option.flags = flags + option.arg = arg + option.arg_data = arg_data + option.description = description + option.arg_description = arg_description + return option + + class DFeetApp(Gtk.Application): def __init__(self, package, version, data_dir): @@ -17,6 +31,16 @@ class DFeetApp(Gtk.Application): self.data_dir = data_dir Gtk.Application.__init__(self, application_id="org.gnome.dfeet", flags=Gio.ApplicationFlags.FLAGS_NONE) + self.add_main_option_entries([ + make_option("--version", description=_("Show version number and exit")), + ]) + + def do_handle_local_options(self, options): + self.options = options + if options.contains("version"): + print(_("D-Feet version: {}").format(self.version)) + return 0 + return -1 # Note that the function in C activate() becomes do_activate() in Python def do_activate(self): |