def __init__(self, parent=None, **kwds): QtGui.QFrame.__init__(self, parent) self.plot_params = kwds print('kwds=', kwds) # self.plotWidget=CartesianPlot() # self.plotWidget = pg.PlotWidget(background='w') self.plotWidget = pg.PlotWidget() try: bg_color = kwds['background'] except LookupError: bg_color = None if bg_color: try: bg_color_rgb = wc.name_to_rgb(bg_color) self.plotWidget.setBackground(background=bg_color_rgb) except ValueError as e: print('Could not decode the color %s : Exception : %s' % (bg_color, str(e)), file=sys.stderr) # self.plotWidget = pg.GraphicsView() self.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)) self.plotInterface = None self.parentWidget = parent layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom) layout.addWidget(self.plotWidget) # self.setWindowTitle(kwds['title']) # setting title bar on the window self.plotWidget.setTitle(kwds['title']) self.plotWidget.setLabel(axis='bottom', text=kwds['xAxisTitle']) self.plotWidget.setLabel(axis='left', text=kwds['yAxisTitle']) x_log_flag, y_log_flag = False, False if kwds['xScaleType'].strip().lower() == 'log': x_log_flag = True if kwds['yScaleType'].strip().lower() == 'log': y_log_flag = True self.plotWidget.setLogMode(x=x_log_flag, y=y_log_flag) if kwds['grid']: self.plotWidget.showGrid(x=True, y=True, alpha=1.0) self.setLayout(layout) # self.resize(600, 600) self.setMinimumSize( 100, 100) # needs to be defined to resize smaller than 400x400
def __init__(self, parent=None, **kwds): QtGui.QFrame.__init__(self, parent) self.plot_params = kwds print 'kwds=', kwds # self.plotWidget=CartesianPlot() # self.plotWidget = pg.PlotWidget(background='w') self.plotWidget = pg.PlotWidget() try: bg_color = kwds['background'] except LookupError: bg_color = None if bg_color: try: bg_color_rgb = wc.name_to_rgb(bg_color) self.plotWidget.setBackground(background=bg_color_rgb) except ValueError as e: print >>sys.stderr, 'Could not decode the color %s : Exception : %s'%(bg_color, str(e)) # self.plotWidget = pg.GraphicsView() self.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)) self.plotInterface = None self.parentWidget = parent layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom) layout.addWidget(self.plotWidget) # self.setWindowTitle(kwds['title']) # setting title bar on the window self.plotWidget.setTitle(kwds['title']) self.plotWidget.setLabel(axis='bottom', text=kwds['xAxisTitle']) self.plotWidget.setLabel(axis='left', text=kwds['yAxisTitle']) x_log_flag, y_log_flag = False, False if kwds['xScaleType'].strip().lower() == 'log': x_log_flag = True if kwds['yScaleType'].strip().lower() == 'log': y_log_flag = True self.plotWidget.setLogMode(x=x_log_flag, y=y_log_flag) if kwds['grid']: self.plotWidget.showGrid(x=True, y=True, alpha=1.0) # self.plotWidget.setLabel(axis='bottom',text='DUPA') # todo OK # view = pg.GraphicsView() # l = pg.GraphicsLayout(border=(100, 100, 100)) # view.setCentralItem(l) # l.addLabel('DUPA') # l.nextRow() # self.plotWidget = l.addPlot(title='Generic Plot') # l.nextRow() # self.legend = pg.LegendItem() # l.addItem(self.legend) # # # # view.show() # view.setWindowTitle('pyqtgraph example: GraphicsLayout') # # layout.addWidget(view) # legend_item = pg.LegendItem() # vb = self.plotWidget.addViewBox() self.setLayout(layout) # self.resize(600, 600) self.setMinimumSize(100, 100) # needs to be defined to resize smaller than 400x400
def init_ui(self): """Initializes all UI elements""" # Sets title and UI layout print("Starting init_ui") self.setWindowTitle('Digital Wattmeter Simulator') win = QtGui.QBoxLayout(QtGui.QBoxLayout.LeftToRight) # creates a plot widget and adds it to the window self.plotwidget = pg.PlotWidget() self.plotwidget.setTitle("Power") self.plotwidget.setLabel('left', "Voltage(V)") self.plotwidget.setLabel('bottom', "Time(ms)") self.plotwidget.showGrid(x=True, y=True) win.addWidget(self.plotwidget) butt_win1 = QtGui.QFormLayout() butt_win2 = QtGui.QFormLayout() butt_win3 = QtGui.QFormLayout() self.space_label = QtGui.QLabel("") # ** Column 1 ** column1 = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom) column1.addLayout(self.waveform1.butt_win) column1.addLayout(self.waveform2.butt_win) # ** Column 2 ** # Label column2 = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom) self.label3 = QtGui.QLabel("Sampling") butt_win1.addRow(self.label3) self.labelp = QtGui.QLabel("Power") butt_win2.addRow(self.labelp) # Sample Time self.edit_time_box = QtGui.QSpinBox() self.edit_time_box.setRange(0, self.total_time) self.edit_time_box.setValue(self.st) self.edit_time_box.setGeometry(1, 1, 1, 1) self.edit_time_box.setSingleStep(100) butt_win1.addRow("Start Time", self.edit_time_box) self.edit_time_box2 = QtGui.QSpinBox() self.edit_time_box2.setRange(0, self.total_time) self.edit_time_box2.setValue(self.et) self.edit_time_box2.setGeometry(1, 1, 1, 1) self.edit_time_box2.setSingleStep(100) butt_win1.addRow("End Time", self.edit_time_box2) self.edit_speed_box = QtGui.QSpinBox() self.edit_speed_box.setRange(0, 1000) self.edit_speed_box.setValue(self.speed) self.edit_speed_box.setGeometry(1, 1, 1, 1) self.edit_speed_box.setSingleStep(1) butt_win1.addRow("Sample Speed", self.edit_speed_box) # Pause self.pause_button = QtGui.QPushButton("Pause") self.pause_button.setCheckable(True) butt_win1.addRow(self.pause_button) # Reset self.reset_button = QtGui.QPushButton("Reset") butt_win1.addRow(self.reset_button) # Save self.save_button = QtGui.QPushButton("Save") butt_win1.addRow(self.save_button) # Power self.show_power_button = QtGui.QPushButton("Show Power") self.show_power_button.setCheckable(True) self.show_power_button.toggle() butt_win2.addRow(self.show_power_button) self.color_boxp = QtGui.QComboBox() self.color_boxp.addItems( ["Red", "Blue", "Green", "Yellow", "White", "None"]) butt_win2.addRow(self.color_boxp) # Power Labels self.power_label = QtGui.QLabel() butt_win2.addRow(self.power_label) self.power_rms_label = QtGui.QLabel() butt_win2.addRow(self.power_rms_label) self.filtered_power_label = QtGui.QLabel() butt_win2.addRow(self.filtered_power_label) self.reactive_power_label = QtGui.QLabel() butt_win2.addRow(self.reactive_power_label) self.apparent_power_label = QtGui.QLabel() butt_win2.addRow(self.apparent_power_label) self.power_factor_label = QtGui.QLabel() butt_win2.addRow(self.power_factor_label) self.lead_lag_label = QtGui.QLabel() butt_win2.addRow(self.lead_lag_label) self.circuit_type = QtGui.QLabel() butt_win2.addRow(self.circuit_type) #butt_win2.addRow(self.space_label) column2.addLayout(butt_win1) column2.addLayout(butt_win2) # Column 3 # Noise column3 = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom) self.label4 = QtGui.QLabel("Noise/Filter") butt_win3.addRow(self.label4) self.rand_noise_box = QtGui.QDoubleSpinBox() self.rand_noise_box.setValue(self.noise_magnitude) self.rand_noise_box.setGeometry(1, 1, 1, 1) self.rand_noise_box.setSingleStep(.01) self.rand_noise_box.setRange(0, 1000) butt_win3.addRow("Random Noise", self.rand_noise_box) # Uniform noise self.noise_button2 = QtGui.QPushButton("Uniform Noise") self.noise_button2.setCheckable(True) butt_win3.addRow(self.noise_button2) self.show_noise_button = QtGui.QPushButton("Show Noise") self.show_noise_button.setCheckable(True) butt_win3.addRow(self.show_noise_button) self.show_power_buttonp = QtGui.QPushButton("Pure Power") self.show_power_buttonp.setCheckable(True) self.show_power_buttonp.toggle() butt_win3.addRow(self.show_power_buttonp) # Filter self.show_power_buttonf = QtGui.QPushButton("Filtered Power") self.show_power_buttonf.setCheckable(True) self.show_power_buttonf.toggle() butt_win3.addRow(self.show_power_buttonf) self.color_boxfp = QtGui.QComboBox() self.color_boxfp.addItems( ["Red", "Blue", "Green", "Yellow", "White", "None"]) self.color_boxfp.setCurrentIndex(3) butt_win3.addRow(self.color_boxfp) self.edit_cutoff_box = QtGui.QDoubleSpinBox() self.edit_cutoff_box.setRange(0, 1000) self.edit_cutoff_box.setValue(self.cutoff) self.edit_cutoff_box.setGeometry(1, 1, 1, 1) self.edit_cutoff_box.setSingleStep(.1) butt_win3.addRow("Cutoff", self.edit_cutoff_box) self.edit_order_box = QtGui.QSpinBox() self.edit_order_box.setValue(self.order) self.edit_order_box.setGeometry(1, 1, 1, 1) self.edit_order_box.setRange(0, 1000) butt_win3.addRow("Order", self.edit_order_box) column3.addLayout(butt_win3) column3.addLayout(self.noiseform.butt_win) win.addLayout(column1) win.addLayout(column2) # adds the windows to the main window win.addLayout(column3) self.setLayout(win) # sets the main layout self.show() # displays the window print("init_ui complete!")
# Plots plot1 = pg.PlotWidget(w) plot1.showGrid(x=True, y=True) plot1_label = QtGui.QLabel('Solutions', font=big_font, alignment=QtCore.Qt.AlignHCenter) plot2 = pg.PlotWidget(w) plot2.showGrid(x=True, y=True) plot2_label = QtGui.QLabel('Error', font=big_font, alignment=QtCore.Qt.AlignHCenter) # Add widgets to the layout in their proper positions layout = QtGui.QBoxLayout(QtGui.QBoxLayout.LeftToRight) w.setLayout(layout) button_layout = QtGui.QGridLayout() plot_layout = QtGui.QVBoxLayout() layout.addLayout(button_layout) layout.addLayout(plot_layout, 9999) # Add plots to layout plot_layout.addWidget(plot1_label) plot_layout.addWidget(plot1) plot_layout.addWidget(plot2_label) plot_layout.addWidget(plot2) # Add fields and labels