/
erapp2.py
88 lines (78 loc) · 3.43 KB
/
erapp2.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
"""
File: erapp2.py
Author: Ken Lambert
Editor: Leigh Stauffer
Project 7
GUI-based view for an emergency room scheduler.
"""
from breezypythongui import EasyFrame
from ermodel import ERModel, Patient, Condition
class ERView(EasyFrame):
"""View of the scheduler."""
def __init__(self, model):
"""Sets up the window and widgets."""
self.model = model
EasyFrame.__init__(self, "ER Scheduler")
self.addLabel(text = "Patient name",
row = 0, column = 0)
self.nameFld = self.addTextField(text = "",
row = 0, column = 1)
self.conditionGrp = self.addRadiobuttonGroup(row = 1, column = 0)
selectedBtn = self.conditionGrp.addRadiobutton("Fair condition")
self.conditionGrp.addRadiobutton("Serious condition")
self.conditionGrp.addRadiobutton("Critical condition")
self.conditionGrp.setSelectedButton(selectedBtn)
self.addButton(text = "Schedule patient", row = 1, column = 1,
rowspan = 3, command = self.schedule)
self.addLabel(text = "Current activity", row = 4, column = 0,
columnspan = 2, sticky = "NSEW")
self.outputArea = self.addTextArea("", row = 5, column = 0,
columnspan = 2,
width = 40, height = 10)
self.treatNextBtn = self.addButton(text = "Treat next",
row = 6, column = 0,
command = self.treatNext,
state = "disabled")
self.treatAllBtn = self.addButton(text = "Treat all",
row = 6, column = 1,
command = self.treatAll,
state = "disabled")
# Event handling methods
def schedule(self):
"""Obtains the patient's name and condition, and schedules
that patient for service."""
name = self.nameFld.getText()
if name == "":
self.messageBox("ERROR", "No named entered.")
return
condition = self.getCondition()
self.model.schedule(Patient(name, condition))
self.outputArea.appendText(name + " is added to the " + \
str(condition) + " list\n")
self.treatNextBtn["state"] = "normal"
self.treatAllBtn["state"] = "normal"
def treatNext(self):
"""Treats the next patient and updates the display."""
patient = self.model.treatNext()
self.outputArea.appendText(str(patient) + " is being treated\n")
if self.model.isEmpty():
self.treatNextBtn["state"] = "disabled"
self.treatAllBtn["state"] = "disabled"
def treatAll(self):
"""Treats all the patients."""
while not self.model.isEmpty():
self.treatNext()
def getCondition(self):
"""Returns a Condition object corresponding to
the selected radio button in the view."""
text = self.conditionGrp.getSelectedButton()["text"].split()[0]
if text == "Fair":
number = 3
elif text == "Serious":
number = 2
else:
number = 1
return Condition(number)
if __name__ == "__main__":
model = ERModel()
ERView(model).mainloop()