class KwFontDataChoicer(QWidget): u''' @version: 0.1.1 ''' fontChanged = pyqtSignal(str, name='fontChanged') font_sizeChanged = pyqtSignal(int, name='font_sizeChanged') def __init__(self, font='', size=10, *args, **kwargs): super(KwFontDataChoicer, self).__init__(*args, **kwargs) self.__fontChoice = QFontComboBox(self) self.__fontChoice.setCurrentFont(QFont(font)) #.setCurrentText(font) self.__fontChoice.currentIndexChanged[str].connect( self.fontChanged.emit) self.__font_sizeEdit = QSpinBox(self) self.__font_sizeEdit.setRange(5, 72) self.__font_sizeEdit.setValue(size) self.__font_sizeEdit.valueChanged[int].connect( self.font_sizeChanged.emit) layout = QHBoxLayout(self) layout.setSpacing(5) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.__fontChoice, 1) layout.addWidget(self.__font_sizeEdit, 0) @property def font_data(self): return self.__fontChoice.currentText(), self.__font_sizeEdit.value() @font_data.setter def font_data(self, font, size): self.__fontChoice.setCurrentText(font) self.__font_sizeEdit.setValue(size) @property def font(self): return self.__fontChoice.currentText() @font.setter def font(self, font): self.__fontChoice.setCurrentText(font) @property def size(self): return self.__font_sizeEdit.value() @size.setter def size(self, size): return self.__font_sizeEdit.setValue(size)
def __init__(self, parent=None): super().__init__() self.parent = parent hlayout = QHBoxLayout() self.setLayout(hlayout) font_combobox = QFontComboBox() font_combobox.setEditable(False) font_combobox.setFixedHeight(30) font_combobox.setStyleSheet("QFontComboBox {background-color: white; color: black; border-radius: 3px;\ border-color: lightgray; border-style: solid; border-width:2px;} \ QFontComboBox::down-arrow {image: url(/usr/share/icons/breeze/actions/24/arrow-down)} \ QFontComboBox::drop-down {border:none;}") font_combobox.setCurrentText(settings().value("Subtitle/font")) hlayout.addWidget(font_combobox) self.color_button = QPushButton() self.color_button.setFixedSize(30, 30) self.color_button.setStyleSheet("QPushButton {border: 1px solid black; border-radius: 3px; \ background-color: %s; }"%(settings().value("Subtitle/color") or QColor("#ffffff")).name()) hlayout.addWidget(self.color_button) self.color_button.clicked.connect(self.colorSelected) font_combobox.currentIndexChanged[str].connect(self.fontChanged)
class SettingsEditDialog(QDialog): def __init__(self, parent=None): super().__init__(parent) self.setModal(True) self.setWindowTitle('Settings') self.setMinimumWidth(400) self.accepted.connect(self.save) # Editor group self.font_family_input = QFontComboBox() self.font_size_input = QSpinBox() self.font_size_input.setRange(8, 24) self.font_size_input.setSuffix(' pt') self.tab_size_input = QSpinBox() self.tab_size_input.setRange(1, 16) self.tab_size_input.setSuffix(' spaces') self.enable_text_wrapping_input = QCheckBox('Enable text wrapping') editor_layout = QFormLayout() editor_layout.addRow('Font family:', self.font_family_input) editor_layout.addRow('Font size:', self.font_size_input) editor_layout.addRow('Tab size:', self.tab_size_input) editor_layout.addRow('', self.enable_text_wrapping_input) editor_group = QGroupBox('Editor') editor_group.setLayout(editor_layout) # Buttons edit_project_button = QPushButton('Edit default project...') edit_project_button.clicked.connect( lambda: projects.show_edit_dialog('default')) save_button = QPushButton('OK') save_button.setDefault(True) save_button.clicked.connect(self.accept) cancel_button = QPushButton('Cancel') cancel_button.clicked.connect(self.reject) button_layout = QHBoxLayout() button_layout.addWidget(edit_project_button, 1, Qt.AlignLeft) button_layout.addWidget(save_button, 0, Qt.AlignRight) button_layout.addWidget(cancel_button) # Main layout main_layout = QVBoxLayout() main_layout.addWidget(editor_group) main_layout.addLayout(button_layout) self.setLayout(main_layout) def show(self): font = QFont(value('editor/font_family')) self.font_family_input.setCurrentFont(font) self.font_family_input.setCurrentText(QFontInfo(font).family()) self.font_family_input.setFocus(Qt.OtherFocusReason) self.font_size_input.setValue(value('editor/font_size')) self.tab_size_input.setValue(value('editor/tab_size')) self.enable_text_wrapping_input.setChecked( value('editor/enable_text_wrapping')) super().show() def save(self): set_value('editor/font_family', QFontInfo(self.font_family_input.currentFont()).family()) set_value('editor/font_size', self.font_size_input.value()) set_value('editor/tab_size', self.tab_size_input.value()) set_value('editor/enable_text_wrapping', self.enable_text_wrapping_input.isChecked()) edit_dialog_saved().emit()