Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2"""
3@file
4@brief Handles window `Tk <https://docs.python.org/3.4/library/tkinter.html#tkinter.Tk>`_
5"""
6import sys
7import tkinter
8import tkinter.tix as ttix # pylint: disable=W0402
11def X_is_running():
12 """
13 Checks that *X* is running.
14 """
15 from subprocess import Popen, PIPE
16 try:
17 p = Popen(["xset", "-q"], stdout=PIPE, stderr=PIPE)
18 p.communicate()
19 return p.returncode == 0
20 except Exception:
21 # this function can fail on eBook
22 # moved as a warning
23 # also remove the warning at is not always meaningful
24 # import warnings
25 # warnings.warn(
26 # "Unable to detected if X11 is running with command xset -q, we assume it is not.\n{0}".format(e))
27 return False
30def has_x_server():
31 """
32 Detects the presences of X server.
33 """
34 if sys.platform.startswith("win"):
35 return True
36 return X_is_running()
39_has_x_server = has_x_server()
42def create_tk():
43 """
44 Calls `Tk <https://docs.python.org/3/library/tkinter.html#tkinter.Tk>`_
45 or `Tcl <https://docs.python.org/3/library/tkinter.html#tkinter.Tcl>`_
46 depending on that fact there is a X server.
48 @return main window
49 """
50 global _has_x_server # pylint: disable=W0602
51 return tkinter.Tk() if _has_x_server else tkinter.Tcl()
54def create_tixtk():
55 """
56 Calls `Tk <https://docs.python.org/3.4/library/tkinter.html#tkinter.Tk>`_
57 or `Tcl <https://docs.python.org/3.4/library/tkinter.html#tkinter.Tcl>`_
58 depending on that fact there is a X server.
60 @return main window
61 """
62 global _has_x_server # pylint: disable=W0602
63 return ttix.Tk() if _has_x_server else ttix.Tcl()