assignprofiledialog.py 2.16 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
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from krita import *
16 17


18 19 20 21 22 23 24 25 26 27
class AssignProfileDialog(Extension):

    def __init__(self, parent):
        super().__init__(parent)

    def assignProfile(self):
        doc = Application.activeDocument()
        if doc == None:
            QMessageBox.information(Application.activeWindow().qwindow(), "Assign Profile", "There is no active document.")
            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 38 39 40 41 42 43 44 45 46
        vbox = QVBoxLayout(self.dialog)
        vbox.addWidget(self.cmbProfile)
        self.buttonBox = QDialogButtonBox(self.dialog)
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        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 54 55 56
        pass
    
    def createActions(self, window):
        action = window.createAction("assing_profile_to_image", "Assign Profile to Image")
57 58 59
        action.triggered.connect(self.assignProfile)

Scripter.addExtension(AssignProfileDialog(Application))