-
Notifications
You must be signed in to change notification settings - Fork 0
/
items.py
99 lines (78 loc) · 2 KB
/
items.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
import wx
import layouts
import inspect
class Items:
def __init__(self, items = [], parent=None):
self.items = items
self.current = 0
def __iter__():
return self
def append(self, item):
self.items.append(item)
def names(self):
names = []
for i in self.items:
names.append(i.name)
return names
def next(self):
if len(self.items) > self.current:
return self.items[current]
else:
raise StopIteration
def index(self, name):
index = -1
for m in self.methods:
index += 1
if name == m.name:
return index
return index
class Item(wx.Window):
"""Master class for all widgets"""
def __init__(self, name, item, parent=None, *args, **kwargs):
if parent:
wx.Window.__init__(self, parent, -1)
else:
try:
wx.Window.__init__(self, wx.Frame(None, -1), -1)
except:
self.app = wx.App(None)
wx.Window.__init__(self, wx.Frame(None, -1), -1)
self.name = name
self.item = item
self.parent = parent
self.SetSizer(wx.GridBagSizer())
self.construct()
def construct(self):
self.items = []
self.controls = {}
def layout(self):
r, c = layouts.LayoutGrid(self.GetSizer(), self.items)
return r, c
def bind(self, event, function):
self.Bind(event, function)
def makeLabel(self, label):
txt = wx.StaticText(self.parent, -1, label)
self.items.append(txt)
return txt
def makeButton(self, label):
btn = wx.Button(self.parent, -1, label)
self.items.append(btn)
self.addControl(btn)
return btn
def addControl(self, ctrl):
"""create a ctrl, add it to children"""
self.controls[str(ctrl.GetId())] = ctrl
def makeTxtCtrl(self, label=""):
txtctrl = wx.TextCtrl(self.parent, -1, label)
self.items.add(txtctrl)
self.addControl(txtctrl)
return txtctrl
def onButton(self, event):
ID = event.GetId()
if self.controls.has_key(str(ID)):
btn = self.controls[str(ID)]
label = btn.GetLabel()
exec(events[label])
def onTextCtrl(self, event):
#not really sure how many fields we really want to pay attention to
exec(events['textctrl'])