class BufferSizeDialog(QDialog): return_value = pyqtSignal(int) def __init__(self, buffersize=0, parent=None, name=None, modal=True, fl=0): QDialog.__init__(self, parent) self.setModal(modal) BufferSizeDialogLayout = QVBoxLayout(self) layout1 = QHBoxLayout(None) self.label = QLabel(self) layout1.addWidget(self.label) self.spinBox1 = QSpinBox(self) self.spinBox1.setMinimum(0) self.spinBox1.setWrapping(True) self.spinBox1.setValue(buffersize) self.value = buffersize layout1.addWidget(self.spinBox1) BufferSizeDialogLayout.addLayout(layout1) layout3 = QHBoxLayout(None) spacer1 = QSpacerItem(71, 31, QSizePolicy.Expanding, QSizePolicy.Minimum) layout3.addItem(spacer1) self.okButton = QPushButton("okButton", self) layout3.addWidget(self.okButton) self.cancelButton = QPushButton("cancelButton", self) layout3.addWidget(self.cancelButton) BufferSizeDialogLayout.addLayout(layout3) self.resize(QSize(267, 84).expandedTo(self.minimumSizeHint())) self.okButton.clicked.connect(self.runDone) self.cancelButton.clicked.connect(self.runCancel) self.spinBox1.valueChanged.connect(self.updateValue) self.label.setBuddy(self.spinBox1) def updateValue(self, a0): self.value = a0 def runDone(self): self.return_value.emit(self.value) self.done(self.value) def runCancel(self): self.value = -1 self.runDone()
def createDataSelectorWidgets(self, parent, parent_layout): """Creates toolbuttons for complex values and Vells selection""" #print('in createDataSelectionWidgets') self._ds_top = top = QWidget(parent) parent_layout.addWidget(top) self._ds_lo = lotop = QVBoxLayout(top) lotop.setContentsMargins(0, 0, 0, 0) self._ds_complex = QWidget(top) self._ds_complex.setVisible(False) lotop.addWidget(self._ds_complex) lo = QVBoxLayout(self._ds_complex) lo.setContentsMargins(0, 0, 0, 0) lab = QLabel("complex:") lab.setAlignment(Qt.AlignHCenter) lo.addWidget(lab) # add complex selector lo0 = QHBoxLayout() lo0.setContentsMargins(0, 0, 0, 0) lo.addLayout(lo0) lo1 = QGridLayout() lo1.setContentsMargins(0, 0, 0, 0) lo1.setHorizontalSpacing(0) lo1.setVerticalSpacing(0) # lo0.addStretch(1); lo0.addLayout(lo1) # lo0.addStretch(1); bgrp = QButtonGroup(self._ds_complex) # tbdesc = { self.AMP:(u"\u007Ca\u007C",0,0),self.PHASE:(u"\u03D5",0,1),self.REAL:("Re",1,0),self.IMAG:("Im",1,1) }; # tbdesc = { self.AMP:("\\u007Ca\\u007C",0,0),self.PHASE:("\\u0278",0,1),self.REAL:("Re",1,0),self.IMAG:("Im",1,1) }; tbdesc = { self.AMP: ("Amp", 0, 0), self.PHASE: ("Pha", 0, 1), self.REAL: ("Re", 1, 0), self.IMAG: ("Im", 1, 1) } for label, qa in list(self._qas_complex.items()): tbtext, row, col = tbdesc[label] tb = QToolButton(self._ds_complex) lo1.addWidget(tb, row, col) bgrp.addButton(tb) tb.setText(tbtext) tb.setToolButtonStyle(Qt.ToolButtonTextOnly) tb.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum) tb.setCheckable(True) tb.setChecked(label is self.complex_component) tb.setMinimumWidth(32) tb.clicked[bool].connect(qa.setChecked) tb.clicked[bool].connect(self._change_complex) qa.triggered[bool].connect(tb.setChecked) self._tbs_complex[label] = tb
def __init__(self, ax_number=1, axis_parms=None, parent=None, name=""): """ specify the layout of the spinbox and the slider """ QWidget.__init__(self, parent) self.button = QPushButton(' ', self) self.ax_number = ax_number self.is_on = False self.axis_parms = axis_parms self.button_label = None self.spinbox = QSpinBox(self) self.spinbox.setMinimum(0) self.spinbox.setMaximum(99) self.spinbox.setWrapping(True) self.maxVal = 99 self.slider = QSlider(Qt.Horizontal, self) self.slider.setTickPosition(QSlider.TicksBelow) self.slider.setTickInterval(10) self.slider.setRange(0, 99) self.maxVal = 99 self.active = False self.label_info = QLabel(' ', self) self.resetValue() self.button.clicked.connect(self.emit_axis_number) self.slider.valueChanged.connect(self.update_slider) self.spinbox.valueChanged.connect(self.update_spinbox) self.layout = QGridLayout(self) self.layout.addWidget(self.label_info, 0, 0) self.layout.addWidget(self.button, 1, 0) self.layout.addWidget(self.spinbox, 0, 2) self.layout.addWidget(self.slider, 1, 2)
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = BodePlot(self) self.plot.setContentsMargins(5, 5, 5, 0) self.setContextMenuPolicy(Qt.NoContextMenu) self.setCentralWidget(self.plot) toolBar = QToolBar(self) self.addToolBar(toolBar) btnPrint = QToolButton(toolBar) btnPrint.setText("Print") btnPrint.setIcon(QIcon(QPixmap(print_xpm))) btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnPrint) btnPrint.clicked.connect(self.print_) btnExport = QToolButton(toolBar) btnExport.setText("Export") btnExport.setIcon(QIcon(QPixmap(print_xpm))) btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnExport) btnExport.clicked.connect(self.exportDocument) btnSet = QToolButton(toolBar) btnSet.setText("Set") btnSet.setIcon(QIcon(QPixmap(print_xpm))) btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnSet) btnSet.clicked.connect(self.exportDocument) toolBar.addSeparator() dampBox = QWidget(toolBar) dampLayout = QHBoxLayout(dampBox) dampLayout.setSpacing(0) dampLayout.addWidget(QWidget(dampBox), 10) # spacer dampLayout.addWidget(QLabel("Damping Factor", dampBox), 0) dampLayout.addSpacing(10) toolBar.addWidget(dampBox) self.statusBar() self.showInfo()
def make(): demo = QWidget() demo.setWindowTitle('Cpu Plot') plot = CpuPlot(demo) plot.setTitle("History") label = QLabel("Press the legend to en/disable a curve", demo) layout = QVBoxLayout(demo) layout.addWidget(plot) layout.addWidget(label) demo.resize(600, 400) demo.show() return demo
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = DataPlot(self) self.plot.setContentsMargins(5, 5, 5, 0) self.setCentralWidget(self.plot) # signal slot connect self.plot.signal_showinfo.connect(self.showInfo) font = QFont() font.setFamily("Calibri") #,Consolas font.setPointSize(16) font2 = QFont() font2.setFamily("Calibri") font2.setPointSize(12) self.plot.setFont(font2) # add toolbar toolBar = QToolBar(self) toolBar.setOrientation(Qt.Vertical) self.addToolBar(toolBar) # label COM lbl_COM = QLabel("COM:", toolBar) lbl_COM.setFont(font2) lbl_COM.setStyleSheet("") toolBar.addWidget(lbl_COM) #lineEdit_COM self.lineEdit_COM = QLineEdit(str(config.Port)) self.lineEdit_COM.setFont(font2) #self.lineEdit_COM.setMinimumWidth(100) toolBar.addWidget(self.lineEdit_COM) # label baudrate lbl_baud = QLabel("BAUD Rate:", toolBar) lbl_baud.setFont(font2) lbl_baud.setStyleSheet("") toolBar.addWidget(lbl_baud) #lineEdit_baud self.lineEdit_baud = QLineEdit(str(config.BaudRate)) #self.lineEdit_baud.setMinimumWidth(100) self.lineEdit_baud.setFont(font2) toolBar.addWidget(self.lineEdit_baud) # Connect device, QIcon(const QString &filename); // 从图像文件构造图标 btnConnect = QToolButton(toolBar) btnConnect.setText("Connect") btnConnect.setFont(font2) btnConnect.setIcon(QIcon('./icon/Connect.png')) btnConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnConnect) btnConnect.clicked.connect(self.GetComSettings_Connect) # disConnect device btnDisConnect = QToolButton(toolBar) btnDisConnect.setText("DisConnect") btnDisConnect.setFont(font2) btnDisConnect.setIcon(QIcon('./icon/Disconnect.jfif')) btnDisConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnDisConnect) btnDisConnect.clicked.connect(self.plot.DisConnect) toolBar.addSeparator() # Start timer btnStartTimer = QToolButton(toolBar) btnStartTimer.setText("Start Timer") btnStartTimer.setFont(font2) btnStartTimer.setIcon(QIcon('./icon/start.jfif')) btnStartTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStartTimer) btnStartTimer.clicked.connect(self.plot.StartTimer) # Stop timer btnStopTimer = QToolButton(toolBar) btnStopTimer.setText("Stop Timer") btnStopTimer.setFont(font2) btnStopTimer.setIcon(QIcon('./icon/stop.jfif')) btnStopTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStopTimer) btnStopTimer.clicked.connect(self.plot.StopTimer) toolBar.addSeparator() #X_LOWER lbl_x_lower = QLabel("X-Lower:", toolBar) lbl_x_lower.setFont(font2) toolBar.addWidget(lbl_x_lower) self.LineEdit_x_lower = QLineEdit(str(config.X_lower), toolBar) self.LineEdit_x_lower.setFont(font2) toolBar.addWidget(self.LineEdit_x_lower) #X_Upper lbl_x_upper = QLabel("X-Upper:", toolBar) lbl_x_upper.setFont(font2) toolBar.addWidget(lbl_x_upper) self.LineEdit_x_upper = QLineEdit(str(config.X_upper), toolBar) self.LineEdit_x_upper.setFont(font2) toolBar.addWidget(self.LineEdit_x_upper) #X_interval lbl_x_inteval = QLabel("X-Interval(s):", toolBar) lbl_x_inteval.setFont(font2) toolBar.addWidget(lbl_x_inteval) self.LineEdit_x_interval = QLineEdit(str(config.X_grid_interval), toolBar) self.LineEdit_x_interval.setFont(font2) toolBar.addWidget(self.LineEdit_x_interval) # Y_Lower lbl_y_lower = QLabel("Y-Lower:", toolBar) lbl_y_lower.setFont(font2) toolBar.addWidget(lbl_y_lower) self.LineEdit_y_Lower = QLineEdit(str(config.Y_lower), toolBar) self.LineEdit_y_Lower.setFont(font2) toolBar.addWidget(self.LineEdit_y_Lower) # Y_Upper lbl_y_uppwer = QLabel("Y-Upper:", toolBar) lbl_y_uppwer.setFont(font2) toolBar.addWidget(lbl_y_uppwer) self.LineEdit_Y_Upper = QLineEdit(str(config.Y_upper), toolBar) self.LineEdit_Y_Upper.setFont(font2) toolBar.addWidget(self.LineEdit_Y_Upper) # Y-Interval lbl_Y_Interval = QLabel("Y-Interval:", toolBar) lbl_Y_Interval.setFont(font2) toolBar.addWidget(lbl_Y_Interval) self.LineEdit_y_interval = QLineEdit(str(config.Y_grid_interval), toolBar) self.LineEdit_y_interval.setFont(font2) toolBar.addWidget(self.LineEdit_y_interval) # Set axis para btnSet = QToolButton(toolBar) btnSet.setText("Set Paras") btnSet.setFont(font2) btnSet.setIcon(QIcon('./icon/Settings.jfif')) btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnSet) btnSet.clicked.connect(self.SetParas) toolBar.addSeparator() # add print btn to toolbar btnPrint = QToolButton(toolBar) btnPrint.setText("Print") btnPrint.setFont(font2) btnPrint.setIcon(QIcon('./icon/print.jfif')) btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnPrint) btnPrint.clicked.connect(self.print_) # add Export btn to toolbar btnExport = QToolButton(toolBar) btnExport.setText("Export") btnExport.setFont(font2) btnExport.setIcon(QIcon('./icon/snapshot.jfif')) btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnExport) btnExport.clicked.connect(self.exportDocument) toolBar.addSeparator() # add About btn to toolbar btnAbout = QToolButton(toolBar) btnAbout.setText("About") btnAbout.setFont(font2) btnAbout.setIcon(QIcon('./icon/about.png')) btnAbout.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnAbout) btnAbout.clicked.connect(self.About) #self.statusBar().setStyleSheet("QStatusBar::item{border: 5px}") self.statusBar().setStyleSheet("color:green") #self.statusBar().addPermanentWidget(VLine()) self.statusBar().addPermanentWidget(QLabel("X = ")) #self.statusBar().addPermanentWidget(VLine()) self.statusBar().addPermanentWidget(QLabel("Y = ")) #self.statusBar().addPermanentWidget(VLine()) PermanentLabel = QLabel("Version:" + kProgVersion + " Developed by " + kProgramDeveloperName + " Python. Running with " + kPythonVersion) font3 = QFont() font3.setFamily("Calibri") font3.setPointSize(12) PermanentLabel.setFont(font3) self.statusBar().setFont(font3) self.statusBar().addPermanentWidget(PermanentLabel) self.showInfo("Show info here ......")
def set_data(self, dataitem, default_open=None, **opts): """ this callback receives data from the meqbrowser, when the user has requested a plot. It decides whether the data is from a VellSet or visu data record, and after any necessary preprocssing forwards the data to one of the functions which does the actual plotting """ if HAS_TIMBA: _dprint(3, '** in collections_plotter:set_data callback') self._rec = dataitem.data if HAS_TIMBA: _dprint(3, 'set_data: initial self._rec ', self._rec) _dprint(3, 'incoming record has keys ', list(self._rec.keys())) # if we are single stepping through requests, Oleg may reset the # cache, so check for a non-data record situation if self._rec is None: return if isinstance(self._rec, bool): return try: self._node_name = self._rec.name except: pass if HAS_TIMBA: _dprint(3, 'node name is ', self._node_name) if hasattr(self._rec, 'plot_label'): self._plot_label = self._rec.plot_label if hasattr(self._rec, 'tab_label'): self._tab_label = self._rec.tab_label self._vells_label = getattr(self._rec, 'vells_label', []) if not isinstance(self._vells_label, (list, tuple)): self._vells_label = [] # previous_statement_gives example output: self._vells_label ('XX', 'XY', 'YX', 'YY' self.label = '' # extra label, filled in if possible # there's a problem here somewhere ... if dmi_typename( self._rec) != 'MeqResult': # data is not already a result? # try to put request ID in label rq_id_found = False data_failure = False try: if "request_id" in self._rec.cache: self.label = "rq " + str(self._rec.cache.request_id) rq_id_found = True if "result" in self._rec.cache: self._rec = self._rec.cache.result # look for cache.result record if not rq_id_found and "request_id" in self._rec: self.label = "rq " + str(self._rec.request_id) rq_id_found = True else: data_failure = True if HAS_TIMBA: _dprint(3, 'we have req id ', self.label) except: data_failure = True if data_failure: if HAS_TIMBA: _dprint(3, ' we have a data failure') # cached_result not found, display an empty viewer with a "no result # in this node record" message (the user can then use the Display with # menu to switch to a different viewer) Message = "No cache result record was found for this node, so no plot can be made." cache_message = QLabel(Message, self.wparent()) cache_message.setTextFormat(Qt.RichText) self._wtop = cache_message self.set_widgets(cache_message) self.set_init_parameters() return if HAS_TIMBA: _dprint(3, 'collections: request id ', self.label) end_str = len(self.label) self._rq_id_end = int(self.label[end_str - 1:end_str]) if self._rq_id_end == self._prev_rq_id: new_plot = False else: new_plot = True self._prev_rq_id = self._rq_id_end if self.label.find(self.prev_label) >= 0: # we have already plotted this stuff, so return return else: self.prev_label = self.label # are we dealing with Vellsets? self.counter = self.counter + 1 self._max_per_display = 64 if "dims" in self._rec: if HAS_TIMBA: _dprint(3, '*** dims field exists ', self._rec.dims) self.dims = list(self._rec.dims) else: self.dims = None if "vellsets" in self._rec: self._number_of_planes = len(self._rec["vellsets"]) self.dims_per_group = 1 index_labels = None # make labels for multi-dim result if not self.dims is None: # in collections plotter, assume that first 'dims' # corresponds to tracks that are displayed , so determine # size of group from second dimension and up if len(self.dims) > 1: dims_start = 1 for i in range(dims_start, len(self.dims)): self.dims_per_group = self.dims_per_group * self.dims[i] if self.dims_per_group == len(self._vells_label): index_labels = self._vells_label else: if len(self._vells_label) > 0: if self._vells_label[ 0] == 'XX' or self._vells_label[0] == 'RR': # we have correlator data to display # - ignore self.dims_per_group stuff index_labels = self._vells_label else: # setup index array -- this makes a list such as [1,1],[1,2],[2,1],[2,2] (for e.g. a 2x2 array) indices = numpy.ndindex(*self.dims[dims_start:]) # sep = "," if any([dim>9 for dim in self.dims[dims_start:]]) else ""; index_labels = [ ",".join([str(x + 1) for x in ind]) for ind in indices ] # index labels not set by the above? set them here if index_labels is None: if self._number_of_planes == len(self._vells_label): index_labels = self._vells_label else: index_labels = list(range(0, 1)) # replace index labels with vells labels if self._visu_plotter is None: self.create_layout_stuff() if new_plot: self._visu_plotter.setNewPlot() data_dict = {} self._visu_plotter.setDataElementLabels( index_labels, list(self.dims[1:]) if self.dims is not None else (1, )) for i in range(self._number_of_planes): channel = int(i / self.dims_per_group) if self._node_name is None: data_dict['source'] = "Channel " + str(channel) else: data_dict['source'] = self._node_name data_dict['channel'] = channel data_dict['sequence_number'] = self.counter screen_num = channel // self._max_per_display # data_dict['data_type'] = self._tab_label + ' ' + str(screen_num+1) data_dict['data_type'] = self._tab_label + ' ' + str( screen_num) index = i - channel * self.dims_per_group if index == 0: data_dict['value'] = {} data_dict['flags'] = {} try: datakey = index_labels[index] except: pass # if channel == 100: # data_dict['value'][index] = 100.0 * self._rec.vellsets[i].value # else: # hopefully handle cases with non-existent results try: if "value" in self._rec.vellsets[i]: data_dict['value'][datakey] = self._rec.vellsets[ i].value else: data_dict['value'][datakey] = None except: data_dict['value'][datakey] = None # for test purposes # if index == 2: # data_dict['value'][datakey] = None try: if "flags" in self._rec.vellsets[i]: data_dict['flags'][datakey] = self._rec.vellsets[ i].flags else: data_dict['flags'][datakey] = None except: data_dict['flags'][datakey] = None if index == self.dims_per_group - 1: self._visu_plotter.updateEvent(data_dict) data_dict = {} # enable & highlight the cell self.enable() self.flash_refresh() if HAS_TIMBA: _dprint(3, 'exiting process_data')
def __init__(self, parent=None, name="",horizontal=False,draw_scale=True,hide_slider=False, use_int=False, add_spacer=True): # QWidget.__init__(self, parent, name) QWidget.__init__(self, parent) self.menu_table = { 'Adjust results buffer size': 301, 'Display summary plot': 302, 'X Axis': 303, 'Y Axis': 304, 'Z Axis': 305, 'Show 2D Display': 306, 'Update': 307, 'Toggle ND Controller': 308, 'Print to Postscript file': 309, 'Align Camera': 310, 'Reset Auto Scaling': 312, 'Save Display in PNG Format': 313, } self.horizontal = horizontal self.hide_slider = hide_slider self.use_int = use_int self.add_spacer = add_spacer self.allow_emit = False self.allow_summary = False self.summary_request = True self.toggle_ND_Controller = 1 self.toggle_scale_display = False self.draw_scale = draw_scale self.menu = None self.maxVal = 100 self.minVal = 0 self.scaler = 1 self.label_info = QLabel('', self) self.string_info = ' ' self.offset_index = -1 if self.horizontal or self.use_int: self.spinbox = QSpinBox(self) else: self.spinbox = QDoubleSpinBox(self) self.spinbox.setSingleStep(0.1) self.spinbox.setMinimum(self.minVal) self.spinbox.setMaximum(self.maxVal) if self.horizontal: self.slider = QSlider(Qt.Horizontal, self) if self.draw_scale: self.slider.setTickPosition(QSlider.TicksBelow) self.slider.setTickInterval(self.minVal) self.slider.setRange(self.minVal, self.maxVal) self.slider.valueChanged[int].connect(self.update_slider) self.spinbox.valueChanged[int].connect(self.update_spinbox) else: #print('creating standard vertical QSlider') self.slider = QSlider(Qt.Vertical, self) if not self.use_int: self.scaler = 10000000 min = self.scaler * self.minVal max = self.scaler * self.maxVal if self.draw_scale: self.slider.setTickPosition(QSlider.TicksRight) step = int((max-min) /20) #print('slider step should me ', step) self.slider.setTickInterval(step) #print('slider min and max', min,max) self.slider.setRange(min, max) self.slider.valueChanged[int].connect(self.update_slider) # we may not want a slider - e.g. when selecion tab pages in collections plotter self.spinbox.setWrapping(True) #print('wrapping should be set') if self.hide_slider: self.slider.hide() if self.horizontal or self.use_int: self.spinbox.valueChanged[int].connect(self.update_spinbox) else: self.spinbox.valueChanged[float].connect(self.update_spinbox) if self.horizontal: self.label_info1 = QLabel(' ', self) self.layout = QHBoxLayout(self) if self.add_spacer: spacer = QSpacerItem(22,9,QSizePolicy.Expanding,QSizePolicy.Minimum) self.layout.addItem(spacer) self.layout.addWidget(self.label_info) self.layout.addWidget(self.spinbox) self.layout.addWidget(self.label_info1) self.layout.addWidget(self.slider) self.setValue() else: self.layout = QVBoxLayout(self) self.layout.addWidget(self.label_info) self.layout.addWidget(self.slider) self.layout.addWidget(self.spinbox) if self.add_spacer: spacer = QSpacerItem(9,22,QSizePolicy.Minimum,QSizePolicy.Expanding) self.layout.addItem(spacer) self.setValue(0,reset_auto=True) # add on-line help self.setWhatsThis(results_range_help)
class ResultsRange(QWidget): # result_index = pyqtSignal(float) result_index = pyqtSignal('PyQt_PyObject') X_axis_selected = pyqtSignal() Y_axis_selected = pyqtSignal() Z_axis_selected = pyqtSignal() align_camera = pyqtSignal() twoD_display_requested = pyqtSignal() save_display = pyqtSignal() postscript_requested = pyqtSignal() doubleValueChanged = pyqtSignal(float) update_requested = pyqtSignal() show_ND_Controller = pyqtSignal() update_scale = pyqtSignal() set_auto_scaling = pyqtSignal() adjust_results_buffer_size = pyqtSignal(int) display_summary_plot = pyqtSignal() def __init__(self, parent=None, name="",horizontal=False,draw_scale=True,hide_slider=False, use_int=False, add_spacer=True): # QWidget.__init__(self, parent, name) QWidget.__init__(self, parent) self.menu_table = { 'Adjust results buffer size': 301, 'Display summary plot': 302, 'X Axis': 303, 'Y Axis': 304, 'Z Axis': 305, 'Show 2D Display': 306, 'Update': 307, 'Toggle ND Controller': 308, 'Print to Postscript file': 309, 'Align Camera': 310, 'Reset Auto Scaling': 312, 'Save Display in PNG Format': 313, } self.horizontal = horizontal self.hide_slider = hide_slider self.use_int = use_int self.add_spacer = add_spacer self.allow_emit = False self.allow_summary = False self.summary_request = True self.toggle_ND_Controller = 1 self.toggle_scale_display = False self.draw_scale = draw_scale self.menu = None self.maxVal = 100 self.minVal = 0 self.scaler = 1 self.label_info = QLabel('', self) self.string_info = ' ' self.offset_index = -1 if self.horizontal or self.use_int: self.spinbox = QSpinBox(self) else: self.spinbox = QDoubleSpinBox(self) self.spinbox.setSingleStep(0.1) self.spinbox.setMinimum(self.minVal) self.spinbox.setMaximum(self.maxVal) if self.horizontal: self.slider = QSlider(Qt.Horizontal, self) if self.draw_scale: self.slider.setTickPosition(QSlider.TicksBelow) self.slider.setTickInterval(self.minVal) self.slider.setRange(self.minVal, self.maxVal) self.slider.valueChanged[int].connect(self.update_slider) self.spinbox.valueChanged[int].connect(self.update_spinbox) else: #print('creating standard vertical QSlider') self.slider = QSlider(Qt.Vertical, self) if not self.use_int: self.scaler = 10000000 min = self.scaler * self.minVal max = self.scaler * self.maxVal if self.draw_scale: self.slider.setTickPosition(QSlider.TicksRight) step = int((max-min) /20) #print('slider step should me ', step) self.slider.setTickInterval(step) #print('slider min and max', min,max) self.slider.setRange(min, max) self.slider.valueChanged[int].connect(self.update_slider) # we may not want a slider - e.g. when selecion tab pages in collections plotter self.spinbox.setWrapping(True) #print('wrapping should be set') if self.hide_slider: self.slider.hide() if self.horizontal or self.use_int: self.spinbox.valueChanged[int].connect(self.update_spinbox) else: self.spinbox.valueChanged[float].connect(self.update_spinbox) if self.horizontal: self.label_info1 = QLabel(' ', self) self.layout = QHBoxLayout(self) if self.add_spacer: spacer = QSpacerItem(22,9,QSizePolicy.Expanding,QSizePolicy.Minimum) self.layout.addItem(spacer) self.layout.addWidget(self.label_info) self.layout.addWidget(self.spinbox) self.layout.addWidget(self.label_info1) self.layout.addWidget(self.slider) self.setValue() else: self.layout = QVBoxLayout(self) self.layout.addWidget(self.label_info) self.layout.addWidget(self.slider) self.layout.addWidget(self.spinbox) if self.add_spacer: spacer = QSpacerItem(9,22,QSizePolicy.Minimum,QSizePolicy.Expanding) self.layout.addItem(spacer) self.setValue(0,reset_auto=True) # add on-line help self.setWhatsThis(results_range_help) def setLabel(self, string_value= '', align=None): """ set current displayed label """ self.label_info.setText(string_value + self.string_info); if align is not None: self.label_info.setAlignment(align); def setStringInfo(self, string_value= ''): """ assign a default leading string """ self.string_info = string_value def set_decimals(self,step): if step < 0.1: self.spinbox.setDecimals(2) if step < 0.01: self.spinbox.setDecimals(3) if step < 0.001: self.spinbox.setDecimals(4) if step < 0.0001: self.spinbox.setDecimals(5) if step < 0.0001: self.spinbox.setDecimals(5) def setMinValue(self, min_value=0): """ reset allowed minimum value for spinbox and slider """ #print('in SetMinValue with min_value', min_value) self.minVal = min_value if self.horizontal or self.use_int: self.spinbox.setMinimum(self.minVal) else: step = (self.maxVal-self.minVal)/20.0 self.set_decimals(step) self.spinbox.setSingleStep(step) self.spinbox.setRange(self.minVal,self.maxVal) min = self.scaler * self.minVal max = self.scaler * self.maxVal #print('in setMinValue slider range set to ', min,max) self.slider.setRange(min, max) def setMaxValue(self, max_value= 0, allow_shrink=True): """ reset allowed maximum value for spinbox and slider """ #print('in setMaxValue with max_value and self.maxVal`', max_value, self.maxVal) #print('in setMaxValue with allow_shrink = `',allow_shrink) if max_value < self.maxVal: if allow_shrink: #print('we can shrink') self.maxVal = max_value min = self.scaler * self.minVal max = self.scaler * self.maxVal #print('in setMaxValue slider range set to ', min,max) self.slider.setRange(min, max) if self.horizontal or self.use_int: self.spinbox.setMaximum(self.maxVal) # adding this next line #print('resetting spinbox range to ', min, max) self.spinbox.setRange(min, max) else: self.spinbox.setSingleStep((self.maxVal-self.minVal)/20.0) self.spinbox.setRange(self.minVal, self.maxVal) else: if max_value > self.maxVal: self.maxVal = max_value min = self.scaler * self.minVal max = self.scaler * self.maxVal self.slider.setRange(min , max) #print('in setMaxValue slider range set to ', min,max) if self.horizontal or self.use_int: self.spinbox.setMaximum(self.maxVal) else: step = (self.maxVal-self.minVal)/20.0 self.set_decimals(step) self.spinbox.setSingleStep(step) self.spinbox.setRange(self.minVal, self.maxVal) self.slider.setValue(self.scaler*max_value) self.spinbox.setValue(max_value) def setValue(self, value= 0, reset_auto=False): """ set current values shown in spinbox and slider """ #print('in setValue raw value is ', value) max = self.scaler*value self.slider.setValue(max) #print('in setValue spinbox value set to ', max) self.spinbox.setValue(value) self.initContextmenu(reset_auto) def setRange(self, range_value, update_value = True): """ define range of values shown with slider """ #print('in setRange range value is ', range_value) if range_value <= self.maxVal: min = self.scaler * self.minVal max = self.scaler * range_value #print('in setRange slider range set to ', max) self.slider.setRange(min, max) if self.draw_scale: step = int((max-min) /20) #print('slider step should me ', step) self.slider.setTickInterval(step) if self.horizontal or self.use_int: #print('spinbox max range should be', range_value) self.spinbox.setMaximum(range_value) else: step = (range_value-self.minVal)/20.0 self.set_decimals(step) self.spinbox.setSingleStep(step) self.spinbox.setRange(self.minVal,range_value) if update_value: self.setValue(range_value) def update_slider(self, raw_slider_value): """ update spinbox value as function of slider value """ #print('raw incoming slider value', raw_slider_value) if self.horizontal or self.use_int: slider_value = raw_slider_value self.spinbox.setValue(int(slider_value)) else: slider_value = float(raw_slider_value) / self.scaler #print('update slider value', slider_value) self.spinbox.setValue(slider_value) def update_spinbox(self, spin_value): """ update displayed contents of spinbox """ #print('incoming spin value', spin_value) self.slider.setValue(int(self.scaler* spin_value)) if self.allow_emit: #print 'emitting result_index signal ', spin_value + self.offset_index self.result_index.emit(spin_value + self.offset_index) def set_emit(self, permission=True): """ flag to allow emitting of Qt signals """ self.allow_emit = permission def X_Axis_Selected(self): """ emit signal to select X Axis for 3D display """ if self.allow_emit: # print 'emitting X_axis_selected signal' self.X_axis_selected.emit(True) def Y_Axis_Selected(self): """ emit signal to select Y Axis for 3D display """ if self.allow_emit: self.Y_axis_selected.emit(True) def Z_Axis_Selected(self): """ emit signal to select Z Axis for 3D display """ if self.allow_emit: self.Z_axis_selected.emit(True) def align_camera(self): """ emit signal to align camera to current axis """ #print('in align_camara') if self.allow_emit: self.align_camera.emit(True) def request_2D_display(self): """ emit signal to request 2D display """ if self.allow_emit: self.twoD_display_requested.emit(True) def request_PNG_file(self): """ emit signal to request PNG printout """ if self.allow_emit: self.save_display.emit(True) def request_postscript(self): """ emit signal to request Postscript printout """ if self.allow_emit: self.postscript_requested.emit(True) def requestUpdate(self): """ emit signal to request update to array (for testing) """ if self.allow_emit: self.update_requested.emit(True) def toggle_ND_controller(self): """ emit signal to toggle ND Controller on or off """ toggle_id = self.menu_table['Toggle ND Controller'] if self.toggle_ND_Controller == 1: self.toggle_ND_Controller = 0 self._toggle_nd_controller.setText('Show ND Controller') else: self.toggle_ND_Controller = 1 self._toggle_nd_controller.setText('Hide ND Controller') if self.allow_emit: self.show_ND_Controller.emit(self.toggle_ND_Controller) def set_summary(self, summary=True): """ override default value for allowing summary plot """ self.allow_summary = summary toggle_id = self.menu_table['Display summary plot'] self.menu.setItemVisible(toggle_id, self.allow_summary) def set_offset_index(self, offset): """ override default value for offset index """ self.offset_index = offset def setTickInterval(self, tick_interval): """ override default tick interval for slider """ if self.horizontal or self.use_int: self.slider.setTickInterval(tick_interval) else: self.slider.setTickInterval(self.scaler*tick_interval) def handleAutoScaling(self): """ emit signal to request 2D display """ if self.allow_emit: self.set_auto_scaling.emit(True) self.setValue(self.maxVal,reset_auto=True) def handle_menu_request(self, menuid): """ handle requested menu option """ #print(' handling menu request with id ', menuid) if menuid == self.menu_table['Reset Auto Scaling']: self.handleAutoScaling() elif menuid == self.menu_table['Display summary plot']: self.requestSummary() def initContextmenu(self, reset_auto = False): """Initialize the result buffer context menu """ if self.menu is None: self.menu = QMenu(self) self.menu.triggered.connect(self.handle_menu_request) toggle_id = self.menu_table['Reset Auto Scaling'] self._reset_auto_scaling = QAction('Reset Auto Scaling',self) self._reset_auto_scaling.setData(toggle_id) self.menu.addAction(self._reset_auto_scaling) if reset_auto: self._reset_auto_scaling.setVisible(True) else: self._reset_auto_scaling.setVisible(False) toggle_id = self.menu_table['Adjust results buffer size'] self._adjust_results_buffer_size = QAction('Adjust results buffer size',self) self._adjust_results_buffer_size.setData(toggle_id) self.menu.addAction(self._adjust_results_buffer_size) self._adjust_results_buffer_size.triggered.connect(self.handleBufferSize) if reset_auto: self._adjust_results_buffer_size.setVisible(False) else: self._adjust_results_buffer_size.setVisible(True) # option for summary plot toggle_id = self.menu_table['Display summary plot'] self._display_summary_plot = QAction('Display summary plot',self) self.menu.addAction(self._display_summary_plot) self._display_summary_plot.setVisible(False) self._display_summary_plot.setData(toggle_id) # options for 3D Display toggle_id = self.menu_table['X Axis'] self._x_axis = QAction('X Axis',self) self.menu.addAction(self._x_axis) self._x_axis.setVisible(False) self._x_axis.setData(toggle_id) self._x_axis.triggered.connect(self.X_Axis_Selected) toggle_id = self.menu_table['Y Axis'] self._y_axis = QAction('Y Axis',self) self.menu.addAction(self._y_axis) self._y_axis.setVisible(False) self._y_axis.setData(toggle_id) self._y_axis.triggered.connect(self.Y_Axis_Selected) toggle_id = self.menu_table['Z Axis'] self._z_axis = QAction('Z Axis',self) self.menu.addAction(self._z_axis) self._z_axis.setVisible(False) self._z_axis.setData(toggle_id) self._z_axis.triggered.connect(self.Z_Axis_Selected) toggle_id = self.menu_table['Align Camera'] self._align_camera = QAction('Align Camera',self) self.menu.addAction(self._align_camera) self._align_camera.setVisible(False) self._align_camera.setData(toggle_id) self._align_camera.setText('Align Camera to Current Axis') self._align_camera.triggered.connect(self.align_camera) toggle_id = self.menu_table['Show 2D Display'] self._show_2d_display = QAction('Show 2D Display',self) self.menu.addAction(self._show_2d_display) self._show_2d_display.setVisible(False) self._show_2d_display.setData(toggle_id) self._show_2d_display.triggered.connect(self.request_2D_display) toggle_id = self.menu_table['Toggle ND Controller'] self._toggle_nd_controller = QAction('Toggle ND Controller',self) self.menu.addAction(self._toggle_nd_controller) self._toggle_nd_controller.setVisible(False) self._toggle_nd_controller.setData(toggle_id) self._toggle_nd_controller.setText('Hide ND Controller') self._toggle_nd_controller.triggered.connect(self.toggle_ND_controller) toggle_id = self.menu_table['Update'] self._update = QAction('Update',self) self.menu.addAction(self._update) self._update.setVisible(False) self._update.setData(toggle_id) self._update.triggered.connect(self.requestUpdate) toggle_id = self.menu_table['Print to Postscript file'] self._print_to_postscript_file = QAction('Print to Postscript file',self) self.menu.addAction(self._print_to_postscript_file) self._print_to_postscript_file.setVisible(False) self._print_to_postscript_file.setData(toggle_id) self._print_to_postscript_file.triggered.connect(self.request_postscript) toggle_id = self.menu_table['Save Display in PNG Format'] self._save_display_in_png_format = QAction('Save Display in PNG Format',self) self.menu.addAction(self._save_display_in_png_format) self._save_display_in_png_format.setVisible(False) self._save_display_in_png_format.setData(toggle_id) self._save_display_in_png_format.triggered.connect(self.request_PNG_file) def hideNDControllerOption(self): """ do not allow the user to toggle ND Controller """ self._toggle_nd_controller.setVisible(False) def setXMenuLabel(self, text): """ update X axis context menu label """ self._x_axis.setText(text) def setYMenuLabel(self, text): """ update Y axis context menu label """ self._y_axis.setText(text) def setZMenuLabel(self, text): """ update Z axis context menu label """ self._z_axis.setText(text) def disableContextmenu(self): """ delete the result buffer context menu """ if not self.menu is None: self.menu.setParent(QWidget()) self.menu = None def init3DContextmenu(self): """add 3D options to context menu """ if self.menu is None: self.initContextmenu() # display options for 3D Display self._x_axis.setVisible(True) self._y_axis.setVisible(True) self._z_axis.setVisible(True) self._align_camera.setVisible(True) self._show_2d_display.setVisible(True) self._toggle_nd_controller.setVisible(True) self._print_to_postscript_file.setVisible(True) self._save_display_in_png_format.setVisible(True) self._adjust_results_buffer_size.setVisible(False) def initWarpContextmenu(self): """add options for warped surface to context menu """ if self.menu is None: self.initContextmenu() # display options for 3D Display self._x_axis.setVisible(False) self._y_axis.setVisible(False) self._z_axis.setVisible(False) self._align_camera.setVisible(False) self._show_2d_display.setVisible(True) self._toggle_nd_controller.setVisible(True) self._print_to_postscript_file.setVisible(True) self._save_display_in_png_format.setVisible(True) self._toggle_vtk_scale.setVisible(True) self._adjust_results_buffer_size.setVisible(False) def displayUpdateItem(self): self._update.setVisible(True) def setResultsBuffer(self, result_value): """ redefine the allowable maximum number of values """ if result_value < 0: return self.maxVal = result_value self.slider.setRange(self.minVal, self.maxVal) if self.horizontal or self.use_int: self.slider.setTickInterval((self.maxVal - self.minVal) / 10) else: self.slider.setStep((self.maxVal - self.minVal) / 10) self.spinbox.setMaximum(self.maxVal) self.adjust_results_buffer_size.emit(result_value) def handleBufferSize(self): """ callback to handle 'Adjust buffer' request from the context menu """ results_dialog = BufferSizeDialog(self.maxVal, self) results_dialog.return_value.connect(self.setResultsBuffer) results_dialog.show() def requestSummary(self, menuid): """ callback to handle 'summary plot' request from the context menu """ if menuid == self.menu_table['Display summary plot']: self.display_summary_plot.emit(self.summary_request) if self.summary_request: self.summary_request = False self.menu.changeItem(menuid, 'Discard summary plot') else: self.summary_request = True self.menu.changeItem(menuid, 'Display summary plot') def mousePressEvent(self, e): if Qt.RightButton == e.button(): e.accept() self.menu.popup(e.globalPos());
def setVellsElementLabels(self, labels, dims): # do nothing when only one label, or when already set if len(labels) < 2 or self._qas_vells: return # make menu items # print 'in setVellsElementLabels, labels = ', labels for label in labels: # make menu action self._qas_vells[label] = va = self._qag_vells.addAction(str(label)) va.setCheckable(True) # if first QAction, then check it if len(self._qas_vells) == 1: va.setChecked(True) self.vells_component = label self.vells_menu.addAction(va) self.vells_menu.menuAction().setVisible(True) # following does nothing at the moment for label in self.StokesComponents: self._qas_stokes[label] = vs = self._qag_stokes.addAction(label) vs.setCheckable(True) self.stokes_menu.addAction(vs) self.stokes_menu.menuAction().setVisible(True) # make grid of selector buttons, if dims are not too big if len(dims) == 1: dims = (1, dims[0]) if len(dims) == 2 and min(*dims) >= 2 and max(*dims) <= 6: # for dims=1, make it 1xN # add vells selector self._ds_lo.addSpacing(16) self._ds_vells = QWidget(self._ds_top) self._ds_lo.addWidget(self._ds_vells) self._ds_stokes = QWidget(self._ds_top) self._ds_lo.addWidget(self._ds_stokes) self._ds_stokes.setVisible(False) lo = QVBoxLayout(self._ds_vells) lo.setContentsMargins(0, 0, 0, 0) lab = QLabel("element:") lab.setAlignment(Qt.AlignHCenter) lo.addWidget(lab) # add data selectors for correlations and Stokes lo0 = QVBoxLayout() lo0.setContentsMargins(0, 0, 0, 0) lo.addLayout(lo0) lo1 = QGridLayout() lo1.setContentsMargins(0, 0, 0, 0) lo1.setHorizontalSpacing(0) lo1.setVerticalSpacing(0) lo0.addLayout(lo1) bgrp = QButtonGroup(self._ds_vells) # make the labels for ilabel, label in enumerate(labels): # make toolbutton tb = QToolButton(self._ds_vells) bgrp.addButton(tb) self._tbs_vells[label] = tb tb.setText(str(label)) tb.setToolButtonStyle(Qt.ToolButtonTextOnly) tb.setCheckable(True) tb.setChecked(label is self.vells_component) tb.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum) # tb.setMinimumWidth(32); qa = self._qas_vells[label] tb.clicked[bool].connect(qa.setChecked) tb.clicked[bool].connect(self._change_vells) qa.triggered[bool].connect(tb.setChecked) # add to layout in correct place row, col = divmod(ilabel, dims[1]) if dims[1] > 3: col, row = row, col lo1.addWidget(tb, row, col) # show/hide controls self._ds_vells.setVisible(len(labels) > 1) lab = QLabel("stokes:") lab.setAlignment(Qt.AlignHCenter) lo0.addWidget(lab) lo2 = QGridLayout() lo2.setContentsMargins(0, 0, 0, 0) lo2.setHorizontalSpacing(0) lo2.setVerticalSpacing(0) lo0.addLayout(lo2) bgrp = QButtonGroup(self._ds_stokes) stdesc = { self.STOKES_I: ("I", 0, 0), self.STOKES_Q: ("Q", 0, 1), self.STOKES_U: ("U", 1, 0), self.STOKES_V: ("V", 1, 1) } for label, qa in list(self._qas_stokes.items()): tbtext, row, col = stdesc[label] tb = QToolButton(self._ds_stokes) lo2.addWidget(tb, row, col) bgrp.addButton(tb) tb.setText(tbtext) tb.setToolButtonStyle(Qt.ToolButtonTextOnly) tb.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum) tb.setCheckable(True) tb.setChecked(label is self.stokes_component) qa = self._qas_stokes[label] tb.clicked[bool].connect(qa.setChecked) tb.clicked[bool].connect(self._change_stokes) qa.triggered[bool].connect(tb.setChecked) self._tbs_complex[label] = tb # show/hide controls self._ds_stokes.setVisible(len(labels) > 1)
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = DataPlot(self) self.plot.setContentsMargins(5, 5, 5, 0) self.setCentralWidget(self.plot) print(type(self.plot.signal_showinfo)) # signal slot connect self.plot.signal_showinfo.connect(self.showInfo) font = QFont() font.setFamily("Calibri") #,Consolas font.setPointSize(16) font2 = QFont() font2.setFamily("Calibri") font2.setPointSize(14) self.plot.setFont(font2) # add toolbar toolBar = QToolBar(self) self.addToolBar(toolBar) # label COM lbl_COM = QLabel("COM:", toolBar) lbl_COM.setFont(font) lbl_COM.setStyleSheet("") toolBar.addWidget(lbl_COM) #lineEdit_COM self.lineEdit_COM = QLineEdit(str(config.Port)) self.lineEdit_COM.setFont(font2) self.lineEdit_COM.setMinimumWidth(50) toolBar.addWidget(self.lineEdit_COM) # label baudrate lbl_baud = QLabel("BAUD Rate:", toolBar) lbl_baud.setFont(font) lbl_baud.setStyleSheet("") toolBar.addWidget(lbl_baud) #lineEdit_baud self.lineEdit_baud = QLineEdit(str(config.BaudRate)) self.lineEdit_baud.setMinimumWidth(100) self.lineEdit_baud.setFont(font2) toolBar.addWidget(self.lineEdit_baud) # Connect device, QIcon(const QString &filename); // 从图像文件构造图标 btnConnect = QToolButton(toolBar) btnConnect.setText("Connect") btnConnect.setFont(font2) btnConnect.setIcon(QIcon('./icon/Connect.png')) btnConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnConnect) btnConnect.clicked.connect(self.GetComSettings_Connect) # disConnect device btnDisConnect = QToolButton(toolBar) btnDisConnect.setText("DisConnect") btnDisConnect.setFont(font2) btnDisConnect.setIcon(QIcon('./icon/Disconnect.jfif')) btnDisConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnDisConnect) btnDisConnect.clicked.connect(self.plot.DisConnect) toolBar.addSeparator() # Start timer btnStartTimer = QToolButton(toolBar) btnStartTimer.setText("Start Timer") btnStartTimer.setFont(font2) btnStartTimer.setIcon(QIcon('./icon/start.jfif')) btnStartTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStartTimer) btnStartTimer.clicked.connect(self.plot.StartTimer) # Stop timer btnStopTimer = QToolButton(toolBar) btnStopTimer.setText("Stop Timer") btnStopTimer.setFont(font2) btnStopTimer.setIcon(QIcon('./icon/stop.jfif')) btnStopTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStopTimer) btnStopTimer.clicked.connect(self.plot.StopTimer) toolBar.addSeparator() #X_LOWER lbl_x_lower = QLabel("X-Lower:", toolBar) lbl_x_lower.setFont(font) toolBar.addWidget(lbl_x_lower) self.LineEdit_x_lower = QLineEdit(str(0), toolBar) self.LineEdit_x_lower.setFont(font2) toolBar.addWidget(self.LineEdit_x_lower) #X_Upper lbl_x_upper = QLabel("X-Upper:", toolBar) lbl_x_upper.setFont(font) toolBar.addWidget(lbl_x_upper) self.LineEdit_x_upper = QLineEdit(str(config.X_upper), toolBar) self.LineEdit_x_upper.setFont(font2) toolBar.addWidget(self.LineEdit_x_upper) #X_interval lbl_x_inteval = QLabel("X-Interval(s):", toolBar) lbl_x_inteval.setFont(font) toolBar.addWidget(lbl_x_inteval) self.LineEdit_x_interval = QLineEdit(str(config.X_grid_interval), toolBar) self.LineEdit_x_interval.setFont(font2) toolBar.addWidget(self.LineEdit_x_interval) # Y_Lower lbl_y_lower = QLabel("Y-Lower:", toolBar) lbl_y_lower.setFont(font) toolBar.addWidget(lbl_y_lower) self.LineEdit_y_Lower = QLineEdit(str(config.Y_lower), toolBar) self.LineEdit_y_Lower.setFont(font2) toolBar.addWidget(self.LineEdit_y_Lower) # Y_Upper lbl_y_uppwer = QLabel("Y-Upper:", toolBar) lbl_y_uppwer.setFont(font) toolBar.addWidget(lbl_y_uppwer) self.LineEdit_Y_Upper = QLineEdit(str(config.Y_upper), toolBar) self.LineEdit_Y_Upper.setFont(font2) toolBar.addWidget(self.LineEdit_Y_Upper) # Y-Interval lbl_Y_Interval = QLabel("Y-Interval:", toolBar) lbl_Y_Interval.setFont(font) toolBar.addWidget(lbl_Y_Interval) self.LineEdit_y_interval = QLineEdit(str(config.Y_grid_interval), toolBar) self.LineEdit_y_interval.setFont(font2) toolBar.addWidget(self.LineEdit_y_interval) # Set axis para btnSet = QToolButton(toolBar) btnSet.setText("Set Paras") btnSet.setFont(font2) btnSet.setIcon(QIcon('./icon/Settings.jfif')) btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnSet) btnSet.clicked.connect(self.SetParas) toolBar.addSeparator() # add print btn to toolbar btnPrint = QToolButton(toolBar) btnPrint.setText("Print") btnPrint.setFont(font2) btnPrint.setIcon(QIcon('./icon/print.jfif')) btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnPrint) btnPrint.clicked.connect(self.print_) # add Export btn to toolbar btnExport = QToolButton(toolBar) btnExport.setText("Export") btnExport.setFont(font2) btnExport.setIcon(QIcon('./icon/snapshot.jfif')) btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnExport) btnExport.clicked.connect(self.exportDocument) toolBar.addSeparator() self.statusBar() self.showInfo("Show info here ......")
class AxisRange(QWidget): """ a spinbox and a slider, either of which can be used to specify a value from within an allowed range """ axis_number = pyqtSignal('int') Value_Changed = pyqtSignal(int, int, str) def __init__(self, ax_number=1, axis_parms=None, parent=None, name=""): """ specify the layout of the spinbox and the slider """ QWidget.__init__(self, parent) self.button = QPushButton(' ', self) self.ax_number = ax_number self.is_on = False self.axis_parms = axis_parms self.button_label = None self.spinbox = QSpinBox(self) self.spinbox.setMinimum(0) self.spinbox.setMaximum(99) self.spinbox.setWrapping(True) self.maxVal = 99 self.slider = QSlider(Qt.Horizontal, self) self.slider.setTickPosition(QSlider.TicksBelow) self.slider.setTickInterval(10) self.slider.setRange(0, 99) self.maxVal = 99 self.active = False self.label_info = QLabel(' ', self) self.resetValue() self.button.clicked.connect(self.emit_axis_number) self.slider.valueChanged.connect(self.update_slider) self.spinbox.valueChanged.connect(self.update_spinbox) self.layout = QGridLayout(self) self.layout.addWidget(self.label_info, 0, 0) self.layout.addWidget(self.button, 1, 0) self.layout.addWidget(self.spinbox, 0, 2) self.layout.addWidget(self.slider, 1, 2) def emit_axis_number(self): # print 'emitting signal ', self.ax_number self.axis_number.emit(self.ax_number) def isOn(self): return self.is_on def setOn(self, value): self.is_on = value def getButton(self): return self.button def setLabel(self, label): """ set label on a button """ self.button_label = label self.button.setText(label) def value(self): """ return current value of the slider """ return self.slider.value() def hide_display(self): self.spinbox.hide() self.slider.hide() self.label_info.hide() def show_display(self): self.spinbox.show() self.slider.show() self.label_info.show() def resetValue(self): """ resets displayed values to zero """ display_str = None if self.axis_parms is None or not self.active: display_str = '' else: delta_vells = (self.axis_parms[1] - self.axis_parms[0]) / self.maxVal index = self.axis_parms[0] + 0.5 * delta_vells if abs(index) < 0.0000001: index = 0.0 display_str = "%-.4g" % index self.slider.setValue(0) self.spinbox.setValue(0) self.label_info.setText(' ' + display_str) def setDisplayString(self, value): """ define current display string from Vells parameters """ display_str = '' if not self.axis_parms is None: delta_vells = (self.axis_parms[1] - self.axis_parms[0]) / self.maxVal index = self.axis_parms[0] + (value + 0.5) * delta_vells if abs(index) < 0.0000001: index = 0.0 display_str = "%-.4g" % index self.label_info.setText(' ' + display_str) if not self.button_label is None: display_str = self.button_label + ' ' + display_str print('parms', self.ax_number, value, display_str) self.Value_Changed.emit(self.ax_number, value, display_str) def setRange(self, array_shape): """ make sure slider and spinbox both have same allowable range """ self.slider.setRange(0, array_shape - 1) self.spinbox.setMaximum(array_shape - 1) self.maxVal = array_shape def setSliderColor(self, color): """ set color of slider - red or green """ self.slider.setStyleSheet("QWidget { background-color: %s }" % color.name()) def setActive(self, active): self.active = active def text(self): return self.label.text() def setText(self, s): self.label.setText(s) def update_slider(self, slider_value): """ synchronize spinbox value to current slider value """ if self.active: self.spinbox.setValue(slider_value) self.setDisplayString(slider_value) else: self.resetValue() def update_spinbox(self, spin_value): """ synchronize slider value to current spinbox value """ if self.active: self.slider.setValue(spin_value) self.setDisplayString(spin_value) else: self.spinbox.setValue(0)
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = DataPlot(self) #self.plot.resize(540,760) self.plot.setContentsMargins(5, 5, 5, 0) self.setCentralWidget(self.plot) print(type(self.plot.signal_showinfo)) # signal slot connect self.plot.signal_showinfo.connect(self.showInfo) font = QFont() font.setFamily("Calibri") #,Consolas font.setPointSize(16) font2 = QFont() font2.setFamily("Calibri") font2.setPointSize(14) self.plot.setFont(font2) # add toolbar toolBar = QToolBar(self) self.addToolBar(toolBar) # label COM lbl_COM = QLabel("COM:",toolBar) lbl_COM.setFont(font) lbl_COM.setStyleSheet("") toolBar.addWidget(lbl_COM) #lineEdit_COM self.lineEdit_COM = QLineEdit('COM37') self.lineEdit_COM.setFont(font2) self.lineEdit_COM.setMinimumWidth(50) toolBar.addWidget(self.lineEdit_COM) # label baudrate lbl_baud = QLabel("BAUD Rate:",toolBar) lbl_baud.setFont(font) lbl_baud.setStyleSheet("") toolBar.addWidget(lbl_baud) #lineEdit_baud self.lineEdit_baud = QLineEdit('9600') self.lineEdit_baud.setMinimumWidth(100) self.lineEdit_baud.setFont(font2) toolBar.addWidget(self.lineEdit_baud) # label command lbl_command = QLabel("Command:",toolBar) lbl_command.setFont(font) lbl_command.setStyleSheet("") toolBar.addWidget(lbl_command) #lineEdit_command self.lineEdit_command = QLineEdit(r'UPPER_VAL?\r\n') self.lineEdit_command.setFont(font2) #self.lineEdit_command.resize(200,12) #self.lineEdit_command.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) self.lineEdit_command.setMinimumWidth(300) toolBar.addWidget(self.lineEdit_command) # label response_rex lbl_response_rex = QLabel("response_rex:",toolBar) lbl_response_rex.setFont(font) lbl_response_rex.setStyleSheet("") toolBar.addWidget(lbl_response_rex) #lineEdit_response_rex self.lineEdit_response_rex = QLineEdit(r'^[-]?([0-9]{1,}[.]?[0-9]*)') self.lineEdit_response_rex.setFont(font2) #self.lineEdit_command.resize(200,12) #self.lineEdit_command.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) self.lineEdit_response_rex.setMinimumWidth(300) toolBar.addWidget(self.lineEdit_response_rex) # Connect device, QIcon(const QString &filename); // 从图像文件构造图标 btnConnect = QToolButton(toolBar) btnConnect.setText("Connect") btnConnect.setFont(font2) btnConnect.setIcon(QIcon('./icon/Connect.png')) btnConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnConnect) btnConnect.clicked.connect(self.GetComSettings_Connect) # disConnect device btnDisConnect = QToolButton(toolBar) btnDisConnect.setText("DisConnect") btnDisConnect.setFont(font2) btnDisConnect.setIcon(QIcon('./icon/Disconnect.jfif')) btnDisConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnDisConnect) btnDisConnect.clicked.connect(self.plot.DisConnect) toolBar.addSeparator() # Label sample interval lbl_timer_interval = QLabel("Timer(ms):",toolBar) lbl_timer_interval.setFont(font) lbl_timer_interval.setStyleSheet("") toolBar.addWidget(lbl_timer_interval) # lineEdit sample interval self.lineEdit_timer_interval = QLineEdit('250') self.lineEdit_timer_interval.setFont(font2) self.lineEdit_timer_interval.setStyleSheet("") toolBar.addWidget(self.lineEdit_timer_interval) # Start timer btnStartTimer = QToolButton(toolBar) btnStartTimer.setText("Start Timer") btnStartTimer.setFont(font2) btnStartTimer.setIcon(QIcon('./icon/start.jfif')) btnStartTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStartTimer) btnStartTimer.clicked.connect(self.plot.StartTimer) # Stop timer btnStopTimer = QToolButton(toolBar) btnStopTimer.setText("Stop Timer") btnStopTimer.setFont(font2) btnStopTimer.setIcon(QIcon('./icon/stop.jfif')) btnStopTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnStopTimer) btnStopTimer.clicked.connect(self.plot.StopTimer) toolBar.addSeparator() # dampBox = QWidget(toolBar) # dampLayout = QHBoxLayout(dampBox) # dampLayout.setSpacing(0) # dampLayout.addWidget(QWidget(dampBox), 0) # spacer #X_interval lbl_x_inteval = QLabel("X-Interval(s):", toolBar) lbl_x_inteval.setFont(font) #dampLayout.addWidget(lbl_x_inteval, 0) toolBar.addWidget(lbl_x_inteval) self.LineEdit_x_interval= QLineEdit('30',toolBar) self.LineEdit_x_interval.setFont(font2) #dampLayout.addWidget(self.LineEdit_x_interval,0) #dampLayout.addSpacing(10) toolBar.addWidget(self.LineEdit_x_interval) # Y_Lower lbl_y_lower = QLabel("Y-Lower:", toolBar) lbl_y_lower.setFont(font) #dampLayout.addWidget(lbl_y_lower, 0) toolBar.addWidget(lbl_y_lower) self.LineEdit_y_Lower = QLineEdit('-90', toolBar) self.LineEdit_y_Lower.setFont(font2) #dampLayout.addWidget(self.LineEdit_y_Lower, 0) #dampLayout.addSpacing(10) toolBar.addWidget(self.LineEdit_y_Lower) # Y_Upper lbl_y_uppwer = QLabel("Y-Upper:", toolBar) lbl_y_uppwer.setFont(font) #dampLayout.addWidget(lbl_y_uppwer, 0) toolBar.addWidget(lbl_y_uppwer) self.LineEdit_Y_Upper = QLineEdit('210', toolBar) self.LineEdit_Y_Upper.setFont(font2) #dampLayout.addWidget(self.LineEdit_Y_Upper, 0) #dampLayout.addSpacing(10) toolBar.addWidget(self.LineEdit_Y_Upper) # Y-Interval lbl_Y_Interval = QLabel("Y-Interval:", toolBar) lbl_Y_Interval.setFont(font) #dampLayout.addWidget(lbl_Y_Interval, 0) toolBar.addWidget(lbl_Y_Interval) self.LineEdit_y_interval= QLineEdit('50', toolBar) self.LineEdit_y_interval.setFont(font2) #dampLayout.addWidget(self.LineEdit_y_interval, 0) #dampLayout.addSpacing(10) toolBar.addWidget(self.LineEdit_y_interval) #toolBar.addWidget(dampBox) # Set axis para btnSet = QToolButton(toolBar) btnSet.setText("Set Paras") btnSet.setFont(font2) btnSet.setIcon(QIcon('./icon/Settings.jfif')) btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnSet) btnSet.clicked.connect(self.SetParas) toolBar.addSeparator() # add print btn to toolbar btnPrint = QToolButton(toolBar) btnPrint.setText("Print") btnPrint.setFont(font2) btnPrint.setIcon(QIcon('./icon/print.jfif')) btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnPrint) btnPrint.clicked.connect(self.print_) # add Export btn to toolbar btnExport = QToolButton(toolBar) btnExport.setText("Export") btnExport.setFont(font2) btnExport.setIcon(QIcon('./icon/snapshot.jfif')) btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnExport) btnExport.clicked.connect(self.exportDocument) toolBar.addSeparator() self.statusBar() self.showInfo("Show info here ......")