-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDictManagerView.enaml
More file actions
59 lines (52 loc) · 1.81 KB
/
DictManagerView.enaml
File metadata and controls
59 lines (52 loc) · 1.81 KB
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
"""
Reusable widgets for handling lists and dictionaries
"""
from widgets import QtListStrWidget
from enaml.widgets.api import Window, Container, PushButton, Form, Label, Field, ComboBox
from enaml.stdlib.mapped_view import MappedView
from enaml.core.declarative import d_
from enaml.core.api import Looper
from enaml.layout.api import hbox, vbox, spacer
enamldef DictManagerView(Container): dictView:
"""
Display a list of items on the left; a view of the selected item on the right and some add/delete buttons.
"""
attr dictManager
attr viewMap # dictionary mapping classes to views
attr viewkwargs # extra parameters to pass to the model view
attr modelName # attr name for the model in the view
attr labelValidator # callable validator for QtListStrWidget labels
constraints = [
hbox(
vbox(
itemList,
hbox(addButton, removeButton, *sum(otherButtons.items, [spacer])),
spacer
),
selectedItemView,
spacer
)
]
QtListStrWidget: itemList:
items << [(item, dictManager.itemDict[item].enabled) for item in dictManager.displayList]
validator = labelValidator
initialized ::
itemList.item_changed.connect(dictManager.name_changed)
itemList.enable_changed.connect(dictManager.update_enable)
PushButton: addButton:
text = "Add"
clicked :: dictManager.add_item(self)
PushButton: removeButton:
text = "Remove"
clicked :: dictManager.remove_item(itemList.selected_item)
Looper: otherButtons:
iterable << dictManager.otherActions.keys()
PushButton:
text = loop_item
clicked :: dictManager.otherActions[loop_item]()
Container: selectedItemView:
MappedView:
model << dictManager.itemDict[itemList.selected_item] if itemList.selected_item else None
typemap = dictView.viewMap
modelkey = dictView.modelName
kwargs = dictView.viewkwargs if dictView.viewkwargs else {}