Skip to content

Commit 3a620b0

Browse files
committed
Simulatous previous and next patient buttons
1 parent 0d7e9a2 commit 3a620b0

File tree

1 file changed

+79
-23
lines changed

1 file changed

+79
-23
lines changed

test_tkinter.ipynb

+79-23
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@
2525
"metadata": {},
2626
"outputs": [],
2727
"source": [
28+
"# This class contains all the hard coded values\n",
2829
"class GUIController():\n",
2930
" \n",
3031
" def __init__(self, view, image_model, patient_info_model):\n",
3132
" self.view = view\n",
3233
" self.image_model = image_model\n",
3334
" self.patient_info_model = patient_info_model\n",
34-
" \n",
35-
" self.check_list = self.fetch_check_list_info()\n",
35+
" self.patient_info_filename = \"patient_data_table.csv\"\n",
36+
" self.check_list = self.fetch_check_list_info() # returns a list\n",
3637
" \n",
3738
" def fetch_check_list_info(self):\n",
3839
" return [\"Vitreous or Subhyaloid Space\", \n",
3940
" \"Posterior Hyaloid\", \n",
4041
" \"Epiretinal Membrane\",\n",
41-
" \"Unknown\"]"
42+
" \"Unknown\"]\n",
43+
" "
4244
]
4345
},
4446
{
@@ -155,15 +157,15 @@
155157
" \n",
156158
" def next_patient(self):\n",
157159
" try:\n",
160+
" self.current_patient = self.patient_table.loc[self.current_index + 1]\n",
158161
" self.current_index += 1\n",
159-
" self.current_patient = self.patient_table.loc[self.current_index]\n",
160162
" except KeyError:\n",
161163
" print(\"You have reached the end of the file.\")\n",
162164
" \n",
163165
" def previous_patient(self):\n",
164166
" try:\n",
167+
" self.current_patient = self.patient_table.loc[self.current_index - 1]\n",
165168
" self.current_index -= 1\n",
166-
" self.current_patient = self.patient_table.loc[self.current_index]\n",
167169
" except KeyError:\n",
168170
" print(\"You have reached the beginning of the file.\")\n",
169171
" \n",
@@ -179,24 +181,26 @@
179181
},
180182
{
181183
"cell_type": "code",
182-
"execution_count": 9,
184+
"execution_count": 27,
183185
"metadata": {},
184186
"outputs": [],
185187
"source": [
186188
"class PatientInformation(tk.Frame):\n",
187189
" def __init__(self, parent, *args, **kwargs):\n",
188190
" tk.Frame.__init__(self, parent, *args, **kwargs)\n",
189-
" self.parent = parent \n",
191+
" self.parent = parent\n",
192+
" \n",
193+
" name_label = tk.Label(self, textvariable=self.parent.current_name) # bind label to patient info\n",
194+
" id_label = tk.Label(self, textvariable=self.parent.current_id) # bind label to patient info\n",
195+
" age_label = tk.Label(self, textvariable=self.parent.current_age) # bind label to patient info\n",
190196
" \n",
191-
" # TODO: SHOULD NOT BE DOING THIS HERE\n",
192-
" db = parent.controller.patient_info_model(\"patient_data_table.csv\")\n",
193-
" db.load_patient_data()\n",
197+
" tk.Label(self, text=\"Name: \").grid(row=0, column=0, sticky=tk.E)\n",
198+
" tk.Label(self, text=\"ID: \").grid(row=1, column=0, sticky=tk.E)\n",
199+
" tk.Label(self, text=\"Age: \").grid(row=2, column=0, sticky=tk.E)\n",
194200
" \n",
195-
" patient_info_string = (\"Name: \" + db.get_name() + \"\\n\" \n",
196-
" + \"ID: \" + str(db.get_id()) + \"\\n\" \n",
197-
" + \"Age: \" + str(db.get_age()) + \"\\n\")\n",
198-
" patient_info_label = tk.Label(self, text = patient_info_string, anchor = tk.W, background = '#FFFFFF', justify=tk.LEFT)\n",
199-
" patient_info_label.grid(row=0, column=0, sticky = tk.E)\n",
201+
" name_label.grid(row=0, column=1, sticky=tk.W)\n",
202+
" id_label.grid(row=1, column=1, sticky=tk.W)\n",
203+
" age_label.grid(row=2, column=1, sticky=tk.W)\n",
200204
" \n",
201205
"class ImageScroller(tk.Frame):\n",
202206
" def __init__(self, parent, *args, **kwargs):\n",
@@ -230,7 +234,7 @@
230234
" canvas.grid(row=0, column=0, padx=10, pady=10, sticky=tk.W)\n",
231235
"\n",
232236
" \n",
233-
"class DropdownMenu(tk.Frame):\n",
237+
"class VisitDropdown(tk.Frame):\n",
234238
" def __init__(self, parent, *args, **kwargs):\n",
235239
" tk.Frame.__init__(self, parent, *args, **kwargs)\n",
236240
" self.parent = parent \n",
@@ -274,29 +278,81 @@
274278
" values = [self.listbox.get(idx) for idx in self.listbox.curselection()]\n",
275279
" print(', '.join(values))\n",
276280
" \n",
281+
" def deselect_all(self):\n",
282+
" self.listbox.selection_clear(0, tk.END)\n",
283+
" \n",
284+
"class ChangePatientButtons(tk.Frame):\n",
285+
" def __init__(self, parent, *args, **kwargs):\n",
286+
" tk.Frame.__init__(self, parent, *args, **kwargs)\n",
287+
" self.parent = parent\n",
288+
"\n",
289+
" nextButton = tk.Button(self, text=\"Next Patient\") # forwards button\n",
290+
" nextButton.grid(row=0, column=1)\n",
291+
" nextButton.bind('<Button-1>', self.next_patient_button_press) # bind button to next function\n",
292+
" \n",
293+
" previousButton = tk.Button(self, text=\"Previous Patient\") # forwards button\n",
294+
" previousButton.grid(row=0, column=0)\n",
295+
" previousButton.bind('<Button-1>', self.previous_patient_button_press) # bind button to next function\n",
296+
" \n",
297+
" def next_patient_button_press(self, event):\n",
298+
" self.parent.db_class.next_patient()\n",
299+
" self.parent.current_name.set(self.parent.db_class.get_name())\n",
300+
" self.parent.current_id.set(self.parent.db_class.get_id())\n",
301+
" self.parent.current_age.set(self.parent.db_class.get_age())\n",
302+
" self.parent.check_list.deselect_all() # reset checklist for next patient #COUPLING\n",
303+
" \n",
304+
" def previous_patient_button_press(self, event):\n",
305+
" self.parent.db_class.previous_patient()\n",
306+
" self.parent.current_name.set(self.parent.db_class.get_name())\n",
307+
" self.parent.current_id.set(self.parent.db_class.get_id())\n",
308+
" self.parent.current_age.set(self.parent.db_class.get_age())\n",
309+
" self.parent.check_list.deselect_all() # reset chacklist for next patient # COUPLING\n",
310+
" \n",
277311
"\n",
278312
"class StartPage(tk.Frame):\n",
279313
" def __init__(self, parent, controller, *args, **kwargs):\n",
280314
" tk.Frame.__init__(self, parent, *args, **kwargs)\n",
281315
" self.parent = parent \n",
282316
" self.controller = controller\n",
283317
" \n",
318+
" # initiate patient info database\n",
319+
" self.db_class = controller.patient_info_model(controller.patient_info_filename)\n",
320+
" self.db_class.load_patient_data()\n",
321+
" self.current_name = tk.StringVar()\n",
322+
" self.current_name.set(self.db_class.get_name())\n",
323+
" self.current_id = tk.StringVar()\n",
324+
" self.current_id.set(self.db_class.get_id())\n",
325+
" self.current_age = tk.StringVar()\n",
326+
" self.current_age.set(self.db_class.get_age())\n",
327+
" \n",
328+
" # create widgets\n",
284329
" self.patient_info = PatientInformation(self)\n",
285330
" self.image_scroller = ImageScroller(self)\n",
286-
" self.dropdown_menu = DropdownMenu(self)\n",
331+
" self.visit_dropdown = VisitDropdown(self)\n",
287332
" self.check_list = CheckList(self)\n",
333+
" self.change_patient_buttons = ChangePatientButtons(self)\n",
288334
"\n",
289-
" self.patient_info.pack()\n",
290-
" self.image_scroller.pack()\n",
291-
" self.dropdown_menu.pack() \n",
292-
" self.check_list.pack()"
335+
" # place widgets\n",
336+
" self.patient_info.grid()\n",
337+
" self.image_scroller.grid()\n",
338+
" self.visit_dropdown.grid() \n",
339+
" self.check_list.grid()\n",
340+
" self.change_patient_buttons.grid()"
293341
]
294342
},
295343
{
296344
"cell_type": "code",
297-
"execution_count": 10,
345+
"execution_count": 28,
298346
"metadata": {},
299-
"outputs": [],
347+
"outputs": [
348+
{
349+
"name": "stdout",
350+
"output_type": "stream",
351+
"text": [
352+
"50\n"
353+
]
354+
}
355+
],
300356
"source": [
301357
"if __name__ == \"__main__\":\n",
302358
" root = tk.Tk()\n",

0 commit comments

Comments
 (0)