File indexing completed on 2025-03-09 04:10:18

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