diff options
author | Thomas Bechtold <thomasbechtold@jpberlin.de> | 2020-04-15 09:53:26 +0000 |
---|---|---|
committer | Thomas Bechtold <thomasbechtold@jpberlin.de> | 2020-04-15 09:53:26 +0000 |
commit | 9181df754095e47f9d767d43613bdafe4d6ab871 (patch) | |
tree | b50781f451fca133ebe02dcb04c72cc5fa3092fa | |
parent | 54bdef31dc41832590608ec9e7f3cf685c79531b (diff) | |
parent | b14c926569ad40d5201787b64f5537eda578c92c (diff) | |
download | d-feet-9181df754095e47f9d767d43613bdafe4d6ab871.tar.gz |
Merge branch 'cmdline' into 'master'
A few improvements & --address=ADDRESS support
See merge request GNOME/d-feet!25
-rw-r--r-- | README | 23 | ||||
-rw-r--r-- | README.md | 23 | ||||
-rw-r--r-- | src/dfeet/application.py | 32 | ||||
-rw-r--r-- | src/dfeet/meson.build | 1 | ||||
-rw-r--r-- | src/dfeet/window.py | 31 |
5 files changed, 74 insertions, 36 deletions
@@ -1,23 +0,0 @@ -Welcome to D-Feet (https://wiki.gnome.org/Apps/DFeet) - -Requirements: - -python >= 2.7 -python-gi >= 3.3.91 -gtk >= 3.6 - -Optional Requriements: - -gnome-python-libwnck - for displaying application icons next to the application - -To run localy for testing, install it using the prefix option: - -meson --prefix=/tmp/d-feet && ninja -C _build install - -And then execute it: - -/tmp/d-feet/bin/d-feet - -To install in the system: - -meson _build && ninja -C _build install diff --git a/README.md b/README.md new file mode 100644 index 0000000..1cecf79 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Welcome to [D-Feet](https://wiki.gnome.org/Apps/DFeet) + +Requirements: + + - python >= 2.7 + - python-gi >= 3.3.91 + - gtk >= 3.6 + +Optional Requirements: + + - gnome-python-libwnck - for displaying application icons next to the application + +To run localy for testing, install it using the prefix option: + + meson --prefix=/tmp/d-feet _build && ninja -C _build install + +And then execute it: + + /tmp/d-feet/bin/d-feet + +To install in the system: + + meson _build && ninja -C _build install diff --git a/src/dfeet/application.py b/src/dfeet/application.py index 920f67b..5d88e00 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,10 +31,26 @@ 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")), + make_option("--address", arg=GLib.OptionArg.STRING, arg_description="ADDRESS", + description=_("Open the specified bus address")), + ]) + + 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): self._main_win = DFeetWindow(self, self.version, self.data_dir) + if self.options.contains("address"): + address = self.options.lookup_value("address").get_string() + if not self._main_win.connect_to(address): + self.quit() # Note that the function in C startup() becomes do_startup() in Python def do_startup(self): diff --git a/src/dfeet/meson.build b/src/dfeet/meson.build index f1460d5..fa7f144 100644 --- a/src/dfeet/meson.build +++ b/src/dfeet/meson.build @@ -16,4 +16,5 @@ df_data = files( python.install_sources( df_data, subdir: 'dfeet', + pure: true, ) diff --git a/src/dfeet/window.py b/src/dfeet/window.py index bfc08cc..01b6032 100644 --- a/src/dfeet/window.py +++ b/src/dfeet/window.py @@ -147,6 +147,24 @@ class DFeetWindow(Gtk.ApplicationWindow): except Exception as e: print(e) + def connect_to(self, address): + """connect to given bus address""" + try: + bw = BusWatch(self.data_dir, address) + self.stack.add_titled(bw.box_bus, address, address) + self.stack.set_visible_child_name(address) + # Fill history + if address in self.bus_history: + self.bus_history.remove(address) + self.bus_history.insert(0, address) + # Truncating history + if (len(self.bus_history) > self.HISTORY_MAX_SIZE): + self.bus_history = self.bus_history[0:self.HISTORY_MAX_SIZE] + except Exception as e: + print("can not connect to '%s': %s" % (address, str(e))) + return False + return True + def __action_connect_other_bus_cb(self, action, parameter): """connect to other bus""" dialog = AddConnectionDialog(self.data_dir, self, self.bus_history) @@ -160,18 +178,7 @@ class DFeetWindow(Gtk.ApplicationWindow): self.activate_action('connect-system-bus', None) return else: - try: - bw = BusWatch(self.data_dir, address) - self.stack.add_titled(bw.box_bus, address, address) - # Fill history - if address in self.bus_history: - self.bus_history.remove(address) - self.bus_history.insert(0, address) - # Truncating history - if (len(self.bus_history) > self.HISTORY_MAX_SIZE): - self.bus_history = self.bus_history[0:self.HISTORY_MAX_SIZE] - except Exception as e: - print("can not connect to '%s': %s" % (address, str(e))) + self.connect_to(address) dialog.destroy() def __action_close_bus_cb(self, action, parameter): |