Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

assignprofiledialog.py 2.35 KB
Newer Older
1
# This script is licensed CC 0 1.0, so that you can learn from it.
2

3
# ------ CC 0 1.0 ---------------
4

5 6 7 8
# 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.
9

10 11 12 13
# 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
14

15 16 17 18
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QDialogButtonBox, QDialog,
                             QMessageBox, QComboBox, QVBoxLayout)
from krita import Extension
19 20


21 22 23
class AssignProfileDialog(Extension):

    def __init__(self, parent):
24
        super(AssignProfileDialog, self).__init__(parent)
25 26 27

    def assignProfile(self):
        doc = Application.activeDocument()
28
        if doc is None:
29 30 31 32
            QMessageBox.information(
                Application.activeWindow().qwindow(),
                i18n("Assign Profile"),
                i18n("There is no active document."))
33
            return
34

35
        self.dialog = QDialog(Application.activeWindow().qwindow())
36

37
        self.cmbProfile = QComboBox(self.dialog)
38 39
        for profile in sorted(
                Application.profiles(doc.colorModel(), doc.colorDepth())):
40
            self.cmbProfile.addItem(profile)
41

42 43 44
        vbox = QVBoxLayout(self.dialog)
        vbox.addWidget(self.cmbProfile)
        self.buttonBox = QDialogButtonBox(self.dialog)
45
        self.buttonBox.setOrientation(Qt.Horizontal)
46 47
        self.buttonBox.setStandardButtons(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
48 49 50 51 52 53 54
        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_()
55

56 57 58 59 60
    def accept(self):
        doc = Application.activeDocument()
        doc.setColorProfile(self.cmbProfile.currentText())

    def setup(self):
61
        pass
62

63
    def createActions(self, window):
64 65
        action = window.createAction("assing_profile_to_image",
                                     i18n("Assign Profile to Image"))
66
        action.triggered.connect(self.assignProfile)