예제 #1
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.config = Settings()    # Initiate application settings.
        # Get application strings.
        strFile = filePath(
            'lang/strings_' + self.config.get('Appearance', 'lang'))
        f = open(strFile, 'r')
        for _, line in enumerate(f):
            exec(line)
        # Setup window.
        self.setWindowTitle(self.str_mainWindowTitle)
        self.centerAndResize()
        # Initialize sub-widgets :
        self.view = MainView(self)
        """A graphical view in which the user can draw circuits."""
        self.setCentralWidget(self.view)
        # Gates and circuits to be dragged in the main view.
        self.boxDock = ToolBoxDockWidget()
        self.addDockWidget(Qt.LeftDockWidgetArea, self.boxDock)
        # Used to modify selected items properties.
        self.optionsDock = SelectionOptionsDockWidget(self.view)
        self.addDockWidget(Qt.LeftDockWidgetArea, self.optionsDock)
        # A log window.
        self.logDock = LogDockWidget()
        self.addDockWidget(Qt.BottomDockWidgetArea, self.logDock)
        # Initialize application menu :
        fileMenu = QMenu(self.str_menuFile)
        fileMenu.addAction(self.str_menuLoad, self.loadCircuit)
        fileMenu.addAction(self.str_menuSave, self.saveCircuit)
        fileMenu.addAction(self.str_menuQuit, self.close)

        editMenu = QMenu(self.str_menuEdit)
        editMenu.addAction(
            self.str_menuSettings,
            lambda: SettingsDialog(self, self.config).exec_())
        editMenu.addAction(self.str_menuClearLogs, self.logDock.widget().clear)
        editMenu.addAction(self.str_menuClearCircuit, self.view.clearCircuit)
        editMenu.addAction("(Exp.) add IOs", self.view.fillIO)
        editMenu.addAction("(Exp.) batch rename", self.view.batchRename)
        editMenu.addAction(self.logDock.toggleViewAction())

        langMenu = QMenu(self.str_menuLang)
        langMenu.addAction(self.str_langEng, lambda: self.setLang('en'))
        langMenu.addAction(self.str_langFr, lambda: self.setLang('fr'))
        helpMenu = QMenu(self.str_menuHelp)
        helpMenu.addAction(self.str_menuDoc, self.showDocumentation)
        helpMenu.addAction(self.str_menuAbout, self.about)

        self.menuBar().addMenu(fileMenu)
        self.menuBar().addMenu(editMenu)
        self.menuBar().addMenu(langMenu)
        self.menuBar().addMenu(helpMenu)
        # WARNING logs will be shown in the MainView.
        self.toastHandler = logging.StreamHandler(self.view)
        self.toastHandler.setLevel(logging.WARNING)
        log.addHandler(self.toastHandler)
        # Every widget is created, we can now apply settings.
        self.setSettings()
        self.show()
예제 #2
0
 def setSettings(self):
     """Set color, verbosity and logging options."""
     self.logDock.setBgColor(self.config.get('Appearance', 'log_bg_color'))
     image = QImage(10, 10, QImage.Format_RGB32)
     image.fill(QColor(self.config.get('Appearance', 'circ_bg_color')))
     image.setPixel(0, 0, QColor(0, 0, 0).rgb())
     self.view.scene().setBackgroundBrush(QBrush(QPixmap.fromImage(image)))
     Plug.setInputVerbose = self.config.getboolean(
         'LogVerbosity', 'input_chang')
     Plug.setOutputVerbose = self.config.getboolean(
         'LogVerbosity', 'output_chang')
     Plug.connectVerbose = self.config.getboolean(
         'LogVerbosity', 'conn_discon_io')
     Plug.addPlugVerbose = self.config.getboolean(
         'LogVerbosity', 'adding_io')
     Circuit.addCircuitVerbose = self.config.getboolean(
         'LogVerbosity', 'adding_circ')
     Circuit.removePlugVerbose = self.config.getboolean(
         'LogVerbosity', 'removing_io')
     Circuit.removeCircuitVerbose = self.config.getboolean(
         'LogVerbosity', 'removing_circ')
     Circuit.detailedRemoveVerbose = self.config.getboolean(
         'LogVerbosity', 'detailed_rm')
     ClockThread.spd = self.config.getfloat(
         'Clock', 'speed')
     if self.config.getboolean('LogHandlers', 'gui'):
         log.addHandler(self.logDock.handler)
     else:
         log.removeHandler(self.logDock.handler)
     if self.config.getboolean('LogHandlers', 'stdout'):
         log.addHandler(stdoutHandler)
     else:
         log.removeHandler(stdoutHandler)
     if self.config.getboolean('LogHandlers', 'file'):
         log.addHandler(fileHandler)
     else:
         log.removeHandler(fileHandler)