From d1d112ca7a40c2b2c676eda6cd661e2f043dbdd8 Mon Sep 17 00:00:00 2001 From: Nic Bricknell Date: Tue, 29 Nov 2016 13:47:03 +0000 Subject: [PATCH] Avoid loading Qt things if $DISPLAY is not defined --- malcolm/imalcolm.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/malcolm/imalcolm.py b/malcolm/imalcolm.py index 50e248287..bc8208fef 100755 --- a/malcolm/imalcolm.py +++ b/malcolm/imalcolm.py @@ -5,6 +5,7 @@ def make_process(): import threading import argparse import logging + from os import environ parser = argparse.ArgumentParser( description="Interactive shell for malcolm") @@ -30,20 +31,28 @@ def make_process(): from malcolm.core import SyncFactory, Process from malcolm.yamlutil import make_include_creator - from PyQt4.Qt import QApplication - - # Start qt - def start_qt(): - global app - app = QApplication(sys.argv) - app.setQuitOnLastWindowClosed(False) - from malcolm.gui.guiopener import GuiOpener - global opener - opener = GuiOpener() - app.exec_() - qt_thread = threading.Thread(target=start_qt) - qt_thread.start() + try: + environ['DISPLAY'] + # If this environment variable doesn't exist then there is probably no + # X server for us to talk to. + except KeyError: + pass + else: + from PyQt4.Qt import QApplication + + # Start qt + def start_qt(): + global app + app = QApplication(sys.argv) + app.setQuitOnLastWindowClosed(False) + from malcolm.gui.guiopener import GuiOpener + global opener + opener = GuiOpener() + app.exec_() + + qt_thread = threading.Thread(target=start_qt) + qt_thread.start() sf = SyncFactory("Sync")