def create_ui(self): """Set up the user interface, signals & slots """ self.main_window = self.load_ui_widget(os.path.join(os.getcwd(), "videosync.ui")) self.main_window.centralwidget.setLayout(self.main_window.vboxlayout) # In this widget, the video will be drawn if platform.system() == "Darwin": # for MacOS self.main_window.videoframe = QtWidgets.QMacCocoaViewContainer(0) self.palette = self.main_window.videoframe.palette() self.palette.setColor(QtGui.QPalette.Window, QtGui.QColor(0, 0, 0)) self.main_window.videoframe.setPalette(self.palette) # Create the position slider (QSlider) self.main_window.positionslider.sliderMoved.connect(self.set_position) # self.positionslider.sliderPressed.connect(self.set_position) self.main_window.positionslider.sliderMoved.connect(self.update_time_label) self.main_window.volume_slider.sliderMoved.connect(self.update_volume) # Create the "previous frame" button self.main_window.previousframe.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaSkipBackward)) self.main_window.previousframe.clicked.connect(self.on_neg_offset) # Create the play button and connect it to the play/pause function self.main_window.playbutton.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay)) self.main_window.playbutton.clicked.connect(self.play_pause) # Create the "next frame" button self.main_window.nextframe.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaSkipForward)) self.main_window.nextframe.clicked.connect(self.on_pos_offset) # Create the "decrease playback rate" button self.main_window.decr_pb_rate.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaSeekBackward)) self.main_window.decr_pb_rate.clicked.connect(self.decr_mov_play_rate) # Create the stop button and connect it to the stop function self.main_window.stopbutton.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaStop)) self.main_window.stopbutton.clicked.connect(self.stop) self.main_window.maximize.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_TitleBarMaxButton)) self.main_window.maximize.clicked.connect(self.on_maximize) # Create the "increase playback rate" button self.main_window.incr_pb_rate.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaSeekForward)) self.main_window.incr_pb_rate.clicked.connect(self.incr_mov_play_rate) self.main_window.videoframe.keyPressEvent = self.on_move # File menu file_menu = self.main_window.menu_bar.addMenu("File") self.audio_lang_menu = self.main_window.menu_bar.addMenu("Audio") self.sub_lang_menu = self.main_window.menu_bar.addMenu("Subtitles") # Create actions to load a new media file and to close the app open_action = QtWidgets.QAction("Load Video", self) close_action = QtWidgets.QAction("Close App", self) file_menu.addAction(open_action) file_menu.addAction(close_action) # test_combo = QtWidgets.QComboBox() # self.main_window.menu_bar.addWidget(test_combo) open_action.triggered.connect(self.open_file) close_action.triggered.connect(sys.exit) self.main_window.videoframe.setFocus() self.main_window.installEventFilter(self) self.main_window.ip_address.textChanged.connect(self.update_mqtt) self.main_window.client_id_input.textChanged.connect(self.update_mqtt) self.main_window.topic_input.textChanged.connect(self.update_mqtt) self.main_window.server_input.stateChanged.connect(self.change_server_state) self.main_window.connect_button.clicked.connect(self.connect_to_mqtt) self.main_window.top_control_box.setEnabled(False) self.main_window.playbutton.setEnabled(False) self.main_window.decr_pb_rate.setEnabled(False) self.main_window.incr_pb_rate.setEnabled(False) self.main_window.stopbutton.setEnabled(False)
def create_ui(self): """Set up the user interface, signals & slots """ self.widget = QtWidgets.QWidget(self) self.setCentralWidget(self.widget) # In this widget, the video will be drawn if platform.system() == "Darwin": # for MacOS self.videoframe = QtWidgets.QMacCocoaViewContainer(0) else: self.videoframe = QtWidgets.QFrame() self.palette = self.videoframe.palette() self.palette.setColor(QtGui.QPalette.Window, QtGui.QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.positionslider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self) self.positionslider.setToolTip("Position") self.positionslider.setMaximum(1000) self.positionslider.sliderMoved.connect(self.set_position) self.positionslider.sliderPressed.connect(self.set_position) self.hbuttonbox = QtWidgets.QHBoxLayout() self.playbutton = QtWidgets.QPushButton("Play") self.hbuttonbox.addWidget(self.playbutton) self.playbutton.clicked.connect(self.play_pause) self.hbuttonbox.addStretch(1) self.progress = QtWidgets.QLabel("--:--") self.hbuttonbox.addWidget(self.progress) self.addeventbutton = QtWidgets.QPushButton("Add Event") self.hbuttonbox.addWidget(self.addeventbutton) self.addeventbutton.clicked.connect(self.add_event) self.hbuttonbox.addStretch(1) self.resetbutton = QtWidgets.QPushButton("Reset") self.hbuttonbox.addWidget(self.resetbutton) self.resetbutton.clicked.connect(self.reset_button_clicked) self.savebutton = QtWidgets.QPushButton("Save Video Manifest") self.hbuttonbox.addWidget(self.savebutton) self.savebutton.clicked.connect(self.save_manifest) self.htablebox = QtWidgets.QHBoxLayout() self.eventstabs = QtWidgets.QTabWidget() self.events = [] self.events.append([]) tab = QtWidgets.QVBoxLayout() radiobutton = QtWidgets.QRadioButton("Game Start") tab.addWidget(radiobutton) # automatically select the game start button radiobutton.setChecked(True) self.events[0].append({ 'radio_button': radiobutton, 'handler': self.game_start_event, 'associated_widgets': {} }) tab_widget = QtWidgets.QWidget() tab_widget.setLayout(tab) self.eventstabs.addTab(tab_widget, 'Game Start') # save a reference of game start button to be used in load manifest self.game_start_radiobutton = radiobutton self.events.append([]) tab = QtWidgets.QVBoxLayout() # wobble goal radiobutton = QtWidgets.QRadioButton( "Wobble Goal Delivered to Target Zone") tab.addWidget(radiobutton) self.events[1].append({ 'radio_button': radiobutton, 'handler': self.wobblegoal_target_event, 'associated_widgets': {} }) # parking radiobutton = QtWidgets.QRadioButton("Robot Parked") tab.addWidget(radiobutton) self.events[1].append({ 'radio_button': radiobutton, 'handler': self.robot_park_event, 'associated_widgets': {} }) # ring goal ring_goals, radiobutton, associated_widgets = self.ring_goal_event_widgets( 'auton') tab.addWidget(radiobutton) tab.addLayout(ring_goals) self.events[1].append({ 'radio_button': radiobutton, 'handler': self.ring_goal_auto_event, 'associated_widgets': associated_widgets }) # power shot radiobutton = QtWidgets.QRadioButton( "Power Shot Target Knocked(auton)") tab.addWidget(radiobutton) self.events[1].append({ 'radio_button': radiobutton, 'handler': self.powershot_event, 'associated_widgets': {} }) # tab tab_widget = QtWidgets.QWidget() tab_widget.setLayout(tab) self.eventstabs.addTab(tab_widget, 'Autonomous') self.events.append([]) tab = QtWidgets.QVBoxLayout() ring_goals, radiobutton, associated_widgets = self.ring_goal_event_widgets( 'teleop') tab.addWidget(radiobutton) tab.addLayout(ring_goals) self.events[2].append({ 'radio_button': radiobutton, 'handler': self.ring_goal_teleop_event, 'associated_widgets': associated_widgets }) tab_widget = QtWidgets.QWidget() tab_widget.setLayout(tab) self.eventstabs.addTab(tab_widget, 'Teleop') self.events.append([]) tab = QtWidgets.QVBoxLayout() # wobble goal to start line radiobutton = QtWidgets.QRadioButton( "Wobble Goal Delivered to Start Line") tab.addWidget(radiobutton) self.events[3].append({ 'radio_button': radiobutton, 'handler': self.wobblegoal_startline_event, 'associated_widgets': {} }) # wobble goal to drop zone radiobutton = QtWidgets.QRadioButton( "Wobble Goal Delivered to Drop Zone") tab.addWidget(radiobutton) self.events[3].append({ 'radio_button': radiobutton, 'handler': self.wobblegoal_dropzone_event, 'associated_widgets': {} }) # ring goal ring_goals, radiobutton, associated_widgets = self.ring_goal_event_widgets( 'teleop') tab.addWidget(radiobutton) tab.addLayout(ring_goals) self.events[3].append({ 'radio_button': radiobutton, 'handler': self.ring_goal_teleop_event, 'associated_widgets': associated_widgets }) # power shot radiobutton = QtWidgets.QRadioButton( "Power Shot Target Knocked(endgame)") tab.addWidget(radiobutton) self.events[3].append({ 'radio_button': radiobutton, 'handler': self.powershot_event, 'associated_widgets': {} }) # tab tab_widget = QtWidgets.QWidget() tab_widget.setLayout(tab) self.eventstabs.addTab(tab_widget, 'End Game') self.events.append([]) tab = QtWidgets.QVBoxLayout() penalty_layout = QtWidgets.QHBoxLayout() radiobutton = QtWidgets.QRadioButton("Minor Penalty") penalty_layout.addWidget(radiobutton) ring_goals.addStretch(1) reason_edit = QtWidgets.QLineEdit() penalty_layout.addWidget(reason_edit) ring_goals.addStretch(1) tab.addLayout(penalty_layout) self.events[4].append({ 'radio_button': radiobutton, 'handler': self.minor_penalty_event, 'associated_widgets': { 'reason': reason_edit } }) penalty_layout = QtWidgets.QHBoxLayout() radiobutton = QtWidgets.QRadioButton("Major Penalty") penalty_layout.addWidget(radiobutton) ring_goals.addStretch(1) reason_edit = QtWidgets.QLineEdit() penalty_layout.addWidget(reason_edit) ring_goals.addStretch(1) tab.addLayout(penalty_layout) self.events[4].append({ 'radio_button': radiobutton, 'handler': self.major_penalty_event, 'associated_widgets': { 'reason': reason_edit } }) tab_widget = QtWidgets.QWidget() tab_widget.setLayout(tab) self.eventstabs.addTab(tab_widget, 'Penalty') self.htablebox.addWidget(self.eventstabs, stretch=6) self.eventstable = QtWidgets.QTableWidget(2, 3) self.eventstable.setHorizontalHeaderLabels(['Event', 'Points', '']) header = self.eventstable.horizontalHeader() header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch) header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents) header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents) self.htablebox.addWidget(self.eventstable, stretch=4) self.vboxlayout = QtWidgets.QVBoxLayout() self.vboxlayout.addWidget(self.videoframe, stretch=10) self.vboxlayout.addWidget(self.positionslider) self.vboxlayout.addLayout(self.hbuttonbox) self.vboxlayout.addLayout(self.htablebox, stretch=7) self.widget.setLayout(self.vboxlayout) menu_bar = self.menuBar() # File menu file_menu = menu_bar.addMenu("File") # Add actions to file menu open_action = QtWidgets.QAction("Load Video", self) close_action = QtWidgets.QAction("Close App", self) file_menu.addAction(open_action) file_menu.addAction(close_action) open_action.triggered.connect(self.open_file) close_action.triggered.connect(sys.exit) self.timer = QtCore.QTimer(self) self.timer.setInterval(100) self.timer.timeout.connect(self.update_ui) self.reset()
def create_ui(self): """Set up the user interface, signals & slots """ self.widget = QtWidgets.QWidget(self) self.setCentralWidget(self.widget) # In this widget, the video will be drawn if platform.system() == "Darwin": # for MacOS self.videoframe = QtWidgets.QMacCocoaViewContainer(0) else: self.videoframe = QtWidgets.QFrame() self.palette = self.videoframe.palette() self.palette.setColor(QtGui.QPalette.Window, QtGui.QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.positionslider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self) self.positionslider.setToolTip("Position") self.positionslider.setMaximum(1000) self.positionslider.sliderMoved.connect(self.set_position) self.positionslider.sliderPressed.connect(self.set_position) self.hbuttonbox = QtWidgets.QHBoxLayout() self.playbutton = QtWidgets.QPushButton("Play") self.hbuttonbox.addWidget(self.playbutton) self.playbutton.clicked.connect(self.play_pause) self.stopbutton = QtWidgets.QPushButton("Stop") self.hbuttonbox.addWidget(self.stopbutton) self.stopbutton.clicked.connect(self.stop) self.hbuttonbox.addStretch(1) self.volumeslider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self) self.volumeslider.setMaximum(100) self.volumeslider.setValue(self.mediaplayer.audio_get_volume()) self.volumeslider.setToolTip("Volume") self.hbuttonbox.addWidget(self.volumeslider) self.volumeslider.valueChanged.connect(self.set_volume) self.vboxlayout = QtWidgets.QVBoxLayout() self.vboxlayout.addWidget(self.videoframe) self.vboxlayout.addWidget(self.positionslider) self.vboxlayout.addLayout(self.hbuttonbox) self.widget.setLayout(self.vboxlayout) menu_bar = self.menuBar() # File menu file_menu = menu_bar.addMenu("File") # Add actions to file menu open_action = QtWidgets.QAction("Load Video", self) close_action = QtWidgets.QAction("Close App", self) file_menu.addAction(open_action) file_menu.addAction(close_action) open_action.triggered.connect(self.open_file) close_action.triggered.connect(sys.exit) self.timer = QtCore.QTimer(self) self.timer.setInterval(100) self.timer.timeout.connect(self.update_ui)