def __init__(self): QWidget.__init__(self) self.ctrl = QApplication.instance().ctrl self.ctrl.switch_language.connect(self.on_switch_language) self.ctrl.switch_configuration.connect(self.on_switch_configuration) self.paras = self.ctrl.paras self.conf = GuiConf() self.setWindowTitle(_("Execute %s") % self.paras.configuration_name()) self.executor_thread = None self.splitter_event_moved = False self.splitter_title_moved = False self.init_ui() self.show()
def __init__(self, application_home, locale_dir): QObject.__init__(self) self.application_home = application_home self.locale_dir = locale_dir self.config = GuiConf() self.last_directory = os.path.expanduser("~") try: self.paras = RsParameters( config_name=self.config.last_configuration_name()) except: self.paras = RsParameters() self.selector = self.__get_selector()
def __init__(self, work="", title_style=Style.h2()): QWidget.__init__(self) self.ctrl = QApplication.instance().ctrl self.ctrl.switch_language.connect(self.on_switch_language) self.ctrl.switch_configuration.connect(self.on_switch_configuration) self.paras = self.ctrl.paras self.conf = GuiConf() # work should be a verb: Execute, Transport ... self.work = work self.title_style = title_style self.setWindowTitle(_(self.work)) self.executor_thread = None self.splitter_event_moved = False self.splitter_title_moved = False self.init_ui() self.show()
def __init__(self, get_selector, title=None, max_lines=1000000): QWidget.__init__(self) self.ctrl = QApplication.instance().ctrl self.ctrl.switch_language.connect(self.on_switch_language) self.get_selector = get_selector self.window_title = title self.setWindowTitle(_(self.window_title)) self.max_lines = max_lines self.conf = GuiConf() self.player = None self.resource_count = 0 self.excluded_resource_count = 0 self.exception_count = 0 self.__init_ui__() self.show()
def __init__(self): super().__init__() self.ctrl = QApplication.instance().ctrl self.ctrl.switch_language.connect(self.on_switch_language) self.ctrl.switch_configuration.connect(self.on_switch_configuration) self.paras = self.ctrl.paras self.config = GuiConf() self.init_ui() self.on_switch_language() self.on_switch_configuration()
def __init__(self): super().__init__() self.ctrl = QApplication.instance().ctrl self.ctrl.switch_language.connect(self.on_switch_language) self.ctrl.switch_configuration.connect(self.on_switch_configuration) self.window_title = (_("Metadata Publishing Tool")) self.paras = self.ctrl.paras self.config = GuiConf() self.init_ui() self.on_switch_language() self.on_switch_configuration()
def current_language(): from rsapp.gui.conf import GuiConf return GuiConf().language(fallback=DEFAULT_LOCALE)
# set an initial language locale_dir = os.path.join(application_home, "i18n") logger.debug("Locale directory: %s", locale_dir) language = current_language() logger.debug("Current language: %s", language) trls = gettext.translation(LOCALE_DOMAIN, localedir=locale_dir, languages=[language], fallback=True) trls.install("gettext") from rsapp.gui.wapp import RsApplication application = RsApplication(sys.argv, application_home=application_home, locale_dir=locale_dir) from rsapp.gui.conf import GuiConf if GuiConf().show_splash(): # Create and display the splash screen splash_pix = QPixmap( os.path.join(application_home, 'conf/img/splash.png')) splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint) splash.setMask(splash_pix.mask()) splash.show() splash.finish(application.main_window) # # start the application application.main_window.show() sys.exit(application.exec_())
def current_language(self): return GuiConf().language(fallback=self.system_language())
class Ctrl(QObject): switch_language = pyqtSignal(str) switch_configuration = pyqtSignal(str) switch_selector = pyqtSignal(str) switch_tab = pyqtSignal(int, int) def __init__(self, application_home, locale_dir): QObject.__init__(self) self.application_home = application_home self.locale_dir = locale_dir self.config = GuiConf() self.last_directory = os.path.expanduser("~") try: self.paras = RsParameters( config_name=self.config.last_configuration_name()) except: self.paras = RsParameters() self.selector = self.__get_selector() def report_tab_switch(self, from_index, to_index): self.switch_tab.emit(from_index, to_index) def locales(self): return [ os.path.basename(x) for x in glob.glob(os.path.join(self.locale_dir, "*-*")) if os.path.isdir(x) ] def system_language(self): loc = None try: loc = locale.getdefaultlocale() except: pass return DEFAULT_LOCALE if loc is None or len(loc) < 2 else loc[0] def current_language(self): return GuiConf().language(fallback=self.system_language()) def set_language(self, code): gettext.translation(LOCALE_DOMAIN, localedir=self.locale_dir, languages=[code], fallback=True).install() self.config.set_language(code) self.config.persist() self.switch_language.emit(code) def iso_lang(self): data = {} iso_path = os.path.join(self.application_home, "i18n", "iso-lang.json") try: with open(iso_path, "r", encoding="utf-8") as iso_file: data = json.load(iso_file) except Exception as err: self.warn(_("Could not read iso-lang.json"), err) return data def load_configuration(self, name): try: self.paras = RsParameters(config_name=name) self.selector = self.__get_selector() self.switch_configuration.emit(name) self.switch_selector.emit(self.selector.abs_location()) LOG.debug("Loaded configuration: '%s'" % name) except ValueError as err: self.error("Unable to load configuration %s" % name, err) def save_configuration_as(self, name): try: if self.paras.selector_file: selector_dir = os.path.dirname(self.paras.selector_file) new_name = os.path.join(selector_dir, name + "-selector.csv") self.selector.write(new_name) self.paras.selector_file = new_name LOG.debug("Saved selector '%s' as '%s'" % (self.paras.selector_file, new_name)) self.paras.save_configuration_as(name) LOG.debug("Saved configuration as '%s'" % name) self.switch_configuration.emit(name) self.switch_selector.emit(self.selector.abs_location()) except ValueError as err: self.error("Unable to save configuration '%s'" % name, err) def reset_configuration(self): try: self.paras.reset() self.selector = self.__get_selector() LOG.debug("Configuration was reset") self.switch_configuration.emit(self.paras.configuration_name()) self.switch_selector.emit(self.selector.abs_location()) except Exception as err: self.error("Unable to reset parameters.", err) def update_configuration(self, paras): self.paras = paras self.paras.save_configuration() LOG.debug("Configuration updated") self.switch_configuration.emit(self.paras.configuration_name()) def __get_selector(self): if self.paras.selector_file: try: selector = Selector(location=self.paras.selector_file) self.last_directory = os.path.dirname(self.paras.selector_file) LOG.debug("Loaded selector from %s" % self.paras.selector_file) except Exception as err: self.warn( "Unable to read selector file '%s'" % self.paras.selector_file, err) selector = Selector() else: selector = Selector() #Difficult keeping track of a selector that is not saved: if selector.location is None: selector_dir = os.path.join(Configurations.rspub_config_dir(), "selectors") os.makedirs(selector_dir, exist_ok=True) location = os.path.join(selector_dir, "default_selector.csv") if os.path.exists(location): selector = Selector(location=location) else: selector.write(location) self.paras.selector_file = location return selector def save_selector(self): if self.selector.location: try: self.selector.write() LOG.debug("Saved selector as %s" % self.selector.abs_location()) except Exception as err: self.warn( "Unable to save selector file '%s'" % self.selector.abs_location(), err) def save_selector_as(self, filename): try: self.selector.write(filename) LOG.debug("Saved selector as %s" % self.selector.abs_location()) self.last_directory = os.path.dirname(self.selector.abs_location()) self.paras.selector_file = filename self.paras.save_configuration() self.switch_configuration.emit(self.paras.configuration_name()) self.switch_selector.emit(self.selector.abs_location()) except Exception as err: self.warn( "Unable to save selector file as '%s'" % self.selector.abs_location(), err) def open_selector(self, filename): try: self.selector = Selector(filename) LOG.debug("Opened selector %s" % self.selector.abs_location()) self.last_directory = os.path.dirname(self.selector.abs_location()) self.paras.selector_file = filename self.paras.save_configuration() self.switch_configuration.emit(self.paras.configuration_name()) self.switch_selector.emit(self.selector.abs_location()) except Exception as err: self.warn( "Unable to open selector file '%s'" % self.selector.abs_location(), err) def load_selector_includes(self, filename): try: self.selector.read_includes(filename) LOG.debug("Loaded includes %s" % filename) self.last_directory = os.path.dirname(filename) self.switch_selector.emit(self.selector.abs_location()) except Exception as err: self.warn("Unable to load includes from %s." % filename, err) def load_selector_excludes(self, filename): try: self.selector.read_excludes(filename) LOG.debug("Loaded excludes %s" % filename) self.last_directory = os.path.dirname(filename) self.switch_selector.emit(self.selector.abs_location()) except Exception as err: self.warn("Unable to load excludes from %s." % filename, err) @staticmethod def error(msg, cause=None): LOG.exception(msg) Ctrl.__msg(QMessageBox.Critical, msg, cause) @staticmethod def warn(msg, cause=None): LOG.warning(msg, exc_info=True) Ctrl.__msg(QMessageBox.Warning, msg, cause) @staticmethod def __msg(icon, text, cause=None): msg_box = QMessageBox() msg_box.setWindowTitle(_("MPT")) if cause: msg_box.setText(_("%s\nCaused by:\n\n%s") % (text, cause)) else: msg_box.setText(text) msg_box.setIcon(icon) msg_box.exec()
class ExecuteWidget(QWidget): def __init__(self): QWidget.__init__(self) self.ctrl = QApplication.instance().ctrl self.ctrl.switch_language.connect(self.on_switch_language) self.ctrl.switch_configuration.connect(self.on_switch_configuration) self.paras = self.ctrl.paras self.conf = GuiConf() self.setWindowTitle(_("Execute %s") % self.paras.configuration_name()) self.executor_thread = None self.splitter_event_moved = False self.splitter_title_moved = False self.init_ui() self.show() def init_ui(self): vbox = QVBoxLayout() self.splitter_title = QSplitter(Qt.Vertical) self.splitter_event = QSplitter(Qt.Vertical) self.splitter_title.splitterMoved.connect(self.on_splitter_title_moved) self.splitter_event.splitterMoved.connect(self.on_splitter_event_moved) self.lbl_events_title1 = QLabel(_("Main events")) self.splitter_title.addWidget(self.lbl_events_title1) self.lbl_events_title2 = QLabel(_("Resources")) self.splitter_title.addWidget(self.lbl_events_title2) self.lbl_events_title3 = QLabel(_("Errors")) self.splitter_title.addWidget(self.lbl_events_title3) self.pte_events1 = QTextBrowser() self.pte_events1.setOpenExternalLinks(True) self.pte_events1.setOpenLinks(False) self.pte_events1.anchorClicked.connect(self.on_anchor_clicked) self.pte_events1.setLineWrapMode(QTextEdit.NoWrap) self.splitter_event.addWidget(self.pte_events1) self.pte_events2 = QTextBrowser() self.pte_events2.setOpenExternalLinks(True) self.pte_events2.setOpenLinks(False) self.pte_events2.anchorClicked.connect(self.on_anchor_clicked) self.pte_events2.setLineWrapMode(QTextEdit.NoWrap) self.splitter_event.addWidget(self.pte_events2) self.pte_events3 = QPlainTextEdit() self.pte_events3.setReadOnly(True) self.pte_events3.setLineWrapMode(QPlainTextEdit.NoWrap) self.pte_events3.setStyleSheet(Style.red_text()) self.pte_events3.setCenterOnScroll(True) self.splitter_event.addWidget(self.pte_events3) self.splitter_title.setStretchFactor(0, 5) self.splitter_title.setStretchFactor(1, 3) self.splitter_title.setStretchFactor(2, 1) self.splitter_event.setStretchFactor(0, 5) self.splitter_event.setStretchFactor(1, 3) self.splitter_event.setStretchFactor(2, 1) hbox_splitters = QHBoxLayout() hbox_splitters.addWidget(self.splitter_title, 0) hbox_splitters.addWidget(self.splitter_event, 5) vbox.addLayout(hbox_splitters) lbl_box = QHBoxLayout() self.lbl_processing = QLabel(_("Processing:")) self.lbl_processing_file = QLabel("") self.lbl_processing.setVisible(False) self.lbl_processing_file.setVisible(False) lbl_box.addWidget(self.lbl_processing) lbl_box.addWidget(self.lbl_processing_file) lbl_box.addStretch(1) vbox.addLayout(lbl_box) btn_box = QHBoxLayout() btn_box.addStretch(1) self.chk_trial_run = QCheckBox(_("Trial run")) self.chk_trial_run.setChecked(not self.paras.is_saving_sitemaps) btn_box.addWidget(self.chk_trial_run) self.btn_run = QPushButton(_("Run")) self.btn_run.clicked.connect(self.on_btn_run_clicked) btn_box.addWidget(self.btn_run) self.btn_stop = QPushButton(_("Stop")) self.btn_stop.clicked.connect(self.on_btn_stop_clicked) self.normal_style = self.btn_stop.styleSheet() self.btn_stop.setEnabled(False) btn_box.addWidget(self.btn_stop) self.btn_close = QPushButton(_("Close")) self.btn_close.clicked.connect(self.on_btn_close_clicked) btn_box.addWidget(self.btn_close) vbox.addLayout(btn_box) self.setLayout(vbox) self.resize(self.conf.execute_widget_width(), self.conf.execute_widget_height()) def on_splitter_title_moved(self, pos, index): self.splitter_title_moved = True if not self.splitter_event_moved: self.splitter_event.moveSplitter(pos, index) self.splitter_title_moved = False def on_splitter_event_moved(self, pos, index): self.splitter_event_moved = True if not self.splitter_title_moved: self.splitter_title.moveSplitter(pos, index) self.splitter_event_moved = False def on_switch_language(self): self.setWindowTitle(_("Execute %s") % self.paras.configuration_name()) self.lbl_events_title1.setText(_("Main events")) self.lbl_events_title2.setText(_("Resources")) self.lbl_events_title3.setText(_("Errors")) self.lbl_processing.setText(_("Processing:")) self.chk_trial_run.setText(_("Trial run")) self.btn_run.setText(_("Run")) self.btn_stop.setText(_("Stop")) self.btn_close.setText(_("Close")) def on_switch_configuration(self, name=None): LOG.debug("Switch configuration: %s" % name) self.paras = self.ctrl.paras self.setWindowTitle(_("Execute %s") % self.paras.configuration_name()) self.chk_trial_run.setChecked(not self.paras.is_saving_sitemaps) def on_btn_run_clicked(self): if self.paras.select_mode == SelectMode.simple: selector = Selector() if self.paras.simple_select_file: selector.include(self.paras.simple_select_file) else: selector = self.ctrl.selector self.paras.is_saving_sitemaps = not self.chk_trial_run.isChecked() self.pte_events1.setPlainText("") self.pte_events2.setPlainText("") self.pte_events3.setPlainText("") self.lbl_processing.setVisible(True) self.lbl_processing_file.setVisible(True) self.btn_close.setEnabled(False) self.btn_run.setEnabled(False) self.chk_trial_run.setEnabled(False) self.btn_stop.setEnabled(True) self.btn_stop.setStyleSheet(Style.alarm()) self.executor_thread = ExecutorThread(self.paras, selector, self) self.executor_thread.signal_exception.connect(self.on_signal_exception) self.executor_thread.ask_confirmation.connect(self.on_ask_confirmation) self.executor_thread.signal_main_event.connect( self.on_signal_main_event) self.executor_thread.signal_minor_event.connect( self.on_signal_minor_event) self.executor_thread.signal_next_file.connect(self.on_signal_next_file) self.executor_thread.signal_end_processing.connect( self.on_signal_end_processing) self.executor_thread.finished.connect(self.on_executor_thread_finished) self.executor_thread.start() self.update() def on_btn_stop_clicked(self): self.btn_stop.setStyleSheet(self.normal_style) self.btn_stop.setEnabled(False) self.executor_thread.requestInterruption() def on_signal_exception(self, msg): self.pte_events3.appendHtml(msg) self.update() def on_ask_confirmation(self, text, i_text, answer): msg_box = QMessageBox() msg_box.setText(text) i_text += "\n\n" i_text += _("Ok to proceed?") msg_box.setInformativeText(i_text) msg_box.setIcon(QMessageBox.Question) msg_box.setStandardButtons(QMessageBox.No | QMessageBox.Yes) msg_box.setDefaultButton(QMessageBox.Yes) exe = msg_box.exec() if exe == QMessageBox.No: answer.answer = False else: answer.answer = True answer.answered = True def on_signal_main_event(self, msg): self.pte_events1.append(msg) self.update() def on_signal_minor_event(self, msg): self.pte_events2.append(msg) self.update() def on_signal_next_file(self, filename): lfn = len(filename) ww = (self.width() - 150) / 7 www = int(ww / 2) if lfn > ww: filename = filename[:www] + "..." + filename[lfn - www:] self.lbl_processing_file.setText(filename) self.update() def on_signal_end_processing(self, paras): self.ctrl.update_configuration(paras) def on_executor_thread_finished(self): self.btn_stop.setStyleSheet(self.normal_style) self.btn_stop.setEnabled(False) self.btn_close.setEnabled(True) self.btn_run.setEnabled(True) self.chk_trial_run.setEnabled(True) self.lbl_processing.setVisible(False) self.lbl_processing_file.setVisible(False) self.update() def on_anchor_clicked(self, url): QDesktopServices.openUrl(QUrl(url)) def on_btn_close_clicked(self): if self.windowState() & Qt.WindowFullScreen: self.setWindowState(Qt.WindowMaximized) else: self.close() def closeEvent(self, event): if self.executor_thread: self.executor_thread.requestInterruption() if self.windowState() & Qt.WindowFullScreen: self.setWindowState(Qt.WindowMaximized) event.ignore() else: self.conf.set_execute_widget_width(self.width()) self.conf.set_execute_widget_height(self.height()) self.conf.persist() event.accept()
class PlayWidget(QWidget): def __init__(self, get_selector, title=None, max_lines=1000000): QWidget.__init__(self) self.ctrl = QApplication.instance().ctrl self.ctrl.switch_language.connect(self.on_switch_language) self.get_selector = get_selector self.window_title = title self.setWindowTitle(_(self.window_title)) self.max_lines = max_lines self.conf = GuiConf() self.player = None self.resource_count = 0 self.excluded_resource_count = 0 self.exception_count = 0 self.__init_ui__() self.show() def __init_ui__(self): vbox = QVBoxLayout() self.lbl_explanation = QLabel(_("Selected resources")) vbox.addWidget(self.lbl_explanation) splitter = QSplitter() splitter.setOrientation(Qt.Vertical) self.pte_output = QPlainTextEdit() self.pte_output.setReadOnly(True) self.pte_output.setMaximumBlockCount(self.max_lines) self.pte_output.setLineWrapMode(QPlainTextEdit.NoWrap) self.pte_output.setCenterOnScroll(True) splitter.addWidget(self.pte_output) self.pte_exceptions = QPlainTextEdit() self.pte_exceptions.setReadOnly(True) self.pte_exceptions.setMaximumBlockCount(5000) self.pte_exceptions.setLineWrapMode(QPlainTextEdit.NoWrap) self.pte_exceptions.setCenterOnScroll(True) self.pte_exceptions.setStyleSheet(Style.blue_text()) splitter.addWidget(self.pte_exceptions) splitter.setStretchFactor(0, 2) splitter.setStretchFactor(1, 1) vbox.addWidget(splitter) btn_box = QHBoxLayout() count_grid = QGridLayout() count_grid.setSpacing(3) self.lbl_recources_count = QLabel(_("Selected resources:")) count_grid.addWidget(self.lbl_recources_count, 1, 1) self.lbl_resources_counter = QLabel("0") self.lbl_resources_counter.setTextInteractionFlags( Qt.TextSelectableByMouse) count_grid.addWidget(self.lbl_resources_counter, 1, 2) self.lbl_excluded_recources_count = QLabel(_("Excluded resources:")) count_grid.addWidget(self.lbl_excluded_recources_count, 2, 1) self.lbl_excluded_resources_counter = QLabel("0") self.lbl_excluded_resources_counter.setTextInteractionFlags( Qt.TextSelectableByMouse) count_grid.addWidget(self.lbl_excluded_resources_counter, 2, 2) btn_box.addLayout(count_grid) btn_box.addStretch(1) self.btn_play = QPushButton(_("Play")) self.btn_play.clicked.connect(self.on_btn_play_clicked) btn_box.addWidget(self.btn_play) self.btn_stop = QPushButton(_("Stop")) self.normal_style = self.btn_stop.styleSheet() self.btn_stop.clicked.connect(self.on_btn_stop_clicked) self.btn_stop.setEnabled(False) btn_box.addWidget(self.btn_stop) self.btn_close = QPushButton(_("Close")) self.btn_close.clicked.connect(self.on_btn_close_clicked) btn_box.addWidget(self.btn_close) vbox.addLayout(btn_box) self.setLayout(vbox) self.resize(self.conf.play_widget_width(), self.conf.play_widget_height()) def on_switch_language(self): self.setWindowTitle(_(self.window_title)) self.lbl_explanation.setText(_("Selected resources")) self.lbl_recources_count.setText(_("Selected resources:")) self.lbl_excluded_recources_count.setText(_("Excluded resources:")) self.btn_play.setText(_("Play")) self.btn_stop.setText(_("Stop")) self.btn_close.setText(_("Close")) def on_btn_play_clicked(self): self.pte_output.setPlainText("") self.pte_exceptions.setPlainText("") selector = self.get_selector() self.player = PlayerThread(selector, self) self.player.yield_resource.connect(self.on_yield_resource) self.player.signal_exception.connect(self.on_signal_exception) self.player.signal_excluded_resource.connect( self.on_signal_excluded_resource) self.player.finished.connect(self.on_player_finished) # counters self.resource_count = 0 self.excluded_resource_count = 0 self.exception_count = 0 self.lbl_resources_counter.setText(str(self.resource_count)) self.lbl_excluded_resources_counter.setText( str(self.excluded_resource_count)) # buttons self.btn_close.setEnabled(False) self.btn_play.setEnabled(False) self.btn_stop.setEnabled(True) self.btn_stop.setStyleSheet(Style.alarm()) self.player.start() self.update() def on_yield_resource(self, file): self.resource_count += 1 self.lbl_resources_counter.setText(str(self.resource_count)) self.pte_output.appendPlainText(file) self.update() def on_signal_exception(self, msg): self.exception_count += 1 self.pte_exceptions.appendHtml("<span style=color:red;>" + msg + "</span>") def on_signal_excluded_resource(self, msg): self.excluded_resource_count += 1 self.lbl_excluded_resources_counter.setText( str(self.excluded_resource_count)) self.pte_exceptions.appendPlainText(msg) self.update() def on_btn_stop_clicked(self): self.btn_stop.setStyleSheet(self.normal_style) self.btn_stop.setEnabled(False) self.player.requestInterruption() def on_player_finished(self): self.btn_stop.setStyleSheet(self.normal_style) self.btn_stop.setEnabled(False) self.btn_play.setEnabled(True) self.btn_close.setEnabled(True) def on_btn_close_clicked(self): if self.windowState() & Qt.WindowFullScreen: self.setWindowState(Qt.WindowMaximized) else: self.close() def closeEvent(self, event): if self.player: self.player.requestInterruption() if self.windowState() & Qt.WindowFullScreen: self.setWindowState(Qt.WindowMaximized) event.ignore() else: self.conf.set_play_widget_width(self.width()) self.conf.set_play_widget_height(self.height()) self.conf.persist() event.accept()
class WorkWidget(QWidget): work_started = pyqtSignal() work_ended = pyqtSignal() def __init__(self, work="", title_style=Style.h2()): QWidget.__init__(self) self.ctrl = QApplication.instance().ctrl self.ctrl.switch_language.connect(self.on_switch_language) self.ctrl.switch_configuration.connect(self.on_switch_configuration) self.paras = self.ctrl.paras self.conf = GuiConf() # work should be a verb: Execute, Transport ... self.work = work self.title_style = title_style self.setWindowTitle(_(self.work)) self.executor_thread = None self.splitter_event_moved = False self.splitter_title_moved = False self.init_ui() self.show() def init_ui(self): vbox = QVBoxLayout() self.label_title = QLabel("%s %s" % (_(self.work), self.paras.configuration_name())) font = QFont() font.setPointSize(18) font.setBold(True) self.label_title.setFont(font) self.label_title.setContentsMargins(10, 5, 5, 7) self.label_title.setStyleSheet(self.title_style) hbox1 = QHBoxLayout() hbox1.addWidget(self.label_title, 1) vbox.addLayout(hbox1) self.splitter_title = QSplitter(Qt.Vertical) self.splitter_event = QSplitter(Qt.Vertical) self.splitter_title.splitterMoved.connect(self.on_splitter_title_moved) self.splitter_event.splitterMoved.connect(self.on_splitter_event_moved) self.lbl_events_title1 = QLabel(_("Main events")) self.splitter_title.addWidget(self.lbl_events_title1) self.lbl_events_title2 = QLabel(_("Resources")) self.splitter_title.addWidget(self.lbl_events_title2) self.lbl_events_title3 = QLabel(_("Errors")) self.splitter_title.addWidget(self.lbl_events_title3) self.pte_events1 = QTextBrowser() self.pte_events1.setOpenExternalLinks(True) self.pte_events1.setOpenLinks(False) self.pte_events1.anchorClicked.connect(self.on_anchor_clicked) self.pte_events1.setLineWrapMode(QTextEdit.NoWrap) self.splitter_event.addWidget(self.pte_events1) self.pte_events2 = QTextBrowser() self.pte_events2.setOpenExternalLinks(True) self.pte_events2.setOpenLinks(False) self.pte_events2.anchorClicked.connect(self.on_anchor_clicked) self.pte_events2.setLineWrapMode(QTextEdit.NoWrap) self.splitter_event.addWidget(self.pte_events2) self.pte_events3 = QPlainTextEdit() self.pte_events3.setReadOnly(True) self.pte_events3.setLineWrapMode(QPlainTextEdit.NoWrap) self.pte_events3.setStyleSheet(Style.red_text()) self.pte_events3.setCenterOnScroll(True) self.splitter_event.addWidget(self.pte_events3) self.splitter_title.setStretchFactor(0, 5) self.splitter_title.setStretchFactor(1, 3) self.splitter_title.setStretchFactor(2, 1) self.splitter_event.setStretchFactor(0, 5) self.splitter_event.setStretchFactor(1, 3) self.splitter_event.setStretchFactor(2, 1) hbox_splitters = QHBoxLayout() hbox_splitters.addWidget(self.splitter_title, 0) hbox_splitters.addWidget(self.splitter_event, 5) vbox.addLayout(hbox_splitters) lbl_box = QHBoxLayout() self.lbl_processing = QLabel(_("Processing:")) self.lbl_processing_file = QLabel("") font = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.lbl_processing_file.setFont(font) self.lbl_processing.setFont(font) self.lbl_processing.setVisible(False) self.lbl_processing_file.setVisible(False) lbl_box.addWidget(self.lbl_processing) lbl_box.addWidget(self.lbl_processing_file) lbl_box.addStretch(1) vbox.addLayout(lbl_box) btn_box = QHBoxLayout() btn_box.addStretch(1) self.chk_trial_run = QCheckBox(_("Trial run")) self.chk_trial_run.setChecked(not self.paras.is_saving_sitemaps) btn_box.addWidget(self.chk_trial_run) self.btn_run = QPushButton(_("Run")) self.btn_run.clicked.connect(self.on_btn_run_clicked) btn_box.addWidget(self.btn_run) self.btn_stop = QPushButton(_("Stop")) self.btn_stop.clicked.connect(self.on_btn_stop_clicked) self.normal_style = self.btn_stop.styleSheet() self.btn_stop.setEnabled(False) btn_box.addWidget(self.btn_stop) self.btn_close = QPushButton(_("Close")) self.btn_close.clicked.connect(self.on_btn_close_clicked) btn_box.addWidget(self.btn_close) vbox.addLayout(btn_box) self.setLayout(vbox) self.resize(self.conf.work_widget_width(self.work), self.conf.work_widget_height(self.work)) def on_splitter_title_moved(self, pos, index): self.splitter_title_moved = True if not self.splitter_event_moved: self.splitter_event.moveSplitter(pos, index) self.splitter_title_moved = False def on_splitter_event_moved(self, pos, index): self.splitter_event_moved = True if not self.splitter_title_moved: self.splitter_title.moveSplitter(pos, index) self.splitter_event_moved = False def on_switch_language(self): self.setWindowTitle(_(self.work)) self.label_title.setText("%s %s" % (_(self.work), self.paras.configuration_name())) self.lbl_events_title1.setText(_("Main events")) self.lbl_events_title2.setText(_("Resources")) self.lbl_events_title3.setText(_("Errors")) self.lbl_processing.setText(_("Processing:")) self.chk_trial_run.setText(_("Trial run")) self.btn_run.setText(_("Run")) self.btn_stop.setText(_("Stop")) self.btn_close.setText(_("Close")) def on_switch_configuration(self, name=None): LOG.debug("Switch configuration: %s" % name) self.paras = self.ctrl.paras self.label_title.setText("%s %s" % (_(self.work), self.paras.configuration_name())) def on_anchor_clicked(self, url): QDesktopServices.openUrl(QUrl(url)) def on_btn_run_clicked(self): self.work_started.emit() self.pte_events1.setPlainText("") self.pte_events2.setPlainText("") self.pte_events3.setPlainText("") self.lbl_processing.setVisible(True) self.lbl_processing_file.setVisible(True) self.btn_close.setEnabled(False) self.btn_run.setEnabled(False) self.chk_trial_run.setEnabled(False) self.btn_stop.setEnabled(True) self.btn_stop.setStyleSheet(Style.alarm()) def on_btn_stop_clicked(self): self.btn_stop.setStyleSheet(self.normal_style) self.btn_stop.setEnabled(False) self.on_signal_main_event(_("Interrupt requested...")) if self.executor_thread: self.executor_thread.requestInterruption() def on_signal_exception(self, msg): self.pte_events3.appendHtml(msg) self.update() def on_ask_confirmation(self, text, i_text, answer): msg_box = QMessageBox() msg_box.setWindowTitle(_("MPT")) msg_box.setText(text) i_text += "\n\n" i_text += _("Ok to proceed?") msg_box.setInformativeText(i_text) msg_box.setIcon(QMessageBox.Question) msg_box.setStandardButtons(QMessageBox.No | QMessageBox.Yes) msg_box.setDefaultButton(QMessageBox.Yes) exe = msg_box.exec() if exe == QMessageBox.No: answer.answer = False else: answer.answer = True answer.answered = True def on_signal_main_event(self, msg): self.pte_events1.append(msg) self.update() def on_signal_minor_event(self, msg): self.pte_events2.append(msg) self.update() def on_signal_next_file(self, filename): lfn = len(filename) ww = (self.width() - 150)/7 www = int(ww/2) if lfn > ww: filename = filename[:www] + "..." + filename[lfn - www:] self.lbl_processing_file.setText(filename) self.update() def on_signal_end_processing(self, paras): self.ctrl.update_configuration(paras) def on_executor_thread_finished(self): self.btn_stop.setStyleSheet(self.normal_style) self.btn_stop.setEnabled(False) self.btn_close.setEnabled(True) self.btn_run.setEnabled(True) self.chk_trial_run.setEnabled(True) self.lbl_processing.setVisible(False) self.lbl_processing_file.setVisible(False) self.update() self.work_ended.emit() def on_btn_close_clicked(self): if self.windowState() & Qt.WindowFullScreen: self.setWindowState(Qt.WindowMaximized) else: self.close() self.destroy() def closeEvent(self, event): LOG.debug("Closing event on work window %s" % self.work) if self.executor_thread: self.executor_thread.requestInterruption() if self.windowState() & Qt.WindowFullScreen: self.setWindowState(Qt.WindowMaximized) event.ignore() else: self.save_dimensions() self.exit_if_last() event.accept() def save_dimensions(self): LOG.debug("Saving dimensions for work-window %s" % self.work) self.conf.set_work_widget_width(self.work, self.width()) self.conf.set_work_widget_height(self.work, self.height()) self.conf.persist() def exit_if_last(self): count_windows = 0 for window in QApplication.instance().topLevelWindows(): if window.type() == 1 or window.type() == 15: count_windows += 1 LOG.debug("Testing for last window. window_count=%d" % count_windows) if count_windows == 1: LOG.debug("Closing last window") QApplication.instance().quit()