コード例 #1
0
ファイル: sessionmanager.py プロジェクト: yboetz/serialbox
 def update_serializer_data(self, serializer_data):
     name = serializer_data.name
     Logger.info("Syncing SerializerData of '%s' with Configuration" % name)
     try:
         self.__config["SerializerData"][name][
             "directory"] = serializer_data.directory
         self.__config["SerializerData"][name][
             "prefix"] = serializer_data.prefix
     except IndexError as e:
         Logger.warning("Error storing SerializerData of '%s': %s" %
                        (name, e))
コード例 #2
0
ファイル: sessionmanager.py プロジェクト: yboetz/serialbox
 def __load_from_file_impl(self, filename):
     try:
         with open(filename, 'r') as file:
             self.__config = load(file)
             Logger.info("Loading config file from \"%s\"" % filename)
     except (OSError, IOError, error) as e:
         Logger.warning("Unable to load config file from \"%s\": %s" %
                        (filename, e))
         return False, str(e)
     except JSONDecodeError as e:
         return False, "JSON decoding error: " + str(e)
     return True, ""
コード例 #3
0
ファイル: sessionmanager.py プロジェクト: yboetz/serialbox
    def set_serializer_data(self, serializer_data):
        name = serializer_data.name
        Logger.info("Loading SerializerData of '%s' from Configuration" % name)

        if not isinstance(serializer_data, SerializerData):
            Logger.error("Type of SerializerData '%s' is not valid: %s" %
                         (name, type(serializer_data)))

        try:
            serializer_data.directory = self.__config["SerializerData"][name][
                "directory"]
            serializer_data.prefix = self.__config["SerializerData"][name][
                "prefix"]
        except IndexError as e:
            Logger.warning("Error loading SerializerData of '%s': %s" %
                           (name, e))
コード例 #4
0
ファイル: sessionmanager.py プロジェクト: yboetz/serialbox
    def __store_to_file_impl(self, filename):
        try:
            try:
                dir = path.dirname(filename)
                makedirs(dir)
            except error:
                pass

            with open(filename, 'w') as file:
                Logger.info("Saving config file in \"%s\"" % filename)
                dump(self.__config, file, indent=2)

        except (OSError, IOError) as e:
            Logger.warning("Unable to save config file in \"%s\": %s" %
                           (filename, e))
            return False, str(e)
        return True, ""
コード例 #5
0
ファイル: sessionmanager.py プロジェクト: yboetz/serialbox
    def load_from_file(self, filename=None):
        """Load configuration file from disk.

        :param filename: Path of the configuration file. If `filename` is ``None``, the default
                         locations will be searched for ``default-config.json``.
        :type filename: str
        """
        config_files = self.excract_config_files(filename)
        error_messages = []

        for config_file in config_files:
            ret, msg = self.__load_from_file_impl(config_file)
            if ret:
                return True, error_messages
            else:
                error_messages += [msg]

        Logger.warning("Failed to load config file")
        return False, error_messages
コード例 #6
0
        from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
        from IPython.qt.inprocess import QtInProcessKernelManager
        from sdbcore.logger import Logger

        # IPython won't work if this is not correctly installed and the error message will be
        # misleading
        from PyQt5 import QtSvg

        SDB_HAS_IPYTHON = True

    except ImportError as e:
        from sdbcore.logger import Logger

        SDB_IPYTHON_IMPORT_ERROR = e
        Logger.warning("cannot import ipython: %s" % e)
else:
    SDB_HAS_IPYTHON = False

if SDB_HAS_IPYTHON:
    from sdbcore.version import Version


    class ErrorConsoleIPythonWidget(RichIPythonWidget):
        """Embedded IPython console
        """

        def __init__(self, *args, **kwargs):
            super(ErrorConsoleIPythonWidget, self).__init__(*args, **kwargs)

            self.kernel_manager = kernel_manager = QtInProcessKernelManager()
コード例 #7
0
ファイル: sdb.py プロジェクト: yboetz/serialbox
def main():
    # ===----------------------------------------------------------------------------------------===
    #   Check Python Version
    # ==-----------------------------------------------------------------------------------------===
    from sys import version_info

    if version_info < (3, 4):
        print("sdb: error: sdb requires atleast python 3.4 (detected %s)" %
              python_version(),
              file=stderr)
        exit(1)

    # ===----------------------------------------------------------------------------------------===
    #   Check if IPython is available
    # ===----------------------------------------------------------------------------------------===
    SDB_HAS_IPYTHON = False
    try:
        from os import environ
        environ['QT_API'] = 'pyqt5'
        from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
        from IPython.qt.inprocess import QtInProcessKernelManager
        SDB_HAS_IPYTHON = True
    except ImportError as e:
        pass

    # ===----------------------------------------------------------------------------------------===
    #   Parse command-line
    # ==-----------------------------------------------------------------------------------------===
    from sdbcore.version import Version
    from sdbcore.error import fatal_error
    from sdbcore.logger import Logger, Level

    parser = OptionParser(version="sdb %s" % Version().sdb_version())
    parser.add_option("-v",
                      "--verbose",
                      dest="verbose",
                      action="store_true",
                      help="enable verbose logging")

    group = BooleanOptionGroup(
        parser, "Configuration Options",
        "All options take a negative form, for example --foo sets the option"
        " foo to True, while --no-foo sets it to False.")
    group.add_boolean_option("ipython",
                             "Embed IPython console in the error description",
                             SDB_HAS_IPYTHON,
                             "True of IPython is available, False otherwise")
    group.add_boolean_option("center-window", "Center main window at launch",
                             True)
    group.add_boolean_option(
        "default-session", "Load (save) default session at startup (shutdown)",
        True)
    group.add_boolean_option("async",
                             "Use asynchronous reading API of Serialbox", True)
    group.add_boolean_option(
        "in-cell-icons",
        "Display small in icons the result table instead of coloring the cell",
        True)

    parser.add_option_group(group)

    parser.add_option(
        "--move-window",
        metavar="X:Y",
        dest="move_window",
        help=
        "Move main window at launch by X in the horizontal and Y in the vertical"
    )

    (options, args) = parser.parse_args()

    if options.verbose:
        Logger.set_level(Level.info)

    # ===----------------------------------------------------------------------------------------===
    #   Check if Serialbox is available
    # ===----------------------------------------------------------------------------------------===
    try:
        from serialbox import __version__
        if options.verbose:
            Logger.enable_serialbox_logging()
        Logger.info("Using Serialbox: %s" % __version__)
    except ImportError as e:
        fatal_error("serialbox not found: %s" % e)

    # ===----------------------------------------------------------------------------------------===
    #   Check if PyQt5 is available
    # ===----------------------------------------------------------------------------------------===
    try:
        from PyQt5.QtCore import QT_VERSION_STR
        Logger.info("Using PyQt5: %s" % QT_VERSION_STR)
    except ImportError as e:
        fatal_error("PyQt5 not found: %s" % e)

    # ===----------------------------------------------------------------------------------------===
    #   Check if matplotlib is available
    # ===----------------------------------------------------------------------------------------===
    try:
        import matplotlib
        Logger.info("Using matplotlib: %s" % matplotlib.__version__)
    except ImportError as e:
        Logger.warning("cannot import matplotlib: %s" % e)

    # ===----------------------------------------------------------------------------------------===
    #  Set global configuration option
    # ===----------------------------------------------------------------------------------------===
    from sdbgui.globalconfig import GlobalConfig
    from PyQt5.QtCore import QPoint

    GlobalConfig()["ipython"] = options.ipython
    GlobalConfig()["default_session"] = options.default_session
    GlobalConfig()["center_window"] = options.center_window
    GlobalConfig()["async"] = options. async
コード例 #8
0
##
##===------------------------------------------------------------------------------------------===##

from PyQt5.QtWidgets import QSizePolicy, QWidget, QLabel, QVBoxLayout

from sdbcore.logger import Logger

SDB_HAS_MATPLOTLIB = False

try:
    import matplotlib

    matplotlib.use('Qt5Agg')
    SDB_HAS_MATPLOTLIB = True
except ImportError as e:
    Logger.warning("cannot import matplotlib: %s" % e)

if SDB_HAS_MATPLOTLIB:

    from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
    from matplotlib.figure import Figure
    from matplotlib.colors import ColorConverter

    from numpy import arange, zeros

    class ErrorVisualizeMatplotlibWidget(FigureCanvas):
        def __init__(self, parent):
            fig = Figure(figsize=(5, 5), dpi=100)
            fig.patch.set_alpha(0)

            self.axes = fig.add_subplot(111)