Changeset View
Changeset View
Standalone View
Standalone View
plugins/python/tenscripts/uitenscripts.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 PyQt5.QtCore import Qt | 15 | from PyQt5.QtCore import Qt | ||
13 | from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QPushButton, | 16 | from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QPushButton, | ||
14 | QLineEdit, QScrollArea, QGridLayout, QFileDialog, | 17 | QLineEdit, QScrollArea, QGridLayout, QFileDialog, | ||
15 | QLabel, QDialogButtonBox) | 18 | QLabel, QDialogButtonBox) | ||
16 | from . import tenscriptsdialog | 19 | from . import tenscriptsdialog | ||
17 | import krita | 20 | import krita | ||
18 | 21 | | |||
19 | 22 | | |||
20 | class UITenScripts(object): | 23 | class UITenScripts(object): | ||
21 | 24 | | |||
22 | def __init__(self): | 25 | def __init__(self): | ||
23 | self.kritaInstance = krita.Krita.instance() | 26 | self.kritaInstance = krita.Krita.instance() | ||
24 | self.mainDialog = tenscriptsdialog.TenScriptsDialog(self, self.kritaInstance.activeWindow().qwindow()) | 27 | self.mainDialog = tenscriptsdialog.TenScriptsDialog( | ||
28 | self, self.kritaInstance.activeWindow().qwindow()) | ||||
25 | 29 | | |||
26 | self.buttonBox = QDialogButtonBox(self.mainDialog) | 30 | self.buttonBox = QDialogButtonBox(self.mainDialog) | ||
27 | self.layout = QVBoxLayout(self.mainDialog) | 31 | self.layout = QVBoxLayout(self.mainDialog) | ||
28 | self.baseWidget = QWidget() | 32 | self.baseWidget = QWidget() | ||
29 | self.baseArea = QWidget() | 33 | self.baseArea = QWidget() | ||
30 | self.scrollArea = QScrollArea() | 34 | self.scrollArea = QScrollArea() | ||
31 | self.scriptsLayout = QGridLayout() | 35 | self.scriptsLayout = QGridLayout() | ||
32 | 36 | | |||
33 | self.buttonBox.accepted.connect(self.mainDialog.accept) | 37 | self.buttonBox.accepted.connect(self.mainDialog.accept) | ||
34 | self.buttonBox.rejected.connect(self.mainDialog.reject) | 38 | self.buttonBox.rejected.connect(self.mainDialog.reject) | ||
35 | 39 | | |||
36 | self.buttonBox.setOrientation(Qt.Horizontal) | 40 | self.buttonBox.setOrientation(Qt.Horizontal) | ||
37 | self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) | 41 | self.buttonBox.setStandardButtons( | ||
42 | QDialogButtonBox.Ok | QDialogButtonBox.Cancel) | ||||
38 | self.scrollArea.setWidgetResizable(True) | 43 | self.scrollArea.setWidgetResizable(True) | ||
39 | 44 | | |||
40 | def initialize(self, tenscripts): | 45 | def initialize(self, tenscripts): | ||
41 | self.tenscripts = tenscripts | 46 | self.tenscripts = tenscripts | ||
42 | 47 | | |||
43 | self._loadGridLayout() | 48 | self._loadGridLayout() | ||
44 | self._fillScripts() | 49 | self._fillScripts() | ||
45 | 50 | | |||
46 | self.baseArea.setLayout(self.scriptsLayout) | 51 | self.baseArea.setLayout(self.scriptsLayout) | ||
47 | self.scrollArea.setWidget(self.baseArea) | 52 | self.scrollArea.setWidget(self.baseArea) | ||
48 | 53 | | |||
49 | self.layout.addWidget(self.scrollArea) | 54 | self.layout.addWidget(self.scrollArea) | ||
50 | self.layout.addWidget(self.buttonBox) | 55 | self.layout.addWidget(self.buttonBox) | ||
51 | 56 | | |||
52 | self.mainDialog.show() | 57 | self.mainDialog.show() | ||
53 | self.mainDialog.activateWindow() | 58 | self.mainDialog.activateWindow() | ||
54 | self.mainDialog.exec_() | 59 | self.mainDialog.exec_() | ||
55 | 60 | | |||
56 | def addNewRow(self, key): | 61 | def addNewRow(self, key): | ||
57 | rowPosition = self.scriptsLayout.rowCount() | 62 | rowPosition = self.scriptsLayout.rowCount() | ||
58 | rowLayout = QHBoxLayout() | | |||
59 | label = QLabel() | 63 | label = QLabel() | ||
60 | directoryTextField = QLineEdit() | 64 | directoryTextField = QLineEdit() | ||
61 | directoryDialogButton = QPushButton(i18n("...")) | 65 | directoryDialogButton = QPushButton(i18n("...")) | ||
62 | 66 | | |||
63 | directoryTextField.setReadOnly(True) | 67 | directoryTextField.setReadOnly(True) | ||
64 | label.setText(self.tenscripts.actions[key].shortcut().toString()) | 68 | label.setText(self.tenscripts.actions[key].shortcut().toString()) | ||
65 | directoryTextField.setToolTip(i18n("Selected path")) | 69 | directoryTextField.setToolTip(i18n("Selected path")) | ||
66 | directoryDialogButton.setToolTip(i18n("Select the script")) | 70 | directoryDialogButton.setToolTip(i18n("Select the script")) | ||
67 | directoryDialogButton.clicked.connect(self._selectScript) | 71 | directoryDialogButton.clicked.connect(self._selectScript) | ||
68 | 72 | | |||
69 | self.scriptsLayout.addWidget(label, rowPosition, 0, Qt.AlignLeft|Qt.AlignTop) | 73 | self.scriptsLayout.addWidget( | ||
70 | self.scriptsLayout.addWidget(directoryTextField, rowPosition, 1, Qt.AlignLeft|Qt.AlignTop) | 74 | label, rowPosition, 0, Qt.AlignLeft | Qt.AlignTop) | ||
71 | self.scriptsLayout.addWidget(directoryDialogButton, rowPosition, 2, Qt.AlignLeft|Qt.AlignTop) | 75 | self.scriptsLayout.addWidget( | ||
76 | directoryTextField, rowPosition, 1, Qt.AlignLeft | Qt.AlignTop) | ||||
77 | self.scriptsLayout.addWidget( | ||||
78 | directoryDialogButton, rowPosition, 2, Qt.AlignLeft | Qt.AlignTop) | ||||
72 | 79 | | |||
73 | def saved_scripts(self): | 80 | def saved_scripts(self): | ||
74 | _saved_scripts = [] | 81 | _saved_scripts = [] | ||
75 | index = 0 | 82 | index = 0 | ||
76 | 83 | | |||
77 | for row in range(self.scriptsLayout.rowCount()-1): | 84 | for row in range(self.scriptsLayout.rowCount()-1): | ||
78 | textField = self.scriptsLayout.itemAt(index + 1).widget() | 85 | textField = self.scriptsLayout.itemAt(index + 1).widget() | ||
79 | if textField.text(): | 86 | if textField.text(): | ||
80 | _saved_scripts.append(textField.text()) | 87 | _saved_scripts.append(textField.text()) | ||
81 | index += 3 | 88 | index += 3 | ||
82 | 89 | | |||
83 | return _saved_scripts | 90 | return _saved_scripts | ||
84 | 91 | | |||
85 | def _selectScript(self): | 92 | def _selectScript(self): | ||
86 | dialog = QFileDialog(self.mainDialog) | 93 | dialog = QFileDialog(self.mainDialog) | ||
87 | dialog.setNameFilter(i18n("Python files (*.py)")) | 94 | dialog.setNameFilter(i18n("Python files (*.py)")) | ||
88 | 95 | | |||
89 | if dialog.exec_(): | 96 | if dialog.exec_(): | ||
90 | selectedFile = dialog.selectedFiles()[0] | 97 | selectedFile = dialog.selectedFiles()[0] | ||
91 | obj = self.mainDialog.sender() | 98 | obj = self.mainDialog.sender() | ||
92 | textField = self.scriptsLayout.itemAt(self.scriptsLayout.indexOf(obj)-1).widget() | 99 | textField = self.scriptsLayout.itemAt( | ||
100 | self.scriptsLayout.indexOf(obj)-1).widget() | ||||
93 | textField.setText(selectedFile) | 101 | textField.setText(selectedFile) | ||
94 | 102 | | |||
95 | def _loadGridLayout(self): | 103 | def _loadGridLayout(self): | ||
96 | for item in range(0, 10): | 104 | for item in range(0, 10): | ||
97 | self.addNewRow(item) | 105 | self.addNewRow(item) | ||
98 | 106 | | |||
99 | def _fillScripts(self): | 107 | def _fillScripts(self): | ||
100 | scripts = self.tenscripts.scripts | 108 | scripts = self.tenscripts.scripts | ||
Show All 9 Lines |