def initUI(self): OVER_CAPACITY = 750 sld = QSlider(Qt.Orientations.Horizontal, self) sld.setFocusPolicy(Qt.FocusPolicy.NoFocus) sld.setRange(1, OVER_CAPACITY) sld.setValue(75) sld.setGeometry(30, 40, 150, 30) self.c = Communicate() self.wid = BurningWidget() self.c.updateBW[int].connect(self.wid.setValue) sld.valueChanged[int].connect(self.changeValue) hbox = QHBoxLayout() hbox.addWidget(self.wid) vbox = QVBoxLayout() vbox.addStretch(1) vbox.addLayout(hbox) self.setLayout(vbox) self.setGeometry(300, 300, 390, 210) self.setWindowTitle('Burning widget') self.show()
def make_slider(MAX_RANGE, INIT_VALUE): label = QLabel("") label.setAlignment(Qt.AlignmentFlag.AlignCenter) slider = QSlider(orientation=Qt.Orientation.Horizontal) slider.setRange(0, SLIDER_MAX_RANGE_INT) slider.setValue(int(SLIDER_MAX_RANGE_INT*(INIT_VALUE/MAX_RANGE))) slider.setTickPosition(QSlider.TickPosition.TicksBelow) slider.setTickInterval(int(SLIDER_MAX_RANGE_INT*0.1)) slider.setSingleStep(1) return slider, label
def initUI(self): sld = QSlider(Qt.Orientation.Horizontal, self) sld.setFocusPolicy(Qt.FocusPolicy.NoFocus) sld.setGeometry(30, 40, 200, 30) sld.valueChanged[int].connect(self.changeValue) self.label = QLabel(self) self.label.setPixmap(QPixmap('mute.png')) self.label.setGeometry(250, 40, 80, 30) self.setGeometry(300, 300, 350, 250) self.setWindowTitle('QSlider') self.show()
def initUI(self): lcd = QLCDNumber(self) sld = QSlider(Qt.Orientation.Horizontal, self) vbox = QVBoxLayout() vbox.addWidget(lcd) vbox.addWidget(sld) self.setLayout(vbox) sld.valueChanged.connect(lcd.display) self.setGeometry(300, 300, 350, 250) self.setWindowTitle('Signal and slot') self.show()
def __init__( self, onValueChanged: Callable[[int], None], parent: Optional[QWidget] = None, *args: Tuple[Any, Any], **kwargs: Tuple[Any, Any], ) -> None: """ Slow/fast slider for maze solver agents speed """ super(MazeSolverSpeedControlView, self).__init__(parent=parent, *args, **kwargs) self.setContentsMargins(0, 0, 0, 0) layout = QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) slider = QSlider(Qt.Orientations.Horizontal) # minimum of 1 op/s (0 would result in a divide by zero op and thus crash) slider.setMinimum(1) # maximum of 50 op/s slider.setMaximum(70) # initial value in the middle slider.setValue(35) # connect the onValueChange event to the method passed to this widget slider.valueChanged.connect(onValueChanged) # type: ignore # slow/fast horizontal labels view slowFastLabelsLayout = QHBoxLayout() slowFastLabelsLayout.setContentsMargins(0, 0, 0, 0) slowLabel = QLabel("Slow") fastLabel = QLabel("Fast") slowFastLabelsLayout.addWidget(slowLabel) slowFastLabelsLayout.addStretch() slowFastLabelsLayout.addWidget(fastLabel) layout.addWidget(slider) layout.addLayout(slowFastLabelsLayout) self.setLayout(layout)
def init_ui(self): pg.setConfigOption('background', 'w') pg.setConfigOption('imageAxisOrder', 'row-major') self.zname = 'Head', 'Feet' self.yname = 'Face', 'Back' self.xname = 'Left Hand', 'Right Hand' self.layout = QVBoxLayout() self.setGeometry(0, 0, 1440, 900) self.setWindowTitle('DICOM Viewer') self.z_slice_label = QLabel(f'Z axis [{self.zname[0]} - {self.zname[1]}] Slice: {self.z + 1}/{self.X.shape[0]}') self.y_slice_label = QLabel(f'Y axis [{self.yname[0]} - {self.yname[1]}] Slice: {self.y + 1}/{self.X.shape[1]}') self.x_slice_label = QLabel(f'X axis [{self.xname[0]} - {self.xname[1]}] Slice: {self.x + 1}/{self.X.shape[2]}') # slices plots ---------------------------------------------------------------- self.autolevels = True self.levels = (0, 100) self.glayout = pg.GraphicsLayoutWidget() self.glayout.ci.layout.setContentsMargins(0, 0, 0, 0) self.glayout.ci.layout.setSpacing(0) self.zi = pg.ImageItem(self.X[self.z, : , : ], autoLevels=self.autolevels, levels=self.levels, border=pg.mkPen(color='r', width=3)) self.yi = pg.ImageItem(self.X[: , self.y, : ], autoLevels=self.autolevels, levels=self.levels, border=pg.mkPen(color='g', width=3)) self.xi = pg.ImageItem(self.X[: , : , self.x], autoLevels=self.autolevels, levels=self.levels, border=pg.mkPen(color='b', width=3)) self.zp = self.glayout.addPlot() self.yp = self.glayout.addPlot() self.xp = self.glayout.addPlot() # self.z_slice_plot.setTitle(f'Z axis [{self.z_axis_name[0]} - {self.z_axis_name[1]}]') # self.y_slice_plot.setTitle(f'Y axis [{self.y_axis_name[0]} - {self.y_axis_name[1]}]') # self.x_slice_plot.setTitle(f'X axis [{self.x_axis_name[0]} - {self.x_axis_name[1]}]') self.zp.setAspectLocked() self.yp.setAspectLocked() self.xp.setAspectLocked() self.zp.setMouseEnabled(x=False, y=False) self.yp.setMouseEnabled(x=False, y=False) self.xp.setMouseEnabled(x=False, y=False) self.z_slice_plot_y_helper1 = self.zp.plot([0 , self.X.shape[2]], [self.y , self.y ], pen='g') self.z_slice_plot_y_helper2 = self.zp.plot([0 , self.X.shape[2]], [self.y + 1, self.y + 1 ], pen='g') self.z_slice_plot_x_helper1 = self.zp.plot([self.x , self.x ], [0 , self.X.shape[1]], pen='b') self.z_slice_plot_x_helper2 = self.zp.plot([self.x + 1, self.x + 1 ], [0 , self.X.shape[1]], pen='b') self.y_slice_plot_z_helper1 = self.yp.plot([0 , self.X.shape[2]], [self.z , self.z ], pen='r') self.y_slice_plot_z_helper2 = self.yp.plot([0 , self.X.shape[2]], [self.z + 1, self.z + 1 ], pen='r') self.y_slice_plot_x_helper1 = self.yp.plot([self.x , self.x ], [0 , self.X.shape[0]], pen='b') self.y_slice_plot_x_helper2 = self.yp.plot([self.x + 1, self.x + 1 ], [0 , self.X.shape[0]], pen='b') self.x_slice_plot_z_helper1 = self.xp.plot([0 , self.X.shape[1]], [self.z , self.z ], pen='r') self.x_slice_plot_z_helper2 = self.xp.plot([0 , self.X.shape[1]], [self.z + 1, self.z + 1 ], pen='r') self.x_slice_plot_y_helper1 = self.xp.plot([self.y , self.y ], [0 , self.X.shape[0]], pen='g') self.x_slice_plot_y_helper2 = self.xp.plot([self.y + 1, self.y + 1 ], [0 , self.X.shape[0]], pen='g') self.zp.invertY(True) self.yp.invertY(True) self.xp.invertY(True) self.zp.setLabel('bottom', f'X axis [{self.xname[0]} - {self.xname[1]}]') self.yp.setLabel('bottom', f'X axis [{self.xname[0]} - {self.xname[1]}]') self.zp.setLabel('left' , f'Y axis [{self.yname[1]} - {self.yname[0]}]') self.xp.setLabel('bottom', f'Y axis [{self.yname[0]} - {self.yname[1]}]') self.yp.setLabel('left' , f'Z axis [{self.zname[1]} - {self.zname[0]}]') self.xp.setLabel('left' , f'Z axis [{self.zname[1]} - {self.zname[0]}]') self.zp.addItem(self.zi) self.yp.addItem(self.yi) self.xp.addItem(self.xi) self.zi.setRect(pg.QtCore.QRectF(0, 0, self.X.shape[2], self.X.shape[1])) self.yi.setRect(pg.QtCore.QRectF(0, 0, self.X.shape[2], self.X.shape[0])) self.xi.setRect(pg.QtCore.QRectF(0, 0, self.X.shape[1], self.X.shape[0])) self.zi.setZValue(-1) self.yi.setZValue(-1) self.xi.setZValue(-1) self.zs = QSlider() self.ys = QSlider() self.xs = QSlider() self.zs.setStyleSheet('background-color: rgba(255, 0, 0, 0.2)') self.ys.setStyleSheet('background-color: rgba(0, 255, 0, 0.2)') self.xs.setStyleSheet('background-color: rgba(0, 0, 255, 0.2)') self.zs.setOrientation(Qt.Orientation.Horizontal) self.ys.setOrientation(Qt.Orientation.Horizontal) self.xs.setOrientation(Qt.Orientation.Horizontal) self.zs.setRange(0, self.X.shape[0] - 1) self.ys.setRange(0, self.X.shape[1] - 1) self.xs.setRange(0, self.X.shape[2] - 1) self.zs.setValue(self.z) self.ys.setValue(self.y) self.xs.setValue(self.x) self.zs.setTickPosition(QSlider.TickPosition.TicksBelow) self.ys.setTickPosition(QSlider.TickPosition.TicksBelow) self.xs.setTickPosition(QSlider.TickPosition.TicksBelow) self.zs.setTickInterval(1) self.ys.setTickInterval(1) self.xs.setTickInterval(1) self.layout.addWidget(self.zs) self.layout.addWidget(self.ys) self.layout.addWidget(self.xs) self.layout.addWidget(self.z_slice_label) self.layout.addWidget(self.y_slice_label) self.layout.addWidget(self.x_slice_label) self.layout.addWidget(self.glayout) self.setLayout(self.layout) self.show()
def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) # region Create CartPole instance and load initial settings # Create CartPole instance self.initial_state = create_cartpole_state() self.CartPoleInstance = CartPole(initial_state=self.initial_state) # Set timescales self.CartPoleInstance.dt_simulation = dt_simulation self.CartPoleInstance.dt_controller = controller_update_interval self.CartPoleInstance.dt_save = save_interval # set other settings self.CartPoleInstance.set_controller(controller_init) self.CartPoleInstance.stop_at_90 = stop_at_90_init self.set_random_experiment_generator_init_params() # endregion # region Decide whether to save the data in "CartPole memory" or not self.save_history = save_history_init self.show_experiment_summary = show_experiment_summary_init if self.save_history or self.show_experiment_summary: self.CartPoleInstance.save_data_in_cart = True else: self.CartPoleInstance.save_data_in_cart = False # endregion # region Other variables initial values as provided in gui_default_parameters.py # Start user controlled experiment/ start random experiment/ load and replay - on start button self.simulator_mode = simulator_mode_init self.slider_on_click = slider_on_click_init # Update slider on click/update slider while hoovering over it self.speedup = speedup_init # Default simulation speed-up # endregion # region Initialize loop-timer # This timer allows to relate the simulation time to user time # And (if your computer is fast enough) run simulation # slower or faster than real-time by predefined factor (speedup) self.looper = loop_timer( dt_target=(self.CartPoleInstance.dt_simulation / self.speedup)) # endregion # region Variables controlling the state of various processes (DO NOT MODIFY) self.terminate_experiment_or_replay_thread = False # True: gives signal causing thread to terminate self.pause_experiment_or_replay_thread = False # True: gives signal causing the thread to pause self.run_set_labels_thread = True # True if gauges (labels) keep being repeatedly updated # Stop threads by setting False # Flag indicating if the "START! / STOP!" button should act as start or as stop when pressed. # Can take values "START!" or "STOP!" self.start_or_stop_action = "START!" # Flag indicating whether the pause button should pause or unpause. self.pause_or_unpause_action = "PAUSE" # Flag indicating that saving of experiment recording to csv file has finished self.experiment_or_replay_thread_terminated = False self.user_time_counter = 0 # Measures the user time # Slider instant value (which is draw in GUI) differs from value saved in CartPole instance # if the option updating slider "on-click" is enabled. self.slider_instant_value = self.CartPoleInstance.slider_value self.noise = 'OFF' self.CartPoleInstance.NoiseAdderInstance.noise_mode = self.noise # endregion # region Create GUI Layout # region - Create container for top level layout layout = QVBoxLayout() # endregion # region - Change geometry of the main window self.setGeometry(300, 300, 2500, 1000) # endregion # region - Matplotlib figures (CartPole drawing and Slider) # Draw Figure self.fig = Figure( figsize=(25, 10) ) # Regulates the size of Figure in inches, before scaling to window size. self.canvas = FigureCanvas(self.fig) self.fig.AxCart = self.canvas.figure.add_subplot(211) self.fig.AxSlider = self.canvas.figure.add_subplot(212) self.fig.AxSlider.set_ylim(0, 1) self.CartPoleInstance.draw_constant_elements(self.fig, self.fig.AxCart, self.fig.AxSlider) # Attach figure to the layout lf = QVBoxLayout() lf.addWidget(self.canvas) # endregion # region - Radio buttons selecting current controller self.rbs_controllers = [] for controller_name in self.CartPoleInstance.controller_names: self.rbs_controllers.append(QRadioButton(controller_name)) # Ensures that radio buttons are exclusive self.controllers_buttons_group = QButtonGroup() for button in self.rbs_controllers: self.controllers_buttons_group.addButton(button) lr_c = QVBoxLayout() lr_c.addStretch(1) for rb in self.rbs_controllers: rb.clicked.connect(self.RadioButtons_controller_selection) lr_c.addWidget(rb) lr_c.addStretch(1) self.rbs_controllers[self.CartPoleInstance.controller_idx].setChecked( True) # endregion # region - Create central part of the layout for figures and radio buttons and add it to the whole layout lc = QHBoxLayout() lc.addLayout(lf) lc.addLayout(lr_c) layout.addLayout(lc) # endregion # region - Gauges displaying current values of various states and parameters (time, velocity, angle,...) # First row ld = QHBoxLayout() # User time self.labTime = QLabel("User's time (s): ") self.timer = QTimer() self.timer.setInterval(100) # Tick every 1/10 of the second self.timer.timeout.connect(self.set_user_time_label) self.timer.start() ld.addWidget(self.labTime) # Speed, angle, motor power (Q) self.labSpeed = QLabel('Speed (m/s):') self.labAngle = QLabel('Angle (deg):') self.labMotor = QLabel('') self.labTargetPosition = QLabel('') ld.addWidget(self.labSpeed) ld.addWidget(self.labAngle) ld.addWidget(self.labMotor) ld.addWidget(self.labTargetPosition) layout.addLayout(ld) # Second row of labels # Simulation time, Measured (real) speed-up, slider-value ld2 = QHBoxLayout() self.labTimeSim = QLabel('Simulation Time (s):') ld2.addWidget(self.labTimeSim) self.labSpeedUp = QLabel('Speed-up (measured):') ld2.addWidget(self.labSpeedUp) self.labSliderInstant = QLabel('') ld2.addWidget(self.labSliderInstant) layout.addLayout(ld2) # endregion # region - Buttons "START!" / "STOP!", "PAUSE", "QUIT" self.bss = QPushButton("START!") self.bss.pressed.connect(self.start_stop_button) self.bp = QPushButton("PAUSE") self.bp.pressed.connect(self.pause_unpause_button) bq = QPushButton("QUIT") bq.pressed.connect(self.quit_application) lspb = QHBoxLayout() # Sub-Layout for Start/Stop and Pause Buttons lspb.addWidget(self.bss) lspb.addWidget(self.bp) # endregion # region - Sliders setting initial state and buttons for kicking the pole # Sliders setting initial position and angle lb = QVBoxLayout() # Layout for buttons lb.addLayout(lspb) lb.addWidget(bq) ip = QHBoxLayout() # Layout for initial position sliders self.initial_position_slider = QSlider( orientation=Qt.Orientation.Horizontal) self.initial_position_slider.setRange( -int(float(1000 * TrackHalfLength)), int(float(1000 * TrackHalfLength))) self.initial_position_slider.setValue(0) self.initial_position_slider.setSingleStep(1) self.initial_position_slider.valueChanged.connect( self.update_initial_position) self.initial_angle_slider = QSlider( orientation=Qt.Orientation.Horizontal) self.initial_angle_slider.setRange(-int(float(100 * np.pi)), int(float(100 * np.pi))) self.initial_angle_slider.setValue(0) self.initial_angle_slider.setSingleStep(1) self.initial_angle_slider.valueChanged.connect( self.update_initial_angle) ip.addWidget(QLabel("Initial position:")) ip.addWidget(self.initial_position_slider) ip.addWidget(QLabel("Initial angle:")) ip.addWidget(self.initial_angle_slider) ip.addStretch(0.01) # Slider setting latency self.LATENCY_SLIDER_RANGE_INT = 1000 self.latency_slider = QSlider(orientation=Qt.Orientation.Horizontal) self.latency_slider.setRange(0, self.LATENCY_SLIDER_RANGE_INT) self.latency_slider.setValue( int(self.CartPoleInstance.LatencyAdderInstance.latency * self.LATENCY_SLIDER_RANGE_INT / self.CartPoleInstance.LatencyAdderInstance.max_latency)) self.latency_slider.setSingleStep(1) self.latency_slider.valueChanged.connect(self.update_latency) ip.addWidget(QLabel("Latency:")) ip.addWidget(self.latency_slider) self.labLatency = QLabel('Latency (ms): {:.1f}'.format( self.CartPoleInstance.LatencyAdderInstance.latency * 1000)) ip.addWidget(self.labLatency) # Buttons activating noise self.rbs_noise = [] for mode_name in ['ON', 'OFF']: self.rbs_noise.append(QRadioButton(mode_name)) # Ensures that radio buttons are exclusive self.noise_buttons_group = QButtonGroup() for button in self.rbs_noise: self.noise_buttons_group.addButton(button) lr_n = QHBoxLayout() lr_n.addWidget(QLabel('Noise:')) for rb in self.rbs_noise: rb.clicked.connect(self.RadioButtons_noise_on_off) lr_n.addWidget(rb) self.rbs_noise[1].setChecked(True) ip.addStretch(0.01) ip.addLayout(lr_n) ip.addStretch(0.01) # Buttons giving kick to the pole kick_label = QLabel("Kick pole:") kick_left_button = QPushButton() kick_left_button.setText("Left") kick_left_button.adjustSize() kick_left_button.clicked.connect(self.kick_pole) kick_right_button = QPushButton() kick_right_button.setText("Right") kick_right_button.adjustSize() kick_right_button.clicked.connect(self.kick_pole) ip.addWidget(kick_label) ip.addWidget(kick_left_button) ip.addWidget(kick_right_button) lb.addLayout(ip) layout.addLayout(lb) # endregion # region - Text boxes and Combobox to provide settings concerning generation of random experiment l_generate_trace = QHBoxLayout() l_generate_trace.addWidget(QLabel('Random experiment settings:')) l_generate_trace.addWidget(QLabel('Length (s):')) self.textbox_length = QLineEdit() l_generate_trace.addWidget(self.textbox_length) l_generate_trace.addWidget(QLabel('Turning Points (m):')) self.textbox_turning_points = QLineEdit() l_generate_trace.addWidget(self.textbox_turning_points) l_generate_trace.addWidget(QLabel('Interpolation:')) self.cb_interpolation = QComboBox() self.cb_interpolation.addItems( ['0-derivative-smooth', 'linear', 'previous']) self.cb_interpolation.currentIndexChanged.connect( self.cb_interpolation_selectionchange) self.cb_interpolation.setCurrentText( self.CartPoleInstance.interpolation_type) l_generate_trace.addWidget(self.cb_interpolation) layout.addLayout(l_generate_trace) # endregion # region - Textbox to provide csv file name for saving or loading data l_text = QHBoxLayout() textbox_title = QLabel('CSV file name:') self.textbox = QLineEdit() l_text.addWidget(textbox_title) l_text.addWidget(self.textbox) layout.addLayout(l_text) # endregion # region - Make strip of layout for checkboxes l_cb = QHBoxLayout() # endregion # region - Textbox to provide the target speed-up value l_text_speedup = QHBoxLayout() tx_speedup_title = QLabel('Speed-up (target):') self.tx_speedup = QLineEdit() l_text_speedup.addWidget(tx_speedup_title) l_text_speedup.addWidget(self.tx_speedup) self.tx_speedup.setText(str(self.speedup)) l_cb.addLayout(l_text_speedup) self.wrong_speedup_msg = QMessageBox() self.wrong_speedup_msg.setWindowTitle("Speed-up value problem") self.wrong_speedup_msg.setIcon(QMessageBox.Icon.Critical) # endregion # region - Checkboxes # region -- Checkbox: Save/don't save experiment recording self.cb_save_history = QCheckBox('Save results', self) if self.save_history: self.cb_save_history.toggle() self.cb_save_history.toggled.connect(self.cb_save_history_f) l_cb.addWidget(self.cb_save_history) # endregion # region -- Checkbox: Display plots showing dynamic evolution of the system as soon as experiment terminates self.cb_show_experiment_summary = QCheckBox('Show experiment summary', self) if self.show_experiment_summary: self.cb_show_experiment_summary.toggle() self.cb_show_experiment_summary.toggled.connect( self.cb_show_experiment_summary_f) l_cb.addWidget(self.cb_show_experiment_summary) # endregion # region -- Checkbox: Block pole if it reaches +/-90 deg self.cb_stop_at_90_deg = QCheckBox('Stop-at-90-deg', self) if self.CartPoleInstance.stop_at_90: self.cb_stop_at_90_deg.toggle() self.cb_stop_at_90_deg.toggled.connect(self.cb_stop_at_90_deg_f) l_cb.addWidget(self.cb_stop_at_90_deg) # endregion # region -- Checkbox: Update slider on click/update slider while hoovering over it self.cb_slider_on_click = QCheckBox('Update slider on click', self) if self.slider_on_click: self.cb_slider_on_click.toggle() self.cb_slider_on_click.toggled.connect(self.cb_slider_on_click_f) l_cb.addWidget(self.cb_slider_on_click) # endregion # endregion # region - Radio buttons selecting simulator mode: user defined experiment, random experiment, replay # List available simulator modes - constant self.available_simulator_modes = [ 'Slider-Controlled Experiment', 'Random Experiment', 'Replay' ] self.rbs_simulator_mode = [] for mode_name in self.available_simulator_modes: self.rbs_simulator_mode.append(QRadioButton(mode_name)) # Ensures that radio buttons are exclusive self.simulator_mode_buttons_group = QButtonGroup() for button in self.rbs_simulator_mode: self.simulator_mode_buttons_group.addButton(button) lr_sm = QHBoxLayout() lr_sm.addStretch(1) lr_sm.addWidget(QLabel('Simulator mode:')) for rb in self.rbs_simulator_mode: rb.clicked.connect(self.RadioButtons_simulator_mode) lr_sm.addWidget(rb) lr_sm.addStretch(1) self.rbs_simulator_mode[self.available_simulator_modes.index( self.simulator_mode)].setChecked(True) l_cb.addStretch(1) l_cb.addLayout(lr_sm) l_cb.addStretch(1) # endregion # region - Add checkboxes to layout layout.addLayout(l_cb) # endregion # region - Create an instance of a GUI window w = QWidget() w.setLayout(layout) self.setCentralWidget(w) self.show() self.setWindowTitle('CartPole Simulator') # endregion # endregion # region Open controller-specific popup windows self.open_additional_controller_widget() # endregion # region Activate functions capturing mouse movements and clicks over the slider # This line links function capturing the mouse position on the canvas of the Figure self.canvas.mpl_connect("motion_notify_event", self.on_mouse_movement) # This line links function capturing the mouse position on the canvas of the Figure click self.canvas.mpl_connect("button_press_event", self.on_mouse_click) # endregion # region Introducing multithreading # To ensure smooth functioning of the app, # the calculations and redrawing of the figures have to be done in a different thread # than the one capturing the mouse position and running the animation self.threadpool = QThreadPool() # endregion # region Starts a thread repeatedly redrawing gauges (labels) of the GUI # It runs till the QUIT button is pressed worker_labels = Worker(self.set_labels_thread) self.threadpool.start(worker_labels) # endregion # region Start animation repeatedly redrawing changing elements of matplotlib figures (CartPole drawing and slider) # This animation runs ALWAYS when the GUI is open # The buttons of GUI only decide if new parameters are calculated or not self.anim = self.CartPoleInstance.run_animation(self.fig)
def initUI(self): self.grid = QGridLayout(self) self.file_control_grid = QGridLayout() self.file_control_grid.setSpacing(3) self.grid.addLayout(self.file_control_grid, 0, 0) self.file_tree_grid = QGridLayout() self.file_tree_grid.setSpacing(3) self.grid.addLayout(self.file_tree_grid, 1, 0) self.group_control_grid = QGridLayout() self.group_control_grid.setSpacing(3) self.grid.addLayout(self.group_control_grid, 0, 1) self.attribute_grid = QGridLayout() self.attribute_grid.setSpacing(3) self.grid.addLayout(self.attribute_grid, 1, 1) self.roi_control_grid = QGridLayout() self.roi_control_grid.setSpacing(3) self.grid.addLayout(self.roi_control_grid, 0, 2) self.plot_grid = QGridLayout() self.plot_grid.setSpacing(3) self.grid.addLayout(self.plot_grid, 1, 2) # # # # File control browser: # # # # # # # # (0,0) loadButton = QPushButton("Load expt. file", self) loadButton.clicked.connect(self.selectDataFile) # Label with current expt file self.currentExperimentLabel = QLabel('') self.file_control_grid.addWidget(loadButton, 0, 0) self.file_control_grid.addWidget(self.currentExperimentLabel, 1, 0) directoryButton = QPushButton("Select data directory", self) directoryButton.clicked.connect(self.selectDataDirectory) self.file_control_grid.addWidget(directoryButton, 0, 1) self.data_directory_display = QLabel('') self.data_directory_display.setFont(QtGui.QFont('SansSerif', 8)) self.file_control_grid.addWidget(self.data_directory_display, 1, 1) # Attach metadata to file attachDatabutton = QPushButton("Attach metadata to file", self) attachDatabutton.clicked.connect(self.attachData) self.file_control_grid.addWidget(attachDatabutton, 2, 0, 1, 2) # Select image data file selectImageDataFileButton = QPushButton("Select image data file", self) selectImageDataFileButton.clicked.connect(self.selectImageDataFile) self.file_control_grid.addWidget(selectImageDataFileButton, 3, 0, 1, 2) # # # # File tree: # # # # # # # # (1,0) self.groupTree = QTreeWidget(self) self.groupTree.setHeaderHidden(True) self.groupTree.itemClicked.connect(self.onTreeItemClicked) self.file_tree_grid.addWidget(self.groupTree, 3, 0, 2, 7) # # # # Group control: # # # # # # # # (0, 1) deleteGroupButton = QPushButton("Delete selected group", self) deleteGroupButton.clicked.connect(self.deleteSelectedGroup) self.group_control_grid.addWidget(deleteGroupButton, 0, 0, 1, 2) # File name display self.currentImageFileNameLabel = QLabel('') self.group_control_grid.addWidget(self.currentImageFileNameLabel, 1, 0) # Channel drop down ch_label = QLabel('Channel:') self.ChannelComboBox = QComboBox(self) self.ChannelComboBox.addItem("1") self.ChannelComboBox.addItem("0") self.ChannelComboBox.activated.connect(self.selectChannel) self.group_control_grid.addWidget(ch_label, 2, 0) self.group_control_grid.addWidget(self.ChannelComboBox, 2, 1) # # # # Attribute table: # # # # # # # # (1, 1) self.tableAttributes = QTableWidget() self.tableAttributes.setStyleSheet("") self.tableAttributes.setColumnCount(2) self.tableAttributes.setObjectName("tableAttributes") self.tableAttributes.setRowCount(0) item = QTableWidgetItem() font = QtGui.QFont() font.setPointSize(10) item.setFont(font) item.setBackground(QtGui.QColor(121, 121, 121)) brush = QtGui.QBrush(QtGui.QColor(91, 91, 91)) brush.setStyle(QtCore.Qt.BrushStyle.SolidPattern) item.setForeground(brush) self.tableAttributes.setHorizontalHeaderItem(0, item) item = QTableWidgetItem() item.setBackground(QtGui.QColor(123, 123, 123)) brush = QtGui.QBrush(QtGui.QColor(91, 91, 91)) brush.setStyle(QtCore.Qt.BrushStyle.SolidPattern) item.setForeground(brush) self.tableAttributes.setHorizontalHeaderItem(1, item) self.tableAttributes.horizontalHeader().setCascadingSectionResizes( True) self.tableAttributes.horizontalHeader().setHighlightSections(False) self.tableAttributes.horizontalHeader().setSortIndicatorShown(True) self.tableAttributes.horizontalHeader().setStretchLastSection(True) self.tableAttributes.verticalHeader().setVisible(False) self.tableAttributes.verticalHeader().setHighlightSections(False) item = self.tableAttributes.horizontalHeaderItem(0) item.setText("Attribute") item = self.tableAttributes.horizontalHeaderItem(1) item.setText("Value") self.tableAttributes.itemChanged.connect(self.update_attrs_to_file) self.attribute_grid.addWidget(self.tableAttributes, 3, 0, 1, 8) # # # # Roi control # # # # # # # # (0, 2) # ROI type drop-down self.RoiTypeComboBox = QComboBox(self) self.RoiTypeComboBox.addItem("freehand") radii = [1, 2, 3, 4, 6, 8] for radius in radii: self.RoiTypeComboBox.addItem("circle:" + str(radius)) self.RoiTypeComboBox.activated.connect(self.selectRoiType) self.roi_control_grid.addWidget(self.RoiTypeComboBox, 0, 0) # Clear all ROIs button self.clearROIsButton = QPushButton("Clear ROIs", self) self.clearROIsButton.clicked.connect(self.clearRois) self.roi_control_grid.addWidget(self.clearROIsButton, 0, 2) # Response display type dropdown self.RoiResponseTypeComboBox = QComboBox(self) self.RoiResponseTypeComboBox.addItem("RawTrace") self.RoiResponseTypeComboBox.addItem("TrialAverage") self.RoiResponseTypeComboBox.addItem("TrialResponses") self.RoiResponseTypeComboBox.addItem("TrialAverageDFF") self.roi_control_grid.addWidget(self.RoiResponseTypeComboBox, 2, 2) # ROIset file name line edit box self.defaultRoiSetName = "roi_set_name" self.le_roiSetName = QLineEdit(self.defaultRoiSetName) self.roi_control_grid.addWidget(self.le_roiSetName, 1, 1) # Save ROIs button self.saveROIsButton = QPushButton("Save ROIs", self) self.saveROIsButton.clicked.connect(self.saveRois) self.roi_control_grid.addWidget(self.saveROIsButton, 1, 0) # Load ROI set combobox self.loadROIsComboBox = QComboBox(self) self.loadROIsComboBox.addItem("(load existing ROI set)") self.loadROIsComboBox.activated.connect(self.selectedExistingRoiSet) self.roi_control_grid.addWidget(self.loadROIsComboBox, 1, 2) self.updateExistingRoiSetList() # Delete current roi button self.deleteROIButton = QPushButton("Delete ROI", self) self.deleteROIButton.clicked.connect(self.deleteRoi) self.roi_control_grid.addWidget(self.deleteROIButton, 2, 0) # Current roi slider self.roiSlider = QSlider(QtCore.Qt.Orientation.Horizontal, self) self.roiSlider.setMinimum(0) self.roiSlider.setMaximum(self.max_rois) self.roiSlider.valueChanged.connect(self.sliderUpdated) self.roi_control_grid.addWidget(self.roiSlider, 2, 1, 1, 1) ctx = plt.rc_context({ 'xtick.major.size': 1, 'axes.spines.top': False, 'axes.spines.right': False, 'xtick.labelsize': 'xx-small', 'ytick.labelsize': 'xx-small', 'xtick.major.size': 1.0, 'ytick.major.size': 1.0, 'xtick.major.pad': 1.0, 'ytick.major.pad': 1.0 }) with ctx: self.responseFig = plt.figure(frameon=False, layout='constrained') self.responsePlot = self.responseFig.add_subplot(111) self.responseCanvas = FigureCanvas(self.responseFig) self.responseCanvas.draw_idle() self.plot_grid.addWidget(self.responseCanvas, 0, 0) # # # # Image canvas # # # # # # # # (1, 2) self.roi_fig = plt.figure() self.roi_ax = self.roi_fig.add_subplot(111) self.roi_canvas = FigureCanvas(self.roi_fig) self.toolbar = NavigationToolbar(self.roi_canvas, self) self.roi_ax.set_aspect('equal') self.roi_ax.set_axis_off() self.plot_grid.addWidget(self.toolbar, 1, 0) self.plot_grid.addWidget(self.roi_canvas, 2, 0) self.plot_grid.setRowStretch(0, 1) self.plot_grid.setRowStretch(1, 3) self.plot_grid.setRowStretch(2, 3) # Current z slice slider self.zSlider = QSlider(QtCore.Qt.Orientation.Horizontal, self) self.zSlider.setMinimum(0) self.zSlider.setMaximum(50) self.zSlider.setValue(0) self.zSlider.valueChanged.connect(self.zSliderUpdated) self.plot_grid.addWidget(self.zSlider, 3, 0) self.roi_fig.tight_layout() self.setWindowTitle('Visanalysis') self.setGeometry(200, 200, 1200, 600) self.show()
def __init__(self): super(MPPIOptionsWindow, self).__init__() self.horizon_steps = controller_mppi.mpc_samples self.num_rollouts = controller_mppi.num_rollouts self.dd_weight = controller_mppi.dd_weight self.ep_weight = controller_mppi.ep_weight self.ekp_weight = controller_mppi.ekp_weight * 1.0e1 self.ekc_weight = controller_mppi.ekc_weight * 1.0e-1 self.cc_weight = controller_mppi.cc_weight * 1.0e-2 self.ccrc_weight = controller_mppi.ccrc_weight * 1.0e-2 self.R = controller_mppi.R # How much to punish Q self.LBD = controller_mppi.LBD # Cost parameter lambda self.NU = controller_mppi.NU # Exploration variance layout = QVBoxLayout() ### Set Horizon Length horizon_options_layout = QVBoxLayout() self.horizon_label = QLabel("") self.horizon_label.setAlignment(Qt.AlignmentFlag.AlignCenter) horizon_options_layout.addWidget(self.horizon_label) slider = QSlider(orientation=Qt.Orientation.Horizontal) slider.setRange(10, 300) slider.setValue(self.horizon_steps) slider.setTickPosition(QSlider.TickPosition.TicksBelow) slider.setTickInterval(10) slider.setSingleStep(10) horizon_options_layout.addWidget(slider) slider.valueChanged.connect(self.horizon_length_changed) ### Set Number of Rollouts rollouts_options_layout = QVBoxLayout() self.rollouts_label = QLabel("") self.rollouts_label.setAlignment(Qt.AlignmentFlag.AlignCenter) rollouts_options_layout.addWidget(self.rollouts_label) slider = QSlider(orientation=Qt.Orientation.Horizontal) slider.setRange(10, 3000) slider.setValue(self.num_rollouts) slider.setTickPosition(QSlider.TickPosition.TicksBelow) slider.setTickInterval(10) slider.setSingleStep(10) rollouts_options_layout.addWidget(slider) slider.valueChanged.connect(self.num_rollouts_changed) ### Set Cost Weights cost_weight_layout = QVBoxLayout() # Distance difference cost self.dd_weight_label = QLabel("") self.dd_weight_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.dd_weight_label) self.dd_label = QLabel("") self.dd_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.dd_label) slider = QSlider(orientation=Qt.Orientation.Horizontal) slider.setRange(0, 990) slider.setValue(self.dd_weight) slider.setTickPosition(QSlider.TickPosition.TicksBelow) slider.setTickInterval(10) slider.setSingleStep(10) cost_weight_layout.addWidget(slider) slider.valueChanged.connect(self.dd_weight_changed) # Potential energy cost self.ep_weight_label = QLabel("") self.ep_weight_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.ep_weight_label) self.ep_label = QLabel("") self.ep_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.ep_label) slider = QSlider(orientation=Qt.Orientation.Horizontal) slider.setRange(0, 1e5 - 1e3) slider.setValue(self.ep_weight) slider.setTickPosition(QSlider.TickPosition.TicksBelow) slider.setTickInterval(1e3) slider.setSingleStep(1e3) cost_weight_layout.addWidget(slider) slider.valueChanged.connect(self.ep_weight_changed) # Pole kinetic energy cost self.ekp_weight_label = QLabel("") self.ekp_weight_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.ekp_weight_label) self.ekp_label = QLabel("") self.ekp_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.ekp_label) slider = QSlider(orientation=Qt.Orientation.Horizontal) slider.setRange(0, 99) slider.setValue(self.ekp_weight) slider.setTickPosition(QSlider.TickPosition.TicksBelow) slider.setTickInterval(1) slider.setSingleStep(1) cost_weight_layout.addWidget(slider) slider.valueChanged.connect(self.ekp_weight_changed) # Cart kinetic energy cost self.ekc_weight_label = QLabel("") self.ekc_weight_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.ekc_weight_label) self.ekc_label = QLabel("") self.ekc_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.ekc_label) slider = QSlider(orientation=Qt.Orientation.Horizontal) slider.setRange(0, 99) slider.setValue(self.ekc_weight) slider.setTickPosition(QSlider.TickPosition.TicksBelow) slider.setTickInterval(1) slider.setSingleStep(1) cost_weight_layout.addWidget(slider) slider.valueChanged.connect(self.ekc_weight_changed) # Control cost self.cc_weight_label = QLabel("") self.cc_weight_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.cc_weight_label) self.cc_label = QLabel("") self.cc_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.cc_label) slider = QSlider(orientation=Qt.Orientation.Horizontal) slider.setRange(0, 99) slider.setValue(self.cc_weight) slider.setTickPosition(QSlider.TickPosition.TicksBelow) slider.setTickInterval(1) slider.setSingleStep(1) cost_weight_layout.addWidget(slider) slider.valueChanged.connect(self.cc_weight_changed) # Control change rate cost self.ccrc_weight_label = QLabel("") self.ccrc_weight_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.ccrc_weight_label) self.ccrc_label = QLabel("") self.ccrc_label.setAlignment(Qt.AlignmentFlag.AlignCenter) cost_weight_layout.addWidget(self.ccrc_label) slider = QSlider(orientation=Qt.Orientation.Horizontal) slider.setRange(0, 99) slider.setValue(self.ccrc_weight) slider.setTickPosition(QSlider.TickPosition.TicksBelow) slider.setTickInterval(1) slider.setSingleStep(1) cost_weight_layout.addWidget(slider) slider.valueChanged.connect(self.ccrc_weight_changed) ### Set some more MPPI constants mppi_constants_layout = QVBoxLayout() # Quadratic cost penalty R textbox = QLineEdit() textbox.setText(str(self.R)) textbox.textChanged.connect(self.R_changed) h_layout = QHBoxLayout() h_layout.addWidget(QLabel("Quadratic input cost penalty R =")) h_layout.addWidget(textbox) mppi_constants_layout.addLayout(h_layout) # Quadratic cost penalty LBD textbox = QLineEdit() textbox.setText(str(self.LBD)) textbox.textChanged.connect(self.LBD_changed) h_layout = QHBoxLayout() h_layout.addWidget(QLabel("Importance of higher-cost rollouts LBD =")) h_layout.addWidget(textbox) mppi_constants_layout.addLayout(h_layout) # Quadratic cost penalty NU textbox = QLineEdit() textbox.setText(str(self.NU)) textbox.textChanged.connect(self.NU_changed) h_layout = QHBoxLayout() h_layout.addWidget(QLabel("Exploration variance NU =")) h_layout.addWidget(textbox) mppi_constants_layout.addLayout(h_layout) # Sampling type h_layout = QHBoxLayout() btn1 = QRadioButton("iid") if btn1.text() == controller_mppi.SAMPLING_TYPE: btn1.setChecked(True) btn1.toggled.connect(lambda: self.toggle_button(btn1)) h_layout.addWidget(btn1) btn2 = QRadioButton("random_walk") if btn2.text() == controller_mppi.SAMPLING_TYPE: btn2.setChecked(True) btn2.toggled.connect(lambda: self.toggle_button(btn2)) h_layout.addWidget(btn2) btn3 = QRadioButton("uniform") if btn3.text() == controller_mppi.SAMPLING_TYPE: btn3.setChecked(True) btn3.toggled.connect(lambda: self.toggle_button(btn3)) h_layout.addWidget(btn3) btn4 = QRadioButton("repeated") if btn4.text() == controller_mppi.SAMPLING_TYPE: btn4.setChecked(True) btn4.toggled.connect(lambda: self.toggle_button(btn4)) h_layout.addWidget(btn4) btn5 = QRadioButton("interpolated") if btn5.text() == controller_mppi.SAMPLING_TYPE: btn5.setChecked(True) btn5.toggled.connect(lambda: self.toggle_button(btn5)) h_layout.addWidget(btn5) mppi_constants_layout.addWidget(QLabel("Sampling type:")) mppi_constants_layout.addLayout(h_layout) ### Put together layout self.update_labels() self.update_slider_labels() layout.addLayout(horizon_options_layout) layout.addLayout(rollouts_options_layout) layout.addLayout(cost_weight_layout) layout.addLayout(mppi_constants_layout) self.setLayout(layout) self.setWindowFlags(self.windowFlags() | Qt.WindowType.WindowStaysOnTopHint) self.setGeometry(0, 0, 400, 50) self.show() self.setWindowTitle("MPPI Options") self.timer = QTimer() self.timer.timeout.connect(self.update_labels) self.timer.start(100)
def __init__(self): super().__init__() self.setFixedSize(800, 410) self.setWindowTitle("PyLX16A Servo Testing Software") self.port_selection_box = QComboBox(self) self.port_selection_box.setFixedSize(200, 27) self.port_selection_box.move(30, 65) port_selection_box_label = QLabel("Select Port:", self) port_selection_box_label.move(30, 35) self.port_selection_box_refresh_button = QPushButton("Refresh", self) self.port_selection_box_refresh_button.setFixedSize(60, 23) self.port_selection_box_refresh_button.move(170, 38) self.id_selection_box = QListWidget(self) self.id_selection_box.setFixedSize(200, 200) self.id_selection_box.move(30, 135) id_selection_box_label = QLabel("Connected Servos:", self) id_selection_box_label.setFixedWidth(200) id_selection_box_label.move(30, 105) self.id_selection_box_refresh_button = QPushButton("Refresh", self) self.id_selection_box_refresh_button.setFixedSize(60, 23) self.id_selection_box_refresh_button.move(170, 108) self.set_id_line_edit = QLineEdit(self) self.set_id_line_edit.setFixedSize(50, 27) self.set_id_line_edit.move(80, 355) set_id_line_edit_label = QLabel("Set ID:", self) set_id_line_edit_label.move(30, 355) set_id_line_edit_label.setFixedSize(50, 27) self.set_id_button = QPushButton("Change ID!", self) self.set_id_button.setFixedSize(85, 27) self.set_id_button.move(145, 355) self.position_slider = QSlider(Qt.Orientation.Horizontal, self) self.position_slider.setMinimum(0) self.position_slider.setMaximum(240) self.position_slider.setFixedWidth(200) self.position_slider.move(300, 55) self.position_slider_readout = QLabel("0.00°", self) self.position_slider_readout.setFixedWidth(50) self.position_slider_readout.move(450, 30) self.position_slider_readout.setAlignment( Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) position_slider_label = QLabel("Angle (degrees):", self) position_slider_label.move(300, 30) self.position_offset_slider = QSlider(Qt.Orientation.Horizontal, self) self.position_offset_slider.setMinimum(-30) self.position_offset_slider.setMaximum(30) self.position_offset_slider.setFixedWidth(200) self.position_offset_slider.move(300, 125) self.position_offset_slider_readout = QLabel("0.00°", self) self.position_offset_slider_readout.setFixedWidth(50) self.position_offset_slider_readout.move(450, 100) self.position_offset_slider_readout.setAlignment( Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) position_offset_slider_label = QLabel("Angle offset (degrees):", self) position_offset_slider_label.setFixedWidth(200) position_offset_slider_label.move(300, 100) self.angle_lower_limit_textentry = QLineEdit(self) self.angle_lower_limit_textentry.setFixedWidth(50) self.angle_lower_limit_textentry.move(450, 175) self.angle_lower_limit_textentry.setValidator( QIntValidator(0, 240, self)) self.angle_upper_limit_textentry = QLineEdit(self) self.angle_upper_limit_textentry.setFixedWidth(50) self.angle_upper_limit_textentry.move(450, 210) self.angle_upper_limit_textentry.setValidator( QIntValidator(0, 240, self)) self.angle_lower_limit_textentry_label = QLabel( "Lower Limit (degrees):", self) self.angle_lower_limit_textentry_label.move(300, 175) self.angle_lower_limit_textentry_label.setFixedWidth(150) self.angle_upper_limit_textentry_label = QLabel( "Upper Limit (degrees):", self) self.angle_upper_limit_textentry_label.move(300, 210) self.angle_upper_limit_textentry_label.setFixedWidth(150) self.vin_lower_limit_textentry = QLineEdit(self) self.vin_lower_limit_textentry.setFixedWidth(50) self.vin_lower_limit_textentry.move(450, 265) self.vin_lower_limit_textentry.setValidator( QIntValidator(4500, 12000, self)) self.vin_upper_limit_textentry = QLineEdit(self) self.vin_upper_limit_textentry.setFixedWidth(50) self.vin_upper_limit_textentry.move(450, 300) self.vin_upper_limit_textentry.setValidator( QIntValidator(4500, 12000, self)) self.vin_lower_limit_textentry_label = QLabel( "Voltage Lower Limit (mV):", self) self.vin_lower_limit_textentry_label.move(300, 265) self.vin_lower_limit_textentry_label.setFixedWidth(150) self.vin_upper_limit_textentry_label = QLabel( "Voltage Upper Limit (mV):", self) self.vin_upper_limit_textentry_label.move(300, 300) self.vin_upper_limit_textentry_label.setFixedWidth(150) self.temp_limit_textentry = QLineEdit(self) self.temp_limit_textentry.setFixedWidth(50) self.temp_limit_textentry.move(450, 355) self.temp_limit_textentry.setValidator(QIntValidator(50, 100, self)) self.temp_limit_textentry_label = QLabel("Temp Limit (°C):", self) self.temp_limit_textentry_label.move(300, 355) self.temp_limit_textentry_label.setFixedWidth(150) self.servo_mode_radio_button = QRadioButton("Servo Mode", self) self.servo_mode_radio_button.move(565, 50) self.motor_mode_radio_button = QRadioButton("Motor Mode", self) self.motor_mode_radio_button.move(565, 75) self.motor_speed_slider = QSlider(Qt.Orientation.Horizontal, self) self.motor_speed_slider.setMinimum(-1000) self.motor_speed_slider.setMaximum(1000) self.motor_speed_slider.setFixedWidth(200) self.motor_speed_slider.move(565, 125) motor_speed_slider_label = QLabel("Motor Speed:", self) motor_speed_slider_label.move(565, 100) self.torque_enabled_checkbox = QCheckBox("Torque Enabled", self) self.torque_enabled_checkbox.move(565, 175) self.torque_enabled_checkbox.setFixedWidth(200) self.led_enabled_checkbox = QCheckBox("LED Enabled", self) self.led_enabled_checkbox.move(565, 210) self.led_enabled_checkbox.setFixedWidth(200) self.led_over_temp_checkbox = QCheckBox("LED Over Temperature", self) self.led_over_temp_checkbox.move(565, 258) self.led_over_temp_checkbox.setFixedWidth(200) self.led_over_voltage_checkbox = QCheckBox("LED Over Voltage", self) self.led_over_voltage_checkbox.move(565, 283) self.led_over_voltage_checkbox.setFixedWidth(200) self.led_rotor_locked_checkbox = QCheckBox("LED Rotor Locked", self) self.led_rotor_locked_checkbox.move(565, 308) self.led_rotor_locked_checkbox.setFixedWidth(200) self.physical_position_readout = QLabel("--°", self) self.physical_position_readout.move(565, 367) self.physical_position_readout.setFixedWidth(200) self.physical_position_readout_label = QLabel("Position", self) self.physical_position_readout_label.move(565, 347) self.temperature_readout = QLabel("-- °C", self) self.temperature_readout.move(635, 367) self.temperature_readout.setFixedWidth(200) self.temperature_readout_label = QLabel("Temperature", self) self.temperature_readout_label.move(635, 347) self.voltage_readout = QLabel("-- V", self) self.voltage_readout.move(730, 367) self.voltage_readout.setFixedWidth(200) self.voltage_readout_label = QLabel("Voltage", self) self.voltage_readout_label.move(730, 347) self.readout_update_timer = QTimer(self) self.readout_update_timer.timeout.connect(self.update_readouts) self.readout_update_timer.start(250) self.active_servo: LX16A = None self.position_slider.setValue(0) self.position_offset_slider.setValue(0) self.motor_speed_slider.setValue(0) self.id_selection_box_refresh_button.setEnabled(False) self.disable_widgets() self.port_selection_box.currentTextChanged.connect( self.port_selection_box_changed) self.port_selection_box_refresh_button.clicked.connect( self.port_refresh_button_clicked) self.id_selection_box.currentTextChanged.connect( self.id_selection_box_changed) self.id_selection_box_refresh_button.clicked.connect( self.id_refresh_button_clicked) self.set_id_button.pressed.connect(self.id_updated) self.position_slider.sliderMoved.connect(self.position_slider_updated) self.position_offset_slider.sliderMoved.connect( self.position_offset_slider_updated) self.angle_lower_limit_textentry.textChanged.connect( self.angle_lower_limit_updated) self.angle_upper_limit_textentry.textChanged.connect( self.angle_upper_limit_updated) self.vin_lower_limit_textentry.textChanged.connect( self.vin_lower_limit_updated) self.vin_upper_limit_textentry.textChanged.connect( self.vin_upper_limit_updated) self.temp_limit_textentry.textChanged.connect(self.temp_limit_updated) self.servo_mode_radio_button.toggled.connect( self.servo_mode_radio_button_toggled) self.motor_mode_radio_button.toggled.connect( self.motor_mode_radio_button_toggled) self.motor_speed_slider.valueChanged.connect( self.motor_speed_slider_updated) self.torque_enabled_checkbox.stateChanged.connect( self.torque_enabled_checkbox_toggled) self.led_enabled_checkbox.stateChanged.connect( self.led_enabled_checkbox_toggled) self.led_over_temp_checkbox.stateChanged.connect( self.led_error_triggers_checkbox_toggled) self.led_over_voltage_checkbox.stateChanged.connect( self.led_error_triggers_checkbox_toggled) self.led_rotor_locked_checkbox.stateChanged.connect( self.led_error_triggers_checkbox_toggled) self.scan_for_ports()
def createEditingBar(self): """Create dock widget for editing tools.""" #TODO: Add a tab widget for the different editing tools self.editing_bar = QDockWidget("Tools") self.editing_bar.setAllowedAreas( Qt.DockWidgetAreas.LeftDockWidgetArea | Qt.DockWidgetAreas.RightDockWidgetArea) self.editing_bar.setMinimumWidth(90) # Create editing tool buttons filters_label = QLabel("Filters") convert_to_grayscale = QToolButton() convert_to_grayscale.setIcon( QIcon(os.path.join(icon_path, "grayscale.png"))) convert_to_grayscale.clicked.connect(self.image_label.convertToGray) convert_to_RGB = QToolButton() convert_to_RGB.setIcon(QIcon(os.path.join(icon_path, "rgb.png"))) convert_to_RGB.clicked.connect(self.image_label.convertToRGB) convert_to_sepia = QToolButton() convert_to_sepia.setIcon(QIcon(os.path.join(icon_path, "sepia.png"))) convert_to_sepia.clicked.connect(self.image_label.convertToSepia) change_hue = QToolButton() change_hue.setIcon(QIcon(os.path.join(icon_path, ""))) change_hue.clicked.connect(self.image_label.changeHue) brightness_label = QLabel("Brightness") self.brightness_slider = QSlider(Qt.Orientations.Horizontal) self.brightness_slider.setRange(-255, 255) self.brightness_slider.setTickInterval(35) self.brightness_slider.setTickPosition(QSlider.TickPosition.TicksAbove) self.brightness_slider.valueChanged.connect( self.image_label.changeBrighteness) contrast_label = QLabel("Contrast") self.contrast_slider = QSlider(Qt.Orientations.Horizontal) self.contrast_slider.setRange(-255, 255) self.contrast_slider.setTickInterval(35) self.contrast_slider.setTickPosition(QSlider.TickPosition.TicksAbove) self.contrast_slider.valueChanged.connect( self.image_label.changeContrast) # Set layout for dock widget editing_grid = QGridLayout() #editing_grid.addWidget(filters_label, 0, 0, 0, 2, Qt.AlignTop) editing_grid.addWidget(convert_to_grayscale, 1, 0) editing_grid.addWidget(convert_to_RGB, 1, 1) editing_grid.addWidget(convert_to_sepia, 2, 0) editing_grid.addWidget(change_hue, 2, 1) editing_grid.addWidget(brightness_label, 3, 0) editing_grid.addWidget(self.brightness_slider, 4, 0, 1, 0) editing_grid.addWidget(contrast_label, 5, 0) editing_grid.addWidget(self.contrast_slider, 6, 0, 1, 0) editing_grid.setRowStretch(7, 10) container = QWidget() container.setLayout(editing_grid) self.editing_bar.setWidget(container) self.addDockWidget(Qt.DockWidgetAreas.LeftDockWidgetArea, self.editing_bar) self.tools_menu_act = self.editing_bar.toggleViewAction()
def __init__(self, parent=None): super(VideoWindow, self).__init__(parent) self.setWindowTitle("StudioProject") self.statusBar = QStatusBar() self.setStatusBar(self.statusBar) self.gScene = QGraphicsScene(self) self.gView = GraphicView(self.gScene, self) self.gView.viewport().setAttribute( Qt.WidgetAttribute.WA_AcceptTouchEvents, False) # self.gView.setBackgroundBrush(QBrush(Qt.black)) self.videoStartDatetime = None self.videoCurrentDatetime = None self.projectFile = '' self.graphicsFile = '' self.videoFile = '' self.obsTb = ObsToolbox(self) # # ===================== Setting video item ============================== # self.videoItem = QGraphicsVideoItem() # self.videoItem.setAspectRatioMode(Qt.KeepAspectRatio) # self.gScene.addItem(self.videoItem) # self.videoItem.mouseMoveEvent = self.gView.mouseMoveEvent self.mediaPlayer = QMediaPlayer(self) # self.mediaPlayer.setVideoOutput(self.videoItem) self.mediaPlayer.playbackStateChanged.connect(self.mediaStateChanged) self.mediaPlayer.positionChanged.connect(self.positionChanged) self.mediaPlayer.durationChanged.connect(self.durationChanged) self.mediaPlayer.errorOccurred.connect(self.handleError) # self.mediaPlayer.setMuted(True) # self.mediaPlayer.setNotifyInterval(100) self.playButton = QPushButton() self.playButton.setEnabled(False) self.playButton.setIcon(self.style().standardIcon( QStyle.StandardPixmap.SP_MediaPlay)) self.playButton.clicked.connect(self.play) self.changePlayRateBtn = QPushButton('1x') self.changePlayRateBtn.setFixedWidth(40) # self.incrPlayRateBtn.setEnabled(False) self.changePlayRateBtn.clicked.connect(self.changePlayRate) self.positionSlider = QSlider(Qt.Orientation.Horizontal) self.positionSlider.setRange(0, 0) self.positionSlider.sliderMoved.connect(self.setPosition) self.timerLabel = QLabel() self.timerLabel.setText('--:--:--') self.timerLabel.setFixedWidth(58) self.dateLabel = QLabel() self.dateLabel.setText('Video date: --') self.statusBar.addPermanentWidget(self.dateLabel) # Create open action self.openVideoAction = QAction(QIcon('icons/video-file.png'), 'Open video', self) self.openVideoAction.setShortcut('Ctrl+O') self.openVideoAction.setStatusTip('Open video file') self.openVideoAction.triggered.connect(self.openVideoFile) # Create observation action obsTbAction = QAction(QIcon('icons/checklist.png'), 'Observation toolbox', self) obsTbAction.setStatusTip('Open observation toolbox') obsTbAction.triggered.connect(self.openObsToolbox) self.drawPointAction = QAction(QIcon('icons/drawPoint.png'), 'Draw point', self) self.drawPointAction.setStatusTip('Draw point over the video') self.drawPointAction.setCheckable(True) self.drawPointAction.setEnabled(False) self.drawPointAction.triggered.connect(self.drawingClick) self.drawLineAction = QAction(QIcon('icons/drawLine.png'), 'Draw line', self) self.drawLineAction.setStatusTip('Draw line over the video') self.drawLineAction.setCheckable(True) self.drawLineAction.setEnabled(False) self.drawLineAction.triggered.connect(self.drawingClick) self.drawZoneAction = QAction(QIcon('icons/drawZone.png'), 'Draw zone', self) self.drawZoneAction.setStatusTip('Draw zone over the video') self.drawZoneAction.setCheckable(True) self.drawZoneAction.setEnabled(False) self.drawZoneAction.triggered.connect(self.drawingClick) self.maskGenAction = QAction(QIcon('icons/mask.png'), 'Generate mask file', self) self.maskGenAction.setStatusTip( 'Generate mask file for TrafficIntelligence') self.maskGenAction.setCheckable(True) self.maskGenAction.setEnabled(False) self.maskGenAction.triggered.connect(self.generateMask) actionGroup = QActionGroup(self) actionGroup.addAction(self.drawPointAction) actionGroup.addAction(self.drawLineAction) actionGroup.addAction(self.drawZoneAction) openProjectAction = QAction(QIcon('icons/open-project.png'), 'Open project', self) openProjectAction.setStatusTip('Open project') openProjectAction.triggered.connect(self.openProject) self.saveProjectAction = QAction(QIcon('icons/save-project.png'), 'Save project', self) self.saveProjectAction.setStatusTip('Save project') self.saveProjectAction.setEnabled(False) self.saveProjectAction.triggered.connect(self.saveProject) self.saveGraphAction = QAction(QIcon('icons/save-graphics.png'), 'Save graphics', self) self.saveGraphAction.setStatusTip('Save graphics to database') self.saveGraphAction.setEnabled(False) self.saveGraphAction.triggered.connect(self.saveGraphics) self.loadGraphAction = QAction(QIcon('icons/folders.png'), 'Load graphics', self) self.loadGraphAction.setStatusTip('Load graphics from database') self.loadGraphAction.setEnabled(False) self.loadGraphAction.triggered.connect(self.loadGraphics) # Create exit action exitAction = QAction(QIcon('icons/close.png'), 'Exit', self) exitAction.setShortcut('Ctrl+Q') exitAction.setStatusTip('Exit application') exitAction.triggered.connect(self.exitCall) # self.exitCall # Create menu bar and add action # menuBar = self.menuBar() # menuBar.setNativeMenuBar(False) # fileMenu = menuBar.addMenu('&File') # fileMenu.addAction(openVideoAction) # fileMenu.addAction(obsTbAction) # fileMenu.addAction(exitAction) self.toolbar = self.addToolBar('Tools') self.toolbar.setIconSize(QSize(24, 24)) self.toolbar.addAction(openProjectAction) self.toolbar.addAction(self.saveProjectAction) self.toolbar.addAction(self.openVideoAction) # self.toolbar.insertSeparator(self.loadGraphAction) # self.toolbar.addAction(self.loadGraphAction) # self.toolbar.addAction(self.saveGraphAction) # self.toolbar.addAction(self.drawPointAction) # self.toolbar.addAction(self.drawLineAction) # self.toolbar.addAction(self.drawZoneAction) self.toolbar.addAction(self.maskGenAction) # self.toolbar.insertSeparator(self.drawPointAction) self.toolbar.insertSeparator(obsTbAction) self.toolbar.addAction(obsTbAction) self.toolbar.insertSeparator(exitAction) self.toolbar.addAction(exitAction) # Create a widget for window contents wid = QWidget(self) self.setCentralWidget(wid) # Create layouts to place inside widget controlLayout = QHBoxLayout() controlLayout.setContentsMargins(0, 0, 0, 0) # controlLayout.addWidget(self.decrPlayRateBtn) controlLayout.addWidget(self.playButton) controlLayout.addWidget(self.changePlayRateBtn) controlLayout.addWidget(self.timerLabel) controlLayout.addWidget(self.positionSlider) # controlLayout.addWidget(self.durationLabel) layout = QVBoxLayout() layout.addWidget(self.gView) layout.addLayout(controlLayout) # Set widget to contain window contents wid.setLayout(layout)