1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
from common import *
class KPTilesetChooserDialog(QtGui.QDialog):
def __init__(self, label='Choose a tileset', specials=None):
QtGui.QDialog.__init__(self)
self.label = QtGui.QLabel(label)
self.label.setWordWrap(True)
# can't be assed to create a model
self.chooser = QtGui.QListWidget()
self.nameList = KP.map.tilesets.keys()
self.nameList.sort()
# this piece of the API is kinda shitty but whatever
self.specials = specials
if specials:
self.chooser.addItems(self.specials)
self.chooser.addItems(self.nameList)
self.chooser.currentRowChanged.connect(self.handleCurrentRowChanged)
self.chooser.itemActivated.connect(self.handleItemActivated)
self.buttons = QtGui.QDialogButtonBox(
QtGui.QDialogButtonBox.Ok |
QtGui.QDialogButtonBox.Cancel)
self.okButton = self.buttons.button(QtGui.QDialogButtonBox.Ok)
self.okButton.setEnabled(False)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.layout = QtGui.QVBoxLayout()
self.layout.addWidget(self.label)
self.layout.addWidget(self.chooser)
self.layout.addWidget(self.buttons)
self.setLayout(self.layout)
def handleCurrentRowChanged(self, row):
self.okButton.setEnabled(row != -1)
def handleItemActivated(self, item):
self.accept()
def getChoice(self):
item = self.chooser.currentItem()
number = self.chooser.currentRow()
if item is None:
return None
else:
if self.specials is not None and number < len(self.specials):
return number
else:
return str(item.text())
@classmethod
def run(cls, *args):
dialog = cls(*args)
result = dialog.exec_()
if result == QtGui.QDialog.Accepted:
return dialog.getChoice()
else:
return None
class KPAnimationPresetChooser(QtGui.QDialog):
def __init__(self, label='Choose a preset to add:', specials=None):
QtGui.QDialog.__init__(self)
self.label = QtGui.QLabel(label)
self.label.setWordWrap(True)
# can't be assed to create a model
self.chooser = QtGui.QListWidget()
settings = KP.app.settings
if settings.contains('AnimationPresets'):
self.presetList = settings.value('AnimationPresets').toPyObject()
self.presets = settings.value('AnimationPresetData').toPyObject()
else:
self.presetList = ["Circle", "Wiggle", "Drifting Cloud"]
self.presets = [ [["Loop", "Sinusoidial", 200.0, "X Position", -200.0, 200.0],
["Loop", "Cosinoidial", 200.0, "Y Position", -200.0, 200.0]],
[["Reversible Loop", "Sinusoidial", 50.0, "Y Scale", 100.0, 120.0],
["Loop", "Cosinoidial", 50.0, "X Scale", 100.0, 90.0],
["Reversible Loop", "Sinusoidial", 20.0, "Angle", 10.0, -10.0]],
[["Loop", "Sinusoidial", 5000.0, "X Position", -400.0, 400.0],
["Loop", "Sinusoidial", 200.0, "Y Position", 10.0, -10.0],
["Reversible Loop", "Linear", 500.0, "Opacity", 80.0, 40.0]] ]
settings.setValue('AnimationPresets', self.presetList)
settings.setValue('AnimationPresetData', self.presets)
self.chooser.addItems(self.presetList)
self.chooser.currentRowChanged.connect(self.handleCurrentRowChanged)
self.chooser.itemActivated.connect(self.handleItemActivated)
self.buttons = QtGui.QDialogButtonBox(
QtGui.QDialogButtonBox.Ok |
QtGui.QDialogButtonBox.Cancel)
self.okButton = self.buttons.button(QtGui.QDialogButtonBox.Ok)
self.okButton.setEnabled(False)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.layout = QtGui.QVBoxLayout()
self.layout.addWidget(self.label)
self.layout.addWidget(self.chooser)
self.layout.addWidget(self.buttons)
self.setLayout(self.layout)
def handleCurrentRowChanged(self, row):
self.okButton.setEnabled(row != -1)
def handleItemActivated(self, item):
self.accept()
def getChoice(self):
item = self.chooser.currentItem()
number = self.chooser.currentRow()
if item is None:
return None
else:
return self.presets[number]
@classmethod
def run(cls, *args):
dialog = cls(*args)
result = dialog.exec_()
if result == QtGui.QDialog.Accepted:
return dialog.getChoice()
else:
return None
def getTextDialog():
text, ok = QtGui.QInputDialog.getText(KP.mainWindow, "Choose Preset Name", "Preset name:")
print text
if ok and text != '':
return text
else:
return None
|