def createListOption(self): def addItem(label, icon_pixmap, width, height): item = QListWidgetItem(list_option) item.setText(label) item.setTextAlignment(Qt.AlignHCenter) item.setIcon(QIcon(icon_pixmap)) item.setSizeHint(QSize(width, height)) list_option = QListWidget() list_option.setAutoFillBackground(True) list_option.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) list_option.setTextElideMode(Qt.ElideNone) list_option.setMovement(QListView.Static) list_option.setFlow(QListView.TopToBottom) list_option.setProperty("isWrapping", QVariant(False)) list_option.setSpacing(3) list_option.setViewMode(QListView.IconMode) items = [] items.append((QApplication.translate("option", "Connections"), "connections.png")) items.append((QApplication.translate("option", "Accounts"), "accounts.png")) items.append((QApplication.translate("option", "Aliases"), "aliases.png")) items.append((QApplication.translate("option", "Macros"), "macros.png")) items.append((QApplication.translate("option", "Keypad"), "keypad.png")) items.append((QApplication.translate("option", "Triggers"), "triggers.png")) items.append((QApplication.translate("option", "Preferences"), "preferences.png")) max_width = 0 for label, icon_name in items: w = list_option.fontMetrics().boundingRect(label).width() if w > max_width: max_width = w # An empiric method to align element in the center of the QListWidget max_width += 15 total_height = 0 for label, icon_name in items: icon_pixmap = QPixmap(":/images/" + icon_name) height = icon_pixmap.height() + list_option.fontMetrics().height() + 3 total_height += height + 5 addItem(label, icon_pixmap, max_width, height) list_option.setUniformItemSizes(True) list_option.setFixedWidth(max_width + 10) list_option.setMinimumHeight(total_height) return list_option
class PreferencesDialog(QDialog): def __init__(self, mainwindow): super(PreferencesDialog, self).__init__(mainwindow) self.setWindowModality(Qt.WindowModal) self.addAction(mainwindow.actionCollection.help_whatsthis) layout = QVBoxLayout() layout.setSpacing(10) self.setLayout(layout) # listview to the left, stacked widget to the right top = QHBoxLayout() layout.addLayout(top) self.pagelist = QListWidget(self) self.stack = QStackedWidget(self) top.addWidget(self.pagelist, 0) top.addWidget(self.stack, 2) layout.addWidget(widgets.Separator(self)) b = self.buttons = QDialogButtonBox(self) b.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Cancel | QDialogButtonBox.Apply | QDialogButtonBox.Reset | QDialogButtonBox.Help) layout.addWidget(b) b.accepted.connect(self.accept) b.rejected.connect(self.reject) b.button(QDialogButtonBox.Apply).clicked.connect(self.saveSettings) b.button(QDialogButtonBox.Reset).clicked.connect(self.loadSettings) b.button(QDialogButtonBox.Help).clicked.connect(self.showHelp) b.button(QDialogButtonBox.Help).setShortcut(QKeySequence.HelpContents) b.button(QDialogButtonBox.Apply).setEnabled(False) # fill the pagelist self.pagelist.setIconSize(QSize(32, 32)) self.pagelist.setSpacing(2) for item in pageorder(): self.pagelist.addItem(item()) self.pagelist.currentItemChanged.connect(self.slotCurrentItemChanged) app.translateUI(self, 100) # read our size and selected page qutil.saveDialogSize(self, "preferences/dialog/size", QSize(500, 300)) self.pagelist.setCurrentRow(_prefsindex) def translateUI(self): self.pagelist.setFixedWidth(self.pagelist.sizeHintForColumn(0) + 12) self.setWindowTitle(app.caption(_("Preferences"))) def done(self, result): if result and self.buttons.button(QDialogButtonBox.Apply).isEnabled(): self.saveSettings() # save our size and selected page global _prefsindex _prefsindex = self.pagelist.currentRow() super(PreferencesDialog, self).done(result) def pages(self): """Yields the settings pages that are already instantiated.""" for n in range(self.stack.count()): yield self.stack.widget(n) def showHelp(self): userguide.show(self.pagelist.currentItem().help) def loadSettings(self): """Loads the settings on reset.""" for page in self.pages(): page.loadSettings() page.hasChanges = False self.buttons.button(QDialogButtonBox.Apply).setEnabled(False) def saveSettings(self): """Saves the settings and applies them.""" for page in self.pages(): if page.hasChanges: page.saveSettings() page.hasChanges = False self.buttons.button(QDialogButtonBox.Apply).setEnabled(False) # emit the signal app.settingsChanged() def slotCurrentItemChanged(self, item): item.activate() def changed(self): """Call this to enable the Apply button.""" self.buttons.button(QDialogButtonBox.Apply).setEnabled(True)
class PreferencesDialog(QDialog): def __init__(self, mainwindow): super(PreferencesDialog, self).__init__(mainwindow) self.setWindowModality(Qt.WindowModal) if mainwindow: self.addAction(mainwindow.actionCollection.help_whatsthis) layout = QVBoxLayout() layout.setSpacing(10) self.setLayout(layout) # listview to the left, stacked widget to the right top = QHBoxLayout() layout.addLayout(top) self.pagelist = QListWidget(self) self.stack = QStackedWidget(self) top.addWidget(self.pagelist, 0) top.addWidget(self.stack, 2) layout.addWidget(widgets.Separator(self)) b = self.buttons = QDialogButtonBox(self) b.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Cancel | QDialogButtonBox.Apply | QDialogButtonBox.Reset | QDialogButtonBox.Help) layout.addWidget(b) b.accepted.connect(self.accept) b.rejected.connect(self.reject) b.button(QDialogButtonBox.Apply).clicked.connect(self.saveSettings) b.button(QDialogButtonBox.Reset).clicked.connect(self.loadSettings) b.button(QDialogButtonBox.Help).clicked.connect(self.showHelp) b.button(QDialogButtonBox.Help).setShortcut(QKeySequence.HelpContents) b.button(QDialogButtonBox.Apply).setEnabled(False) # fill the pagelist self.pagelist.setIconSize(QSize(32, 32)) self.pagelist.setSpacing(2) for item in pageorder(): self.pagelist.addItem(item()) self.pagelist.currentItemChanged.connect(self.slotCurrentItemChanged) app.translateUI(self, 100) # read our size and selected page qutil.saveDialogSize(self, "preferences/dialog/size", QSize(500, 300)) self.pagelist.setCurrentRow(_prefsindex) def translateUI(self): self.pagelist.setFixedWidth(self.pagelist.sizeHintForColumn(0) + 12) self.setWindowTitle(app.caption(_("Preferences"))) def done(self, result): if result and self.buttons.button(QDialogButtonBox.Apply).isEnabled(): self.saveSettings() # save our size and selected page global _prefsindex _prefsindex = self.pagelist.currentRow() super(PreferencesDialog, self).done(result) def pages(self): """Yields the settings pages that are already instantiated.""" for n in range(self.stack.count()): yield self.stack.widget(n) def showHelp(self): userguide.show(self.pagelist.currentItem().help) def loadSettings(self): """Loads the settings on reset.""" for page in self.pages(): page.loadSettings() page.hasChanges = False self.buttons.button(QDialogButtonBox.Apply).setEnabled(False) def saveSettings(self): """Saves the settings and applies them.""" for page in self.pages(): if page.hasChanges: page.saveSettings() page.hasChanges = False self.buttons.button(QDialogButtonBox.Apply).setEnabled(False) # emit the signal app.settingsChanged() def slotCurrentItemChanged(self, item): item.activate() def changed(self): """Call this to enable the Apply button.""" self.buttons.button(QDialogButtonBox.Apply).setEnabled(True)
class Window(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.media = Phonon.MediaObject(self) ### video widget #### self.video = Phonon.VideoWidget(self) self.video.setMinimumSize(320,200) self.videoCuts = [] self.myfilename = "" self.extension = "" self.t1 = "" self.t2 = "" self.t3 = "" self.t4 = "" self.t5 = "" self.t6 = "" ### open button ### self.button = QtGui.QPushButton('Choose Video', self) self.button.setFixedWidth(90) self.button.clicked.connect(self.handleButton) self.button.setStyleSheet(stylesheet(self)) ### context menu #### self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.popup2) ### play / pause button ### self.playbutton = QtGui.QPushButton('Play', self) self.playbutton.setFixedWidth(70) self.playbutton.clicked.connect(self.handlePlayButton) self.playbutton.setStyleSheet(stylesheet(self)) self.connect(QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Space), self), QtCore.SIGNAL('activated()'), self.handlePlayButton) self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+o"), self), QtCore.SIGNAL('activated()'), self.handleButton) self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+s"), self), QtCore.SIGNAL('activated()'), self.handleSaveVideo) self.connect(QtGui.QShortcut(QtGui.QKeySequence("Ctrl+q"), self), QtCore.SIGNAL('activated()'), self.handleQuit) ### save button ### self.savebutton = QtGui.QPushButton('Save Video', self) self.savebutton.setFixedWidth(90) self.savebutton.clicked.connect(self.handleSaveVideo) self.savebutton.setStyleSheet(stylesheet(self)) ### seek slider ### self.slider = Phonon.SeekSlider(self.media) self.slider.setStyleSheet(stylesheet(self)) isize = QSize(16,16) self.slider.setIconSize(isize) self.slider.setFocus() # self.slider.connect(self.handleLabel) ### connection position to label ### self.media.isSeekable() self.media.tick.connect(self.handleLabel) self.media.seekableChanged.connect(self.handleLabel) #self.slider.wheel.connect(self.handleLabel) ### table view ### self.iconList = QListWidget() self.iconList.setAlternatingRowColors(True) self.iconList.setFixedWidth(200) self.iconList.setContextMenuPolicy(Qt.CustomContextMenu) self.iconList.setStyleSheet("QListWidget::item:selected:active { background: #7D8ED9; color:#FFFFFF; } ") self.iconList.setViewMode(0) self.iconList.setSelectionBehavior(1) self.iconList.setIconSize(QSize(80, 80/1.78)) self._hookListActions() self.iconList.customContextMenuRequested.connect(self._openListMenu) ### set start button ### self.startbutton = QtGui.QPushButton('set Start', self) self.startbutton.setFixedWidth(70) self.startbutton.clicked.connect(self.handleStartButton) self.startbutton.setStyleSheet(stylesheet(self)) self.connect(QtGui.QShortcut(QtGui.QKeySequence("s"), self), QtCore.SIGNAL('activated()'), self.handleStartButton) ### set end button ### self.endbutton = QtGui.QPushButton('set End', self) self.endbutton.setFixedWidth(70) self.endbutton.clicked.connect(self.handleEndButton) self.endbutton.setStyleSheet(stylesheet(self)) self.connect(QtGui.QShortcut(QtGui.QKeySequence("e"), self), QtCore.SIGNAL('activated()'), self.handleEndButton) ### label ### self.mlabel = QtGui.QLabel('Frame', self) self.mlabel.setStyleSheet('QLabel \ {background-color: transparent; color: white;}\nQLabel{color: darkcyan; font-size: 12px; background-color: transparent; border-radius: 5px; padding: 6px; text-align: center;}\n QLabel:hover{color: red;}') #self.mlabel.setFixedWidth(80) ### layout ### layout = QtGui.QGridLayout(self) layout.addWidget(self.iconList, 0, 0, 1, 1) layout.addWidget(self.video, 0, 1, 1, 6) layout.addWidget(self.slider, 1, 1, 1, 6) layout.addWidget(self.button, 2, 0, 1, 1) layout.addWidget(self.savebutton, 2, 1, 1, 1) layout.addWidget(self.playbutton, 2, 3, 1, 1) layout.addWidget(self.startbutton, 2, 5, 1, 1) layout.addWidget(self.endbutton, 2, 6, 1, 1) layout.addWidget(self.mlabel, 2, 4, 1, 1) def popup2(self, pos): contextmenu = QMenu() contextmenu.addAction("Play / Pause (SPACE)", self.handlePlayButton) contextmenu.addSeparator() contextmenu.addAction("Load Video (Ctrl-O)", self.handleButton) contextmenu.addAction("Save Video (Ctrl-S)", self.handleSaveVideo) contextmenu.addSeparator() contextmenu.addAction("Info", self.handleInfo) contextmenu.addSeparator() contextmenu.addAction("Exit (q)", self.handleQuit) contextmenu.exec_(QCursor.pos()) def handleInfo(self): msg = QMessageBox() #msg.setFixedSize(500, 300) #msg.setGeometry(100,100, 400, 200) msg.setIcon(QMessageBox.Information) msg.setText("Axel Schneider") msg.setInformativeText(unicode(u"©2016")) msg.setWindowTitle("Cut Video") msg.setDetailedText("Python Qt4") msg.setStandardButtons(QMessageBox.Ok) retval = msg.exec_() print "value of pressed message box button:", retval def handleQuit(self): app.quit() def handleButton(self): if self.media.state() == Phonon.PlayingState: self.media.stop() else: path = QtGui.QFileDialog.getOpenFileName(self, ("Video laden"), '/Axel_1/Filme', "Videos (*.ts *.mp4)") if path: self.myfilename = unicode(path) #.encode("utf-8") window.setWindowTitle(self.myfilename.split("/")[-1]) self.extension = path.split(".")[1] print(self.extension) self.media.setCurrentSource(Phonon.MediaSource(path)) self.video.setScaleMode(1) self.video.setAspectRatio(1) self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self) Phonon.createPath(self.media, self.audio) Phonon.createPath(self.media, self.video) self.media.play() self.playbutton.setText('Pause') def handleSaveVideo(self): result = QFileDialog.getSaveFileName(self, ("Video speichern"), '/tmp/film.' + str(self.extension), "Videos (*.ts *.mp4)") if result: target = unicode(result) self.t1 = float(self.videoCuts[0]) self.t2 = float(self.videoCuts[1]) ffmpeg_extract_subclip(self.myfilename, self.t1, self.t2, targetname=target) window.setWindowTitle("Film gespeichert") self.purgeMarker() def handlePlayButton(self): if self.media.state() == Phonon.PlayingState: self.media.pause() self.playbutton.setText('Play') else: #print(self.iconList.count()) self.media.play() self.playbutton.setText('Pause') def handleStartButton(self): if self.iconList.count() < 2: rm = str(self.media.currentTime() / 100.00 / 10.00) item = QListWidgetItem() img = QImage(self.video.snapshot()) pix = QtGui.QPixmap.fromImage(img) item.setIcon(QIcon(pix)) item.setText("Start: " + rm) self.iconList.addItem(item) self.videoCuts.append(rm) else: return def handleEndButton(self): if self.iconList.count() < 2: rm = str(self.media.currentTime() / 100.00 / 10.00) item = QListWidgetItem() #item.setSizeHint(QSize(150, 40)) img = QImage(self.video.snapshot()) pix = QtGui.QPixmap.fromImage(img) item.setIcon(QIcon(pix)) item.setText("End: " + rm) self.iconList.addItem(item) self.videoCuts.append(rm) self.t3 = float(str(self.media.remainingTime())) print(self.t3) self.media.stop() self.playbutton.setText('Play') else: return def handleLabel(self): ms = self.media.currentTime() seconds=str((ms/1000)%60) minutes=str((ms/(1000*60))%60) hours=str((ms/(1000*60*60))%24) if int(seconds) < 10: seconds = "0" + seconds if int(minutes) < 10: minutes = "0" + minutes if int(hours) < 10: hours = "0" + hours s = hours + ":" + minutes + ":" + seconds self.mlabel.setText(s) def _hookListActions(self): #TOO bad-the list model -should be here... rmAction = QtGui.QAction(QtGui.QIcon('icons/close-x.png'), 'entfernen', self) rmAction.triggered.connect(self._removeMarker) rmAllAction = QtGui.QAction(QtGui.QIcon('icons/clear-all.png'), 'alle entfernen', self) rmAllAction.triggered.connect(self.purgeMarker) self.gotoAction = QtGui.QAction(QtGui.QIcon('icons/go-next.png'), 'zu dieser Position springen', self) self.gotoAction.triggered.connect(self._gotoFromMarker) #menus self._listMenu = QMenu() self._listMenu.addAction(self.gotoAction) self._listMenu.addSeparator() self._listMenu.addAction(rmAction) self._listMenu.addAction(rmAllAction) #---List widget context menu def _removeMarker(self,whatis): selectionList = self.iconList.selectedIndexes() if len(selectionList)==0: return item = selectionList[0] self.iconList.takeItem(item.row()) #self.videoCuts.remove[1]) def clearMarkerList(self): self.iconList.clear() #remove contents, remove file def purgeMarker(self): self.iconList.clear() self.videoCuts = [] def _gotoFromMarker(self,whatis): selectionList = self.iconList.selectedIndexes() if len(selectionList)==0: return item = selectionList[0] pos = item.data().toString().replace("Start: ", "").replace("End: ", "") #frame = pos.ToInt() #self.video.currentTime = 1589 self.setWindowTitle(pos) def _openListMenu(self,position): selectionList = self.iconList.selectedIndexes() if len(selectionList)==0: return self._listMenu.exec_(self.iconList.viewport().mapToGlobal(position))
class statisticsInfoWidget(infoWidget): __chart = None __mainLayout = None __statistics = None __projectsList = None __buttonsLayout = None __statisticGroupBox = None __statisticLayout = None __modeGroupBox = None __modeLayout = None __colors = [Qt.red, QColor(200, 160, 30), Qt.darkGreen, Qt.blue, Qt.black, Qt.darkRed, Qt.darkBlue] def __init__(self, client, parent = None): infoWidget.__init__(self, client, parent) self.__mainLayout = QHBoxLayout() self.__chart = LineChartFrame() self.__projectsList = QListWidget() self.__projectsList.setFixedWidth(200) self.__statisticGroupBox = QGroupBox(self.tr("Statistics type")) self.__statisticLayout = QVBoxLayout() self.__statisticGroupBox.setLayout(self.__statisticLayout) userTotalRadio = QRadioButton(self.tr("User total"), self.__statisticGroupBox) userAverageRadio = QRadioButton(self.tr("User average"), self.__statisticGroupBox) hostTotalRadio = QRadioButton(self.tr("Host total"), self.__statisticGroupBox) hostAverageRadio = QRadioButton(self.tr("Host average"), self.__statisticGroupBox) self.__statisticLayout.addWidget(userTotalRadio) self.__statisticLayout.addWidget(userAverageRadio) self.__statisticLayout.addWidget(hostTotalRadio) self.__statisticLayout.addWidget(hostAverageRadio) self.__buttonsLayout = QVBoxLayout() self.__buttonsLayout.addWidget(self.__projectsList) self.__buttonsLayout.addWidget(self.__statisticGroupBox) self.__mainLayout.addWidget(self.__chart) self.__mainLayout.addLayout(self.__buttonsLayout) self.setMainLayout(self.__mainLayout) userTotalRadio.setChecked(True) self.connect(userTotalRadio, SIGNAL("toggled(bool)"), self.__setUserTotalGraph) self.connect(userAverageRadio, SIGNAL("toggled(bool)"), self.__setUserAverageGraph) self.connect(hostTotalRadio, SIGNAL("toggled(bool)"), self.__setHostTotalGraph) self.connect(hostAverageRadio, SIGNAL("toggled(bool)"), self.__setHostAverageGraph) self.connect(self.__projectsList, SIGNAL("itemChanged(QListWidgetItem *)"), self.__updateStatisticsGraph) self.connect(client, SIGNAL("getStatisticsRecv(PyQt_PyObject)"), self.__updateStatistics) client.getStatistics() def __setUserTotalGraph(self, checked): if checked: self.__chart.setIndex(0) def __setUserAverageGraph(self, checked): if checked: self.__chart.setIndex(1) def __setHostTotalGraph(self, checked): if checked: self.__chart.setIndex(2) def __setHostAverageGraph(self, checked): if checked: self.__chart.setIndex(3) def __updateStatistics(self, statistics): self.disconnect(self.sender(), SIGNAL("getStatisticsRecv(PyQt_PyObject)"), self.__updateStatistics) self.__statistics = statistics self.__addListItems() self.__updateStatisticsGraph() def __addListItems(self): i = 0 for key in self.__statistics.keys(): name = self.sender().getProjectName(key) if name is None: name = key color = self.__colors[i] item = QListWidgetItem(name) item.setData(Qt.DecorationRole, QVariant(QColor(color))) item.setData(Qt.UserRole, QVariant(key)) item.setFlags(Qt.ItemIsSelectable|Qt.ItemIsUserCheckable|Qt.ItemIsEnabled) item.setCheckState(Qt.Checked) self.__projectsList.addItem(item) i = i + 1 if i >= len(self.__colors): i = 0 def __updateStatisticsGraph(self): self.__chart.removeGraphs() for i in range(self.__projectsList.count()): item = self.__projectsList.item(i) color = item.data(Qt.DecorationRole) name = str(item.data(Qt.DisplayRole).toString()) key = str(item.data(Qt.UserRole).toString()) if item.checkState() == Qt.Checked: self.__chart.addGraph(self.__statistics[key], name, color)