[d-feet: 5/7] DFeetApp: add --version
- From: Thomas Bechtold <toabctl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [d-feet: 5/7] DFeetApp: add --version
- Date: Wed, 15 Apr 2020 09:53:58 +0000 (UTC)
commit 5e745a2faa5f2780e4ebcd42ea0105bdd9c8bd57
Author: Marc-André Lureau <marcandre lureau redhat com>
Date: Thu Mar 26 23:17:07 2020 +0100
DFeetApp: add --version
Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>
src/dfeet/application.py | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
---
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):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]