def onColorPicker(self): dlg = QColorDialog() if self._color is not None: dlg.setCurrentColor(QColor(self._color)) if dlg.exec_() == dlg.Accepted: self.setColor(dlg.currentColor().name())
def slot_call_color_dialog(self): dialog = QColorDialog(self) dialog.setCurrentColor(self.currentColor) if dialog.exec_() == QDialog.Accepted: self.currentColor = dialog.currentColor() self.updateImagePreview()
def showColorPicker(self): dialogue = QColorDialog() dialogue.setCurrentColor(self._colour) dialogue.setOption(QColorDialog.ShowAlphaChannel) if dialogue.exec_(): self.setColor(dialogue.currentColor())
def __choose_color(self): dialog = QColorDialog(self.window()) dialog.setOption(QColorDialog.ShowAlphaChannel, True) dialog.setCurrentColor(QColor.fromRgba(self.__color.argb)) if dialog.exec_() == QColorDialog.Accepted: self.__color = Color(dialog.currentColor().rgba()) self.__refresh_label() self.color_changed.emit(self.__color)
def on_treeView_doubleClicked(self, index): if index.column() not in [1, 2, 4]: return color = QColor(index.data(Qt.EditRole)) dialog = QColorDialog(self) dialog.setCurrentColor(color) if dialog.exec_() == QDialog.Accepted: self.pickedModel.setData(index, dialog.currentColor())
def on_color_click(self): init_color = QColor(self._plot_settings['widget']['color']) _colordialog = QColorDialog(init_color) _colordialog.exec_() x = _colordialog.currentColor().name() self._plot_settings['widget']['color'] = x self.ui.lblColor.setStyleSheet( 'padding: 0 10; background-color: {}'.format(x))
def pickColor(self): if self._readOnly: return dialog = QColorDialog(self._color) dialog.setOptions(QColorDialog.ShowAlphaChannel) ok = dialog.exec_() if ok: self.setColor(dialog.currentColor()) self.colorChanged.emit()
def mouseDoubleClickEvent(self, event): event.accept() if self._readOnly: return dialog = QColorDialog() ok = dialog.exec_() if ok: self.setColor(dialog.currentColor()) self.colorChanged.emit()
def mouseDoubleClickEvent(self, event): if self._readOnly: return dialog = QColorDialog(self._color) dialog.setOptions(QColorDialog.ShowAlphaChannel) ok = dialog.exec_() if ok: self.setColor(dialog.currentColor()) self.colorChanged.emit()
def on_user_event(self): colord = QColorDialog()#self._color) colord.setOption(QColorDialog.DontUseNativeDialog) if self._kind == "rgbf": colord.setOption(QColorDialog.ShowAlphaChannel) colord.setCurrentColor(self._color) colord.setCustomColor(0, self._color) if colord.exec(): self.update_color(colord.currentColor())
def PickColor(self): self.c_color = None dlg = QColorDialog(self) if self.c_color: dlg.setCurrentColor(QColor(self.c_color)) if dlg.exec_(): self.setColor(dlg.currentColor().name())
def getColor(context, initial, title): if not isLinux: return QColorDialog.getColor(initial=initial, title=title) dlg = QColorDialog(initial, context) dlg.setWindowTitle(title) dlg.setOption(QColorDialog.DontUseNativeDialog) color = QColor() if dlg.exec() == QDialog.Accepted: color = dlg.currentColor() return color
def onColorPick(self): dlg = QColorDialog(self) # if self._color: # dlg.setCurrentColor(QColor(self._color)) if dlg.exec_(): new_color = dlg.currentColor() self.setButtonColor(new_color) self.data_handle.set_color(new_color)
def on_color_picker(self): ''' Show color-picker dialog to select color. Qt will use the native dialog by default. ''' dlg = QColorDialog(self) if self._color: dlg.setCurrentColor(QColor(self._color)) if dlg.exec_(): self.set_color(dlg.currentColor().name())
def _doubleClicked(self, index): model = self.model() if model is None: return data = model.data(index) if isinstance(data, QColor): dialog = QColorDialog(self) dialog.setCurrentColor(data) ret = dialog.exec_() if ret: color = dialog.currentColor() model.setData(index, color)
def mousePressEvent(self, event): scene_pos = self.mapToScene(event.pos()) pixmap = self.scene.itemAt(scene_pos) if not pixmap: return image = pixmap.pixmap().toImage() pos = int(scene_pos.x()), int(scene_pos.y()) if event.button() == Qt.LeftButton: dlg = QColorDialog() dlg.setCurrentColor(QColor(image.pixel(pos[0], pos[1]))) if dlg.exec_(): self.window.change_current_palette(pos, dlg.currentColor())
def onColorPicker(self): """ Show color-picker dialog to select color. Qt will use the native dialog by default. """ dlg = QColorDialog(self) if self._color: dlg.setCurrentColor(QColor(self._color)) if dlg.exec_(): self.setColor(dlg.currentColor()) self.colorChangedFromDialog.emit()
def _doubleClicked(self, index): model = self.model() if model is None: return data = model.data(index) if isinstance(data, QColor): if QApplication.keyboardModifiers() & Qt.AltModifier: model.setData(index, QColor()) else: dialog = QColorDialog(self) dialog.setCurrentColor(data) dialog.setOption(QColorDialog.ShowAlphaChannel) ret = dialog.exec_() if ret: color = dialog.currentColor() model.setData(index, color)
def pickColor(self): """ Opens up a modal QColorDialog_ to choose a new color, and stores it in this widget if the user clicks on the Ok button. Emits *colorChanged* when successful. .. _QColorDialog: http://doc.qt.io/qt-5/qcolordialog.html """ if self._readOnly: return dialog = QColorDialog(self._color) dialog.setOptions(QColorDialog.ShowAlphaChannel) ok = dialog.exec_() if ok: self.setColor(dialog.currentColor()) self.colorChanged.emit()
def OnColorPicker(self, *_args): dialog = QColorDialog(self) # Set starting/default/previous value if self.color: dialog.setCurrentColor(QColor(self.color)) # On ok if dialog.exec_(): self.color = dialog.currentColor() rgbcolor = [ self.color.redF(), self.color.greenF(), self.color.blueF() ] self.is_changed.emit(rgbcolor)
class Demo(QWidget): def __init__(self): super().__init__() self.resize(300, 300) self.setWindowTitle('QFontDialog') self.label = QLabel('塘沽五中', self) self.label.move(100, 10) self.cd = QColorDialog(QColor(250, 0, 0), self) # 创建颜色对话框--但不显示 # 参数1 默认颜色 self.pl = QPalette() # 创建调色板 btn = QPushButton('按钮', self) btn.move(100, 250) btn.clicked.connect(self.AA) # self.cd.setOption(QColorDialog.NoButtons) #选项控制--单个选项 # QColorDialog.NoButtons 不显示“ 确定”和“ 取消”按钮。(对“实时对话框”有用) # 参数2 on 表示有效 False表示取消 self.cd.setOptions(QColorDialog.NoButtons | QColorDialog.ShowAlphaChannel) # 选项控制--多个选项 # QColorDialog.ShowAlphaChannel 对话框中增加alpha设置项 self.cd.currentColorChanged.connect(self.BB) # 当前颜色变化时发出信号 def BB(self): s = self.cd.currentColor() # 返回当前颜色 # setCurrentColor(QColor()) 设置当前颜色 self.pl.setColor(QPalette.Background, s) self.setPalette(self.pl) def AA(self): r = self.cd.exec() if r: self.pl.setColor(QPalette.Background, self.cd.selectedColor()) # 给调色板设置颜色 self.setPalette(self.pl) # 给控件设置颜色
def on_pressed(self): """Button pressed event handler Shows color dialog and sets the chosen color. """ dlg = QColorDialog(self.parent()) dlg.setCurrentColor(self.color) dlg.setWindowTitle(self.title) dlg.setWindowFlags(Qt.Tool | Qt.FramelessWindowHint) dlg.setWindowModality(Qt.ApplicationModal) dlg.setOptions(QColorDialog.DontUseNativeDialog) p = self.mapFromGlobal(QCursor.pos()) p.setX(p.x() + (self.rect().width() / 2)) p.setY(p.y() + (self.rect().height() / 2)) dlg.move(self.mapToGlobal(p)) if dlg.exec_(): self.color = dlg.currentColor() self.colorChanged.emit()
class ColorPanel(QGraphicsItem): _scaf_colors = styles.SCAF_COLORS _stap_colors = styles.STAP_COLORS _PEN = Qt.NoPen def __init__(self, parent=None): super(ColorPanel, self).__init__(parent) self.rect = QRectF(0, 0, 30, 30) self.setFlag(QGraphicsItem.ItemIgnoresTransformations) self.colordialog = QColorDialog() # self.colordialog.setOption(QColorDialog.DontUseNativeDialog) self._scaf_color_index = -1 # init on -1, painttool will cycle to 0 self._stap_color_index = -1 # init on -1, painttool will cycle to 0 self._scaf_color = self._scaf_colors[self._scaf_color_index] self._stap_color = self._stap_colors[self._stap_color_index] self._scaf_brush = QBrush(self._scaf_color) self._stap_brush = QBrush(self._stap_color) self._initLabel() self.hide() def _initLabel(self): self._label = label = QGraphicsSimpleTextItem("scaf\nstap", parent=self) label.setPos(32, 0) label.setFont(_FONT) # label.setBrush(_labelbrush) # label.hide() def boundingRect(self): return self.rect def paint(self, painter, option, widget=None): painter.setPen(self._PEN) painter.setBrush(self._scaf_brush) painter.drawRect(0, 0, 30, 15) painter.setBrush(self._stap_brush) painter.drawRect(0, 15, 30, 15) def nextColor(self): self._stap_color_index += 1 if self._stap_color_index == len(self._stap_colors): self._stap_color_index = 0 self._stap_color = self._stap_colors[self._stap_color_index] self._stap_brush.setColor(self._stap_color) self.update() def prevColor(self): self._stap_color_index -= 1 def color(self): return self._stap_color def scafColorName(self): return self._scaf_color.name() def stapColorName(self): return self._stap_color.name() def changeScafColor(self): self.update() def changeStapColor(self): self._stap_color = self.colordialog.currentColor() self._stap_brush = QBrush(self._stap_color) self.update() def mousePressEvent(self, event): if event.pos().y() < 10: new_color = self.colordialog.getColor(self._scaf_color) if new_color.isValid() and new_color.name() != self._scaf_color.name(): self._scaf_color = new_color self._scaf_brush = QBrush(new_color) if not new_color in self._scaf_colors: self._scaf_colors.insert(self._scaf_color_index, new_color) self.update() else: new_color = self.colordialog.getColor(self._stap_color) if new_color.isValid() and new_color.name() != self._stap_color.name(): self._stap_color = new_color self._stap_brush = QBrush(new_color) if not new_color in self._stap_colors: self._stap_colors.insert(self._stap_color_index, new_color) self.update()
def choose_color(self): dlg = QColorDialog(self) dlg.setCurrentColor(QColor(self.color)) if dlg.exec_(): self.color = dlg.currentColor().name()
class SkinColorDialogUI(QWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # 初始化颜色 self.color = QColor(*settings.SKIN_COLOR) # 创建颜色对话框--但不显示 # self.color_dialog = QColorDialog(self.color, self.main_window) self.color_dialog = QColorDialog(self.color, self) # 创建调色板 self.palette = QPalette() self.options() def update_color(self, event: QColor) -> None: """ 更新颜色 两种方式同时 :param event: :return: """ # print(event, type(event)) # print(self.color_dialog.selectedColor(), type(self.color_dialog.selectedColor())) # QPalette.Background 表示设置背景色 # QPalette.WindowText 表示设置文本颜色 self.palette.setColor(QPalette.Background, event) # 给调色板设置颜色 self.palette.setBrush(QPalette.Base, QBrush(QColor(*event.getRgb()))) # self.palette.setColor(QPalette.Background, self.color_dialog.selectedColor()) # 给调色板设置颜色 # 给控件设置颜色 if event.isValid(): # self.main_window.setStyleSheet('QWidget {background-color:%s}' % event.name()) # self.main_window.setPalette(self.palette) self.color_dialog.setStyleSheet('QWidget {background-color:%s}' % event.name()) self.color_dialog.setPalette(self.palette) # 发色信号 communicate.skin_color.emit(event) def options(self) -> None: """ 参数设置 """ # 颜色选取信号 # 会向槽函数传递一个值---QColor # self.color_dialog.colorSelected.connect(self.update_color) # 选中最终颜色时发出信号-点击对话框的确定按钮时 self.color_dialog.currentColorChanged.connect( self.update_color) # 当前颜色变化时 # self.cd.setOption(QColorDialog.NoButtons) #选项控制--单个选项 # QColorDialog.NoButtons 不显示“ 确定”和“ 取消”按钮。(对“实时对话框”有用) # QColorDialog.ShowAlphaChannel 对话框中增加alpha设置项 self.color_dialog.setOptions( QColorDialog.NoButtons | QColorDialog.ShowAlphaChannel) # 选项控制--多个选项 # 打开对话框,会等待完成 # noinspection PyCallByClass # self.color_dialog.getColor(self.color, None) # 最终回调函数 self.color_dialog.finished.connect(self.finished_color) def setup_ui(self) -> None: # 打开对话框,等待打开 # self.color_dialog.open() self.color_dialog.show() def finished_color(self, event: int) -> None: """ 设置颜色到全局变量 :param event: :return: """ if event: pass color = self.color_dialog.currentColor().getRgb()[:3] settings.SKIN_COLOR = color
class comic_export_setting_dialog(QDialog): acbfStylesList = [ "speech", "commentary", "formal", "letter", "code", "heading", "audio", "thought", "sign", "sound", "emphasis", "strong" ] def __init__(self): super().__init__() self.setLayout(QVBoxLayout()) self.setWindowTitle(i18n("Export Settings")) buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) mainWidget = QTabWidget() self.layout().addWidget(mainWidget) self.layout().addWidget(buttons) # Set basic crop settings # Set which layers to remove before export. mainExportSettings = QWidget() mainExportSettings.setLayout(QVBoxLayout()) groupExportCrop = QGroupBox(i18n("Crop Settings")) formCrop = QFormLayout() groupExportCrop.setLayout(formCrop) self.chk_toOutmostGuides = QCheckBox(i18n("Crop to outmost guides")) self.chk_toOutmostGuides.setChecked(True) self.chk_toOutmostGuides.setToolTip( i18n( "This will crop to the outmost guides if possible and otherwise use the underlying crop settings." )) formCrop.addRow("", self.chk_toOutmostGuides) btn_fromSelection = QPushButton( i18n("Set Margins from Active Selection")) btn_fromSelection.clicked.connect(self.slot_set_margin_from_selection) # This doesn't work. formCrop.addRow("", btn_fromSelection) self.spn_marginLeft = QSpinBox() self.spn_marginLeft.setMaximum(99999) self.spn_marginLeft.setSuffix(" px") formCrop.addRow(i18n("Left:"), self.spn_marginLeft) self.spn_marginTop = QSpinBox() self.spn_marginTop.setMaximum(99999) self.spn_marginTop.setSuffix(" px") formCrop.addRow(i18n("Top:"), self.spn_marginTop) self.spn_marginRight = QSpinBox() self.spn_marginRight.setMaximum(99999) self.spn_marginRight.setSuffix(" px") formCrop.addRow(i18n("Right:"), self.spn_marginRight) self.spn_marginBottom = QSpinBox() self.spn_marginBottom.setMaximum(99999) self.spn_marginBottom.setSuffix(" px") formCrop.addRow(i18n("Bottom:"), self.spn_marginBottom) groupExportLayers = QGroupBox(i18n("Layers")) formLayers = QFormLayout() groupExportLayers.setLayout(formLayers) self.cmbLabelsRemove = labelSelector() formLayers.addRow(i18n("Label for removal:"), self.cmbLabelsRemove) self.ln_text_layer_name = QLineEdit() self.ln_text_layer_name.setToolTip( i18n( "These are keywords that can be used to identify text layers. A layer only needs to contain the keyword to be recognized. Keywords should be comma separated." )) self.ln_panel_layer_name = QLineEdit() self.ln_panel_layer_name.setToolTip( i18n( "These are keywords that can be used to identify panel layers. A layer only needs to contain the keyword to be recognized. Keywords should be comma separated." )) formLayers.addRow(i18n("Text Layer Key:"), self.ln_text_layer_name) formLayers.addRow(i18n("Panel Layer Key:"), self.ln_panel_layer_name) mainExportSettings.layout().addWidget(groupExportCrop) mainExportSettings.layout().addWidget(groupExportLayers) mainWidget.addTab(mainExportSettings, i18n("General")) # CBZ, crop, resize, which metadata to add. CBZexportSettings = QWidget() CBZexportSettings.setLayout(QVBoxLayout()) self.CBZactive = QCheckBox(i18n("Export to CBZ")) CBZexportSettings.layout().addWidget(self.CBZactive) self.CBZgroupResize = comic_export_resize_widget("CBZ") CBZexportSettings.layout().addWidget(self.CBZgroupResize) self.CBZactive.clicked.connect(self.CBZgroupResize.setEnabled) CBZgroupMeta = QGroupBox(i18n("Metadata to Add")) # CBZexportSettings.layout().addWidget(CBZgroupMeta) CBZgroupMeta.setLayout(QFormLayout()) mainWidget.addTab(CBZexportSettings, i18n("CBZ")) # ACBF, crop, resize, creator name, version history, panel layer, text layers. ACBFExportSettings = QWidget() ACBFform = QFormLayout() ACBFExportSettings.setLayout(QVBoxLayout()) ACBFdocInfo = QGroupBox() ACBFdocInfo.setTitle(i18n("ACBF Document Info")) ACBFdocInfo.setLayout(ACBFform) self.lnACBFID = QLabel() self.lnACBFID.setToolTip( i18n( "By default this will be filled with a generated universal unique identifier. The ID by itself is merely so that comic book library management programs can figure out if this particular comic is already in their database and whether it has been rated. Of course, the UUID can be changed into something else by manually changing the JSON, but this is advanced usage." )) self.spnACBFVersion = QSpinBox() self.ACBFhistoryModel = QStandardItemModel() acbfHistoryList = QListView() acbfHistoryList.setModel(self.ACBFhistoryModel) btn_add_history = QPushButton(i18n("Add History Entry")) btn_add_history.clicked.connect(self.slot_add_history_item) self.chkIncludeTranslatorComments = QCheckBox() self.chkIncludeTranslatorComments.setText( i18n("Include translator's comments")) self.chkIncludeTranslatorComments.setToolTip( i18n( "A PO file can contain translator's comments. If this is checked, the translations comments will be added as references into the ACBF file." )) self.lnTranslatorHeader = QLineEdit() ACBFform.addRow(i18n("ACBF UID:"), self.lnACBFID) ACBFform.addRow(i18n("Version:"), self.spnACBFVersion) ACBFform.addRow(i18n("Version history:"), acbfHistoryList) ACBFform.addRow("", btn_add_history) ACBFform.addRow("", self.chkIncludeTranslatorComments) ACBFform.addRow(i18n("Translator header:"), self.lnTranslatorHeader) ACBFAuthorInfo = QWidget() acbfAVbox = QVBoxLayout(ACBFAuthorInfo) infoLabel = QLabel( i18n( "The people responsible for the generation of the CBZ/ACBF files." )) infoLabel.setWordWrap(True) ACBFAuthorInfo.layout().addWidget(infoLabel) self.ACBFauthorModel = QStandardItemModel(0, 6) labels = [ i18n("Nick Name"), i18n("Given Name"), i18n("Middle Name"), i18n("Family Name"), i18n("Email"), i18n("Homepage") ] self.ACBFauthorModel.setHorizontalHeaderLabels(labels) self.ACBFauthorTable = QTableView() acbfAVbox.addWidget(self.ACBFauthorTable) self.ACBFauthorTable.setModel(self.ACBFauthorModel) self.ACBFauthorTable.verticalHeader().setDragEnabled(True) self.ACBFauthorTable.verticalHeader().setDropIndicatorShown(True) self.ACBFauthorTable.verticalHeader().setSectionsMovable(True) self.ACBFauthorTable.verticalHeader().sectionMoved.connect( self.slot_reset_author_row_visual) AuthorButtons = QHBoxLayout() btn_add_author = QPushButton(i18n("Add Author")) btn_add_author.clicked.connect(self.slot_add_author) AuthorButtons.addWidget(btn_add_author) btn_remove_author = QPushButton(i18n("Remove Author")) btn_remove_author.clicked.connect(self.slot_remove_author) AuthorButtons.addWidget(btn_remove_author) acbfAVbox.addLayout(AuthorButtons) ACBFStyle = QWidget() ACBFStyle.setLayout(QHBoxLayout()) self.ACBFStylesModel = QStandardItemModel() self.ACBFStyleClass = QListView() self.ACBFStyleClass.setModel(self.ACBFStylesModel) ACBFStyle.layout().addWidget(self.ACBFStyleClass) ACBFStyleEdit = QWidget() ACBFStyleEditVB = QVBoxLayout(ACBFStyleEdit) self.ACBFuseFont = QCheckBox(i18n("Use font")) self.ACBFFontList = QListView() self.ACBFFontList.setItemDelegate(font_list_delegate()) self.ACBFuseFont.toggled.connect(self.font_slot_enable_font_view) self.ACBFFontListModel = QStandardItemModel() self.ACBFFontListModel.rowsRemoved.connect( self.slot_font_current_style) self.ACBFFontListModel.itemChanged.connect( self.slot_font_current_style) self.btnAcbfAddFont = QPushButton() self.btnAcbfAddFont.setIcon(Application.icon("list-add")) self.btnAcbfAddFont.clicked.connect(self.font_slot_add_font) self.btn_acbf_remove_font = QPushButton() self.btn_acbf_remove_font.setIcon(Application.icon("edit-delete")) self.btn_acbf_remove_font.clicked.connect(self.font_slot_remove_font) self.ACBFFontList.setModel(self.ACBFFontListModel) self.ACBFdefaultFont = QComboBox() self.ACBFdefaultFont.addItems( ["sans-serif", "serif", "monospace", "cursive", "fantasy"]) acbfFontButtons = QHBoxLayout() acbfFontButtons.addWidget(self.btnAcbfAddFont) acbfFontButtons.addWidget(self.btn_acbf_remove_font) self.ACBFBold = QCheckBox(i18n("Bold")) self.ACBFItal = QCheckBox(i18n("Italic")) self.ACBFStyleClass.clicked.connect(self.slot_set_style) self.ACBFStyleClass.selectionModel().selectionChanged.connect( self.slot_set_style) self.ACBFStylesModel.itemChanged.connect(self.slot_set_style) self.ACBFBold.toggled.connect(self.slot_font_current_style) self.ACBFItal.toggled.connect(self.slot_font_current_style) colorWidget = QGroupBox(self) colorWidget.setTitle(i18n("Text Colors")) colorWidget.setLayout(QVBoxLayout()) self.regularColor = QColorDialog() self.invertedColor = QColorDialog() self.btn_acbfRegColor = QPushButton(i18n("Regular Text"), self) self.btn_acbfRegColor.clicked.connect(self.slot_change_regular_color) self.btn_acbfInvColor = QPushButton(i18n("Inverted Text"), self) self.btn_acbfInvColor.clicked.connect(self.slot_change_inverted_color) colorWidget.layout().addWidget(self.btn_acbfRegColor) colorWidget.layout().addWidget(self.btn_acbfInvColor) ACBFStyleEditVB.addWidget(colorWidget) ACBFStyleEditVB.addWidget(self.ACBFuseFont) ACBFStyleEditVB.addWidget(self.ACBFFontList) ACBFStyleEditVB.addLayout(acbfFontButtons) ACBFStyleEditVB.addWidget(self.ACBFdefaultFont) ACBFStyleEditVB.addWidget(self.ACBFBold) ACBFStyleEditVB.addWidget(self.ACBFItal) ACBFStyleEditVB.addStretch() ACBFStyle.layout().addWidget(ACBFStyleEdit) ACBFTabwidget = QTabWidget() ACBFTabwidget.addTab(ACBFdocInfo, i18n("Document Info")) ACBFTabwidget.addTab(ACBFAuthorInfo, i18n("Author Info")) ACBFTabwidget.addTab(ACBFStyle, i18n("Style Sheet")) ACBFExportSettings.layout().addWidget(ACBFTabwidget) mainWidget.addTab(ACBFExportSettings, i18n("ACBF")) # Epub export, crop, resize, other questions. EPUBexportSettings = QWidget() EPUBexportSettings.setLayout(QVBoxLayout()) self.EPUBactive = QCheckBox(i18n("Export to EPUB")) EPUBexportSettings.layout().addWidget(self.EPUBactive) self.EPUBgroupResize = comic_export_resize_widget("EPUB") EPUBexportSettings.layout().addWidget(self.EPUBgroupResize) self.EPUBactive.clicked.connect(self.EPUBgroupResize.setEnabled) mainWidget.addTab(EPUBexportSettings, i18n("EPUB")) # For Print. Crop, no resize. TIFFExportSettings = QWidget() TIFFExportSettings.setLayout(QVBoxLayout()) self.TIFFactive = QCheckBox(i18n("Export to TIFF")) TIFFExportSettings.layout().addWidget(self.TIFFactive) self.TIFFgroupResize = comic_export_resize_widget("TIFF") TIFFExportSettings.layout().addWidget(self.TIFFgroupResize) self.TIFFactive.clicked.connect(self.TIFFgroupResize.setEnabled) mainWidget.addTab(TIFFExportSettings, i18n("TIFF")) # SVG, crop, resize, embed vs link. #SVGExportSettings = QWidget() #mainWidget.addTab(SVGExportSettings, i18n("SVG")) """ Add a history item to the acbf version history list. """ def slot_add_history_item(self): newItem = QStandardItem() newItem.setText( str(i18n("v{version}-in this version...")).format( version=str(self.spnACBFVersion.value()))) self.ACBFhistoryModel.appendRow(newItem) """ Get the margins by treating the active selection in a document as the trim area. This allows people to snap selections to a vector or something, and then get the margins. """ def slot_set_margin_from_selection(self): doc = Application.activeDocument() if doc is not None: if doc.selection() is not None: self.spn_marginLeft.setValue(doc.selection().x()) self.spn_marginTop.setValue(doc.selection().y()) self.spn_marginRight.setValue(doc.width() - (doc.selection().x() + doc.selection().width())) self.spn_marginBottom.setValue(doc.height() - (doc.selection().y() + doc.selection().height())) """ Add an author with default values initialised. """ def slot_add_author(self): listItems = [] listItems.append(QStandardItem(i18n("Anon"))) # Nick name listItems.append(QStandardItem(i18n("John"))) # First name listItems.append(QStandardItem()) # Middle name listItems.append(QStandardItem(i18n("Doe"))) # Last name listItems.append(QStandardItem()) # email listItems.append(QStandardItem()) # homepage self.ACBFauthorModel.appendRow(listItems) """ Remove the selected author from the author list. """ def slot_remove_author(self): self.ACBFauthorModel.removeRow( self.ACBFauthorTable.currentIndex().row()) """ Ensure that the drag and drop of authors doesn't mess up the labels. """ def slot_reset_author_row_visual(self): headerLabelList = [] for i in range(self.ACBFauthorTable.verticalHeader().count()): headerLabelList.append(str(i)) for i in range(self.ACBFauthorTable.verticalHeader().count()): logicalI = self.ACBFauthorTable.verticalHeader().logicalIndex(i) headerLabelList[logicalI] = str(i + 1) self.ACBFauthorModel.setVerticalHeaderLabels(headerLabelList) """ Set the style item to the gui item's style. """ def slot_set_style(self): index = self.ACBFStyleClass.currentIndex() if index.isValid(): item = self.ACBFStylesModel.item(index.row()) fontUsed = item.data(role=styleEnum.FONT) if fontUsed is not None: self.ACBFuseFont.setChecked(fontUsed) else: self.ACBFuseFont.setChecked(False) self.font_slot_enable_font_view() fontList = item.data(role=styleEnum.FONTLIST) self.ACBFFontListModel.clear() for font in fontList: NewItem = QStandardItem(font) NewItem.setEditable(True) self.ACBFFontListModel.appendRow(NewItem) self.ACBFdefaultFont.setCurrentText( str(item.data(role=styleEnum.FONTGENERIC))) bold = item.data(role=styleEnum.BOLD) if bold is not None: self.ACBFBold.setChecked(bold) else: self.ACBFBold.setChecked(False) italic = item.data(role=styleEnum.ITALIC) if italic is not None: self.ACBFItal.setChecked(italic) else: self.ACBFItal.setChecked(False) """ Set the gui items to the currently selected style. """ def slot_font_current_style(self): index = self.ACBFStyleClass.currentIndex() if index.isValid(): item = self.ACBFStylesModel.item(index.row()) fontList = [] for row in range(self.ACBFFontListModel.rowCount()): font = self.ACBFFontListModel.item(row) fontList.append(font.text()) item.setData(self.ACBFuseFont.isChecked(), role=styleEnum.FONT) item.setData(fontList, role=styleEnum.FONTLIST) item.setData(self.ACBFdefaultFont.currentText(), role=styleEnum.FONTGENERIC) item.setData(self.ACBFBold.isChecked(), role=styleEnum.BOLD) item.setData(self.ACBFItal.isChecked(), role=styleEnum.ITALIC) self.ACBFStylesModel.setItem(index.row(), item) """ Change the regular color """ def slot_change_regular_color(self): if (self.regularColor.exec_() == QDialog.Accepted): square = QPixmap(32, 32) square.fill(self.regularColor.currentColor()) self.btn_acbfRegColor.setIcon(QIcon(square)) """ change the inverted color """ def slot_change_inverted_color(self): if (self.invertedColor.exec_() == QDialog.Accepted): square = QPixmap(32, 32) square.fill(self.invertedColor.currentColor()) self.btn_acbfInvColor.setIcon(QIcon(square)) def font_slot_enable_font_view(self): self.ACBFFontList.setEnabled(self.ACBFuseFont.isChecked()) self.btn_acbf_remove_font.setEnabled(self.ACBFuseFont.isChecked()) self.btnAcbfAddFont.setEnabled(self.ACBFuseFont.isChecked()) self.ACBFdefaultFont.setEnabled(self.ACBFuseFont.isChecked()) if self.ACBFFontListModel.rowCount() < 2: self.btn_acbf_remove_font.setEnabled(False) def font_slot_add_font(self): NewItem = QStandardItem(QFont().family()) NewItem.setEditable(True) self.ACBFFontListModel.appendRow(NewItem) def font_slot_remove_font(self): index = self.ACBFFontList.currentIndex() if index.isValid(): self.ACBFFontListModel.removeRow(index.row()) if self.ACBFFontListModel.rowCount() < 2: self.btn_acbf_remove_font.setEnabled(False) """ Load the UI values from the config dictionary given. """ def setConfig(self, config): if "cropToGuides" in config.keys(): self.chk_toOutmostGuides.setChecked(config["cropToGuides"]) if "cropLeft" in config.keys(): self.spn_marginLeft.setValue(config["cropLeft"]) if "cropTop" in config.keys(): self.spn_marginTop.setValue(config["cropTop"]) if "cropRight" in config.keys(): self.spn_marginRight.setValue(config["cropRight"]) if "cropBottom" in config.keys(): self.spn_marginBottom.setValue(config["cropBottom"]) if "labelsToRemove" in config.keys(): self.cmbLabelsRemove.setLabels(config["labelsToRemove"]) if "textLayerNames" in config.keys(): self.ln_text_layer_name.setText(", ".join( config["textLayerNames"])) else: self.ln_text_layer_name.setText("text") if "panelLayerNames" in config.keys(): self.ln_panel_layer_name.setText(", ".join( config["panelLayerNames"])) else: self.ln_panel_layer_name.setText("panels") self.CBZgroupResize.set_config(config) if "CBZactive" in config.keys(): self.CBZactive.setChecked(config["CBZactive"]) self.EPUBgroupResize.set_config(config) if "EPUBactive" in config.keys(): self.EPUBactive.setChecked(config["EPUBactive"]) self.TIFFgroupResize.set_config(config) if "TIFFactive" in config.keys(): self.TIFFactive.setChecked(config["TIFFactive"]) if "acbfAuthor" in config.keys(): if isinstance(config["acbfAuthor"], list): for author in config["acbfAuthor"]: listItems = [] listItems.append(QStandardItem(author.get("nickname", ""))) listItems.append( QStandardItem(author.get("first-name", ""))) listItems.append(QStandardItem(author.get("initials", ""))) listItems.append(QStandardItem(author.get("last-name", ""))) listItems.append(QStandardItem(author.get("email", ""))) listItems.append(QStandardItem(author.get("homepage", ""))) self.ACBFauthorModel.appendRow(listItems) pass else: listItems = [] listItems.append(QStandardItem( config["acbfAuthor"])) # Nick name for i in range(0, 5): listItems.append(QStandardItem()) # First name self.ACBFauthorModel.appendRow(listItems) if "uuid" in config.keys(): self.lnACBFID.setText(config["uuid"]) elif "acbfID" in config.keys(): self.lnACBFID.setText(config["acbfID"]) else: config["uuid"] = QUuid.createUuid().toString() self.lnACBFID.setText(config["uuid"]) if "acbfVersion" in config.keys(): self.spnACBFVersion.setValue(config["acbfVersion"]) if "acbfHistory" in config.keys(): for h in config["acbfHistory"]: item = QStandardItem() item.setText(h) self.ACBFhistoryModel.appendRow(item) if "acbfStyles" in config.keys(): styleDict = config.get("acbfStyles", {}) for key in self.acbfStylesList: keyDict = styleDict.get(key, {}) style = QStandardItem(key.title()) style.setCheckable(True) if key in styleDict.keys(): style.setCheckState(Qt.Checked) else: style.setCheckState(Qt.Unchecked) fontOn = False if "font" in keyDict.keys() or "genericfont" in keyDict.keys(): fontOn = True style.setData(fontOn, role=styleEnum.FONT) if "font" in keyDict: fontlist = keyDict["font"] if isinstance(fontlist, list): font = keyDict.get("font", QFont().family()) style.setData(font, role=styleEnum.FONTLIST) else: style.setData([fontlist], role=styleEnum.FONTLIST) else: style.setData([QFont().family()], role=styleEnum.FONTLIST) style.setData(keyDict.get("genericfont", "sans-serif"), role=styleEnum.FONTGENERIC) style.setData(keyDict.get("bold", False), role=styleEnum.BOLD) style.setData(keyDict.get("ital", False), role=styleEnum.ITALIC) self.ACBFStylesModel.appendRow(style) keyDict = styleDict.get("general", {}) self.regularColor.setCurrentColor( QColor(keyDict.get("color", "#000000"))) square = QPixmap(32, 32) square.fill(self.regularColor.currentColor()) self.btn_acbfRegColor.setIcon(QIcon(square)) keyDict = styleDict.get("inverted", {}) self.invertedColor.setCurrentColor( QColor(keyDict.get("color", "#FFFFFF"))) square.fill(self.invertedColor.currentColor()) self.btn_acbfInvColor.setIcon(QIcon(square)) else: for key in self.acbfStylesList: style = QStandardItem(key.title()) style.setCheckable(True) style.setCheckState(Qt.Unchecked) style.setData(False, role=styleEnum.FONT) style.setData(QFont().family(), role=styleEnum.FONTLIST) style.setData("sans-serif", role=styleEnum.FONTGENERIC) style.setData(False, role=styleEnum.BOLD) #Bold style.setData(False, role=styleEnum.ITALIC) #Italic self.ACBFStylesModel.appendRow(style) self.CBZgroupResize.setEnabled(self.CBZactive.isChecked()) self.lnTranslatorHeader.setText( config.get("translatorHeader", "Translator's Notes")) self.chkIncludeTranslatorComments.setChecked( config.get("includeTranslComment", False)) """ Store the GUI values into the config dictionary given. @return the config diactionary filled with new values. """ def getConfig(self, config): config["cropToGuides"] = self.chk_toOutmostGuides.isChecked() config["cropLeft"] = self.spn_marginLeft.value() config["cropTop"] = self.spn_marginTop.value() config["cropBottom"] = self.spn_marginRight.value() config["cropRight"] = self.spn_marginBottom.value() config["labelsToRemove"] = self.cmbLabelsRemove.getLabels() config["CBZactive"] = self.CBZactive.isChecked() config = self.CBZgroupResize.get_config(config) config["EPUBactive"] = self.EPUBactive.isChecked() config = self.EPUBgroupResize.get_config(config) config["TIFFactive"] = self.TIFFactive.isChecked() config = self.TIFFgroupResize.get_config(config) authorList = [] for row in range(self.ACBFauthorTable.verticalHeader().count()): logicalIndex = self.ACBFauthorTable.verticalHeader().logicalIndex( row) listEntries = [ "nickname", "first-name", "initials", "last-name", "email", "homepage" ] author = {} for i in range(len(listEntries)): entry = self.ACBFauthorModel.data( self.ACBFauthorModel.index(logicalIndex, i)) if entry is None: entry = " " if entry.isspace() is False and len(entry) > 0: author[listEntries[i]] = entry elif listEntries[i] in author.keys(): author.pop(listEntries[i]) authorList.append(author) config["acbfAuthor"] = authorList config["acbfVersion"] = self.spnACBFVersion.value() versionList = [] for r in range(self.ACBFhistoryModel.rowCount()): index = self.ACBFhistoryModel.index(r, 0) versionList.append( self.ACBFhistoryModel.data(index, Qt.DisplayRole)) config["acbfHistory"] = versionList acbfStylesDict = {} for row in range(0, self.ACBFStylesModel.rowCount()): entry = self.ACBFStylesModel.item(row) if entry.checkState() == Qt.Checked: key = entry.text().lower() style = {} if entry.data(role=styleEnum.FONT): font = entry.data(role=styleEnum.FONTLIST) if font is not None: style["font"] = font genericfont = entry.data(role=styleEnum.FONTGENERIC) if font is not None: style["genericfont"] = genericfont bold = entry.data(role=styleEnum.BOLD) if bold is not None: style["bold"] = bold italic = entry.data(role=styleEnum.ITALIC) if italic is not None: style["ital"] = italic acbfStylesDict[key] = style acbfStylesDict["general"] = { "color": self.regularColor.currentColor().name() } acbfStylesDict["inverted"] = { "color": self.invertedColor.currentColor().name() } config["acbfStyles"] = acbfStylesDict config["translatorHeader"] = self.lnTranslatorHeader.text() config[ "includeTranslComment"] = self.chkIncludeTranslatorComments.isChecked( ) # Turn this into something that retrieves from a line-edit when string freeze is over. config["textLayerNames"] = self.ln_text_layer_name.text().split(",") config["panelLayerNames"] = self.ln_panel_layer_name.text().split(",") return config
def show_color_selection(self, current_color): dialog = QColorDialog(self) dialog.setCurrentColor(QColor(current_color)) if dialog.exec_(): return dialog.currentColor().name()
class Example(QWidget): def __init__(self): super(Example, self).__init__() self.initUI() #To determine whether the square is clicked self.mouseClicked = False def initUI(self): #initializing the color dialog self.qcd = QColorDialog(self) self.qcd.colorSelected.connect(self.changeSquareColor) #initializing the square's dimension self.x = 20 self.y = 20 self.d = 50 #start the timer self.qt = QTimer() self.qt.timeout.connect(self.update) self.qt.start(1) #initializing the color self.qc = QColor(255, 0, 0) #initializing the widget's dimension self.setGeometry(300, 300, 600, 400) self.setWindowTitle('Square') self.show() def paintEvent(self, e): qp = QPainter() qp.begin(self) self.drawRectangles(qp) qp.end() def drawRectangles(self, qp): qp.setPen(QColor(0, 0, 0, 255)) #draw the widget qp.setBrush(QColor(255, 255, 255)) qp.drawRect(0, 0, self.width(), self.height()) #draw the square qp.setBrush(self.qc) qp.drawRect(self.x, self.y, self.d, self.d) def mouseDoubleClickEvent(self, e): if self.x <= e.x() and e.x() <= self.x + self.d and ( self.y <= e.y() and e.y() <= self.y + self.d): self.qcd.open() def mousePressEvent(self, e): #if we click in the square, determine the offset if self.x <= e.x() and e.x() <= self.x + self.d and ( self.y <= e.y() and e.y() <= self.y + self.d): self.deltax = e.x() - self.x self.deltay = e.y() - self.y self.mouseClicked = True def mouseMoveEvent(self, e): #drag the square when it is moved if self.mouseClicked: self.x = e.x() - self.deltax self.y = e.y() - self.deltay def mouseReleaseEvent(self, e): self.mouseClicked = False def changeSquareColor(self, color): self.qc = self.qcd.currentColor()
def btn_vertex_custom_color_action(self): color_dlg = QColorDialog() color_dlg.setCurrentColor(self.draw_param['vertex_color']) if color_dlg.exec_(): self.draw_param['vertex_color'] = color_dlg.currentColor() self.ui.standart_btns.button(QDialogButtonBox.Apply).setEnabled(True)
class QssWin(QMainWindow, QssWin): def __init__(self, parent=None): super(QMainWindow, self).__init__(parent) import os os.chdir(os.path.dirname(__file__)) self.setWindowTitle(self.tr("Qss Template Editor")) self.setWindowIcon(QIcon("Ui/img/Colorize.ico")) self.qsst = Qsst() self.dlg = QColorDialog(self) self.setupUi(self) self.renderAct.triggered.connect(lambda: self.render(True)) self.norenderAct.triggered.connect(lambda: self.render(False)) self.textEdit.keyPressed.connect(self.textChanged) self.modeBtn.toggled.connect(self.chToColorMode) self.textEdit.loseFocus.connect(self.render) self.textEdit.mouseLeave.connect(self.render) self.saveAct.triggered.connect(self.save) self.openAct.triggered.connect(self.open) self.exportAct.triggered.connect(self.export) self.open(file="data/default.qsst") self.file = "data/new-1.qsst" self.setWindowTitle("Qss Template Editor - " + os.path.basename(self.file)) self.statusbar.showMessage("Ready") def open(self, _=None, file=None): if (file is None): file, _ = QFileDialog.getOpenFileName(self, "open Qsst File", ".", "Qsst(*.qsst);;all(*.*)") if (os.path.exists(file)): self.textEdit.setText(open(file, 'r').read()) self.loadColors() self.render() self.setWindowTitle("Qss Template Editor - " + os.path.basename(file)) def save(self): if (os.path.exists(self.file)): file = self.file else: file, _ = QFileDialog.getSaveFileName(self, "save file", ".", "Qsst(*.qsst);;all(*.*)") if (file): self.file = file with open(file, 'w') as f: f.write(self.textEdit.toPlainText()) self.setWindowTitle("Qss Template Editor - " + os.path.basename(file)) def export(self): self.qsst.convertQss() #f=os.path.join(os.path.splitext(f)[0],"Qss") file, _ = QFileDialog.getSaveFileName(self, "export Qss file", ".", "Qss(*.qss);;all(*.*)") with open(file, 'w') as f: f.write(self.qsst.qss) def loadColors(self): self.qsst.srctext = self.textEdit.toPlainText() self.qsst.loadVars() item = self.colorGridLayout.itemAt(0) while (item != None): self.colorGridLayout.removeItem(item) #self.colorGridLayout.removeWidget(item.widget()) #item.widget().setParent(None)#这三行没有作用 sip.delete(item.widget()) #虽然控件删除了,但是grid的行数列数没减少,但是不影响使用 sip.delete(item) item = self.colorGridLayout.itemAt(0) self.colorGridLayout.update() #不起作用 i = 0 self.dict = {} for var, clr in self.qsst.varDict.items(): a = QLabel(var, self) b = QPushButton(clr, self) b.setMinimumSize(100, 10) b.clicked.connect(lambda x, var=var: self.chclr(var)) self.colorGridLayout.addWidget(a, i, 0) self.colorGridLayout.addWidget(b, i, 1) self.dict[var] = b i = i + 1 self.colorGridLayout.setSpacing(15) self.colorGridLayout.setRowStretch(i, 1) def chclr(self, var): color = self.dlg.getColor(self.dlg.currentColor(), self, "color pick", QColorDialog.ShowAlphaChannel) if (color.isValid()): s = '' if (color.alpha() == 255): clrstr = color.name() else: clrstr = 'rgba({},{},{},{})'.format(color.red(), color.green(), color.blue(), color.alpha()) s = 'font-size:8px;' if (qGray(color.rgb()) < 100): s += 'color:white;' self.dict[var].setText(clrstr) self.dict[var].setStyleSheet(s + "background:" + clrstr) self.qsst.varDict[var] = clrstr self.qsst.writeVars() self.textEdit.setPlainText(self.qsst.srctext) self.render() def render(self, rend=True): if (rend): if (self.modeBtn.isChecked()): self.qsst.srctext = self.textEdit.toPlainText() self.qsst.loadVars() self.qsst.convertQss() self.setStyleSheet(self.qsst.qss) else: self.setStyleSheet('') for var, btn in self.dict.items(): if ("rgb" in btn.text()): t = btn.text().strip(r" rgba()") c = t.split(',') if (len(c) > 3): a = c[3] else: a = 255 color = QColor(r, g, b, a) else: color = QColor(btn.text()) s = '' if (qGray(color.rgb()) < 100): s += "color:white;" btn.setStyleSheet(s + "background:" + btn.text()) def textChanged( self, e): #QKeyEvent(QEvent.KeyPress, Qt.Key_Enter, Qt.NoModifier) if (not self.textEdit.isReadOnly()): if (e.key() == Qt.Key_Enter or e.key() == Qt.Key_Return or e.key() == Qt.Key_Tab or e.key() == Qt.Key_Semicolon): self.render() def chToColorMode(self, iseditable): if (not iseditable): self.loadColors() self.render()
class ColorPanel(QGraphicsItem): _scaf_colors = styles.SCAF_COLORS _stap_colors = styles.STAP_COLORS _PEN = Qt.NoPen def __init__(self, parent=None): super(ColorPanel, self).__init__(parent) self.rect = QRectF(0, 0, 30, 30) self.setFlag(QGraphicsItem.ItemIgnoresTransformations) self.colordialog = QColorDialog() # self.colordialog.setOption(QColorDialog.DontUseNativeDialog) self._scaf_color_index = -1 # init on -1, painttool will cycle to 0 self._stap_color_index = -1 # init on -1, painttool will cycle to 0 self._scaf_color = self._scaf_colors[self._scaf_color_index] self._stap_color = self._stap_colors[self._stap_color_index] self._scaf_brush = QBrush(self._scaf_color) self._stap_brush = QBrush(self._stap_color) self._initLabel() self.hide() def _initLabel(self): self._label = label = QGraphicsSimpleTextItem("scaf\nstap", parent=self) label.setPos(32, 0) label.setFont(_FONT) # label.setBrush(_labelbrush) # label.hide() def boundingRect(self): return self.rect def paint(self, painter, option, widget=None): painter.setPen(self._PEN) painter.setBrush(self._scaf_brush) painter.drawRect(0, 0, 30, 15) painter.setBrush(self._stap_brush) painter.drawRect(0, 15, 30, 15) def nextColor(self): self._stap_color_index += 1 if self._stap_color_index == len(self._stap_colors): self._stap_color_index = 0 self._stap_color = self._stap_colors[self._stap_color_index] self._stap_brush.setColor(self._stap_color) self.update() def prevColor(self): self._stap_color_index -= 1 def color(self): return self._stap_color def scafColorName(self): return self._scaf_color.name() def stapColorName(self): return self._stap_color.name() def changeScafColor(self): self.update() def changeStapColor(self): self._stap_color = self.colordialog.currentColor() self._stap_brush = QBrush(self._stap_color) self.update() def mousePressEvent(self, event): if event.pos().y() < 10: new_color = self.colordialog.getColor(self._scaf_color) if new_color.isValid( ) and new_color.name() != self._scaf_color.name(): self._scaf_color = new_color self._scaf_brush = QBrush(new_color) if not new_color in self._scaf_colors: self._scaf_colors.insert(self._scaf_color_index, new_color) self.update() else: new_color = self.colordialog.getColor(self._stap_color) if new_color.isValid( ) and new_color.name() != self._stap_color.name(): self._stap_color = new_color self._stap_brush = QBrush(new_color) if not new_color in self._stap_colors: self._stap_colors.insert(self._stap_color_index, new_color) self.update()
def onColorPicker(self): dlg = QColorDialog() if self._color: dlg.setCurrentColor(QColor(self._color)) if dlg.exec_(): self.set_color(dlg.currentColor().name())
def onColorPicker(self): dialog = QColorDialog() dialog.setCurrentColor(self._color) if dialog.exec_(): self.set_color(dialog.currentColor())