assignprofiledialog.py 2.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
'''
This script is licensed CC 0 1.0, so that you can learn from it.

------ CC 0 1.0 ---------------

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.

You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

https://creativecommons.org/publicdomain/zero/1.0/legalcode
'''
12 13 14 15
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QDialogButtonBox, QDialog,
                             QMessageBox, QComboBox, QVBoxLayout)
from krita import Extension
16 17


18 19 20
class AssignProfileDialog(Extension):

    def __init__(self, parent):
21
        super(AssignProfileDialog, self).__init__(parent)
22 23 24

    def assignProfile(self):
        doc = Application.activeDocument()
25
        if doc is None:
Pino Toscano's avatar
Pino Toscano committed
26
            QMessageBox.information(Application.activeWindow().qwindow(), i18n("Assign Profile"), i18n("There is no active document."))
27
            return
28

29
        self.dialog = QDialog(Application.activeWindow().qwindow())
30

31 32 33
        self.cmbProfile = QComboBox(self.dialog)
        for profile in sorted(Application.profiles(doc.colorModel(), doc.colorDepth())):
            self.cmbProfile.addItem(profile)
34

35 36 37
        vbox = QVBoxLayout(self.dialog)
        vbox.addWidget(self.cmbProfile)
        self.buttonBox = QDialogButtonBox(self.dialog)
38
        self.buttonBox.setOrientation(Qt.Horizontal)
39 40 41 42 43 44 45 46
        self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        self.buttonBox.accepted.connect(self.dialog.accept)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.dialog.reject)
        vbox.addWidget(self.buttonBox)
        self.dialog.show()
        self.dialog.activateWindow()
        self.dialog.exec_()
47

48 49 50 51 52
    def accept(self):
        doc = Application.activeDocument()
        doc.setColorProfile(self.cmbProfile.currentText())

    def setup(self):
53
        pass
54

55
    def createActions(self, window):
Pino Toscano's avatar
Pino Toscano committed
56
        action = window.createAction("assing_profile_to_image", i18n("Assign Profile to Image"))
57 58
        action.triggered.connect(self.assignProfile)

59

60
Scripter.addExtension(AssignProfileDialog(Application))