def _setup_keybindings_ui(self): """ Create everything related to the keybindings tab """ layout = QFormLayout() self.keybinding_fullscreen_label = QLabel("Toggle Fullscreen:") self.keybinding_fullscreen = QKeySequenceEdit() layout.addRow(self.keybinding_fullscreen_label, self.keybinding_fullscreen) self.keybinding_save_image_label = QLabel("Save image:") self.keybinding_save_image = QKeySequenceEdit(QKeySequence(self.settings.keybinding_save_image)) layout.addRow(self.keybinding_save_image_label, self.keybinding_save_image) self.keybinding_trigger_image_label = QLabel("Trigger images via softwaretrigger:") self.keybinding_trigger_image = QKeySequenceEdit(QKeySequence(self.settings.keybinding_trigger_image)) layout.addRow(self.keybinding_trigger_image_label, self.keybinding_trigger_image) self.keybinding_open_dialog_label = QLabel("Open device dialog:") self.keybinding_open_dialog = QKeySequenceEdit(QKeySequence(self.settings.keybinding_open_dialog)) layout.addRow(self.keybinding_open_dialog_label, self.keybinding_open_dialog) self.keybindings_widget.setLayout(layout)
def build_ui(self): self.ui = Ui_Dialog() self.ui.setupUi(self) # Layout self.ui.pushButton_browse_directory.clicked.connect(self.on_update_default_directory) self.ui.lineEdit_default_directory.setText(self.model.get('Directory', 'default')) self.ui.lineEdit_background_color.setText(self.model.get('Look', 'background')) self.ui.pushButton_colorpicker.clicked.connect(self.on_update_background) self.generate_checkbox_list() self.generate_hotkey_list() # Set viewport behaviour self.ui.comboBox_default_viewport.setCurrentIndex(self.model.getint('Viewport', 'selection')) # Slideshow self.ui.horizontalSlider_speed_slideshow.setSliderPosition(self.model.getint('Slideshow', 'speed')) self.ui.lineEdit_speed_slideshow.setText(self.model.get('Slideshow', 'speed')) # Global self.ui.pushButton_save.clicked.connect(self.on_save) self.ui.pushButton_cancel.clicked.connect(self.close) # Hotkey assigning self.new_shortcut = QKeySequenceEdit(self.ui.lineEdit_new_shortcut) self.ui.pushButton_assign_hotkey.clicked.connect(self.on_new_shortcut) self.ui.pushButton_reset.clicked.connect(self.controller.load_defaults) # Select current language self.ui.listWidget_locale.setCurrentRow(self.model.get_locale_code_index(self.model.get('Language', 'code')))
def createFormGroupBox(self): self.formGroupBox = QGroupBox('Label form') self.lid = QLineEdit() self.lid.setValidator(QIntValidator()) self.label = QLineEdit() self.shortcut = QKeySequenceEdit() layout = QFormLayout() layout.addRow(QLabel('id:'), self.lid) layout.addRow(QLabel('label:'), self.label) layout.addRow(QLabel('shortcut:'), self.shortcut) self.formGroupBox.setLayout(layout)
def _getStylingGroupBox(self): boldLabel = QLabel('Bold') self.boldSeqEditBox = QKeySequenceEdit(self.settings['boldSeq']) boldLayout = QHBoxLayout() boldLayout.addWidget(boldLabel) boldLayout.addStretch() boldLayout.addWidget(self.boldSeqEditBox) italicLabel = QLabel('Italic') self.italicSeqEditBox = QKeySequenceEdit(self.settings['italicSeq']) italicLayout = QHBoxLayout() italicLayout.addWidget(italicLabel) italicLayout.addStretch() italicLayout.addWidget(self.italicSeqEditBox) underlineLabel = QLabel('Underline') self.underlineSeqEditBox = QKeySequenceEdit( self.settings['underlineSeq']) underlineLayout = QHBoxLayout() underlineLayout.addWidget(underlineLabel) underlineLayout.addStretch() underlineLayout.addWidget(self.underlineSeqEditBox) strikeLabel = QLabel('Strikethrough') self.strikeSeqEditBox = QKeySequenceEdit(self.settings['strikeSeq']) strikeLayout = QHBoxLayout() strikeLayout.addWidget(strikeLabel) strikeLayout.addStretch() strikeLayout.addWidget(self.strikeSeqEditBox) layout = QVBoxLayout() layout.addLayout(boldLayout) layout.addLayout(italicLayout) layout.addLayout(underlineLayout) layout.addLayout(strikeLayout) layout.addStretch() groupBox = QGroupBox('Styling') groupBox.setLayout(layout) return groupBox
def build_ui(self): self.ui = Ui_Dialog() self.ui.setupUi(self) # Layout self.ui.button_browse_directory.clicked.connect(self.on_update_default_directory) self.ui.input_default_directory.setText(self.model.get('Directory', 'default')) self.ui.input_background_color.setText(self.model.get('Look', 'background')) self.ui.button_colorpicker.clicked.connect(self.on_update_background) self.generate_checkbox_list() self.generate_hotkey_list() # Global self.ui.button_save.clicked.connect(self.on_save) self.ui.button_cancel.clicked.connect(self.close) # Hotkey assigning self.new_shortcut = QKeySequenceEdit(self.ui.input_new_shortcut) self.ui.button_assign.clicked.connect(self.on_new_shortcut) self.ui.button_reset.clicked.connect(self.controller.load_defaults)
def __init__(self, *args, model=None, **kwargs): super().__init__(*args, **kwargs) layout = QVBoxLayout() self.setLayout(layout) self.kbview = view = QTableView(parent=self) view.setModel(model) view.setSortingEnabled(True) view.setSelectionMode(QAbstractItemView.SingleSelection) view.setSelectionBehavior(QAbstractItemView.SelectRows) view.setEditTriggers(QAbstractItemView.NoEditTriggers) view.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) layout.addWidget(view) edit = QKeySequenceEdit(parent=self) edit.editingFinished.connect(partial(self.edit_finished, edit)) layout.addWidget(edit) view.show() edit.show()
def createFormGroupBox(self): self.formGroupBox = QGroupBox('Label form') self.lid = QLineEdit() self.lid.setValidator(QIntValidator()) self.label = QLineEdit() self.shortcut = QKeySequenceEdit() self.group = QLineEdit() self.pred_incomp = QLineEdit() layout = QFormLayout() layout.addRow(QLabel('id:'), self.lid) layout.addRow(QLabel('label:'), self.label) layout.addRow(QLabel('shortcut:'), self.shortcut) layout.addRow(QLabel('group:'), self.group) layout.addRow(QLabel('pred incompatibilities:'), self.pred_incomp) self.formGroupBox.setLayout(layout)
def __init__(self, **kwargs): super().__init__(**kwargs) self.setLayout(QVBoxLayout()) self.layout().setAlignment(Qt.AlignTop) self.behaviorsGroup = QGroupBox(self) self.behaviorsGroup.setLayout(QVBoxLayout()) self.layout().addWidget(self.behaviorsGroup) self.showPlaying = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.showPlaying) self.showDbMeters = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.showDbMeters) self.showAccurate = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.showAccurate) self.showSeek = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.showSeek) self.autoNext = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.autoNext) self.endListLayout = QHBoxLayout() self.behaviorsGroup.layout().addLayout(self.endListLayout) self.endListLabel = QLabel(self.behaviorsGroup) self.endListLayout.addWidget(self.endListLabel) self.endListBehavior = QComboBox(self.behaviorsGroup) self.endListBehavior.addItem(translate('ListLayout', 'Stop'), 'Stop') self.endListBehavior.addItem(translate('ListLayout', 'Restart'), 'Restart') self.endListLayout.addWidget(self.endListBehavior) self.endListLayout.setStretch(0, 2) self.endListLayout.setStretch(1, 5) self.goKeyLayout = QHBoxLayout() self.behaviorsGroup.layout().addLayout(self.goKeyLayout) self.goKeyLabel = QLabel(self.behaviorsGroup) self.goKeyLayout.addWidget(self.goKeyLabel) self.goKeyEdit = QKeySequenceEdit(self.behaviorsGroup) self.goKeyLayout.addWidget(self.goKeyEdit) self.goKeyLayout.setStretch(0, 2) self.goKeyLayout.setStretch(1, 5) self.useFadeGroup = QGroupBox(self) self.useFadeGroup.setLayout(QGridLayout()) self.layout().addWidget(self.useFadeGroup) # per-cue self.stopCueFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.stopCueFade, 0, 0) self.pauseCueFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.pauseCueFade, 1, 0) self.restartCueFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.restartCueFade, 2, 0) self.interruptCueFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.interruptCueFade, 3, 0) # all self.stopAllFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.stopAllFade, 0, 1) self.pauseAllFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.pauseAllFade, 1, 1) self.restartAllFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.restartAllFade, 2, 1) self.interruptAllFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.interruptAllFade, 3, 1) self.retranslateUi()
class ListLayoutSettings(SettingsPage): Name = 'List Layout' def __init__(self, **kwargs): super().__init__(**kwargs) self.setLayout(QVBoxLayout()) self.layout().setAlignment(Qt.AlignTop) self.behaviorsGroup = QGroupBox(self) self.behaviorsGroup.setLayout(QVBoxLayout()) self.layout().addWidget(self.behaviorsGroup) self.showPlaying = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.showPlaying) self.showDbMeters = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.showDbMeters) self.showAccurate = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.showAccurate) self.showSeek = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.showSeek) self.autoNext = QCheckBox(self.behaviorsGroup) self.behaviorsGroup.layout().addWidget(self.autoNext) self.endListLayout = QHBoxLayout() self.behaviorsGroup.layout().addLayout(self.endListLayout) self.endListLabel = QLabel(self.behaviorsGroup) self.endListLayout.addWidget(self.endListLabel) self.endListBehavior = QComboBox(self.behaviorsGroup) self.endListBehavior.addItem(translate('ListLayout', 'Stop'), 'Stop') self.endListBehavior.addItem(translate('ListLayout', 'Restart'), 'Restart') self.endListLayout.addWidget(self.endListBehavior) self.endListLayout.setStretch(0, 2) self.endListLayout.setStretch(1, 5) self.goKeyLayout = QHBoxLayout() self.behaviorsGroup.layout().addLayout(self.goKeyLayout) self.goKeyLabel = QLabel(self.behaviorsGroup) self.goKeyLayout.addWidget(self.goKeyLabel) self.goKeyEdit = QKeySequenceEdit(self.behaviorsGroup) self.goKeyLayout.addWidget(self.goKeyEdit) self.goKeyLayout.setStretch(0, 2) self.goKeyLayout.setStretch(1, 5) self.useFadeGroup = QGroupBox(self) self.useFadeGroup.setLayout(QGridLayout()) self.layout().addWidget(self.useFadeGroup) # per-cue self.stopCueFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.stopCueFade, 0, 0) self.pauseCueFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.pauseCueFade, 1, 0) self.restartCueFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.restartCueFade, 2, 0) self.interruptCueFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.interruptCueFade, 3, 0) # all self.stopAllFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.stopAllFade, 0, 1) self.pauseAllFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.pauseAllFade, 1, 1) self.restartAllFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.restartAllFade, 2, 1) self.interruptAllFade = QCheckBox(self.useFadeGroup) self.useFadeGroup.layout().addWidget(self.interruptAllFade, 3, 1) self.retranslateUi() def retranslateUi(self): self.behaviorsGroup.setTitle( translate('ListLayout', 'Default behaviors')) self.showPlaying.setText(translate('ListLayout', 'Show playing cues')) self.showDbMeters.setText(translate('ListLayout', 'Show dB-meters')) self.showAccurate.setText(translate('ListLayout', 'Show accurate time')) self.showSeek.setText(translate('ListLayout', 'Show seek-bars')) self.autoNext.setText(translate('ListLayout', 'Auto-select next cue')) self.endListLabel.setText(translate('ListLayout', 'At list end:')) self.goKeyLabel.setText(translate('ListLayout', 'Go key:')) self.useFadeGroup.setTitle(translate('ListLayout', 'Use fade')) self.stopCueFade.setText(translate('ListLayout', 'Stop Cue')) self.pauseCueFade.setText(translate('ListLayout', 'Pause Cue')) self.restartCueFade.setText(translate('ListLayout', 'Restart Cue')) self.interruptCueFade.setText(translate('ListLayout', 'Interrupt Cue')) self.stopAllFade.setText(translate('ListLayout', 'Stop All')) self.pauseAllFade.setText(translate('ListLayout', 'Pause All')) self.restartAllFade.setText(translate('ListLayout', 'Restart All')) self.interruptAllFade.setText(translate('ListLayout', 'Interrupt All')) def get_settings(self): settings = { 'showplaying': str(self.showPlaying.isChecked()), 'showdbmeters': str(self.showDbMeters.isChecked()), 'showseek': str(self.showSeek.isChecked()), 'showaccurate': str(self.showAccurate.isChecked()), 'autocontinue': str(self.autoNext.isChecked()), 'endlist': str(self.endListBehavior.currentData()), 'gokey': self.goKeyEdit.keySequence().toString(QKeySequence.NativeText), 'stopcuefade': str(self.stopCueFade.isChecked()), 'pausecuefade': str(self.pauseCueFade.isChecked()), 'restartcuefade': str(self.restartCueFade.isChecked()), 'interruptcuefade': str(self.interruptCueFade.isChecked()), 'stopallfade': str(self.stopAllFade.isChecked()), 'pauseallfade': str(self.pauseAllFade.isChecked()), 'restartallfade': str(self.restartAllFade.isChecked()), 'interruptallfade': str(self.interruptAllFade.isChecked()), } return {'ListLayout': settings} def load_settings(self, settings): settings = settings.get('ListLayout', {}) self.showPlaying.setChecked(settings.get('showplaying') == 'True') self.showDbMeters.setChecked(settings.get('showdbmeters') == 'True') self.showAccurate.setChecked(settings.get('showaccurate') == 'True') self.showSeek.setChecked(settings.get('showseek') == 'True') self.autoNext.setChecked(settings.get('autocontinue') == 'True') self.endListBehavior.setCurrentText( translate('ListLayout', settings.get('endlist', ''))) self.goKeyEdit.setKeySequence( QKeySequence(settings.get('gokey', 'Space'), QKeySequence.NativeText)) self.stopCueFade.setChecked(settings.get('stopcuefade') == 'True') self.pauseCueFade.setChecked(settings.get('pausecuefade') == 'True') self.restartCueFade.setChecked( settings.get('restartcuefade') == 'True') self.interruptCueFade.setChecked( settings.get('interruptcuefade') == 'True') self.stopAllFade.setChecked(settings.get('stopallfade') == 'True') self.pauseAllFade.setChecked(settings.get('pauseallfade') == 'True') self.restartAllFade.setChecked( settings.get('restartallfade') == 'True') self.interruptAllFade.setChecked( settings.get('interruptallfade') == 'True')
def one_key_sequence_edit(parent, name): edit = QKeySequenceEdit(parent) edit.setObjectName(name) return edit
class OptionDialog(QDialog): def __init__(self, parent, parent_ui): self.model = SettingsModel() self.controller = SettingsController(self.model) self.parent_ui = parent_ui super(OptionDialog, self).__init__(parent) self.build_ui() self.model.subscribe_update_func(self.update_ui_from_model) def build_ui(self): self.ui = Ui_Dialog() self.ui.setupUi(self) # Layout self.ui.button_browse_directory.clicked.connect(self.on_update_default_directory) self.ui.input_default_directory.setText(self.model.get('Directory', 'default')) self.ui.input_background_color.setText(self.model.get('Look', 'background')) self.ui.button_colorpicker.clicked.connect(self.on_update_background) self.generate_checkbox_list() self.generate_hotkey_list() # Global self.ui.button_save.clicked.connect(self.on_save) self.ui.button_cancel.clicked.connect(self.close) # Hotkey assigning self.new_shortcut = QKeySequenceEdit(self.ui.input_new_shortcut) self.ui.button_assign.clicked.connect(self.on_new_shortcut) self.ui.button_reset.clicked.connect(self.controller.load_defaults) def generate_checkbox_list(self): self.ui.checkbox_check_updates.setChecked(self.model.get('Misc', 'check_updates') == 'True') self.ui.checkbox_hide_menubar.setChecked(self.model.get('Misc', 'hide_menubar') == 'True') self.ui.checkbox_hide_statusbar.setChecked(self.model.get('Misc', 'hide_statusbar') == 'True') def generate_hotkey_list(self): for option in self.model.options('Hotkeys'): item = QListWidgetItem() item.setText(option) item.setData(Qt.UserRole, self.model.get('Hotkeys', option)) self.ui.listWidget.addItem(item) def on_update_default_directory(self): self.controller.update_default_directory() self.ui.input_default_directory.setText(self.model.get('Directory', 'default')) def on_update_background(self): self.controller.update_background() self.ui.input_background_color.setText(self.model.get('Look', 'background')) def on_listWidget_currentItemChanged(self, new, prev): if new is not None: self.selected_option = new.text() self.ui.input_cur_shortcut.setText(new.data(Qt.UserRole)) def on_new_shortcut(self): _new_shortcut = str(QKeySequence.toString(self.new_shortcut.keySequence())) self.controller.update_hotkey(self.selected_option, _new_shortcut) # Regenerate list self.ui.listWidget.clear() self.generate_hotkey_list() # Update inputs self.ui.input_cur_shortcut.setText(_new_shortcut) # possible self.model.get('Hotkeys', self.selected_option) self.new_shortcut.clear() def on_checkbox_check_updates_stateChanged(self, state): self.controller.update_boolean('check_updates', state) def on_checkbox_hide_menubar_stateChanged(self, state): self.controller.update_boolean('hide_menubar', state) def on_checkbox_hide_statusbar_stateChanged(self, state): self.controller.update_boolean('hide_statusbar', state) def on_save(self): self.controller.apply_settings() self.parent_ui.graphicsView.setBackgroundBrush(QBrush(QColor(self.model.get('Look', 'background')), Qt.SolidPattern)) self.close() def update_ui_from_model(self): self.ui.button_save.setEnabled(True)
class OptionsDialog(QDialog): def __init__(self, setting: Settings, have_dutils, parent=None): super(OptionsDialog, self).__init__(parent) self.settings = setting self.enabled_video = True # temporary toggle to disable video features as they do not exist self.enabled_logging = True self.enabled_keybindings = True self.enabled_dutils = have_dutils self.setWindowTitle("Tcam-Capture Options") self.layout = QVBoxLayout(self) self.setLayout(self.layout) self.tabs = QTabWidget() self.general_widget = QWidget() self.keybindings_widget = QWidget() self.logging_widget = QWidget() self.saving_widget = QWidget() self._setup_general_ui() self.tabs.addTab(self.general_widget, "General") if self.enabled_keybindings: self._setup_keybindings_ui() self.tabs.addTab(self.keybindings_widget, "Keybindings") self._setup_saving_ui() self.tabs.addTab(self.saving_widget, "Image/Video") self.layout.addWidget(self.tabs) # OK and Cancel buttons self.buttons = QDialogButtonBox( QDialogButtonBox.Reset | QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.layout.addWidget(self.buttons) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.buttons.clicked.connect(self.clicked) def _setup_general_ui(self): """ Create everything related to the general tab """ layout = QFormLayout() layout.setSpacing(20) layout.setVerticalSpacing(20) self.device_dialog_checkbox = QCheckBox(self) device_dialog_label = QLabel("Open device dialog on start:") layout.addRow(device_dialog_label, self.device_dialog_checkbox) self.reopen_device_checkbox = QCheckBox(self) reopen_device_label = QLabel("Reopen device on start(ignores device dialog):", self) layout.addRow(reopen_device_label, self.reopen_device_checkbox) self.use_dutils_checkbox = QCheckBox(self) self.use_dutils_label = QLabel("Use tiscamera dutils, if present:", self) layout.addRow(self.use_dutils_label, self.use_dutils_checkbox) if not self.enabled_dutils: self.use_dutils_label.setToolTip("Enabled when tiscamera-dutils are installed") self.use_dutils_label.setEnabled(False) self.use_dutils_checkbox.setToolTip("Enabled when tiscamera-dutils are installed") self.use_dutils_checkbox.setEnabled(False) self.general_widget.setLayout(layout) def _setup_saving_ui(self): """ Create everything related to the image/video saving tab """ encoder_dict = Encoder.get_encoder_dict() form_layout = QFormLayout() layout = QVBoxLayout() layout.addLayout(form_layout) location_layout = QHBoxLayout() location_label = QLabel("Where to save images/videos:", self) self.location_edit = QLineEdit(self) location_dialog_button = QPushButton("...", self) location_dialog_button.clicked.connect(self.open_file_dialog) location_layout.addWidget(self.location_edit) location_layout.addWidget(location_dialog_button) # maintain descriptions as own labels # pyqt seems to loose the descriptions somewhere # when simple strings are used or the qlabel does not have self as owner form_layout.addRow(location_label, location_layout) self.image_type_combobox = QComboBox(self) for key, value in encoder_dict.items(): if value.encoder_type == Encoder.MediaType.image: self.image_type_combobox.addItem(key) image_type_label = QLabel("Save images as:") self.image_type_combobox.currentIndexChanged['QString'].connect(self.image_name_suffix_changed) form_layout.addRow(image_type_label, self.image_type_combobox) if self.enabled_video: self.video_type_combobox = QComboBox(self) for key, value in encoder_dict.items(): if value.encoder_type == Encoder.MediaType.video: self.video_type_combobox.addItem(key) self.video_type_combobox.currentIndexChanged['QString'].connect(self.video_name_suffix_changed) video_type_label = QLabel("Save videos as:", self) form_layout.addRow(video_type_label, self.video_type_combobox) image_name_groupbox = QGroupBox("Image File Names") groupbox_layout = QFormLayout() image_name_groupbox.setLayout(groupbox_layout) self.image_name_preview = QLabel("<USER-PREFIX>-<SERIAL>-<FORMAT>-<TIMESTAMP>-<COUNTER>.png") self.image_name_preview_description = QLabel("Images will be named like:") groupbox_layout.addRow(self.image_name_preview_description, self.image_name_preview) self.image_name_prefix = QLineEdit() self.image_name_prefix.textChanged.connect(self.image_name_prefix_changed) self.image_name_prefix.setMaxLength(100) self.image_name_prefix_description = QLabel("User Prefix:", self) groupbox_layout.addRow(self.image_name_prefix_description, self.image_name_prefix) self.image_name_serial = QCheckBox(self) self.image_name_serial.toggled.connect(self.image_name_properties_toggled) self.image_name_serial_description = QLabel("Include Serial:") groupbox_layout.addRow(self.image_name_serial_description, self.image_name_serial) self.image_name_format = QCheckBox(self) self.image_name_format.toggled.connect(self.image_name_properties_toggled) self.image_name_format_description = QLabel("Include Format:") groupbox_layout.addRow(self.image_name_format_description, self.image_name_format) self.image_name_counter = QCheckBox(self) self.image_name_counter.toggled.connect(self.image_name_properties_toggled) self.image_name_counter_description = QLabel("Include Counter:") groupbox_layout.addRow(self.image_name_counter_description, self.image_name_counter) self.image_name_counter_box = QSpinBox(self) self.image_name_counter_box.setRange(1, 10) self.image_name_counter_box.valueChanged.connect(self.image_name_counter_changed) self.image_name_counter_box_description = QLabel("Counter Size:") groupbox_layout.addRow(self.image_name_counter_box_description, self.image_name_counter_box) self.image_name_counter.toggled.connect(self.toggle_image_counter_box_availability) self.image_name_counter.toggled.connect(self.image_name_properties_toggled) self.image_name_timestamp = QCheckBox(self) self.image_name_timestamp.toggled.connect(self.image_name_properties_toggled) self.image_name_timestamp_description = QLabel("Include Timestamp:") groupbox_layout.addRow(self.image_name_timestamp_description, self.image_name_timestamp) layout.addWidget(image_name_groupbox) video_groupbox = QGroupBox("Video File Names") video_layout = QFormLayout() video_groupbox.setLayout(video_layout) self.video_name_preview = QLabel("<USER-PREFIX>-<SERIAL>-<FORMAT>-<TIMESTAMP>-<COUNTER>.png") self.video_name_preview_description = QLabel("Videos will be named like:") video_layout.addRow(self.video_name_preview_description, self.video_name_preview) self.video_name_prefix = QLineEdit() self.video_name_prefix.textChanged.connect(self.video_name_prefix_changed) self.video_name_prefix.setMaxLength(100) self.video_name_prefix_description = QLabel("User Prefix:", self) video_layout.addRow(self.video_name_prefix_description, self.video_name_prefix) self.video_name_serial = QCheckBox(self) self.video_name_serial.toggled.connect(self.video_name_properties_toggled) self.video_name_serial_description = QLabel("Include Serial:") video_layout.addRow(self.video_name_serial_description, self.video_name_serial) self.video_name_format = QCheckBox(self) self.video_name_format.toggled.connect(self.video_name_properties_toggled) self.video_name_format_description = QLabel("Include Format:") video_layout.addRow(self.video_name_format_description, self.video_name_format) self.video_name_counter = QCheckBox(self) self.video_name_counter.toggled.connect(self.video_name_properties_toggled) self.video_name_counter_description = QLabel("Include Counter:") video_layout.addRow(self.video_name_counter_description, self.video_name_counter) self.video_name_counter_box = QSpinBox(self) self.video_name_counter_box.setRange(1, 10) self.video_name_counter_box.valueChanged.connect(self.video_name_counter_changed) self.video_name_counter_box_description = QLabel("Counter Size:") video_layout.addRow(self.video_name_counter_box_description, self.video_name_counter_box) self.video_name_counter.toggled.connect(self.toggle_video_counter_box_availability) self.video_name_counter.toggled.connect(self.video_name_properties_toggled) self.video_name_timestamp = QCheckBox(self) self.video_name_timestamp.toggled.connect(self.video_name_properties_toggled) self.video_name_timestamp_description = QLabel("Include Timestamp:") video_layout.addRow(self.video_name_timestamp_description, self.video_name_timestamp) layout.addWidget(video_groupbox) self.saving_widget.setLayout(layout) def image_name_prefix_changed(self, name: str): """""" self.settings.image_name.user_prefix = self.image_name_prefix.text() self.update_image_name_preview() def image_name_suffix_changed(self, suffix: str): """""" self.update_image_name_preview() def image_name_counter_changed(self, name: str): """""" self.settings.image_name.counter_size = self.image_name_counter_box.value() self.update_image_name_preview() def image_name_properties_toggled(self): """""" self.settings.image_name.include_timestamp = self.image_name_timestamp.isChecked() self.settings.image_name.include_counter = self.image_name_counter.isChecked() self.settings.image_name.include_format = self.image_name_format.isChecked() self.settings.image_name.include_serial = self.image_name_serial.isChecked() self.update_image_name_preview() def update_image_name_preview(self): preview_string = "" if self.settings.image_name.user_prefix != "": max_prefix_length = 15 prefix = (self.settings.image_name.user_prefix[:max_prefix_length] + '..') if len(self.settings.image_name.user_prefix) > max_prefix_length else self.settings.image_name.user_prefix preview_string += prefix if self.settings.image_name.include_serial: if preview_string != "": preview_string += "-" preview_string += "00001234" if self.settings.image_name.include_format: if preview_string != "": preview_string += "-" preview_string += "gbrg_1920x1080_15_1" if self.settings.image_name.include_timestamp: if preview_string != "": preview_string += "-" preview_string += "19701230T125503" if self.settings.image_name.include_counter: if preview_string != "": preview_string += "-" preview_string += '{message:0>{fill}}'.format(message=1, fill=self.settings.image_name.counter_size) if preview_string == "": preview_string = "image" preview_string += "." + self.image_type_combobox.currentText() self.image_name_preview.setText(preview_string) def video_name_prefix_changed(self, name: str): """""" self.settings.video_name.user_prefix = self.video_name_prefix.text() self.update_video_name_preview() def video_name_suffix_changed(self, suffix: str): """""" self.update_video_name_preview() def video_name_counter_changed(self, name: str): """""" self.settings.video_name.counter_size = self.video_name_counter_box.value() self.update_video_name_preview() def video_name_properties_toggled(self): """""" self.settings.video_name.include_timestamp = self.video_name_timestamp.isChecked() self.settings.video_name.include_counter = self.video_name_counter.isChecked() self.settings.video_name.include_format = self.video_name_format.isChecked() self.settings.video_name.include_serial = self.video_name_serial.isChecked() self.update_video_name_preview() def update_video_name_preview(self): preview_string = "" if self.settings.video_name.user_prefix != "": # This is a convenience change to the displayed string. # We only display an amount of max_prefix_length # chars to save screen space max_prefix_length = 15 prefix = (self.settings.video_name.user_prefix[:max_prefix_length] + '..') if len(self.settings.video_name.user_prefix) > max_prefix_length else self.settings.video_name.user_prefix preview_string += prefix if self.settings.video_name.include_serial: if preview_string != "": preview_string += "-" preview_string += "00001234" if self.settings.video_name.include_format: if preview_string != "": preview_string += "-" preview_string += "gbrg_1920x1080_15_1" if self.settings.video_name.include_timestamp: if preview_string != "": preview_string += "-" preview_string += "19701230T125503" if self.settings.video_name.include_counter: if preview_string != "": preview_string += "-" preview_string += '{message:0>{fill}}'.format(message=1, fill=self.settings.video_name.counter_size) if preview_string == "": preview_string = "video" preview_string += "." + self.video_type_combobox.currentText() self.video_name_preview.setText(preview_string) def toggle_image_counter_box_availability(self): """""" if self.image_name_counter.isChecked(): self.image_name_counter_box.setEnabled(True) else: self.image_name_counter_box.setEnabled(False) def toggle_video_counter_box_availability(self): """""" if self.video_name_counter.isChecked(): self.video_name_counter_box.setEnabled(True) else: self.video_name_counter_box.setEnabled(False) def _setup_keybindings_ui(self): """ Create everything related to the keybindings tab """ layout = QFormLayout() self.keybinding_fullscreen_label = QLabel("Toggle Fullscreen:") self.keybinding_fullscreen = QKeySequenceEdit() layout.addRow(self.keybinding_fullscreen_label, self.keybinding_fullscreen) self.keybinding_save_image_label = QLabel("Save image:") self.keybinding_save_image = QKeySequenceEdit(QKeySequence(self.settings.keybinding_save_image)) layout.addRow(self.keybinding_save_image_label, self.keybinding_save_image) self.keybinding_trigger_image_label = QLabel("Trigger images via softwaretrigger:") self.keybinding_trigger_image = QKeySequenceEdit(QKeySequence(self.settings.keybinding_trigger_image)) layout.addRow(self.keybinding_trigger_image_label, self.keybinding_trigger_image) self.keybinding_open_dialog_label = QLabel("Open device dialog:") self.keybinding_open_dialog = QKeySequenceEdit(QKeySequence(self.settings.keybinding_open_dialog)) layout.addRow(self.keybinding_open_dialog_label, self.keybinding_open_dialog) self.keybindings_widget.setLayout(layout) def set_settings(self, settings: Settings): self.location_edit.setText(settings.get_save_location()) self.image_type_combobox.setCurrentText(settings.get_image_type()) if self.enabled_video: self.video_type_combobox.setCurrentText(settings.get_video_type()) self.device_dialog_checkbox.setChecked(settings.show_device_dialog_on_startup) self.reopen_device_checkbox.setChecked(settings.reopen_device_on_startup) self.use_dutils_checkbox.setChecked(settings.use_dutils) # # keybindings # if self.enabled_keybindings: self.keybinding_fullscreen.setKeySequence(QKeySequence(self.settings.keybinding_fullscreen)) self.keybinding_save_image.setKeySequence(QKeySequence(self.settings.keybinding_save_image)) self.keybinding_trigger_image.setKeySequence(QKeySequence(self.settings.keybinding_trigger_image)) self.keybinding_open_dialog.setKeySequence(QKeySequence(self.settings.keybinding_open_dialog)) # # image saving # if settings.image_name.include_timestamp: self.image_name_timestamp.blockSignals(True) self.image_name_timestamp.toggle() self.image_name_timestamp.blockSignals(False) if settings.image_name.include_counter: self.image_name_counter.blockSignals(True) self.image_name_counter.toggle() self.image_name_counter.blockSignals(False) self.image_name_counter_box.blockSignals(True) self.image_name_counter_box.setValue(settings.image_name.counter_size) self.image_name_counter_box.blockSignals(False) self.toggle_image_counter_box_availability() if settings.image_name.include_format: self.image_name_format.blockSignals(True) self.image_name_format.toggle() self.image_name_format.blockSignals(False) if settings.image_name.include_serial: self.image_name_serial.blockSignals(True) self.image_name_serial.toggle() self.image_name_serial.blockSignals(False) self.image_name_prefix.blockSignals(True) self.image_name_prefix.setText(settings.image_name.user_prefix) self.image_name_prefix.blockSignals(False) self.update_image_name_preview() # # video saving # if settings.video_name.include_timestamp: self.video_name_timestamp.blockSignals(True) self.video_name_timestamp.toggle() self.video_name_timestamp.blockSignals(False) if settings.video_name.include_counter: self.video_name_counter.blockSignals(True) self.video_name_counter.toggle() self.video_name_counter.blockSignals(False) self.video_name_counter_box.blockSignals(True) self.video_name_counter_box.setValue(settings.video_name.counter_size) self.video_name_counter_box.blockSignals(False) self.toggle_video_counter_box_availability() if settings.video_name.include_format: self.video_name_format.blockSignals(True) self.video_name_format.toggle() self.video_name_format.blockSignals(False) if settings.video_name.include_serial: self.video_name_serial.blockSignals(True) self.video_name_serial.toggle() self.video_name_serial.blockSignals(False) self.video_name_prefix.blockSignals(True) self.video_name_prefix.setText(settings.video_name.user_prefix) self.video_name_prefix.blockSignals(False) self.update_video_name_preview() def save_settings(self): self.settings.save_location = self.location_edit.text() self.settings.image_type = self.image_type_combobox.currentText() if self.enabled_video: self.settings.video_type = self.video_type_combobox.currentText() self.settings.show_device_dialog_on_startup = self.device_dialog_checkbox.isChecked() self.settings.reopen_device_on_startup = self.reopen_device_checkbox.isChecked() self.settings.use_dutils = self.use_dutils_checkbox.isChecked() # # keybindings # if self.enabled_keybindings: self.settings.keybinding_fullscreen = self.keybinding_fullscreen.keySequence().toString() self.settings.keybinding_save_image = self.keybinding_save_image.keySequence().toString() self.settings.keybinding_trigger_image = self.keybinding_trigger_image.keySequence().toString() self.settings.keybinding_open_dialog = self.keybinding_open_dialog.keySequence().toString() # # image saving # self.settings.image_name.include_timestamp = self.image_name_timestamp.isChecked() self.settings.image_name.include_counter = self.image_name_counter.isChecked() if self.image_name_counter.isChecked(): self.settings.image_name.counter_size = self.image_name_counter_box.value() self.settings.image_name.include_format = self.image_name_format.isChecked() self.settings.image_name.include_serial = self.image_name_serial.isChecked() self.settings.image_name.user_prefix = self.image_name_prefix.text() # # video saving # self.settings.video_name.include_timestamp = self.video_name_timestamp.isChecked() self.settings.video_name.include_counter = self.video_name_counter.isChecked() if self.video_name_counter.isChecked(): self.settings.video_name.counter_size = self.video_name_counter_box.value() self.settings.video_name.include_format = self.video_name_format.isChecked() self.settings.video_name.include_serial = self.video_name_serial.isChecked() self.settings.video_name.user_prefix = self.video_name_prefix.text() def open_file_dialog(self): fdia = QFileDialog() fdia.setFileMode(QFileDialog.Directory) fdia.setWindowTitle("Select Directory for saving images and videos") if fdia.exec_(): self.location_edit.setText(fdia.selectedFiles()[0]) def get_location(self): return self.location_edit.text() def get_image_format(self): return self.image_type_combobox.currentText() def get_video_format(self): return self.video_type_combobox.currentText() def clicked(self, button): if self.buttons.buttonRole(button) == QDialogButtonBox.ResetRole: self.reset() def reset(self): """""" log.info("reset called") self.settings.reset() self.set_settings(self.settings) @staticmethod def get_options(settings, parent=None): dialog = OptionsDialog(settings, parent) if settings is not None: dialog.set_settings(settings) result = dialog.exec_() if result == QDialog.Accepted: dialog.save_settings() settings.save() return result == QDialog.Accepted
def initUI(self): entries = ['one', 'two', 'three', 'four', 'five', 'six', 'seven'] self.centralwidget = QWidget(self) grid = QGridLayout() #Label grid.addWidget(QLabel("Label"), 0, 0) #QLineEdit grid.addWidget(QLineEdit("QLineEdit"), 0, 1) #QPlainTextEdit grid.addWidget(QPlainTextEdit("QPlainTextEdit"), 0, 2) #QListWidget listWidget = QListWidget() listWidget.addItems(entries) grid.addWidget(listWidget, 0, 3) #QScrollArea scrollArea = QScrollArea() formLayout = QFormLayout() formLayout.addRow(QLabel(entries[0])) formLayout.addRow(QLabel(entries[1])) formLayout.addRow(QLabel(entries[2])) formLayout.addRow(QLabel(entries[3])) formLayout.addRow(QLabel(entries[4])) formLayout.addRow(QLabel(entries[5])) formLayout.addRow(QLabel(entries[6])) #QGroupBox groupBox = QGroupBox("This Is Group Box") groupBox.setLayout(formLayout) scrollArea.setWidget(groupBox) scrollArea.setWidgetResizable(True) grid.addWidget(scrollArea, 0, 4) #QKeySequenceEdit grid.addWidget(QKeySequenceEdit("QKeySequenceEdit"), 0, 5) #QPushButton grid.addWidget(QPushButton("QPushButton"), 1, 0) #QRadioButton grid.addWidget(QRadioButton("QRadioButton"), 1, 1) #QCheckBox grid.addWidget(QCheckBox("QCheckBox"), 1, 2) #QComboBox comboBox = QComboBox() comboBox.addItems(entries) grid.addWidget(comboBox, 1, 3) #QDialogButtonBox grid.addWidget( QDialogButtonBox(QDialogButtonBox.Cancel | QDialogButtonBox.Ok), 1, 4) #QDoubleSpinBox grid.addWidget(QDoubleSpinBox(), 1, 5) self.setLayout(grid) self.setGeometry(300, 300, 300, 150) self.setWindowTitle("Controls") self.show()
class OptionDialog(QDialog): def __init__(self, parent): self.model = SettingsModel() self.controller = SettingsController(self.model) self.parent = parent super(OptionDialog, self).__init__(parent) self.build_ui() self.model.subscribe_update_func(self.update_ui_from_model) def build_ui(self): self.ui = Ui_Dialog() self.ui.setupUi(self) # Layout self.ui.pushButton_browse_directory.clicked.connect(self.on_update_default_directory) self.ui.lineEdit_default_directory.setText(self.model.get('Directory', 'default')) self.ui.lineEdit_background_color.setText(self.model.get('Look', 'background')) self.ui.pushButton_colorpicker.clicked.connect(self.on_update_background) self.generate_checkbox_list() self.generate_hotkey_list() # Set viewport behaviour self.ui.comboBox_default_viewport.setCurrentIndex(self.model.getint('Viewport', 'selection')) # Slideshow self.ui.horizontalSlider_speed_slideshow.setSliderPosition(self.model.getint('Slideshow', 'speed')) self.ui.lineEdit_speed_slideshow.setText(self.model.get('Slideshow', 'speed')) # Global self.ui.pushButton_save.clicked.connect(self.on_save) self.ui.pushButton_cancel.clicked.connect(self.close) # Hotkey assigning self.new_shortcut = QKeySequenceEdit(self.ui.lineEdit_new_shortcut) self.ui.pushButton_assign_hotkey.clicked.connect(self.on_new_shortcut) self.ui.pushButton_reset.clicked.connect(self.controller.load_defaults) # Select current language self.ui.listWidget_locale.setCurrentRow(self.model.get_locale_code_index(self.model.get('Language', 'code'))) def generate_checkbox_list(self): """Set all checkboxes according to their values.""" self.ui.checkBox_check_updates.setChecked(self.model.get('Misc', 'check_updates') == 'True') self.ui.checkBox_fullscreen_mode.setChecked(self.model.get('Misc', 'fullscreen_mode') == 'True') self.ui.checkBox_hide_menubar.setChecked(self.model.get('Misc', 'hide_menubar') == 'True') self.ui.checkBox_reverse_slideshow.setChecked(self.model.get('Slideshow', 'reverse') == 'True') self.ui.checkBox_restart_slideshow.setChecked(self.model.get('Slideshow', 'restart') == 'True') self.ui.checkBox_random_slideshow.setChecked(self.model.get('Slideshow', 'random') == 'True') def generate_hotkey_list(self): """Generate the hotkey list.""" for option in self.model.options('Hotkeys'): if not option.startswith(';'): item = QListWidgetItem() item.setText(option) item.setData(Qt.UserRole, self.model.get('Hotkeys', option)) self.ui.listWidget_hotkey.addItem(item) # Layout tab def on_update_default_directory(self): self.controller.update_default_directory() self.ui.lineEdit_default_directory.setText(self.model.get('Directory', 'default')) def on_update_background(self): self.controller.update_background() self.ui.lineEdit_background_color.setText(self.model.get('Look', 'background')) def on_checkBox_check_updates_stateChanged(self, state): self.controller.update_boolean('Misc', 'check_updates', state) def on_checkBox_fullscreen_mode_stateChanged(self, state): self.controller.update_boolean('Misc', 'fullscreen_mode', state) def on_checkBox_hide_menubar_stateChanged(self, state): self.controller.update_boolean('Misc', 'hide_menubar', state) @pyqtSlot(int) def on_comboBox_default_viewport_currentIndexChanged(self, index): self.controller.update_viewport_behaviour(index) # Hotkeys tab def on_listWidget_hotkey_currentItemChanged(self, new, prev): if new is not None: self.selected_option = new.text() self.ui.lineEdit_current_shortcut.setText(new.data(Qt.UserRole)) def on_new_shortcut(self): new_shortcut = str(QKeySequence.toString(self.new_shortcut.keySequence())) self.controller.update_hotkey(self.selected_option, new_shortcut) # Regenerate list self.ui.listWidget_hotkey.clear() self.generate_hotkey_list() # Update inputs self.ui.lineEdit_current_shortcut.setText(new_shortcut) self.new_shortcut.clear() # Slideshow tab def on_horizontalSlider_speed_slideshow_valueChanged(self, value): self.ui.lineEdit_speed_slideshow.setText(str(value)) self.controller.update_slideshow_speed(value) def on_checkBox_reverse_slideshow_stateChanged(self, state): self.controller.update_boolean('Slideshow', 'reverse', state) def on_checkBox_restart_slideshow_stateChanged(self, state): self.controller.update_boolean('Slideshow', 'restart', state) def on_checkBox_random_slideshow_stateChanged(self, state): self.controller.update_boolean('Slideshow', 'random', state) # Localization tab @pyqtSlot(int) def on_listWidget_locale_currentRowChanged(self, index): """Localization settings.""" self.controller.update_locale(index) # Save button def on_save(self): self.controller.apply_settings() self.parent.ui.graphicsView.setBackgroundBrush(QBrush(QColor(self.model.get('Look', 'background')), Qt.SolidPattern)) self.parent.model.announce_update() # Todo: dynamic config changes? self.close() notify = QMessageBox() notify.setWindowTitle("Configuration saved") notify.setText("Some changes only take effect after restarting the application.") notify.exec_() def update_ui_from_model(self): self.ui.pushButton_save.setEnabled(True)
def edit_finished(self, edit: QKeySequenceEdit, *args, **kwargs): sel = self.kbview.selectedIndexes() kb: Keybind = self.kbview.model().selectedData(sel) if kb: kb.update(edit.keySequence())