class JoystickInvertPreference(QWidget): def __init__(self, parent=None): super(JoystickInvertPreference, self).__init__(parent) layout = QHBoxLayout() self._btnGroup = QButtonGroup() self.btnNormal = ExpandingButton() self.btnNormal.setText('Down') self.btnNormal.setCheckable(True) self.btnNormal.clicked.connect(self.set_preference) self._btnGroup.addButton(self.btnNormal) layout.addWidget(self.btnNormal) self.btnInvert = ExpandingButton() self.btnInvert.setText('Up') self.btnInvert.setCheckable(True) self.btnInvert.clicked.connect(self.set_preference) self._btnGroup.addButton(self.btnInvert) layout.addWidget(self.btnInvert) self.setLayout(layout) self.update_from_preferences() Preferences.subscribe(self.update_from_preferences) def update_from_preferences(self): invert_y = Preferences.get('joystick.invert_y', False) self.btnInvert.setChecked(invert_y) self.btnNormal.setChecked(not invert_y) def set_preference(self): Preferences.set('joystick.invert_y', self.btnInvert.isChecked())
class ColorChoiceWidget(ColorWidget): def __init__(self): super(ColorChoiceWidget, self).__init__() self.buttons = [] self.buttonGroup = QButtonGroup() self.buttonGroup.setExclusive(True) self.buttonGroup.buttonClicked.connect(self.selectColor) def setColors(self, colors): layout = self.buttonWidget.layout() id = 0 for color in colors: button = ColorButton() button.setColor(color) button.setCheckable(True) layout.addWidget(button) self.buttonGroup.addButton(button) self.buttonGroup.setId(button, id) id += 1 layout.addStretch(10) def setColor(self, color): self.color = color for button in self.buttonGroup.buttons(): diffs = map(lambda x, y: abs(x - y), button.color, color) if sum(diffs) < 0.0001: button.setChecked(True) break def selectColor(self, button): self.color = button.color self.valueChanged.emit(self.color)
class RadioButtons(WidgetBridge, Choices): _qttype = QGroupBox def customize(self, widget): assert self.choices, "RadioButtons: Cannot build widget bridge without choices" # We give the GroupBox a container so we can add stretch at the end. self.container = QWidget(self.parent) hbox = QHBoxLayout(self.container) self.buttongroup = QButtonGroup(self.parent) if "direction" in self.config and \ self.config["direction"].lower() == "vertical": box = QVBoxLayout() else: box = QHBoxLayout() ix = 1 for text in self.choicesdict().values(): rb = QRadioButton(text, self.parent) box.addWidget(rb) self.buttongroup.addButton(rb, ix) ix += 1 widget.setLayout(box) hbox.addWidget(widget) hbox.addStretch(1) hbox.setContentsMargins(QMargins(0, 0, 0, 0)) def apply(self, value): for b in self.buttongroup.buttons(): b.setChecked(False) b = self.buttongroup.button(self.index(value) + 1) if b: b.setChecked(True) def retrieve(self): ix = self.buttongroup.checkedId() return self.at(ix - 1) if ix > 0 else None
class PickerTypeDialog(QDialog): """ PickerTypeDialog """ def __init__(self, parent): super(PickerTypeDialog, self).__init__(parent) self.pickerType = None self.pickerTypes = [(SurfaceType, "Surface picker"), (TwoStepType, "Two step picker")] self.radioButtons = [] for picker in self.pickerTypes: self.radioButtons.append(QRadioButton(picker[1])) # self.radioButtons[0].setChecked(True) self.buttonGroup = QButtonGroup() ind = 0 for button in self.radioButtons: self.buttonGroup.addButton(button) self.buttonGroup.setId(button, ind) ind += 1 self.nextButton = QPushButton("Choose") self.nextButton.clicked.connect(self.choose) self.cancelButton = QPushButton("Cancel") self.cancelButton.clicked.connect(self.cancel) groupLayout = QVBoxLayout() for radioButton in self.radioButtons: groupLayout.addWidget(radioButton) self.groupBox = QGroupBox("Choose picker type:") self.groupBox.setLayout(groupLayout) self.setModal(True) layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.addWidget(self.groupBox, 0, 0, 1, 2) layout.addWidget(self.cancelButton, 1, 0) layout.addWidget(self.nextButton, 1, 1) self.setLayout(layout) @Slot() def choose(self): selectedIndex = self.buttonGroup.checkedId() if selectedIndex >= 0: # load choosen picker type self.pickerType = self.pickerTypes[selectedIndex][0] self.accept() @Slot() def cancel(self): self.reject()
def _createChoiceGroup(valueTypes, valueTypeTips): _buttonGroupLayout = QHBoxLayout() buttonGroupValueType = QButtonGroup() buttonGroupValueType.setExclusive(True) for id, choice in enumerate(valueTypes): rb = QRadioButton(choice) rb.setToolTip(valueTypeTips[id]) buttonGroupValueType.addButton(rb, id) _buttonGroupLayout.addWidget(rb) if id == 0: rb.setChecked(True) return buttonGroupValueType, _buttonGroupLayout
def initUI(self): layout = QGridLayout() self.setLayout(layout) inputs = QButtonGroup() btnE1 = InputButton(self) btnE1.setText("Extras 1") btnE1.setInput(VisualsSystem.extras1) layout.addWidget(btnE1, 0, 0) inputs.addButton(btnE1, 1) btnE1.clicked.connect(self.takePreview) btnE2 = InputButton(self) btnE2.setText("Extras 2") btnE2.setInput(VisualsSystem.extras2) layout.addWidget(btnE2, 0, 1) inputs.addButton(btnE2, 2) btnE2.clicked.connect(self.takePreview) btnE3 = InputButton(self) btnE3.setText("Extras 3") btnE3.setInput(VisualsSystem.extras3) layout.addWidget(btnE3, 0, 2) inputs.addButton(btnE3, 3) btnE3.clicked.connect(self.takePreview) btnE4 = InputButton(self) btnE4.setText("Extras 4") btnE4.setInput(VisualsSystem.extras4) layout.addWidget(btnE4, 0, 3) inputs.addButton(btnE4, 4) btnE4.clicked.connect(self.takePreview) btnEVideo = InputButton(self) btnEVideo.setText("Visuals PC video") btnEVideo.setInput(VisualsSystem.visualsPCVideo) layout.addWidget(btnEVideo, 0, 4) inputs.addButton(btnEVideo, 8) btnEVideo.clicked.connect(self.takePreview) self.inputs = inputs self._maybeAddScanConverterControls(layout) self.noInputWarning = NoInputSelectedWarning(self) layout.addWidget(self.noInputWarning, 1, 0, 1, 4)
class ChoiceDialog(QDialog): def __init__(self, choices, help_texts=[], parent=None): super(ChoiceDialog, self).__init__(parent) title = "select one from choices" self.setWindowTitle(title) layout = QVBoxLayout(self) self.choiceButtonGroup = QButtonGroup(self) # it is not a visible UI self.choiceButtonGroup.setExclusive(True) if choices and len(choices) >= 1: if len(help_texts) < len(choices): help_texts = choices self.choices = choices for id, choice in enumerate(self.choices): rb = QRadioButton(choice) rb.setToolTip(help_texts[id]) self.choiceButtonGroup.addButton(rb) self.choiceButtonGroup.setId( rb, id) # negative id if not specified layout.addWidget(rb) if id == 0: rb.setChecked(True) self.choiceButtonGroup.buttonClicked.connect(self.choiceChanged) # OK and Cancel buttons buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) layout.addWidget(buttons) self.setLayout(layout) def choice(self): return self.choices[self.choiceButtonGroup.checkedId()] def choiceId(self): return self.choiceButtonGroup.checkedId() def choiceChanged(self): #print(self.choiceButtonGroup.checkedId()) self.currentChoice = self.choices[self.choiceButtonGroup.checkedId()]
def initUI(self): layout = QGridLayout() self.setLayout(layout) inputs = QButtonGroup() btnE1 = InputButton(self) btnE1.setText("Extras 1") layout.addWidget(btnE1, 0, 0) inputs.addButton(btnE1, 1) btnE2 = InputButton(self) btnE2.setText("Extras 2") layout.addWidget(btnE2, 0, 1) inputs.addButton(btnE2, 2) btnE3 = InputButton(self) btnE3.setText("Extras 3") layout.addWidget(btnE3, 0, 2) inputs.addButton(btnE3, 3) btnE4 = InputButton(self) btnE4.setText("Extras 4") layout.addWidget(btnE4, 0, 3) inputs.addButton(btnE4, 4) btnEVideo = InputButton(self) btnEVideo.setText("Visuals PC video") layout.addWidget(btnEVideo, 0, 4) inputs.addButton(btnEVideo, 8) self.inputs = inputs if self.controller.hasDevice("Extras Scan Converter"): scControl = OverscanFreezeWidget() layout.addWidget(scControl, 1, 4) scControl.btnOverscan.toggled.connect(self.toggleOverscan) scControl.btnFreeze.toggled.connect(self.toggleFreeze) btnPrevMix = OutputButton(1) btnPrevMix.setText("Preview / PC Mix") layout.addWidget(btnPrevMix, 2, 0, 1, 5) btnPrevMix.clicked.connect(self.takePreview)
class ChoiceWidget(QWidget): def __init__(self, choices, help_texts=[], parent=None): super(ChoiceWidget, self).__init__(parent) title = "select one from choices" self.setWindowTitle(title) layout = QVBoxLayout(self) self.choiceButtonGroup = QButtonGroup(self) # it is not a visible UI self.choiceButtonGroup.setExclusive(True) if choices and len(choices) >= 1: if len(help_texts) < len(choices): help_texts = choices self.choices = choices for id, choice in enumerate(self.choices): rb = QRadioButton(choice) rb.setToolTip(help_texts[id]) self.choiceButtonGroup.addButton(rb) self.choiceButtonGroup.setId( rb, id) # negative id if not specified layout.addWidget(rb) if id == 0: rb.setChecked(True) self.choiceButtonGroup.buttonClicked.connect(self.choiceChanged) self.setLayout(layout) def choice(self): return self.choices[self.choiceButtonGroup.checkedId()] def setChoice(self, choice): for i, ch in enumerate(self.choices): if ch == choice: self.choiceButtonGroup.button(i).setChecked(True) def choiceId(self): return self.choiceButtonGroup.checkedId() def choiceChanged(self): #print(self.choiceButtonGroup.checkedId()) self.currentChoice = self.choices[self.choiceButtonGroup.checkedId()]
class StackedPage(QWidget): def __init__(self, parent = None): super(StackedPage, self).__init__(parent) layout = QHBoxLayout(self) leftpane = QVBoxLayout() self.buttongroup = QButtonGroup(self) self.buttongroup.setExclusive(True) self.groupbox = QGroupBox(self) self.groupbox.setMinimumWidth(200) QVBoxLayout(self.groupbox) leftpane.addWidget(self.groupbox) leftpane.addStretch(1) layout.addLayout(leftpane) self.rightpane = QStackedWidget(self) layout.addWidget(self.rightpane) self.buttongroup.buttonClicked[int].connect(self.rightpane.setCurrentIndex) self.rightpane.currentChanged[int].connect(self.activate) def addPage(self, buttontext, widget): button = QPushButton(buttontext) button.setCheckable(True) button.setChecked(self.rightpane.count() == 0) self.buttongroup.addButton(button, self.rightpane.count()) self.groupbox.layout().addWidget(button) self.rightpane.addWidget(widget) def pages(self): return [ self.rightpane.widget(i) for i in range(self.rightpane.count()) ] def activate(self, ix): page = self.rightpane.currentWidget() if hasattr(page, "activate") and callable(page.activate): page.activate() def showEvent(self, *args, **kwargs): self.activate(0) return QWidget.showEvent(self, *args, **kwargs)
class AdvancedCameraControl(ScreenWithBackButton): def __init__(self, title, camera, mainScreen): self.camera = camera super(AdvancedCameraControl, self).__init__(title, mainScreen) def makeContent(self): layout = QHBoxLayout() # self.exposureControls = ExposureControl(self.camera) # layout.addWidget(self.exposureControls) whiteBalanceGrid = QGridLayout() wbTitle = QLabel("White Balance") wbTitle.setAlignment(Qt.AlignCenter) whiteBalanceGrid.addWidget(wbTitle, 0, 0, 1, 2) btnAuto = OptionButton() btnAuto.setText("Auto") _safelyConnect(btnAuto.clicked, self.camera.whiteBalanceAuto) whiteBalanceGrid.addWidget(btnAuto, 1, 0) btnIndoor = OptionButton() btnIndoor.setText("Indoor") _safelyConnect(btnIndoor.clicked, self.camera.whiteBalanceIndoor) whiteBalanceGrid.addWidget(btnIndoor, 2, 0) btnOutdoor = OptionButton() btnOutdoor.setText("Outdoor") _safelyConnect(btnOutdoor.clicked, self.camera.whiteBalanceOutdoor) whiteBalanceGrid.addWidget(btnOutdoor, 3, 0) btnOnePush = OptionButton() btnOnePush.setText("One Push") _safelyConnect(btnOnePush.clicked, self.camera.whiteBalanceOnePush) whiteBalanceGrid.addWidget(btnOnePush, 4, 0) btnOnePushTrigger = ExpandingButton() btnOnePushTrigger.setText("Set") _safelyConnect(btnOnePushTrigger.clicked, self.camera.whiteBalanceOnePushTrigger) btnOnePushTrigger.setEnabled(False) whiteBalanceGrid.addWidget(btnOnePushTrigger, 4, 1) self.wbOpts = QButtonGroup() self.wbOpts.addButton(btnAuto, 1) self.wbOpts.addButton(btnIndoor, 2) self.wbOpts.addButton(btnOutdoor, 3) self.wbOpts.addButton(btnOnePush, 4) self.wbOpts.buttonClicked.connect(lambda: btnOnePushTrigger.setEnabled(self.wbOpts.checkedId() == 4)) layout.addLayout(whiteBalanceGrid) return layout
class ConfigDialog(QtGui.QDialog): pressedclosebutton = False moreToggling = False def moreToggled(self): if self.moreToggling == False: self.moreToggling = True if self.showmoreCheckbox.isChecked() and self.showmoreCheckbox.isVisible(): self.showmoreCheckbox.setChecked(False) self.moreSettingsGroup.setChecked(True) self.moreSettingsGroup.show() self.showmoreCheckbox.hide() self.saveMoreState(True) else: self.moreSettingsGroup.setChecked(False) self.moreSettingsGroup.hide() self.showmoreCheckbox.show() self.saveMoreState(False) self.moreToggling = False self.adjustSize() self.setFixedSize(self.sizeHint()) def runButtonTextUpdate(self): if (self.donotstoreCheckbox.isChecked()): self.runButton.setText(getMessage("en", "run-label")) else: self.runButton.setText(getMessage("en", "storeandrun-label")) def openHelp(self): self.QtGui.QDesktopServices.openUrl("http://syncplay.pl/guide/client/") def _tryToFillPlayerPath(self, playerpath, playerpathlist): settings = QSettings("Syncplay", "PlayerList") settings.beginGroup("PlayerList") savedPlayers = settings.value("PlayerList", []) if(not isinstance(savedPlayers, list)): savedPlayers = [] playerpathlist = list(set(os.path.normcase(os.path.normpath(path)) for path in set(playerpathlist + savedPlayers))) settings.endGroup() foundpath = "" if playerpath != None and playerpath != "": if not os.path.isfile(playerpath): expandedpath = PlayerFactory().getExpandedPlayerPathByPath(playerpath) if expandedpath != None and os.path.isfile(expandedpath): playerpath = expandedpath if os.path.isfile(playerpath): foundpath = playerpath self.executablepathCombobox.addItem(foundpath) for path in playerpathlist: if(os.path.isfile(path) and os.path.normcase(os.path.normpath(path)) != os.path.normcase(os.path.normpath(foundpath))): self.executablepathCombobox.addItem(path) if foundpath == "": foundpath = path if foundpath != "": settings.beginGroup("PlayerList") playerpathlist.append(os.path.normcase(os.path.normpath(foundpath))) settings.setValue("PlayerList", list(set(os.path.normcase(os.path.normpath(path)) for path in set(playerpathlist)))) settings.endGroup() return(foundpath) def updateExecutableIcon(self): currentplayerpath = unicode(self.executablepathCombobox.currentText()) iconpath = PlayerFactory().getPlayerIconByPath(currentplayerpath) if iconpath != None and iconpath != "": self.executableiconImage.load(self.resourcespath + iconpath) self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(self.executableiconImage)) else: self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage())) def browsePlayerpath(self): options = QtGui.QFileDialog.Options() defaultdirectory = "" browserfilter = "All files (*)" if os.name == 'nt': browserfilter = "Executable files (*.exe);;All files (*)" if "PROGRAMFILES(X86)" in os.environ: defaultdirectory = os.environ["ProgramFiles(x86)"] elif "PROGRAMFILES" in os.environ: defaultdirectory = os.environ["ProgramFiles"] elif "PROGRAMW6432" in os.environ: defaultdirectory = os.environ["ProgramW6432"] elif sys.platform.startswith('linux'): defaultdirectory = "/usr/bin" fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, "Browse for media player executable", defaultdirectory, browserfilter, "", options) if fileName: self.executablepathCombobox.setEditText(os.path.normpath(fileName)) def loadMediaBrowseSettings(self): settings = QSettings("Syncplay", "MediaBrowseDialog") settings.beginGroup("MediaBrowseDialog") self.mediadirectory = settings.value("mediadir", "") settings.endGroup() def saveMediaBrowseSettings(self): settings = QSettings("Syncplay", "MediaBrowseDialog") settings.beginGroup("MediaBrowseDialog") settings.setValue("mediadir", self.mediadirectory) settings.endGroup() def getMoreState(self): settings = QSettings("Syncplay", "MoreSettings") settings.beginGroup("MoreSettings") morestate = unicode.lower(unicode(settings.value("ShowMoreSettings", "false"))) settings.endGroup() if morestate == "true": return(True) else: return(False) def saveMoreState(self, morestate): settings = QSettings("Syncplay", "MoreSettings") settings.beginGroup("MoreSettings") settings.setValue("ShowMoreSettings", morestate) settings.endGroup() def browseMediapath(self): self.loadMediaBrowseSettings() options = QtGui.QFileDialog.Options() if (os.path.isdir(self.mediadirectory)): defaultdirectory = self.mediadirectory elif (os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.MoviesLocation))): defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.MoviesLocation) elif (os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.HomeLocation))): defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.HomeLocation) else: defaultdirectory = "" browserfilter = "All files (*)" fileName, filtr = QtGui.QFileDialog.getOpenFileName(self,"Browse for media files",defaultdirectory, browserfilter, "", options) if fileName: self.mediapathTextbox.setText(os.path.normpath(fileName)) self.mediadirectory = os.path.dirname(fileName) self.saveMediaBrowseSettings() def _saveDataAndLeave(self): self.config['host'] = self.hostTextbox.text() if ":" in self.hostTextbox.text() else self.hostTextbox.text() + ":" + unicode(constants.DEFAULT_PORT) self.config['name'] = self.usernameTextbox.text() self.config['room'] = self.defaultroomTextbox.text() self.config['password'] = self.serverpassTextbox.text() self.config['playerPath'] = unicode(self.executablepathCombobox.currentText()) if self.mediapathTextbox.text() == "": self.config['file'] = None elif os.path.isfile(os.path.abspath(self.mediapathTextbox.text())): self.config['file'] = os.path.abspath(self.mediapathTextbox.text()) else: self.config['file'] = unicode(self.mediapathTextbox.text()) if self.alwaysshowCheckbox.isChecked() == True: self.config['forceGuiPrompt'] = True else: self.config['forceGuiPrompt'] = False if self.donotstoreCheckbox.isChecked() == True: self.config['noStore'] = True else: self.config['noStore'] = False if self.slowdownCheckbox.isChecked() == True: self.config['slowOnDesync'] = True else: self.config['slowOnDesync'] = False if self.pauseonleaveCheckbox.isChecked() == True: self.config['pauseOnLeave'] = True else: self.config['pauseOnLeave'] = False if constants.SHOW_REWIND_ON_DESYNC_CHECKBOX == True: if self.rewindCheckbox.isChecked() == True: self.config['rewindOnDesync'] = True else: self.config['rewindOnDesync'] = False self.config['malUsername'] = self.malusernameTextbox.text() self.config['malPassword'] = self.malpasswordTextbox.text() if self.filenameprivacySendRawOption.isChecked() == True: self.config['filenamePrivacyMode'] = constants.PRIVACY_SENDRAW_MODE elif self.filenameprivacySendHashedOption.isChecked() == True: self.config['filenamePrivacyMode'] = constants.PRIVACY_SENDHASHED_MODE elif self.filenameprivacyDontSendOption.isChecked() == True: self.config['filenamePrivacyMode'] = constants.PRIVACY_DONTSEND_MODE if self.filesizeprivacySendRawOption.isChecked() == True: self.config['filesizePrivacyMode'] = constants.PRIVACY_SENDRAW_MODE elif self.filesizeprivacySendHashedOption.isChecked() == True: self.config['filesizePrivacyMode'] = constants.PRIVACY_SENDHASHED_MODE elif self.filesizeprivacyDontSendOption.isChecked() == True: self.config['filesizePrivacyMode'] = constants.PRIVACY_DONTSEND_MODE self.pressedclosebutton = True self.close() return def closeEvent(self, event): if self.pressedclosebutton == False: sys.exit() raise GuiConfiguration.WindowClosed event.accept() def dragEnterEvent(self, event): data = event.mimeData() urls = data.urls() if (urls and urls[0].scheme() == 'file'): event.acceptProposedAction() def dropEvent(self, event): data = event.mimeData() urls = data.urls() if (urls and urls[0].scheme() == 'file'): if sys.platform.startswith('linux'): dropfilepath = unicode(urls[0].path()) else: dropfilepath = unicode(urls[0].path())[1:] # Removes starting slash if dropfilepath[-4:].lower() == ".exe": self.executablepathCombobox.setEditText(dropfilepath) else: self.mediapathTextbox.setText(dropfilepath) def __init__(self, config, playerpaths, error): from syncplay import utils self.config = config self.datacleared = False if config['clearGUIData'] == True: settings = QSettings("Syncplay","PlayerList") settings.clear() settings = QSettings("Syncplay","MediaBrowseDialog") settings.clear() settings = QSettings("Syncplay","MainWindow") settings.clear() settings = QSettings("Syncplay","MoreSettings") settings.clear() self.datacleared = True self.QtGui = QtGui self.error = error if sys.platform.startswith('linux'): resourcespath = utils.findWorkingDir() + "/resources/" else: resourcespath = utils.findWorkingDir() + "\\resources\\" self.resourcespath = resourcespath super(ConfigDialog, self).__init__() self.setWindowTitle(getMessage("en", "config-window-title")) self.setWindowFlags(self.windowFlags() & Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) self.setWindowIcon(QtGui.QIcon(resourcespath + "syncplay.png")) if(config['host'] == None): host = "" elif(":" in config['host']): host = config['host'] else: host = config['host']+":"+str(config['port']) self.connectionSettingsGroup = QtGui.QGroupBox(getMessage("en", "connection-group-title")) self.hostTextbox = QLineEdit(host, self) self.hostLabel = QLabel(getMessage("en", "host-label"), self) self.usernameTextbox = QLineEdit(config['name'],self) self.serverpassLabel = QLabel(getMessage("en", "password-label"), self) self.defaultroomTextbox = QLineEdit(config['room'],self) self.usernameLabel = QLabel(getMessage("en", "username-label"), self) self.serverpassTextbox = QLineEdit(config['password'],self) self.defaultroomLabel = QLabel(getMessage("en", "room-label"), self) if (constants.SHOW_TOOLTIPS == True): self.hostLabel.setToolTip(getMessage("en", "host-tooltip")) self.hostTextbox.setToolTip(getMessage("en", "host-tooltip")) self.usernameLabel.setToolTip(getMessage("en", "username-tooltip")) self.usernameTextbox.setToolTip(getMessage("en", "username-tooltip")) self.serverpassLabel.setToolTip(getMessage("en", "password-tooltip")) self.serverpassTextbox.setToolTip(getMessage("en", "password-tooltip")) self.defaultroomLabel.setToolTip(getMessage("en", "room-tooltip")) self.defaultroomTextbox.setToolTip(getMessage("en", "room-tooltip")) self.connectionSettingsLayout = QtGui.QGridLayout() self.connectionSettingsLayout.addWidget(self.hostLabel, 0, 0) self.connectionSettingsLayout.addWidget(self.hostTextbox, 0, 1) self.connectionSettingsLayout.addWidget(self.serverpassLabel, 1, 0) self.connectionSettingsLayout.addWidget(self.serverpassTextbox, 1, 1) self.connectionSettingsLayout.addWidget(self.usernameLabel, 2, 0) self.connectionSettingsLayout.addWidget(self.usernameTextbox, 2, 1) self.connectionSettingsLayout.addWidget(self.defaultroomLabel, 3, 0) self.connectionSettingsLayout.addWidget(self.defaultroomTextbox, 3, 1) self.connectionSettingsGroup.setLayout(self.connectionSettingsLayout) self.mediaplayerSettingsGroup = QtGui.QGroupBox(getMessage("en", "media-setting-title")) self.executableiconImage = QtGui.QImage() self.executableiconLabel = QLabel(self) self.executableiconLabel.setMinimumWidth(16) self.executablepathCombobox = QtGui.QComboBox(self) self.executablepathCombobox.setEditable(True) self.executablepathCombobox.currentIndexChanged.connect(self.updateExecutableIcon) self.executablepathCombobox.setEditText(self._tryToFillPlayerPath(config['playerPath'], playerpaths)) self.executablepathCombobox.setMinimumWidth(200) self.executablepathCombobox.setMaximumWidth(200) self.executablepathCombobox.editTextChanged.connect(self.updateExecutableIcon) self.executablepathLabel = QLabel(getMessage("en", "executable-path-label"), self) self.executablebrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'),getMessage("en", "browse-label")) self.executablebrowseButton.clicked.connect(self.browsePlayerpath) self.mediapathTextbox = QLineEdit(config['file'], self) self.mediapathLabel = QLabel(getMessage("en", "media-path-label"), self) self.mediabrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'),getMessage("en", "browse-label")) self.mediabrowseButton.clicked.connect(self.browseMediapath) if (constants.SHOW_TOOLTIPS == True): self.executablepathLabel.setToolTip(getMessage("en", "executable-path-tooltip")) self.executablepathCombobox.setToolTip(getMessage("en", "executable-path-tooltip")) self.mediapathLabel.setToolTip(getMessage("en", "media-path-tooltip")) self.mediapathTextbox.setToolTip(getMessage("en", "media-path-tooltip")) if constants.SHOW_REWIND_ON_DESYNC_CHECKBOX == True: self.rewindCheckbox = QCheckBox(getMessage("en", "rewind-label")) if (constants.SHOW_TOOLTIPS == True): self.rewindCheckbox.setToolTip(getMessage("en", "rewind-tooltip")) self.mediaplayerSettingsLayout = QtGui.QGridLayout() self.mediaplayerSettingsLayout.addWidget(self.executablepathLabel, 0, 0) self.mediaplayerSettingsLayout.addWidget(self.executableiconLabel, 0, 1) self.mediaplayerSettingsLayout.addWidget(self.executablepathCombobox, 0, 2) self.mediaplayerSettingsLayout.addWidget(self.executablebrowseButton, 0, 3) self.mediaplayerSettingsLayout.addWidget(self.mediapathLabel, 1, 0) self.mediaplayerSettingsLayout.addWidget(self.mediapathTextbox , 1, 2) self.mediaplayerSettingsLayout.addWidget(self.mediabrowseButton , 1, 3) self.mediaplayerSettingsGroup.setLayout(self.mediaplayerSettingsLayout) self.moreSettingsGroup = QtGui.QGroupBox(getMessage("en", "more-title")) self.moreSettingsGroup.setCheckable(True) self.malSettingsSplit = QtGui.QSplitter(self) self.malusernameTextbox = QLineEdit(config['malUsername'],self) self.malusernameTextbox.setMaximumWidth(115) self.malusernameLabel = QLabel(getMessage("en", "mal-username-label"), self) self.malpasswordTextbox = QLineEdit(config['malPassword'],self) self.malpasswordTextbox.setEchoMode(QtGui.QLineEdit.Password) self.malpasswordLabel = QLabel(getMessage("en", "mal-password-label"), self) ### <MAL DISABLE> self.malpasswordTextbox.hide() self.malpasswordLabel.hide() self.malusernameTextbox.hide() self.malusernameLabel.hide() ### </MAL DISABLE> self.filenameprivacyLabel = QLabel(getMessage("en", "filename-privacy-label"), self) self.filenameprivacyButtonGroup = QButtonGroup() self.filenameprivacySendRawOption = QRadioButton(getMessage("en", "privacy-sendraw-option")) self.filenameprivacySendHashedOption = QRadioButton(getMessage("en", "privacy-sendhashed-option")) self.filenameprivacyDontSendOption = QRadioButton(getMessage("en", "privacy-dontsend-option")) self.filenameprivacyButtonGroup.addButton(self.filenameprivacySendRawOption) self.filenameprivacyButtonGroup.addButton(self.filenameprivacySendHashedOption) self.filenameprivacyButtonGroup.addButton(self.filenameprivacyDontSendOption) self.filesizeprivacyLabel = QLabel(getMessage("en", "filesize-privacy-label"), self) self.filesizeprivacyButtonGroup = QButtonGroup() self.filesizeprivacySendRawOption = QRadioButton(getMessage("en", "privacy-sendraw-option")) self.filesizeprivacySendHashedOption = QRadioButton(getMessage("en", "privacy-sendhashed-option")) self.filesizeprivacyDontSendOption = QRadioButton(getMessage("en", "privacy-dontsend-option")) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacySendRawOption) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacySendHashedOption) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacyDontSendOption) self.slowdownCheckbox = QCheckBox(getMessage("en", "slowdown-label")) self.pauseonleaveCheckbox = QCheckBox(getMessage("en", "pauseonleave-label")) self.alwaysshowCheckbox = QCheckBox(getMessage("en", "alwayshow-label")) self.donotstoreCheckbox = QCheckBox(getMessage("en", "donotstore-label")) filenamePrivacyMode = config['filenamePrivacyMode'] if filenamePrivacyMode == constants.PRIVACY_DONTSEND_MODE: self.filenameprivacyDontSendOption.setChecked(True) elif filenamePrivacyMode == constants.PRIVACY_SENDHASHED_MODE: self.filenameprivacySendHashedOption.setChecked(True) else: self.filenameprivacySendRawOption.setChecked(True) filesizePrivacyMode = config['filesizePrivacyMode'] if filesizePrivacyMode == constants.PRIVACY_DONTSEND_MODE: self.filesizeprivacyDontSendOption.setChecked(True) elif filesizePrivacyMode == constants.PRIVACY_SENDHASHED_MODE: self.filesizeprivacySendHashedOption.setChecked(True) else: self.filesizeprivacySendRawOption.setChecked(True) if config['slowOnDesync'] == True: self.slowdownCheckbox.setChecked(True) if constants.SHOW_REWIND_ON_DESYNC_CHECKBOX == True and config['rewindOnDesync'] == True: self.rewindCheckbox.setChecked(True) if config['pauseOnLeave'] == True: self.pauseonleaveCheckbox.setChecked(True) if (constants.SHOW_TOOLTIPS == True): self.malusernameLabel.setToolTip(getMessage("en", "mal-username-tooltip")) self.malusernameTextbox.setToolTip(getMessage("en", "mal-username-tooltip")) self.malpasswordLabel.setToolTip(getMessage("en", "mal-password-tooltip")) self.malpasswordTextbox.setToolTip(getMessage("en", "mal-password-tooltip")) self.filenameprivacyLabel.setToolTip(getMessage("en", "filename-privacy-tooltip")) self.filenameprivacySendRawOption.setToolTip(getMessage("en", "privacy-sendraw-tooltip")) self.filenameprivacySendHashedOption.setToolTip(getMessage("en", "privacy-sendhashed-tooltip")) self.filenameprivacyDontSendOption.setToolTip(getMessage("en", "privacy-dontsend-tooltip")) self.filesizeprivacyLabel.setToolTip(getMessage("en", "filesize-privacy-tooltip")) self.filesizeprivacySendRawOption.setToolTip(getMessage("en", "privacy-sendraw-tooltip")) self.filesizeprivacySendHashedOption.setToolTip(getMessage("en", "privacy-sendhashed-tooltip")) self.filesizeprivacyDontSendOption.setToolTip(getMessage("en", "privacy-dontsend-tooltip")) self.slowdownCheckbox.setToolTip(getMessage("en", "slowdown-tooltip")) self.pauseonleaveCheckbox.setToolTip(getMessage("en", "pauseonleave-tooltip")) self.alwaysshowCheckbox.setToolTip(getMessage("en", "alwayshow-tooltip")) self.donotstoreCheckbox.setToolTip(getMessage("en", "donotstore-tooltip")) self.slowdownCheckbox.setToolTip(getMessage("en", "slowdown-tooltip")) self.moreSettingsLayout = QtGui.QGridLayout() self.privacySettingsLayout = QtGui.QGridLayout() self.privacyFrame = QtGui.QFrame() self.privacyFrame.setLineWidth(0) self.privacyFrame.setMidLineWidth(0) self.privacySettingsLayout.setContentsMargins(0,0,0,0) self.privacySettingsLayout.addWidget(self.filenameprivacyLabel, 0, 0) self.privacySettingsLayout.addWidget(self.filenameprivacySendRawOption, 0, 1, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filenameprivacySendHashedOption, 0,2, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filenameprivacyDontSendOption, 0, 3, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filesizeprivacyLabel, 1, 0) self.privacySettingsLayout.addWidget(self.filesizeprivacySendRawOption, 1, 1, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filesizeprivacySendHashedOption, 1, 2, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filesizeprivacyDontSendOption, 1, 3, Qt.AlignRight) self.privacyFrame.setLayout(self.privacySettingsLayout) self.moreSettingsLayout.addWidget(self.privacyFrame, 0, 0, 1, 4) self.moreSettingsLayout.addWidget(self.malusernameLabel , 1, 0) self.moreSettingsLayout.addWidget(self.malusernameTextbox, 1, 1) self.moreSettingsLayout.addWidget(self.malpasswordLabel , 1, 2) self.moreSettingsLayout.addWidget(self.malpasswordTextbox, 1, 3) self.moreSettingsLayout.addWidget(self.slowdownCheckbox, 2, 0,1,4) if constants.SHOW_REWIND_ON_DESYNC_CHECKBOX == True: self.moreSettingsLayout.addWidget(self.rewindCheckbox, 3, 0, 1, 4) self.moreSettingsLayout.addWidget(self.pauseonleaveCheckbox, 4, 0, 1, 4) self.moreSettingsLayout.addWidget(self.alwaysshowCheckbox, 5, 0, 1, 4) self.moreSettingsLayout.addWidget(self.donotstoreCheckbox, 6, 0, 1, 4) self.moreSettingsGroup.setLayout(self.moreSettingsLayout) self.showmoreCheckbox = QCheckBox(getMessage("en", "more-title")) if self.getMoreState() == False: self.showmoreCheckbox.setChecked(False) self.moreSettingsGroup.hide() else: self.showmoreCheckbox.hide() self.showmoreCheckbox.toggled.connect(self.moreToggled) self.moreSettingsGroup.toggled.connect(self.moreToggled) if config['forceGuiPrompt'] == True: self.alwaysshowCheckbox.setChecked(True) if (constants.SHOW_TOOLTIPS == True): self.showmoreCheckbox.setToolTip(getMessage("en", "more-tooltip")) self.donotstoreCheckbox.toggled.connect(self.runButtonTextUpdate) self.mainLayout = QtGui.QVBoxLayout() if error: self.errorLabel = QLabel(error, self) self.errorLabel.setAlignment(Qt.AlignCenter) self.errorLabel.setStyleSheet("QLabel { color : red; }") self.mainLayout.addWidget(self.errorLabel) self.mainLayout.addWidget(self.connectionSettingsGroup) self.mainLayout.addSpacing(12) self.mainLayout.addWidget(self.mediaplayerSettingsGroup) self.mainLayout.addSpacing(12) self.mainLayout.addWidget(self.showmoreCheckbox) self.mainLayout.addWidget(self.moreSettingsGroup) self.mainLayout.addSpacing(12) self.topLayout = QtGui.QHBoxLayout() self.helpButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'help.png'),getMessage("en", "help-label")) if (constants.SHOW_TOOLTIPS == True): self.helpButton.setToolTip(getMessage("en", "help-tooltip")) self.helpButton.setMaximumSize(self.helpButton.sizeHint()) self.helpButton.pressed.connect(self.openHelp) self.runButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'accept.png'),getMessage("en", "storeandrun-label")) self.runButton.pressed.connect(self._saveDataAndLeave) if config['noStore'] == True: self.donotstoreCheckbox.setChecked(True) self.runButton.setText(getMessage("en", "run-label")) self.topLayout.addWidget(self.helpButton, Qt.AlignLeft) self.topLayout.addWidget(self.runButton, Qt.AlignRight) self.mainLayout.addLayout(self.topLayout) self.mainLayout.addStretch(1) self.setLayout(self.mainLayout) self.runButton.setFocus() self.setFixedSize(self.sizeHint()) self.setAcceptDrops(True) if self.datacleared == True: QtGui.QMessageBox.information(self,"Syncplay", getMessage("en", "gui-data-cleared-notification"))
class OptionsContainer(QWidget): def __init__(self,main_window): QWidget.__init__(self) self.main_window = main_window self.layout = QGridLayout() self.setLayout(self.layout) self.lr = numpy.zeros(2) self.fps = QSpinBox() self.fps.setValue(25) self.fps.setMinimum(1) self.fps.setMaximum(1000) self.layout.addWidget(QLabel("FPS:"),10,10) self.layout.addWidget(self.fps,10,11) self.capture_area_group = QButtonGroup() self.capture_area_fs = QRadioButton("Full Screen") self.connect(self.capture_area_fs, SIGNAL("clicked()"),self.capture_area_change) self.capture_area_fs.setChecked(True) self.capture_area_sa = QRadioButton("Selected Area") self.connect(self.capture_area_sa, SIGNAL("clicked()"),self.capture_area_change) self.capture_area_group.addButton(self.capture_area_fs) self.capture_area_group.addButton(self.capture_area_sa) self.capture_area_group.setExclusive(True) self.layout.addWidget(self.capture_area_fs,12,10) self.layout.addWidget(self.capture_area_sa,12,11) self.sa_group = QGroupBox() self.sa_grid = QGridLayout() self.sa_group.setLayout(self.sa_grid) self.sa_ul_bt = QPushButton("Select Upper Left") self.connect(self.sa_ul_bt, SIGNAL("clicked()"), self.select_ul) self.sa_lr_bt = QPushButton("Select Lower Right") self.connect(self.sa_lr_bt, SIGNAL("clicked()"), self.select_lr) self.sa_x = QSpinBox() self.sa_y = QSpinBox() self.sa_w = QSpinBox() self.sa_h = QSpinBox() for sb in [self.sa_h,self.sa_w,self.sa_x,self.sa_y]: sb.setMaximum(999999) sb.setMinimum(0) self.sa_grid.addWidget(self.sa_ul_bt,14,10,1,1) self.sa_grid.addWidget(self.sa_lr_bt,15,10,1,1) self.sa_grid.addWidget(QLabel("x"),14,11,1,1) self.sa_grid.addWidget(self.sa_x,14,12,1,1) self.sa_grid.addWidget(QLabel("y"),15,11,1,1) self.sa_grid.addWidget(self.sa_y,15,12,1,1) self.sa_grid.addWidget(QLabel("w"),16,11,1,1) self.sa_grid.addWidget(self.sa_w,16,12,1,1) self.sa_grid.addWidget(QLabel("h"),17,11,1,1) self.sa_grid.addWidget(self.sa_h,17,12,1,1) self.sa_show_bt = QPushButton("Show Area") self.sa_show_bt.setCheckable(True) self.connect(self.sa_show_bt, SIGNAL("clicked()"), self.show_selected_area) self.sa_grid.addWidget(self.sa_show_bt,18,10,1,10) self.sa_group.hide() self.layout.addWidget(self.sa_group,14,10,1,10) self.capture_delay = QSpinBox() self.capture_delay.setMinimum(0) self.capture_delay.setMaximum(10000) self.layout.addWidget(QLabel("Capture Delay"),18,10,1,1) self.layout.addWidget(self.capture_delay,18,11,1,1) self.capture_bt = QPushButton("Capture") self.stop_capture_bt = QPushButton("Stop") self.stop_capture_bt.hide() self.layout.addWidget(self.capture_bt,20,10,1,10) self.layout.addWidget(self.stop_capture_bt,30,10,1,10) self.ffmpeg_flags = QLineEdit() self.ffmpeg_flags.setText("-qscale 0 -vcodec mpeg4") self.layout.addWidget(QLabel("FFMPEG Flags:"),40,10) self.layout.addWidget(self.ffmpeg_flags,50,10,1,10) self.encode_bt = QPushButton("Encode Video") self.layout.addWidget(self.encode_bt,60,10,1,10) self.open_dir_bt = QPushButton("Open Directory") self.layout.addWidget(self.open_dir_bt,80,10,1,10) self.connect(self.open_dir_bt, SIGNAL("clicked()"),self.open_cwd) self.selected_area = SelectedArea() def show_selected_area(self): x = self.sa_x.value() y = self.sa_y.value() w = self.sa_w.value() h = self.sa_h.value() self.selected_area.setGeometry(x,y,w,h) self.selected_area.activateWindow() self.selected_area.raise_() if(self.sa_show_bt.isChecked()): self.selected_area.show() else:self.selected_area.hide() def select_ul(self): print "select_ul" self.clicked = False self.tw = TransWindow() self.tw.mouse_press = False self.tw.show() self.connect(self.tw, SIGNAL("mouse_press()"),self.set_ul) def select_lr(self): print "select_lr" self.clicked = False self.tw = TransWindow() self.tw.mouse_press = False self.tw.show() self.connect(self.tw, SIGNAL("mouse_press()"),self.set_lr) def set_ul(self): self.sa_x.setValue( self.tw.pos[0]) self.sa_y.setValue( self.tw.pos[1]) self.sa_w.setValue( self.lr[0] - self.sa_x.value()) self.sa_h.setValue( self.lr[1] - self.sa_y.value()) self.show_selected_area() def set_lr(self): self.lr = numpy.array([self.tw.pos[0],self.tw.pos[1]]) self.sa_w.setValue( self.tw.pos[0] - self.sa_x.value()) self.sa_h.setValue( self.tw.pos[1] - self.sa_y.value()) self.show_selected_area() def capture_area_change(self): print "capture_area_change" if(self.capture_area_fs.isChecked()): self.sa_group.hide() else: self.sa_group.show() self.adjustSize() self.main_window.adjustSize() def open_cwd(self): #will need to detect os and change accordingly os.system("open {}".format(os.getcwd()))
class MainWindow(object): ''' Contains the implementation for building and displaying the application's main window. ''' def __init__(self, model, alg): ''' Constructs the GUI and initializes internal parameters. ''' self._window = QMainWindow() self._window.setWindowTitle("Reverse A*") self._worldWidget = WorldWidget(model, alg) self._model = model self._alg = alg self._spdSetting = 0 self._timer = QTimer() #Every time the timer times out, invoke the _onStep method. self._timer.timeout.connect(self._onStep) self._buildGUI() self._window.show() def _buildGUI(self): ''' Construct the GUI widgets and layouts. ''' centerWidget = QWidget() self._window.setCentralWidget(centerWidget) worldLayout = QHBoxLayout() worldLayout.addWidget(self._worldWidget) grpBx = QGroupBox("2D World") grpBx.setLayout(worldLayout) grpBx.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) ctrlPan = self._buildControlPanel() layout = QHBoxLayout() layout.addWidget(ctrlPan) layout.addWidget(grpBx) layout.setAlignment(ctrlPan, Qt.AlignLeft | Qt.AlignTop) centerWidget.setLayout(layout) def _buildControlPanel(self): ''' Create all buttons, labels, etc for the application control elements ''' layout = QVBoxLayout() layout.addWidget(self._buildSetupPanel()) layout.addWidget(self._buildSpeedPanel()) layout.addWidget(self._buildResultsPanel()) layout.addWidget(self._buildRenderingOptions()) layout.setAlignment(Qt.AlignLeft | Qt.AlignTop) ctrlWidget = QWidget(self._window) ctrlWidget.setLayout(layout) ctrlWidget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) return ctrlWidget def _buildSetupPanel(self): ''' Creates the sub-panel containing control widgets for re-initializing the world on demand. ''' self._percentLbl = QLabel("%") self._setupBtn = QPushButton("Setup", self._window) self._setupBtn.clicked.connect(self._onSetup) self._percentObstacleSldr = QSlider(Qt.Horizontal, self._window) self._percentObstacleSldr.setTickPosition(QSlider.TickPosition.TicksBelow) self._percentObstacleSldr.setTickInterval(10) self._percentObstacleSldr.setMinimum(0) self._percentObstacleSldr.setMaximum(100) self._percentObstacleSldr.valueChanged.connect(self._onPercentSlideChange) self._percentObstacleSldr.setValue(33) layout = QGridLayout() layout.addWidget(self._setupBtn, 0, 0, 1, 2) layout.addWidget(QLabel("Percent Occupied:"), 1, 0) layout.addWidget(self._percentLbl, 1, 1) layout.addWidget(self._percentObstacleSldr, 2, 0, 1, 2) grpBx = QGroupBox("Setup Controls") grpBx.setLayout(layout) grpBx.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) return grpBx def _buildSpeedPanel(self): ''' Creates the sub-panel containing control widgets for controlling the speed of execution of the algorithm. ''' self._runBtn = QPushButton("Run", self._window) self._stepBtn = QPushButton("Step Once", self._window) self._runBtn.clicked.connect(self._onRun) self._stepBtn.clicked.connect(self._onStep) slowRadio = QRadioButton('Slow', self._window) medRadio = QRadioButton('Medium', self._window) fastRadio = QRadioButton('Fast', self._window) notVisRadio = QRadioButton('Not visible', self._window) slowRadio.setChecked(True) self._speedGroup = QButtonGroup(self._window) self._speedGroup.addButton(slowRadio, 0) self._speedGroup.addButton(medRadio, 1) self._speedGroup.addButton(fastRadio, 2) self._speedGroup.addButton(notVisRadio, 3) self._speedGroup.buttonClicked.connect(self._onSpeedChange) layout = QVBoxLayout() layout.addWidget(self._runBtn) layout.addWidget(self._stepBtn) layout.addWidget(slowRadio) layout.addWidget(medRadio) layout.addWidget(fastRadio) layout.addWidget(notVisRadio) grpBx = QGroupBox("Run Controls") grpBx.setLayout(layout) grpBx.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) return grpBx def _buildResultsPanel(self): ''' Creates the sub-panel containing displays widgets for informing the user on the results of running the algorithm. ''' self._doneLbl = QLabel("No", self._window) self._solvableLbl = QLabel("Yes", self._window) #_doneLbl is highlighted green upon successful algorithm completion pal = self._doneLbl.palette() pal.setColor(QPalette.Window, Qt.green) self._doneLbl.setPalette(pal) #_solvableLbl is highlighted red if the world model isn't solvable pal = self._solvableLbl.palette() pal.setColor(QPalette.Window, Qt.red) self._solvableLbl.setPalette(pal) layout = QGridLayout() layout.addWidget(QLabel("Path Found:"), 0, 0) layout.addWidget(self._doneLbl, 0, 1) layout.addWidget(QLabel("Is Solvable:"), 1, 0) layout.addWidget(self._solvableLbl, 1, 1) grpBx = QGroupBox("Results") grpBx.setLayout(layout) grpBx.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) return grpBx def _buildRenderingOptions(self): ''' Creates the sub-panel containing control widgets for setting options in how the world is rendered on the GUI. ''' self._openChk = QCheckBox("Active Cells") self._visitedChk = QCheckBox("Visited Cells") self._pathChk = QCheckBox("Draw Path") self._costChk = QCheckBox("Draw Estimated Costs") pal = self._openChk.palette() pal.setColor(QPalette.WindowText, Qt.green) self._openChk.setPalette(pal) pal = self._visitedChk.palette() pal.setColor(QPalette.WindowText, Qt.cyan) self._visitedChk.setPalette(pal) pal = self._pathChk.palette() pal.setColor(QPalette.WindowText, Qt.red) self._pathChk.setPalette(pal) self._visitedChk.setChecked(True) self._pathChk.setChecked(True) self._costChk.setChecked(True) self._openChk.stateChanged.connect(self._renderingOptionChanged) self._visitedChk.stateChanged.connect(self._renderingOptionChanged) self._pathChk.stateChanged.connect(self._renderingOptionChanged) self._costChk.stateChanged.connect(self._renderingOptionChanged) layout = QVBoxLayout() layout.addWidget(self._openChk) layout.addWidget(self._visitedChk) layout.addWidget(self._pathChk) layout.addWidget(self._costChk) grpBx = QGroupBox("Rendering Options") grpBx.setLayout(layout) grpBx.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) return grpBx @Slot() def _renderingOptionChanged(self, value): ''' When any rendering option is changed this method is invoked. It polls the GUI for the selected setting values and passes them to the 2D world widget. ''' self._worldWidget.setDrawActiveCells(self._openChk.isChecked()) self._worldWidget.setDrawVisitedCells(self._visitedChk.isChecked()) self._worldWidget.setDrawPath(self._pathChk.isChecked()) self._worldWidget.setDrawCosts(self._costChk.isChecked()) self._worldWidget.repaint() @Slot() def _onPercentSlideChange(self, value): ''' Invoked every time the percent slider is changed. Displays the percent value on the GUI. ''' #Add extra padding to the front of the string to help prevent #gui layout resizing if value < 10: self._percentLbl.setText(" " + str(value) + "%") elif value < 100: self._percentLbl.setText(" " + str(value) + "%") else: self._percentLbl.setText(str(value) + "%") @Slot() def _onSpeedChange(self, value): ''' Invoked every time one of the speed setting radio buttons are selected. Resets the algorithm iterating callback timer if it's currently running. ''' self._spdSetting = self._speedGroup.checkedId() if self._timer.isActive(): self._resetTimer() @Slot() def _onSetup(self): ''' Invoked when the setup button is pushed. Re-initializes the world model and the algorithm. ''' self._timer.stop() self._runBtn.setText('Run') self._model.reset(self._percentObstacleSldr.value() / 100.0) self._alg.reset() self._doneLbl.setText("No") self._solvableLbl.setText("Yes") self._doneLbl.setAutoFillBackground(False) self._solvableLbl.setAutoFillBackground(False) self._worldWidget.repaint() @Slot() def _onRun(self): ''' Invoked when the run button is pushed. Toggles the algorithm iterating timer on and off. ''' if self._timer.isActive(): self._timer.stop() self._runBtn.setText("Run") else: self._resetTimer() self._runBtn.setText("Stop") @Slot() def _onStep(self): ''' Invoked on every 'step once' call and on every timer timeout. Iterates one step of the algorithm and then checks for termination conditions such as the algorithm being done or solvable. ''' self._alg.step() self._worldWidget.repaint() if self._alg.isDone() or not self._alg.isSolvable(): self._timer.stop() self._runBtn.setText('Run') self._checkTerminalConditions() def _checkTerminalConditions(self): ''' Sets the 'results' labels based on the algorithm results. ''' if self._alg.isDone(): self._doneLbl.setText("Yes") self._doneLbl.setAutoFillBackground(True) if not self._alg.isSolvable(): self._solvableLbl.setAutoFillBackground(True) self._solvableLbl.setText("No") def _resetTimer(self): ''' When the algorithm run speed is modified by the user this resets the algorithm timer. ''' if self._spdSetting == 3: while not self._alg.isDone() and self._alg.isSolvable(): self._alg.step() self._worldWidget.repaint() self._timer.stop() self._runBtn.setText("Run") self._checkTerminalConditions() else: timeOut = 1 if self._spdSetting == 0: timeOut = 500 elif self._spdSetting == 1: timeOut = 250 elif self._spdSetting == 2: timeOut = 1 self._timer.start(timeOut)
class ServiceBrowser(QWidget): def __init__(self, parent = None): QWidget.__init__(self, parent) self.serviceManager = QServiceManager(self) self.registerExampleServices() self.initWidgets() self.reloadServicesList() self.setWindowTitle(self.tr("Services Browser")) def __del__(self): self.unregisterExampleServices() def currentInterfaceImplChanged(self, current, previous): if not current: return descriptor = current.data(Qt.UserRole) self.reloadAttributesList() self.reloadAttributesRadioButtonText() if descriptor.isValid(): self.defaultInterfaceButton.setText(self.tr("Set as default implementation for %s" % str(descriptor.interfaceName()))) self.defaultInterfaceButton.setEnabled(True) def reloadServicesList(self): self.servicesListWidget.clear() services = self.serviceManager.findServices() for serv in services: self.servicesListWidget.addItem(serv) self.servicesListWidget.addItem(self.showAllServicesItem) self._services = services def reloadInterfaceImplementationsList(self): serviceName = None allServices = self.servicesListWidget.currentItem().text() == self.showAllServicesItem.text() if self.servicesListWidget.currentItem() and not allServices: serviceName = self.servicesListWidget.currentItem().text() self.interfacesGroup.setTitle(self.tr("Interfaces implemented by %s" % str(serviceName))) else: self.interfacesGroup.setTitle(self.tr("All interface implementations")) descriptors = self.serviceManager.findInterfaces(serviceName) self.attributesListWidget.clear() self.interfacesListWidget.clear() self._i = [] for desc in descriptors: text = "%s %d.%d" % (desc.interfaceName(), desc.majorVersion(), desc.minorVersion()) if not serviceName: text += " (" + desc.serviceName() + ")" defaultInterfaceImpl = self.serviceManager.interfaceDefault(desc.interfaceName()) if desc == defaultInterfaceImpl: text += self.tr(" (default)") item = QListWidgetItem(text) item.setData(Qt.UserRole, desc) item._data = desc self.interfacesListWidget.addItem(item) self.defaultInterfaceButton.setEnabled(False) def reloadAttributesList(self): item = self.interfacesListWidget.currentItem() if not item: return selectedImpl = item.data(Qt.UserRole) implementationRef = None if self.selectedImplRadioButton.isChecked(): implementationRef = self.serviceManager.loadInterface(selectedImpl) else: implementationRef = self.serviceManager.loadInterface(selectedImpl.interfaceName()) self.attributesListWidget.clear() if not implementationRef: self.attributesListWidget.addItem(self.tr("(Error loading service plugin)")) return metaObject = implementationRef.metaObject() self.attributesGroup.setTitle(self.tr("Invokable attributes for %s class" % metaObject.className())) for i in range(metaObject.methodCount()): method = metaObject.method(i) self.attributesListWidget.addItem("[METHOD] " + method.signature()) for i in range(metaObject.propertyCount()): p = metaObject.property(i) self.attributesListWidget.addItem("[PROPERTY] " + p.name()) def setDefaultInterfaceImplementation(self): item = self.interfacesListWidget.currentItem() if not item: return descriptor = item.data(Qt.UserRole) if descriptor.isValid(): if self.serviceManager.setInterfaceDefault(descriptor): currentIndex = self.interfacesListWidget.row(item) self.reloadInterfaceImplementationsList() self.interfacesListWidget.setCurrentRow(currentIndex) else: print "Unable to set default service for interface:", descriptor.interfaceName() def registerExampleServices(self): exampleXmlFiles = ["filemanagerservice.xml", "bluetoothtransferservice.xml"] for fileName in exampleXmlFiles: path = "./xmldata/" + fileName self.serviceManager.addService(path) def unregisterExampleServices(self): self.serviceManager.removeService("FileManagerService") self.serviceManager.removeService("BluetoothTransferService") def reloadAttributesRadioButtonText(self): item = self.interfacesListWidget.currentItem() if not item: return selectedImpl = item.data(Qt.UserRole) defaultImpl = self.serviceManager.interfaceDefault(selectedImpl.interfaceName()) self.defaultImplRadioButton.setText(self.tr("Default implementation for %s\n(currently provided by %s)" % (str(defaultImpl.interfaceName()), str(defaultImpl.serviceName())))) def initWidgets(self): self.showAllServicesItem = QListWidgetItem(self.tr("(All registered services)")) self.servicesListWidget = QListWidget() self.interfacesListWidget = QListWidget() self.interfacesListWidget.addItem(self.tr("(Select a service)")) self.attributesListWidget = QListWidget() self.attributesListWidget.addItem(self.tr("(Select an interface implementation)")) self.interfacesListWidget.setMinimumWidth(450) self.servicesListWidget.currentItemChanged.connect(self.reloadInterfaceImplementationsList) self.interfacesListWidget.currentItemChanged.connect(self.currentInterfaceImplChanged) self.defaultInterfaceButton = QPushButton(self.tr("Set as default implementation")) self.defaultInterfaceButton.setEnabled(False) self.defaultInterfaceButton.clicked.connect(self.setDefaultInterfaceImplementation) self.selectedImplRadioButton = QRadioButton(self.tr("Selected interface implementation")) self.defaultImplRadioButton = QRadioButton(self.tr("Default implementation")) self.selectedImplRadioButton.setChecked(True) self.radioButtons = QButtonGroup(self) self.radioButtons.addButton(self.selectedImplRadioButton) self.radioButtons.addButton(self.defaultImplRadioButton) self.radioButtons.buttonClicked.connect(self.reloadAttributesList) self.servicesGroup = QGroupBox(self.tr("Show services for:")) servicesLayout = QVBoxLayout() servicesLayout.addWidget(self.servicesListWidget) self.servicesGroup.setLayout(servicesLayout) self.interfacesGroup = QGroupBox(self.tr("Interface implementations")) interfacesLayout = QVBoxLayout() interfacesLayout.addWidget(self.interfacesListWidget) interfacesLayout.addWidget(self.defaultInterfaceButton) self.interfacesGroup.setLayout(interfacesLayout) self.attributesGroup = QGroupBox(self.tr("Invokable attributes")) attributesLayout = QVBoxLayout() self.attributesGroup.setLayout(attributesLayout) attributesLayout.addWidget(self.attributesListWidget) attributesLayout.addWidget(QLabel(self.tr("Show attributes for:"))) attributesLayout.addWidget(self.selectedImplRadioButton) attributesLayout.addWidget(self.defaultImplRadioButton) self.attributesGroup.setLayout(attributesLayout) layout = QGridLayout() layout.addWidget(self.servicesGroup, 0, 0) layout.addWidget(self.attributesGroup, 0, 1, 2, 1) layout.addWidget(self.interfacesGroup, 1, 0) self.setLayout(layout)
class ConfigDialog(QtGui.QDialog): pressedclosebutton = False moreToggling = False def moreToggled(self): if self.moreToggling == False: self.moreToggling = True if self.showmoreCheckbox.isChecked(): self.tabListFrame.show() self.resetButton.show() self.nostoreCheckbox.show() self.alwaysshowCheckbox.show() self.saveMoreState(True) self.tabListWidget.setCurrentRow(0) self.ensureTabListIsVisible() else: self.tabListFrame.hide() self.resetButton.hide() self.nostoreCheckbox.hide() self.alwaysshowCheckbox.hide() self.saveMoreState(False) self.stackedLayout.setCurrentIndex(0) self.adjustSize() self.setFixedSize(self.sizeHint()) self.moreToggling = False self.setFixedWidth(self.minimumSizeHint().width()) self.executablepathCombobox.setFixedWidth(self.mediapathTextbox.width()) def runButtonTextUpdate(self): if self.nostoreCheckbox.isChecked(): self.runButton.setText(getMessage("run-label")) else: self.runButton.setText(getMessage("storeandrun-label")) def openHelp(self): self.QtGui.QDesktopServices.openUrl("http://syncplay.pl/guide/client/") def _tryToFillPlayerPath(self, playerpath, playerpathlist): settings = QSettings("Syncplay", "PlayerList") settings.beginGroup("PlayerList") savedPlayers = settings.value("PlayerList", []) if not isinstance(savedPlayers, list): savedPlayers = [] playerpathlist = list(set(os.path.normcase(os.path.normpath(path)) for path in set(playerpathlist + savedPlayers))) settings.endGroup() foundpath = "" if playerpath != None and playerpath != "": if not os.path.isfile(playerpath): expandedpath = PlayerFactory().getExpandedPlayerPathByPath(playerpath) if expandedpath != None and os.path.isfile(expandedpath): playerpath = expandedpath if os.path.isfile(playerpath): foundpath = playerpath self.executablepathCombobox.addItem(foundpath) for path in playerpathlist: if os.path.isfile(path) and os.path.normcase(os.path.normpath(path)) != os.path.normcase(os.path.normpath(foundpath)): self.executablepathCombobox.addItem(path) if foundpath == "": foundpath = path if foundpath != "": settings.beginGroup("PlayerList") playerpathlist.append(os.path.normcase(os.path.normpath(foundpath))) settings.setValue("PlayerList", list(set(os.path.normcase(os.path.normpath(path)) for path in set(playerpathlist)))) settings.endGroup() return foundpath def updateExecutableIcon(self): currentplayerpath = unicode(self.executablepathCombobox.currentText()) iconpath = PlayerFactory().getPlayerIconByPath(currentplayerpath) if iconpath != None and iconpath != "": self.executableiconImage.load(self.resourcespath + iconpath) self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(self.executableiconImage)) else: self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage())) def browsePlayerpath(self): options = QtGui.QFileDialog.Options() defaultdirectory = "" browserfilter = "All files (*)" if os.name == 'nt': browserfilter = "Executable files (*.exe);;All files (*)" if "PROGRAMFILES(X86)" in os.environ: defaultdirectory = os.environ["ProgramFiles(x86)"] elif "PROGRAMFILES" in os.environ: defaultdirectory = os.environ["ProgramFiles"] elif "PROGRAMW6432" in os.environ: defaultdirectory = os.environ["ProgramW6432"] elif sys.platform.startswith('linux'): defaultdirectory = "/usr/bin" elif sys.platform.startswith('darwin'): defaultdirectory = "/Applications/" fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, "Browse for media player executable", defaultdirectory, browserfilter, "", options) if fileName: self.executablepathCombobox.setEditText(os.path.normpath(fileName)) def loadMediaBrowseSettings(self): settings = QSettings("Syncplay", "MediaBrowseDialog") settings.beginGroup("MediaBrowseDialog") self.mediadirectory = settings.value("mediadir", "") settings.endGroup() def saveMediaBrowseSettings(self): settings = QSettings("Syncplay", "MediaBrowseDialog") settings.beginGroup("MediaBrowseDialog") settings.setValue("mediadir", self.mediadirectory) settings.endGroup() def getMoreState(self): settings = QSettings("Syncplay", "MoreSettings") settings.beginGroup("MoreSettings") morestate = unicode.lower(unicode(settings.value("ShowMoreSettings", "false"))) settings.endGroup() if morestate == "true": return True else: return False def saveMoreState(self, morestate): settings = QSettings("Syncplay", "MoreSettings") settings.beginGroup("MoreSettings") settings.setValue("ShowMoreSettings", morestate) settings.endGroup() def browseMediapath(self): self.loadMediaBrowseSettings() options = QtGui.QFileDialog.Options() if os.path.isdir(self.mediadirectory): defaultdirectory = self.mediadirectory elif os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.MoviesLocation)): defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.MoviesLocation) elif os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.HomeLocation)): defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.HomeLocation) else: defaultdirectory = "" browserfilter = "All files (*)" fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, "Browse for media files", defaultdirectory, browserfilter, "", options) if fileName: self.mediapathTextbox.setText(os.path.normpath(fileName)) self.mediadirectory = os.path.dirname(fileName) self.saveMediaBrowseSettings() def _saveDataAndLeave(self): self.processWidget(self, lambda w: self.saveValues(w)) if self.hostTextbox.text(): self.config['host'] = self.hostTextbox.text() if ":" in self.hostTextbox.text() else self.hostTextbox.text() + ":" + unicode(constants.DEFAULT_PORT) else: self.config['host'] = None self.config['playerPath'] = unicode(self.executablepathCombobox.currentText()) if self.mediapathTextbox.text() == "": self.config['file'] = None elif os.path.isfile(os.path.abspath(self.mediapathTextbox.text())): self.config['file'] = os.path.abspath(self.mediapathTextbox.text()) else: self.config['file'] = unicode(self.mediapathTextbox.text()) if not self.slowdownThresholdSpinbox.text: self.slowdownThresholdSpinbox.value = constants.DEFAULT_SLOWDOWN_KICKIN_THRESHOLD if not self.rewindThresholdSpinbox.text: self.rewindThresholdSpinbox.value = constants.DEFAULT_REWIND_THRESHOLD self.config['slowdownThreshold'] = self.slowdownThresholdSpinbox.value() self.config['rewindThreshold'] = self.rewindThresholdSpinbox.value() self.pressedclosebutton = True self.close() return def closeEvent(self, event): if self.pressedclosebutton == False: sys.exit() raise GuiConfiguration.WindowClosed event.accept() def dragEnterEvent(self, event): data = event.mimeData() urls = data.urls() if urls and urls[0].scheme() == 'file': event.acceptProposedAction() def dropEvent(self, event): data = event.mimeData() urls = data.urls() if urls and urls[0].scheme() == 'file': if sys.platform.startswith('win'): dropfilepath = unicode(urls[0].path())[1:] # Removes starting slash else: dropfilepath = unicode(urls[0].path()) if dropfilepath[-4:].lower() == ".exe": self.executablepathCombobox.setEditText(dropfilepath) else: self.mediapathTextbox.setText(dropfilepath) def processWidget(self, container, torun): for widget in container.children(): self.processWidget(widget, torun) if hasattr(widget, 'objectName') and widget.objectName() and widget.objectName()[:3] != "qt_": torun(widget) def loadTooltips(self, widget): tooltipName = widget.objectName().lower().split(constants.CONFIG_NAME_MARKER)[0] + "-tooltip" if tooltipName[:1] == constants.INVERTED_STATE_MARKER or tooltipName[:1] == constants.LOAD_SAVE_MANUALLY_MARKER: tooltipName = tooltipName[1:] widget.setToolTip(getMessage(tooltipName)) def loadValues(self, widget): valueName = str(widget.objectName()) if valueName[:1] == constants.LOAD_SAVE_MANUALLY_MARKER: return if isinstance(widget, QCheckBox) and widget.objectName(): if valueName[:1] == constants.INVERTED_STATE_MARKER: valueName = valueName[1:] inverted = True else: inverted = False widget.setChecked(self.config[valueName] != inverted) elif isinstance(widget, QRadioButton): radioName, radioValue = valueName.split(constants.CONFIG_NAME_MARKER)[1].split(constants.CONFIG_VALUE_MARKER) if self.config[radioName] == radioValue: widget.setChecked(True) elif isinstance(widget, QLineEdit): widget.setText(self.config[valueName]) def saveValues(self, widget): valueName = str(widget.objectName()) if valueName[:1] == constants.LOAD_SAVE_MANUALLY_MARKER: return if isinstance(widget, QCheckBox) and widget.objectName(): if valueName[:1] == constants.INVERTED_STATE_MARKER: valueName = valueName[1:] inverted = True else: inverted = False self.config[valueName] = widget.isChecked() != inverted elif isinstance(widget, QRadioButton): radioName, radioValue = valueName.split(constants.CONFIG_NAME_MARKER)[1].split(constants.CONFIG_VALUE_MARKER) if widget.isChecked(): self.config[radioName] = radioValue elif isinstance(widget, QLineEdit): self.config[valueName] = widget.text() def connectChildren(self, widget): widgetName = str(widget.objectName()) if self.subitems.has_key(widgetName) and isinstance(widget, QCheckBox): widget.stateChanged.connect(lambda: self.updateSubwidgets(self, widget)) self.updateSubwidgets(self, widget) def updateSubwidgets(self, container, parentwidget, subwidgets=None): widgetName = parentwidget.objectName() if not subwidgets: subwidgets = self.subitems[widgetName] for widget in container.children(): self.updateSubwidgets(widget, parentwidget, subwidgets) if hasattr(widget, 'objectName') and widget.objectName() and widget.objectName() in subwidgets: widget.setDisabled(not parentwidget.isChecked()) def addBasicTab(self): config = self.config playerpaths = self.playerpaths resourcespath = self.resourcespath error = self.error if self.datacleared == True: error = constants.ERROR_MESSAGE_MARKER + "{}".format(getMessage("gui-data-cleared-notification")) if config['host'] == None: host = "" elif ":" in config['host']: host = config['host'] else: host = config['host'] + ":" + str(config['port']) self.connectionSettingsGroup = QtGui.QGroupBox(getMessage("connection-group-title")) self.hostTextbox = QLineEdit(host, self) self.hostLabel = QLabel(getMessage("host-label"), self) self.usernameTextbox = QLineEdit(self) self.usernameTextbox.setObjectName("name") self.serverpassLabel = QLabel(getMessage("password-label"), self) self.defaultroomTextbox = QLineEdit(self) self.usernameLabel = QLabel(getMessage("name-label"), self) self.serverpassTextbox = QLineEdit(self) self.defaultroomLabel = QLabel(getMessage("room-label"), self) self.hostLabel.setObjectName("host") self.hostTextbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "host") self.usernameLabel.setObjectName("name") self.usernameTextbox.setObjectName("name") self.serverpassLabel.setObjectName("password") self.serverpassTextbox.setObjectName("password") self.defaultroomLabel.setObjectName("room") self.defaultroomTextbox.setObjectName("room") self.connectionSettingsLayout = QtGui.QGridLayout() self.connectionSettingsLayout.addWidget(self.hostLabel, 0, 0) self.connectionSettingsLayout.addWidget(self.hostTextbox, 0, 1) self.connectionSettingsLayout.addWidget(self.serverpassLabel, 1, 0) self.connectionSettingsLayout.addWidget(self.serverpassTextbox, 1, 1) self.connectionSettingsLayout.addWidget(self.usernameLabel, 2, 0) self.connectionSettingsLayout.addWidget(self.usernameTextbox, 2, 1) self.connectionSettingsLayout.addWidget(self.defaultroomLabel, 3, 0) self.connectionSettingsLayout.addWidget(self.defaultroomTextbox, 3, 1) self.connectionSettingsGroup.setLayout(self.connectionSettingsLayout) self.mediaplayerSettingsGroup = QtGui.QGroupBox(getMessage("media-setting-title")) self.executableiconImage = QtGui.QImage() self.executableiconLabel = QLabel(self) self.executableiconLabel.setMinimumWidth(16) self.executablepathCombobox = QtGui.QComboBox(self) self.executablepathCombobox.setEditable(True) self.executablepathCombobox.currentIndexChanged.connect(self.updateExecutableIcon) self.executablepathCombobox.setEditText(self._tryToFillPlayerPath(config['playerPath'], playerpaths)) self.executablepathCombobox.setFixedWidth(165) self.executablepathCombobox.editTextChanged.connect(self.updateExecutableIcon) self.executablepathLabel = QLabel(getMessage("executable-path-label"), self) self.executablebrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("browse-label")) self.executablebrowseButton.clicked.connect(self.browsePlayerpath) self.mediapathTextbox = QLineEdit(config['file'], self) self.mediapathLabel = QLabel(getMessage("media-path-label"), self) self.mediabrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("browse-label")) self.mediabrowseButton.clicked.connect(self.browseMediapath) self.executablepathLabel.setObjectName("executable-path") self.executablepathCombobox.setObjectName("executable-path") self.mediapathLabel.setObjectName("media-path") self.mediapathTextbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "media-path") self.mediaplayerSettingsLayout = QtGui.QGridLayout() self.mediaplayerSettingsLayout.addWidget(self.executablepathLabel, 0, 0) self.mediaplayerSettingsLayout.addWidget(self.executableiconLabel, 0, 1) self.mediaplayerSettingsLayout.addWidget(self.executablepathCombobox, 0, 2) self.mediaplayerSettingsLayout.addWidget(self.executablebrowseButton, 0, 3) self.mediaplayerSettingsLayout.addWidget(self.mediapathLabel, 1, 0) self.mediaplayerSettingsLayout.addWidget(self.mediapathTextbox , 1, 2) self.mediaplayerSettingsLayout.addWidget(self.mediabrowseButton , 1, 3) self.mediaplayerSettingsGroup.setLayout(self.mediaplayerSettingsLayout) self.showmoreCheckbox = QCheckBox(getMessage("more-title")) self.showmoreCheckbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "more") self.basicOptionsFrame = QtGui.QFrame() self.basicOptionsLayout = QtGui.QVBoxLayout() if error: self.errorLabel = QLabel(self) if error[:1] != constants.ERROR_MESSAGE_MARKER: self.errorLabel.setStyleSheet(constants.STYLE_ERRORLABEL) else: error = error[1:] self.errorLabel.setStyleSheet(constants.STYLE_SUCCESSLABEL) self.errorLabel.setText(error) self.errorLabel.setAlignment(Qt.AlignCenter) self.basicOptionsLayout.addWidget(self.errorLabel, 0, 0) self.basicOptionsLayout.addWidget(self.connectionSettingsGroup) self.basicOptionsLayout.addSpacing(12) self.basicOptionsLayout.addWidget(self.mediaplayerSettingsGroup) self.basicOptionsFrame.setLayout(self.basicOptionsLayout) self.stackedLayout.addWidget(self.basicOptionsFrame) def addSyncTab(self): self.syncSettingsFrame = QtGui.QFrame() self.syncSettingsLayout = QtGui.QVBoxLayout() self.desyncSettingsGroup = QtGui.QGroupBox("If others are lagging behind...") self.desyncOptionsFrame = QtGui.QFrame() self.desyncSettingsOptionsLayout = QtGui.QHBoxLayout() config = self.config self.slowdownCheckbox = QCheckBox(getMessage("slowondesync-label")) self.slowdownCheckbox.setObjectName("slowOnDesync") self.rewindCheckbox = QCheckBox(getMessage("rewindondesync-label")) self.rewindCheckbox.setObjectName("rewindOnDesync") self.spaceLabel = QLabel() self.spaceLabel.setFixedHeight(5) self.desyncSettingsLayout = QtGui.QGridLayout() self.desyncSettingsLayout.setSpacing(2) self.desyncFrame = QtGui.QFrame() self.desyncFrame.setLineWidth(0) self.desyncFrame.setMidLineWidth(0) self.slowdownThresholdLabel = QLabel(getMessage("slowdown-threshold-label"), self) self.slowdownThresholdLabel.setStyleSheet(constants.STYLE_SUBLABEL.format(self.posixresourcespath + "bullet_black.png")) self.slowdownThresholdSpinbox = QDoubleSpinBox() try: slowdownThreshold = float(config['slowdownThreshold']) self.slowdownThresholdSpinbox.setValue(slowdownThreshold) if slowdownThreshold < constants.MINIMUM_SLOWDOWN_THRESHOLD: constants.MINIMUM_SLOWDOWN_THRESHOLD = slowdownThreshold except ValueError: self.slowdownThresholdSpinbox.setValue(constants.DEFAULT_SLOWDOWN_KICKIN_THRESHOLD) self.slowdownThresholdSpinbox.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) self.slowdownThresholdSpinbox.setMinimum(constants.MINIMUM_SLOWDOWN_THRESHOLD) self.slowdownThresholdSpinbox.setSingleStep(0.1) self.slowdownThresholdSpinbox.setSuffix(getMessage("seconds-suffix")) self.slowdownThresholdSpinbox.adjustSize() self.rewindThresholdLabel = QLabel(getMessage("rewind-threshold-label"), self) self.rewindThresholdLabel.setStyleSheet(constants.STYLE_SUBLABEL.format(self.posixresourcespath + "bullet_black.png")) self.rewindThresholdSpinbox = QDoubleSpinBox() try: rewindThreshold = float(config['rewindThreshold']) self.rewindThresholdSpinbox.setValue(rewindThreshold) if rewindThreshold < constants.MINIMUM_REWIND_THRESHOLD: constants.MINIMUM_REWIND_THRESHOLD = rewindThreshold except ValueError: self.rewindThresholdSpinbox.setValue(constants.DEFAULT_REWIND_THRESHOLD) self.rewindThresholdSpinbox.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) self.rewindThresholdSpinbox.setMinimum(constants.MINIMUM_REWIND_THRESHOLD) self.rewindThresholdSpinbox.setSingleStep(0.1) self.rewindThresholdSpinbox.setSuffix(getMessage("seconds-suffix")) self.rewindThresholdSpinbox.adjustSize() self.slowdownThresholdLabel.setObjectName("slowdown-threshold") self.slowdownThresholdSpinbox.setObjectName("slowdown-threshold") self.rewindThresholdLabel.setObjectName("rewind-threshold") self.rewindThresholdSpinbox.setObjectName("rewind-threshold") self.desyncSettingsLayout.addWidget(self.slowdownCheckbox, 0, 0, 1, 2, Qt.AlignLeft) self.desyncSettingsLayout.addWidget(self.slowdownThresholdLabel, 1, 0, 1, 1, Qt.AlignLeft) self.desyncSettingsLayout.addWidget(self.slowdownThresholdSpinbox, 1, 1, 1, 1, Qt.AlignLeft) self.desyncSettingsLayout.addWidget(self.spaceLabel, 2, 0,1,2, Qt.AlignLeft) self.desyncSettingsLayout.addWidget(self.rewindCheckbox, 3, 0,1,2, Qt.AlignLeft) self.desyncSettingsLayout.addWidget(self.rewindThresholdLabel, 4, 0, 1, 1, Qt.AlignLeft) self.desyncSettingsLayout.addWidget(self.rewindThresholdSpinbox, 4, 1, Qt.AlignLeft) self.subitems['slowOnDesync'] = ["slowdown-threshold"] self.subitems['rewindOnDesync'] = ["rewind-threshold"] self.desyncSettingsLayout.setAlignment(Qt.AlignLeft) self.desyncSettingsGroup.setLayout(self.desyncSettingsLayout) self.desyncSettingsOptionsLayout.addWidget(self.desyncFrame) self.syncSettingsLayout.addWidget(self.desyncSettingsGroup) self.desyncFrame.setLayout(self.syncSettingsLayout) self.othersyncSettingsGroup = QtGui.QGroupBox("Other sync options") self.othersyncOptionsFrame = QtGui.QFrame() self.othersyncSettingsLayout = QtGui.QGridLayout() self.dontslowwithmeCheckbox = QCheckBox(getMessage("dontslowdownwithme-label")) self.pauseonleaveCheckbox = QCheckBox(getMessage("pauseonleave-label")) self.othersyncSettingsLayout.addWidget(self.dontslowwithmeCheckbox) self.othersyncSettingsLayout.addWidget(self.pauseonleaveCheckbox) self.dontslowwithmeCheckbox.setObjectName("dontSlowDownWithMe") self.pauseonleaveCheckbox.setObjectName("pauseOnLeave") self.othersyncSettingsGroup.setLayout(self.othersyncSettingsLayout) self.syncSettingsLayout.addWidget(self.othersyncSettingsGroup) self.syncSettingsFrame.setLayout(self.syncSettingsLayout) self.desyncSettingsGroup.setMaximumHeight(self.desyncSettingsGroup.minimumSizeHint().height()) self.syncSettingsLayout.setAlignment(Qt.AlignTop) self.stackedLayout.addWidget(self.syncSettingsFrame) def addMessageTab(self): self.messageFrame = QtGui.QFrame() self.messageLayout = QtGui.QVBoxLayout() # OSD self.osdSettingsGroup = QtGui.QGroupBox("On-screen Display settings") self.osdSettingsLayout = QtGui.QVBoxLayout() self.osdSettingsFrame = QtGui.QFrame() self.showOSDCheckbox = QCheckBox(getMessage("showosd-label")) self.showOSDCheckbox.setObjectName("showOSD") self.osdSettingsLayout.addWidget(self.showOSDCheckbox) self.showSameRoomOSDCheckbox = QCheckBox(getMessage("showsameroomosd-label")) self.showSameRoomOSDCheckbox.setObjectName("showSameRoomOSD") self.showSameRoomOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "bullet_black.png")) self.osdSettingsLayout.addWidget(self.showSameRoomOSDCheckbox) self.showDifferentRoomOSDCheckbox = QCheckBox(getMessage("showdifferentroomosd-label")) self.showDifferentRoomOSDCheckbox.setObjectName("showDifferentRoomOSD") self.showDifferentRoomOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "bullet_black.png")) self.osdSettingsLayout.addWidget(self.showDifferentRoomOSDCheckbox) self.slowdownOSDCheckbox = QCheckBox(getMessage("showslowdownosd-label")) self.slowdownOSDCheckbox.setObjectName("showSlowdownOSD") self.slowdownOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "bullet_black.png")) self.osdSettingsLayout.addWidget(self.slowdownOSDCheckbox) self.showOSDWarningsCheckbox = QCheckBox(getMessage("showosdwarnings-label")) self.showOSDWarningsCheckbox.setObjectName("showOSDWarnings") self.showOSDWarningsCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "bullet_black.png")) self.osdSettingsLayout.addWidget(self.showOSDWarningsCheckbox) self.subitems['showOSD'] = ["showSameRoomOSD", "showDifferentRoomOSD", "showSlowdownOSD", "showOSDWarnings"] self.osdSettingsGroup.setLayout(self.osdSettingsLayout) self.osdSettingsLayout.setAlignment(Qt.AlignTop) self.messageLayout.addWidget(self.osdSettingsGroup) # Other display self.displaySettingsGroup = QtGui.QGroupBox("Other display settings") self.displaySettingsLayout = QtGui.QVBoxLayout() self.displaySettingsFrame = QtGui.QFrame() self.showDurationNotificationCheckbox = QCheckBox(getMessage("showdurationnotification-label")) self.showDurationNotificationCheckbox.setObjectName("showDurationNotification") self.displaySettingsLayout.addWidget(self.showDurationNotificationCheckbox) self.showcontactinfoCheckbox = QCheckBox(getMessage("showcontactinfo-label")) self.showcontactinfoCheckbox.setObjectName("showContactInfo") self.displaySettingsLayout.addWidget(self.showcontactinfoCheckbox) self.showButtonLabelsCheckbox = QCheckBox(getMessage("showbuttonlabels-label")) self.showButtonLabelsCheckbox.setObjectName("showButtonLabels") self.displaySettingsLayout.addWidget(self.showButtonLabelsCheckbox) self.showTooltipsCheckbox = QCheckBox(getMessage("showtooltips-label")) self.showTooltipsCheckbox.setObjectName("showTooltips") self.displaySettingsLayout.addWidget(self.showTooltipsCheckbox) self.displaySettingsGroup.setLayout(self.displaySettingsLayout) self.displaySettingsLayout.setAlignment(Qt.AlignTop) self.messageLayout.addWidget(self.displaySettingsGroup) # messageFrame self.messageFrame.setLayout(self.messageLayout) self.stackedLayout.addWidget(self.messageFrame) def addPrivacyTab(self): self.privacySettingsGroup = QtGui.QGroupBox("Privacy settings") self.privacySettingsLayout = QtGui.QVBoxLayout() self.privacySettingsFrame = QtGui.QFrame() self.privacyFrame = QtGui.QFrame() self.privacyLayout = QtGui.QGridLayout() self.filenameprivacyLabel = QLabel(getMessage("filename-privacy-label"), self) self.filenameprivacyButtonGroup = QButtonGroup() self.filenameprivacySendRawOption = QRadioButton(getMessage("privacy-sendraw-option")) self.filenameprivacySendHashedOption = QRadioButton(getMessage("privacy-sendhashed-option")) self.filenameprivacyDontSendOption = QRadioButton(getMessage("privacy-dontsend-option")) self.filenameprivacyButtonGroup.addButton(self.filenameprivacySendRawOption) self.filenameprivacyButtonGroup.addButton(self.filenameprivacySendHashedOption) self.filenameprivacyButtonGroup.addButton(self.filenameprivacyDontSendOption) self.filesizeprivacyLabel = QLabel(getMessage("filesize-privacy-label"), self) self.filesizeprivacyButtonGroup = QButtonGroup() self.filesizeprivacySendRawOption = QRadioButton(getMessage("privacy-sendraw-option")) self.filesizeprivacySendHashedOption = QRadioButton(getMessage("privacy-sendhashed-option")) self.filesizeprivacyDontSendOption = QRadioButton(getMessage("privacy-dontsend-option")) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacySendRawOption) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacySendHashedOption) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacyDontSendOption) self.filenameprivacyLabel.setObjectName("filename-privacy") self.filenameprivacySendRawOption.setObjectName("privacy-sendraw" + constants.CONFIG_NAME_MARKER + "filenamePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_SENDRAW_MODE) self.filenameprivacySendHashedOption.setObjectName("privacy-sendhashed" + constants.CONFIG_NAME_MARKER + "filenamePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_SENDHASHED_MODE) self.filenameprivacyDontSendOption.setObjectName("privacy-dontsend" + constants.CONFIG_NAME_MARKER + "filenamePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_DONTSEND_MODE) self.filesizeprivacyLabel.setObjectName("filesize-privacy") self.filesizeprivacySendRawOption.setObjectName("privacy-sendraw" + constants.CONFIG_NAME_MARKER + "filesizePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_SENDRAW_MODE) self.filesizeprivacySendHashedOption.setObjectName("privacy-sendhashed" + constants.CONFIG_NAME_MARKER + "filesizePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_SENDHASHED_MODE) self.filesizeprivacyDontSendOption.setObjectName("privacy-dontsend" + constants.CONFIG_NAME_MARKER + "filesizePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_DONTSEND_MODE) self.privacyLayout.addWidget(self.filenameprivacyLabel, 1, 0) self.privacyLayout.addWidget(self.filenameprivacySendRawOption, 1, 1, Qt.AlignLeft) self.privacyLayout.addWidget(self.filenameprivacySendHashedOption, 1, 2, Qt.AlignLeft) self.privacyLayout.addWidget(self.filenameprivacyDontSendOption, 1, 3, Qt.AlignLeft) self.privacyLayout.addWidget(self.filesizeprivacyLabel, 2, 0) self.privacyLayout.addWidget(self.filesizeprivacySendRawOption, 2, 1, Qt.AlignLeft) self.privacyLayout.addWidget(self.filesizeprivacySendHashedOption, 2, 2, Qt.AlignLeft) self.privacyLayout.addWidget(self.filesizeprivacyDontSendOption, 2, 3, Qt.AlignLeft) self.privacyFrame.setLayout(self.privacyLayout) self.privacySettingsGroup.setLayout(self.privacyLayout) self.privacySettingsGroup.setMaximumHeight(self.privacySettingsGroup.minimumSizeHint().height()) self.privacySettingsLayout.addWidget(self.privacySettingsGroup) self.privacySettingsLayout.setAlignment(Qt.AlignTop) self.privacyFrame.setLayout(self.privacySettingsLayout) self.stackedLayout.addWidget(self.privacyFrame) def addBottomLayout(self): config = self.config resourcespath = self.resourcespath self.bottomButtonFrame = QtGui.QFrame() self.bottomButtonLayout = QtGui.QHBoxLayout() self.helpButton = QtGui.QPushButton(QtGui.QIcon(self.resourcespath + 'help.png'), getMessage("help-label")) self.helpButton.setObjectName("help") self.helpButton.setMaximumSize(self.helpButton.sizeHint()) self.helpButton.pressed.connect(self.openHelp) self.resetButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'cog_delete.png'),getMessage("reset-label")) self.resetButton.setMaximumSize(self.resetButton.sizeHint()) self.resetButton.setObjectName("reset") self.resetButton.pressed.connect(self.resetSettings) self.runButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'accept.png'), getMessage("storeandrun-label")) self.runButton.pressed.connect(self._saveDataAndLeave) self.bottomButtonLayout.addWidget(self.helpButton) self.bottomButtonLayout.addWidget(self.resetButton) self.bottomButtonLayout.addWidget(self.runButton) self.bottomButtonFrame.setLayout(self.bottomButtonLayout) if config['noStore'] == True: self.runButton.setText(getMessage("run-label")) self.bottomButtonLayout.setContentsMargins(5,0,5,0) self.mainLayout.addWidget(self.bottomButtonFrame, 1, 0, 1, 2) self.bottomCheckboxFrame = QtGui.QFrame() self.bottomCheckboxFrame.setContentsMargins(0,0,0,0) self.bottomCheckboxLayout = QtGui.QGridLayout() self.alwaysshowCheckbox = QCheckBox(getMessage("forceguiprompt-label")) self.nostoreCheckbox = QCheckBox(getMessage("nostore-label")) self.bottomCheckboxLayout.addWidget(self.showmoreCheckbox) self.bottomCheckboxLayout.addWidget(self.alwaysshowCheckbox, 0, 1, Qt.AlignLeft) self.bottomCheckboxLayout.addWidget(self.nostoreCheckbox, 0, 2, Qt.AlignRight) self.alwaysshowCheckbox.setObjectName(constants.INVERTED_STATE_MARKER + "forceGuiPrompt") self.nostoreCheckbox.setObjectName("noStore") self.nostoreCheckbox.toggled.connect(self.runButtonTextUpdate) self.bottomCheckboxFrame.setLayout(self.bottomCheckboxLayout) self.mainLayout.addWidget(self.bottomCheckboxFrame, 2, 0, 1, 2) def tabList(self): self.tabListLayout = QtGui.QHBoxLayout() self.tabListFrame = QtGui.QFrame() self.tabListWidget = QtGui.QListWidget() self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + "house.png"),getMessage("basics-label"))) self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + "film_link.png"),getMessage("sync-label"))) self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + "comments.png"),getMessage("messages-label"))) self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + "eye.png"),getMessage("privacy-label"))) self.tabListLayout.addWidget(self.tabListWidget) self.tabListFrame.setLayout(self.tabListLayout) self.tabListFrame.setFixedWidth(self.tabListFrame.minimumSizeHint().width()) self.tabListWidget.setStyleSheet(constants.STYLE_TABLIST) self.tabListWidget.currentItemChanged.connect(self.tabChange) self.tabListWidget.itemClicked.connect(self.tabChange) self.tabListWidget.itemPressed.connect(self.tabChange) self.mainLayout.addWidget(self.tabListFrame, 0, 0, 1, 1) def ensureTabListIsVisible(self): self.stackedFrame.setFixedWidth(self.stackedFrame.width()) while self.tabListWidget.horizontalScrollBar().isVisible() and self.tabListFrame.width() < 200: self.tabListFrame.setFixedWidth(self.tabListFrame.width()+1) def tabChange(self): self.setFocus() self.stackedLayout.setCurrentIndex(self.tabListWidget.currentRow()) def resetSettings(self): self.clearGUIData(leaveMore=True) self.config['resetConfig'] = True self.pressedclosebutton = True self.close() def showEvent(self, *args, **kwargs): self.ensureTabListIsVisible() self.setFixedWidth(self.minimumSizeHint().width()) self.executablepathCombobox.setFixedWidth(self.mediapathTextbox.width()) def clearGUIData(self, leaveMore=False): settings = QSettings("Syncplay", "PlayerList") settings.clear() settings = QSettings("Syncplay", "MediaBrowseDialog") settings.clear() settings = QSettings("Syncplay", "MainWindow") settings.clear() if not leaveMore: settings = QSettings("Syncplay", "MoreSettings") settings.clear() self.datacleared = True def __init__(self, config, playerpaths, error, defaultConfig): from syncplay import utils self.config = config self.defaultConfig = defaultConfig self.playerpaths = playerpaths self.datacleared = False self.config['resetConfig'] = False self.subitems = {} if self.config['clearGUIData'] == True: self.config['clearGUIData'] = False self.clearGUIData() self.QtGui = QtGui self.error = error if sys.platform.startswith('win'): resourcespath = utils.findWorkingDir() + "\\resources\\" else: resourcespath = utils.findWorkingDir() + "/resources/" self.posixresourcespath = utils.findWorkingDir().replace("\\","/") + "/resources/" self.resourcespath = resourcespath super(ConfigDialog, self).__init__() self.setWindowTitle(getMessage("config-window-title")) self.setWindowFlags(self.windowFlags() & Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) self.setWindowIcon(QtGui.QIcon(resourcespath + "syncplay.png")) self.stackedLayout = QtGui.QStackedLayout() self.stackedFrame = QtGui.QFrame() self.stackedFrame.setLayout(self.stackedLayout) self.mainLayout = QtGui.QGridLayout() self.mainLayout.setSpacing(0) self.mainLayout.setContentsMargins(0,0,0,0) self.addBasicTab() self.addSyncTab() self.addMessageTab() self.addPrivacyTab() self.tabList() self.mainLayout.addWidget(self.stackedFrame, 0, 1) self.addBottomLayout() if self.getMoreState() == False: self.tabListFrame.hide() self.nostoreCheckbox.hide() self.alwaysshowCheckbox.hide() self.resetButton.hide() else: self.showmoreCheckbox.setChecked(True) self.tabListWidget.setCurrentRow(0) self.showmoreCheckbox.toggled.connect(self.moreToggled) self.setLayout(self.mainLayout) self.runButton.setFocus() self.setFixedSize(self.sizeHint()) self.setAcceptDrops(True) if constants.SHOW_TOOLTIPS: self.processWidget(self, lambda w: self.loadTooltips(w)) self.processWidget(self, lambda w: self.loadValues(w)) self.processWidget(self, lambda w: self.connectChildren(w))
class VideoSwitcher(QWidget): def __init__(self, controller, mainWindow): super(VideoSwitcher, self).__init__() self.controller = controller self.mainWindow = mainWindow self.setupUi() def setupUi(self): gridlayout = QGridLayout() self.setLayout(gridlayout) ''' Buttons added to inputs should have a numeric ID set equal to their input number on the Aldates main switcher. ''' self.inputs = QButtonGroup() inputsGrid = QHBoxLayout() self.btnCamera1 = CameraSelectionButton() self.btnCamera1.setText("Camera 1") inputsGrid.addWidget(self.btnCamera1) self.inputs.addButton(self.btnCamera1, 1) self.btnCamera1.setIcon(QIcon("icons/camera-video.svg")) self.btnCamera1.longpress.connect(lambda: self.showCameraAdvanced("Camera 1")) self.btnCamera2 = CameraSelectionButton() self.btnCamera2.setText("Camera 2") inputsGrid.addWidget(self.btnCamera2) self.inputs.addButton(self.btnCamera2, 2) self.btnCamera2.setIcon(QIcon("icons/camera-video.svg")) self.btnCamera2.longpress.connect(lambda: self.showCameraAdvanced("Camera 2")) self.btnCamera3 = CameraSelectionButton() self.btnCamera3.setText("Camera 3") inputsGrid.addWidget(self.btnCamera3) self.inputs.addButton(self.btnCamera3, 3) self.btnCamera3.setIcon(QIcon("icons/camera-video.svg")) self.btnCamera3.longpress.connect(lambda: self.showCameraAdvanced("Camera 3")) self.btnDVD = InputButton() self.btnDVD.setText("DVD") inputsGrid.addWidget(self.btnDVD) self.inputs.addButton(self.btnDVD, 4) self.btnDVD.setIcon(QIcon("icons/media-optical.svg")) self.btnExtras = InputButton() self.btnExtras.setText("Extras") inputsGrid.addWidget(self.btnExtras) self.btnExtras.setIcon(QIcon("icons/video-display.svg")) self.inputs.addButton(self.btnExtras, 5) self.btnVisualsPC = InputButton() self.btnVisualsPC.setText("Visuals PC") inputsGrid.addWidget(self.btnVisualsPC) self.inputs.addButton(self.btnVisualsPC, 6) self.btnVisualsPC.setIcon(QIcon("icons/computer.svg")) self.btnBlank = InputButton() self.btnBlank.setText("Blank") inputsGrid.addWidget(self.btnBlank) self.inputs.addButton(self.btnBlank, 0) gridlayout.addLayout(inputsGrid, 0, 0, 1, 7) self.extrasSwitcher = ExtrasSwitcher(self.controller) self.blank = QWidget(self) gridlayout.addWidget(self.blank, 1, 0, 1, 5) self.outputsGrid = OutputsGrid() gridlayout.addWidget(self.outputsGrid, 1, 5, 1, 2) gridlayout.setRowStretch(0, 1) gridlayout.setRowStretch(1, 5) QMetaObject.connectSlotsByName(self) self.setInputClickHandlers() self.setOutputClickHandlers(self.outputsGrid) self.configureInnerControlPanels() self.gridlayout = gridlayout def configureInnerControlPanels(self): self.panels = [ QWidget(), # Blank CameraControl(self.controller, "Camera 1") if self.controller.hasDevice("Camera 1") else QLabel(StringConstants.noDevice), CameraControl(self.controller, "Camera 2") if self.controller.hasDevice("Camera 2") else QLabel(StringConstants.noDevice), CameraControl(self.controller, "Camera 3") if self.controller.hasDevice("Camera 3") else QLabel(StringConstants.noDevice), QLabel(StringConstants.noDevice), # DVD - no controls self.extrasSwitcher if self.controller.hasDevice("Extras") else QLabel(StringConstants.noDevice), # Extras EclipseControls(self.controller, "Main Scan Converter") if self.controller.hasDevice("Main Scan Converter") else QLabel(StringConstants.noDevice), # Visuals PC ] def setInputClickHandlers(self): self.btnCamera1.clicked.connect(self.handleInputSelect) self.btnCamera2.clicked.connect(self.handleInputSelect) self.btnCamera3.clicked.connect(self.handleInputSelect) self.btnDVD.clicked.connect(self.handleInputSelect) self.btnExtras.clicked.connect(self.handleInputSelect) self.btnVisualsPC.clicked.connect(self.handleInputSelect) self.btnBlank.clicked.connect(self.handleInputSelect) def setOutputClickHandlers(self, outputsGrid): outputsGrid.connectMainOutputs(self.handleOutputSelect) ''' btnPCMix is a special case since that's on a different switcher ''' outputsGrid.connectPreviewOutputs(self.handlePCMixSelect) def keyPressEvent(self, e): if e.key() == Qt.Key_0: self.btnBlank.click() elif e.key() == Qt.Key_1: self.btnCamera1.click() elif e.key() == Qt.Key_2: self.btnCamera2.click() elif e.key() == Qt.Key_3: self.btnCamera3.click() elif e.key() == Qt.Key_4: self.btnDVD.click() elif e.key() == Qt.Key_5: self.btnExtras.click() elif e.key() == Qt.Key_6: self.btnVisualsPC.click() elif e.key() == Qt.Key_Space: self.outputsGrid.btnAll.click() else: self.panels[self.inputs.checkedId()].keyPressEvent(e) def keyReleaseEvent(self, e): self.panels[self.inputs.checkedId()].keyReleaseEvent(e) def handleInputSelect(self): inputID = self.inputs.checkedId() logging.debug("Input selected: " + str(inputID)) if inputID > 0: try: # HACK HACK HACK someone wired these up the wrong way around if inputID == 5: self.controller.switch("Preview", 6, 1) elif inputID == 6: self.controller.switch("Preview", 5, 1) else: self.controller.switch("Preview", inputID, 1) except NamingError: self.mainWindow.errorBox(StringConstants.nameErrorText) except ProtocolError: self.mainWindow.errorBox(StringConstants.protocolErrorText) self.gridlayout.removeWidget(self.gridlayout.itemAtPosition(1, 0).widget()) for p in self.panels: p.hide() chosenPanel = self.panels[inputID] self.gridlayout.addWidget(chosenPanel, 1, 0, 1, 5) chosenPanel.show() # Prevent certain options from being selectable if inputID == 6 or inputID == 0: self.outputsGrid.btnPCMix.setEnabled(False) else: self.outputsGrid.btnPCMix.setEnabled(True) def handleOutputSelect(self): outputChannel = self.sender().ID inputChannel = self.inputs.checkedId() if inputChannel == 5: self.extrasSwitcher.take() try: self.controller.switch("Main", inputChannel, outputChannel) except NamingError: self.mainWindow.errorBox(StringConstants.nameErrorText) except ProtocolError: self.mainWindow.errorBox(StringConstants.protocolErrorText) def handlePCMixSelect(self): outputChannel = self.sender().ID inputChannel = self.inputs.checkedId() if outputChannel != 2: raise RuntimeError("This isn't PC Mix...") try: if inputChannel == 5: self.extrasSwitcher.takePreview() # HACK HACK HACK someone wired these up the wrong way self.controller.switch("Preview", 6, outputChannel) elif inputChannel != 6: self.controller.switch("Preview", inputChannel, outputChannel) else: logging.error("Tried to send PC to PC Mix. Bad things would have happened!") except NamingError: self.mainWindow.errorBox(StringConstants.nameErrorText) except ProtocolError: self.mainWindow.errorBox(StringConstants.protocolErrorText) def showCameraAdvanced(self, camDevice): ctls = AdvancedCameraControl(self.controller, camDevice, self.mainWindow) self.mainWindow.showScreen(ctls) def updateOutputMappings(self, mapping): self.outputsGrid.updateOutputMappings(mapping)
class ConfigDialog(QtGui.QDialog): pressedclosebutton = False moreToggling = False def moreToggled(self): if self.moreToggling == False: self.moreToggling = True if self.showmoreCheckbox.isChecked() and self.showmoreCheckbox.isVisible(): self.showmoreCheckbox.setChecked(False) self.moreSettingsGroup.setChecked(True) self.moreSettingsGroup.show() self.showmoreCheckbox.hide() self.saveMoreState(True) else: self.moreSettingsGroup.setChecked(False) self.moreSettingsGroup.hide() self.showmoreCheckbox.show() self.saveMoreState(False) self.moreToggling = False self.adjustSize() self.setFixedSize(self.sizeHint()) def runButtonTextUpdate(self): if (self.donotstoreCheckbox.isChecked()): self.runButton.setText(getMessage("en", "run-label")) else: self.runButton.setText(getMessage("en", "storeandrun-label")) def openHelp(self): self.QtGui.QDesktopServices.openUrl("http://syncplay.pl/guide/client/") def _tryToFillPlayerPath(self, playerpath, playerpathlist): settings = QSettings("Syncplay", "PlayerList") settings.beginGroup("PlayerList") savedPlayers = settings.value("PlayerList", []) if(not isinstance(savedPlayers, list)): savedPlayers = [] playerpathlist = list(set(os.path.normcase(os.path.normpath(path)) for path in set(playerpathlist + savedPlayers))) settings.endGroup() foundpath = "" if playerpath != None and playerpath != "": if not os.path.isfile(playerpath): expandedpath = PlayerFactory().getExpandedPlayerPathByPath(playerpath) if expandedpath != None and os.path.isfile(expandedpath): playerpath = expandedpath if os.path.isfile(playerpath): foundpath = playerpath self.executablepathCombobox.addItem(foundpath) for path in playerpathlist: if(os.path.isfile(path) and os.path.normcase(os.path.normpath(path)) != os.path.normcase(os.path.normpath(foundpath))): self.executablepathCombobox.addItem(path) if foundpath == "": foundpath = path if foundpath != "": settings.beginGroup("PlayerList") playerpathlist.append(os.path.normcase(os.path.normpath(foundpath))) settings.setValue("PlayerList", list(set(os.path.normcase(os.path.normpath(path)) for path in set(playerpathlist)))) settings.endGroup() return(foundpath) def updateExecutableIcon(self): currentplayerpath = unicode(self.executablepathCombobox.currentText()) iconpath = PlayerFactory().getPlayerIconByPath(currentplayerpath) if iconpath != None and iconpath != "": self.executableiconImage.load(self.resourcespath + iconpath) self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(self.executableiconImage)) else: self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage())) def browsePlayerpath(self): options = QtGui.QFileDialog.Options() defaultdirectory = "" browserfilter = "All files (*)" if os.name == 'nt': browserfilter = "Executable files (*.exe);;All files (*)" if "PROGRAMFILES(X86)" in os.environ: defaultdirectory = os.environ["ProgramFiles(x86)"] elif "PROGRAMFILES" in os.environ: defaultdirectory = os.environ["ProgramFiles"] elif "PROGRAMW6432" in os.environ: defaultdirectory = os.environ["ProgramW6432"] elif sys.platform.startswith('linux'): defaultdirectory = "/usr/bin" fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, "Browse for media player executable", defaultdirectory, browserfilter, "", options) if fileName: self.executablepathCombobox.setEditText(os.path.normpath(fileName)) def loadMediaBrowseSettings(self): settings = QSettings("Syncplay", "MediaBrowseDialog") settings.beginGroup("MediaBrowseDialog") self.mediadirectory = settings.value("mediadir", "") settings.endGroup() def saveMediaBrowseSettings(self): settings = QSettings("Syncplay", "MediaBrowseDialog") settings.beginGroup("MediaBrowseDialog") settings.setValue("mediadir", self.mediadirectory) settings.endGroup() def getMoreState(self): settings = QSettings("Syncplay", "MoreSettings") settings.beginGroup("MoreSettings") morestate = unicode.lower(unicode(settings.value("ShowMoreSettings", "false"))) settings.endGroup() if morestate == "true": return(True) else: return(False) def saveMoreState(self, morestate): settings = QSettings("Syncplay", "MoreSettings") settings.beginGroup("MoreSettings") settings.setValue("ShowMoreSettings", morestate) settings.endGroup() def browseMediapath(self): self.loadMediaBrowseSettings() options = QtGui.QFileDialog.Options() if (os.path.isdir(self.mediadirectory)): defaultdirectory = self.mediadirectory elif (os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.MoviesLocation))): defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.MoviesLocation) elif (os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.HomeLocation))): defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.HomeLocation) else: defaultdirectory = "" browserfilter = "All files (*)" fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, "Browse for media files", defaultdirectory, browserfilter, "", options) if fileName: self.mediapathTextbox.setText(os.path.normpath(fileName)) self.mediadirectory = os.path.dirname(fileName) self.saveMediaBrowseSettings() def _saveDataAndLeave(self): self.config['host'] = self.hostTextbox.text() if ":" in self.hostTextbox.text() else self.hostTextbox.text() + ":" + unicode(constants.DEFAULT_PORT) self.config['name'] = self.usernameTextbox.text() self.config['room'] = self.defaultroomTextbox.text() self.config['password'] = self.serverpassTextbox.text() self.config['playerPath'] = unicode(self.executablepathCombobox.currentText()) if self.mediapathTextbox.text() == "": self.config['file'] = None elif os.path.isfile(os.path.abspath(self.mediapathTextbox.text())): self.config['file'] = os.path.abspath(self.mediapathTextbox.text()) else: self.config['file'] = unicode(self.mediapathTextbox.text()) if self.alwaysshowCheckbox.isChecked() == True: self.config['forceGuiPrompt'] = True else: self.config['forceGuiPrompt'] = False if self.donotstoreCheckbox.isChecked() == True: self.config['noStore'] = True else: self.config['noStore'] = False if self.slowdownCheckbox.isChecked() == True: self.config['slowOnDesync'] = True else: self.config['slowOnDesync'] = False if self.dontslowwithmeCheckbox.isChecked() == True: self.config['dontSlowDownWithMe'] = True else: self.config['dontSlowDownWithMe'] = False if self.pauseonleaveCheckbox.isChecked() == True: self.config['pauseOnLeave'] = True else: self.config['pauseOnLeave'] = False if constants.SHOW_REWIND_ON_DESYNC_CHECKBOX == True: if self.rewindCheckbox.isChecked() == True: self.config['rewindOnDesync'] = True else: self.config['rewindOnDesync'] = False if self.filenameprivacySendRawOption.isChecked() == True: self.config['filenamePrivacyMode'] = constants.PRIVACY_SENDRAW_MODE elif self.filenameprivacySendHashedOption.isChecked() == True: self.config['filenamePrivacyMode'] = constants.PRIVACY_SENDHASHED_MODE elif self.filenameprivacyDontSendOption.isChecked() == True: self.config['filenamePrivacyMode'] = constants.PRIVACY_DONTSEND_MODE if self.filesizeprivacySendRawOption.isChecked() == True: self.config['filesizePrivacyMode'] = constants.PRIVACY_SENDRAW_MODE elif self.filesizeprivacySendHashedOption.isChecked() == True: self.config['filesizePrivacyMode'] = constants.PRIVACY_SENDHASHED_MODE elif self.filesizeprivacyDontSendOption.isChecked() == True: self.config['filesizePrivacyMode'] = constants.PRIVACY_DONTSEND_MODE self.pressedclosebutton = True self.close() return def closeEvent(self, event): if self.pressedclosebutton == False: sys.exit() raise GuiConfiguration.WindowClosed event.accept() def dragEnterEvent(self, event): data = event.mimeData() urls = data.urls() if (urls and urls[0].scheme() == 'file'): event.acceptProposedAction() def dropEvent(self, event): data = event.mimeData() urls = data.urls() if (urls and urls[0].scheme() == 'file'): if sys.platform.startswith('linux'): dropfilepath = unicode(urls[0].path()) else: dropfilepath = unicode(urls[0].path())[1:] # Removes starting slash if dropfilepath[-4:].lower() == ".exe": self.executablepathCombobox.setEditText(dropfilepath) else: self.mediapathTextbox.setText(dropfilepath) def __init__(self, config, playerpaths, error): from syncplay import utils self.config = config self.datacleared = False if config['clearGUIData'] == True: settings = QSettings("Syncplay", "PlayerList") settings.clear() settings = QSettings("Syncplay", "MediaBrowseDialog") settings.clear() settings = QSettings("Syncplay", "MainWindow") settings.clear() settings = QSettings("Syncplay", "MoreSettings") settings.clear() self.datacleared = True self.QtGui = QtGui self.error = error if sys.platform.startswith('linux'): resourcespath = utils.findWorkingDir() + "/resources/" else: resourcespath = utils.findWorkingDir() + "\\resources\\" self.resourcespath = resourcespath super(ConfigDialog, self).__init__() self.setWindowTitle(getMessage("en", "config-window-title")) self.setWindowFlags(self.windowFlags() & Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) self.setWindowIcon(QtGui.QIcon(resourcespath + "syncplay.png")) if(config['host'] == None): host = "" elif(":" in config['host']): host = config['host'] else: host = config['host'] + ":" + str(config['port']) self.connectionSettingsGroup = QtGui.QGroupBox(getMessage("en", "connection-group-title")) self.hostTextbox = QLineEdit(host, self) self.hostLabel = QLabel(getMessage("en", "host-label"), self) self.usernameTextbox = QLineEdit(config['name'], self) self.serverpassLabel = QLabel(getMessage("en", "password-label"), self) self.defaultroomTextbox = QLineEdit(config['room'], self) self.usernameLabel = QLabel(getMessage("en", "username-label"), self) self.serverpassTextbox = QLineEdit(config['password'], self) self.defaultroomLabel = QLabel(getMessage("en", "room-label"), self) if (constants.SHOW_TOOLTIPS == True): self.hostLabel.setToolTip(getMessage("en", "host-tooltip")) self.hostTextbox.setToolTip(getMessage("en", "host-tooltip")) self.usernameLabel.setToolTip(getMessage("en", "username-tooltip")) self.usernameTextbox.setToolTip(getMessage("en", "username-tooltip")) self.serverpassLabel.setToolTip(getMessage("en", "password-tooltip")) self.serverpassTextbox.setToolTip(getMessage("en", "password-tooltip")) self.defaultroomLabel.setToolTip(getMessage("en", "room-tooltip")) self.defaultroomTextbox.setToolTip(getMessage("en", "room-tooltip")) self.connectionSettingsLayout = QtGui.QGridLayout() self.connectionSettingsLayout.addWidget(self.hostLabel, 0, 0) self.connectionSettingsLayout.addWidget(self.hostTextbox, 0, 1) self.connectionSettingsLayout.addWidget(self.serverpassLabel, 1, 0) self.connectionSettingsLayout.addWidget(self.serverpassTextbox, 1, 1) self.connectionSettingsLayout.addWidget(self.usernameLabel, 2, 0) self.connectionSettingsLayout.addWidget(self.usernameTextbox, 2, 1) self.connectionSettingsLayout.addWidget(self.defaultroomLabel, 3, 0) self.connectionSettingsLayout.addWidget(self.defaultroomTextbox, 3, 1) self.connectionSettingsGroup.setLayout(self.connectionSettingsLayout) self.mediaplayerSettingsGroup = QtGui.QGroupBox(getMessage("en", "media-setting-title")) self.executableiconImage = QtGui.QImage() self.executableiconLabel = QLabel(self) self.executableiconLabel.setMinimumWidth(16) self.executablepathCombobox = QtGui.QComboBox(self) self.executablepathCombobox.setEditable(True) self.executablepathCombobox.currentIndexChanged.connect(self.updateExecutableIcon) self.executablepathCombobox.setEditText(self._tryToFillPlayerPath(config['playerPath'], playerpaths)) self.executablepathCombobox.setMinimumWidth(200) self.executablepathCombobox.setMaximumWidth(200) self.executablepathCombobox.editTextChanged.connect(self.updateExecutableIcon) self.executablepathLabel = QLabel(getMessage("en", "executable-path-label"), self) self.executablebrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("en", "browse-label")) self.executablebrowseButton.clicked.connect(self.browsePlayerpath) self.mediapathTextbox = QLineEdit(config['file'], self) self.mediapathLabel = QLabel(getMessage("en", "media-path-label"), self) self.mediabrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("en", "browse-label")) self.mediabrowseButton.clicked.connect(self.browseMediapath) if (constants.SHOW_TOOLTIPS == True): self.executablepathLabel.setToolTip(getMessage("en", "executable-path-tooltip")) self.executablepathCombobox.setToolTip(getMessage("en", "executable-path-tooltip")) self.mediapathLabel.setToolTip(getMessage("en", "media-path-tooltip")) self.mediapathTextbox.setToolTip(getMessage("en", "media-path-tooltip")) if constants.SHOW_REWIND_ON_DESYNC_CHECKBOX == True: self.rewindCheckbox = QCheckBox(getMessage("en", "rewind-label")) if (constants.SHOW_TOOLTIPS == True): self.rewindCheckbox.setToolTip(getMessage("en", "rewind-tooltip")) self.mediaplayerSettingsLayout = QtGui.QGridLayout() self.mediaplayerSettingsLayout.addWidget(self.executablepathLabel, 0, 0) self.mediaplayerSettingsLayout.addWidget(self.executableiconLabel, 0, 1) self.mediaplayerSettingsLayout.addWidget(self.executablepathCombobox, 0, 2) self.mediaplayerSettingsLayout.addWidget(self.executablebrowseButton, 0, 3) self.mediaplayerSettingsLayout.addWidget(self.mediapathLabel, 1, 0) self.mediaplayerSettingsLayout.addWidget(self.mediapathTextbox , 1, 2) self.mediaplayerSettingsLayout.addWidget(self.mediabrowseButton , 1, 3) self.mediaplayerSettingsGroup.setLayout(self.mediaplayerSettingsLayout) self.moreSettingsGroup = QtGui.QGroupBox(getMessage("en", "more-title")) self.moreSettingsGroup.setCheckable(True) self.filenameprivacyLabel = QLabel(getMessage("en", "filename-privacy-label"), self) self.filenameprivacyButtonGroup = QButtonGroup() self.filenameprivacySendRawOption = QRadioButton(getMessage("en", "privacy-sendraw-option")) self.filenameprivacySendHashedOption = QRadioButton(getMessage("en", "privacy-sendhashed-option")) self.filenameprivacyDontSendOption = QRadioButton(getMessage("en", "privacy-dontsend-option")) self.filenameprivacyButtonGroup.addButton(self.filenameprivacySendRawOption) self.filenameprivacyButtonGroup.addButton(self.filenameprivacySendHashedOption) self.filenameprivacyButtonGroup.addButton(self.filenameprivacyDontSendOption) self.filesizeprivacyLabel = QLabel(getMessage("en", "filesize-privacy-label"), self) self.filesizeprivacyButtonGroup = QButtonGroup() self.filesizeprivacySendRawOption = QRadioButton(getMessage("en", "privacy-sendraw-option")) self.filesizeprivacySendHashedOption = QRadioButton(getMessage("en", "privacy-sendhashed-option")) self.filesizeprivacyDontSendOption = QRadioButton(getMessage("en", "privacy-dontsend-option")) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacySendRawOption) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacySendHashedOption) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacyDontSendOption) self.slowdownCheckbox = QCheckBox(getMessage("en", "slowdown-label")) self.dontslowwithmeCheckbox = QCheckBox(getMessage("en", "dontslowwithme-label")) self.pauseonleaveCheckbox = QCheckBox(getMessage("en", "pauseonleave-label")) self.alwaysshowCheckbox = QCheckBox(getMessage("en", "alwayshow-label")) self.donotstoreCheckbox = QCheckBox(getMessage("en", "donotstore-label")) filenamePrivacyMode = config['filenamePrivacyMode'] if filenamePrivacyMode == constants.PRIVACY_DONTSEND_MODE: self.filenameprivacyDontSendOption.setChecked(True) elif filenamePrivacyMode == constants.PRIVACY_SENDHASHED_MODE: self.filenameprivacySendHashedOption.setChecked(True) else: self.filenameprivacySendRawOption.setChecked(True) filesizePrivacyMode = config['filesizePrivacyMode'] if filesizePrivacyMode == constants.PRIVACY_DONTSEND_MODE: self.filesizeprivacyDontSendOption.setChecked(True) elif filesizePrivacyMode == constants.PRIVACY_SENDHASHED_MODE: self.filesizeprivacySendHashedOption.setChecked(True) else: self.filesizeprivacySendRawOption.setChecked(True) if config['slowOnDesync'] == True: self.slowdownCheckbox.setChecked(True) if config['dontSlowDownWithMe'] == True: self.dontslowwithmeCheckbox.setChecked(True) if constants.SHOW_REWIND_ON_DESYNC_CHECKBOX == True and config['rewindOnDesync'] == True: self.rewindCheckbox.setChecked(True) if config['pauseOnLeave'] == True: self.pauseonleaveCheckbox.setChecked(True) if (constants.SHOW_TOOLTIPS == True): self.filenameprivacyLabel.setToolTip(getMessage("en", "filename-privacy-tooltip")) self.filenameprivacySendRawOption.setToolTip(getMessage("en", "privacy-sendraw-tooltip")) self.filenameprivacySendHashedOption.setToolTip(getMessage("en", "privacy-sendhashed-tooltip")) self.filenameprivacyDontSendOption.setToolTip(getMessage("en", "privacy-dontsend-tooltip")) self.filesizeprivacyLabel.setToolTip(getMessage("en", "filesize-privacy-tooltip")) self.filesizeprivacySendRawOption.setToolTip(getMessage("en", "privacy-sendraw-tooltip")) self.filesizeprivacySendHashedOption.setToolTip(getMessage("en", "privacy-sendhashed-tooltip")) self.filesizeprivacyDontSendOption.setToolTip(getMessage("en", "privacy-dontsend-tooltip")) self.slowdownCheckbox.setToolTip(getMessage("en", "slowdown-tooltip")) self.dontslowwithmeCheckbox.setToolTip(getMessage("en", "dontslowwithme-tooltip")) self.pauseonleaveCheckbox.setToolTip(getMessage("en", "pauseonleave-tooltip")) self.alwaysshowCheckbox.setToolTip(getMessage("en", "alwayshow-tooltip")) self.donotstoreCheckbox.setToolTip(getMessage("en", "donotstore-tooltip")) self.slowdownCheckbox.setToolTip(getMessage("en", "slowdown-tooltip")) self.moreSettingsLayout = QtGui.QGridLayout() self.privacySettingsLayout = QtGui.QGridLayout() self.privacyFrame = QtGui.QFrame() self.privacyFrame.setLineWidth(0) self.privacyFrame.setMidLineWidth(0) self.privacySettingsLayout.setContentsMargins(0, 0, 0, 0) self.privacySettingsLayout.addWidget(self.filenameprivacyLabel, 0, 0) self.privacySettingsLayout.addWidget(self.filenameprivacySendRawOption, 0, 1, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filenameprivacySendHashedOption, 0, 2, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filenameprivacyDontSendOption, 0, 3, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filesizeprivacyLabel, 1, 0) self.privacySettingsLayout.addWidget(self.filesizeprivacySendRawOption, 1, 1, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filesizeprivacySendHashedOption, 1, 2, Qt.AlignRight) self.privacySettingsLayout.addWidget(self.filesizeprivacyDontSendOption, 1, 3, Qt.AlignRight) self.privacyFrame.setLayout(self.privacySettingsLayout) self.moreSettingsLayout.addWidget(self.privacyFrame, 0, 0, 1, 4) self.moreSettingsLayout.addWidget(self.slowdownCheckbox, 2, 0, 1, 4) self.moreSettingsLayout.addWidget(self.dontslowwithmeCheckbox, 3, 0, 1, 4) if constants.SHOW_REWIND_ON_DESYNC_CHECKBOX == True: self.moreSettingsLayout.addWidget(self.rewindCheckbox, 4, 0, 1, 4) self.moreSettingsLayout.addWidget(self.pauseonleaveCheckbox, 5, 0, 1, 4) self.moreSettingsLayout.addWidget(self.alwaysshowCheckbox, 6, 0, 1, 4) self.moreSettingsLayout.addWidget(self.donotstoreCheckbox, 7, 0, 1, 4) self.moreSettingsGroup.setLayout(self.moreSettingsLayout) self.showmoreCheckbox = QCheckBox(getMessage("en", "more-title")) if self.getMoreState() == False: self.showmoreCheckbox.setChecked(False) self.moreSettingsGroup.hide() else: self.showmoreCheckbox.hide() self.showmoreCheckbox.toggled.connect(self.moreToggled) self.moreSettingsGroup.toggled.connect(self.moreToggled) if config['forceGuiPrompt'] == True: self.alwaysshowCheckbox.setChecked(True) if (constants.SHOW_TOOLTIPS == True): self.showmoreCheckbox.setToolTip(getMessage("en", "more-tooltip")) self.donotstoreCheckbox.toggled.connect(self.runButtonTextUpdate) self.mainLayout = QtGui.QVBoxLayout() if error: self.errorLabel = QLabel(error, self) self.errorLabel.setAlignment(Qt.AlignCenter) self.errorLabel.setStyleSheet("QLabel { color : red; }") self.mainLayout.addWidget(self.errorLabel) self.mainLayout.addWidget(self.connectionSettingsGroup) self.mainLayout.addSpacing(12) self.mainLayout.addWidget(self.mediaplayerSettingsGroup) self.mainLayout.addSpacing(12) self.mainLayout.addWidget(self.showmoreCheckbox) self.mainLayout.addWidget(self.moreSettingsGroup) self.mainLayout.addSpacing(12) self.topLayout = QtGui.QHBoxLayout() self.helpButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'help.png'), getMessage("en", "help-label")) if (constants.SHOW_TOOLTIPS == True): self.helpButton.setToolTip(getMessage("en", "help-tooltip")) self.helpButton.setMaximumSize(self.helpButton.sizeHint()) self.helpButton.pressed.connect(self.openHelp) self.runButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'accept.png'), getMessage("en", "storeandrun-label")) self.runButton.pressed.connect(self._saveDataAndLeave) if config['noStore'] == True: self.donotstoreCheckbox.setChecked(True) self.runButton.setText(getMessage("en", "run-label")) self.topLayout.addWidget(self.helpButton, Qt.AlignLeft) self.topLayout.addWidget(self.runButton, Qt.AlignRight) self.mainLayout.addLayout(self.topLayout) self.mainLayout.addStretch(1) self.setLayout(self.mainLayout) self.runButton.setFocus() self.setFixedSize(self.sizeHint()) self.setAcceptDrops(True) if self.datacleared == True: QtGui.QMessageBox.information(self, "Syncplay", getMessage("en", "gui-data-cleared-notification"))
class BlindsControl(ScreenWithBackButton): ''' Controls for the blinds. ''' def __init__(self, blindsDevice, mainWindow): self.blindsDevice = blindsDevice ScreenWithBackButton.__init__(self, "Blinds", mainWindow) def makeContent(self): layout = QGridLayout() self.blinds = QButtonGroup() for i in range(1, 7): btn = IDedButton(i) btn.setText(str(i)) layout.addWidget(btn, 0, i - 1) btn.setCheckable(True) self.blinds.addButton(btn, i) btnAll = IDedButton(0) btnAll.setText("All") layout.addWidget(btnAll, 0, 6) btnAll.setCheckable(True) btnAll.setChecked(True) self.blinds.addButton(btnAll, 0) btnRaise = SvgButton(":icons/go-up", 96, 96) btnRaise.setText("Raise") btnRaise.setToolButtonStyle( Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnRaise, 1, 1, 1, 3) btnRaise.clicked.connect(self.raiseUp) btnLower = SvgButton(":icons/go-down", 96, 96) btnLower.setText("Lower") btnLower.setToolButtonStyle( Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnLower, 2, 1, 1, 3) btnLower.clicked.connect(self.lowerDown) btnStop = SvgButton(":icons/process-stop", 96, 96) btnStop.setText("Stop") btnStop.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon) layout.addWidget(btnStop, 1, 4, 2, 2) btnStop.clicked.connect(self.stop) return layout @handlePyroErrors def raiseUp(self): blindID = self.blinds.checkedId() self.blindsDevice.raiseUp(blindID) @handlePyroErrors def lowerDown(self): blindID = self.blinds.checkedId() self.blindsDevice.lower(blindID) @handlePyroErrors def stop(self): blindID = self.blinds.checkedId() self.blindsDevice.stop(blindID)
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(810, 492) lbMinWidth = 65 lbMinWidthLogin = 110 # leMinWidth = 200 # self.centralwidget = QWidget(MainWindow) self.mainSplitter = QSplitter(Qt.Horizontal, MainWindow) self.mainSplitter.setObjectName("centralwidget") self.mainSplitter.setProperty("childrenCollapsible", False) MainWindow.setCentralWidget(self.mainSplitter) self.leftSplitter = QSplitter(Qt.Vertical, self.mainSplitter) self.leftSplitter.setProperty("childrenCollapsible", False) # login_gbox self.login_gbox = QGroupBox(self.leftSplitter) self.login_gbox.setFlat(True) self.login_gbox.setObjectName("login_gbox") login_gbox_layout = QVBoxLayout(self.login_gbox) login_gbox_presets_layout = QHBoxLayout() login_gbox_server_layout = QHBoxLayout() login_gbox_ssl_layout = QHBoxLayout() login_gbox_address_layout = QHBoxLayout() login_gbox_pass_layout = QHBoxLayout() login_gbox_connect_layout = QHBoxLayout() login_gbox_layout.addLayout(login_gbox_presets_layout) login_gbox_layout.addLayout(login_gbox_server_layout) login_gbox_layout.addLayout(login_gbox_ssl_layout) login_gbox_layout.addLayout(login_gbox_address_layout) login_gbox_layout.addLayout(login_gbox_pass_layout) login_gbox_layout.addLayout(login_gbox_connect_layout) self.lb_presets = QLabel(self.login_gbox) self.lb_presets.setObjectName("lb_presets") self.lb_presets.setMinimumWidth(lbMinWidthLogin) self.lb_presets.setMaximumWidth(lbMinWidthLogin) self.presets_cbox = QComboBox(self.login_gbox) self.presets_cbox.setObjectName("presets_cbox") self.add_preset_btn = QPushButton(self.login_gbox) self.add_preset_btn.setObjectName("add_preset_btn") self.add_preset_btn.setMaximumWidth(30) self.remove_preset_btn = QPushButton(self.login_gbox) self.remove_preset_btn.setObjectName("remove_preset_btn") self.remove_preset_btn.setMaximumWidth(20) login_gbox_presets_layout.addWidget(self.lb_presets) login_gbox_presets_layout.addWidget(self.presets_cbox) login_gbox_presets_layout.addWidget(self.add_preset_btn) login_gbox_presets_layout.addWidget(self.remove_preset_btn) self.lb_imap_server = QLabel(self.login_gbox) self.lb_imap_server.setObjectName("lb_imap_server") self.lb_imap_server.setMinimumWidth(lbMinWidthLogin) self.imap_server_le = QLineEdit(self.login_gbox) self.imap_server_le.setObjectName("imap_server_le") login_gbox_server_layout.addWidget(self.lb_imap_server) login_gbox_server_layout.addWidget(self.imap_server_le) self.lb_ssl = QLabel(self.login_gbox) self.lb_ssl.setObjectName("lb_ssl") self.lb_ssl.setMinimumWidth(lbMinWidthLogin) self.lb_ssl.setMaximumWidth(lbMinWidthLogin) self.ssl_cb = QCheckBox(self.login_gbox) self.ssl_cb.setEnabled(False) self.ssl_cb.setCheckable(True) self.ssl_cb.setChecked(True) self.ssl_cb.setObjectName("ssl_cb") login_gbox_ssl_layout.addWidget(self.lb_ssl) login_gbox_ssl_layout.addWidget(self.ssl_cb) self.lb_adress = QLabel(self.login_gbox) self.lb_adress.setObjectName("lb_adress") self.lb_adress.setMinimumWidth(lbMinWidthLogin) self.adress_le = QLineEdit(self.login_gbox) self.adress_le.setInputMethodHints(Qt.ImhNone) self.adress_le.setObjectName("adress_le") login_gbox_address_layout.addWidget(self.lb_adress) login_gbox_address_layout.addWidget(self.adress_le) self.lb_pass = QLabel(self.login_gbox) self.lb_pass.setObjectName("lb_pass") self.lb_pass.setMinimumWidth(lbMinWidthLogin) self.pass_le = QLineEdit(self.login_gbox) self.pass_le.setText("") self.pass_le.setEchoMode(QLineEdit.Password) self.pass_le.setObjectName("pass_le") login_gbox_pass_layout.addWidget(self.lb_pass) login_gbox_pass_layout.addWidget(self.pass_le) self.connect_btn = QPushButton(self.login_gbox) self.connect_btn.setObjectName("connect_btn") login_gbox_connect_layout.addStretch() login_gbox_connect_layout.addWidget(self.connect_btn) # search_gbox self.search_gbox = QGroupBox(self.leftSplitter) self.search_gbox.hide() self.search_gbox.setObjectName("search_gbox") search_gbox_layout = QVBoxLayout(self.search_gbox) search_gbox_mailbox_layout = QVBoxLayout() search_gbox_date_layout = QHBoxLayout() search_gbox_from_layout = QHBoxLayout() search_gbox_to_layout = QHBoxLayout() search_gbox_subject_layout = QHBoxLayout() search_gbox_threads_layout = QHBoxLayout() search_gbox_paramaters_layout = QHBoxLayout() search_gbox_layout.addLayout(search_gbox_mailbox_layout) search_gbox_layout.addLayout(search_gbox_date_layout) search_gbox_layout.addLayout(search_gbox_from_layout) search_gbox_layout.addLayout(search_gbox_to_layout) search_gbox_layout.addLayout(search_gbox_subject_layout) search_gbox_layout.addLayout(search_gbox_threads_layout) search_gbox_layout.addLayout(search_gbox_paramaters_layout) self.lb_select_mailbox = QLabel(self.search_gbox) self.lb_select_mailbox.setObjectName("lb_select_mailbox") self.mailboxes_lw = QListWidget(self.search_gbox) self.mailboxes_lw.setEditTriggers(QAbstractItemView.NoEditTriggers) self.mailboxes_lw.setSelectionMode(QAbstractItemView.ExtendedSelection) self.mailboxes_lw.setObjectName("mailboxes_lw") search_gbox_mailbox_layout.addWidget(self.lb_select_mailbox) search_gbox_mailbox_layout.addWidget(self.mailboxes_lw) self.since_date_cb = QCheckBox(self.search_gbox) self.since_date_cb.setObjectName("since_date_cb") self.since_date_cb.setMinimumWidth(lbMinWidth) self.since_date_cb.setMaximumWidth(lbMinWidth) self.since_date_edit = QDateEdit(self.search_gbox) self.since_date_edit.setCalendarPopup(True) self.since_date_edit.setObjectName("since_date_edit") self.since_date_edit.setDate(QDate.currentDate().addDays(-365)) self.since_date_edit.setMaximumDate(QDate.currentDate()) self.since_date_edit.setEnabled(False) self.before_date_cb = QCheckBox(self.search_gbox) self.before_date_cb.setObjectName("before_date_cb") self.before_date_cb.setMinimumWidth(70) self.before_date_cb.setMaximumWidth(70) self.before_date_edit = QDateEdit(self.search_gbox) self.before_date_edit.setCalendarPopup(True) self.before_date_edit.setObjectName("before_date_edit") self.before_date_edit.setDate(QDate.currentDate()) self.before_date_edit.setMaximumDate(QDate.currentDate()) self.before_date_edit.setEnabled(False) search_gbox_date_layout.addWidget(self.since_date_cb) search_gbox_date_layout.addWidget(self.since_date_edit) search_gbox_date_layout.addWidget(self.before_date_cb) search_gbox_date_layout.addWidget(self.before_date_edit) self.lb_from = QLabel(self.search_gbox) self.lb_from.setObjectName("lb_from") self.lb_from.setMinimumWidth(lbMinWidth) self.from_le = QLineEdit(self.search_gbox) self.from_le.setObjectName("from_le") search_gbox_from_layout.addWidget(self.lb_from) search_gbox_from_layout.addWidget(self.from_le) self.lb_to = QLabel(self.search_gbox) self.lb_to.setObjectName("lb_to") self.lb_to.setMinimumWidth(lbMinWidth) self.to_le = QLineEdit(self.search_gbox) self.to_le.setObjectName("to_le") search_gbox_to_layout.addWidget(self.lb_to) search_gbox_to_layout.addWidget(self.to_le) self.lb_subject = QLabel(self.search_gbox) self.lb_subject.setObjectName("lb_subject") self.lb_subject.setMinimumWidth(lbMinWidth) self.subject_le = QLineEdit(self.search_gbox) self.subject_le.setObjectName("subject_le") search_gbox_subject_layout.addWidget(self.lb_subject) search_gbox_subject_layout.addWidget(self.subject_le) # self.lb_threads = QLabel(self.search_gbox) # self.lb_threads.setObjectName("lb_threads") # self.lb_threads.setMaximumWidth(lbMinWidth) # self.thread_count_sb = QSpinBox(self.search_gbox) # self.thread_count_sb.setMinimum(1) # self.thread_count_sb.setMaximum(10) # self.thread_count_sb.setObjectName("thread_count_sb") self.html_radio = QRadioButton(self.search_gbox) self.html_radio.setObjectName("html_radio") self.text_radio = QRadioButton(self.search_gbox) self.text_radio.setObjectName("text_radio") self.extactTypeButtonGroup = QButtonGroup(self) self.extactTypeButtonGroup.addButton(self.html_radio) self.extactTypeButtonGroup.addButton(self.text_radio) self.html_radio.setChecked(True) self.search_btn = QPushButton(self.search_gbox) self.search_btn.setObjectName("search_btn") # search_gbox_threads_layout.addWidget(self.lb_threads) # search_gbox_threads_layout.addWidget(self.thread_count_sb) search_gbox_threads_layout.addStretch() search_gbox_threads_layout.addWidget(self.html_radio) search_gbox_threads_layout.addWidget(self.text_radio) # search_gbox_threads_layout.addStretch() search_gbox_threads_layout.addWidget(self.search_btn) self.parameters_cb = QCheckBox(self.search_gbox) self.parameters_cb.setText("") self.parameters_cb.setObjectName("parameters_cb") self.parameters_le = QLineEdit(self.search_gbox) self.parameters_le.setEnabled(False) self.parameters_le.setObjectName("parameters_le") search_gbox_paramaters_layout.addWidget(self.parameters_cb) search_gbox_paramaters_layout.addWidget(self.parameters_le) # log_gbox self.log_gbox = QGroupBox(self.leftSplitter) self.log_gbox.setFlat(True) self.log_gbox.setObjectName("log_gbox") log_layout = QVBoxLayout(self.log_gbox) self.log_te = QTextEdit(self.log_gbox) self.log_te.setLineWrapMode(QTextEdit.NoWrap) self.log_te.setReadOnly(True) self.log_te.setTextInteractionFlags(Qt.TextSelectableByKeyboard | Qt.TextSelectableByMouse) self.log_te.setObjectName("log_te") self.disconnect_btn = QPushButton(self.log_gbox) self.disconnect_btn.setObjectName("disconnect_btn") self.disconnect_btn.hide() log_layout.addWidget(self.log_te) log_layout_btn = QHBoxLayout() log_layout.addLayout(log_layout_btn) log_layout_btn.addWidget(self.disconnect_btn) log_layout_btn.addStretch() # links_gbox self.links_gbox = QGroupBox(self.mainSplitter) self.links_gbox.setFlat(True) self.links_gbox.setObjectName("links_gbox") links_gbox_layout = QVBoxLayout(self.links_gbox) links_gbox_links_layout = QVBoxLayout() links_gbox_buttons_layout = QHBoxLayout() links_gbox_layout.addLayout(links_gbox_links_layout) links_gbox_layout.addLayout(links_gbox_buttons_layout) self.links_text_edit = QTextEdit(self.links_gbox) self.links_text_edit.setObjectName("links_text_edit") links_gbox_links_layout.addWidget(self.links_text_edit) self.export_txt_btn = QPushButton(self.links_gbox) self.export_txt_btn.setObjectName("export_txt_btn") self.export_txt_btn.setEnabled(False) self.export_html_btn = QPushButton(self.links_gbox) self.export_html_btn.setObjectName("export_html_btn") self.export_html_btn.setEnabled(False) links_gbox_buttons_layout.addWidget(self.export_txt_btn) links_gbox_buttons_layout.addWidget(self.export_html_btn) # menubar self.menubar = QMenuBar(MainWindow) self.menubar.setObjectName("menubar") self.menu_file = QMenu(self.menubar) self.menu_file.setObjectName("menu_file") self.menu_about = QMenu(self.menubar) self.menu_about.setObjectName("menu_about") MainWindow.setMenuBar(self.menubar) self.action_about = QAction(MainWindow) self.action_about.setObjectName("action_about") self.action_About_Qt = QAction(MainWindow) self.action_About_Qt.setObjectName("action_About_Qt") self.action_exit = QAction(MainWindow) self.action_exit.setObjectName("action_exit") self.actionSave = QAction(MainWindow) self.actionSave.setObjectName("actionSave") self.menu_file.addAction(self.action_exit) self.menu_about.addAction(self.action_about) self.menu_about.addAction(self.action_About_Qt) self.menubar.addAction(self.menu_file.menuAction()) self.menubar.addAction(self.menu_about.menuAction()) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) MainWindow.setTabOrder(self.presets_cbox, self.imap_server_le) MainWindow.setTabOrder(self.imap_server_le, self.adress_le) MainWindow.setTabOrder(self.adress_le, self.pass_le) MainWindow.setTabOrder(self.pass_le, self.connect_btn) MainWindow.setTabOrder(self.connect_btn, self.log_te) MainWindow.setTabOrder(self.log_te, self.since_date_cb) MainWindow.setTabOrder(self.since_date_cb, self.since_date_edit) MainWindow.setTabOrder(self.since_date_edit, self.before_date_cb) MainWindow.setTabOrder(self.before_date_cb, self.before_date_edit) MainWindow.setTabOrder(self.before_date_edit, self.mailboxes_lw) MainWindow.setTabOrder(self.mailboxes_lw, self.from_le) MainWindow.setTabOrder(self.from_le, self.to_le) MainWindow.setTabOrder(self.to_le, self.subject_le) MainWindow.setTabOrder(self.subject_le, self.search_btn) MainWindow.setTabOrder(self.search_btn, self.links_text_edit) MainWindow.setTabOrder(self.links_text_edit, self.export_txt_btn) MainWindow.setTabOrder(self.export_txt_btn, self.export_html_btn) MainWindow.setTabOrder(self.export_html_btn, self.disconnect_btn) MainWindow.setTabOrder(self.disconnect_btn, self.add_preset_btn) MainWindow.setTabOrder(self.add_preset_btn, self.remove_preset_btn) MainWindow.setTabOrder(self.remove_preset_btn, self.ssl_cb) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QApplication.translate("MainWindow", "Email Link Extractor", None, QApplication.UnicodeUTF8)) self.login_gbox.setTitle(QApplication.translate("MainWindow", " Login", None, QApplication.UnicodeUTF8)) self.lb_presets.setText(QApplication.translate("MainWindow", "Server Presets", None, QApplication.UnicodeUTF8)) self.add_preset_btn.setText(QApplication.translate("MainWindow", "+", None, QApplication.UnicodeUTF8)) self.remove_preset_btn.setText(QApplication.translate("MainWindow", "-", None, QApplication.UnicodeUTF8)) self.lb_imap_server.setText(QApplication.translate("MainWindow", "IMAP Server", None, QApplication.UnicodeUTF8)) self.lb_ssl.setText(QApplication.translate("MainWindow", "SSL", None, QApplication.UnicodeUTF8)) self.ssl_cb.setText(QApplication.translate("MainWindow", "Port : 993", None, QApplication.UnicodeUTF8)) self.lb_adress.setText(QApplication.translate("MainWindow", "Adress", None, QApplication.UnicodeUTF8)) self.lb_pass.setText(QApplication.translate("MainWindow", "Password", None, QApplication.UnicodeUTF8)) self.connect_btn.setText(QApplication.translate("MainWindow", "Connect", None, QApplication.UnicodeUTF8)) self.lb_select_mailbox.setText(QApplication.translate("MainWindow", "Select Mailbox", None, QApplication.UnicodeUTF8)) self.search_gbox.setTitle(QApplication.translate("MainWindow", " Search Parameters", None, QApplication.UnicodeUTF8)) self.since_date_cb.setText(QApplication.translate("MainWindow", "Since", None, QApplication.UnicodeUTF8)) self.since_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "dd-MMM-yyyy", None, QApplication.UnicodeUTF8)) self.before_date_cb.setText(QApplication.translate("MainWindow", "Before", None, QApplication.UnicodeUTF8)) self.before_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "dd-MMM-yyyy", None, QApplication.UnicodeUTF8)) self.html_radio.setText(QApplication.translate("MainWindow", "html", None, QApplication.UnicodeUTF8)) self.text_radio.setText(QApplication.translate("MainWindow", "text", None, QApplication.UnicodeUTF8)) # self.lb_threads.setText(QApplication.translate("MainWindow", "Threads", None, QApplication.UnicodeUTF8)) self.lb_from.setText(QApplication.translate("MainWindow", "From", None, QApplication.UnicodeUTF8)) self.lb_to.setText(QApplication.translate("MainWindow", "To", None, QApplication.UnicodeUTF8)) self.lb_subject.setText(QApplication.translate("MainWindow", "Subject", None, QApplication.UnicodeUTF8)) self.search_btn.setText(QApplication.translate("MainWindow", "Search", None, QApplication.UnicodeUTF8)) self.links_gbox.setTitle(QApplication.translate("MainWindow", " Links", None, QApplication.UnicodeUTF8)) self.export_html_btn.setText(QApplication.translate("MainWindow", "Export as HTML", None, QApplication.UnicodeUTF8)) self.export_txt_btn.setText(QApplication.translate("MainWindow", "Export as txt", None, QApplication.UnicodeUTF8)) self.log_gbox.setTitle(QApplication.translate("MainWindow", " Log", None, QApplication.UnicodeUTF8)) self.disconnect_btn.setText(QApplication.translate("MainWindow", "Disconnect", None, QApplication.UnicodeUTF8)) self.menu_file.setTitle(QApplication.translate("MainWindow", "File", None, QApplication.UnicodeUTF8)) self.menu_about.setTitle(QApplication.translate("MainWindow", "About", None, QApplication.UnicodeUTF8)) self.action_about.setText(QApplication.translate("MainWindow", "About", None, QApplication.UnicodeUTF8)) self.action_About_Qt.setText(QApplication.translate("MainWindow", "About Qt", None, QApplication.UnicodeUTF8)) self.action_exit.setText(QApplication.translate("MainWindow", "Exit", None, QApplication.UnicodeUTF8)) self.action_exit.setShortcut(QApplication.translate("MainWindow", "Ctrl+Q", None, QApplication.UnicodeUTF8)) self.actionSave.setText(QApplication.translate("MainWindow", "Save", None, QApplication.UnicodeUTF8))
class LightingControl(ScreenWithBackButton): def __init__(self, lightsDevice, mainWindow): self.lights = lightsDevice ScreenWithBackButton.__init__(self, "Lighting", mainWindow) def makeContent(self): layout = QHBoxLayout() layout.addLayout(self._welcomeAreaControls()) layout.addLayout(self._modeControls()) return layout def _welcomeAreaControls(self): def onOff(presetString): @handlePyroErrors def inner(isOn): if isOn: self.lights.activate(presetString) else: self.lights.deactivate(presetString) return inner layout = QHBoxLayout() gallery_ext = QVBoxLayout() gallery_ext.addWidget(TitleLabel("Gallery and External")) gallery = ExpandingButton() gallery.setText("Gallery") gallery.setCheckable(True) gallery.toggled.connect(onOff("St Aldate's.Welcome Area.gall on")) gallery_ext.addWidget(gallery) external = ExpandingButton() external.setText("External Lights") external.setCheckable(True) external.toggled.connect(onOff("EXTERIOR.Section Zero.ENTRA ONLY ON")) gallery_ext.addWidget(external) layout.addLayout(gallery_ext) welcomeArea = QVBoxLayout() welcomeArea.addWidget(TitleLabel("Welcome Area")) full = OptionButton() full.setText("100%") _safelyConnect(full.clicked, lambda: self.lights.activate("St Aldate's.Welcome Area.Welcome100%")) welcomeArea.addWidget(full) std = OptionButton() std.setText("70%") _safelyConnect(std.clicked, lambda: self.lights.activate("St Aldate's.Welcome Area.Welcome70%")) welcomeArea.addWidget(std) off = OptionButton() off.setText("Off") _safelyConnect(off.clicked, lambda: self.lights.activate("St Aldate's.Welcome Area.Ent&GalOFF")) welcomeArea.addWidget(off) self.welcomeArea = QButtonGroup() self.welcomeArea.addButton(full, 1) self.welcomeArea.addButton(std, 2) self.welcomeArea.addButton(off, 3) layout.addLayout(welcomeArea) return layout def _modeControls(self): layout = QVBoxLayout() layout.addWidget(TitleLabel("Lighting Mode")) normal = OptionButton() normal.setText("Normal") _safelyConnect(normal.clicked, lambda: self.lights.execute("goto default")) layout.addWidget(normal) late = OptionButton() late.setText("8.15 Service") _safelyConnect(late.clicked, lambda: self.lights.execute("Goto 8:15")) layout.addWidget(late) test = OptionButton() test.setText("Test (All @50%)") _safelyConnect(test.clicked, lambda: self.lights.activate("St Aldate's.Section Zero.All at 50")) layout.addWidget(test) self.modes = QButtonGroup() self.modes.addButton(normal, 1) self.modes.addButton(late, 2) self.modes.addButton(test, 3) return layout
class ProjectorScreensControl(ScreenWithBackButton): ''' Controls for the projector screens. ''' def __init__(self, screensDevice, mainWindow): self.screensDevice = screensDevice ScreenWithBackButton.__init__(self, "Projector Screens", mainWindow) def makeContent(self): layout = QGridLayout() self.screens = QButtonGroup() btnLeft = IDedButton(1) btnLeft.setText("Left") layout.addWidget(btnLeft, 1, 0, 1, 2) btnLeft.setCheckable(True) self.screens.addButton(btnLeft, 1) btnAll = IDedButton(0) btnAll.setText("Both") layout.addWidget(btnAll, 1, 2, 1, 3) btnAll.setCheckable(True) btnAll.setChecked(True) self.screens.addButton(btnAll, 0) btnRight = IDedButton(2) btnRight.setText("Right") layout.addWidget(btnRight, 1, 5, 1, 2) btnRight.setCheckable(True) self.screens.addButton(btnRight, 2) btnRaise = SvgButton(":icons/go-up", 96, 96) btnRaise.setText("Raise") btnRaise.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnRaise, 2, 1, 1, 3) btnRaise.clicked.connect(self.raiseUp) btnLower = SvgButton(":icons/go-down", 96, 96) btnLower.setText("Lower") btnLower.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnLower, 3, 1, 1, 3) btnLower.clicked.connect(self.lowerDown) btnStop = SvgButton(":icons/process-stop", 96, 96) btnStop.setText("Stop") btnStop.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon) layout.addWidget(btnStop, 2, 4, 2, 2) btnStop.clicked.connect(self.stop) return layout @handlePyroErrors def raiseUp(self): screenID = self.screens.checkedId() self.screensDevice.raiseUp(screenID) @handlePyroErrors def lowerDown(self): screenID = self.screens.checkedId() self.screensDevice.lower(screenID) @handlePyroErrors def stop(self): screenID = self.screens.checkedId() self.screensDevice.stop(screenID)
class VideoSwitcher(QWidget): def __init__(self, controller, mainWindow, switcherState, joystickAdapter=None): super(VideoSwitcher, self).__init__() self.mainWindow = mainWindow self.atem = controller['ATEM'] self.controller = controller self.switcherState = switcherState self.joystickAdapter = joystickAdapter self.setupUi() def setupUi(self): layout = QGridLayout() inputs_grid = QHBoxLayout() self.inputs = QButtonGroup() def ifDevice(deviceID, func): if self.controller.hasDevice(deviceID): return func() return (None, None, None, None) def setCamera(cam, cc): if self.joystickAdapter: self.joystickAdapter.set_camera(cam) self.joystickAdapter.set_on_move(cc.deselectPreset) def makeCamera(videoSource, cameraID): cam = self.controller[cameraID] cc = CameraControl(cam) return ( videoSource, cc, AdvancedCameraControl(cameraID, cam, self.mainWindow), lambda: setCamera(cam, cc) ) def deselectCamera(): if self.joystickAdapter: self.joystickAdapter.set_camera(None) self.joystickAdapter.set_on_move(None) self.input_buttons_config = [ ifDevice("Camera 1", lambda: makeCamera(VideoSource.INPUT_1, "Camera 1")), ifDevice("Camera 2", lambda: makeCamera(VideoSource.INPUT_2, "Camera 2")), ifDevice("Camera 3", lambda: makeCamera(VideoSource.INPUT_3, "Camera 3")), (VideoSource.INPUT_4, QLabel(StringConstants.noDevice), None, deselectCamera), (VideoSource.INPUT_5, OverlayControl(self.switcherState.dsks[0], self.atem), None, deselectCamera), (VideoSource.INPUT_6, QLabel(StringConstants.noDevice), None, deselectCamera) ] for source, panel, adv_panel, on_select_func in self.input_buttons_config: if source: btn = InputButton(self.switcherState.inputs[source]) btn.setProperty("panel", panel) btn.setProperty("adv_panel", adv_panel) btn.clicked.connect(self.preview) btn.clicked.connect(self.displayPanel) if on_select_func: btn.clicked.connect(on_select_func) btn.longpress.connect(self.displayAdvPanel) self.inputs.addButton(btn) inputs_grid.addWidget(btn) self.extrasBtn = InputButton(None) self.inputs.addButton(self.extrasBtn) self.extrasBtn.clicked.connect(self.preview) self.extrasBtn.clicked.connect(self.displayPanel) self.extrasBtn.clicked.connect(deselectCamera) # An empty menu means the button will be given a "down arrow" icon # without actually showing a menu when pressed. self.extrasBtn.setMenu(QMenu()) self.allInputs = AllInputsPanel(self.switcherState) self.extrasBtn.setProperty("panel", self.allInputs) self.allInputs.inputSelected.connect(self.setExtraInput) inputs_grid.addWidget(self.extrasBtn) self.blackBtn = FlashingInputButton(self.switcherState.inputs[VideoSource.BLACK]) inputs_grid.addWidget(self.blackBtn) self.inputs.addButton(self.blackBtn) self.blackBtn.clicked.connect(self.preview) self.blackBtn.clicked.connect(self.displayPanel) self.blackBtn.clicked.connect(deselectCamera) self.ftb = FadeToBlackControl(self.switcherState.ftb, self.atem) self.blackBtn.setProperty("panel", self.ftb) self.blackBtn.flashing = self.switcherState.ftb.active self.switcherState.ftb.activeChanged.connect(self.blackBtn.setFlashing) layout.addLayout(inputs_grid, 0, 0, 1, 7) self.og = OutputsGrid(self.switcherState) self.og.take.connect(self.take) self.og.cut.connect(self.cut) self.og.selected.connect(self.sendToAux) self.og.mainToAll.connect(self.sendMainToAllAuxes) self.og.all.connect(self.sendToAll) self.og.sendMain.connect(self.sendMainToAux) self.og.setAuxesEnabled(False) # since we start off without an input selected layout.addWidget(self.og, 1, 5, 1, 2) self.blankWidget = QWidget() layout.addWidget(self.blankWidget, 1, 0, 1, 5) layout.setRowStretch(0, 1) layout.setRowStretch(1, 5) self.setLayout(layout) def setExtraInput(self, inp): self.extrasBtn.setInput(inp) self.preview() @with_atem def preview(self): checkedButton = self.inputs.checkedButton() if checkedButton and checkedButton.input: self.og.setAuxesEnabled(True) if self.atem: self.atem.setPreview(checkedButton.input.source) else: self.og.setAuxesEnabled(False) @with_atem def cut(self): self.atem.performCut() @with_atem def take(self): self.atem.setNextTransition(TransitionStyle.MIX, bkgd=True, key1=False, key2=False, key3=False, key4=False) self.atem.performAutoTake() @with_atem def sendToAux(self, auxIndex): if self.inputs.checkedButton().input: self.atem.setAuxSource(auxIndex + 1, self.inputs.checkedButton().input.source) @with_atem def sendToAll(self): if self.inputs.checkedButton().input: self.atem.setProgram(self.inputs.checkedButton().input.source) for aux in self.switcherState.outputs.keys(): self.sendToAux(aux) @with_atem def sendMainToAux(self, auxIndex): self.atem.setAuxSource(auxIndex + 1, VideoSource.ME_1_PROGRAM) @with_atem def sendMainToAllAuxes(self): for aux in self.switcherState.outputs.keys(): self.atem.setAuxSource(aux + 1, VideoSource.ME_1_PROGRAM) def displayPanel(self): panel = self.inputs.checkedButton().property("panel") layout = self.layout() existing = layout.itemAtPosition(1, 0) if existing: widget = existing.widget() widget.hide() layout.removeWidget(widget) if panel: # display panel layout.addWidget(panel, 1, 0, 1, 5) panel.show() else: # hide panel layout.addWidget(self.blankWidget, 1, 0, 1, 5) self.blankWidget.show() def displayAdvPanel(self): panel = self.sender().property("adv_panel") if panel: self.mainWindow.showScreen(panel)
class CameraControl(QWidget): ''' GUI to control a camera. ''' def __init__(self, camera): super(CameraControl, self).__init__() self.camera = camera self.initUI() self.panSpeed = 12 self.tiltSpeed = 12 self.zoomSpeed = 6 def initUI(self): layout = QGridLayout() self.setLayout(layout) self.btnUp = CameraButton() layout.addWidget(self.btnUp, 0, 1, 2, 1) _safelyConnect(self.btnUp.pressed, lambda: self.camera.moveUp(self.panSpeed, self.tiltSpeed)) _safelyConnect(self.btnUp.released, self.camera.stop) _safelyConnect(self.btnUp.clicked, self.deselectPreset) self.btnUp.setIcon(QIcon(":icons/go-up")) self.btnLeft = CameraButton() layout.addWidget(self.btnLeft, 1, 0, 2, 1) _safelyConnect(self.btnLeft.pressed, lambda: self.camera.moveLeft(self.panSpeed, self.tiltSpeed)) _safelyConnect(self.btnLeft.released, self.camera.stop) _safelyConnect(self.btnLeft.clicked, self.deselectPreset) self.btnLeft.setIcon(QIcon(":icons/go-previous")) self.btnDown = CameraButton() layout.addWidget(self.btnDown, 2, 1, 2, 1) _safelyConnect(self.btnDown.pressed, lambda: self.camera.moveDown(self.panSpeed, self.tiltSpeed)) _safelyConnect(self.btnDown.released, self.camera.stop) _safelyConnect(self.btnDown.clicked, self.deselectPreset) self.btnDown.setIcon(QIcon(":icons/go-down")) self.btnRight = CameraButton() layout.addWidget(self.btnRight, 1, 2, 2, 1) _safelyConnect(self.btnRight.pressed, lambda: self.camera.moveRight(self.panSpeed, self.tiltSpeed)) _safelyConnect(self.btnRight.released, self.camera.stop) _safelyConnect(self.btnRight.clicked, self.deselectPreset) self.btnRight.setIcon(QIcon(":icons/go-next")) zoomInOut = PlusMinusButtons("Zoom") _safelyConnect(zoomInOut.upButton.pressed, lambda: self.camera.zoomIn(self.zoomSpeed)) _safelyConnect(zoomInOut.upButton.released, self.camera.zoomStop) _safelyConnect(zoomInOut.upButton.clicked, self.deselectPreset) _safelyConnect(zoomInOut.downButton.pressed, lambda: self.camera.zoomOut(self.zoomSpeed)) _safelyConnect(zoomInOut.downButton.released, self.camera.zoomStop) _safelyConnect(zoomInOut.downButton.clicked, self.deselectPreset) layout.addWidget(zoomInOut, 0, 3, 4, 1) focus = PlusMinusAutoButtons("Focus") _safelyConnect(focus.upButton.pressed, self.camera.focusFar) _safelyConnect(focus.upButton.released, self.camera.focusStop) _safelyConnect(focus.upButton.clicked, self.deselectPreset) _safelyConnect(focus.downButton.pressed, self.camera.focusNear) _safelyConnect(focus.downButton.released, self.camera.focusStop) _safelyConnect(focus.downButton.clicked, self.deselectPreset) def autoFocusAndDeselect(): self.camera.focusAuto() self.deselectPreset() _safelyConnect(focus.autoButton.clicked, autoFocusAndDeselect) layout.addWidget(focus, 0, 4, 4, 1) brightness = PlusMinusAutoButtons("Bright") _safelyConnect(brightness.upButton.clicked, self.camera.brighter) _safelyConnect(brightness.downButton.clicked, self.camera.darker) _safelyConnect(brightness.autoButton.clicked, self.camera.setAutoExposure) layout.addWidget(brightness, 0, 5, 4, 1) presets = QGridLayout() presets.setRowStretch(0, 2) presets.setRowStretch(1, 1) self.presetGroup = QButtonGroup() for i in range(1, 7): btnPresetRecall = CameraButton() presets.addWidget(btnPresetRecall, 0, i, 1, 1) btnPresetRecall.setText(str(i)) _safelyConnect(btnPresetRecall.clicked, lambda i=i: self.recallPreset(i)) btnPresetRecall.setCheckable(True) self.presetGroup.addButton(btnPresetRecall, i) btnPresetSet = CameraButton() presets.addWidget(btnPresetSet, 1, i, 1, 1) btnPresetSet.setText("Set") _safelyConnect(btnPresetSet.clicked, lambda i=i: self.storePreset(i)) layout.addLayout(presets, 4, 0, 3, 6) def keyPressEvent(self, e): if e.key() == Qt.Key_Left: self.btnLeft.pressed.emit() elif e.key() == Qt.Key_Right: self.btnRight.pressed.emit() elif e.key() == Qt.Key_Up: self.btnUp.pressed.emit() elif e.key() == Qt.Key_Down: self.btnDown.pressed.emit() def keyReleaseEvent(self, e): if e.key() == Qt.Key_Left: self.btnLeft.released.emit() elif e.key() == Qt.Key_Right: self.btnRight.released.emit() elif e.key() == Qt.Key_Up: self.btnUp.released.emit() elif e.key() == Qt.Key_Down: self.btnDown.released.emit() @handlePyroErrors def storePreset(self, index): print "Storing preset " + str(index) result = self.camera.storePreset(index) self.presetGroup.buttons()[index - 1].setChecked(True) return result @handlePyroErrors def recallPreset(self, index): print "Recalling preset " + str(index) return self.camera.recallPreset(index) def deselectPreset(self): if self.presetGroup.checkedId() >= 0: # Yuck. self.presetGroup.setExclusive(False) while (self.presetGroup.checkedId() >= 0): self.presetGroup.checkedButton().setChecked(False) self.presetGroup.setExclusive(True)
class ExposureControl(QWidget): class Mode(Enum): AUTO = 1 TV = 2 AV = 4 MANUAL = 8 def __or__(self, other): return self.value | other.value def __init__(self, camera): super(ExposureControl, self).__init__() self.camera = camera self.initUI() def initUI(self): layout = QGridLayout() title = QLabel("Exposure") title.setAlignment(Qt.AlignCenter) layout.addWidget(title, 0, 0, 1, 4) btnAuto = OptionButton() btnAuto.setText("Full Auto") _safelyConnect(btnAuto.clicked, self.camera.setAutoExposure) btnAuto.setChecked(True) layout.addWidget(btnAuto, 1, 0) btnTV = OptionButton() btnTV.setText("Tv") _safelyConnect(btnTV.clicked, self.camera.setShutterPriority) layout.addWidget(btnTV, 1, 1) btnAV = OptionButton() btnAV.setText("Av") _safelyConnect(btnAV.clicked, self.camera.setAperturePriority) layout.addWidget(btnAV, 1, 2) btnManual = OptionButton() btnManual.setText("M") _safelyConnect(btnManual.clicked, self.camera.setManualExposure) layout.addWidget(btnManual, 1, 3) layout.addWidget(QLabel("Aperture"), 2, 0) self.aperture = QComboBox(self) for a in list(Aperture): self.aperture.addItem(a.label, userData=a) self.aperture.currentIndexChanged.connect(self.setAperture) self.aperture.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.aperture.setEnabled(False) layout.addWidget(self.aperture, 2, 1, 1, 3) layout.addWidget(QLabel("Shutter"), 3, 0) self.shutter = QComboBox(self) for s in list(Shutter): self.shutter.addItem(s.label, userData=s) self.shutter.currentIndexChanged.connect(self.setShutter) self.shutter.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.shutter.setEnabled(False) layout.addWidget(self.shutter, 3, 1, 1, 3) layout.addWidget(QLabel("Gain"), 4, 0) self.gain = QComboBox(self) for g in list(Gain): self.gain.addItem(g.label, userData=g) self.gain.currentIndexChanged.connect(self.setGain) self.gain.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.gain.setEnabled(False) layout.addWidget(self.gain, 4, 1, 1, 3) self.exposureButtons = QButtonGroup() self.exposureButtons.addButton(btnAuto, self.Mode.AUTO.value) self.exposureButtons.addButton(btnTV, self.Mode.TV.value) self.exposureButtons.addButton(btnAV, self.Mode.AV.value) self.exposureButtons.addButton(btnManual, self.Mode.MANUAL.value) self.exposureButtons.buttonClicked.connect(self.onExposureMethodSelected) layout.setRowStretch(0, 0) layout.setRowStretch(1, 1) layout.setRowStretch(2, 1) layout.setRowStretch(3, 1) layout.setRowStretch(4, 1) self.setLayout(layout) def onExposureMethodSelected(self): checked = self.exposureButtons.checkedId() self.aperture.setEnabled(checked & (self.Mode.MANUAL | self.Mode.AV)) self.shutter.setEnabled(checked & (self.Mode.MANUAL | self.Mode.TV)) self.gain.setEnabled(checked & self.Mode.MANUAL.value) @handlePyroErrors def setAperture(self, idx): ap = self.aperture.itemData(idx) self.camera.setAperture(ap) @handlePyroErrors def setShutter(self, idx): sh = self.shutter.itemData(idx) self.camera.setShutter(sh) @handlePyroErrors def setGain(self, idx): g = self.gain.itemData(idx) self.camera.setGain(g)
class ProjectorScreensControl(ScreenWithBackButton): ''' Controls for the projector screens. ''' def __init__(self, controller, mainWindow): self.controller = controller ScreenWithBackButton.__init__(self, "Projector Screens", mainWindow) def makeContent(self): layout = QGridLayout() self.screens = QButtonGroup() btnLeft = IDedButton(1) btnLeft.setText("Left") layout.addWidget(btnLeft, 1, 0, 1, 2) btnLeft.setCheckable(True) self.screens.addButton(btnLeft, 1) btnAll = IDedButton(0) btnAll.setText("Both") layout.addWidget(btnAll, 1, 2, 1, 3) btnAll.setCheckable(True) btnAll.setChecked(True) self.screens.addButton(btnAll, 0) btnRight = IDedButton(2) btnRight.setText("Right") layout.addWidget(btnRight, 1, 5, 1, 2) btnRight.setCheckable(True) self.screens.addButton(btnRight, 2) iconSize = QSize(96, 96) btnRaise = ExpandingButton() btnRaise.setText("Raise") btnRaise.setIcon(QIcon("icons/go-up.svg")) btnRaise.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnRaise, 2, 1, 1, 3) btnRaise.setIconSize(iconSize) btnRaise.clicked.connect(self.raiseUp) btnLower = ExpandingButton() btnLower.setText("Lower") btnLower.setIcon(QIcon("icons/go-down.svg")) btnLower.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnLower, 3, 1, 1, 3) btnLower.setIconSize(iconSize) btnLower.clicked.connect(self.lowerDown) btnStop = ExpandingButton() btnStop.setText("Stop") btnStop.setIcon(QIcon("icons/process-stop.svg")) btnStop.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnStop, 2, 4, 2, 2) btnStop.setIconSize(iconSize) btnStop.clicked.connect(self.stop) return layout def raiseUp(self): screenID = self.screens.checkedId() try: self.controller.raiseUp("Screens", screenID) except NamingError: self.mainWindow.errorBox(StringConstants.nameErrorText) except ProtocolError: self.mainWindow.errorBox(StringConstants.protocolErrorText) def lowerDown(self): screenID = self.screens.checkedId() try: self.controller.lower("Screens", screenID) except NamingError: self.mainWindow.errorBox(StringConstants.nameErrorText) except ProtocolError: self.mainWindow.errorBox(StringConstants.protocolErrorText) def stop(self): screenID = self.screens.checkedId() try: self.controller.stop("Screens", screenID) except NamingError: self.mainWindow.errorBox(StringConstants.nameErrorText) except ProtocolError: self.mainWindow.errorBox(StringConstants.protocolErrorText)
class PeriodicTableWidget(QWidget): selectionChanged = Signal() def __init__(self, parent=None): QWidget.__init__(self, parent) # Widgets, layouts and signals self._group = QButtonGroup() layout = QGridLayout() layout.setSpacing(0) for i in range(18): layout.setColumnMinimumWidth(i, 40) layout.setColumnStretch(i, 0) for i in list(range(7)) + [8, 9]: layout.setRowMinimumHeight(i, 40) layout.setRowStretch(i, 0) ## Element for z, position in _ELEMENT_POSITIONS.items(): widget = ElementPushButton(z) widget.setCheckable(True) layout.addWidget(widget, *position) self._group.addButton(widget, z) ## Labels layout.addWidget(QLabel(''), 7, 0) # Dummy layout.addWidget(QLabel('*'), 5, 2, Qt.AlignCenter) layout.addWidget(QLabel('*'), 8, 2, Qt.AlignCenter) layout.addWidget(QLabel('**'), 6, 2, Qt.AlignCenter) layout.addWidget(QLabel('**'), 9, 2, Qt.AlignCenter) for row in [0, 1, 2, 3, 4, 5, 6, 8, 9]: layout.setRowStretch(row, 1) self.setLayout(layout) # Signals self._group.buttonClicked.connect(self.selectionChanged) # Default self.setColorFunction(_category_color_function) def setColorFunction(self, func): if not callable(func): raise ValueError('Not a function') self._color_function = func # Redraw for widget in self._group.buttons(): z = self._group.id(widget) bcolor = func(z) fcolor = 'white' if _calculate_brightness(bcolor) < 128 else 'black' sheet = 'background-color: %s; color: %s' % (bcolor.name(), fcolor) widget.setStyleSheet(sheet) def colorFunction(self): return self._color_function def setMultipleSelection(self, multiple): self._group.setExclusive(not multiple) def isMultipleSelection(self): return not self._group.exclusive() def setSelection(self, selection): def _uncheckedAll(): for widget in self._group.buttons(): widget.setChecked(False) if selection is None: _uncheckedAll() self.selectionChanged.emit() return if isinstance(selection, (int, six.string_types)): selection = [selection] if not self.isMultipleSelection() and len(selection) > 1: raise ValueError('Multiple selection mode is off. Cannot select more than one element') _uncheckedAll() for z in selection: if isinstance(z, six.string_types): z = ep.atomic_number(z.strip()) self._group.button(z).setChecked(True) self.selectionChanged.emit() # def selection(self): selection = set() for widget in self._group.buttons(): if widget.isChecked(): selection.add(self._group.id(widget)) if self.isMultipleSelection(): return frozenset(selection) else: if len(selection) > 0: return list(selection)[0] else: return None def selectionSymbol(self): selection = self.selection() if self.isMultipleSelection(): return frozenset(map(ep.symbol, selection)) else: if selection is None: return None else: return ep.symbol(selection)
class VideoSwitcher(QWidget): def __init__(self, controller, mainWindow): super(VideoSwitcher, self).__init__() self.controller = controller self.mainWindow = mainWindow self.setupUi() def setupUi(self): gridlayout = QGridLayout() self.setLayout(gridlayout) ''' Buttons added to inputs should have a numeric ID set equal to their input number on the Aldates main switcher. ''' self.inputs = QButtonGroup() inputsGrid = QHBoxLayout() self.btnCamera1 = CameraSelectionButton(1) self.btnCamera1.setText("Camera 1") self.btnCamera1.setInput(VisualsSystem.camera1) inputsGrid.addWidget(self.btnCamera1) self.inputs.addButton(self.btnCamera1, 1) self.btnCamera1.setIcon(QIcon(":icons/camera-video")) self.btnCamera2 = CameraSelectionButton(2) self.btnCamera2.setText("Camera 2") self.btnCamera2.setInput(VisualsSystem.camera2) inputsGrid.addWidget(self.btnCamera2) self.inputs.addButton(self.btnCamera2, 2) self.btnCamera2.setIcon(QIcon(":icons/camera-video")) self.btnCamera3 = CameraSelectionButton(3) self.btnCamera3.setText("Camera 3") self.btnCamera3.setInput(VisualsSystem.camera3) inputsGrid.addWidget(self.btnCamera3) self.inputs.addButton(self.btnCamera3, 3) self.btnCamera3.setIcon(QIcon(":icons/camera-video")) self.btnDVD = InputButton() self.btnDVD.setText("DVD") self.btnDVD.setInput(VisualsSystem.dvd) inputsGrid.addWidget(self.btnDVD) self.inputs.addButton(self.btnDVD, 4) self.btnDVD.setIcon(QIcon(":icons/media-optical")) self.btnExtras = InputButton() self.btnExtras.setText("Extras") inputsGrid.addWidget(self.btnExtras) self.btnExtras.setIcon(QIcon(":icons/video-display")) self.inputs.addButton(self.btnExtras, 5) self.btnVisualsPC = InputButton() self.btnVisualsPC.setText("Visuals PC") self.btnVisualsPC.setInput(VisualsSystem.visualsPC) inputsGrid.addWidget(self.btnVisualsPC) self.inputs.addButton(self.btnVisualsPC, 6) self.btnVisualsPC.setIcon(QIcon(":icons/computer")) self.btnBlank = InputButton() self.btnBlank.setText("Blank") self.btnBlank.setInput(VisualsSystem.blank) inputsGrid.addWidget(self.btnBlank) self.inputs.addButton(self.btnBlank, 0) gridlayout.addLayout(inputsGrid, 0, 0, 1, 7) self.extrasSwitcher = ExtrasSwitcher(self.controller) self.extrasSwitcher.inputSelected.connect(self.handleExtrasSelect) self.btnExtras.setInput(ProxyInput(self.extrasSwitcher)) self.blank = QWidget(self) gridlayout.addWidget(self.blank, 1, 0, 1, 5) self.outputsGrid = OutputsGrid() gridlayout.addWidget(self.outputsGrid, 1, 5, 1, 2) gridlayout.setRowStretch(0, 1) gridlayout.setRowStretch(1, 5) QMetaObject.connectSlotsByName(self) self.setInputClickHandlers() self.setOutputClickHandlers(self.outputsGrid) self.configureInnerControlPanels() self.gridlayout = gridlayout def configureInnerControlPanels(self): self.panels = [ QWidget(), # Blank CameraControl(self.controller["Camera 1"]) if self.controller.hasDevice("Camera 1") else QLabel(StringConstants.noDevice), CameraControl(self.controller["Camera 2"]) if self.controller.hasDevice("Camera 2") else QLabel(StringConstants.noDevice), CameraControl(self.controller["Camera 3"]) if self.controller.hasDevice("Camera 3") else QLabel(StringConstants.noDevice), QLabel(StringConstants.noDevice), # DVD - no controls self.extrasSwitcher if self.controller.hasDevice("Extras") else QLabel(StringConstants.noDevice), # Extras EclipseControls(self.controller["Main Scan Converter"]) if self.controller.hasDevice("Main Scan Converter") else QLabel(StringConstants.noDevice), # Visuals PC ] self.advPanels = [ None, AdvancedCameraControl("Camera 1", self.controller["Camera 1"], self.mainWindow) if self.controller.hasDevice("Camera 1") else None, AdvancedCameraControl("Camera 2", self.controller["Camera 2"], self.mainWindow) if self.controller.hasDevice("Camera 1") else None, AdvancedCameraControl("Camera 3", self.controller["Camera 3"], self.mainWindow) if self.controller.hasDevice("Camera 1") else None, None, None, None ] def setInputClickHandlers(self): for btn in self.inputs.buttons(): btn.clicked.connect(self.handleInputSelect) btn.longpress.connect(self.showAdvPanel) def setOutputClickHandlers(self, outputsGrid): outputsGrid.connectMainOutputs(self.handleOutputSelect) ''' btnPCMix is a special case since that's on a different switcher ''' outputsGrid.connectPreviewOutputs(self.handlePCMixSelect) def keyPressEvent(self, e): if e.key() == Qt.Key_0: self.btnBlank.click() elif e.key() == Qt.Key_1: self.btnCamera1.click() elif e.key() == Qt.Key_2: self.btnCamera2.click() elif e.key() == Qt.Key_3: self.btnCamera3.click() elif e.key() == Qt.Key_4: self.btnDVD.click() elif e.key() == Qt.Key_5: self.btnExtras.click() elif e.key() == Qt.Key_6: self.btnVisualsPC.click() elif e.key() == Qt.Key_Space: self.outputsGrid.btnAll.click() else: self.panels[self.inputs.checkedId()].keyPressEvent(e) def keyReleaseEvent(self, e): self.panels[self.inputs.checkedId()].keyReleaseEvent(e) def handleInputSelect(self): inputID = self.inputs.checkedId() logging.debug("Input selected: " + str(inputID)) if inputID >= 0: myInput = self.inputs.checkedButton().input if myInput: myInput.preview(self.controller) self.gridlayout.removeWidget(self.gridlayout.itemAtPosition(1, 0).widget()) for p in self.panels: p.hide() chosenPanel = self.panels[inputID] self.gridlayout.addWidget(chosenPanel, 1, 0, 1, 5) chosenPanel.show() # Prevent certain options from being selectable if inputID == 6 or inputID == 0: self.outputsGrid.setEnabled(True) self.outputsGrid.btnPCMix.setEnabled(False) elif inputID == 5 and self.extrasSwitcher.currentInput() is None: self.outputsGrid.setEnabled(False) self.outputsGrid.btnPCMix.setEnabled(True) else: self.outputsGrid.setEnabled(True) self.outputsGrid.btnPCMix.setEnabled(True) def handleOutputSelect(self): outputChannel = self.sender().ID inputID = self.inputs.checkedId() checkedExtrasButton = self.extrasSwitcher.inputs.checkedButton() inputChannel = checkedExtrasButton.input if (inputID == 5 and checkedExtrasButton) else self.inputs.checkedButton().input if inputChannel: inputChannel.toMain(self.controller, outputChannel) def handlePCMixSelect(self): inputID = self.inputs.checkedId() checkedExtrasButton = self.extrasSwitcher.inputs.checkedButton() inputChannel = checkedExtrasButton.input if (inputID == 5 and checkedExtrasButton) else self.inputs.checkedButton().input if inputChannel: inputChannel.toPCMix(self.controller) @Slot(VisualsSystem.Input) def handleExtrasSelect(self, extrasInput): if extrasInput is not None: self.btnExtras.setText(extrasInput.name) self.outputsGrid.inputNames[5] = extrasInput.name self.outputsGrid.setEnabled(True) else: # Not sure under what circumstances, if any, this will arise self.btnExtras.setText("Extras") self.outputsGrid.inputNames[5] = "Extras" self.outputsGrid.setEnabled(False) def showAdvPanel(self): sender = self.sender() inputID = self.sender().ID if hasattr(sender, "ID") else None if inputID is not None and self.advPanels[inputID] is not None: self.mainWindow.showScreen(self.advPanels[inputID]) def updateOutputMappings(self, mapping): print mapping self.outputsGrid.updateOutputMappings(mapping)
class CameraControl(QWidget): ''' GUI to control a camera. ''' def __init__(self, controller, cameraID): super(CameraControl, self).__init__() self.controller = controller self.cameraID = cameraID self.initUI() def initUI(self): layout = QGridLayout() self.setLayout(layout) self.btnUp = CameraButton(CameraMove.Up) layout.addWidget(self.btnUp, 0, 1, 2, 1) self.btnUp.pressed.connect(self.move) self.btnUp.released.connect(self.stop) self.btnUp.setIcon(QIcon("icons/go-up.svg")) self.btnLeft = CameraButton(CameraMove.Left) layout.addWidget(self.btnLeft, 1, 0, 2, 1) self.btnLeft.pressed.connect(self.move) self.btnLeft.released.connect(self.stop) self.btnLeft.setIcon(QIcon("icons/go-previous.svg")) self.btnDown = CameraButton(CameraMove.Down) layout.addWidget(self.btnDown, 2, 1, 2, 1) self.btnDown.pressed.connect(self.move) self.btnDown.released.connect(self.stop) self.btnDown.setIcon(QIcon("icons/go-down.svg")) self.btnRight = CameraButton(CameraMove.Right) layout.addWidget(self.btnRight, 1, 2, 2, 1) self.btnRight.pressed.connect(self.move) self.btnRight.released.connect(self.stop) self.btnRight.setIcon(QIcon("icons/go-next.svg")) zoomInOut = PlusMinusButtons("Zoom", CameraZoom.Tele, CameraZoom.Wide) zoomInOut.connectPressed(self.zoom) zoomInOut.connectReleased(self.stopZoom) layout.addWidget(zoomInOut, 0, 3, 4, 1) focus = PlusMinusAutoButtons("Focus", CameraFocus.Far, CameraFocus.Near, CameraFocus.Auto) focus.connectPressed(self.focus) focus.connectReleased(self.stopFocus) focus.autoButton.clicked.connect(self.focus) layout.addWidget(focus, 0, 4, 4, 1) brightness = PlusMinusButtons("Brightness", True, False) brightness.connectClicked(self.exposure) layout.addWidget(brightness, 0, 5, 4, 1) presets = QGridLayout() presets.setRowStretch(0, 2) presets.setRowStretch(1, 1) self.presetGroup = QButtonGroup() for i in range(0, 6): btnPresetRecall = CameraButton(i) presets.addWidget(btnPresetRecall, 0, i, 1, 1) btnPresetRecall.setText(str(i + 1)) btnPresetRecall.clicked.connect(self.recallPreset) btnPresetRecall.setCheckable(True) self.presetGroup.addButton(btnPresetRecall, i) btnPresetSet = CameraButton(i) presets.addWidget(btnPresetSet, 1, i, 1, 1) btnPresetSet.setText("Set") btnPresetSet.clicked.connect(self.storePreset) layout.addLayout(presets, 4, 0, 3, 6) def keyPressEvent(self, e): if e.key() == Qt.Key_Left: self.btnLeft.pressed.emit() elif e.key() == Qt.Key_Right: self.btnRight.pressed.emit() elif e.key() == Qt.Key_Up: self.btnUp.pressed.emit() elif e.key() == Qt.Key_Down: self.btnDown.pressed.emit() def keyReleaseEvent(self, e): if e.key() == Qt.Key_Left: self.btnLeft.released.emit() elif e.key() == Qt.Key_Right: self.btnRight.released.emit() elif e.key() == Qt.Key_Up: self.btnUp.released.emit() elif e.key() == Qt.Key_Down: self.btnDown.released.emit() def move(self): sender = self.sender() try: result = self.controller.move(self.cameraID, sender.cameraBinding) self.deselectPreset() return result except NamingError: self.errorBox(StringConstants.nameErrorText) except ProtocolError: self.errorBox(StringConstants.protocolErrorText) def stop(self): try: self.controller.move(self.cameraID, CameraMove.Stop) except NamingError: self.errorBox(StringConstants.nameErrorText) except ProtocolError: self.errorBox(StringConstants.protocolErrorText) def focus(self): sender = self.sender() try: result = self.controller.focus(self.cameraID, sender.cameraBinding) self.deselectPreset() return result except NamingError: self.errorBox(StringConstants.nameErrorText) except ProtocolError: self.errorBox(StringConstants.protocolErrorText) def stopFocus(self): try: self.controller.focus(self.cameraID, CameraFocus.Stop) except NamingError: self.errorBox(StringConstants.nameErrorText) except ProtocolError: self.errorBox(StringConstants.protocolErrorText) def zoom(self): sender = self.sender() try: result = self.controller.zoom(self.cameraID, sender.cameraBinding) self.deselectPreset() return result except NamingError: self.errorBox(StringConstants.nameErrorText) except ProtocolError: self.errorBox(StringConstants.protocolErrorText) def stopZoom(self): try: self.controller.zoom(self.cameraID, CameraZoom.Stop) except NamingError: self.errorBox(StringConstants.nameErrorText) except ProtocolError: self.errorBox(StringConstants.protocolErrorText) def exposure(self): sender = self.sender() try: result = self.controller.backlightComp(self.cameraID, sender.cameraBinding) self.deselectPreset() return result except NamingError: self.errorBox(StringConstants.nameErrorText) except ProtocolError: self.errorBox(StringConstants.protocolErrorText) def storePreset(self): sender = self.sender() try: result = self.controller.savePreset(self.cameraID, sender.cameraBinding) self.presetGroup.buttons()[sender.cameraBinding].setChecked(True) return result except NamingError: self.errorBox(StringConstants.nameErrorText) except ProtocolError: self.errorBox(StringConstants.protocolErrorText) def recallPreset(self): sender = self.sender() try: return self.controller.recallPreset(self.cameraID, sender.cameraBinding) except NamingError: self.errorBox(StringConstants.nameErrorText) except ProtocolError: self.errorBox(StringConstants.protocolErrorText) def deselectPreset(self): # Yuck. self.presetGroup.setExclusive(False) while (self.presetGroup.checkedId() >= 0): self.presetGroup.checkedButton().setChecked(False) self.presetGroup.setExclusive(True) def errorBox(self, text): msgBox = QMessageBox() msgBox.setText(text) msgBox.setIcon(QMessageBox.Critical) msgBox.exec_()
class Mixin: def createWidgets(self): settings = QSettings() self.searchLabel = QLabel("Search For") self.searchLineEdit = QLineEdit() self.tooltips.append((self.searchLineEdit, """\ <p><b>Search For editor</b></p> <p>The text or regular expression to search for.</p>""")) self.searchLabel.setBuddy(self.searchLineEdit) self.replaceLabel = QLabel("Replace With") self.replaceLineEdit = QLineEdit() self.tooltips.append((self.replaceLineEdit, """\ <p><b>Replace With editor</b></p> <p>The replacement text (which may include backreferences, \\1, \\2, etc., if a regular expression search is being made).</p>""")) self.replaceLabel.setBuddy(self.replaceLineEdit) self.allEntriesRadioButton = QRadioButton("All Entries") self.allEntriesRadioButton.setChecked( bool(int(settings.value("RP/All", 1)))) self.tooltips.append((self.allEntriesRadioButton, """\ <p><b>All Entries</b></p> <p>If checked, the search will consider every entry in the index.</p>""")) self.filteredEntriesRadioButton = QRadioButton("Filtered Entries") self.filteredEntriesRadioButton.setChecked( bool(int(settings.value("RP/Filtered", 0)))) self.tooltips.append((self.filteredEntriesRadioButton, """\ <p><b>Filtered Entries</b></p> <p>If checked, the search will consider only those entries that are in the current filtered view.</p>""")) self.considerLabel = QLabel("Consider") self.scopeGroup = QButtonGroup() self.scopeGroup.addButton(self.allEntriesRadioButton) self.scopeGroup.addButton(self.filteredEntriesRadioButton) self.literalRadioButton = QRadioButton("Literal") self.literalRadioButton.setChecked( bool(int(settings.value("RP/Literal", 1)))) self.tooltips.append((self.literalRadioButton, """<p><b>Literal</b></p> <p>If checked, the <b>Search For</b> text will be searched for literally.</p>""")) self.regexRadioButton = QRadioButton("Regex") self.regexRadioButton.setChecked( bool(int(settings.value("RP/Regex", 0)))) self.tooltips.append((self.regexRadioButton, """<p><b>Regex</b></p> <p>If checked, the <b>Search For</b> text will be searched for as a regular expression pattern.</p>""")) self.matchAsGroup = QButtonGroup() self.matchAsGroup.addButton(self.literalRadioButton) self.matchAsGroup.addButton(self.regexRadioButton) self.ignoreCaseCheckBox = QCheckBox("Ignore Case") self.ignoreCaseCheckBox.setChecked( bool(int(settings.value("RP/ICase", 0)))) self.tooltips.append((self.ignoreCaseCheckBox, """\ <p><b>Ignore Case</b></p> <p>If checked, the <b>Search For</b> text will be searched for case-insensitively.</p>""")) self.wholeWordsCheckBox = QCheckBox("Whole Words") self.wholeWordsCheckBox.setChecked( bool(int(settings.value("RP/WW", 0)))) self.tooltips.append((self.wholeWordsCheckBox, """\ <p><b>Whole Words</b></p> <p>If checked—and when <b>Literal</b> is checked—the <b>Search For</b> text will be matched as whole words.</p> <p>For example, “habit” will not match “habitat” when whole words is checked.</p> <p>(For regular expressions use \\b before and after each word to get whole word matches.)</p>""")) self.replaceInLabel = QLabel("Look In") self.replaceInTermsCheckBox = QCheckBox("Terms") self.replaceInTermsCheckBox.setChecked( bool(int(settings.value("RP/Terms", 1)))) self.tooltips.append((self.replaceInTermsCheckBox, """\ <p><b>Terms</b></p> <p>If checked, the search will look in term texts.</p>""")) self.replaceInPagesCheckBox = QCheckBox("Pages") self.replaceInPagesCheckBox.setChecked( bool(int(settings.value("RP/Pages", 0)))) self.tooltips.append((self.replaceInPagesCheckBox, """\ <p><b>Pages</b></p> <p>If checked, the search will look in pages texts.</p>""")) self.replaceInNotesCheckBox = QCheckBox("Notes") self.replaceInNotesCheckBox.setChecked( bool(int(settings.value("RP/Notes", 0)))) self.tooltips.append((self.replaceInNotesCheckBox, """\ <p><b>Notes</b></p> <p>If checked, the search will look in notes texts.</p>""")) self.startButton = QPushButton(QIcon(":/edit-find.svg"), "Start Search") self.tooltips.append((self.startButton, """<p><b>Start Search</b></p> <p>Start the search from the first entry in the index or the first entry in the filtered view's entries.</p>""")) self.replaceButton = QPushButton(QIcon(":/edit-find-replace.svg"), "Replace") self.tooltips.append((self.replaceButton, """<p><b>Replace</b></p> <p>Replace the highlighted text with the <b>Replace With</b> text (using backreferences if they are in the replacement text and a <b>Regex</b> search is underway), and then try to find the next matching text.</p>""")) self.skipButton = QPushButton(QIcon(":/skip.svg"), "S&kip") self.tooltips.append((self.skipButton, """<p><b>Skip</b></p> <p>Skip the highlighted text and try to find the next matching text.</p>""")) self.stopButton = QPushButton(QIcon(":/process-stop.svg"), "Stop Search") self.tooltips.append((self.stopButton, """<p><b>Stop Search</b></p> <p>Stop the current search. This allows the search options to be changed.</p>""")) self.closeButton = QToolButton() self.closeButton.setIcon(QIcon(":/hide.svg")) self.closeButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append((self.closeButton, """<p><b>Hide</b></p> <p>Hide the Search and Replace panel.</p> <p>Press <b>Ctrl+H</b> or click <img src=":/edit-find-replace.svg" width={0} height={0}> or click <b>Edit→Search and Replace</b> to show it again.</p>""".format(TOOLTIP_IMAGE_SIZE))) self.helpButton = QToolButton() self.helpButton.setIcon(QIcon(":/help.svg")) self.helpButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append( (self.helpButton, "Help on the Search and Replace panel.")) def layoutWidgets(self): form = QFormLayout() hbox = QHBoxLayout() hbox.addWidget(self.searchLineEdit) hbox.addWidget(self.closeButton) form.addRow(self.searchLabel, hbox) hbox = QHBoxLayout() hbox.addWidget(self.replaceLineEdit) hbox.addWidget(self.helpButton) form.addRow(self.replaceLabel, hbox) hbox = QHBoxLayout() hbox.addWidget(self.allEntriesRadioButton) hbox.addWidget(self.filteredEntriesRadioButton) hbox.addStretch() form.addRow(self.considerLabel, hbox) hbox = QHBoxLayout() hbox.addWidget(self.literalRadioButton) hbox.addWidget(self.regexRadioButton) hbox.addStretch(1) hbox.addWidget(self.ignoreCaseCheckBox) hbox.addWidget(self.wholeWordsCheckBox) hbox.addStretch(5) form.addRow(QLabel("Match"), hbox) hbox = QHBoxLayout() hbox.addWidget(self.replaceInTermsCheckBox) hbox.addWidget(self.replaceInPagesCheckBox) hbox.addWidget(self.replaceInNotesCheckBox) hbox.addStretch() form.addRow(self.replaceInLabel, hbox) hbox = QHBoxLayout() hbox.addWidget(self.startButton) hbox.addWidget(self.replaceButton) hbox.addWidget(self.skipButton) hbox.addWidget(self.stopButton) hbox.addStretch() form.addRow(hbox) self.setLayout(form) def createConnections(self): self.helpButton.clicked.connect(self.help) self.stopButton.clicked.connect(self.stop) self.startButton.clicked.connect(self.start) self.replaceButton.clicked.connect(self.replace) self.skipButton.clicked.connect(self.skip) self.searchLineEdit.textChanged.connect(self.updateUi) self.searchLineEdit.returnPressed.connect(self.doAction) self.replaceLineEdit.textChanged.connect(self.updateUi) self.replaceLineEdit.returnPressed.connect(self.doAction) for button in (self.literalRadioButton, self.regexRadioButton, self.ignoreCaseCheckBox, self.wholeWordsCheckBox, self.replaceInTermsCheckBox, self.replaceInPagesCheckBox, self.replaceInNotesCheckBox): button.clicked.connect(self.updateUi) def doAction(self): button = None if self.skipButton.isEnabled(): button = self.skipButton elif self.startButton.isEnabled(): button = self.startButton if button is not None: button.setFocus() button.click() if self.skipButton.isEnabled(): self.skipButton.setFocus() def help(self): self.state.help("xix_ref_panel_replace.html")
class RecorderControl(ScreenWithBackButton): def __init__(self, hyperdeck, atem, state, mainWindow): self.hyperdeck = hyperdeck self.atem = atem self.state = state self.mainWindow = mainWindow super(RecorderControl, self).__init__("Recorder", mainWindow) self.state.transportChange.connect(self.updateState) if self.hyperdeck: self.updateState(state.transport) def makeContent(self): layout = QGridLayout() self.btnGroupSDCard = QButtonGroup() self.sdSlotMapper = QSignalMapper() for i in range(2): btn = ExpandingButton() btn.setCheckable(True) btn.setText("SD card {}".format(i + 1)) btn.clicked.connect(self.sdSlotMapper.map) self.sdSlotMapper.setMapping(btn, i + 1) self.btnGroupSDCard.addButton(btn, i) layout.addWidget(btn, 0, i) self.sdSlotMapper.mapped.connect(self.hyperdeck.selectSlot) self.btnSetPreview = ExpandingButton() self.btnSetPreview.setText("To preview") self.btnSetPreview.clicked.connect(lambda: self.atem.setPreview(VideoSource.INPUT_7)) layout.addWidget(self.btnSetPreview, 0, 4) btnClearPeaks = ExpandingButton() btnClearPeaks.setText("Clear VU peaks") btnClearPeaks.clicked.connect(self.atem.resetAudioMixerPeaks) layout.addWidget(btnClearPeaks, 0, 5) self.btnGroupTransportMode = QButtonGroup() self.btnPlaybackMode = ExpandingButton() self.btnPlaybackMode.setCheckable(True) self.btnPlaybackMode.setChecked(True) self.btnPlaybackMode.setText("Playback mode") self.btnGroupTransportMode.addButton(self.btnPlaybackMode) self.btnPlaybackMode.clicked.connect(lambda: self._setRecordMode(False)) layout.addWidget(self.btnPlaybackMode, 1, 1, 1, 2) self.btnRecordMode = ExpandingButton() self.btnRecordMode.setCheckable(True) self.btnRecordMode.setText("Record mode") self.btnGroupTransportMode.addButton(self.btnRecordMode) self.btnRecordMode.clicked.connect(lambda: self._setRecordMode(True)) layout.addWidget(self.btnRecordMode, 1, 3, 1, 2) self.btnSkipBack = _make_button("Back", ":icons/media-skip-backward", self.hyperdeck.prev) layout.addWidget(self.btnSkipBack, 2, 0) self.btngroup = QButtonGroup() self.btnPlay = _make_button("Play", ":icons/media-playback-start", self.hyperdeck.play) self.btnPlay.setCheckable(True) self.btngroup.addButton(self.btnPlay) layout.addWidget(self.btnPlay, 2, 1) self.btnLoopPlay = _make_button("Loop", ":icons/media-playback-loop", lambda: self.hyperdeck.play(loop=True)) layout.addWidget(self.btnLoopPlay, 2, 2) self.btnSkipForward = _make_button("Forward", ":icons/media-skip-forward", self.hyperdeck.next) layout.addWidget(self.btnSkipForward, 2, 3) self.btnStop = _make_button("Stop", ":icons/media-playback-stop", self.hyperdeck.stop) self.btnStop.setCheckable(True) self.btngroup.addButton(self.btnStop) layout.addWidget(self.btnStop, 2, 4) self.btnRecord = _make_button("Record", ":icons/media-record", self.hyperdeck.record) self.btnRecord.setCheckable(True) self.btnRecord.setEnabled(False) self.btngroup.addButton(self.btnRecord) layout.addWidget(self.btnRecord, 2, 5) self.clipSelectionScreen = RecorderClipSelectionScreen(self.hyperdeck, self.state, self.mainWindow) self.state.clipsListChange.connect(self.clipSelectionScreen.populateClipsList) self.state.transportChange.connect(self.clipSelectionScreen._updateClipSelectionFromState) self.btnChooseClip = ExpandingButton() self.btnChooseClip.setText("Select clip") self.btnChooseClip.clicked.connect(self._showClipSelection) layout.addWidget(self.btnChooseClip, 3, 1, 1, 2) layout.setRowStretch(0, 1) layout.setRowStretch(1, 1) layout.setRowStretch(2, 2) layout.setRowStretch(3, 1) return layout def updateState(self, state): if 'status' in state: self.btnRecord.setChecked(state['status'] == TransportState.RECORD) self.btnPlay.setChecked(state['status'] == TransportState.PLAYING) self.btnStop.setChecked(state['status'] != TransportState.RECORD and state['status'] != TransportState.PLAYING) currentSlot = state.get('active slot', 1) self.btnGroupSDCard.button(currentSlot - 1).setChecked(True) def _setRecordMode(self, isRecordMode): if isRecordMode: self.btnSkipBack.setEnabled(False) self.btnSkipForward.setEnabled(False) self.btnPlay.setEnabled(False) self.btnPlay.setChecked(False) self.btnLoopPlay.setEnabled(False) self.btnRecord.setEnabled(True) self.hyperdeck.setTransportMode(TransportMode.RECORD) else: self.btnSkipBack.setEnabled(True) self.btnSkipForward.setEnabled(True) self.btnPlay.setEnabled(True) self.btnLoopPlay.setEnabled(True) self.btnRecord.setEnabled(False) self.btnRecord.setChecked(False) self.hyperdeck.setTransportMode(TransportMode.PLAYBACK) def _showClipSelection(self): self.hyperdeck.broadcastClipsList() self.mainWindow.showScreen(self.clipSelectionScreen)
class RecorderControl(ScreenWithBackButton): def __init__(self, hyperdeck, atem, state, mainWindow): self.hyperdeck = hyperdeck self.atem = atem self.state = state self.mainWindow = mainWindow super(RecorderControl, self).__init__("Recorder", mainWindow) self.state.transportChange.connect(self.updateState) if self.hyperdeck: self.updateState(state.transport) def makeContent(self): layout = QGridLayout() self.btnGroupSDCard = QButtonGroup() self.sdSlotMapper = QSignalMapper() for i in range(2): btn = ExpandingButton() btn.setCheckable(True) btn.setText("SD card {}".format(i + 1)) btn.clicked.connect(self.sdSlotMapper.map) self.sdSlotMapper.setMapping(btn, i + 1) self.btnGroupSDCard.addButton(btn, i) layout.addWidget(btn, 0, i) self.sdSlotMapper.mapped.connect(self.hyperdeck.selectSlot) self.btnSetPreview = ExpandingButton() self.btnSetPreview.setText("To preview") self.btnSetPreview.clicked.connect( lambda: self.atem.setPreview(VideoSource.INPUT_7)) layout.addWidget(self.btnSetPreview, 0, 4) btnClearPeaks = ExpandingButton() btnClearPeaks.setText("Clear VU peaks") btnClearPeaks.clicked.connect(self.atem.resetAudioMixerPeaks) layout.addWidget(btnClearPeaks, 0, 5) self.btnGroupTransportMode = QButtonGroup() self.btnPlaybackMode = ExpandingButton() self.btnPlaybackMode.setCheckable(True) self.btnPlaybackMode.setChecked(True) self.btnPlaybackMode.setText("Playback mode") self.btnGroupTransportMode.addButton(self.btnPlaybackMode) self.btnPlaybackMode.clicked.connect( lambda: self._setRecordMode(False)) layout.addWidget(self.btnPlaybackMode, 1, 1, 1, 2) self.btnRecordMode = ExpandingButton() self.btnRecordMode.setCheckable(True) self.btnRecordMode.setText("Record mode") self.btnGroupTransportMode.addButton(self.btnRecordMode) self.btnRecordMode.clicked.connect(lambda: self._setRecordMode(True)) layout.addWidget(self.btnRecordMode, 1, 3, 1, 2) self.btnSkipBack = _make_button("Back", ":icons/media-skip-backward", self.hyperdeck.prev) layout.addWidget(self.btnSkipBack, 2, 0) self.btngroup = QButtonGroup() self.btnPlay = _make_button("Play", ":icons/media-playback-start", self.hyperdeck.play) self.btnPlay.setCheckable(True) self.btngroup.addButton(self.btnPlay) layout.addWidget(self.btnPlay, 2, 1) self.btnLoopPlay = _make_button("Loop", ":icons/media-playback-loop", lambda: self.hyperdeck.play(loop=True)) layout.addWidget(self.btnLoopPlay, 2, 2) self.btnSkipForward = _make_button("Forward", ":icons/media-skip-forward", self.hyperdeck.next) layout.addWidget(self.btnSkipForward, 2, 3) self.btnStop = _make_button("Stop", ":icons/media-playback-stop", self.hyperdeck.stop) self.btnStop.setCheckable(True) self.btngroup.addButton(self.btnStop) layout.addWidget(self.btnStop, 2, 4) self.btnRecord = _make_button("Record", ":icons/media-record", self.hyperdeck.record) self.btnRecord.setCheckable(True) self.btnRecord.setEnabled(False) self.btngroup.addButton(self.btnRecord) layout.addWidget(self.btnRecord, 2, 5) self.clipSelectionScreen = RecorderClipSelectionScreen( self.hyperdeck, self.state, self.mainWindow) self.state.clipsListChange.connect( self.clipSelectionScreen.populateClipsList) self.state.transportChange.connect( self.clipSelectionScreen._updateClipSelectionFromState) self.btnChooseClip = ExpandingButton() self.btnChooseClip.setText("Select clip") self.btnChooseClip.clicked.connect(self._showClipSelection) layout.addWidget(self.btnChooseClip, 3, 1, 1, 2) layout.setRowStretch(0, 1) layout.setRowStretch(1, 1) layout.setRowStretch(2, 2) layout.setRowStretch(3, 1) return layout def updateState(self, state): if 'status' in state: self.btnRecord.setChecked(state['status'] == TransportState.RECORD) self.btnPlay.setChecked(state['status'] == TransportState.PLAYING) self.btnStop.setChecked( state['status'] != TransportState.RECORD and state['status'] != TransportState.PLAYING) currentSlot = state.get('active slot', 1) self.btnGroupSDCard.button(currentSlot - 1).setChecked(True) def _setRecordMode(self, isRecordMode): if isRecordMode: self.btnSkipBack.setEnabled(False) self.btnSkipForward.setEnabled(False) self.btnPlay.setEnabled(False) self.btnPlay.setChecked(False) self.btnLoopPlay.setEnabled(False) self.btnRecord.setEnabled(True) self.hyperdeck.setTransportMode(TransportMode.RECORD) else: self.btnSkipBack.setEnabled(True) self.btnSkipForward.setEnabled(True) self.btnPlay.setEnabled(True) self.btnLoopPlay.setEnabled(True) self.btnRecord.setEnabled(False) self.btnRecord.setChecked(False) self.hyperdeck.setTransportMode(TransportMode.PLAYBACK) def _showClipSelection(self): self.hyperdeck.broadcastClipsList() self.mainWindow.showScreen(self.clipSelectionScreen)
class BlindsControl(ScreenWithBackButton): ''' Controls for the blinds. ''' def __init__(self, controller, mainWindow): self.controller = controller ScreenWithBackButton.__init__(self, "Blinds", mainWindow) def makeContent(self): layout = QGridLayout() self.blinds = QButtonGroup() for i in range(1, 7): btn = IDedButton(i) btn.setText(str(i)) layout.addWidget(btn, 0, i - 1) btn.setCheckable(True) self.blinds.addButton(btn, i) btnAll = IDedButton(0) btnAll.setText("All") layout.addWidget(btnAll, 0, 6) btnAll.setCheckable(True) btnAll.setChecked(True) self.blinds.addButton(btnAll, 0) iconSize = QSize(96, 96) btnRaise = ExpandingButton() btnRaise.setText("Raise") btnRaise.setIcon(QIcon("icons/go-up.svg")) btnRaise.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnRaise, 1, 1, 1, 3) btnRaise.setIconSize(iconSize) btnRaise.clicked.connect(self.raiseUp) btnLower = ExpandingButton() btnLower.setText("Lower") btnLower.setIcon(QIcon("icons/go-down.svg")) btnLower.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnLower, 2, 1, 1, 3) btnLower.setIconSize(iconSize) btnLower.clicked.connect(self.lowerDown) btnStop = ExpandingButton() btnStop.setText("Stop") btnStop.setIcon(QIcon("icons/process-stop.svg")) btnStop.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnStop, 1, 4, 2, 2) btnStop.setIconSize(iconSize) btnStop.clicked.connect(self.stop) return layout def raiseUp(self): blindID = self.blinds.checkedId() try: self.controller.raiseUp("Blinds", blindID) except NamingError: self.mainWindow.errorBox(StringConstants.nameErrorText) except ProtocolError: self.mainWindow.errorBox(StringConstants.protocolErrorText) def lowerDown(self): blindID = self.blinds.checkedId() try: self.controller.lower("Blinds", blindID) except NamingError: self.mainWindow.errorBox(StringConstants.nameErrorText) except ProtocolError: self.mainWindow.errorBox(StringConstants.protocolErrorText) def stop(self): blindID = self.blinds.checkedId() try: self.controller.stop("Blinds", blindID) except NamingError: self.mainWindow.errorBox(StringConstants.nameErrorText) except ProtocolError: self.mainWindow.errorBox(StringConstants.protocolErrorText)
class BlindsControl(ScreenWithBackButton): ''' Controls for the blinds. ''' def __init__(self, blindsDevice, mainWindow): self.blindsDevice = blindsDevice ScreenWithBackButton.__init__(self, "Blinds", mainWindow) def makeContent(self): layout = QGridLayout() self.blinds = QButtonGroup() for i in range(1, 7): btn = IDedButton(i) btn.setText(str(i)) layout.addWidget(btn, 0, i - 1) btn.setCheckable(True) self.blinds.addButton(btn, i) btnAll = IDedButton(0) btnAll.setText("All") layout.addWidget(btnAll, 0, 6) btnAll.setCheckable(True) btnAll.setChecked(True) self.blinds.addButton(btnAll, 0) btnRaise = SvgButton(":icons/go-up", 96, 96) btnRaise.setText("Raise") btnRaise.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnRaise, 1, 1, 1, 3) btnRaise.clicked.connect(self.raiseUp) btnLower = SvgButton(":icons/go-down", 96, 96) btnLower.setText("Lower") btnLower.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) layout.addWidget(btnLower, 2, 1, 1, 3) btnLower.clicked.connect(self.lowerDown) btnStop = SvgButton(":icons/process-stop", 96, 96) btnStop.setText("Stop") btnStop.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon) layout.addWidget(btnStop, 1, 4, 2, 2) btnStop.clicked.connect(self.stop) return layout @handlePyroErrors def raiseUp(self): blindID = self.blinds.checkedId() self.blindsDevice.raiseUp(blindID) @handlePyroErrors def lowerDown(self): blindID = self.blinds.checkedId() self.blindsDevice.lower(blindID) @handlePyroErrors def stop(self): blindID = self.blinds.checkedId() self.blindsDevice.stop(blindID)
class Ui_MainWindow(object): def setupUi(self, MainWindow): lbMinWidth = 65 # leMinWidth = 200 MainWindow.setObjectName("MainWindow") MainWindow.resize(400, 310) # self.centralwidget = QWidget(MainWindow) self.mainSplitter = QSplitter(Qt.Horizontal, MainWindow) self.mainSplitter.setObjectName("centralwidget") self.mainSplitter.setProperty("childrenCollapsible", False) MainWindow.setCentralWidget(self.mainSplitter) self.leftSplitter = QSplitter(Qt.Vertical, self.mainSplitter) self.leftSplitter.setProperty("childrenCollapsible", False) ##### login_gbox self.login_gbox = QGroupBox(self.leftSplitter) self.login_gbox.setFlat(True) self.login_gbox.setObjectName("login_gbox") login_gbox_layout = QVBoxLayout(self.login_gbox) login_gbox_csf_layout = QHBoxLayout() login_gbox_account_layout = QHBoxLayout() login_gbox_connect_layout = QHBoxLayout() login_gbox_layout.addLayout(login_gbox_csf_layout) login_gbox_layout.addLayout(login_gbox_account_layout) login_gbox_layout.addLayout(login_gbox_connect_layout) self.lb_client_secrets_file_path = QLabel(self.login_gbox) self.lb_client_secrets_file_path.setObjectName("lb_client_secrets_file_path") self.lb_client_secrets_file_path.setMinimumWidth(lbMinWidth) self.client_secrets_file_path_le = QLineEdit(self.login_gbox) self.client_secrets_file_path_le.setObjectName("client_secrets_file_path_le") self.client_secret_file_path_tBtn = QToolButton(self.login_gbox) self.client_secret_file_path_tBtn.setObjectName("client_secret_file_path_tBtn") login_gbox_csf_layout.addWidget(self.lb_client_secrets_file_path) login_gbox_csf_layout.addWidget(self.client_secrets_file_path_le) login_gbox_csf_layout.addWidget(self.client_secret_file_path_tBtn) self.lb_account = QLabel(self.login_gbox) self.lb_account.setMaximumWidth(lbMinWidth) self.lb_account.setObjectName("lb_account") self.remove_account_btn = QToolButton(self.login_gbox) self.remove_account_btn.setObjectName("remove_account_btn") self.remove_account_btn.setMinimumWidth(20) self.remove_account_btn.setEnabled(False) self.add_account_btn = QToolButton(self.login_gbox) self.add_account_btn.setObjectName("add_account_btn") self.add_account_btn.setMinimumWidth(20) self.accounts_cb = QComboBox(self.login_gbox) self.accounts_cb.setObjectName("accounts_cb") login_gbox_account_layout.addWidget(self.lb_account) login_gbox_account_layout.addWidget(self.remove_account_btn) login_gbox_account_layout.addWidget(self.add_account_btn) login_gbox_account_layout.addWidget(self.accounts_cb) self.lb_decryption_key = QLabel(self.login_gbox) self.lb_decryption_key.setObjectName("lb_decryption_key") self.lb_decryption_key.setMinimumWidth(lbMinWidth) self.lb_decryption_key.hide() self.decryption_key_le = QLineEdit(self.login_gbox) self.decryption_key_le.setEchoMode(QLineEdit.Password) self.decryption_key_le.setObjectName("decryption_key_le") self.decryption_key_le.hide() self.connect_btn = QPushButton(self.login_gbox) self.connect_btn.setEnabled(False) self.connect_btn.setObjectName("connect_btn") login_gbox_connect_layout.addWidget(self.lb_decryption_key) login_gbox_connect_layout.addWidget(self.decryption_key_le) login_gbox_connect_layout.addWidget(self.connect_btn) #### search_gbox self.search_gbox = QGroupBox(self.leftSplitter) self.search_gbox.setFlat(True) self.search_gbox.setObjectName("search_gbox") self.search_gbox.hide() search_gbox_layout = QVBoxLayout(self.search_gbox) search_gbox_mailbox_layout = QVBoxLayout() search_gbox_date_layout = QHBoxLayout() search_gbox_from_layout = QHBoxLayout() search_gbox_to_layout = QHBoxLayout() search_gbox_subject_layout = QHBoxLayout() search_gbox_threads_layout = QHBoxLayout() search_gbox_paramaters_layout = QHBoxLayout() search_gbox_layout.addLayout(search_gbox_mailbox_layout) search_gbox_layout.addLayout(search_gbox_date_layout) search_gbox_layout.addLayout(search_gbox_from_layout) search_gbox_layout.addLayout(search_gbox_to_layout) search_gbox_layout.addLayout(search_gbox_subject_layout) search_gbox_layout.addLayout(search_gbox_threads_layout) search_gbox_layout.addLayout(search_gbox_paramaters_layout) self.lb_select_mailbox = QLabel(self.search_gbox) self.lb_select_mailbox.setObjectName("lb_select_mailbox") self.mailboxes_lw = QListWidget(self.search_gbox) self.mailboxes_lw.setEditTriggers(QAbstractItemView.NoEditTriggers) self.mailboxes_lw.setSelectionMode(QAbstractItemView.ExtendedSelection) self.mailboxes_lw.setObjectName("mailboxes_lw") search_gbox_mailbox_layout.addWidget(self.lb_select_mailbox) search_gbox_mailbox_layout.addWidget(self.mailboxes_lw) self.after_date_cb = QCheckBox(self.search_gbox) self.after_date_cb.setObjectName("after_date_cb") self.after_date_cb.setMinimumWidth(lbMinWidth) self.after_date_cb.setMaximumWidth(lbMinWidth) self.after_date_edit = QDateEdit(self.search_gbox) self.after_date_edit.setCalendarPopup(True) self.after_date_edit.setObjectName("after_date_edit") self.after_date_edit.setDate(QDate.currentDate().addDays(-365)) self.after_date_edit.setMaximumDate(QDate.currentDate()) self.after_date_edit.setEnabled(False) self.before_date_cb = QCheckBox(self.search_gbox) self.before_date_cb.setObjectName("before_date_cb") self.before_date_cb.setMinimumWidth(70) self.before_date_cb.setMaximumWidth(70) self.before_date_edit = QDateEdit(self.search_gbox) self.before_date_edit.setCalendarPopup(True) self.before_date_edit.setObjectName("before_date_edit") self.before_date_edit.setDate(QDate.currentDate()) self.before_date_edit.setMaximumDate(QDate.currentDate()) self.before_date_edit.setEnabled(False) search_gbox_date_layout.addWidget(self.after_date_cb) search_gbox_date_layout.addWidget(self.after_date_edit) search_gbox_date_layout.addWidget(self.before_date_cb) search_gbox_date_layout.addWidget(self.before_date_edit) self.lb_from = QLabel(self.search_gbox) self.lb_from.setObjectName("lb_from") self.lb_from.setMinimumWidth(lbMinWidth) self.from_le = QLineEdit(self.search_gbox) self.from_le.setObjectName("from_le") search_gbox_from_layout.addWidget(self.lb_from) search_gbox_from_layout.addWidget(self.from_le) self.lb_to = QLabel(self.search_gbox) self.lb_to.setObjectName("lb_to") self.lb_to.setMinimumWidth(lbMinWidth) self.to_le = QLineEdit(self.search_gbox) self.to_le.setObjectName("to_le") search_gbox_to_layout.addWidget(self.lb_to) search_gbox_to_layout.addWidget(self.to_le) self.lb_subject = QLabel(self.search_gbox) self.lb_subject.setObjectName("lb_subject") self.lb_subject.setMinimumWidth(lbMinWidth) self.subject_le = QLineEdit(self.search_gbox) self.subject_le.setObjectName("subject_le") search_gbox_subject_layout.addWidget(self.lb_subject) search_gbox_subject_layout.addWidget(self.subject_le) self.lb_threads = QLabel(self.search_gbox) self.lb_threads.setObjectName("lb_threads") self.lb_threads.setMaximumWidth(lbMinWidth) self.thread_count_sb = QSpinBox(self.search_gbox) self.thread_count_sb.setMinimum(1) self.thread_count_sb.setMaximum(10) self.thread_count_sb.setObjectName("thread_count_sb") self.html_radio = QRadioButton(self.search_gbox) self.html_radio.setObjectName("html_radio") self.text_radio = QRadioButton(self.search_gbox) self.text_radio.setObjectName("text_radio") self.extactTypeButtonGroup = QButtonGroup(self) self.extactTypeButtonGroup.addButton(self.html_radio) self.extactTypeButtonGroup.addButton(self.text_radio) self.html_radio.setChecked(True) self.search_btn = QPushButton(self.search_gbox) self.search_btn.setObjectName("search_btn") search_gbox_threads_layout.addWidget(self.lb_threads) search_gbox_threads_layout.addWidget(self.thread_count_sb) search_gbox_threads_layout.addWidget(self.html_radio) search_gbox_threads_layout.addWidget(self.text_radio) search_gbox_threads_layout.addWidget(self.search_btn) self.parameters_cb = QCheckBox(self.search_gbox) self.parameters_cb.setText("") self.parameters_cb.setObjectName("parameters_cb") self.parameters_le = QLineEdit(self.search_gbox) self.parameters_le.setEnabled(False) self.parameters_le.setObjectName("parameters_le") search_gbox_paramaters_layout.addWidget(self.parameters_cb) search_gbox_paramaters_layout.addWidget(self.parameters_le) #### log_gbox self.log_gbox = QGroupBox(self.leftSplitter) self.log_gbox.setFlat(True) self.log_gbox.setObjectName("log_gbox") log_layout = QVBoxLayout(self.log_gbox) self.log_te = QTextEdit(self.log_gbox) self.log_te.setLineWrapMode(QTextEdit.NoWrap) self.log_te.setReadOnly(True) self.log_te.setTextInteractionFlags(Qt.TextSelectableByKeyboard | Qt.TextSelectableByMouse) self.log_te.setObjectName("log_te") self.disconnect_btn = QPushButton(self.log_gbox) self.disconnect_btn.setObjectName("disconnect_btn") self.disconnect_btn.hide() log_layout.addWidget(self.log_te) log_layout_btn = QHBoxLayout() log_layout.addLayout(log_layout_btn) log_layout_btn.addWidget(self.disconnect_btn) log_layout_btn.addStretch() #### links_gbox self.links_gbox = QGroupBox(self.mainSplitter) self.links_gbox.setFlat(True) self.links_gbox.setObjectName("links_gbox") self.links_gbox.hide() links_gbox_layout = QVBoxLayout(self.links_gbox) links_gbox_links_layout = QVBoxLayout() links_gbox_buttons_layout = QHBoxLayout() links_gbox_layout.addLayout(links_gbox_links_layout) links_gbox_layout.addLayout(links_gbox_buttons_layout) self.links_text_edit = QTextEdit(self.links_gbox) self.links_text_edit.setObjectName("links_text_edit") links_gbox_links_layout.addWidget(self.links_text_edit) self.export_txt_btn = QPushButton(self.links_gbox) self.export_txt_btn.setObjectName("export_txt_btn") self.export_txt_btn.setEnabled(False) self.export_html_btn = QPushButton(self.links_gbox) self.export_html_btn.setObjectName("export_html_btn") self.export_html_btn.setEnabled(False) links_gbox_buttons_layout.addWidget(self.export_txt_btn) links_gbox_buttons_layout.addWidget(self.export_html_btn) ### menubar self.menubar = QMenuBar(MainWindow) # self.menubar.setGeometry(QRect(0, 0, 860, 21)) self.menubar.setObjectName("menubar") self.menu_file = QMenu(self.menubar) self.menu_file.setObjectName("menu_file") self.menu_help = QMenu(self.menubar) self.menu_help.setObjectName("menu_help") MainWindow.setMenuBar(self.menubar) self.action_about = QAction(MainWindow) self.action_about.setObjectName("action_about") self.action_About_Qt = QAction(MainWindow) self.action_About_Qt.setObjectName("action_About_Qt") self.action_exit = QAction(MainWindow) self.action_exit.setObjectName("action_exit") self.actionSave = QAction(MainWindow) self.actionSave.setObjectName("actionSave") self.action_Gmail_Advanced_Search_Syntax = QAction(MainWindow) self.action_Gmail_Advanced_Search_Syntax.setObjectName("action_Gmail_Advanced_Search_Syntax") self.menu_file.addAction(self.action_exit) self.menu_help.addAction(self.action_Gmail_Advanced_Search_Syntax) self.menu_help.addSeparator() self.menu_help.addAction(self.action_about) self.menu_help.addAction(self.action_About_Qt) self.menubar.addAction(self.menu_file.menuAction()) self.menubar.addAction(self.menu_help.menuAction()) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) MainWindow.setTabOrder(self.client_secrets_file_path_le, self.client_secret_file_path_tBtn) MainWindow.setTabOrder(self.client_secret_file_path_tBtn, self.remove_account_btn) MainWindow.setTabOrder(self.remove_account_btn, self.add_account_btn) MainWindow.setTabOrder(self.add_account_btn, self.accounts_cb) MainWindow.setTabOrder(self.decryption_key_le, self.connect_btn) MainWindow.setTabOrder(self.connect_btn, self.log_te) MainWindow.setTabOrder(self.log_te, self.mailboxes_lw) MainWindow.setTabOrder(self.mailboxes_lw, self.after_date_cb) MainWindow.setTabOrder(self.after_date_cb, self.after_date_edit) MainWindow.setTabOrder(self.after_date_edit, self.before_date_cb) MainWindow.setTabOrder(self.before_date_cb, self.before_date_edit) MainWindow.setTabOrder(self.before_date_edit, self.from_le) MainWindow.setTabOrder(self.from_le, self.to_le) MainWindow.setTabOrder(self.to_le, self.subject_le) MainWindow.setTabOrder(self.subject_le, self.thread_count_sb) MainWindow.setTabOrder(self.thread_count_sb, self.html_radio) MainWindow.setTabOrder(self.html_radio, self.text_radio) MainWindow.setTabOrder(self.text_radio, self.search_btn) MainWindow.setTabOrder(self.search_btn, self.parameters_cb) MainWindow.setTabOrder(self.parameters_cb, self.parameters_le) MainWindow.setTabOrder(self.parameters_le, self.disconnect_btn) MainWindow.setTabOrder(self.disconnect_btn, self.links_text_edit) MainWindow.setTabOrder(self.links_text_edit, self.export_txt_btn) MainWindow.setTabOrder(self.export_txt_btn, self.export_html_btn) MainWindow.setTabOrder(self.export_html_btn, self.mailboxes_lw) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QApplication.translate("MainWindow", "Gmail URL Parser", None, QApplication.UnicodeUTF8)) self.login_gbox.setTitle(QApplication.translate("MainWindow", " Client secrets file path ", None, QApplication.UnicodeUTF8)) self.client_secrets_file_path_le.setPlaceholderText(QApplication.translate("MainWindow", "Please select your client secrets file", None, QApplication.UnicodeUTF8)) self.lb_client_secrets_file_path.setText(QApplication.translate("MainWindow", "Path", None, QApplication.UnicodeUTF8)) self.connect_btn.setText(QApplication.translate("MainWindow", "Connect", None, QApplication.UnicodeUTF8)) self.client_secret_file_path_tBtn.setText(QApplication.translate("MainWindow", "...", None, QApplication.UnicodeUTF8)) self.lb_account.setText(QApplication.translate("MainWindow", "Account", None, QApplication.UnicodeUTF8)) self.add_account_btn.setText(QApplication.translate("MainWindow", "+", None, QApplication.UnicodeUTF8)) self.remove_account_btn.setText(QApplication.translate("MainWindow", "-", None, QApplication.UnicodeUTF8)) self.decryption_key_le.setPlaceholderText(QApplication.translate("MainWindow", "Decryption key", None, QApplication.UnicodeUTF8)) self.lb_decryption_key.setText(QApplication.translate("MainWindow", "Key", None, QApplication.UnicodeUTF8)) self.log_gbox.setTitle(QApplication.translate("MainWindow", " Log ", None, QApplication.UnicodeUTF8)) self.search_gbox.setTitle(QApplication.translate("MainWindow", " Search Parameters ", None, QApplication.UnicodeUTF8)) self.lb_to.setText(QApplication.translate("MainWindow", "To", None, QApplication.UnicodeUTF8)) self.lb_from.setText(QApplication.translate("MainWindow", "From", None, QApplication.UnicodeUTF8)) self.lb_subject.setText(QApplication.translate("MainWindow", "Subject", None, QApplication.UnicodeUTF8)) self.search_btn.setText(QApplication.translate("MainWindow", "Search", None, QApplication.UnicodeUTF8)) self.after_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "yyyy-MM-dd", None, QApplication.UnicodeUTF8)) self.before_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "yyyy-MM-dd", None, QApplication.UnicodeUTF8)) self.lb_select_mailbox.setToolTip(QApplication.translate("MainWindow", "<html><head/><body><p>Select multiple items to select labels</p></body></html>", None, QApplication.UnicodeUTF8)) self.lb_select_mailbox.setText(QApplication.translate("MainWindow", "Select Mailbox or Labels", None, QApplication.UnicodeUTF8)) self.after_date_cb.setText(QApplication.translate("MainWindow", "After", None, QApplication.UnicodeUTF8)) self.before_date_cb.setText(QApplication.translate("MainWindow", "Before", None, QApplication.UnicodeUTF8)) self.html_radio.setText(QApplication.translate("MainWindow", "html", None, QApplication.UnicodeUTF8)) self.text_radio.setText(QApplication.translate("MainWindow", "text", None, QApplication.UnicodeUTF8)) self.lb_threads.setText(QApplication.translate("MainWindow", "Threads", None, QApplication.UnicodeUTF8)) self.links_gbox.setTitle(QApplication.translate("MainWindow", " Links ", None, QApplication.UnicodeUTF8)) self.disconnect_btn.setText(QApplication.translate("MainWindow", "Disconnect", None, QApplication.UnicodeUTF8)) self.export_txt_btn.setText(QApplication.translate("MainWindow", "Export as txt", None, QApplication.UnicodeUTF8)) self.export_html_btn.setText(QApplication.translate("MainWindow", "Export as HTML", None, QApplication.UnicodeUTF8)) self.menu_file.setTitle(QApplication.translate("MainWindow", "File", None, QApplication.UnicodeUTF8)) self.menu_help.setTitle(QApplication.translate("MainWindow", "Help", None, QApplication.UnicodeUTF8)) self.action_about.setText(QApplication.translate("MainWindow", "About", None, QApplication.UnicodeUTF8)) self.action_About_Qt.setText(QApplication.translate("MainWindow", "About Qt", None, QApplication.UnicodeUTF8)) self.action_exit.setText(QApplication.translate("MainWindow", "Exit", None, QApplication.UnicodeUTF8)) self.action_exit.setShortcut(QApplication.translate("MainWindow", "Ctrl+Q", None, QApplication.UnicodeUTF8)) self.actionSave.setText(QApplication.translate("MainWindow", "Save", None, QApplication.UnicodeUTF8)) self.action_Gmail_Advanced_Search_Syntax.setText(QApplication.translate("MainWindow", "Gmail Advanced Search Syntax", None, QApplication.UnicodeUTF8))
class ServiceBrowser(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.serviceManager = QServiceManager(self) self.registerExampleServices() self.initWidgets() self.reloadServicesList() self.setWindowTitle(self.tr("Services Browser")) def __del__(self): self.unregisterExampleServices() def currentInterfaceImplChanged(self, current, previous): if not current: return descriptor = current.data(Qt.UserRole) self.reloadAttributesList() self.reloadAttributesRadioButtonText() if descriptor.isValid(): self.defaultInterfaceButton.setText( self.tr("Set as default implementation for %s" % str(descriptor.interfaceName()))) self.defaultInterfaceButton.setEnabled(True) def reloadServicesList(self): self.servicesListWidget.clear() services = self.serviceManager.findServices() for serv in services: self.servicesListWidget.addItem(serv) self.servicesListWidget.addItem(self.showAllServicesItem) self._services = services def reloadInterfaceImplementationsList(self): serviceName = None allServices = self.servicesListWidget.currentItem().text( ) == self.showAllServicesItem.text() if self.servicesListWidget.currentItem() and not allServices: serviceName = self.servicesListWidget.currentItem().text() self.interfacesGroup.setTitle( self.tr("Interfaces implemented by %s" % str(serviceName))) else: self.interfacesGroup.setTitle( self.tr("All interface implementations")) descriptors = self.serviceManager.findInterfaces(serviceName) self.attributesListWidget.clear() self.interfacesListWidget.clear() self._i = [] for desc in descriptors: text = "%s %d.%d" % (desc.interfaceName(), desc.majorVersion(), desc.minorVersion()) if not serviceName: text += " (" + desc.serviceName() + ")" defaultInterfaceImpl = self.serviceManager.interfaceDefault( desc.interfaceName()) if desc == defaultInterfaceImpl: text += self.tr(" (default)") item = QListWidgetItem(text) item.setData(Qt.UserRole, desc) item._data = desc self.interfacesListWidget.addItem(item) self.defaultInterfaceButton.setEnabled(False) def reloadAttributesList(self): item = self.interfacesListWidget.currentItem() if not item: return selectedImpl = item.data(Qt.UserRole) implementationRef = None if self.selectedImplRadioButton.isChecked(): implementationRef = self.serviceManager.loadInterface(selectedImpl) else: implementationRef = self.serviceManager.loadInterface( selectedImpl.interfaceName()) self.attributesListWidget.clear() if not implementationRef: self.attributesListWidget.addItem( self.tr("(Error loading service plugin)")) return metaObject = implementationRef.metaObject() self.attributesGroup.setTitle( self.tr("Invokable attributes for %s class" % metaObject.className())) for i in range(metaObject.methodCount()): method = metaObject.method(i) self.attributesListWidget.addItem("[METHOD] " + method.signature()) for i in range(metaObject.propertyCount()): p = metaObject.property(i) self.attributesListWidget.addItem("[PROPERTY] " + p.name()) def setDefaultInterfaceImplementation(self): item = self.interfacesListWidget.currentItem() if not item: return descriptor = item.data(Qt.UserRole) if descriptor.isValid(): if self.serviceManager.setInterfaceDefault(descriptor): currentIndex = self.interfacesListWidget.row(item) self.reloadInterfaceImplementationsList() self.interfacesListWidget.setCurrentRow(currentIndex) else: print "Unable to set default service for interface:", descriptor.interfaceName( ) def registerExampleServices(self): exampleXmlFiles = [ "filemanagerservice.xml", "bluetoothtransferservice.xml" ] for fileName in exampleXmlFiles: path = "./xmldata/" + fileName self.serviceManager.addService(path) def unregisterExampleServices(self): self.serviceManager.removeService("FileManagerService") self.serviceManager.removeService("BluetoothTransferService") def reloadAttributesRadioButtonText(self): item = self.interfacesListWidget.currentItem() if not item: return selectedImpl = item.data(Qt.UserRole) defaultImpl = self.serviceManager.interfaceDefault( selectedImpl.interfaceName()) self.defaultImplRadioButton.setText( self.tr( "Default implementation for %s\n(currently provided by %s)" % (str(defaultImpl.interfaceName()), str(defaultImpl.serviceName())))) def initWidgets(self): self.showAllServicesItem = QListWidgetItem( self.tr("(All registered services)")) self.servicesListWidget = QListWidget() self.interfacesListWidget = QListWidget() self.interfacesListWidget.addItem(self.tr("(Select a service)")) self.attributesListWidget = QListWidget() self.attributesListWidget.addItem( self.tr("(Select an interface implementation)")) self.interfacesListWidget.setMinimumWidth(450) self.servicesListWidget.currentItemChanged.connect( self.reloadInterfaceImplementationsList) self.interfacesListWidget.currentItemChanged.connect( self.currentInterfaceImplChanged) self.defaultInterfaceButton = QPushButton( self.tr("Set as default implementation")) self.defaultInterfaceButton.setEnabled(False) self.defaultInterfaceButton.clicked.connect( self.setDefaultInterfaceImplementation) self.selectedImplRadioButton = QRadioButton( self.tr("Selected interface implementation")) self.defaultImplRadioButton = QRadioButton( self.tr("Default implementation")) self.selectedImplRadioButton.setChecked(True) self.radioButtons = QButtonGroup(self) self.radioButtons.addButton(self.selectedImplRadioButton) self.radioButtons.addButton(self.defaultImplRadioButton) self.radioButtons.buttonClicked.connect(self.reloadAttributesList) self.servicesGroup = QGroupBox(self.tr("Show services for:")) servicesLayout = QVBoxLayout() servicesLayout.addWidget(self.servicesListWidget) self.servicesGroup.setLayout(servicesLayout) self.interfacesGroup = QGroupBox(self.tr("Interface implementations")) interfacesLayout = QVBoxLayout() interfacesLayout.addWidget(self.interfacesListWidget) interfacesLayout.addWidget(self.defaultInterfaceButton) self.interfacesGroup.setLayout(interfacesLayout) self.attributesGroup = QGroupBox(self.tr("Invokable attributes")) attributesLayout = QVBoxLayout() self.attributesGroup.setLayout(attributesLayout) attributesLayout.addWidget(self.attributesListWidget) attributesLayout.addWidget(QLabel(self.tr("Show attributes for:"))) attributesLayout.addWidget(self.selectedImplRadioButton) attributesLayout.addWidget(self.defaultImplRadioButton) self.attributesGroup.setLayout(attributesLayout) layout = QGridLayout() layout.addWidget(self.servicesGroup, 0, 0) layout.addWidget(self.attributesGroup, 0, 1, 2, 1) layout.addWidget(self.interfacesGroup, 1, 0) self.setLayout(layout)
class ConfigDialog(QtGui.QDialog): pressedclosebutton = False moreToggling = False def automaticUpdatePromptCheck(self): if self.automaticupdatesCheckbox.checkState() == Qt.PartiallyChecked and not self.nostoreCheckbox.isChecked(): reply = QtGui.QMessageBox.question(self, "Syncplay", getMessage("promptforupdate-label"), QtGui.QMessageBox.StandardButton.Yes | QtGui.QMessageBox.StandardButton.No) if reply == QtGui.QMessageBox.Yes: self.automaticupdatesCheckbox.setChecked(True) else: self.automaticupdatesCheckbox.setChecked(False) def moreToggled(self): if self.moreToggling == False: self.moreToggling = True if self.showmoreCheckbox.isChecked(): self.tabListFrame.show() self.resetButton.show() self.nostoreCheckbox.show() self.saveMoreState(True) self.tabListWidget.setCurrentRow(0) self.ensureTabListIsVisible() else: self.tabListFrame.hide() self.resetButton.hide() self.nostoreCheckbox.hide() self.saveMoreState(False) self.stackedLayout.setCurrentIndex(0) self.adjustSize() self.setFixedSize(self.sizeHint()) self.moreToggling = False self.setFixedWidth(self.minimumSizeHint().width()) self.executablepathCombobox.setFixedWidth(self.mediapathTextbox.width()) def runButtonTextUpdate(self): if self.nostoreCheckbox.isChecked(): self.runButton.setText(getMessage("run-label")) else: self.runButton.setText(getMessage("storeandrun-label")) def openHelp(self): self.QtGui.QDesktopServices.openUrl(QUrl("http://syncplay.pl/guide/client/")) def _isURL(self, path): if path is None: return False if "http://" in path: return True def safenormcaseandpath(self, path): if self._isURL(path): return path else: return os.path.normcase(os.path.normpath(path)) def _tryToFillPlayerPath(self, playerpath, playerpathlist): settings = QSettings("Syncplay", "PlayerList") settings.beginGroup("PlayerList") savedPlayers = settings.value("PlayerList", []) if not isinstance(savedPlayers, list): savedPlayers = [] else: for i, savedPlayer in enumerate(savedPlayers): savedPlayers[i] = self.safenormcaseandpath(savedPlayer) playerpathlist = list(set(playerpathlist + savedPlayers)) settings.endGroup() foundpath = "" if playerpath != None and playerpath != "": if self._isURL(playerpath): foundpath = playerpath self.executablepathCombobox.addItem(foundpath) else: if not os.path.isfile(playerpath): expandedpath = PlayerFactory().getExpandedPlayerPathByPath(playerpath) if expandedpath != None and os.path.isfile(expandedpath): playerpath = expandedpath if os.path.isfile(playerpath): foundpath = playerpath self.executablepathCombobox.addItem(foundpath) for path in playerpathlist: if self._isURL(path): if foundpath == "": foundpath = path if path != playerpath: self.executablepathCombobox.addItem(path) elif os.path.isfile(path) and os.path.normcase(os.path.normpath(path)) != os.path.normcase(os.path.normpath(foundpath)): self.executablepathCombobox.addItem(path) if foundpath == "": foundpath = path if foundpath != "": settings.beginGroup("PlayerList") playerpathlist.append(self.safenormcaseandpath(foundpath)) settings.setValue("PlayerList", list(set(playerpathlist))) settings.endGroup() return foundpath def updateExecutableIcon(self): currentplayerpath = unicode(self.executablepathCombobox.currentText()) iconpath = PlayerFactory().getPlayerIconByPath(currentplayerpath) if iconpath != None and iconpath != "": self.executableiconImage.load(self.resourcespath + iconpath) self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(self.executableiconImage)) else: self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage())) def languageChanged(self): setLanguage(unicode(self.languageCombobox.itemData(self.languageCombobox.currentIndex()))) QtGui.QMessageBox.information(self, "Syncplay", getMessage("language-changed-msgbox-label")) def browsePlayerpath(self): options = QtGui.QFileDialog.Options() defaultdirectory = "" browserfilter = "All files (*)" if os.name == 'nt': browserfilter = "Executable files (*.exe);;All files (*)" if "PROGRAMFILES(X86)" in os.environ: defaultdirectory = os.environ["ProgramFiles(x86)"] elif "PROGRAMFILES" in os.environ: defaultdirectory = os.environ["ProgramFiles"] elif "PROGRAMW6432" in os.environ: defaultdirectory = os.environ["ProgramW6432"] elif sys.platform.startswith('linux'): defaultdirectory = "/usr/bin" elif sys.platform.startswith('darwin'): defaultdirectory = "/Applications/" elif "bsd" in sys.platform or sys.platform.startswith('dragonfly'): defaultdirectory = "/usr/local/bin" fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, "Browse for media player executable", defaultdirectory, browserfilter, "", options) if fileName: self.executablepathCombobox.setEditText(os.path.normpath(fileName)) def loadLastUpdateCheckDate(self): settings = QSettings("Syncplay", "Interface") settings.beginGroup("Update") self.lastCheckedForUpdates = settings.value("lastChecked", None) if self.lastCheckedForUpdates: if self.config["lastCheckedForUpdates"] is not None and self.config["lastCheckedForUpdates"] is not "": if self.lastCheckedForUpdates > datetime.strptime(self.config["lastCheckedForUpdates"], "%Y-%m-%d %H:%M:%S.%f"): self.config["lastCheckedForUpdates"] = str(self.lastCheckedForUpdates) else: self.config["lastCheckedForUpdates"] = str(self.lastCheckedForUpdates) def loadMediaBrowseSettings(self): settings = QSettings("Syncplay", "MediaBrowseDialog") settings.beginGroup("MediaBrowseDialog") self.mediadirectory = settings.value("mediadir", "") settings.endGroup() def saveMediaBrowseSettings(self): settings = QSettings("Syncplay", "MediaBrowseDialog") settings.beginGroup("MediaBrowseDialog") settings.setValue("mediadir", self.mediadirectory) settings.endGroup() def getMoreState(self): settings = QSettings("Syncplay", "MoreSettings") settings.beginGroup("MoreSettings") morestate = unicode.lower(unicode(settings.value("ShowMoreSettings", "false"))) settings.endGroup() if morestate == "true": return True else: return False def saveMoreState(self, morestate): settings = QSettings("Syncplay", "MoreSettings") settings.beginGroup("MoreSettings") settings.setValue("ShowMoreSettings", morestate) settings.endGroup() def browseMediapath(self): self.loadMediaBrowseSettings() options = QtGui.QFileDialog.Options() if os.path.isdir(self.mediadirectory): defaultdirectory = self.mediadirectory elif os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.MoviesLocation)): defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.MoviesLocation) elif os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.HomeLocation)): defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.HomeLocation) else: defaultdirectory = "" browserfilter = "All files (*)" fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, "Browse for media files", defaultdirectory, browserfilter, "", options) if fileName: self.mediapathTextbox.setText(os.path.normpath(fileName)) self.mediadirectory = os.path.dirname(fileName) self.saveMediaBrowseSettings() def _saveDataAndLeave(self): self.automaticUpdatePromptCheck() self.loadLastUpdateCheckDate() self.processWidget(self, lambda w: self.saveValues(w)) if self.hostTextbox.text(): self.config['host'] = self.hostTextbox.text() if ":" in self.hostTextbox.text() else self.hostTextbox.text() + ":" + unicode(constants.DEFAULT_PORT) else: self.config['host'] = None self.config['playerPath'] = unicode(self.safenormcaseandpath(self.executablepathCombobox.currentText())) self.config['language'] = unicode(self.languageCombobox.itemData(self.languageCombobox.currentIndex())) if self.mediapathTextbox.text() == "": self.config['file'] = None elif os.path.isfile(os.path.abspath(self.mediapathTextbox.text())): self.config['file'] = os.path.abspath(self.mediapathTextbox.text()) else: self.config['file'] = unicode(self.mediapathTextbox.text()) self.pressedclosebutton = True self.close() return def closeEvent(self, event): if self.pressedclosebutton == False: sys.exit() def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: sys.exit() def dragEnterEvent(self, event): data = event.mimeData() urls = data.urls() if urls and urls[0].scheme() == 'file': event.acceptProposedAction() def dropEvent(self, event): data = event.mimeData() urls = data.urls() if urls and urls[0].scheme() == 'file': dropfilepath = os.path.abspath(unicode(event.mimeData().urls()[0].toLocalFile())) if dropfilepath[-4:].lower() == ".exe": self.executablepathCombobox.setEditText(dropfilepath) else: self.mediapathTextbox.setText(dropfilepath) def processWidget(self, container, torun): for widget in container.children(): self.processWidget(widget, torun) if hasattr(widget, 'objectName') and widget.objectName() and widget.objectName()[:3] != "qt_": torun(widget) def loadTooltips(self, widget): tooltipName = widget.objectName().lower().split(constants.CONFIG_NAME_MARKER)[0] + "-tooltip" if tooltipName[:1] == constants.INVERTED_STATE_MARKER or tooltipName[:1] == constants.LOAD_SAVE_MANUALLY_MARKER: tooltipName = tooltipName[1:] widget.setToolTip(getMessage(tooltipName)) def loadValues(self, widget): valueName = str(widget.objectName()) if valueName[:1] == constants.LOAD_SAVE_MANUALLY_MARKER: return if isinstance(widget, QCheckBox) and widget.objectName(): if valueName[:1] == constants.INVERTED_STATE_MARKER: valueName = valueName[1:] inverted = True else: inverted = False if self.config[valueName] is None: widget.setTristate(True) widget.setCheckState(Qt.PartiallyChecked) widget.stateChanged.connect(lambda: widget.setTristate(False)) else: widget.setChecked(self.config[valueName] != inverted) elif isinstance(widget, QRadioButton): radioName, radioValue = valueName.split(constants.CONFIG_NAME_MARKER)[1].split(constants.CONFIG_VALUE_MARKER) if self.config[radioName] == radioValue: widget.setChecked(True) elif isinstance(widget, QLineEdit): widget.setText(self.config[valueName]) def saveValues(self, widget): valueName = str(widget.objectName()) if valueName[:1] == constants.LOAD_SAVE_MANUALLY_MARKER: return if isinstance(widget, QCheckBox) and widget.objectName(): if widget.checkState() == Qt.PartiallyChecked: self.config[valueName] = None else: if valueName[:1] == constants.INVERTED_STATE_MARKER: valueName = valueName[1:] inverted = True else: inverted = False self.config[valueName] = widget.isChecked() != inverted elif isinstance(widget, QRadioButton): radioName, radioValue = valueName.split(constants.CONFIG_NAME_MARKER)[1].split(constants.CONFIG_VALUE_MARKER) if widget.isChecked(): self.config[radioName] = radioValue elif isinstance(widget, QLineEdit): self.config[valueName] = widget.text() def connectChildren(self, widget): widgetName = str(widget.objectName()) if self.subitems.has_key(widgetName) and isinstance(widget, QCheckBox): widget.stateChanged.connect(lambda: self.updateSubwidgets(self, widget)) self.updateSubwidgets(self, widget) def updateSubwidgets(self, container, parentwidget, subwidgets=None): widgetName = parentwidget.objectName() if not subwidgets: subwidgets = self.subitems[widgetName] for widget in container.children(): self.updateSubwidgets(widget, parentwidget, subwidgets) if hasattr(widget, 'objectName') and widget.objectName() and widget.objectName() in subwidgets: widget.setDisabled(not parentwidget.isChecked()) def addBasicTab(self): config = self.config playerpaths = self.playerpaths resourcespath = self.resourcespath error = self.error if self.datacleared == True: error = constants.ERROR_MESSAGE_MARKER + "{}".format(getMessage("gui-data-cleared-notification")) if config['host'] == None: host = "" elif ":" in config['host']: host = config['host'] else: host = config['host'] + ":" + str(config['port']) self.connectionSettingsGroup = QtGui.QGroupBox(getMessage("connection-group-title")) self.hostTextbox = QLineEdit(host, self) self.hostLabel = QLabel(getMessage("host-label"), self) self.usernameTextbox = QLineEdit(self) self.usernameTextbox.setObjectName("name") self.serverpassLabel = QLabel(getMessage("password-label"), self) self.defaultroomTextbox = QLineEdit(self) self.usernameLabel = QLabel(getMessage("name-label"), self) self.serverpassTextbox = QLineEdit(self) self.defaultroomLabel = QLabel(getMessage("room-label"), self) self.hostLabel.setObjectName("host") self.hostTextbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "host") self.usernameLabel.setObjectName("name") self.usernameTextbox.setObjectName("name") self.serverpassLabel.setObjectName("password") self.serverpassTextbox.setObjectName("password") self.defaultroomLabel.setObjectName("room") self.defaultroomTextbox.setObjectName("room") self.connectionSettingsLayout = QtGui.QGridLayout() self.connectionSettingsLayout.addWidget(self.hostLabel, 0, 0) self.connectionSettingsLayout.addWidget(self.hostTextbox, 0, 1) self.connectionSettingsLayout.addWidget(self.serverpassLabel, 1, 0) self.connectionSettingsLayout.addWidget(self.serverpassTextbox, 1, 1) self.connectionSettingsLayout.addWidget(self.usernameLabel, 2, 0) self.connectionSettingsLayout.addWidget(self.usernameTextbox, 2, 1) self.connectionSettingsLayout.addWidget(self.defaultroomLabel, 3, 0) self.connectionSettingsLayout.addWidget(self.defaultroomTextbox, 3, 1) self.connectionSettingsGroup.setLayout(self.connectionSettingsLayout) self.connectionSettingsGroup.setMaximumHeight(self.connectionSettingsGroup.minimumSizeHint().height()) self.mediaplayerSettingsGroup = QtGui.QGroupBox(getMessage("media-setting-title")) self.executableiconImage = QtGui.QImage() self.executableiconLabel = QLabel(self) self.executableiconLabel.setMinimumWidth(16) self.executablepathCombobox = QtGui.QComboBox(self) self.executablepathCombobox.setEditable(True) self.executablepathCombobox.currentIndexChanged.connect(self.updateExecutableIcon) self.executablepathCombobox.setEditText(self._tryToFillPlayerPath(config['playerPath'], playerpaths)) self.executablepathCombobox.setFixedWidth(165) self.executablepathCombobox.editTextChanged.connect(self.updateExecutableIcon) self.executablepathLabel = QLabel(getMessage("executable-path-label"), self) self.executablebrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("browse-label")) self.executablebrowseButton.clicked.connect(self.browsePlayerpath) self.mediapathTextbox = QLineEdit(config['file'], self) self.mediapathLabel = QLabel(getMessage("media-path-label"), self) self.mediabrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("browse-label")) self.mediabrowseButton.clicked.connect(self.browseMediapath) self.executablepathLabel.setObjectName("executable-path") self.executablepathCombobox.setObjectName("executable-path") self.mediapathLabel.setObjectName("media-path") self.mediapathTextbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "media-path") self.mediaplayerSettingsLayout = QtGui.QGridLayout() self.mediaplayerSettingsLayout.addWidget(self.executablepathLabel, 0, 0) self.mediaplayerSettingsLayout.addWidget(self.executableiconLabel, 0, 1) self.mediaplayerSettingsLayout.addWidget(self.executablepathCombobox, 0, 2) self.mediaplayerSettingsLayout.addWidget(self.executablebrowseButton, 0, 3) self.mediaplayerSettingsLayout.addWidget(self.mediapathLabel, 1, 0) self.mediaplayerSettingsLayout.addWidget(self.mediapathTextbox , 1, 2) self.mediaplayerSettingsLayout.addWidget(self.mediabrowseButton , 1, 3) self.mediaplayerSettingsGroup.setLayout(self.mediaplayerSettingsLayout) self.showmoreCheckbox = QCheckBox(getMessage("more-title")) self.showmoreCheckbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "more") self.basicOptionsFrame = QtGui.QFrame() self.basicOptionsLayout = QtGui.QVBoxLayout() if error: self.errorLabel = QLabel(self) if error[:1] != constants.ERROR_MESSAGE_MARKER: self.errorLabel.setStyleSheet(constants.STYLE_ERRORLABEL) else: error = error[1:] self.errorLabel.setStyleSheet(constants.STYLE_SUCCESSLABEL) self.errorLabel.setText(error) self.errorLabel.setAlignment(Qt.AlignCenter) self.basicOptionsLayout.addWidget(self.errorLabel, 0, 0) self.connectionSettingsGroup.setMaximumHeight(self.connectionSettingsGroup.minimumSizeHint().height()) self.basicOptionsLayout.setAlignment(Qt.AlignTop) self.basicOptionsLayout.addWidget(self.connectionSettingsGroup) self.basicOptionsLayout.addSpacing(5) self.mediaplayerSettingsGroup.setMaximumHeight(self.mediaplayerSettingsGroup.minimumSizeHint().height()) self.basicOptionsLayout.addWidget(self.mediaplayerSettingsGroup) self.basicOptionsFrame.setLayout(self.basicOptionsLayout) self.stackedLayout.addWidget(self.basicOptionsFrame) def addReadinessTab(self): self.readyFrame = QtGui.QFrame() self.readyLayout = QtGui.QVBoxLayout() self.readyFrame.setLayout(self.readyLayout) # Initial state self.readyInitialGroup = QtGui.QGroupBox(u"Initial readiness state") self.readyInitialLayout = QtGui.QVBoxLayout() self.readyInitialGroup.setLayout(self.readyInitialLayout) self.readyatstartCheckbox = QCheckBox(getMessage("readyatstart-label")) self.readyatstartCheckbox.setObjectName("readyAtStart") self.readyInitialLayout.addWidget(self.readyatstartCheckbox) self.readyLayout.addWidget(self.readyInitialGroup) # Automatically pausing self.readyPauseGroup = QtGui.QGroupBox(u"Pausing") self.readyPauseLayout = QtGui.QVBoxLayout() self.readyPauseGroup.setLayout(self.readyPauseLayout) self.pauseonleaveCheckbox = QCheckBox(getMessage("pauseonleave-label")) self.pauseonleaveCheckbox.setObjectName("pauseOnLeave") self.readyPauseLayout.addWidget(self.pauseonleaveCheckbox) self.readyLayout.addWidget(self.readyPauseGroup) # Unpausing self.readyUnpauseGroup = QtGui.QGroupBox(getMessage("unpause-title")) self.readyUnpauseLayout = QtGui.QVBoxLayout() self.readyUnpauseGroup.setLayout(self.readyUnpauseLayout) self.readyUnpauseButtonGroup = QButtonGroup() self.unpauseIfAlreadyReadyOption = QRadioButton(getMessage("unpause-ifalreadyready-option")) self.readyUnpauseButtonGroup.addButton(self.unpauseIfAlreadyReadyOption) self.unpauseIfAlreadyReadyOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.unpauseIfAlreadyReadyOption.setObjectName("unpause-ifalreadyready" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_IFALREADYREADY_MODE) self.readyUnpauseLayout.addWidget(self.unpauseIfAlreadyReadyOption) self.unpauseIfOthersReadyOption = QRadioButton(getMessage("unpause-ifothersready-option")) self.readyUnpauseButtonGroup.addButton(self.unpauseIfOthersReadyOption) self.unpauseIfOthersReadyOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.unpauseIfOthersReadyOption.setObjectName("unpause-ifothersready" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_IFOTHERSREADY_MODE) self.readyUnpauseLayout.addWidget(self.unpauseIfOthersReadyOption) self.unpauseIfMinUsersReadyOption = QRadioButton(getMessage("unpause-ifminusersready-option")) self.readyUnpauseButtonGroup.addButton(self.unpauseIfMinUsersReadyOption) self.unpauseIfMinUsersReadyOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.unpauseIfMinUsersReadyOption.setObjectName("unpause-ifminusersready" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_IFMINUSERSREADY_MODE) self.readyUnpauseLayout.addWidget(self.unpauseIfMinUsersReadyOption) self.unpauseAlwaysUnpauseOption = QRadioButton(getMessage("unpause-always")) self.readyUnpauseButtonGroup.addButton(self.unpauseAlwaysUnpauseOption) self.unpauseAlwaysUnpauseOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.unpauseAlwaysUnpauseOption.setObjectName("unpause-always" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_ALWAYS_MODE) self.readyUnpauseLayout.addWidget(self.unpauseAlwaysUnpauseOption) self.readyLayout.addWidget(self.readyUnpauseGroup) self.readyLayout.setAlignment(Qt.AlignTop) self.stackedLayout.addWidget(self.readyFrame) def addMiscTab(self): self.miscFrame = QtGui.QFrame() self.miscLayout = QtGui.QVBoxLayout() self.miscFrame.setLayout(self.miscLayout) self.coreSettingsGroup = QtGui.QGroupBox(getMessage("core-behaviour-title")) self.coreSettingsLayout = QtGui.QGridLayout() self.coreSettingsGroup.setLayout(self.coreSettingsLayout) ### Privacy: self.filenameprivacyLabel = QLabel(getMessage("filename-privacy-label"), self) self.filenameprivacyButtonGroup = QButtonGroup() self.filenameprivacySendRawOption = QRadioButton(getMessage("privacy-sendraw-option")) self.filenameprivacySendHashedOption = QRadioButton(getMessage("privacy-sendhashed-option")) self.filenameprivacyDontSendOption = QRadioButton(getMessage("privacy-dontsend-option")) self.filenameprivacyButtonGroup.addButton(self.filenameprivacySendRawOption) self.filenameprivacyButtonGroup.addButton(self.filenameprivacySendHashedOption) self.filenameprivacyButtonGroup.addButton(self.filenameprivacyDontSendOption) self.filesizeprivacyLabel = QLabel(getMessage("filesize-privacy-label"), self) self.filesizeprivacyButtonGroup = QButtonGroup() self.filesizeprivacySendRawOption = QRadioButton(getMessage("privacy-sendraw-option")) self.filesizeprivacySendHashedOption = QRadioButton(getMessage("privacy-sendhashed-option")) self.filesizeprivacyDontSendOption = QRadioButton(getMessage("privacy-dontsend-option")) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacySendRawOption) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacySendHashedOption) self.filesizeprivacyButtonGroup.addButton(self.filesizeprivacyDontSendOption) self.filenameprivacyLabel.setObjectName("filename-privacy") self.filenameprivacySendRawOption.setObjectName("privacy-sendraw" + constants.CONFIG_NAME_MARKER + "filenamePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_SENDRAW_MODE) self.filenameprivacySendHashedOption.setObjectName("privacy-sendhashed" + constants.CONFIG_NAME_MARKER + "filenamePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_SENDHASHED_MODE) self.filenameprivacyDontSendOption.setObjectName("privacy-dontsend" + constants.CONFIG_NAME_MARKER + "filenamePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_DONTSEND_MODE) self.filesizeprivacyLabel.setObjectName("filesize-privacy") self.filesizeprivacySendRawOption.setObjectName("privacy-sendraw" + constants.CONFIG_NAME_MARKER + "filesizePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_SENDRAW_MODE) self.filesizeprivacySendHashedOption.setObjectName("privacy-sendhashed" + constants.CONFIG_NAME_MARKER + "filesizePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_SENDHASHED_MODE) self.filesizeprivacyDontSendOption.setObjectName("privacy-dontsend" + constants.CONFIG_NAME_MARKER + "filesizePrivacyMode" + constants.CONFIG_VALUE_MARKER + constants.PRIVACY_DONTSEND_MODE) self.coreSettingsLayout.addWidget(self.filenameprivacyLabel, 3, 0) self.coreSettingsLayout.addWidget(self.filenameprivacySendRawOption, 3, 1, Qt.AlignLeft) self.coreSettingsLayout.addWidget(self.filenameprivacySendHashedOption, 3, 2, Qt.AlignLeft) self.coreSettingsLayout.addWidget(self.filenameprivacyDontSendOption, 3, 3, Qt.AlignLeft) self.coreSettingsLayout.addWidget(self.filesizeprivacyLabel, 4, 0) self.coreSettingsLayout.addWidget(self.filesizeprivacySendRawOption, 4, 1, Qt.AlignLeft) self.coreSettingsLayout.addWidget(self.filesizeprivacySendHashedOption, 4, 2, Qt.AlignLeft) self.coreSettingsLayout.addWidget(self.filesizeprivacyDontSendOption, 4, 3, Qt.AlignLeft) ## Syncplay internals self.internalSettingsGroup = QtGui.QGroupBox(getMessage("syncplay-internals-title")) self.internalSettingsLayout = QtGui.QVBoxLayout() self.internalSettingsGroup.setLayout(self.internalSettingsLayout) self.alwaysshowCheckbox = QCheckBox(getMessage("forceguiprompt-label")) self.alwaysshowCheckbox.setObjectName(constants.INVERTED_STATE_MARKER + "forceGuiPrompt") self.internalSettingsLayout.addWidget(self.alwaysshowCheckbox) self.automaticupdatesCheckbox = QCheckBox(getMessage("checkforupdatesautomatically-label")) self.automaticupdatesCheckbox.setObjectName("checkForUpdatesAutomatically") self.internalSettingsLayout.addWidget(self.automaticupdatesCheckbox) self.miscLayout.addWidget(self.coreSettingsGroup) self.miscLayout.addWidget(self.internalSettingsGroup) self.miscLayout.setAlignment(Qt.AlignTop) self.stackedLayout.addWidget(self.miscFrame) def addSyncTab(self): self.syncSettingsFrame = QtGui.QFrame() self.syncSettingsLayout = QtGui.QVBoxLayout() self.desyncSettingsGroup = QtGui.QGroupBox(getMessage("sync-otherslagging-title")) self.desyncOptionsFrame = QtGui.QFrame() self.desyncSettingsOptionsLayout = QtGui.QHBoxLayout() config = self.config self.slowdownCheckbox = QCheckBox(getMessage("slowondesync-label")) self.slowdownCheckbox.setObjectName("slowOnDesync") self.rewindCheckbox = QCheckBox(getMessage("rewindondesync-label")) self.rewindCheckbox.setObjectName("rewindOnDesync") self.fastforwardCheckbox = QCheckBox(getMessage("fastforwardondesync-label")) self.fastforwardCheckbox.setObjectName("fastforwardOnDesync") self.desyncSettingsLayout = QtGui.QGridLayout() self.desyncSettingsLayout.setSpacing(2) self.desyncFrame = QtGui.QFrame() self.desyncFrame.setLineWidth(0) self.desyncFrame.setMidLineWidth(0) self.desyncSettingsLayout.addWidget(self.slowdownCheckbox, 0, 0, 1, 2, Qt.AlignLeft) self.desyncSettingsLayout.addWidget(self.rewindCheckbox, 1, 0,1,2, Qt.AlignLeft) self.desyncSettingsLayout.setAlignment(Qt.AlignLeft) self.desyncSettingsGroup.setLayout(self.desyncSettingsLayout) self.desyncSettingsOptionsLayout.addWidget(self.desyncFrame) self.desyncFrame.setLayout(self.syncSettingsLayout) self.othersyncSettingsGroup = QtGui.QGroupBox(getMessage("sync-youlaggging-title")) self.othersyncOptionsFrame = QtGui.QFrame() self.othersyncSettingsLayout = QtGui.QGridLayout() self.dontslowwithmeCheckbox = QCheckBox(getMessage("dontslowdownwithme-label")) self.dontslowwithmeCheckbox.setObjectName("dontSlowDownWithMe") self.othersyncSettingsLayout.addWidget(self.dontslowwithmeCheckbox, 2, 0, 1, 2, Qt.AlignLeft) self.othersyncSettingsLayout.setAlignment(Qt.AlignLeft) self.othersyncSettingsLayout.addWidget(self.fastforwardCheckbox, 3, 0,1,2, Qt.AlignLeft) self.othersyncSettingsGroup.setLayout(self.othersyncSettingsLayout) self.othersyncSettingsGroup.setMaximumHeight(self.othersyncSettingsGroup.minimumSizeHint().height()) self.syncSettingsLayout.addWidget(self.othersyncSettingsGroup) self.syncSettingsLayout.addWidget(self.desyncSettingsGroup) self.syncSettingsFrame.setLayout(self.syncSettingsLayout) self.desyncSettingsGroup.setMaximumHeight(self.desyncSettingsGroup.minimumSizeHint().height()) self.syncSettingsLayout.setAlignment(Qt.AlignTop) self.stackedLayout.addWidget(self.syncSettingsFrame) def addMessageTab(self): self.messageFrame = QtGui.QFrame() self.messageLayout = QtGui.QVBoxLayout() self.messageLayout.setAlignment(Qt.AlignTop) # OSD self.osdSettingsGroup = QtGui.QGroupBox(getMessage("messages-osd-title")) self.osdSettingsLayout = QtGui.QVBoxLayout() self.osdSettingsFrame = QtGui.QFrame() self.showOSDCheckbox = QCheckBox(getMessage("showosd-label")) self.showOSDCheckbox.setObjectName("showOSD") self.osdSettingsLayout.addWidget(self.showOSDCheckbox) self.showSameRoomOSDCheckbox = QCheckBox(getMessage("showsameroomosd-label")) self.showSameRoomOSDCheckbox.setObjectName("showSameRoomOSD") self.showSameRoomOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.osdSettingsLayout.addWidget(self.showSameRoomOSDCheckbox) self.showNonControllerOSDCheckbox = QCheckBox(getMessage("shownoncontrollerosd-label")) self.showNonControllerOSDCheckbox.setObjectName("showNonControllerOSD") self.showNonControllerOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.osdSettingsLayout.addWidget(self.showNonControllerOSDCheckbox) self.showDifferentRoomOSDCheckbox = QCheckBox(getMessage("showdifferentroomosd-label")) self.showDifferentRoomOSDCheckbox.setObjectName("showDifferentRoomOSD") self.showDifferentRoomOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.osdSettingsLayout.addWidget(self.showDifferentRoomOSDCheckbox) self.slowdownOSDCheckbox = QCheckBox(getMessage("showslowdownosd-label")) self.slowdownOSDCheckbox.setObjectName("showSlowdownOSD") self.slowdownOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.osdSettingsLayout.addWidget(self.slowdownOSDCheckbox) self.showOSDWarningsCheckbox = QCheckBox(getMessage("showosdwarnings-label")) self.showOSDWarningsCheckbox.setObjectName("showOSDWarnings") self.showOSDWarningsCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.osdSettingsLayout.addWidget(self.showOSDWarningsCheckbox) self.subitems['showOSD'] = ["showSameRoomOSD", "showDifferentRoomOSD", "showSlowdownOSD", "showOSDWarnings", "showNonControllerOSD"] self.osdSettingsGroup.setLayout(self.osdSettingsLayout) self.osdSettingsGroup.setMaximumHeight(self.osdSettingsGroup.minimumSizeHint().height()) self.osdSettingsLayout.setAlignment(Qt.AlignTop) self.messageLayout.addWidget(self.osdSettingsGroup) # Other display self.displaySettingsGroup = QtGui.QGroupBox(getMessage("messages-other-title")) self.displaySettingsLayout = QtGui.QVBoxLayout() self.displaySettingsLayout.setAlignment(Qt.AlignTop & Qt.AlignLeft) self.displaySettingsFrame = QtGui.QFrame() self.showDurationNotificationCheckbox = QCheckBox(getMessage("showdurationnotification-label")) self.showDurationNotificationCheckbox.setObjectName("showDurationNotification") self.displaySettingsLayout.addWidget(self.showDurationNotificationCheckbox) self.languageFrame = QtGui.QFrame() self.languageLayout = QtGui.QHBoxLayout() self.languageLayout.setContentsMargins(0, 0, 0, 0) self.languageFrame.setLayout(self.languageLayout) self.languageFrame.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) self.languageLayout.setAlignment(Qt.AlignTop & Qt.AlignLeft) self.languageLabel = QLabel(getMessage("language-label"), self) self.languageCombobox = QtGui.QComboBox(self) self.languageCombobox.addItem(getMessage("automatic-language").format(getMessage("LANGUAGE", getInitialLanguage()))) self.languages = getLanguages() for lang in self.languages: self.languageCombobox.addItem(self.languages[lang], lang) if lang == self.config['language']: self.languageCombobox.setCurrentIndex(self.languageCombobox.count()-1) self.languageCombobox.currentIndexChanged.connect(self.languageChanged) self.languageLayout.addWidget(self.languageLabel, 1, 0) self.languageLayout.addWidget(self.languageCombobox, 1, 1) self.displaySettingsLayout.addWidget(self.languageFrame) self.languageLabel.setObjectName("language") self.languageCombobox.setObjectName("language") self.languageFrame.setMaximumWidth(self.languageFrame.minimumSizeHint().width()) self.displaySettingsGroup.setLayout(self.displaySettingsLayout) self.displaySettingsGroup.setMaximumHeight(self.displaySettingsGroup.minimumSizeHint().height()) self.displaySettingsLayout.setAlignment(Qt.AlignTop & Qt.AlignLeft) self.messageLayout.addWidget(self.displaySettingsGroup) # messageFrame self.messageFrame.setLayout(self.messageLayout) self.stackedLayout.addWidget(self.messageFrame) def addBottomLayout(self): config = self.config resourcespath = self.resourcespath self.bottomButtonFrame = QtGui.QFrame() self.bottomButtonLayout = QtGui.QHBoxLayout() self.helpButton = QtGui.QPushButton(QtGui.QIcon(self.resourcespath + 'help.png'), getMessage("help-label")) self.helpButton.setObjectName("help") self.helpButton.setMaximumSize(self.helpButton.sizeHint()) self.helpButton.pressed.connect(self.openHelp) self.resetButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'cog_delete.png'),getMessage("reset-label")) self.resetButton.setMaximumSize(self.resetButton.sizeHint()) self.resetButton.setObjectName("reset") self.resetButton.pressed.connect(self.resetSettings) self.runButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'accept.png'), getMessage("storeandrun-label")) self.runButton.pressed.connect(self._saveDataAndLeave) self.bottomButtonLayout.addWidget(self.helpButton) self.bottomButtonLayout.addWidget(self.resetButton) self.bottomButtonLayout.addWidget(self.runButton) self.bottomButtonFrame.setLayout(self.bottomButtonLayout) if config['noStore'] == True: self.runButton.setText(getMessage("run-label")) self.bottomButtonLayout.setContentsMargins(5,0,5,0) self.mainLayout.addWidget(self.bottomButtonFrame, 1, 0, 1, 2) self.bottomCheckboxFrame = QtGui.QFrame() self.bottomCheckboxFrame.setContentsMargins(0,0,0,0) self.bottomCheckboxLayout = QtGui.QGridLayout() self.alwaysshowCheckbox = QCheckBox(getMessage("forceguiprompt-label")) self.nostoreCheckbox = QCheckBox(getMessage("nostore-label")) self.bottomCheckboxLayout.addWidget(self.showmoreCheckbox) self.bottomCheckboxLayout.addWidget(self.nostoreCheckbox, 0, 2, Qt.AlignRight) self.alwaysshowCheckbox.setObjectName(constants.INVERTED_STATE_MARKER + "forceGuiPrompt") self.nostoreCheckbox.setObjectName("noStore") self.nostoreCheckbox.toggled.connect(self.runButtonTextUpdate) self.bottomCheckboxFrame.setLayout(self.bottomCheckboxLayout) self.mainLayout.addWidget(self.bottomCheckboxFrame, 2, 0, 1, 2) def tabList(self): self.tabListLayout = QtGui.QHBoxLayout() self.tabListFrame = QtGui.QFrame() self.tabListWidget = QtGui.QListWidget() self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + "house.png"),getMessage("basics-label"))) self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + "control_pause_blue.png"),getMessage("readiness-label"))) self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + "film_link.png"),getMessage("sync-label"))) self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + "comments.png"),getMessage("messages-label"))) self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + "cog.png"),getMessage("misc-label"))) self.tabListLayout.addWidget(self.tabListWidget) self.tabListFrame.setLayout(self.tabListLayout) self.tabListFrame.setFixedWidth(self.tabListFrame.minimumSizeHint().width()) self.tabListWidget.setStyleSheet(constants.STYLE_TABLIST) self.tabListWidget.currentItemChanged.connect(self.tabChange) self.tabListWidget.itemClicked.connect(self.tabChange) self.tabListWidget.itemPressed.connect(self.tabChange) self.mainLayout.addWidget(self.tabListFrame, 0, 0, 1, 1) def ensureTabListIsVisible(self): self.stackedFrame.setFixedWidth(self.stackedFrame.width()) while self.tabListWidget.horizontalScrollBar().isVisible() and self.tabListFrame.width() < 200: self.tabListFrame.setFixedWidth(self.tabListFrame.width()+1) def tabChange(self): self.setFocus() self.stackedLayout.setCurrentIndex(self.tabListWidget.currentRow()) def resetSettings(self): self.clearGUIData(leaveMore=True) self.config['resetConfig'] = True self.pressedclosebutton = True self.close() def showEvent(self, *args, **kwargs): self.ensureTabListIsVisible() self.setFixedWidth(self.minimumSizeHint().width()) self.executablepathCombobox.setFixedWidth(self.mediapathTextbox.width()) def clearGUIData(self, leaveMore=False): settings = QSettings("Syncplay", "PlayerList") settings.clear() settings = QSettings("Syncplay", "MediaBrowseDialog") settings.clear() settings = QSettings("Syncplay", "MainWindow") settings.clear() settings = QSettings("Syncplay", "Interface") settings.beginGroup("Update") settings.setValue("lastChecked", None) settings.endGroup() if not leaveMore: settings = QSettings("Syncplay", "MoreSettings") settings.clear() self.datacleared = True def __init__(self, config, playerpaths, error, defaultConfig): from syncplay import utils self.config = config self.defaultConfig = defaultConfig self.playerpaths = playerpaths self.datacleared = False self.config['resetConfig'] = False self.subitems = {} if self.config['clearGUIData'] == True: self.config['clearGUIData'] = False self.clearGUIData() self.QtGui = QtGui self.error = error if sys.platform.startswith('win'): resourcespath = utils.findWorkingDir() + "\\resources\\" else: resourcespath = utils.findWorkingDir() + "/resources/" self.posixresourcespath = utils.findWorkingDir().replace("\\","/") + "/resources/" self.resourcespath = resourcespath super(ConfigDialog, self).__init__() self.setWindowTitle(getMessage("config-window-title")) self.setWindowFlags(self.windowFlags() & Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) self.setWindowIcon(QtGui.QIcon(resourcespath + "syncplay.png")) self.stackedLayout = QtGui.QStackedLayout() self.stackedFrame = QtGui.QFrame() self.stackedFrame.setLayout(self.stackedLayout) self.mainLayout = QtGui.QGridLayout() self.mainLayout.setSpacing(0) self.mainLayout.setContentsMargins(0,0,0,0) self.addBasicTab() self.addReadinessTab() self.addSyncTab() self.addMessageTab() self.addMiscTab() self.tabList() self.mainLayout.addWidget(self.stackedFrame, 0, 1) self.addBottomLayout() if self.getMoreState() == False: self.tabListFrame.hide() self.nostoreCheckbox.hide() self.resetButton.hide() else: self.showmoreCheckbox.setChecked(True) self.tabListWidget.setCurrentRow(0) self.showmoreCheckbox.toggled.connect(self.moreToggled) self.setLayout(self.mainLayout) self.runButton.setFocus() self.setFixedSize(self.sizeHint()) self.setAcceptDrops(True) if constants.SHOW_TOOLTIPS: self.processWidget(self, lambda w: self.loadTooltips(w)) self.processWidget(self, lambda w: self.loadValues(w)) self.processWidget(self, lambda w: self.connectChildren(w))
class AllInputsPanel(QWidget): inputSelected = Signal(Input) def __init__(self, switcherState, parent=None): super(AllInputsPanel, self).__init__(parent) self.switcherState = switcherState self.selectedInput = None self.page = 0 self.sources = [] self.layout = QGridLayout() self.input_buttons = QButtonGroup() self.btnPageUp = ExpandingButton() self.btnPageUp.setIcon(QIcon(":icons/go-up")) self.btnPageUp.clicked.connect(lambda: self.setPage(self.page - 1)) self.layout.addWidget(self.btnPageUp, 0, 5, 3, 1) self.btnPageDown = ExpandingButton() self.btnPageDown.setIcon(QIcon(":icons/go-down")) self.btnPageDown.clicked.connect(lambda: self.setPage(self.page + 1)) self.layout.addWidget(self.btnPageDown, 3, 5, 3, 1) for col in range(5): self.layout.setColumnStretch(col, 1) for row in range(3): btn = InputButton(None) self.layout.addWidget(btn, row * 2, col, 2, 1) self.input_buttons.addButton(btn) btn.clicked.connect(self.selectInput) btn.setFixedWidth(120) self.setLayout(self.layout) self.switcherState.inputsChanged.connect(self.setSources) self.setSources() self.displayInputs() def setSources(self): self.sources = [ vs for vs in VideoSource if vs in self.switcherState.inputs.keys() ] def displayInputs(self): idx = 0 start = self.page * 15 end = start + 15 self.input_buttons.setExclusive(False) for btn in self.input_buttons.buttons(): btn.hide() btn.setChecked(False) self.input_buttons.setExclusive(True) for vs in self.sources[start:end]: inp = self.switcherState.inputs[vs] row = (idx / 5) * 2 col = idx % 5 btn = self.layout.itemAtPosition(row, col).widget() btn.setInput(inp) btn.setChecked(inp == self.selectedInput) btn.show() idx += 1 self.btnPageUp.setEnabled(self.page > 0) self.btnPageDown.setEnabled(end < len(self.switcherState.inputs)) def setPage(self, page): self.page = page self.displayInputs() def selectInput(self): inputBtn = self.sender() self.selectedInput = inputBtn.input self.inputSelected.emit(inputBtn.input)
class AdvancedCameraControl(ScreenWithBackButton): def __init__(self, controller, cameraID, mainScreen): self.controller = controller self.cameraID = cameraID super(AdvancedCameraControl, self).__init__(cameraID, mainScreen) def makeContent(self): layout = QGridLayout() self.posDisplay = QGridLayout() self.posDisplay.addWidget(QLabel("Pan:"), 0, 0) self.posDisplay.addWidget(QLabel("Tilt:"), 1, 0) self.posDisplay.addWidget(QLabel("Zoom:"), 2, 0) self.posDisplay.addWidget(QLabel(), 0, 1) self.posDisplay.addWidget(QLabel(), 1, 1) self.posDisplay.addWidget(QLabel(), 2, 1) layout.addLayout(self.posDisplay, 1, 0) btnGetPos = ExpandingButton() btnGetPos.setText("Get Position") btnGetPos.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) layout.addWidget(btnGetPos, 2, 0) btnGetPos.clicked.connect(self.displayPosition) whiteBalanceGrid = QGridLayout() wbTitle = QLabel("White Balance") wbTitle.setAlignment(Qt.AlignCenter) whiteBalanceGrid.addWidget(wbTitle, 0, 0, 1, 2) btnAuto = OptionButton() btnAuto.setText("Auto") btnAuto.clicked.connect(lambda: self.controller.whiteBalance(self.cameraID, CameraWhiteBalance.Auto)) whiteBalanceGrid.addWidget(btnAuto, 1, 0) btnIndoor = OptionButton() btnIndoor.setText("Indoor") btnIndoor.clicked.connect(lambda: self.controller.whiteBalance(self.cameraID, CameraWhiteBalance.Indoor)) whiteBalanceGrid.addWidget(btnIndoor, 2, 0) btnOutdoor = OptionButton() btnOutdoor.setText("Outdoor") btnOutdoor.clicked.connect(lambda: self.controller.whiteBalance(self.cameraID, CameraWhiteBalance.Outdoor)) whiteBalanceGrid.addWidget(btnOutdoor, 3, 0) btnOnePush = OptionButton() btnOnePush.setText("One Push") btnOnePush.clicked.connect(lambda: self.controller.whiteBalance(self.cameraID, CameraWhiteBalance.OnePush)) whiteBalanceGrid.addWidget(btnOnePush, 4, 0) btnOnePushTrigger = ExpandingButton() btnOnePushTrigger.setText("Set") btnOnePushTrigger.clicked.connect(lambda: self.controller.whiteBalance(self.cameraID, CameraWhiteBalance.Trigger)) btnOnePushTrigger.setEnabled(False) whiteBalanceGrid.addWidget(btnOnePushTrigger, 4, 1) self.wbOpts = QButtonGroup() self.wbOpts.addButton(btnAuto, 1) self.wbOpts.addButton(btnIndoor, 2) self.wbOpts.addButton(btnOutdoor, 3) self.wbOpts.addButton(btnOnePush, 4) self.wbOpts.buttonClicked.connect(lambda: btnOnePushTrigger.setEnabled(self.wbOpts.checkedId() == 4)) layout.addLayout(whiteBalanceGrid, 1, 1, 2, 1) return layout def displayPosition(self): pos = self.controller.getPosition(self.cameraID) self.posDisplay.itemAtPosition(0, 1).widget().setText(str(pos.pan)) self.posDisplay.itemAtPosition(1, 1).widget().setText(str(pos.tilt)) self.posDisplay.itemAtPosition(2, 1).widget().setText(str(pos.zoom))