-
Notifications
You must be signed in to change notification settings - Fork 1
/
view_configuration_place.py
122 lines (97 loc) · 5.11 KB
/
view_configuration_place.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
#!/usr/bin/python
import pygtk
import gtk
import view_configuration_component as view
class ViewConfigurationPlace(view.ViewConfigurationComponent):
""" The ViewConfigurationPlace class is a specific view that inherits from the general ViewConfigurationComponent class and is used to visualise theconfiguration window for a places and contains a ControllerConfigurationPlace object. """
__ent = None
def __init__(self):
""" Constructor of ViewConfigurationPlace. """
# call constructor of parent class
view.ViewConfigurationComponent.__init__(self)
# set size and title of the window
self._window.resize(150, 150)
self._window.set_title("Configuration: Place")
def __init__(self, model = None, controller = None):
""" Constructor of ViewConfigurationPlace. """
# call constructor of parent class
view.ViewConfigurationComponent.__init__(self, model, controller)
# set size and title of the window
self._window.resize(150, 150)
self._window.set_title("Configuration: Place")
def show(self):
""" Interface to create and display the GUI on the screen. """
# call show method from the parent class
view.ViewConfigurationComponent.show(self)
# create table
self._table = gtk.Table(5, 2, True)
# check if a controller is available
if self._controller.component != None:
# create widgets
self.__ent = self._add_label_widget_pair(["Original Label:", "Label:", "Marking:", "Capacity:"],
[self._controller.component.key, self._controller.component.label,
self._controller.component.marking,
str(self._controller.component.capacity)],
[[0, 1, 0, 1], [0, 1, 1, 2], [0, 1, 2, 3], [0, 1, 3, 4]],
[[1, 2, 0, 1], [1, 2, 1, 2], [1, 2, 2, 3], [1, 2, 3, 4]],
[self.I_NONE, self.I_ENTRY, self.I_ENTRY, self.I_ENTRY])
else:
# create widgets
self.__ent = self._add_label_widget_pair(["Original Key:", "Label:", "Marking:", "Capacity:"],
["not defined", "", "0"],
[[0, 1, 0, 1], [0, 1, 1, 2], [0, 1, 2, 3], [0, 1, 3, 4]],
[[1, 2, 0, 1], [1, 2, 1, 2], [1, 2, 2, 3], [1, 2, 3, 4]],
[self.I_NONE, self.I_ENTRY, self.I_ENTRY, self.I_ENTRY])
# create OK and Cancel button
button_ok = gtk.Button("OK")
button_ok.connect("clicked", self._on_ok_clicked)
button_cancel = gtk.Button("Cancel")
button_cancel.connect("clicked", self._on_cancel_clicked)
# attach buttons to the table
self._table.attach(button_ok, 0, 1, 4, 5)
self._table.attach(button_cancel, 1, 2, 4, 5)
# attach table to the window
self._window.add(self._table)
# show all components
self._window.show_all()
self._window.show()
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 _on_ok_clicked(self, button):
""" Is called if the OK button sends the clicked event. """
# check if a controller is available
if self._controller != None:
try:
if self._model.data.has_key(self.__ent[1].get_text()) or self._model.data.has_label(self.__ent[1].get_text()):
self.show_message_box_error("Label is already used! Please choose another label!")
else:
# set properties
self._controller.key = str(self.__ent[1].get_text())
self._controller.label = str(self.__ent[1].get_text())
self._controller.marking = float(self.__ent[2].get_text())
self._controller.capacity = float(str(self.__ent[3].get_text()))
# update data
self._controller.update()
# close window
self._window.destroy()
except ValueError:
self.show_message_box_error("There are invalid entries!")
def _on_cancel_clicked(self, button):
""" Is called if the OK button sends the clicked event. """
if self._controller != None:
self._controller.cancel()
self._window.destroy()
if __name__ == "__main__":
app = ViewConfigurationPlace()
app.show()
gtk.main()