summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Wright <fw@fwright.net>2016-11-26 17:20:41 -0800
committerJon Schlueter <jon.schlueter@gmail.com>2016-12-18 22:27:55 -0500
commit116c0b548aa8ce5430c9f19a40534b1056268f5b (patch)
tree105abf8b2b810a0018c0ac64f71c993ba09098a7
parent40b8f6657f3766926900c7c552b0c25972d0230a (diff)
downloadgpsd-116c0b548aa8ce5430c9f19a40534b1056268f5b.tar.gz
Tweaks xgps and xgpsspeed UIs.
This makes a couple of minor improvements to the xgps[speed] UIs: 1) If a target (host/port/device) is specified, it is included in the window title. This is especially useful when running multiple instances pointing at different targets. 2) Interprets blank host and/or port fields in host:port:device notation as the default values. This allows, e.g., specifying a device without having to explicitly specify the default host/port. Also replaces all hardcoded '2947' instances with gps.GPSD_PORT. TESTED: Tried various arguments, including using the option forms in xgpsspeed. Also tried a long string of leading zeroes on the port number to verify that a ridiculously long target string is taken in stride.
-rwxr-xr-xxgps15
-rwxr-xr-xxgpsspeed28
2 files changed, 29 insertions, 14 deletions
diff --git a/xgps b/xgps
index 44ea0628..d27b273c 100755
--- a/xgps
+++ b/xgps
@@ -462,7 +462,7 @@ class Base(object):
("EPD", lambda s, r: s.update_err_degrees(r, "epd")),
)
- def __init__(self, deg_type, rotate=0.0):
+ def __init__(self, deg_type, rotate=0.0, target=[]):
self.deg_type = deg_type
self.rotate = rotate
self.conversions = unit_adjustments()
@@ -473,7 +473,7 @@ class Base(object):
self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
if not self.window.get_display():
raise Exception("Can't open display")
- self.window.set_title("xgps")
+ self.window.set_title(" ".join(["xgps"] + target))
self.window.connect("delete_event", self.delete_event)
self.window.set_resizable(False)
@@ -901,17 +901,20 @@ if __name__ == "__main__":
'm': gps.clienthelpers.deg_ddmm,
's': gps.clienthelpers.deg_ddmmss}[degreefmt]
- (host, port, device) = ("localhost", "2947", None)
+ (host, port, device) = ("localhost", gps.GPSD_PORT, None)
if len(arguments):
args = arguments[0].split(":")
- if len(args) >= 1:
+ if len(args) >= 1 and args[0]:
host = args[0]
- if len(args) >= 2:
+ if len(args) >= 2 and args[1]:
port = args[1]
if len(args) >= 3:
device = args[2]
+ target = arguments[0:]
+ else:
+ target = []
- base = Base(deg_type=degreefmt, rotate=rotate)
+ base = Base(deg_type=degreefmt, rotate=rotate, target=target)
base.set_units(unit_system)
try:
daemon = gps.gps(host=host,
diff --git a/xgpsspeed b/xgpsspeed
index 29a6fc7d..612018f9 100755
--- a/xgpsspeed
+++ b/xgpsspeed
@@ -516,8 +516,9 @@ class NauticalSpeedometer(Speedometer):
class Main(object):
- def __init__(self, host='localhost', port='2947', device=None, debug=0,
- speed_unit=None, maxspeed=0, nautical=False, rotate=0.0):
+ def __init__(self, host='localhost', port=gps.GPSD_PORT, device=None,
+ debug=0, speed_unit=None, maxspeed=0, nautical=False,
+ rotate=0.0, target=[]):
self.host = host
self.port = port
self.device = device
@@ -529,7 +530,7 @@ class Main(object):
self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
if not self.window.get_display():
raise Exception("Can't open display")
- self.window.set_title('xgpsspeed')
+ self.window.set_title(' '.join(['xgpsspeed'] + target))
if self.nautical:
self.window.set_size_request(500, 550)
self.widget = NauticalSpeedometer(
@@ -690,14 +691,14 @@ if __name__ == '__main__':
parser.add_option(
'--host',
dest='host',
- default='localhost',
+ default=None,
help='The host to connect. [Default localhost]'
)
parser.add_option(
'--port',
dest='port',
- default='2947',
- help='The port to connect. [Default 2947]'
+ default=None,
+ help='The port to connect. [Default %s]' % gps.GPSD_PORT
)
parser.add_option(
'--device',
@@ -760,13 +761,24 @@ if __name__ == '__main__':
else:
parser.print_help()
sys.exit(0)
+ target = args[0:]
+ elif options.host or options.port or options.device:
+ target = [options.host or 'localhost']
+ if options.port or options.device:
+ target += [options.port or '']
+ if options.device:
+ target += [options.device]
+ target = [':'.join(target)]
+ else:
+ target = []
Main(
- host=options.host,
- port=options.port,
+ host=options.host or 'localhost',
+ port=options.port or gps.GPSD_PORT,
device=options.device,
speed_unit=options.speedunits,
maxspeed=options.maxspeed,
nautical=options.nautical,
debug=options.debug,
rotate=options.rotate,
+ target=target,
).run()