File indexing completed on 2024-05-12 05:46:37
0001 """ 0002 Copyright (c) 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com> 0003 0004 This file is part of the Comics Project Management Tools(CPMT). 0005 0006 CPMT is free software: you can redistribute it and/or modify 0007 it under the terms of the GNU General Public License as published by 0008 the Free Software Foundation, either version 3 of the License, or 0009 (at your option) any later version. 0010 0011 CPMT is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with the CPMT. If not, see <http://www.gnu.org/licenses/>. 0018 """ 0019 0020 """ 0021 A dialog for editing the exporter settings. 0022 """ 0023 0024 from enum import IntEnum 0025 from PyQt5.QtGui import QStandardItem, QStandardItemModel, QColor, QFont, QIcon, QPixmap 0026 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QGroupBox, QFormLayout, QCheckBox, QComboBox, QSpinBox, QWidget, QVBoxLayout, QHBoxLayout, QTabWidget, QPushButton, QLineEdit, QLabel, QListView, QTableView, QFontComboBox, QSpacerItem, QColorDialog, QStyledItemDelegate 0027 from PyQt5.QtCore import Qt, QUuid 0028 from krita import * 0029 0030 """ 0031 A generic widget to make selecting size easier. 0032 It works by initialising with a config name(like "scale"), and then optionally setting the config with a dictionary. 0033 Then, afterwards, you get the config with a dictionary, with the config name being the entry the values are under. 0034 """ 0035 0036 0037 class comic_export_resize_widget(QGroupBox): 0038 configName = "" 0039 0040 def __init__(self, configName, batch=False, fileType=True): 0041 super().__init__() 0042 self.configName = configName 0043 self.setTitle(i18n("Adjust Working File")) 0044 formLayout = QFormLayout() 0045 self.setLayout(formLayout) 0046 self.crop = QCheckBox(i18n("Crop files before resize")) 0047 self.cmbFile = QComboBox() 0048 self.cmbFile.addItems(["png", "jpg", "webp"]) 0049 self.resizeMethod = QComboBox() 0050 self.resizeMethod.addItems([i18n("Percentage"), i18n("DPI"), i18n("Maximum Width"), i18n("Maximum Height")]) 0051 self.resizeMethod.currentIndexChanged.connect(self.slot_set_enabled) 0052 self.spn_DPI = QSpinBox() 0053 self.spn_DPI.setMaximum(1200) 0054 self.spn_DPI.setSuffix(i18n(" DPI")) 0055 self.spn_DPI.setValue(72) 0056 self.spn_PER = QSpinBox() 0057 if batch is True: 0058 self.spn_PER.setMaximum(1000) 0059 else: 0060 self.spn_PER.setMaximum(100) 0061 self.spn_PER.setSuffix(" %") 0062 self.spn_PER.setValue(100) 0063 self.spn_width = QSpinBox() 0064 self.spn_width.setMaximum(99999) 0065 self.spn_width.setSuffix(" px") 0066 self.spn_width.setValue(800) 0067 self.spn_height = QSpinBox() 0068 self.spn_height.setMaximum(99999) 0069 self.spn_height.setSuffix(" px") 0070 self.spn_height.setValue(800) 0071 0072 if batch is False: 0073 formLayout.addRow("", self.crop) 0074 if fileType is True and configName != "TIFF": 0075 formLayout.addRow(i18n("File Type"), self.cmbFile) 0076 formLayout.addRow(i18n("Method:"), self.resizeMethod) 0077 formLayout.addRow(i18n("DPI:"), self.spn_DPI) 0078 formLayout.addRow(i18n("Percentage:"), self.spn_PER) 0079 formLayout.addRow(i18n("Width:"), self.spn_width) 0080 formLayout.addRow(i18n("Height:"), self.spn_height) 0081 self.slot_set_enabled() 0082 0083 def slot_set_enabled(self): 0084 method = self.resizeMethod.currentIndex() 0085 self.spn_DPI.setEnabled(False) 0086 self.spn_PER.setEnabled(False) 0087 self.spn_width.setEnabled(False) 0088 self.spn_height.setEnabled(False) 0089 0090 if method == 0: 0091 self.spn_PER.setEnabled(True) 0092 if method == 1: 0093 self.spn_DPI.setEnabled(True) 0094 if method == 2: 0095 self.spn_width.setEnabled(True) 0096 if method == 3: 0097 self.spn_height.setEnabled(True) 0098 0099 def set_config(self, config): 0100 if self.configName in config.keys(): 0101 mConfig = config[self.configName] 0102 if "Method" in mConfig.keys(): 0103 self.resizeMethod.setCurrentIndex(mConfig["Method"]) 0104 if "FileType" in mConfig.keys(): 0105 self.cmbFile.setCurrentText(mConfig["FileType"]) 0106 if "Crop" in mConfig.keys(): 0107 self.crop.setChecked(mConfig["Crop"]) 0108 if "DPI" in mConfig.keys(): 0109 self.spn_DPI.setValue(mConfig["DPI"]) 0110 if "Percentage" in mConfig.keys(): 0111 self.spn_PER.setValue(mConfig["Percentage"]) 0112 if "Width" in mConfig.keys(): 0113 self.spn_width.setValue(mConfig["Width"]) 0114 if "Height" in mConfig.keys(): 0115 self.spn_height.setValue(mConfig["Height"]) 0116 self.slot_set_enabled() 0117 0118 def get_config(self, config): 0119 mConfig = {} 0120 mConfig["Method"] = self.resizeMethod.currentIndex() 0121 if self.configName == "TIFF": 0122 mConfig["FileType"] = "tiff" 0123 else: 0124 mConfig["FileType"] = self.cmbFile.currentText() 0125 mConfig["Crop"] = self.crop.isChecked() 0126 mConfig["DPI"] = self.spn_DPI.value() 0127 mConfig["Percentage"] = self.spn_PER.value() 0128 mConfig["Width"] = self.spn_width.value() 0129 mConfig["Height"] = self.spn_height.value() 0130 config[self.configName] = mConfig 0131 return config 0132 0133 0134 """ 0135 Quick combobox for selecting the color label. 0136 """ 0137 0138 0139 class labelSelector(QComboBox): 0140 def __init__(self): 0141 super(labelSelector, self).__init__() 0142 lisOfColors = [] 0143 lisOfColors.append(Qt.transparent) 0144 lisOfColors.append(QColor(91, 173, 220)) 0145 lisOfColors.append(QColor(151, 202, 63)) 0146 lisOfColors.append(QColor(247, 229, 61)) 0147 lisOfColors.append(QColor(255, 170, 63)) 0148 lisOfColors.append(QColor(177, 102, 63)) 0149 lisOfColors.append(QColor(238, 50, 51)) 0150 lisOfColors.append(QColor(191, 106, 209)) 0151 lisOfColors.append(QColor(118, 119, 114)) 0152 0153 self.itemModel = QStandardItemModel() 0154 for color in lisOfColors: 0155 item = QStandardItem() 0156 item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) 0157 item.setCheckState(Qt.Unchecked) 0158 item.setText(" ") 0159 item.setData(color, Qt.BackgroundColorRole) 0160 self.itemModel.appendRow(item) 0161 self.setModel(self.itemModel) 0162 0163 def getLabels(self): 0164 listOfIndexes = [] 0165 for i in range(self.itemModel.rowCount()): 0166 index = self.itemModel.index(i, 0) 0167 item = self.itemModel.itemFromIndex(index) 0168 if item.checkState(): 0169 listOfIndexes.append(i) 0170 return listOfIndexes 0171 0172 def setLabels(self, listOfIndexes): 0173 for i in listOfIndexes: 0174 index = self.itemModel.index(i, 0) 0175 item = self.itemModel.itemFromIndex(index) 0176 item.setCheckState(True) 0177 0178 """ 0179 Little Enum to keep track of where in the item we add styles. 0180 """ 0181 class styleEnum(IntEnum): 0182 FONT = Qt.UserRole + 1 0183 FONTLIST = Qt.UserRole + 2 0184 FONTGENERIC = Qt.UserRole + 3 0185 BOLD = Qt.UserRole + 4 0186 ITALIC = Qt.UserRole + 5 0187 """ 0188 A simple delegate to allows editing fonts with a QFontComboBox 0189 """ 0190 class font_list_delegate(QStyledItemDelegate): 0191 def __init__(self, parent=None): 0192 super(QStyledItemDelegate, self).__init__(parent) 0193 def createEditor(self, parent, option, index): 0194 editor = QFontComboBox(parent) 0195 return editor 0196 0197 """ 0198 The comic export settings dialog will allow configuring the export. 0199 0200 This config consists of... 0201 0202 * Crop settings. for removing bleeds. 0203 * Selecting layer labels to remove. 0204 * Choosing which formats to export to. 0205 * Choosing how to resize these 0206 * Whether to crop. 0207 * Which file type to use. 0208 0209 And for ACBF, it gives the ability to edit acbf document info. 0210 0211 """ 0212 0213 0214 class comic_export_setting_dialog(QDialog): 0215 acbfStylesList = ["speech", "commentary", "formal", "letter", "code", "heading", "audio", "thought", "sign", "sound", "emphasis", "strong"] 0216 0217 def __init__(self): 0218 super().__init__() 0219 self.setLayout(QVBoxLayout()) 0220 self.setWindowTitle(i18n("Export Settings")) 0221 buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) 0222 0223 buttons.accepted.connect(self.accept) 0224 buttons.rejected.connect(self.reject) 0225 mainWidget = QTabWidget() 0226 self.layout().addWidget(mainWidget) 0227 self.layout().addWidget(buttons) 0228 0229 # Set basic crop settings 0230 # Set which layers to remove before export. 0231 mainExportSettings = QWidget() 0232 mainExportSettings.setLayout(QVBoxLayout()) 0233 groupExportCrop = QGroupBox(i18n("Crop Settings")) 0234 formCrop = QFormLayout() 0235 groupExportCrop.setLayout(formCrop) 0236 self.chk_toOutmostGuides = QCheckBox(i18n("Crop to outmost guides")) 0237 self.chk_toOutmostGuides.setChecked(True) 0238 self.chk_toOutmostGuides.setToolTip(i18n("This will crop to the outmost guides if possible and otherwise use the underlying crop settings.")) 0239 formCrop.addRow("", self.chk_toOutmostGuides) 0240 btn_fromSelection = QPushButton(i18n("Set Margins from Active Selection")) 0241 btn_fromSelection.clicked.connect(self.slot_set_margin_from_selection) 0242 # This doesn't work. 0243 formCrop.addRow("", btn_fromSelection) 0244 self.spn_marginLeft = QSpinBox() 0245 self.spn_marginLeft.setMaximum(99999) 0246 self.spn_marginLeft.setSuffix(" px") 0247 formCrop.addRow(i18n("Left:"), self.spn_marginLeft) 0248 self.spn_marginTop = QSpinBox() 0249 self.spn_marginTop.setMaximum(99999) 0250 self.spn_marginTop.setSuffix(" px") 0251 formCrop.addRow(i18n("Top:"), self.spn_marginTop) 0252 self.spn_marginRight = QSpinBox() 0253 self.spn_marginRight.setMaximum(99999) 0254 self.spn_marginRight.setSuffix(" px") 0255 formCrop.addRow(i18n("Right:"), self.spn_marginRight) 0256 self.spn_marginBottom = QSpinBox() 0257 self.spn_marginBottom.setMaximum(99999) 0258 self.spn_marginBottom.setSuffix(" px") 0259 formCrop.addRow(i18n("Bottom:"), self.spn_marginBottom) 0260 groupExportLayers = QGroupBox(i18n("Layers")) 0261 formLayers = QFormLayout() 0262 groupExportLayers.setLayout(formLayers) 0263 self.cmbLabelsRemove = labelSelector() 0264 formLayers.addRow(i18n("Label for removal:"), self.cmbLabelsRemove) 0265 self.ln_text_layer_name = QLineEdit() 0266 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.")) 0267 self.ln_panel_layer_name = QLineEdit() 0268 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.")) 0269 formLayers.addRow(i18n("Text Layer Key:"), self.ln_text_layer_name) 0270 formLayers.addRow(i18n("Panel Layer Key:"), self.ln_panel_layer_name) 0271 0272 mainExportSettings.layout().addWidget(groupExportCrop) 0273 mainExportSettings.layout().addWidget(groupExportLayers) 0274 mainWidget.addTab(mainExportSettings, i18n("General")) 0275 0276 # CBZ, crop, resize, which metadata to add. 0277 CBZexportSettings = QWidget() 0278 CBZexportSettings.setLayout(QVBoxLayout()) 0279 self.CBZactive = QCheckBox(i18n("Export to CBZ")) 0280 CBZexportSettings.layout().addWidget(self.CBZactive) 0281 self.CBZgroupResize = comic_export_resize_widget("CBZ") 0282 CBZexportSettings.layout().addWidget(self.CBZgroupResize) 0283 self.CBZactive.clicked.connect(self.CBZgroupResize.setEnabled) 0284 CBZgroupMeta = QGroupBox(i18n("Metadata to Add")) 0285 # CBZexportSettings.layout().addWidget(CBZgroupMeta) 0286 CBZgroupMeta.setLayout(QFormLayout()) 0287 0288 mainWidget.addTab(CBZexportSettings, i18n("CBZ")) 0289 0290 # ACBF, crop, resize, creator name, version history, panel layer, text layers. 0291 ACBFExportSettings = QWidget() 0292 ACBFform = QFormLayout() 0293 ACBFExportSettings.setLayout(QVBoxLayout()) 0294 ACBFdocInfo = QGroupBox() 0295 ACBFdocInfo.setTitle(i18n("ACBF Document Info")) 0296 ACBFdocInfo.setLayout(ACBFform) 0297 self.lnACBFID = QLabel() 0298 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.")) 0299 self.spnACBFVersion = QSpinBox() 0300 self.ACBFhistoryModel = QStandardItemModel() 0301 acbfHistoryList = QListView() 0302 acbfHistoryList.setModel(self.ACBFhistoryModel) 0303 btn_add_history = QPushButton(i18n("Add History Entry")) 0304 btn_add_history.clicked.connect(self.slot_add_history_item) 0305 self.chkIncludeTranslatorComments = QCheckBox() 0306 self.chkIncludeTranslatorComments.setText(i18n("Include translator's comments")) 0307 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.")) 0308 self.lnTranslatorHeader = QLineEdit() 0309 0310 ACBFform.addRow(i18n("ACBF UID:"), self.lnACBFID) 0311 ACBFform.addRow(i18n("Version:"), self.spnACBFVersion) 0312 ACBFform.addRow(i18n("Version history:"), acbfHistoryList) 0313 ACBFform.addRow("", btn_add_history) 0314 ACBFform.addRow("", self.chkIncludeTranslatorComments) 0315 ACBFform.addRow(i18n("Translator header:"), self.lnTranslatorHeader) 0316 0317 ACBFAuthorInfo = QWidget() 0318 acbfAVbox = QVBoxLayout(ACBFAuthorInfo) 0319 infoLabel = QLabel(i18n("The people responsible for the generation of the CBZ/ACBF files.")) 0320 infoLabel.setWordWrap(True) 0321 ACBFAuthorInfo.layout().addWidget(infoLabel) 0322 self.ACBFauthorModel = QStandardItemModel(0, 6) 0323 labels = [i18n("Nick Name"), i18n("Given Name"), i18n("Middle Name"), i18n("Family Name"), i18n("Email"), i18n("Homepage")] 0324 self.ACBFauthorModel.setHorizontalHeaderLabels(labels) 0325 self.ACBFauthorTable = QTableView() 0326 acbfAVbox.addWidget(self.ACBFauthorTable) 0327 self.ACBFauthorTable.setModel(self.ACBFauthorModel) 0328 self.ACBFauthorTable.verticalHeader().setDragEnabled(True) 0329 self.ACBFauthorTable.verticalHeader().setDropIndicatorShown(True) 0330 self.ACBFauthorTable.verticalHeader().setSectionsMovable(True) 0331 self.ACBFauthorTable.verticalHeader().sectionMoved.connect(self.slot_reset_author_row_visual) 0332 AuthorButtons = QHBoxLayout() 0333 btn_add_author = QPushButton(i18n("Add Author")) 0334 btn_add_author.clicked.connect(self.slot_add_author) 0335 AuthorButtons.addWidget(btn_add_author) 0336 btn_remove_author = QPushButton(i18n("Remove Author")) 0337 btn_remove_author.clicked.connect(self.slot_remove_author) 0338 AuthorButtons.addWidget(btn_remove_author) 0339 acbfAVbox.addLayout(AuthorButtons) 0340 0341 ACBFStyle = QWidget() 0342 ACBFStyle.setLayout(QHBoxLayout()) 0343 self.ACBFStylesModel = QStandardItemModel() 0344 self.ACBFStyleClass = QListView() 0345 self.ACBFStyleClass.setModel(self.ACBFStylesModel) 0346 ACBFStyle.layout().addWidget(self.ACBFStyleClass) 0347 ACBFStyleEdit = QWidget() 0348 ACBFStyleEditVB = QVBoxLayout(ACBFStyleEdit) 0349 self.ACBFuseFont = QCheckBox(i18n("Use font")) 0350 self.ACBFFontList = QListView() 0351 self.ACBFFontList.setItemDelegate(font_list_delegate()) 0352 self.ACBFuseFont.toggled.connect(self.font_slot_enable_font_view) 0353 self.ACBFFontListModel = QStandardItemModel() 0354 self.ACBFFontListModel.rowsRemoved.connect(self.slot_font_current_style) 0355 self.ACBFFontListModel.itemChanged.connect(self.slot_font_current_style) 0356 self.btnAcbfAddFont = QPushButton() 0357 self.btnAcbfAddFont.setIcon(Application.icon("list-add")) 0358 self.btnAcbfAddFont.clicked.connect(self.font_slot_add_font) 0359 self.btn_acbf_remove_font = QPushButton() 0360 self.btn_acbf_remove_font.setIcon(Application.icon("edit-delete")) 0361 self.btn_acbf_remove_font.clicked.connect(self.font_slot_remove_font) 0362 self.ACBFFontList.setModel(self.ACBFFontListModel) 0363 self.ACBFdefaultFont = QComboBox() 0364 self.ACBFdefaultFont.addItems(["sans-serif", "serif", "monospace", "cursive", "fantasy"]) 0365 acbfFontButtons = QHBoxLayout() 0366 acbfFontButtons.addWidget(self.btnAcbfAddFont) 0367 acbfFontButtons.addWidget(self.btn_acbf_remove_font) 0368 self.ACBFBold = QCheckBox(i18n("Bold")) 0369 self.ACBFItal = QCheckBox(i18n("Italic")) 0370 self.ACBFStyleClass.clicked.connect(self.slot_set_style) 0371 self.ACBFStyleClass.selectionModel().selectionChanged.connect(self.slot_set_style) 0372 self.ACBFStylesModel.itemChanged.connect(self.slot_set_style) 0373 self.ACBFBold.toggled.connect(self.slot_font_current_style) 0374 self.ACBFItal.toggled.connect(self.slot_font_current_style) 0375 colorWidget = QGroupBox(self) 0376 colorWidget.setTitle(i18n("Text Colors")) 0377 colorWidget.setLayout(QVBoxLayout()) 0378 self.regularColor = QColorDialog() 0379 self.invertedColor = QColorDialog() 0380 self.btn_acbfRegColor = QPushButton(i18n("Regular Text"), self) 0381 self.btn_acbfRegColor.clicked.connect(self.slot_change_regular_color) 0382 self.btn_acbfInvColor = QPushButton(i18n("Inverted Text"), self) 0383 self.btn_acbfInvColor.clicked.connect(self.slot_change_inverted_color) 0384 colorWidget.layout().addWidget(self.btn_acbfRegColor) 0385 colorWidget.layout().addWidget(self.btn_acbfInvColor) 0386 ACBFStyleEditVB.addWidget(colorWidget) 0387 ACBFStyleEditVB.addWidget(self.ACBFuseFont) 0388 ACBFStyleEditVB.addWidget(self.ACBFFontList) 0389 ACBFStyleEditVB.addLayout(acbfFontButtons) 0390 ACBFStyleEditVB.addWidget(self.ACBFdefaultFont) 0391 ACBFStyleEditVB.addWidget(self.ACBFBold) 0392 ACBFStyleEditVB.addWidget(self.ACBFItal) 0393 ACBFStyleEditVB.addStretch() 0394 ACBFStyle.layout().addWidget(ACBFStyleEdit) 0395 0396 ACBFTabwidget = QTabWidget() 0397 ACBFTabwidget.addTab(ACBFdocInfo, i18n("Document Info")) 0398 ACBFTabwidget.addTab(ACBFAuthorInfo, i18n("Author Info")) 0399 ACBFTabwidget.addTab(ACBFStyle, i18n("Style Sheet")) 0400 ACBFExportSettings.layout().addWidget(ACBFTabwidget) 0401 mainWidget.addTab(ACBFExportSettings, i18n("ACBF")) 0402 0403 # Epub export, crop, resize, other questions. 0404 EPUBexportSettings = QWidget() 0405 EPUBexportSettings.setLayout(QVBoxLayout()) 0406 self.EPUBactive = QCheckBox(i18n("Export to EPUB")) 0407 EPUBexportSettings.layout().addWidget(self.EPUBactive) 0408 self.EPUBgroupResize = comic_export_resize_widget("EPUB") 0409 EPUBexportSettings.layout().addWidget(self.EPUBgroupResize) 0410 self.EPUBactive.clicked.connect(self.EPUBgroupResize.setEnabled) 0411 mainWidget.addTab(EPUBexportSettings, i18n("EPUB")) 0412 0413 # For Print. Crop, no resize. 0414 TIFFExportSettings = QWidget() 0415 TIFFExportSettings.setLayout(QVBoxLayout()) 0416 self.TIFFactive = QCheckBox(i18n("Export to TIFF")) 0417 TIFFExportSettings.layout().addWidget(self.TIFFactive) 0418 self.TIFFgroupResize = comic_export_resize_widget("TIFF") 0419 TIFFExportSettings.layout().addWidget(self.TIFFgroupResize) 0420 self.TIFFactive.clicked.connect(self.TIFFgroupResize.setEnabled) 0421 mainWidget.addTab(TIFFExportSettings, i18n("TIFF")) 0422 0423 # SVG, crop, resize, embed vs link. 0424 #SVGExportSettings = QWidget() 0425 0426 #mainWidget.addTab(SVGExportSettings, i18n("SVG")) 0427 0428 """ 0429 Add a history item to the acbf version history list. 0430 """ 0431 0432 def slot_add_history_item(self): 0433 newItem = QStandardItem() 0434 newItem.setText(str(i18n("v{version}-in this version...")).format(version=str(self.spnACBFVersion.value()))) 0435 self.ACBFhistoryModel.appendRow(newItem) 0436 0437 """ 0438 Get the margins by treating the active selection in a document as the trim area. 0439 This allows people to snap selections to a vector or something, and then get the margins. 0440 """ 0441 0442 def slot_set_margin_from_selection(self): 0443 doc = Application.activeDocument() 0444 if doc is not None: 0445 if doc.selection() is not None: 0446 self.spn_marginLeft.setValue(doc.selection().x()) 0447 self.spn_marginTop.setValue(doc.selection().y()) 0448 self.spn_marginRight.setValue(doc.width() - (doc.selection().x() + doc.selection().width())) 0449 self.spn_marginBottom.setValue(doc.height() - (doc.selection().y() + doc.selection().height())) 0450 0451 """ 0452 Add an author with default values initialised. 0453 """ 0454 0455 def slot_add_author(self): 0456 listItems = [] 0457 listItems.append(QStandardItem(i18n("Anon"))) # Nick name 0458 listItems.append(QStandardItem(i18n("John"))) # First name 0459 listItems.append(QStandardItem()) # Middle name 0460 listItems.append(QStandardItem(i18n("Doe"))) # Last name 0461 listItems.append(QStandardItem()) # email 0462 listItems.append(QStandardItem()) # homepage 0463 self.ACBFauthorModel.appendRow(listItems) 0464 0465 """ 0466 Remove the selected author from the author list. 0467 """ 0468 0469 def slot_remove_author(self): 0470 self.ACBFauthorModel.removeRow(self.ACBFauthorTable.currentIndex().row()) 0471 0472 """ 0473 Ensure that the drag and drop of authors doesn't mess up the labels. 0474 """ 0475 0476 def slot_reset_author_row_visual(self): 0477 headerLabelList = [] 0478 for i in range(self.ACBFauthorTable.verticalHeader().count()): 0479 headerLabelList.append(str(i)) 0480 for i in range(self.ACBFauthorTable.verticalHeader().count()): 0481 logicalI = self.ACBFauthorTable.verticalHeader().logicalIndex(i) 0482 headerLabelList[logicalI] = str(i + 1) 0483 self.ACBFauthorModel.setVerticalHeaderLabels(headerLabelList) 0484 """ 0485 Set the style item to the gui item's style. 0486 """ 0487 0488 def slot_set_style(self): 0489 index = self.ACBFStyleClass.currentIndex() 0490 if index.isValid(): 0491 item = self.ACBFStylesModel.item(index.row()) 0492 fontUsed = item.data(role=styleEnum.FONT) 0493 if fontUsed is not None: 0494 self.ACBFuseFont.setChecked(fontUsed) 0495 else: 0496 self.ACBFuseFont.setChecked(False) 0497 self.font_slot_enable_font_view() 0498 fontList = item.data(role=styleEnum.FONTLIST) 0499 self.ACBFFontListModel.clear() 0500 for font in fontList: 0501 NewItem = QStandardItem(font) 0502 NewItem.setEditable(True) 0503 self.ACBFFontListModel.appendRow(NewItem) 0504 self.ACBFdefaultFont.setCurrentText(str(item.data(role=styleEnum.FONTGENERIC))) 0505 bold = item.data(role=styleEnum.BOLD) 0506 if bold is not None: 0507 self.ACBFBold.setChecked(bold) 0508 else: 0509 self.ACBFBold.setChecked(False) 0510 italic = item.data(role=styleEnum.ITALIC) 0511 if italic is not None: 0512 self.ACBFItal.setChecked(italic) 0513 else: 0514 self.ACBFItal.setChecked(False) 0515 0516 """ 0517 Set the gui items to the currently selected style. 0518 """ 0519 0520 def slot_font_current_style(self): 0521 index = self.ACBFStyleClass.currentIndex() 0522 if index.isValid(): 0523 item = self.ACBFStylesModel.item(index.row()) 0524 fontList = [] 0525 for row in range(self.ACBFFontListModel.rowCount()): 0526 font = self.ACBFFontListModel.item(row) 0527 fontList.append(font.text()) 0528 item.setData(self.ACBFuseFont.isChecked(), role=styleEnum.FONT) 0529 item.setData(fontList, role=styleEnum.FONTLIST) 0530 item.setData(self.ACBFdefaultFont.currentText(), role=styleEnum.FONTGENERIC) 0531 item.setData(self.ACBFBold.isChecked(), role=styleEnum.BOLD) 0532 item.setData(self.ACBFItal.isChecked(), role=styleEnum.ITALIC) 0533 self.ACBFStylesModel.setItem(index.row(), item) 0534 """ 0535 Change the regular color 0536 """ 0537 0538 def slot_change_regular_color(self): 0539 if (self.regularColor.exec_() == QDialog.Accepted): 0540 square = QPixmap(32, 32) 0541 square.fill(self.regularColor.currentColor()) 0542 self.btn_acbfRegColor.setIcon(QIcon(square)) 0543 """ 0544 change the inverted color 0545 """ 0546 0547 def slot_change_inverted_color(self): 0548 if (self.invertedColor.exec_() == QDialog.Accepted): 0549 square = QPixmap(32, 32) 0550 square.fill(self.invertedColor.currentColor()) 0551 self.btn_acbfInvColor.setIcon(QIcon(square)) 0552 0553 def font_slot_enable_font_view(self): 0554 self.ACBFFontList.setEnabled(self.ACBFuseFont.isChecked()) 0555 self.btn_acbf_remove_font.setEnabled(self.ACBFuseFont.isChecked()) 0556 self.btnAcbfAddFont.setEnabled(self.ACBFuseFont.isChecked()) 0557 self.ACBFdefaultFont.setEnabled(self.ACBFuseFont.isChecked()) 0558 if self.ACBFFontListModel.rowCount() < 2: 0559 self.btn_acbf_remove_font.setEnabled(False) 0560 0561 def font_slot_add_font(self): 0562 NewItem = QStandardItem(QFont().family()) 0563 NewItem.setEditable(True) 0564 self.ACBFFontListModel.appendRow(NewItem) 0565 0566 def font_slot_remove_font(self): 0567 index = self.ACBFFontList.currentIndex() 0568 if index.isValid(): 0569 self.ACBFFontListModel.removeRow(index.row()) 0570 if self.ACBFFontListModel.rowCount() < 2: 0571 self.btn_acbf_remove_font.setEnabled(False) 0572 0573 """ 0574 Load the UI values from the config dictionary given. 0575 """ 0576 0577 def setConfig(self, config): 0578 if "cropToGuides" in config.keys(): 0579 self.chk_toOutmostGuides.setChecked(config["cropToGuides"]) 0580 if "cropLeft" in config.keys(): 0581 self.spn_marginLeft.setValue(config["cropLeft"]) 0582 if "cropTop" in config.keys(): 0583 self.spn_marginTop.setValue(config["cropTop"]) 0584 if "cropRight" in config.keys(): 0585 self.spn_marginRight.setValue(config["cropRight"]) 0586 if "cropBottom" in config.keys(): 0587 self.spn_marginBottom.setValue(config["cropBottom"]) 0588 if "labelsToRemove" in config.keys(): 0589 self.cmbLabelsRemove.setLabels(config["labelsToRemove"]) 0590 if "textLayerNames" in config.keys(): 0591 self.ln_text_layer_name.setText(", ".join(config["textLayerNames"])) 0592 else: 0593 self.ln_text_layer_name.setText("text") 0594 if "panelLayerNames" in config.keys(): 0595 self.ln_panel_layer_name.setText(", ".join(config["panelLayerNames"])) 0596 else: 0597 self.ln_panel_layer_name.setText("panels") 0598 self.CBZgroupResize.set_config(config) 0599 if "CBZactive" in config.keys(): 0600 self.CBZactive.setChecked(config["CBZactive"]) 0601 self.EPUBgroupResize.set_config(config) 0602 if "EPUBactive" in config.keys(): 0603 self.EPUBactive.setChecked(config["EPUBactive"]) 0604 self.TIFFgroupResize.set_config(config) 0605 if "TIFFactive" in config.keys(): 0606 self.TIFFactive.setChecked(config["TIFFactive"]) 0607 0608 if "acbfAuthor" in config.keys(): 0609 if isinstance(config["acbfAuthor"], list): 0610 for author in config["acbfAuthor"]: 0611 listItems = [] 0612 listItems.append(QStandardItem(author.get("nickname", ""))) 0613 listItems.append(QStandardItem(author.get("first-name", ""))) 0614 listItems.append(QStandardItem(author.get("initials", ""))) 0615 listItems.append(QStandardItem(author.get("last-name", ""))) 0616 listItems.append(QStandardItem(author.get("email", ""))) 0617 listItems.append(QStandardItem(author.get("homepage", ""))) 0618 self.ACBFauthorModel.appendRow(listItems) 0619 pass 0620 else: 0621 listItems = [] 0622 listItems.append(QStandardItem(config["acbfAuthor"])) # Nick name 0623 for i in range(0, 5): 0624 listItems.append(QStandardItem()) # First name 0625 self.ACBFauthorModel.appendRow(listItems) 0626 0627 if "uuid" in config.keys(): 0628 self.lnACBFID.setText(config["uuid"]) 0629 elif "acbfID" in config.keys(): 0630 self.lnACBFID.setText(config["acbfID"]) 0631 else: 0632 config["uuid"] = QUuid.createUuid().toString() 0633 self.lnACBFID.setText(config["uuid"]) 0634 if "acbfVersion" in config.keys(): 0635 self.spnACBFVersion.setValue(config["acbfVersion"]) 0636 if "acbfHistory" in config.keys(): 0637 for h in config["acbfHistory"]: 0638 item = QStandardItem() 0639 item.setText(h) 0640 self.ACBFhistoryModel.appendRow(item) 0641 if "acbfStyles" in config.keys(): 0642 styleDict = config.get("acbfStyles", {}) 0643 for key in self.acbfStylesList: 0644 keyDict = styleDict.get(key, {}) 0645 style = QStandardItem(key.title()) 0646 style.setCheckable(True) 0647 if key in styleDict.keys(): 0648 style.setCheckState(Qt.Checked) 0649 else: 0650 style.setCheckState(Qt.Unchecked) 0651 fontOn = False 0652 if "font" in keyDict.keys() or "genericfont" in keyDict.keys(): 0653 fontOn = True 0654 style.setData(fontOn, role=styleEnum.FONT) 0655 if "font" in keyDict: 0656 fontlist = keyDict["font"] 0657 if isinstance(fontlist, list): 0658 font = keyDict.get("font", QFont().family()) 0659 style.setData(font, role=styleEnum.FONTLIST) 0660 else: 0661 style.setData([fontlist], role=styleEnum.FONTLIST) 0662 else: 0663 style.setData([QFont().family()], role=styleEnum.FONTLIST) 0664 style.setData(keyDict.get("genericfont", "sans-serif"), role=styleEnum.FONTGENERIC) 0665 style.setData(keyDict.get("bold", False), role=styleEnum.BOLD) 0666 style.setData(keyDict.get("ital", False), role=styleEnum.ITALIC) 0667 self.ACBFStylesModel.appendRow(style) 0668 keyDict = styleDict.get("general", {}) 0669 self.regularColor.setCurrentColor(QColor(keyDict.get("color", "#000000"))) 0670 square = QPixmap(32, 32) 0671 square.fill(self.regularColor.currentColor()) 0672 self.btn_acbfRegColor.setIcon(QIcon(square)) 0673 keyDict = styleDict.get("inverted", {}) 0674 self.invertedColor.setCurrentColor(QColor(keyDict.get("color", "#FFFFFF"))) 0675 square.fill(self.invertedColor.currentColor()) 0676 self.btn_acbfInvColor.setIcon(QIcon(square)) 0677 else: 0678 for key in self.acbfStylesList: 0679 style = QStandardItem(key.title()) 0680 style.setCheckable(True) 0681 style.setCheckState(Qt.Unchecked) 0682 style.setData(False, role=styleEnum.FONT) 0683 style.setData(QFont().family(), role=styleEnum.FONTLIST) 0684 style.setData("sans-serif", role=styleEnum.FONTGENERIC) 0685 style.setData(False, role=styleEnum.BOLD) #Bold 0686 style.setData(False, role=styleEnum.ITALIC) #Italic 0687 self.ACBFStylesModel.appendRow(style) 0688 self.CBZgroupResize.setEnabled(self.CBZactive.isChecked()) 0689 self.lnTranslatorHeader.setText(config.get("translatorHeader", "Translator's Notes")) 0690 self.chkIncludeTranslatorComments.setChecked(config.get("includeTranslComment", False)) 0691 0692 """ 0693 Store the GUI values into the config dictionary given. 0694 0695 @return the config diactionary filled with new values. 0696 """ 0697 0698 def getConfig(self, config): 0699 0700 config["cropToGuides"] = self.chk_toOutmostGuides.isChecked() 0701 config["cropLeft"] = self.spn_marginLeft.value() 0702 config["cropTop"] = self.spn_marginTop.value() 0703 config["cropBottom"] = self.spn_marginRight.value() 0704 config["cropRight"] = self.spn_marginBottom.value() 0705 config["labelsToRemove"] = self.cmbLabelsRemove.getLabels() 0706 config["CBZactive"] = self.CBZactive.isChecked() 0707 config = self.CBZgroupResize.get_config(config) 0708 config["EPUBactive"] = self.EPUBactive.isChecked() 0709 config = self.EPUBgroupResize.get_config(config) 0710 config["TIFFactive"] = self.TIFFactive.isChecked() 0711 config = self.TIFFgroupResize.get_config(config) 0712 authorList = [] 0713 for row in range(self.ACBFauthorTable.verticalHeader().count()): 0714 logicalIndex = self.ACBFauthorTable.verticalHeader().logicalIndex(row) 0715 listEntries = ["nickname", "first-name", "initials", "last-name", "email", "homepage"] 0716 author = {} 0717 for i in range(len(listEntries)): 0718 entry = self.ACBFauthorModel.data(self.ACBFauthorModel.index(logicalIndex, i)) 0719 if entry is None: 0720 entry = " " 0721 if entry.isspace() is False and len(entry) > 0: 0722 author[listEntries[i]] = entry 0723 elif listEntries[i] in author.keys(): 0724 author.pop(listEntries[i]) 0725 authorList.append(author) 0726 config["acbfAuthor"] = authorList 0727 config["acbfVersion"] = self.spnACBFVersion.value() 0728 versionList = [] 0729 for r in range(self.ACBFhistoryModel.rowCount()): 0730 index = self.ACBFhistoryModel.index(r, 0) 0731 versionList.append(self.ACBFhistoryModel.data(index, Qt.DisplayRole)) 0732 config["acbfHistory"] = versionList 0733 0734 acbfStylesDict = {} 0735 for row in range(0, self.ACBFStylesModel.rowCount()): 0736 entry = self.ACBFStylesModel.item(row) 0737 if entry.checkState() == Qt.Checked: 0738 key = entry.text().lower() 0739 style = {} 0740 if entry.data(role=styleEnum.FONT): 0741 font = entry.data(role=styleEnum.FONTLIST) 0742 if font is not None: 0743 style["font"] = font 0744 genericfont = entry.data(role=styleEnum.FONTGENERIC) 0745 if font is not None: 0746 style["genericfont"] = genericfont 0747 bold = entry.data(role=styleEnum.BOLD) 0748 if bold is not None: 0749 style["bold"] = bold 0750 italic = entry.data(role=styleEnum.ITALIC) 0751 if italic is not None: 0752 style["ital"] = italic 0753 acbfStylesDict[key] = style 0754 acbfStylesDict["general"] = {"color": self.regularColor.currentColor().name()} 0755 acbfStylesDict["inverted"] = {"color": self.invertedColor.currentColor().name()} 0756 config["acbfStyles"] = acbfStylesDict 0757 config["translatorHeader"] = self.lnTranslatorHeader.text() 0758 config["includeTranslComment"] = self.chkIncludeTranslatorComments.isChecked() 0759 0760 # Turn this into something that retrieves from a line-edit when string freeze is over. 0761 config["textLayerNames"] = self.ln_text_layer_name.text().split(",") 0762 config["panelLayerNames"] = self.ln_panel_layer_name.text().split(",") 0763 return config