From ee63003048ac062b47d39088c58aca7a989dce45 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Fri, 25 Apr 2008 11:58:07 +0200 Subject: [PATCH] Check for available X DISPLAY when creating window Make sure we error out and exit when the X display is not available, if we try to create a window. Also modify utils.quit_dragbox() to handle the case where we are outside the gtk main loop. --- Dragbox/utils.py | 9 +++++++-- Dragbox/window.py | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Dragbox/utils.py b/Dragbox/utils.py index eb0f08b..6189d81 100644 --- a/Dragbox/utils.py +++ b/Dragbox/utils.py @@ -62,13 +62,18 @@ def quit_dragbox(): """ terinates the gtk loop and exits """ - from gtk import main_quit - main_quit() + from gtk import main_quit, main_level + from sys import exit # Make sure we output it all from sys import stdout, stderr stdout.flush() stderr.flush() + + if main_level(): + main_quit() + else: + exit() def print_error(string): """ diff --git a/Dragbox/window.py b/Dragbox/window.py index f0ed281..da2906b 100644 --- a/Dragbox/window.py +++ b/Dragbox/window.py @@ -243,6 +243,13 @@ class WindowController(object): create a new window """ self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) + window_display = self.window.get_display() + print_debug("Window display is %s" % window_display) + if not window_display: + from utils import quit_dragbox + print_error("Could not get X Display") + quit_dragbox() + if name: self.window.set_title(name) -- 2.11.4.GIT