def load_session(self, session): self.notice('Loading session: %r', session) if isinstance(session, basestring): session = self.sessions_controller.get_session(session) self.session = session if self.session.specification_file and not os.path.exists( self.session.specification_file): error_dialog('Specification file does not exists: %r' % (self.session.specification_file, )) if self.session.configuration_file and not os.path.exists( self.session.configuration_file): error_dialog('Configuration file does not exists: %r' % (self.session.configuration_file, )) self.session.initialize() self.main_controller.main_window.set_specification( self.session.session_config_manager) if self.session.session_config: self.main_controller.main_window.set_configuration( self.session.session_config_manager, self.session.session_config, self.session.session_config_raw) self.main_controller.main_window.update_session_status()
def finished(): if not os.path.isfile(check_file): msg = 'Error while generating file %r' % check_file self.error(msg) error_dialog(msg, title=tool['title']) else: msg = 'File %r generated' % check_file self.info(msg) info_dialog(msg, title=tool['title'])
def excepthook(self, etype, evalue, tb): ''' Display a detailed error message. ''' #self.error('Unhandled exception %s', ''.join(traceback.format_exception(etype, evalue, tb))) msg = 'Unhandled exception %s: %s' % (evalue.__class__.__name__, evalue) exc = ''.join(traceback.format_exception(etype, evalue, tb)) self.error('%s\n%s', msg, exc) error_dialog(msg, detail=exc)
def finished(): if not os.path.isfile(html_file): msg = 'Error while generating file %r' % html_file self.error(msg) error_dialog(msg, title=tool['title']) else: msg = 'File %r generated' % html_file self.info(msg) self.add_html_tab(tool['title'], html_file) info_dialog(msg, title=tool['title'])
def wrapped_finished(res, exc, tb): self.verbose('tool thread finised %r', name) progress.hide() thread = tool['thread'] if exc: detail = tb error_dialog('Error running tool %r: %s' % (tool['title'], exc), title=tool['title'], detail=detail) else: finished() thread.deleteLater() tool.pop('thread')
def run(self, args): if args.configuration_directory: self.configuration_directory = args.configuration_directory QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads) # Create the application (view) self.qapplication = QtGui.QApplication([]) # Exit, exception and signal handlers sys.excepthook = self.excepthook self.setup_signals() # Hold the session currently in use self.session = None # Create controllers self.preferences_controller = PreferencesController(self) self.sessions_controller = SessionsController(self) self.main_controller = MainController(self) # Setup plugins for name, plugin in list(self.plugins.items()): self.verbose('Enabling plugin %s', name) plugin.enable() # Start the gui self.main_controller.show_main_window() try: if args.session: self.load_session(args.session) elif args.spcfile: self.load_session( Session(specification_file=args.spcfile, configuration_file=args.cfgfile)) else: self.load_session(self.create_session()) except Exception as e: msg = 'Error loading session: %s' % e self.exception(msg) error_dialog(msg, detail=traceback.format_exc(e)) res = self.qapplication.exec_() return res
def show_log(self): title = self.tools['sonat_logs']['title'] cfg = self.get_configuration() log_file = cfg['logger']['file'] #log_file = os.path.join(cfg['session']['workdir'], log_file) if not os.path.exists(log_file): error_dialog('Log file %r does not exists' % (log_file, ), title=title) return tab = QtGui.QWidget() layout = QtGui.QVBoxLayout(tab) tab_index = self.main_window.tabs.addTab( tab, title + ' - ' + os.path.basename(log_file)) self.tab_widgets.add(tab) self.main_window.tabs.setCurrentIndex(tab_index) sublayout = QtGui.QVBoxLayout(tab) layout.addLayout(sublayout) refresh_button = QtGui.QPushButton(tab) refresh_button.setText('Refresh') refresh_button.setIcon(QtGui.QIcon.fromTheme('view-refresh')) refresh_button.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)) sublayout.addWidget(refresh_button) auto_refresh_checkbox = QtGui.QCheckBox(tab) auto_refresh_checkbox.setText('Auto refresh') auto_refresh_checkbox.setCheckState(True) sublayout.addWidget(auto_refresh_checkbox) auto_refresh_checkbox.setTristate(False) textedit = QtGui.QTextEdit(tab) textedit.setReadOnly(True) layout.addWidget(textedit) def refresh(): with file(log_file, 'rU') as f: textedit.setText(f.read()) textedit.moveCursor(QtGui.QTextCursor.End) refresh() refresh_button.clicked.connect(refresh) def setup_auto_refresh(): data = dict(last_stat=os.stat(log_file)) def auto_refresh(): if not auto_refresh_checkbox.isChecked(): return stat = os.stat(log_file) if stat.st_mtime != data['last_stat'].st_mtime: refresh() data['last_stat'] = stat return auto_refresh timer = QtCore.QTimer(tab) timer.timeout.connect(setup_auto_refresh()) timer.start(1500)