class CustomInfoWidget(QWidget): """Custom information widget""" def __init__(self, *args): QWidget.__init__(self, *args) self.value_plot = None self.title_label = QLabel(self) self.value_widget = QWidget(self) self.value_label = QLabel(self.value_widget) self.value_label.setAlignment(Qt.AlignCenter) self.history_button = QPushButton(\ Qt4_Icons.load_icon("LineGraph"), "", self.value_widget) self.history_button.hide() self.history_button.setFixedWidth(22) self.history_button.setFixedHeight(22) _value_widget_hlayout = QHBoxLayout(self.value_widget) _value_widget_hlayout.addWidget(self.value_label) _value_widget_hlayout.addWidget(self.history_button) _value_widget_hlayout.setSpacing(2) _value_widget_hlayout.setContentsMargins(0, 0, 0, 0) self.main_vlayout = QVBoxLayout(self) self.main_vlayout.addWidget(self.title_label) self.main_vlayout.addWidget(self.value_widget) self.main_vlayout.setSpacing(1) self.main_vlayout.setContentsMargins(0, 0, 0, 0) self.history_button.clicked.connect(self.open_history_view) def init_info(self, info_dict, max_plot_points=None): self.title_label.setText(info_dict.get("title", "???")) self.history_button.setVisible(info_dict.get("history", False)) font = self.value_label.font() if info_dict.get("font"): font.setPointSize(info_dict.get("font")) if info_dict.get("bold"): font.setBold(True) self.value_label.setFont(font) if info_dict.get("align") == "left": self.value_label.setAlignment(Qt.AlignLeft) elif info_dict.get("align") == "right": self.value_label.setAlignment(Qt.AlignRight) elif info_dict.get("align") == "center": self.value_label.setAlignment(Qt.AlignHCenter) elif info_dict.get("align") == "justify": self.value_label.setAlignment(Qt.AlignJustify) if info_dict.get("history"): self.history_button.show() self.value_plot = TwoAxisPlotWidget(self, realtime_plot=True) self.value_plot.hide() self.main_vlayout.addWidget(self.value_plot) self.value_plot.set_tight_layout() self.value_plot.clear() self.value_plot.set_max_plot_point(max_plot_points) #self.value_plot.set_y_axis_limits([0, None]) self.update_info(info_dict) def update_info(self, info_dict): if info_dict.get("value_str"): self.value_label.setText(info_dict.get("value_str")) else: self.value_label.setText(str(info_dict.get("value"))) if info_dict.get('in_range') is None: Qt4_widget_colors.set_widget_color(self.value_label, Qt4_widget_colors.GRAY) elif info_dict.get('in_range') == True: Qt4_widget_colors.set_widget_color(self.value_label, Qt4_widget_colors.LIGHT_BLUE) else: Qt4_widget_colors.set_widget_color(self.value_label, Qt4_widget_colors.LIGHT_RED) value = info_dict.get('value') if type(value) in (int, float) and self.value_plot: self.value_plot.add_new_plot_value(value) def open_history_view(self): self.value_plot.setVisible(not self.value_plot.isVisible())
class CustomInfoWidget(QtGui.QWidget): def __init__(self, *args): """ Descript. : """ QtGui.QWidget.__init__(self, *args) self.value_plot = None self.title_label = QtGui.QLabel(self) self.value_widget = QtGui.QWidget(self) self.value_label = QtGui.QLabel(self.value_widget) self.value_label.setAlignment(QtCore.Qt.AlignCenter) self.history_button = QtGui.QPushButton(\ Qt4_Icons.load_icon("LineGraph"), "", self.value_widget) self.history_button.hide() self.history_button.setFixedWidth(22) self.history_button.setFixedHeight(22) _value_widget_hlayout = QtGui.QHBoxLayout(self.value_widget) _value_widget_hlayout.addWidget(self.value_label) _value_widget_hlayout.addWidget(self.history_button) _value_widget_hlayout.setSpacing(2) _value_widget_hlayout.setContentsMargins(0, 0, 0, 0) self.main_vlayout = QtGui.QVBoxLayout(self) self.main_vlayout.addWidget(self.title_label) self.main_vlayout.addWidget(self.value_widget) self.main_vlayout.setSpacing(1) self.main_vlayout.setContentsMargins(0, 0, 0, 0) self.history_button.clicked.connect(self.open_history_view) def init_info(self, info_dict, max_plot_points=None): self.title_label.setText(info_dict.get("title", "???")) self.history_button.setVisible(info_dict.get("history", False)) font = self.value_label.font() if info_dict.get("font"): font.setPointSize(info_dict.get("font")) if info_dict.get("bold"): font.setBold(True) self.value_label.setFont(font) if info_dict.get("history"): self.history_button.show() self.value_plot = TwoAxisPlotWidget(self, realtime_plot=True) self.value_plot.hide() self.main_vlayout.addWidget(self.value_plot) self.value_plot.set_tight_layout() self.value_plot.clear() self.value_plot.set_max_plot_point(max_plot_points) self.update_info(info_dict) def update_info(self, info_dict): if info_dict.get("value_str"): self.value_label.setText(info_dict.get("value_str")) else: self.value_label.setText(str(info_dict.get("value"))) if info_dict.get('in_range') is None: Qt4_widget_colors.set_widget_color(self.value_label, Qt4_widget_colors.GRAY) elif info_dict.get('in_range') == True: Qt4_widget_colors.set_widget_color(self.value_label, Qt4_widget_colors.LIGHT_BLUE) else: Qt4_widget_colors.set_widget_color(self.value_label, Qt4_widget_colors.LIGHT_RED) value = info_dict.get('value') if type(value) in (int, float) and self.value_plot: self.value_plot.add_new_plot_value(value) def open_history_view(self): self.value_plot.setVisible(not self.value_plot.isVisible())