def closeEvent(self, event): self.__session_manager.update_serializer_data( self.__input_serializer_data) self.__session_manager.update_serializer_data( self.__reference_serializer_data) if GlobalConfig()["default_session"]: self.__session_manager.store_to_file()
# -*- coding: utf-8 -*- ##===-----------------------------------------------------------------------------*- Python -*-===## ## ## S E R I A L B O X ## ## This file is distributed under terms of BSD license. ## See LICENSE.txt for more information. ## ##===------------------------------------------------------------------------------------------===## from sdbgui.globalconfig import GlobalConfig SDB_HAS_IPYTHON = False SDB_IPYTHON_IMPORT_ERROR = None if GlobalConfig()["ipython"]: try: from os import environ environ['QT_API'] = 'pyqt5' 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
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
# ===----------------------------------------------------------------------------------------=== # 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 if options.move_window: try: point = options.move_window.split(":") GlobalConfig()["move_window"] = QPoint(int(point[0]), int(point[1])) GlobalConfig()["center_window"] = False except (IndexError, ValueError) as e: fatal_error("invalid value of option \"--move-window\": %s" % e) else: GlobalConfig()["move_window"] = None # ===----------------------------------------------------------------------------------------=== # Launch Gui # ===----------------------------------------------------------------------------------------=== from PyQt5.QtWidgets import QApplication from sdbgui.mainwindow import MainWindow app = QApplication(argv) mainWindow = MainWindow()
def __init__(self): super().__init__() Logger.info("Setup main window") self.__input_serializer_data = SerializerData("Input Serializer") self.__input_stencil_data = StencilData(self.__input_serializer_data) self.__reference_serializer_data = SerializerData( "Reference Serializer") self.__reference_stencil_data = StencilData( self.__reference_serializer_data) self.__stencil_field_mapper = StencilFieldMapper( self.__input_stencil_data, self.__reference_stencil_data, GlobalConfig()["async"]) self.__file_system_watcher = QFileSystemWatcher() self.__file_system_watcher.directoryChanged[str].connect( self.popup_reload_box) self.__file_system_watcher_last_modify = time() # Load from session? self.__session_manager = SessionManager() if GlobalConfig()["default_session"]: self.__session_manager.load_from_file() self.__session_manager.set_serializer_data( self.__input_serializer_data) self.__session_manager.set_serializer_data( self.__reference_serializer_data) # Setup GUI self.setWindowTitle('sdb - stencil debugger (%s)' % Version().sdb_version()) self.resize(1200, 600) if GlobalConfig()["center_window"]: self.center() if GlobalConfig()["move_window"]: self.move(GlobalConfig()["move_window"]) self.setWindowIcon(Icon("logo-small.png")) self.init_menu_tool_bar() # Tabs self.__tab_highest_valid_state = TabState.Setup self.__widget_tab = QTabWidget(self) # Setup tab self.__widget_tab.addTab( SetupWindow(self, self.__input_serializer_data, self.__reference_serializer_data), "Setup") # Stencil tab self.__widget_tab.addTab( StencilWindow(self, self.__stencil_field_mapper, self.__input_stencil_data, self.__reference_stencil_data), "Stencil") # Result tab self.__widget_tab.addTab( ResultWindow(self, self.__widget_tab.widget(TabState.Stencil.value), self.__stencil_field_mapper), "Result") # Error tab self.__widget_tab.addTab(ErrorWindow(self), "Error") self.__widget_tab.currentChanged.connect(self.switch_to_tab) self.__widget_tab.setTabEnabled(TabState.Setup.value, True) self.__widget_tab.setTabEnabled(TabState.Stencil.value, False) self.__widget_tab.setTabEnabled(TabState.Result.value, False) self.__widget_tab.setTabEnabled(TabState.Error.value, False) self.__widget_tab.setTabToolTip(TabState.Setup.value, "Setup Input and Refrence Serializer") self.__widget_tab.setTabToolTip( TabState.Stencil.value, "Set the stencil to compare and define the mapping of the fields") self.__widget_tab.setTabToolTip(TabState.Result.value, "View to comparison result") self.__widget_tab.setTabToolTip( TabState.Error.value, "Detailed error desscription of the current field") self.__tab_current_state = TabState.Setup self.set_tab_highest_valid_state(TabState.Setup) self.switch_to_tab(TabState.Setup) self.setCentralWidget(self.__widget_tab) # If the MainWindow is closed, kill all popup windows self.setAttribute(Qt.WA_DeleteOnClose) Logger.info("Starting main loop") self.show()