[575] | 1 | import os
|
---|
| 2 |
|
---|
| 3 | #-----------------------------------------------------------------------------
|
---|
| 4 |
|
---|
| 5 | ## @package mlx.common
|
---|
| 6 | #
|
---|
| 7 | # Common definitions to be used by both the GUI and possible other parts
|
---|
| 8 | #
|
---|
| 9 | # The main purpose of this module is to import Gtk+2 or 3 and related modules
|
---|
| 10 | # and provide common names for them. There is a similator module in the GUI
|
---|
| 11 | # part (\ref mlx.gui.common), which contains the GUI-specific names. This one
|
---|
| 12 | # contains only what is used by other modules as well.
|
---|
| 13 | # The variable \c pygobject tells which version of Gtk is being used. If it is
|
---|
| 14 | # \c True, Gtk+ 3 is used via the PyGObject interface. Otherwise Gtk+ 2 is
|
---|
| 15 | # used, which is the default on Windows or when the \c FORCE_PYGTK environment
|
---|
| 16 | # variable is set.
|
---|
| 17 |
|
---|
[740] | 18 | #---------------------------------------------------------------------------------------
|
---|
| 19 |
|
---|
| 20 | MAVA_BASE_URL = os.environ.get("MAVA_BASE_URL", "http://virtualairlines.hu")
|
---|
| 21 |
|
---|
[575] | 22 | #-------------------------------------------------------------------------------
|
---|
| 23 |
|
---|
[942] | 24 | if "FORCE_PYGTK" in os.environ:
|
---|
[919] | 25 | print("Using PyGTK")
|
---|
[575] | 26 | pygobject = False
|
---|
| 27 | import gobject
|
---|
| 28 | else:
|
---|
[919] | 29 | print("Using PyGObject")
|
---|
[575] | 30 | pygobject = True
|
---|
| 31 |
|
---|
| 32 | from gi.repository import GObject as gobject
|
---|
[955] | 33 |
|
---|
| 34 | #-------------------------------------------------------------------------------
|
---|
| 35 |
|
---|
| 36 | def fixUnpickledValue(value):
|
---|
| 37 | """Fix the given unpickled value.
|
---|
| 38 |
|
---|
| 39 | It handles some basic data, like scalars, lists and tuples. If it
|
---|
| 40 | encounters byte arrays, they are decoded as 'utf-8' strings."""
|
---|
| 41 | if isinstance(value, bytes):
|
---|
| 42 | return str(value, "utf-8")
|
---|
| 43 | elif isinstance(value, list):
|
---|
| 44 | return [fixUnpickledValue(v) for v in value]
|
---|
| 45 | elif isinstance(value, tuple):
|
---|
| 46 | return tuple([fixUnpickledValue(v) for v in value])
|
---|
| 47 | else:
|
---|
| 48 | return value
|
---|
| 49 |
|
---|
| 50 | #-------------------------------------------------------------------------------
|
---|
| 51 |
|
---|
| 52 | def fixUnpickled(state):
|
---|
| 53 | """Fix the given unpickled state.
|
---|
| 54 |
|
---|
| 55 | It checks keys and values, and if it encounters any byte arrays, they are
|
---|
| 56 | decoded with the encoding 'utf-8'. It returns a new dictionary.
|
---|
| 57 | """
|
---|
| 58 | newDict = {}
|
---|
| 59 | for (key, value) in iter(state.items()):
|
---|
| 60 | newDict[fixUnpickledValue(key)] = fixUnpickledValue(value)
|
---|
| 61 |
|
---|
| 62 | return newDict
|
---|