forked from mxcube/BlissFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Qt4_BaseLayoutItems.py
398 lines (336 loc) · 11.7 KB
/
Qt4_BaseLayoutItems.py
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#
# Project: MXCuBE
# https://github.com/mxcube.
#
# This file is part of MXCuBE software.
#
# MXCuBE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# MXCuBE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MXCuBE. If not, see <http://www.gnu.org/licenses/>.
from QtImport import *
from BlissFramework.Utils import PropertyBag
DEFAULT_MARGIN = 5
DEFAULT_SPACING = 5
DEFAULT_ALIGNMENT = "top center"
class _CfgItem:
"""
Descript. :
"""
def __init__(self, name, item_type=""):
"""
Descript. :
"""
self.name = name
self.type = item_type
self.children = []
self.connections = []
self.properties = PropertyBag.PropertyBag()
self.properties.addProperty("alignment", "combo", ("none",
"top center", "top left", "top right",
"bottom center", "bottom left",
"bottom right", "center", "hcenter",
"vcenter", "left", "right"), "none")
self.signals = {}
self.slots = {}
def setProperties(self, properties):
"""Set properties
Add new properties (if any) and remove odd ones (if any)
"""
for item_property in properties:
if hasattr(item_property, "getName"):
prop_name = item_property.getName()
if prop_name in self.properties.properties:
self.properties.getProperty(prop_name).setValue(\
item_property.getUserValue())
elif item_property.hidden or prop_name.startswith("closable_"):
self.properties[prop_name] = item_property
else:
if item_property["type"] == "combo":
arg1 = item_property["choices"]
else:
arg1 = item_property["value"]
arg2 = item_property["defaultValue"]
self.properties.addProperty(propertyName=item_property["name"],
propertyType=item_property["type"],
arg1=arg1,
arg2=arg2,
comment=item_property["comment"],
hidden=item_property["hidden"])
def __getitem__(self, item):
"""
Descript. :
"""
try:
return getattr(self, item)
except AttributeError:
raise KeyError(item)
def __setitem__(self, item, value):
"""
Descript. :
"""
setattr(self, item, value)
def __repr__(self):
"""
Descript. :
"""
return repr(self.__dict__)
def rename(self, new_name):
"""
Descript. :
"""
self.name = new_name
class ContainerCfg(_CfgItem):
"""
Descript. :
"""
def __init__(self, *args):
"""
Descript. :
"""
_CfgItem.__init__(self, *args)
self.properties.addProperty("label", "string", "")
self.properties.addProperty("icon", "string", "")
self.properties.addProperty("spacing", "integer", DEFAULT_SPACING)
self.properties.addProperty("margin", "integer", DEFAULT_MARGIN)
self.properties.addProperty("color", "color", None)
self.properties.addProperty("hsizepolicy", "combo",
("fixed", "expanding", "default"),
"default")
self.properties.addProperty("vsizepolicy", "combo",
("fixed", "expanding", "default"),
"default")
self.properties.addProperty("frameshape", "combo",
("Box", "Panel", "StyledPanel", "HLine",
"VLine", "default"),
"default")
self.properties.addProperty("shadowstyle", "combo",
("plain", "raised", "sunken", "default"),
"default")
self.properties.addProperty("fixedwidth", "integer", -1)
self.properties.addProperty("fixedheight", "integer", -1)
def addChild(self, item):
"""
Descript. :
"""
self.children.append(item)
return ""
def childPropertyChanged(self, child_name, property_name,
old_value, new_value):
"""
Descript. :
"""
pass
def updateSlots(self):
"""
Descript. :
"""
pass
def removeChild(self, child_index):
"""
Descript. :
"""
del self.children[child_index]
class WindowCfg(ContainerCfg):
"""
Descript. :
"""
def __init__(self, *args):
"""
Descript. :
"""
_CfgItem.__init__(self, *args)
self.type = "window"
self.properties.addProperty("caption", "string", "")
self.properties.addProperty("show", "boolean", True)
self.properties.addProperty("closeOnExit", "boolean", True)
self.properties.addProperty("menubar", "boolean", False)
self.properties.addProperty("statusbar", "boolean", False)
self.properties.addProperty("menudata", "", {}, hidden=True)
self.properties.addProperty("expertPwd", "string", "tonic")
self.signals.update({"isShown": (),
"isHidden": (),
"enableExpertMode": (),
"quit":()})
self.slots.update({"show": (),
"hide": (),
"setCaption": (),
"exitExpertMode": ()})
class TabCfg(ContainerCfg):
"""
Descript. :
"""
def __init__(self, *args):
"""
Descript. :
"""
ContainerCfg.__init__(self, *args)
self.properties.addProperty("fontSize", "integer", 0)
self.signals.update({"notebookPageChanged": "pageName"})
def __repr__(self):
"""
Descript. :
"""
try:
widget = self.widget
except AttributeError:
r = repr(self.__dict__)
else:
delattr(self, 'widget')
r = repr(self.__dict__)
self.widget = widget
return r
def addChild(self, item):
"""
Descript. :
"""
if isinstance(item, ContainerCfg):
return ContainerCfg.addChild(self, item)
else:
return "Tabs can only have container children."
def childPropertyChanged(self, child_name, property_name,
old_value, new_value):
"""
Descript. :
"""
if property_name == "label":
self.updateSlots()
def removeChild(self, child_index):
"""
Descript. :
"""
ContainerCfg.removeChild(self, child_index)
self.updateSlots()
def updateSlots(self):
"""
Descript. :
"""
closable_props = {}
for prop in self.properties:
if hasattr(prop, "name"):
if prop.name.startswith("closable_"):
closable_props[prop.name] = prop.getValue()
else:
if prop["name"].startswith("closable_"):
closable_props[prop["name"]] = prop["value"]
for prop_name in closable_props.keys():
self.properties.delProperty(prop_name)
self.slots = {}
for child in self.children:
if "label" in child["properties"].properties:
child_lbl = child["properties"]["label"]
child_lbl = child_lbl.replace(" ", "_")
self.properties.addProperty("closable_%s" % child_lbl,
"boolean", closable_props.get("closable_%s" % child_lbl,
False))
slot_name = "showPage_%s" % child_lbl
self.slots[slot_name.replace(" ", "_")] = ()
slot_name = "hidePage_%s" % child_lbl
self.slots[slot_name.replace(" ", "_")] = ()
slot_name = "enablePage_%s" % child_lbl
self.slots[slot_name.replace(" ", "_")] = ()
slot_name = "enableTab_%s" % child_lbl
self.slots[slot_name.replace(" ", "_")] = ()
slot_name = "incTabCount_%s" % child_lbl
self.slots[slot_name.replace(" ", "_")] = ()
slot_name = "resetTabCount_%s" % child_lbl
self.slots[slot_name.replace(" ", "_")] = ()
def notebook_page_changed(self, new_tab_label):
"""
Descript. :
"""
new_tab_label = new_tab_label.replace(" ", "_")
if self.properties.getProperty("closable_%s" % new_tab_label).getValue():
self.widget.close_tab_button.show()
else:
self.widget.close_tab_button.hide()
class SplitterCfg(ContainerCfg):
"""
Descript. :
"""
def __init__(self, *args):
"""
Descript. :
"""
ContainerCfg.__init__(self, *args)
self.properties.addProperty("sizes", "string", "[]",
hidden=True)
for key in [Qt.Key_F9,
Qt.Key_F10,
Qt.Key_F11,
Qt.Key_F12]:
self.properties.addProperty("sizes_%d" % key,
"string",
"[]",
hidden=True)
class SpacerCfg(_CfgItem):
"""
Descript. :
"""
def __init__(self, *args):
"""
Descript. :
"""
_CfgItem.__init__(self, *args)
self.properties.addProperty("fixed_size", "boolean", False)
self.properties.addProperty("size", "integer", 100)
class LabelCfg(_CfgItem):
"""
Descript. :
"""
def __init__(self, *args):
"""
Descript. :
"""
_CfgItem.__init__(self, *args)
self.properties.addProperty("text", "string", "")
self.properties.addProperty("fontSize", "integer", 0)
class IconCfg(_CfgItem):
"""
Descript. :
"""
def __init__(self, *args):
"""
Descript. :
"""
_CfgItem.__init__(self, *args)
self.properties.addProperty("filename", "file", "")
class BrickCfg(_CfgItem):
"""
Descript. :
"""
def __init__(self, name, brick_type, brick=None):
"""
Descript. :
"""
_CfgItem.__init__(self, name, brick_type)
self.name = name
self.type = brick_type
self.brick = brick
# bricks have their own thing for signals and slots
del self.signals
del self.slots
# bricks have their own thing for properties
if brick is not None:
self.setProperties(brick.property_bag)
def setProperties(self, properties):
"""
Descript. :
"""
self.brick.setPersistentPropertyBag(properties)
self.properties = self.brick.property_bag
def rename(self, new_name):
"""
Descript. :
"""
_CfgItem.rename(self, new_name)
if self.brick is not None:
self.brick.setObjectName(new_name)