Krita Source Code Documentation
Loading...
Searching...
No Matches
comics_project_settings_dialog.py
Go to the documentation of this file.
1"""
2SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3
4This file is part of the Comics Project Management Tools(CPMT).
5
6SPDX-License-Identifier: GPL-3.0-or-later
7"""
8
9"""
10A dialog for editing the general project settings.
11"""
12import os
13try:
14 from PyQt6.QtWidgets import QWidget, QDialog, QDialogButtonBox, QHBoxLayout, QFormLayout, QLabel, QLineEdit, QToolButton, QFrame, QComboBox, QSizePolicy
15 from PyQt6.QtCore import QDir, Qt, pyqtSignal
16 from PyQt6.QtGui import QAction
17except:
18 from PyQt5.QtWidgets import QWidget, QDialog, QDialogButtonBox, QHBoxLayout, QFormLayout, QLabel, QLineEdit, QToolButton, QFrame, QAction, QComboBox, QSizePolicy
19 from PyQt5.QtCore import QDir, Qt, pyqtSignal
20from krita import FileDialog
21from builtins import i18n, Application
22
23"""
24A Widget that contains both a qlabel and a button for selecting a path.
25"""
26
27
28class path_select(QWidget):
29 projectUrl = ""
30 question = i18n("Which folder?")
31
32 """
33 emits when a new directory has been chosen.
34 """
35 locationChanged = pyqtSignal()
36 """
37 Initialise the widget.
38 @param question is the question asked when selecting a directory.
39 @param project url is the url to which the label is relative.
40 """
41
42 def __init__(self, parent=None, flags=None, question=str(), projectUrl=None):
43 super(path_select, self).__init__(parent)
44 self.setLayout(QHBoxLayout())
45 self.location = QLabel()
46 self.button = QToolButton() # Until we have a proper icon
47 self.layout().addWidget(self.location)
48 self.layout().addWidget(self.button)
49 self.layout().setContentsMargins(0, 0, 0, 0)
50 self.setSizePolicy(QSizePolicy.Policy.MinimumExpanding, QSizePolicy.Policy.Minimum)
51 self.location.setFrameStyle(QFrame.Shape.StyledPanel | QFrame.Shadow.Sunken)
52 self.button.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum)
53 self.location.setSizePolicy(QSizePolicy.Policy.MinimumExpanding, QSizePolicy.Policy.Minimum)
54 self.location.setAlignment(Qt.AlignmentFlag.AlignRight)
55 self.location.setLineWidth(1)
56 if projectUrl is None:
57 self.projectUrlprojectUrl = QDir.homePath()
58 else:
59 self.projectUrlprojectUrl = projectUrl
60 self.question = question
61 self.action_change_folder = QAction(i18n("Change Folder"), self)
62 self.action_change_folder.setIcon(Application.icon("folder"))
64 self.button.setDefaultAction(self.action_change_folder)
65
66 """
67 pops up a directory chooser widget, and when a directory is chosen a locationChanged signal is emitted.
68 """
69
71 location = FileDialog.getExistingDirectory(caption=self.question, directory=self.projectUrlprojectUrl)
72 if location is not None and location.isspace() is False and len(location) > 0:
73 location = os.path.relpath(location, self.projectUrlprojectUrl)
74 self.location.setText(location)
75 self.locationChanged.emit()
76 """
77 Set the location.
78 @param path - the location relative to the projectUrl.
79 """
80
81 def setLocation(self, path=str()):
82 self.location.setText(path)
83 """
84 Get the location.
85 @returns a string with the location relative to the projectUrl.
86 """
87
88 def getLocation(self):
89 return str(self.location.text())
90
91
92"""
93Dialog for editing basic project details like the project name, default template,
94template location, etc.
95"""
96
97
99 configGroup = "ComicsProjectManagementTools"
100 """
101 Initialise the editor.
102 @param projectUrl - The directory to which all paths are relative.
103 """
104
105 def __init__(self, projectUrl=str()):
106 super().__init__()
107 self.projectUrl = projectUrl
108 layout = QFormLayout()
109 self.setLayout(layout)
110 self.setWindowTitle(i18n("Comic Project Settings"))
111 buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
112
113 buttons.accepted.connect(self.accept)
114 buttons.rejected.connect(self.reject)
115 self.lnProjectName = QLineEdit()
116 self.lnProjectConcept = QLineEdit()
117 self.cmb_defaultTemplate = QComboBox()
118
119 self.pagesLocation = path_select(question=i18n("Where should the pages go?"), projectUrl=self.projectUrl)
120 self.exportLocation = path_select(question=i18n("Where should the export go?"), projectUrl=self.projectUrl)
121 self.templateLocation = path_select(question=i18n("Where are the templates?"), projectUrl=self.projectUrl)
122 self.translationLocation = path_select(question=i18n("Where are the translations?"), projectUrl=self.projectUrl)
123 self.keyLocation = path_select(question=i18n("Where are the extra auto-completion keys located?"))
124 self.keyLocation.setToolTip(i18n("The location for extra autocompletion keys in the metadata editor. Point this at a folder containing key_characters/key_format/key_genre/key_rating/key_author_roles/key_other with inside txt files (csv for rating) containing the extra auto-completion keys, each on a new line. This path is stored in the Krita configuration, and not the project configuration."))
125 self.templateLocation.locationChanged.connect(self.refill_templatesrefill_templates)
126
127 layout.addRow(i18n("Project name:"), self.lnProjectName)
128 layout.addRow(i18n("Project concept:"), self.lnProjectConcept)
129 layout.addRow(i18n("Pages folder:"), self.pagesLocation)
130 layout.addRow(i18n("Export folder:"), self.exportLocation)
131 layout.addRow(i18n("Template folder:"), self.templateLocation)
132 layout.addRow(i18n("Translation folder:"), self.translationLocation)
133 layout.addRow(i18n("Default template:"), self.cmb_defaultTemplate)
134 layout.addRow(i18n("Extra keys folder:"), self.keyLocation)
135
136 self.layout().addWidget(buttons)
137
138 """
139 Fill the templates doc with the kra files found in the templates directory.
140 Might want to extend this to other files as well, as they basically get resaved anyway...
141 """
142
144 self.cmb_defaultTemplate.clear()
145 templateLocation = os.path.join(self.projectUrl, self.templateLocation.getLocation())
146 for entry in os.scandir(templateLocation):
147 if entry.name.endswith('.kra') and entry.is_file():
148 name = os.path.relpath(entry.path, templateLocation)
149 self.cmb_defaultTemplate.addItem(name)
150
151 """
152 Load the UI values from the config dictionary given.
153 """
154
155 def setConfig(self, config, projectUrl):
156
157 self.projectUrl = projectUrl
158 if "projectName"in config.keys():
159 self.lnProjectName.setText(config["projectName"])
160 if "concept"in config.keys():
161 self.lnProjectConcept.setText(config["concept"])
162 if "pagesLocation" in config.keys():
163 self.pagesLocation.setLocation(config.get("pagesLocation", "pages"))
164 self.exportLocation.setLocation(config.get("exportLocation", "export"))
165 self.templateLocation.setLocation(config.get("templateLocation", "templates"))
166 self.translationLocation.setLocation(config.get("translationLocation", "translations"))
168 self.keyLocation.setLocation(Application.readSetting(self.configGroupconfigGroup, "extraKeysLocation", str()))
169
170 """
171 Store the GUI values into the config dictionary given.
172
173 @return the config diactionary filled with new values.
174 """
175
176 def getConfig(self, config):
177 config["projectName"] = self.lnProjectName.text()
178 config["concept"] = self.lnProjectConcept.text()
179 config["pagesLocation"] = self.pagesLocation.getLocation()
180 config["exportLocation"] = self.exportLocation.getLocation()
181 config["templateLocation"] = self.templateLocation.getLocation()
182 config["translationLocation"] = self.translationLocation.getLocation()
183 config["singlePageTemplate"] = os.path.join(self.templateLocation.getLocation(), self.cmb_defaultTemplate.currentText())
184 Application.writeSetting(self.configGroupconfigGroup, "extraKeysLocation", self.keyLocation.getLocation())
185 return config
static QString getExistingDirectory(QWidget *parent=nullptr, const QString &caption=QString(), const QString &directory=QString(), const QString &dialogName=QString())
Create and show a file dialog and return the name of an existing directory selected by the user.
__init__(self, parent=None, flags=None, question=str(), projectUrl=None)