Changeset View
Changeset View
Standalone View
Standalone View
plugins/python/tenbrushes/tenbrushes.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 | import krita | 15 | import krita | ||
13 | from . import uitenbrushes | 16 | from . import uitenbrushes | ||
14 | 17 | | |||
15 | 18 | | |||
16 | class TenBrushesExtension(krita.Extension): | 19 | class TenBrushesExtension(krita.Extension): | ||
17 | 20 | | |||
18 | def __init__(self, parent): | 21 | def __init__(self, parent): | ||
19 | super(TenBrushesExtension, self).__init__(parent) | 22 | super(TenBrushesExtension, self).__init__(parent) | ||
Show All 15 Lines | 35 | def createActions(self, window): | |||
35 | action.triggered.connect(self.initialize) | 38 | action.triggered.connect(self.initialize) | ||
36 | self.loadActions(window) | 39 | self.loadActions(window) | ||
37 | 40 | | |||
38 | def initialize(self): | 41 | def initialize(self): | ||
39 | self.uitenbrushes = uitenbrushes.UITenBrushes() | 42 | self.uitenbrushes = uitenbrushes.UITenBrushes() | ||
40 | self.uitenbrushes.initialize(self) | 43 | self.uitenbrushes.initialize(self) | ||
41 | 44 | | |||
42 | def readSettings(self): | 45 | def readSettings(self): | ||
43 | self.selectedPresets = Application.readSetting("", "tenbrushes", "").split(',') | 46 | self.selectedPresets = Application.readSetting( | ||
44 | setting = Application.readSetting("", "tenbrushesActivatePrev2ndPress", "True") | 47 | "", "tenbrushes", "").split(',') | ||
48 | setting = Application.readSetting( | ||||
49 | "", "tenbrushesActivatePrev2ndPress", "True") | ||||
45 | # we should not get anything other than 'True' and 'False' | 50 | # we should not get anything other than 'True' and 'False' | ||
46 | self.activatePrev = setting == 'True' | 51 | self.activatePrev = setting == 'True' | ||
47 | 52 | | |||
48 | def writeSettings(self): | 53 | def writeSettings(self): | ||
49 | presets = [] | 54 | presets = [] | ||
50 | 55 | | |||
51 | for index, button in enumerate(self.buttons): | 56 | for index, button in enumerate(self.buttons): | ||
52 | self.actions[index].preset = button.preset | 57 | self.actions[index].preset = button.preset | ||
53 | presets.append(button.preset) | 58 | presets.append(button.preset) | ||
54 | Application.writeSetting("", "tenbrushes", ','.join(map(str, presets))) | 59 | Application.writeSetting("", "tenbrushes", ','.join(map(str, presets))) | ||
55 | Application.writeSetting("", "tenbrushesActivatePrev2ndPress", | 60 | Application.writeSetting("", "tenbrushesActivatePrev2ndPress", | ||
56 | str(self.activatePrev)) | 61 | str(self.activatePrev)) | ||
57 | 62 | | |||
58 | def loadActions(self, window): | 63 | def loadActions(self, window): | ||
59 | allPresets = Application.resources("preset") | 64 | allPresets = Application.resources("preset") | ||
60 | 65 | | |||
61 | for index, item in enumerate(['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']): | 66 | for index, item in enumerate(['1', '2', '3', '4', '5', | ||
62 | action = window.createAction("activate_preset_" + item, str(i18n("Activate Brush Preset {num}")).format(num=item), "") | 67 | '6', '7', '8', '9', '0']): | ||
68 | action = window.createAction( | ||||
69 | "activate_preset_" + item, | ||||
70 | str(i18n("Activate Brush Preset {num}")).format(num=item), "") | ||||
63 | action.triggered.connect(self.activatePreset) | 71 | action.triggered.connect(self.activatePreset) | ||
64 | 72 | | |||
65 | if index < len(self.selectedPresets) and self.selectedPresets[index] in allPresets: | 73 | if (index < len(self.selectedPresets) | ||
74 | and self.selectedPresets[index] in allPresets): | ||||
66 | action.preset = self.selectedPresets[index] | 75 | action.preset = self.selectedPresets[index] | ||
67 | else: | 76 | else: | ||
68 | action.preset = None | 77 | action.preset = None | ||
69 | 78 | | |||
70 | self.actions.append(action) | 79 | self.actions.append(action) | ||
71 | 80 | | |||
72 | def activatePreset(self): | 81 | def activatePreset(self): | ||
73 | allPresets = Application.resources("preset") | 82 | allPresets = Application.resources("preset") | ||
74 | if Application.activeWindow() and len(Application.activeWindow().views()) > 0 and self.sender().preset in allPresets: | 83 | window = Application.activeWindow() | ||
75 | currentPreset = Application.activeWindow().views()[0].currentBrushPreset() | 84 | if (window and len(window.views()) > 0 | ||
76 | if self.activatePrev and self.sender().preset == currentPreset.name(): | 85 | and self.sender().preset in allPresets): | ||
77 | Application.activeWindow().views()[0].activateResource(self.oldPreset) | 86 | currentPreset = window.views()[0].currentBrushPreset() | ||
87 | if (self.activatePrev | ||||
88 | and self.sender().preset == currentPreset.name()): | ||||
89 | window.views()[0].activateResource(self.oldPreset) | ||||
78 | else: | 90 | else: | ||
79 | self.oldPreset = Application.activeWindow().views()[0].currentBrushPreset() | 91 | self.oldPreset = window.views()[0].currentBrushPreset() | ||
80 | Application.activeWindow().views()[0].activateResource(allPresets[self.sender().preset]) | 92 | window.views()[0].activateResource( | ||
81 | 93 | allPresets[self.sender().preset]) | |||
82 | | ||||
83 | Scripter.addExtension(TenBrushesExtension(Application)) | |