Changeset View
Changeset View
Standalone View
Standalone View
plugins/python/colorspace/uicolorspace.py
1 | ''' | 1 | # This script is licensed CC 0 1.0, so that you can learn from it. | ||
---|---|---|---|---|---|
2 | This script is licensed CC 0 1.0, so that you can learn from it. | | |||
3 | 2 | | |||
4 | ------ CC 0 1.0 --------------- | 3 | # ------ CC 0 1.0 --------------- | ||
5 | 4 | | |||
6 | The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. | 5 | # The person who associated a work with this deed has dedicated the | ||
6 | # work to the public domain by waiving all of his or her rights to the | ||||
7 | # work worldwide under copyright law, including all related and | ||||
8 | # neighboring rights, to the extent allowed by law. | ||||
7 | 9 | | |||
8 | You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. | 10 | # You can copy, modify, distribute and perform the work, even for | ||
11 | # commercial purposes, all without asking permission. | ||||
12 | | ||||
13 | # https://creativecommons.org/publicdomain/zero/1.0/legalcode | ||||
9 | 14 | | |||
10 | https://creativecommons.org/publicdomain/zero/1.0/legalcode | | |||
11 | ''' | | |||
12 | from . import colorspacedialog | 15 | from . import colorspacedialog | ||
13 | from .components import colormodelcombobox, colordepthcombobox, colorprofilecombobox | 16 | from .components import ( | ||
17 | colordepthcombobox, | ||||
18 | colormodelcombobox, | ||||
19 | colorprofilecombobox, | ||||
20 | ) | ||||
14 | from PyQt5.QtCore import Qt | 21 | from PyQt5.QtCore import Qt | ||
15 | from PyQt5.QtWidgets import (QFormLayout, QListWidget, QListWidgetItem, | 22 | from PyQt5.QtWidgets import (QFormLayout, QListWidget, | ||
16 | QAbstractItemView, QComboBox, QDialogButtonBox, | 23 | QAbstractItemView, QDialogButtonBox, | ||
17 | QVBoxLayout, QFrame, QMessageBox, QPushButton, | 24 | QVBoxLayout, QFrame, QMessageBox, QPushButton, | ||
18 | QHBoxLayout, QAbstractScrollArea) | 25 | QAbstractScrollArea) | ||
19 | from PyQt5.QtGui import QIcon | 26 | from PyQt5.QtGui import QIcon | ||
20 | import krita | 27 | import krita | ||
21 | from . import resources_rc | | |||
22 | 28 | | |||
23 | 29 | | |||
24 | class UIColorSpace(object): | 30 | class UIColorSpace(object): | ||
25 | 31 | | |||
26 | def __init__(self): | 32 | def __init__(self): | ||
27 | self.mainDialog = colorspacedialog.ColorSpaceDialog() | 33 | self.mainDialog = colorspacedialog.ColorSpaceDialog() | ||
28 | self.mainLayout = QVBoxLayout(self.mainDialog) | 34 | self.mainLayout = QVBoxLayout(self.mainDialog) | ||
29 | self.formLayout = QFormLayout() | 35 | self.formLayout = QFormLayout() | ||
30 | self.documentLayout = QVBoxLayout() | 36 | self.documentLayout = QVBoxLayout() | ||
31 | self.refreshButton = QPushButton(QIcon(':/icons/refresh.svg'), i18n("Refresh")) | 37 | self.refreshButton = QPushButton(QIcon(':/icons/refresh.svg'), | ||
38 | i18n("Refresh")) | ||||
32 | self.widgetDocuments = QListWidget() | 39 | self.widgetDocuments = QListWidget() | ||
33 | self.colorModelComboBox = colormodelcombobox.ColorModelComboBox(self) | 40 | self.colorModelComboBox = colormodelcombobox.ColorModelComboBox(self) | ||
34 | self.colorDepthComboBox = colordepthcombobox.ColorDepthComboBox(self) | 41 | self.colorDepthComboBox = colordepthcombobox.ColorDepthComboBox(self) | ||
35 | self.colorProfileComboBox = colorprofilecombobox.ColorProfileComboBox(self) | 42 | self.colorProfileComboBox = \ | ||
36 | self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) | 43 | colorprofilecombobox.ColorProfileComboBox(self) | ||
44 | self.buttonBox = QDialogButtonBox( | ||||
45 | QDialogButtonBox.Ok | QDialogButtonBox.Cancel) | ||||
37 | 46 | | |||
38 | self.kritaInstance = krita.Krita.instance() | 47 | self.kritaInstance = krita.Krita.instance() | ||
39 | self.documentsList = [] | 48 | self.documentsList = [] | ||
40 | self.colorModelsList = [] | 49 | self.colorModelsList = [] | ||
41 | self.colorDepthsList = [] | 50 | self.colorDepthsList = [] | ||
42 | self.colorProfilesList = [] | 51 | self.colorProfilesList = [] | ||
43 | 52 | | |||
44 | self.refreshButton.clicked.connect(self.refreshButtonClicked) | 53 | self.refreshButton.clicked.connect(self.refreshButtonClicked) | ||
45 | self.buttonBox.accepted.connect(self.confirmButton) | 54 | self.buttonBox.accepted.connect(self.confirmButton) | ||
46 | self.buttonBox.rejected.connect(self.mainDialog.close) | 55 | self.buttonBox.rejected.connect(self.mainDialog.close) | ||
47 | 56 | | |||
48 | self.mainDialog.setWindowModality(Qt.NonModal) | 57 | self.mainDialog.setWindowModality(Qt.NonModal) | ||
49 | self.widgetDocuments.setSelectionMode(QAbstractItemView.MultiSelection) | 58 | self.widgetDocuments.setSelectionMode(QAbstractItemView.MultiSelection) | ||
50 | self.widgetDocuments.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents) | 59 | self.widgetDocuments.setSizeAdjustPolicy( | ||
60 | QAbstractScrollArea.AdjustToContents) | ||||
51 | 61 | | |||
52 | def initialize(self): | 62 | def initialize(self): | ||
53 | self.loadDocuments() | 63 | self.loadDocuments() | ||
54 | self.loadColorModels() | 64 | self.loadColorModels() | ||
55 | self.loadColorDepths() | 65 | self.loadColorDepths() | ||
56 | self.loadColorProfiles() | 66 | self.loadColorProfiles() | ||
57 | 67 | | |||
58 | self.documentLayout.addWidget(self.widgetDocuments) | 68 | self.documentLayout.addWidget(self.widgetDocuments) | ||
59 | self.documentLayout.addWidget(self.refreshButton) | 69 | self.documentLayout.addWidget(self.refreshButton) | ||
60 | 70 | | |||
61 | self.formLayout.addRow(i18n("Documents:"), self.documentLayout) | 71 | self.formLayout.addRow(i18n("Documents:"), self.documentLayout) | ||
62 | self.formLayout.addRow(i18n("Color model:"), self.colorModelComboBox) | 72 | self.formLayout.addRow(i18n("Color model:"), self.colorModelComboBox) | ||
63 | self.formLayout.addRow(i18n("Color depth:"), self.colorDepthComboBox) | 73 | self.formLayout.addRow(i18n("Color depth:"), self.colorDepthComboBox) | ||
64 | self.formLayout.addRow(i18n("Color profile:"), self.colorProfileComboBox) | 74 | self.formLayout.addRow(i18n("Color profile:"), | ||
75 | self.colorProfileComboBox) | ||||
65 | 76 | | |||
66 | self.line = QFrame() | 77 | self.line = QFrame() | ||
67 | self.line.setFrameShape(QFrame.HLine) | 78 | self.line.setFrameShape(QFrame.HLine) | ||
68 | self.line.setFrameShadow(QFrame.Sunken) | 79 | self.line.setFrameShadow(QFrame.Sunken) | ||
69 | 80 | | |||
70 | self.mainLayout.addLayout(self.formLayout) | 81 | self.mainLayout.addLayout(self.formLayout) | ||
71 | self.mainLayout.addWidget(self.line) | 82 | self.mainLayout.addWidget(self.line) | ||
72 | self.mainLayout.addWidget(self.buttonBox) | 83 | self.mainLayout.addWidget(self.buttonBox) | ||
73 | 84 | | |||
74 | self.mainDialog.resize(500, 300) | 85 | self.mainDialog.resize(500, 300) | ||
75 | self.mainDialog.setWindowTitle(i18n("Color Space")) | 86 | self.mainDialog.setWindowTitle(i18n("Color Space")) | ||
76 | self.mainDialog.setSizeGripEnabled(True) | 87 | self.mainDialog.setSizeGripEnabled(True) | ||
77 | self.mainDialog.show() | 88 | self.mainDialog.show() | ||
78 | self.mainDialog.activateWindow() | 89 | self.mainDialog.activateWindow() | ||
79 | 90 | | |||
80 | def loadColorModels(self): | 91 | def loadColorModels(self): | ||
81 | self.colorModelsList = sorted(self.kritaInstance.colorModels()) | 92 | self.colorModelsList = sorted(self.kritaInstance.colorModels()) | ||
82 | 93 | | |||
83 | self.colorModelComboBox.addItems(self.colorModelsList) | 94 | self.colorModelComboBox.addItems(self.colorModelsList) | ||
84 | 95 | | |||
85 | def loadColorDepths(self): | 96 | def loadColorDepths(self): | ||
86 | self.colorDepthComboBox.clear() | 97 | self.colorDepthComboBox.clear() | ||
87 | 98 | | |||
88 | colorModel = self.colorModelComboBox.currentText() | 99 | colorModel = self.colorModelComboBox.currentText() | ||
89 | self.colorDepthsList = sorted(self.kritaInstance.colorDepths(colorModel)) | 100 | self.colorDepthsList = sorted( | ||
101 | self.kritaInstance.colorDepths(colorModel)) | ||||
90 | 102 | | |||
91 | self.colorDepthComboBox.addItems(self.colorDepthsList) | 103 | self.colorDepthComboBox.addItems(self.colorDepthsList) | ||
92 | 104 | | |||
93 | def loadColorProfiles(self): | 105 | def loadColorProfiles(self): | ||
94 | self.colorProfileComboBox.clear() | 106 | self.colorProfileComboBox.clear() | ||
95 | 107 | | |||
96 | colorModel = self.colorModelComboBox.currentText() | 108 | colorModel = self.colorModelComboBox.currentText() | ||
97 | colorDepth = self.colorDepthComboBox.currentText() | 109 | colorDepth = self.colorDepthComboBox.currentText() | ||
98 | self.colorProfilesList = sorted(self.kritaInstance.profiles(colorModel, colorDepth)) | 110 | self.colorProfilesList = sorted( | ||
111 | self.kritaInstance.profiles(colorModel, colorDepth)) | ||||
99 | 112 | | |||
100 | self.colorProfileComboBox.addItems(self.colorProfilesList) | 113 | self.colorProfileComboBox.addItems(self.colorProfilesList) | ||
101 | 114 | | |||
102 | def loadDocuments(self): | 115 | def loadDocuments(self): | ||
103 | self.widgetDocuments.clear() | 116 | self.widgetDocuments.clear() | ||
104 | 117 | | |||
105 | self.documentsList = [document for document in self.kritaInstance.documents() if document.fileName()] | 118 | self.documentsList = [ | ||
119 | document for document in self.kritaInstance.documents() | ||||
120 | if document.fileName() | ||||
121 | ] | ||||
106 | 122 | | |||
107 | for document in self.documentsList: | 123 | for document in self.documentsList: | ||
108 | self.widgetDocuments.addItem(document.fileName()) | 124 | self.widgetDocuments.addItem(document.fileName()) | ||
109 | 125 | | |||
110 | def refreshButtonClicked(self): | 126 | def refreshButtonClicked(self): | ||
111 | self.loadDocuments() | 127 | self.loadDocuments() | ||
112 | 128 | | |||
113 | def confirmButton(self): | 129 | def confirmButton(self): | ||
114 | selectedPaths = [item.text() for item in self.widgetDocuments.selectedItems()] | 130 | selectedPaths = [ | ||
115 | selectedDocuments = [document for document in self.documentsList for path in selectedPaths if path == document.fileName()] | 131 | item.text() for item in self.widgetDocuments.selectedItems()] | ||
132 | selectedDocuments = [ | ||||
133 | document for document in self.documentsList | ||||
134 | for path in selectedPaths if path == document.fileName() | ||||
135 | ] | ||||
116 | 136 | | |||
117 | self.msgBox = QMessageBox(self.mainDialog) | 137 | self.msgBox = QMessageBox(self.mainDialog) | ||
118 | if selectedDocuments: | 138 | if selectedDocuments: | ||
119 | self.convertColorSpace(selectedDocuments) | 139 | self.convertColorSpace(selectedDocuments) | ||
120 | self.msgBox.setText(i18n("The selected documents has been converted.")) | 140 | self.msgBox.setText( | ||
141 | i18n("The selected documents has been converted.")) | ||||
121 | else: | 142 | else: | ||
122 | self.msgBox.setText(i18n("Select at least one document.")) | 143 | self.msgBox.setText(i18n("Select at least one document.")) | ||
123 | self.msgBox.exec_() | 144 | self.msgBox.exec_() | ||
124 | 145 | | |||
125 | def convertColorSpace(self, documents): | 146 | def convertColorSpace(self, documents): | ||
126 | for document in documents: | 147 | for document in documents: | ||
127 | document.setColorSpace(self.colorModelComboBox.currentText(), | 148 | document.setColorSpace(self.colorModelComboBox.currentText(), | ||
128 | self.colorDepthComboBox.currentText(), | 149 | self.colorDepthComboBox.currentText(), | ||
129 | self.colorProfileComboBox.currentText()) | 150 | self.colorProfileComboBox.currentText()) |