Skip to content

Commit

Permalink
* fix py3k strings..
Browse files Browse the repository at this point in the history
* catch signals in mdns / sessions gui and return a non-zero exit_code

git-svn-id: https://xpra.org/svn/Xpra/trunk@17498 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Nov 25, 2017
1 parent 45b6e18 commit 6a226c3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/xpra/client/gtk_base/mdns_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import sys

from xpra.gtk_common.gobject_compat import import_gtk, import_glib
gtk = import_gtk()
glib = import_glib()
Expand Down Expand Up @@ -57,14 +59,16 @@ def do_main(opts):
if not get_listener_class():
command_error("no mDNS support in this build")
return 1
mdns_sessions(opts)
gui = mdns_sessions(opts)
gtk_main()
return gui.exit_code

def main():
from xpra.scripts.config import make_defaults_struct
opts = make_defaults_struct()
do_main(opts)
return do_main(opts)


if __name__ == "__main__":
main()
r = main()
sys.exit(r)
20 changes: 16 additions & 4 deletions src/xpra/client/gtk_base/sessions_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SessionsGUI(gtk.Window):

def __init__(self, options, title="Xpra Session Browser"):
gtk.Window.__init__(self)
self.exit_code = 0
self.set_title(title)
self.set_border_width(20)
self.set_resizable(True)
Expand Down Expand Up @@ -83,6 +84,9 @@ def __init__(self, options, title="Xpra Session Browser"):
glib.timeout_add(5*1000, self.poll_local_sessions)
self.populate_table()

import signal
signal.signal(signal.SIGINT, self.app_signal)
signal.signal(signal.SIGTERM, self.app_signal)
self.show_all()

def quit(self, *args):
Expand All @@ -93,6 +97,11 @@ def do_quit(self):
log("do_quit()")
gtk.main_quit()

def app_signal(self, signum, _frame):
self.exit_code = 128 + signum
log("app_signal(%s, %s) exit_code=%i", signum, _frame, self.exit_code)
self.do_quit()


def poll_local_sessions(self):
#TODO: run in a thread so we don't block the UI thread!
Expand Down Expand Up @@ -155,7 +164,7 @@ def get_session_info(self, sockpath):
out = strtobytes(stdout)
info = {}
for line in out.splitlines():
parts = line.split("=", 1)
parts = line.split(b"=", 1)
if len(parts)==2:
info[parts[0]] = parts[1]
return info
Expand Down Expand Up @@ -316,14 +325,17 @@ def do_main(opts):
from xpra.log import enable_color
with program_context("Xpra-Session-Browser", "Xpra Session Browser"):
enable_color()
SessionsGUI(opts)
gui = SessionsGUI(opts)
gtk_main()
log.info("do_main() gui.exit_code=%i", gui.exit_code)
return gui.exit_code

def main():
from xpra.scripts.config import make_defaults_struct
opts = make_defaults_struct()
do_main(opts)
return do_main(opts)


if __name__ == "__main__":
main()
r = main()
sys.exit(r)
6 changes: 3 additions & 3 deletions src/xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ def parse_display_name(error_cb, opts, display_name):
pos +=1
if protocol=="socket":
#socket paths may start with a slash!
#in which case the slash is part of the path, not the seperator!
#in which case the last slash is part of the path, not the seperator!
if psep==":/" or psep==":///":
psep = psep[:-1]
pos -= 1
Expand Down Expand Up @@ -3040,15 +3040,15 @@ def run_sessions_gui(error_cb, options):
if mdns:
return run_mdns_gui(error_cb, options)
from xpra.client.gtk_base import sessions_gui
sessions_gui.do_main(options)
return sessions_gui.do_main(options)

def run_mdns_gui(error_cb, options):
from xpra.net.mdns import get_listener_class
listener = get_listener_class()
if not listener:
error_cb("sorry, 'mdns-gui' is not supported on this platform yet")
from xpra.client.gtk_base import mdns_gui
mdns_gui.do_main(options)
return mdns_gui.do_main(options)

def run_list_mdns(error_cb, extra_args):
no_gtk()
Expand Down

0 comments on commit 6a226c3

Please sign in to comment.