Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1648 from jangarrevoet/1106-no_x_session
Browse files Browse the repository at this point in the history
add support for running without an X-session
  • Loading branch information
reszelaz authored Jul 13, 2021
2 parents 106959b + a66ad34 commit f6b7108
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/sardana/spock/ipython_01_00/genutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
from IPython.utils.path import get_ipython_dir


from sardana.util.graphics import display_available
import taurus
#from taurus.core import Release as TCRelease

Expand Down Expand Up @@ -116,10 +117,15 @@
def get_gui_mode():
try:
import taurus.external.qt.Qt
return 'qt'
ret_val = 'qt'
except ImportError:
return None

# Check for running without an X-session on linux
if not display_available():
ret_val = None

return ret_val

def get_pylab_mode():
return get_app().pylab
Expand Down Expand Up @@ -1303,6 +1309,11 @@ def prepare_input_handler():
except ImportError:
raise Exception("Cannot use Spock Qt input handler!")

if not display_available():
raise Exception(
"Running without graphical user interface support."
" Cannot use Spock Qt input handler!"
)

def prepare_cmdline(argv=None):
if argv is None:
Expand Down
25 changes: 25 additions & 0 deletions src/sardana/spock/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
'post_mortem', 'macrodata', 'edmac', 'spock_late_startup_hook',
'spock_pre_prompt_hook']

from sardana.util.graphics import display_available
from sardana.util.whichpython import which_python_executable
from .genutils import MSG_DONE, MSG_FAILED
from .genutils import get_ipapi
from .genutils import page, get_door, get_macro_server, ask_yes_no, arg_split



def expconf(self, parameter_s=''):
"""Launches a GUI for configuring the environment variables
for the experiments (scans)"""
Expand All @@ -49,6 +51,15 @@ def expconf(self, parameter_s=''):
"https://sardana-controls.org/users/standard_macro_catalog.html#experiment-configuration-macros)")
return

if not display_available():
print(
"Running without graphical user interface support. "
"ExpConf cannot work without it. "
"(hint: maybe you want to use experiment configuration macros? "
"https://sardana-controls.org/users/standard_macro_catalog.html#experiment-configuration-macros)"
)
return

try:
from sardana.taurus.qt.qtgui.extra_sardana import ExpDescriptionEditor
except:
Expand Down Expand Up @@ -97,6 +108,13 @@ def showscan(self, parameter_s=''):
print("Qt binding is not available. Showscan cannot work without it.")
return

if not display_available():
print(
"Running without graphical user interface support."
" Showscan cannot work without it."
)
return

params = parameter_s.split()
door = get_door()
scan_nb = None
Expand All @@ -118,6 +136,13 @@ def spsplot(self, parameter_s=''):
print("Qt binding is not available. SPSplot cannot work without it.")
return

if not display_available():
print(
"Running without graphical user interface support."
" SPSplot cannot work without it."
)
return

get_door().plot()


Expand Down
6 changes: 6 additions & 0 deletions src/sardana/spock/spockms.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from sardana.sardanautils import is_pure_str, is_non_str_seq
from sardana.spock import genutils
from sardana.util.parser import ParamParser
from sardana.util.graphics import display_available
from sardana import sardanacustomsettings

CHANGE_EVTS = TaurusEventType.Change, TaurusEventType.Periodic
Expand Down Expand Up @@ -519,6 +520,11 @@ def processRecordData(self, data):
except ImportError:
print("Qt binding is not available. Macro plotting cannot work without it.")
return
if not display_available():
print("Running without graphical user interface support."
" Macro plotting cannot work without it."
)
return
func_name = self.MathFrontend + "." + func_name
args = data['args']
kwargs = data['kwargs']
Expand Down
72 changes: 72 additions & 0 deletions src/sardana/util/graphics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

##############################################################################
##
# This file is part of Sardana
##
# http://www.sardana-controls.org/
##
# Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
##
# Sardana is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
##
# Sardana is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
##
# You should have received a copy of the GNU Lesser General Public License
# along with Sardana. If not, see <http://www.gnu.org/licenses/>.
##
##############################################################################

"""This package provides graphics related helper functions"""

import os
import sys


def display_available():
"""
Checks if a graphical display is available.
:returns: True when a display is available. False when not.
:rtype: bool
.. note ::
This is only used for linux since it can run without graphical
sessions.
For Windows this always returns True since it can not run without.
"""

ret_val = True

if sys.platform.startswith("linux"):
ret_val = xsession_available()

return ret_val


def xsession_available():
"""
Checks if an X-session is available.
:returns: True when an X-session is available. False when not.
:rtype: bool
"""

ret_val = True

# No display environment
if os.environ.get("DISPLAY") is None:
ret_val = False

# In docker without X-session auth
elif not os.path.exists("/tmp/.X11-unix"):
ret_val = False

return ret_val

0 comments on commit f6b7108

Please sign in to comment.