-
Notifications
You must be signed in to change notification settings - Fork 1
/
view_configuration_component.py
123 lines (95 loc) · 4.68 KB
/
view_configuration_component.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
#!/usr/bin/python
import pygtk
import gtk
import view
class ViewConfigurationComponent(view.View):
""" The ViewConfigurationComponent class is a specific view that inherits from the general View class and is used as a parent class to visualise the configuration window and contains a ControllerConfigurationComponent object. """
I_NONE = 0
I_ENTRY = 1
I_SPIN_BUTTON = 2
I_RADIO_BUTTON = 3
I_CHECK_BUTTON = 4
_table = None
_component = None
def __init__(self):
""" Constructor of ViewConfigurationComponent. """
# call constructor of parent class
view.View.__init__(self)
# set title of the window
self._window.set_title("Configuration: Component")
def __init__(self, model = None, controller = None):
""" Constructor of ViewConfigurationComponent. """
# call constructor of parent class
view.View.__init__(self, model, controller)
# set title of the window
self._window.set_title("Configuration: Component")
def show(self):
""" Interface to create and display the GUI on the screen. """
pass
def update(self):
""" Interface to notify MVCObserver objects about a general data change. """
pass
def update_component(self, key):
""" Interface to notify Observer objects about a data change of a component. """
pass
def update_output(self):
""" Interface to notify Observer objects about a data change of simulation results. """
pass
def undo(self):
""" Interface to notify Observer objects about an undo. """
pass
def _add_label_widget_pair(self, list_label, list_initial_value, list_tbl_pos_label, list_tbl_pos_widget, list_widget_type):
""" General method to add different widgets to a defined location within a table. The first parameter describes a label describing the widged, list_initial_value the initial value, list_tbl_pos_label the position of the label and list_tbl_pos_widget the position of the widget within the table. List_widget_type defines the widget type. A list with all references to the widgets, in the same order, will be returned. """
# stores references to the widgets
ent = []
# needed to connect radio buttons
radio_btn = None
# iteration through all
for i in range(len(list_label)):
# create label
label = gtk.Label()
if list_widget_type[i] == self.I_CHECK_BUTTON:
label.set_markup("")
else:
label.set_markup(list_label[i])
# attach label to the table
self._table.attach(label, list_tbl_pos_label[i][0], list_tbl_pos_label[i][1], list_tbl_pos_label[i][2], list_tbl_pos_label[i][3], gtk.FILL, gtk.FILL)
# create another label
if list_widget_type[i] == self.I_NONE:
comp = gtk.Label()
comp.set_markup(list_initial_value[i])
# create an entry box
if list_widget_type[i] == self.I_ENTRY:
comp = gtk.Entry()
comp.set_text(str(list_initial_value[i]))
# create a spin button
if list_widget_type[i] == self.I_SPIN_BUTTON:
comp = gtk.SpinButton()
comp.set_adjustment(gtk.Adjustment(float(list_initial_value[i]), 0, sys.maxint, 1, 10, 0))
# create a radio button
if list_widget_type[i] == self.I_RADIO_BUTTON:
comp = gtk.RadioButton(radio_btn, list_initial_value[i])
if radio_btn == None:
radio_btn = comp
comp.connect("toggled", self._on_change_radio_button, list_initial_value[i])
# create a checkbox
if list_widget_type[i] == self.I_CHECK_BUTTON:
comp = gtk.CheckButton(list_label[i])
comp.set_active(list_initial_value[i])
comp.connect("toggled", self._on_change_check_button, list_label[i])
# attach reference to the list of references
ent.append(comp)
# attach widget to the list
self._table.attach(comp, list_tbl_pos_widget[i][0], list_tbl_pos_widget[i][1], list_tbl_pos_widget[i][2], list_tbl_pos_widget[i][3])
# return list of references
return ent
def _on_change_radio_button(self, widget, data = None):
""" Is called if a radio button change ocurres. """
pass
def _on_change_check_button(self, widget, data = None):
""" Is called if a check button change ocurres. """
pass
if __name__ == "__main__":
app = ViewConfigurationComponent()
app.show()
gtk.main()