class SlidersGroup(QGroupBox): valueChanged = pyqtSignal(int) def __init__(self, orientation, title, parent=None): super(SlidersGroup, self).__init__(title, parent) self.slider = QSlider(orientation) self.slider.setFocusPolicy(Qt.StrongFocus) self.slider.setTickPosition(QSlider.TicksBothSides) self.slider.setTickInterval(10) self.slider.setSingleStep(1) self.scrollBar = QScrollBar(orientation) self.scrollBar.setFocusPolicy(Qt.StrongFocus) self.dial = QDial() self.dial.setFocusPolicy(Qt.StrongFocus) self.slider.valueChanged.connect(self.scrollBar.setValue) self.scrollBar.valueChanged.connect(self.dial.setValue) self.dial.valueChanged.connect(self.slider.setValue) self.dial.valueChanged.connect(self.valueChanged) if orientation == Qt.Horizontal: direction = QBoxLayout.TopToBottom else: direction = QBoxLayout.LeftToRight slidersLayout = QBoxLayout(direction) slidersLayout.addWidget(self.slider) slidersLayout.addWidget(self.scrollBar) slidersLayout.addWidget(self.dial) self.setLayout(slidersLayout) def setValue(self, value): self.slider.setValue(value) def setMinimum(self, value): self.slider.setMinimum(value) self.scrollBar.setMinimum(value) self.dial.setMinimum(value) def setMaximum(self, value): self.slider.setMaximum(value) self.scrollBar.setMaximum(value) self.dial.setMaximum(value) def invertAppearance(self, invert): self.slider.setInvertedAppearance(invert) self.scrollBar.setInvertedAppearance(invert) self.dial.setInvertedAppearance(invert) def invertKeyBindings(self, invert): self.slider.setInvertedControls(invert) self.scrollBar.setInvertedControls(invert) self.dial.setInvertedControls(invert)
class SlidersGroup(QGroupBox): valueChanged = pyqtSignal(int) def __init__(self, orientation, title, parent=None): super(SlidersGroup, self).__init__(title, parent) self.slider = QSlider(orientation) self.slider.setFocusPolicy(Qt.StrongFocus) self.slider.setTickPosition(QSlider.TicksBothSides) self.slider.setTickInterval(10) self.slider.setSingleStep(1) self.scrollBar = QScrollBar(orientation) self.scrollBar.setFocusPolicy(Qt.StrongFocus) self.dial = QDial() self.dial.setFocusPolicy(Qt.StrongFocus) self.slider.valueChanged.connect(self.scrollBar.setValue) self.scrollBar.valueChanged.connect(self.dial.setValue) self.dial.valueChanged.connect(self.slider.setValue) self.dial.valueChanged.connect(self.valueChanged) if orientation == Qt.Horizontal: direction = QBoxLayout.TopToBottom else: direction = QBoxLayout.LeftToRight slidersLayout = QBoxLayout(direction) slidersLayout.addWidget(self.slider) slidersLayout.addWidget(self.scrollBar) slidersLayout.addWidget(self.dial) self.setLayout(slidersLayout) def setValue(self, value): self.slider.setValue(value) def setMinimum(self, value): self.slider.setMinimum(value) self.scrollBar.setMinimum(value) self.dial.setMinimum(value) def setMaximum(self, value): self.slider.setMaximum(value) self.scrollBar.setMaximum(value) self.dial.setMaximum(value) def invertAppearance(self, invert): self.slider.setInvertedAppearance(invert) self.scrollBar.setInvertedAppearance(invert) self.dial.setInvertedAppearance(invert) def invertKeyBindings(self, invert): self.slider.setInvertedControls(invert) self.scrollBar.setInvertedControls(invert) self.dial.setInvertedControls(invert)
class QConnectionView(QWidget): def __init__(self, parent=None): '''Initialization of the QMatrixView. Arguments --------- parent : QWidget The parent argument is sent to the QWidget constructor. ''' super().__init__(parent) self._inputScrollBar = QScrollBar(Qt.Vertical) self._inputScrollBar.setFocusPolicy(Qt.StrongFocus) self._inputScrollBar.setMaximum(0) self._inputScrollBar.setValue(0) self._connections = QConnectionDisplay() self._outputScrollBar = QScrollBar(Qt.Vertical) self._outputScrollBar.setFocusPolicy(Qt.StrongFocus) self._outputScrollBar.setMaximum(0) self._outputScrollBar.setValue(0) layout = QHBoxLayout() layout.addWidget(self._inputScrollBar) layout.addWidget(self._connections) layout.addWidget(self._outputScrollBar) self.setLayout(layout) self._inputScrollBar.valueChanged.connect( self._connections.setInputOffset) def setActivation(self, input: np.ndarray, output: np.ndarray) -> None: self._connections.setActivation(input, output) self._inputScrollBar.setMaximum( max( self._connections.getInputHeight() - self._connections.height(), 0)) self._inputScrollBar.setValue(self._connections.getInputOffset()) self._inputScrollBar.setPageStep(self._connections.height())
class PreviewWidgetStyle(QGroupBox): def __init__(self, parent=None): super().__init__(parent) self.setTitle(self.tr("Preview")) self.setMaximumHeight(220) self.setObjectName("groupBox") self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.tabWidget = QTabWidget(self) self.tabWidget.setObjectName("tabWidgetPreview") self.tab = QWidget() self.tab.setObjectName("tab") self.horizontalLayout = QHBoxLayout(self.tab) self.horizontalLayout.setObjectName("horizontalLayout") self.groupBox = QGroupBox(self.tab) self.groupBox.setTitle(self.tr("Group Box")) self.groupBox.setObjectName("groupBox") self.verticalLayout_2 = QVBoxLayout(self.groupBox) self.verticalLayout_2.setObjectName("verticalLayout_2") self.radioButton = QRadioButton(self.groupBox) self.radioButton.setText(self.tr("Radio Button")) self.radioButton.setChecked(True) self.radioButton.setObjectName("radioButton") self.verticalLayout_2.addWidget(self.radioButton) self.radioButton_2 = QRadioButton(self.groupBox) self.radioButton_2.setText(self.tr("Radio Button")) self.radioButton_2.setObjectName("radioButton_2") self.verticalLayout_2.addWidget(self.radioButton_2) self.line = QFrame(self.groupBox) self.line.setFrameShape(QFrame.HLine) self.line.setFrameShadow(QFrame.Sunken) self.line.setObjectName("line") self.verticalLayout_2.addWidget(self.line) self.checkBox = QCheckBox(self.groupBox) self.checkBox.setText(self.tr("Check Box")) self.checkBox.setChecked(True) self.checkBox.setObjectName("checkBox") self.verticalLayout_2.addWidget(self.checkBox) self.horizontalLayout.addWidget(self.groupBox) self.verticalLayout_3 = QVBoxLayout() self.verticalLayout_3.setObjectName("verticalLayout_3") self.progressBar = QProgressBar(self.tab) self.progressBar.setProperty("value", 75) self.progressBar.setObjectName("progressBar") self.verticalLayout_3.addWidget(self.progressBar) self.horizontalSlider = QSlider(self.tab) self.horizontalSlider.setProperty("value", 45) self.horizontalSlider.setSliderPosition(45) self.horizontalSlider.setOrientation(Qt.Horizontal) self.horizontalSlider.setObjectName("horizontalSlider") self.verticalLayout_3.addWidget(self.horizontalSlider) self.horizontalLayout_2 = QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.spinBox = QSpinBox(self.tab) self.spinBox.setObjectName("spinBox") self.horizontalLayout_2.addWidget(self.spinBox) self.pushButton = QPushButton(self.tab) self.pushButton.setText(self.tr("Button")) self.pushButton.setObjectName("pushButton") self.horizontalLayout_2.addWidget(self.pushButton) self.verticalLayout_3.addLayout(self.horizontalLayout_2) self.comboBox = QComboBox(self.tab) self.comboBox.setObjectName("comboBox") self.comboBox.addItem(self.tr("Combo Box")) self.verticalLayout_3.addWidget(self.comboBox) self.horizontalLayout.addLayout(self.verticalLayout_3) self.verticalScrollBar = QScrollBar(self.tab) self.verticalScrollBar.setPageStep(50) self.verticalScrollBar.setOrientation(Qt.Vertical) self.verticalScrollBar.setObjectName("verticalScrollBar") self.horizontalLayout.addWidget(self.verticalScrollBar) self.tabWidget.addTab(self.tab, self.tr("Tab 1")) self.tab_2 = QWidget() self.tab_2.setObjectName("tab_2") self.tabWidget.addTab(self.tab_2, self.tr("Tab 2")) self.verticalLayout.addWidget(self.tabWidget) self.pushButton.installEventFilter(self) self.pushButton.setFocusPolicy(Qt.NoFocus) self.radioButton.installEventFilter(self) self.radioButton.setFocusPolicy(Qt.NoFocus) self.radioButton_2.installEventFilter(self) self.radioButton_2.setFocusPolicy(Qt.NoFocus) self.checkBox.installEventFilter(self) self.checkBox.setFocusPolicy(Qt.NoFocus) self.comboBox.installEventFilter(self) self.comboBox.setFocusPolicy(Qt.NoFocus) self.spinBox.installEventFilter(self) self.spinBox.setFocusPolicy(Qt.NoFocus) self.horizontalSlider.installEventFilter(self) self.horizontalSlider.setFocusPolicy(Qt.NoFocus) self.verticalScrollBar.installEventFilter(self) self.verticalScrollBar.setFocusPolicy(Qt.NoFocus) self.tab.installEventFilter(self) self.tab.setFocusPolicy(Qt.NoFocus) self.tab_2.installEventFilter(self) self.tab_2.setFocusPolicy(Qt.NoFocus) self.tabWidget.installEventFilter(self) self.tabWidget.setFocusPolicy(Qt.NoFocus) self.tabWidget.currentChanged.connect(self.noClick) def noClick(self, x): self.tabWidget.setCurrentIndex(0) def eventFilter(self, obj, event): if self.pushButton: if event.type() == QEvent.MouseButtonRelease: return True elif event.type() == QEvent.MouseButtonPress: return True elif event.type() == QEvent.MouseButtonDblClick: return True else: return False else: super().eventFilter(obj, event)
class PreviewWidgetStyle(QGroupBox): def __init__(self, parent=None): super().__init__(parent) self.setTitle(self.tr("Preview")) self.setMaximumHeight(220) self.setObjectName("groupBox") self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.tabWidget = QTabWidget(self) self.tabWidget.setObjectName("tabWidgetPreview") self.tab = QWidget() self.tab.setObjectName("tab") self.horizontalLayout = QHBoxLayout(self.tab) self.horizontalLayout.setObjectName("horizontalLayout") self.groupBox = QGroupBox(self.tab) self.groupBox.setTitle(self.tr("Group Box")) self.groupBox.setObjectName("groupBox") self.verticalLayout_2 = QVBoxLayout(self.groupBox) self.verticalLayout_2.setObjectName("verticalLayout_2") self.radioButton = QRadioButton(self.groupBox) self.radioButton.setText(self.tr("Radio Button")) self.radioButton.setChecked(True) self.radioButton.setObjectName("radioButton") self.verticalLayout_2.addWidget(self.radioButton) self.radioButton_2 = QRadioButton(self.groupBox) self.radioButton_2.setText(self.tr("Radio Button")) self.radioButton_2.setObjectName("radioButton_2") self.verticalLayout_2.addWidget(self.radioButton_2) self.line = QFrame(self.groupBox) self.line.setFrameShape(QFrame.HLine) self.line.setFrameShadow(QFrame.Sunken) self.line.setObjectName("line") self.verticalLayout_2.addWidget(self.line) self.checkBox = QCheckBox(self.groupBox) self.checkBox.setText(self.tr("Check Box")) self.checkBox.setChecked(True) self.checkBox.setObjectName("checkBox") self.verticalLayout_2.addWidget(self.checkBox) self.horizontalLayout.addWidget(self.groupBox) self.verticalLayout_3 = QVBoxLayout() self.verticalLayout_3.setObjectName("verticalLayout_3") self.progressBar = QProgressBar(self.tab) self.progressBar.setProperty("value", 75) self.progressBar.setObjectName("progressBar") self.verticalLayout_3.addWidget(self.progressBar) self.horizontalSlider = QSlider(self.tab) self.horizontalSlider.setProperty("value", 45) self.horizontalSlider.setSliderPosition(45) self.horizontalSlider.setOrientation(Qt.Horizontal) self.horizontalSlider.setObjectName("horizontalSlider") self.verticalLayout_3.addWidget(self.horizontalSlider) self.horizontalLayout_2 = QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.spinBox = QSpinBox(self.tab) self.spinBox.setObjectName("spinBox") self.horizontalLayout_2.addWidget(self.spinBox) self.pushButton = QPushButton(self.tab) self.pushButton.setText(self.tr("Button")) self.pushButton.setObjectName("pushButton") self.horizontalLayout_2.addWidget(self.pushButton) self.verticalLayout_3.addLayout(self.horizontalLayout_2) self.comboBox = QComboBox(self.tab) self.comboBox.setObjectName("comboBox") self.comboBox.addItem(self.tr("Combo Box")) self.verticalLayout_3.addWidget(self.comboBox) self.horizontalLayout.addLayout(self.verticalLayout_3) self.verticalScrollBar = QScrollBar(self.tab) self.verticalScrollBar.setPageStep(50) self.verticalScrollBar.setOrientation(Qt.Vertical) self.verticalScrollBar.setObjectName("verticalScrollBar") self.horizontalLayout.addWidget(self.verticalScrollBar) self.tabWidget.addTab(self.tab, self.tr("Tab 1")) self.tab_2 = QWidget() self.tab_2.setObjectName("tab_2") self.tabWidget.addTab(self.tab_2, self.tr("Tab 2")) self.verticalLayout.addWidget(self.tabWidget) self.pushButton.installEventFilter(self) self.pushButton.setFocusPolicy(Qt.NoFocus) self.radioButton.installEventFilter(self) self.radioButton.setFocusPolicy(Qt.NoFocus) self.radioButton_2.installEventFilter(self) self.radioButton_2.setFocusPolicy(Qt.NoFocus) self.checkBox.installEventFilter(self) self.checkBox.setFocusPolicy(Qt.NoFocus) self.comboBox.installEventFilter(self) self.comboBox.setFocusPolicy(Qt.NoFocus) self.spinBox.installEventFilter(self) self.spinBox.setFocusPolicy(Qt.NoFocus) self.horizontalSlider.installEventFilter(self) self.horizontalSlider.setFocusPolicy(Qt.NoFocus) self.verticalScrollBar.installEventFilter(self) self.verticalScrollBar.setFocusPolicy(Qt.NoFocus) self.tab.installEventFilter(self) self.tab.setFocusPolicy(Qt.NoFocus) self.tab_2.installEventFilter(self) self.tab_2.setFocusPolicy(Qt.NoFocus) self.tabWidget.installEventFilter(self) self.tabWidget.setFocusPolicy(Qt.NoFocus) self.tabWidget.currentChanged.connect(self.noClick) def noClick(self, x): self.tabWidget.setCurrentIndex(0) def eventFilter(self, obj, event): if self.pushButton: if event.type() == QEvent.MouseButtonRelease: return True elif event.type() == QEvent.MouseButtonPress: return True elif event.type() == QEvent.MouseButtonDblClick: return True else: return False else: super().eventFilter(obj, event)
class MainWindow(MainWindowBase, MainWindowUI): VIDEOS = ('front_video_file', 'eyes_video_file') def __init__(self, manager, parent=None): MainWindowBase.__init__(self, parent) self.manager = manager self.current_segment = None self.current_video = 0 self.nav_hide_empty = True self.setupUi(self) self.setupConnections() def setupUi(self, parent): MainWindowUI.setupUi(self, parent) # content area layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.content.setLayout(layout) # add video widget self.contentWidget = VideoWidget() self.content.layout().addWidget(self.contentWidget) self.prev_code = 'def f(img):\n return img' self.te_code = PyCodeEdit() self.te_code.setPlainText(self.prev_code) self.content.layout().addWidget(self.te_code) # footer area layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.footer.setLayout(layout) self.bar_index = QScrollBar(Qt.Horizontal) self.bar_index.setFocusPolicy(Qt.WheelFocus) self.bar_index.setMinimum(0) self.bar_index.setSingleStep(1) self.bar_index.valueChanged.connect(self.indexChanged) layout.addWidget(self.bar_index) self.info = QLabel() layout.addWidget(self.info) # construct navigation tree self.refreshNavigation() # design the view self.treeView.header().hide() # hide header self.treeView.expandToDepth(0) # expand first level def setupConnections(self): # shortcuts self.sc_next = QShortcut(QKeySequence("Right"), self) self.sc_next.activated.connect(self.nextImage) self.sc_prev = QShortcut(QKeySequence("Left"), self) self.sc_prev.activated.connect(self.prevImage) self.treeView.doubleClicked.connect(self.navigation_doubleClicked) self.pb_video_toggle.clicked.connect(self.toggleVideo) self.pb_hide_toggle.clicked.connect(self.toggleHideEmpty) def toggleVideo(self): self.current_video = (self.current_video + 1) % len(MainWindow.VIDEOS) self.setSegment(self.current_segment) def toggleHideEmpty(self): self.nav_hide_empty = not self.nav_hide_empty self.refreshNavigation() def refreshNavigation(self): items = [] for project_id in self.manager.getProjectNames(): project = self.manager.getProject(project_id) p_node = NavigationNode(project.info['Name']) p_node.obj_data = project items.append(p_node) for r_id in sorted(p_node.obj_data.getRecordingNames()): print(r_id) recording = p_node.obj_data.getRecording(r_id) print(recording) if recording: r_node = NavigationNode(r_id) r_node.obj_data = recording p_node.addChild(r_node) for segment_id in r_node.obj_data.getSegmentIDs(): s_node = NavigationNode(segment_id) s_node.obj_data = r_node.obj_data.getSegment( segment_id) r_node.addChild(s_node) self.treeView.setSelectionBehavior(QAbstractItemView.SelectRows) self.treeView.setUniformRowHeights(True) self.treeView.setModel(NavigationModel(items)) def navigation_doubleClicked(self, _): item = self.treeView.selectedIndexes()[0] obj = item.internalPointer().obj_data if hasattr(obj, 'segments') and obj.segments_data: obj = obj.segments_data[0] if hasattr(obj, 'eyes_video_file'): self.setSegment(obj) def applyCode(self): code = self.te_code.toPlainText() if self.prev_code != code: try: exec(code, globals(), locals()) self.contentWidget.onImage = locals()['f'] except Exception as e: print(e) def prevImage(self): self.bar_index.setValue(self.bar_index.value() - 1) def nextImage(self): self.bar_index.setValue(self.bar_index.value() + 1) def setVideo(self, path): self.contentWidget.openVideo(path) self.bar_index.setMaximum(self.contentWidget.video.length) def indexChanged(self, value): self.applyCode() video = self.contentWidget.video video.pos_frame = value self.contentWidget.updateImage() info_msg = [] info_msg.append('FPS: %s' % video.fps) info_msg.append('Frame: %d / %d (%.4f)' % (video.pos_frame + 1, video.length, video.pos_msec)) self.info.setText('\n'.join(info_msg)) def setSegment(self, segment): try: self.current_segment = segment self.setVideo( getattr(self.current_segment, MainWindow.VIDEOS[self.current_video])) self.bar_index.setValue(0) self.indexChanged(0) except: pass