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 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 selectDrawColor(self): self.setBScale(False) colorDialog = QColorDialog(self) colorDialog.setWindowTitle('Select Draw Color: ') colorDialog.setCurrentColor(Qt.red) if colorDialog.exec_() == QColorDialog.Accepted: drawColor = colorDialog.selectedColor() self.canvas.setDrawColor(drawColor) red = drawColor.red() green = drawColor.green() blue = drawColor.blue() self.cfg.set('file', 'drawColorRed', str(red)) self.cfg.set('file', 'drawColorGreen', str(green)) self.cfg.set('file', 'drawColorBlue', str(blue)) self.cfg.write(open('SWQT.ini', 'w'))
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)
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 getColor( parent = None, title = "", color = None, alpha = False, ): """Ask the user a color.""" global _savedColor if color is None: color = _savedColor dlg = QColorDialog(color, parent) options = QColorDialog.ColorDialogOptions() if alpha: options |= QColorDialog.ShowAlphaChannel if not QSettings().value("native_dialogs/colordialog", True, bool): options |= QColorDialog.DontUseNativeDialog dlg.setOptions(options) dlg.setWindowTitle(title or app.caption(_("Select Color"))) if dlg.exec_(): _savedColor = dlg.selectedColor() return _savedColor
def getColor( parent=None, title="", color=None, alpha=False, ): """Ask the user a color.""" global _savedColor if color is None: color = _savedColor dlg = QColorDialog(color, parent) options = QColorDialog.ColorDialogOptions() if alpha: options |= QColorDialog.ShowAlphaChannel if not QSettings().value("native_dialogs/colordialog", True, bool): options |= QColorDialog.DontUseNativeDialog dlg.setOptions(options) dlg.setWindowTitle(title or app.caption(_("Select Color"))) if dlg.exec_(): _savedColor = dlg.selectedColor() return _savedColor
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()
def mousePressEvent(self, e): color_dialog = QColorDialog() color_dialog.exec_() self.current_color = color_dialog.selectedColor() self.reset_style_sheet()
def onChooseColor(self): colorDiag = QColorDialog() colorDiag.exec_() color = colorDiag.selectedColor() self.color = color.getRgb() self.styleColorBttn(self.color)
def show_color_selection(self, current_color): dialog = QColorDialog(self) dialog.setCurrentColor(QColor(current_color)) if dialog.exec_(): return dialog.currentColor().name()
def onColorPicker(self): dialog = QColorDialog() dialog.setCurrentColor(self._color) if dialog.exec_(): self.set_color(dialog.currentColor())
def chooseColor(self): colorDiag = QColorDialog() colorDiag.exec_() color = colorDiag.selectedColor() return color.getRgb()
def onColorPicker(self): dlg = QColorDialog() if self._color: dlg.setCurrentColor(QColor(self._color)) if dlg.exec_(): self.set_color(dlg.currentColor().name())
class GraphNode(GfxObject, LabeledGfx): DefaultRect = QRectF(-15, -15, 30, 30) DefaultCornerRadius = 7 DefaultInsetPadding = 15 Circle, RoundedRect = range(2) symbolChanged = pyqtSignal(str) def __init__(self, new=True): super().__init__(new) super().__init__(new) self._contextMenu = None self._shape = self.RoundedRect if new: self._insetPadding = self.DefaultInsetPadding self._defaultRect = self.DefaultRect self._cornerRadius = self.DefaultCornerRadius self._arrows = [] self._boundScale = (1.0, 1.0) self._brush = SimpleBrush(Qt.cyan) self._pen = Pen(Qt.yellow, 2.0) self.setupConnections() self.setFiltersChildEvents(True) self._renderHints = QPainter.Antialiasing | QPainter.HighQualityAntialiasing | QPainter.SmoothPixmapTransform self.setAcceptHoverEvents(True) self._hover = False def __setstate__(self, data): super().__setstate__(data) super().__setstate__(data) self._insetPadding = data["inset padding"] self._defaultRect = data["default rect"] self._cornerRadius = data["corner radius"] self._arrows = data["arrows"] self._boundScale = data["bound scale"] self.setupConnections() self.updateArrowsAndClearResidual() def __getstate__(self): data = super().__getstate__() data = {**data, **super().__getstate__()} data["inset padding"] = self._insetPadding data["default rect"] = self._defaultRect data["corner radius"] = self._cornerRadius data["arrows"] = self._arrows data["bound scale"] = self._boundScale return data def __deepcopy__(self, memo): copy = deepcopy(super(), memo) memo[id(self)] = copy copy._shape = self._shape copy._defaultRect = QRectF(self._defaultRect) copy._insetPadding = self._insetPadding copy._cornerRadius = self._cornerRadius copy._arrows = deepcopy(self._arrows, memo) #for arr in copy._arrows: #assert(arr.toNode() is self or arr.fromNode() is self) copy._boundScale = tuple(self._boundScale) copy._brush = deepcopy(self._brush, memo) copy.setupConnections() return copy def hoverEnterEvent(self, event): self._hover = True super().hoverEnterEvent(event) def hoverLeaveEvent(self, event): self._hover = False super().hoverLeaveEvent(event) def sceneEventFilter(self, watched, event): if event.type() == QEvent.GraphicsSceneMouseMove and mag2D( event.scenePos() - event.lastScenePos()) > 1: self.updateArrows() self.scene().update() return False def cornerRadius(self): return self._cornerRadius def setCornerRadius(self, radius): self._cornerRadius = radius self.changed.emit() self.update() def setupConnections(self): self.setFlags(self.ItemIsMovable | self.ItemIsFocusable | self.ItemIsSelectable | self.ItemSendsGeometryChanges) self._brushColorDlg = QColorDialog(self.brush().color()) self._brushColorDlg.setOption(QColorDialog.ShowAlphaChannel, True) self._brushColorDlg.currentColorChanged.connect( lambda col: self.setBrush(SimpleBrush(col))) self._penColorDlg = QColorDialog(self.pen().color()) self._penColorDlg.setOption(QColorDialog.ShowAlphaChannel, True) self._penColorDlg.currentColorChanged.connect( lambda col: self.setPen(setPenColor(self.pen(), col))) def itemChange(self, change, value): if change == self.ItemPositionChange: self.updateArrows() if self.scene(): self.scene().update() return super().itemChange(change, value) def arrows(self): return self._arrows def attachArrow(self, arr): self._arrows.append(arr) self.updateArrows() def detachArrow(self, arr): if arr in self._arrows: self._arrows.remove(arr) self.updateArrows() def boundingRect(self): w = self._insetPadding rect = self.childrenBoundingRect() rect.translate(-rect.center()) rect.adjust(-w, -w, w, w) return rect def setDefaultBoundingRect(self, rect=None): if rect is None: rect = self.DefaultRect self._defaultRect = rect self.changed.emit() self.update() def defaultBoundingRect(self): return self._defaultRect def paint(self, painter, option, widget): if self.scene(): if self.isSelected(): paintSelectionShape(painter, self) painter.setRenderHints(self.renderHints()) painter.setBrush(self.brush()) if self._hover: painter.setPen(self.painterPen()) else: painter.setPen(QPen(Qt.NoPen)) if self._shape == self.RoundedRect: painter.drawRoundedRect(self.boundingRect(), self.cornerRadius(), self.cornerRadius()) elif self._shape == self.Circle: rect = self.boundingRect() if rect.width() > rect.height(): rect.setX(rect.x() - (rect.height() - rect.width()) / 2) rect.setWidth(rect.height()) elif rect.height() > rect.width(): rect.setY(rect.y() - (rect.width() - rect.height()) / 2) rect.setHeight(rect.width()) pen_w = self.pen().width() rect.adjust(pen_w, pen_w, -pen_w, -pen_w) painter.drawEllipse(rect) painter.setPen(QPen(Qt.red, 2.0)) def setRenderHints(self, hints): self._renderHints = hints self.update() def renderHints(self): return self._renderHints def centerChild(self, child): rect = child.boundingRect() center = self.boundingRect().center() delta = center - rect.center() child.setPos(child.pos() + delta) def closestBoundaryPos(self, pos): rect = self.boundingRect() #s = self._boundScale #T = QTransform.fromScale(1/s[0], 1/s[1]) #rect = T.mapRect(rect) if pos.x() < rect.left(): x = rect.left() elif pos.x() > rect.right(): x = rect.right() else: x = pos.x() if pos.y() < rect.top(): y = rect.top() elif pos.y() > rect.bottom(): y = rect.bottom() else: y = pos.y() rect_point = QPointF(x, y) r = self.cornerRadius() poly = None if mag2D(rect_point - rect.bottomRight()) <= r: poly = polygonFromArc(rect.bottomRight() + QPointF(-r, -r), r, 0, 90, seg=30) elif mag2D(rect_point - rect.topRight()) <= r: poly = polygonFromArc(rect.topRight() + QPointF(-r, r), r, 270, 360, seg=30) elif mag2D(rect_point - rect.topLeft()) <= r: poly = polygonFromArc(rect.topLeft() + QPointF(r, r), r, 180, 270, seg=30) elif mag2D(rect_point - rect.bottomLeft()) <= r: poly = polygonFromArc(rect.bottomLeft() + QPointF(r, -r), r, 90, 180, seg=30) if poly is None: return rect_point else: return closestPolyPoint(poly, pos)[0] def updateArrows(self): for arr in self._arrows: arr.updatePosition() def updateArrowsAndClearResidual(self): self.updateArrows() if self.scene(): self.scene().update() def contextMenuEvent(self, event): if self._contextMenu: self._contextMenu.exec_(event.screenPos()) def buildDefaultContextMenu(self, menu=None): if menu is None: menu = QMenu() col_menu = menu.addMenu("Color") col_menu.addAction("Brush").triggered.connect( lambda: self._brushColorDlg.exec_()) col_menu.addAction("Pen").triggered.connect( lambda: self._penColorDlg.exec_()) return menu def setContextMenu(self, menu): self._contextMenu = menu def brush(self): return self._brush def setBrush(self, brush): self._brush = brush self._brushColorDlg.setCurrentColor(brush.color()) self.update() def pen(self): return self._pen def setPen(self, pen): self._pen = pen self._penColorDlg.setCurrentColor(pen.color()) self.update() def saveTextPosition(self): pass def updateTextPosition(self): pass def addLabel(self, label): label = super().addLabel(label) if isinstance(label, TextItem): label.onPositionChanged = self.updateArrowsAndClearResidual return label def updateGraph(self): self.updateArrows() def delete(self, deleted=None): if deleted is None: deleted = {} deleted["arrows"] = [] for arr in self.arrows(): if arr.toNode() is self: arr.setTo(None) deleted["arrows"].append((arr, 1)) else: arr.setFrom(None) deleted["arrows"].append((arr, 0)) super().delete(deleted) return deleted def undelete(self, deleted, emit=True): super().undelete(deleted, emit=False) for arr, isstart in deleted["arrows"]: if isstart == 0: arr.setFrom(self) else: arr.setTo(self) if emit: self.undeleted.emit(self) def setEditable(self, editable): super().setEditable(editable) super().setEditable(editable)
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 choose_color(self): dlg = QColorDialog(self) dlg.setCurrentColor(QColor(self.color)) if dlg.exec_(): self.color = dlg.currentColor().name()
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)