def init_formatter(self): try: self.formatter = PlotFormatter(self.settings) except Exception as e: traceback.print_exc() if isinstance(e, RuntimeError): err = "%s" % e else: typ, val, tra = sys.exc_info() err = "".join(traceback.format_exception_only(typ, val)) QMessageBox.warning( self, "Error loading plot", "Error while loading plot:\n\n%s\nFalling back to default plot. Full traceback output to console." % err) self.settings.PLOT = self.settings.DEFAULTS['PLOT'] self.formatter = PlotFormatter(self.settings) self.canvas = FigureCanvas(self.formatter.figure) self.canvas.setParent(self.graphDisplay) self.toolbar = NavigationToolbar(self.canvas, self.graphDisplay) vbl = QVBoxLayout() vbl.addWidget(self.canvas) vbl.addWidget(self.toolbar) self.graphDisplay.setLayout(vbl) self.plotModel = PlotModel(self, self.settings) self.plotSelectionModel = QItemSelectionModel(self.plotModel) self.plotSelectionModel.setCurrentIndex( self.plotModel.index_of(self.settings.PLOT), QItemSelectionModel.SelectCurrent) self.plotSelectionModel.currentChanged.connect(self.change_plot) self.metadataModel = MetadataModel(self, self.results.meta()) self.metadataSelectionModel = QItemSelectionModel(self.metadataModel) if self.settings.TITLE: self.title = "%s - %s" % (self.settings.NAME, self.settings.TITLE) self.long_title = "%s - %s" % ( self.title, self.settings.TIME.strftime("%Y-%m-%d %H:%M:%S")) else: self.title = "%s - %s" % ( self.settings.NAME, self.settings.TIME.strftime("%Y-%m-%d %H:%M:%S")) self.long_title = self.title if self.settings.GUI_NO_DEFER: self.redraw()
def init_formatter(self): try: self.formatter = PlotFormatter(self.settings) except Exception as e: traceback.print_exc() if isinstance(e, RuntimeError): err = "%s" % e else: typ,val,tra = sys.exc_info() err = "".join(traceback.format_exception_only(typ,val)) QMessageBox.warning(self, "Error loading plot", "Error while loading plot:\n\n%s\nFalling back to default plot. Full traceback output to console." % err) self.settings.PLOT = self.settings.DEFAULTS['PLOT'] self.formatter = PlotFormatter(self.settings) self.canvas = FigureCanvas(self.formatter.figure) self.canvas.setParent(self.graphDisplay) self.toolbar = NavigationToolbar(self.canvas, self.graphDisplay) vbl = QVBoxLayout() vbl.addWidget(self.canvas) vbl.addWidget(self.toolbar) self.graphDisplay.setLayout(vbl) self.plotModel = PlotModel(self, self.settings) self.plotSelectionModel = QItemSelectionModel(self.plotModel) self.plotSelectionModel.setCurrentIndex(self.plotModel.index_of(self.settings.PLOT), QItemSelectionModel.SelectCurrent) self.plotSelectionModel.currentChanged.connect(self.change_plot) self.metadataModel = MetadataModel(self, self.results.meta()) self.metadataSelectionModel = QItemSelectionModel(self.metadataModel) if self.settings.TITLE: self.title = "%s - %s" % (self.settings.NAME, self.settings.TITLE) self.long_title = "%s - %s" % (self.title, self.settings.TIME.strftime("%Y-%m-%d %H:%M:%S")) else: self.title = "%s - %s" % (self.settings.NAME, self.settings.TIME.strftime("%Y-%m-%d %H:%M:%S")) self.long_title = self.title if self.settings.GUI_NO_DEFER: self.redraw()
class ResultWidget(get_ui_class("resultwidget.ui")): update_start = pyqtSignal() update_end = pyqtSignal() plot_changed = pyqtSignal('QString', 'QString') default_title = "New tab" def __init__(self, parent, settings): super(ResultWidget, self).__init__(parent) self.results = None self.settings = settings.copy() self.dirty = True self.settings.OUTPUT = "-" self.extra_results = [] self.title = self.default_title self.plotModel = None self.plotSelectionModel = None self.metadataModel = None self.metadataSelectionModel = None self.toolbar = None self.formatter = None @property def is_active(self): return self.results is not None def init_formatter(self): try: self.formatter = PlotFormatter(self.settings) except Exception as e: traceback.print_exc() if isinstance(e, RuntimeError): err = "%s" % e else: typ,val,tra = sys.exc_info() err = "".join(traceback.format_exception_only(typ,val)) QMessageBox.warning(self, "Error loading plot", "Error while loading plot:\n\n%s\nFalling back to default plot. Full traceback output to console." % err) self.settings.PLOT = self.settings.DEFAULTS['PLOT'] self.formatter = PlotFormatter(self.settings) self.canvas = FigureCanvas(self.formatter.figure) self.canvas.setParent(self.graphDisplay) self.toolbar = NavigationToolbar(self.canvas, self.graphDisplay) vbl = QVBoxLayout() vbl.addWidget(self.canvas) vbl.addWidget(self.toolbar) self.graphDisplay.setLayout(vbl) self.plotModel = PlotModel(self, self.settings) self.plotSelectionModel = QItemSelectionModel(self.plotModel) self.plotSelectionModel.setCurrentIndex(self.plotModel.index_of(self.settings.PLOT), QItemSelectionModel.SelectCurrent) self.plotSelectionModel.currentChanged.connect(self.change_plot) self.metadataModel = MetadataModel(self, self.results.meta()) self.metadataSelectionModel = QItemSelectionModel(self.metadataModel) if self.settings.TITLE: self.title = "%s - %s" % (self.settings.NAME, self.settings.TITLE) self.long_title = "%s - %s" % (self.title, self.settings.TIME.strftime("%Y-%m-%d %H:%M:%S")) else: self.title = "%s - %s" % (self.settings.NAME, self.settings.TIME.strftime("%Y-%m-%d %H:%M:%S")) self.long_title = self.title if self.settings.GUI_NO_DEFER: self.redraw() def has(self, resultset): return resultset in chain([self.results], self.extra_results) def load_results(self, results): if isinstance(results, ResultSet): self.results = results else: self.results = ResultSet.load_file(unicode(results)) self.settings.update(self.results.meta()) self.settings.load_test(informational=True) self.settings.compute_missing_results(self.results) self.init_formatter() return True def disconnect_all(self): for s in (self.update_start, self.update_end, self.plot_changed): s.disconnect() def disable_cleanup(self): if self.formatter is not None: self.formatter.disable_cleanup = True def load_files(self, filenames): added = 0 for f in filenames: if self.add_extra(ResultSet.load_file(unicode(f))): self.update(False) added += 1 self.redraw() return added def add_extra(self, resultset): if self.results is None: return self.load_results(resultset) if resultset in self.extra_results: return False if resultset.meta('NAME') == self.settings.NAME: self.extra_results.append(resultset) self.update() return True return False def remove_extra(self, resultset): if not resultset in self.extra_results: if resultset == self.results and self.extra_results: self.results = self.extra_results.pop(0) self.update() return True return False self.extra_results.remove(resultset) self.update() return True def clear_extra(self): self.extra_results = [] self.update() @property def can_save(self): # Check for attribute to not crash on a matplotlib version that does not # have the save action. return hasattr(self.toolbar, 'save_figure') def save_plot(self): if self.can_save: self.toolbar.save_figure() def zero_y(self, val=None): if val is not None and val != self.settings.ZERO_Y: self.settings.ZERO_Y = val self.update() return self.settings.ZERO_Y def invert_y(self, val=None): if val is not None and val != self.settings.INVERT_Y: self.settings.INVERT_Y = val self.update() return self.settings.INVERT_Y def disable_log(self, val=None): if val is not None and val == self.settings.LOG_SCALE: self.settings.LOG_SCALE = not val self.update() return not self.settings.LOG_SCALE def scale_mode(self, val=None): if val is not None and val != self.settings.SCALE_MODE: self.settings.SCALE_MODE = val self.update() return self.settings.SCALE_MODE def subplot_combine(self, val=None): if val is not None and val != self.settings.SUBPLOT_COMBINE: self.settings.SUBPLOT_COMBINE = val self.update() return self.settings.SUBPLOT_COMBINE def draw_annotation(self, val=None): if val is not None and val != self.settings.ANNOTATE: self.settings.ANNOTATE = val self.update() return self.settings.ANNOTATE def draw_legend(self, val=None): if val is not None and val != self.settings.PRINT_LEGEND: self.settings.PRINT_LEGEND = val self.update() return self.settings.PRINT_LEGEND def draw_title(self, val=None): if val is not None and val != self.settings.PRINT_TITLE: self.settings.PRINT_TITLE = val self.update() return self.settings.PRINT_TITLE def filter_legend(self, val=None): if val is not None and val != self.settings.FILTER_LEGEND: self.settings.FILTER_LEGEND = val self.update() return self.settings.FILTER_LEGEND def change_plot(self, plot_name): if isinstance(plot_name, QModelIndex): plot_name = self.plotModel.name_of(plot_name) plot_name = unicode(plot_name) if plot_name != self.settings.PLOT and plot_name in self.settings.PLOTS: self.settings.PLOT = plot_name self.plotSelectionModel.setCurrentIndex(self.plotModel.index_of(self.settings.PLOT), QItemSelectionModel.SelectCurrent) self.plot_changed.emit(self.settings.NAME, self.settings.PLOT) self.update() return True return False @property def current_plot(self): if not self.is_active: return None return self.settings.PLOT def updates_disabled(self): return UpdateDisabler(self) def update(self, redraw=True): self.dirty = True if redraw and ((self.isVisible() and self.updatesEnabled()) or self.settings.GUI_NO_DEFER): self.redraw() def redraw(self): if not self.dirty or not self.is_active: return self.update_start.emit() try: self.formatter.init_plots() if self.settings.SCALE_MODE: self.settings.SCALE_DATA = self.extra_results self.formatter.format([self.results]) else: self.settings.SCALE_DATA = [] self.formatter.format([self.results] + self.extra_results) self.canvas.draw() self.dirty = False except Exception as e: traceback.print_exc() typ,val,tra = sys.exc_info() err = "".join(traceback.format_exception_only(typ,val)) QMessageBox.warning(self, "Error plotting", "Unhandled exception while plotting:\n\n%s\nAborting. Full traceback output to console." % err) finally: self.update_end.emit()
class ResultWidget(get_ui_class("resultwidget.ui")): update_start = pyqtSignal() update_end = pyqtSignal() plot_changed = pyqtSignal('QString', 'QString') def __init__(self, parent, filename, settings): super(ResultWidget, self).__init__(parent) self.filename = unicode(filename) self.settings = settings.copy() self.dirty = True self.settings.OUTPUT = "-" self.results = ResultSet.load_file(self.filename) self.extra_results = [] self.settings.update(self.results.meta()) self.settings.load_test(informational=True) self.settings.compute_missing_results(self.results) try: self.formatter = PlotFormatter(self.settings) except Exception as e: traceback.print_exc() if isinstance(e, RuntimeError): err = "%s" % e else: typ, val, tra = sys.exc_info() err = "".join(traceback.format_exception_only(typ, val)) QMessageBox.warning( self, "Error loading plot", "Error while loading plot:\n\n%s\nFalling back to default plot. Full traceback output to console." % err) self.settings.PLOT = self.settings.DEFAULTS['PLOT'] self.formatter = PlotFormatter(self.settings) self.canvas = FigureCanvas(self.formatter.figure) self.canvas.setParent(self.graphDisplay) self.toolbar = NavigationToolbar(self.canvas, self.graphDisplay) vbl = QVBoxLayout() vbl.addWidget(self.canvas) vbl.addWidget(self.toolbar) self.graphDisplay.setLayout(vbl) self.plotModel = PlotModel(self, self.settings) self.plotSelectionModel = QItemSelectionModel(self.plotModel) self.plotSelectionModel.setCurrentIndex( self.plotModel.index_of(self.settings.PLOT), QItemSelectionModel.SelectCurrent) self.plotSelectionModel.currentChanged.connect(self.change_plot) self.metadataModel = MetadataModel(self, self.results.meta()) self.metadataSelectionModel = QItemSelectionModel(self.metadataModel) if self.settings.TITLE: self.title = "%s - %s" % (self.settings.NAME, self.settings.TITLE) self.long_title = "%s - %s" % ( self.title, self.settings.TIME.strftime("%Y-%m-%d %H:%M:%S")) else: self.title = "%s - %s" % ( self.settings.NAME, self.settings.TIME.strftime("%Y-%m-%d %H:%M:%S")) self.long_title = self.title if self.settings.GUI_NO_DEFER: self.redraw() def disconnect_all(self): for s in (self.update_start, self.update_end, self.plot_changed): s.disconnect() def disable_cleanup(self): self.formatter.disable_cleanup = True def load_files(self, filenames): added = 0 for f in filenames: if self.add_extra(ResultSet.load_file(unicode(f))): self.update(False) added += 1 self.redraw() return added def add_extra(self, resultset): if resultset.meta('NAME') == self.settings.NAME: self.extra_results.append(resultset) self.update() return True return False def clear_extra(self): self.extra_results = [] self.update() def can_save(self): # Check for attribute to not crash on a matplotlib version that does not # have the save action. return hasattr(self.toolbar, 'save_figure') def save_plot(self): if self.can_save(): self.toolbar.save_figure() def zero_y(self, val=None): if val is not None and val != self.settings.ZERO_Y: self.settings.ZERO_Y = val self.update() return self.settings.ZERO_Y def invert_y(self, val=None): if val is not None and val != self.settings.INVERT_Y: self.settings.INVERT_Y = val self.update() return self.settings.INVERT_Y def disable_log(self, val=None): if val is not None and val == self.settings.LOG_SCALE: self.settings.LOG_SCALE = not val self.update() return not self.settings.LOG_SCALE def scale_mode(self, val=None): if val is not None and val != self.settings.SCALE_MODE: self.settings.SCALE_MODE = val self.update() return self.settings.SCALE_MODE def subplot_combine(self, val=None): if val is not None and val != self.settings.SUBPLOT_COMBINE: self.settings.SUBPLOT_COMBINE = val self.update() return self.settings.SUBPLOT_COMBINE def draw_annotation(self, val=None): if val is not None and val != self.settings.ANNOTATE: self.settings.ANNOTATE = val self.update() return self.settings.ANNOTATE def draw_legend(self, val=None): if val is not None and val != self.settings.PRINT_LEGEND: self.settings.PRINT_LEGEND = val self.update() return self.settings.PRINT_LEGEND def draw_title(self, val=None): if val is not None and val != self.settings.PRINT_TITLE: self.settings.PRINT_TITLE = val self.update() return self.settings.PRINT_TITLE def filter_legend(self, val=None): if val is not None and val != self.settings.FILTER_LEGEND: self.settings.FILTER_LEGEND = val self.update() return self.settings.FILTER_LEGEND def change_plot(self, plot_name): if isinstance(plot_name, QModelIndex): plot_name = self.plotModel.name_of(plot_name) plot_name = unicode(plot_name) if plot_name != self.settings.PLOT and plot_name in self.settings.PLOTS: self.settings.PLOT = plot_name self.plotSelectionModel.setCurrentIndex( self.plotModel.index_of(self.settings.PLOT), QItemSelectionModel.SelectCurrent) self.plot_changed.emit(self.settings.NAME, self.settings.PLOT) self.update() return True return False def current_plot(self): return self.settings.PLOT def updates_disabled(self): return UpdateDisabler(self) def update(self, redraw=True): self.dirty = True if redraw and ((self.isVisible() and self.updatesEnabled()) or self.settings.GUI_NO_DEFER): self.redraw() def redraw(self): if not self.dirty: return self.update_start.emit() try: self.formatter.init_plots() if self.settings.SCALE_MODE: self.settings.SCALE_DATA = self.extra_results self.formatter.format([self.results]) else: self.settings.SCALE_DATA = [] self.formatter.format([self.results] + self.extra_results) self.canvas.draw() self.dirty = False except Exception as e: traceback.print_exc() typ, val, tra = sys.exc_info() err = "".join(traceback.format_exception_only(typ, val)) QMessageBox.warning( self, "Error plotting", "Unhandled exception while plotting:\n\n%s\nAborting. Full traceback output to console." % err) finally: self.update_end.emit()