|
25 | 25 | "metadata": {},
|
26 | 26 | "outputs": [],
|
27 | 27 | "source": [
|
| 28 | + "# This class contains all the hard coded values\n", |
28 | 29 | "class GUIController():\n",
|
29 | 30 | " \n",
|
30 | 31 | " def __init__(self, view, image_model, patient_info_model):\n",
|
31 | 32 | " self.view = view\n",
|
32 | 33 | " self.image_model = image_model\n",
|
33 | 34 | " 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", |
36 | 37 | " \n",
|
37 | 38 | " def fetch_check_list_info(self):\n",
|
38 | 39 | " return [\"Vitreous or Subhyaloid Space\", \n",
|
39 | 40 | " \"Posterior Hyaloid\", \n",
|
40 | 41 | " \"Epiretinal Membrane\",\n",
|
41 |
| - " \"Unknown\"]" |
| 42 | + " \"Unknown\"]\n", |
| 43 | + " " |
42 | 44 | ]
|
43 | 45 | },
|
44 | 46 | {
|
|
155 | 157 | " \n",
|
156 | 158 | " def next_patient(self):\n",
|
157 | 159 | " try:\n",
|
| 160 | + " self.current_patient = self.patient_table.loc[self.current_index + 1]\n", |
158 | 161 | " self.current_index += 1\n",
|
159 |
| - " self.current_patient = self.patient_table.loc[self.current_index]\n", |
160 | 162 | " except KeyError:\n",
|
161 | 163 | " print(\"You have reached the end of the file.\")\n",
|
162 | 164 | " \n",
|
163 | 165 | " def previous_patient(self):\n",
|
164 | 166 | " try:\n",
|
| 167 | + " self.current_patient = self.patient_table.loc[self.current_index - 1]\n", |
165 | 168 | " self.current_index -= 1\n",
|
166 |
| - " self.current_patient = self.patient_table.loc[self.current_index]\n", |
167 | 169 | " except KeyError:\n",
|
168 | 170 | " print(\"You have reached the beginning of the file.\")\n",
|
169 | 171 | " \n",
|
|
179 | 181 | },
|
180 | 182 | {
|
181 | 183 | "cell_type": "code",
|
182 |
| - "execution_count": 9, |
| 184 | + "execution_count": 27, |
183 | 185 | "metadata": {},
|
184 | 186 | "outputs": [],
|
185 | 187 | "source": [
|
186 | 188 | "class PatientInformation(tk.Frame):\n",
|
187 | 189 | " def __init__(self, parent, *args, **kwargs):\n",
|
188 | 190 | " 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", |
190 | 196 | " \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", |
194 | 200 | " \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", |
200 | 204 | " \n",
|
201 | 205 | "class ImageScroller(tk.Frame):\n",
|
202 | 206 | " def __init__(self, parent, *args, **kwargs):\n",
|
|
230 | 234 | " canvas.grid(row=0, column=0, padx=10, pady=10, sticky=tk.W)\n",
|
231 | 235 | "\n",
|
232 | 236 | " \n",
|
233 |
| - "class DropdownMenu(tk.Frame):\n", |
| 237 | + "class VisitDropdown(tk.Frame):\n", |
234 | 238 | " def __init__(self, parent, *args, **kwargs):\n",
|
235 | 239 | " tk.Frame.__init__(self, parent, *args, **kwargs)\n",
|
236 | 240 | " self.parent = parent \n",
|
|
274 | 278 | " values = [self.listbox.get(idx) for idx in self.listbox.curselection()]\n",
|
275 | 279 | " print(', '.join(values))\n",
|
276 | 280 | " \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", |
277 | 311 | "\n",
|
278 | 312 | "class StartPage(tk.Frame):\n",
|
279 | 313 | " def __init__(self, parent, controller, *args, **kwargs):\n",
|
280 | 314 | " tk.Frame.__init__(self, parent, *args, **kwargs)\n",
|
281 | 315 | " self.parent = parent \n",
|
282 | 316 | " self.controller = controller\n",
|
283 | 317 | " \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", |
284 | 329 | " self.patient_info = PatientInformation(self)\n",
|
285 | 330 | " self.image_scroller = ImageScroller(self)\n",
|
286 |
| - " self.dropdown_menu = DropdownMenu(self)\n", |
| 331 | + " self.visit_dropdown = VisitDropdown(self)\n", |
287 | 332 | " self.check_list = CheckList(self)\n",
|
| 333 | + " self.change_patient_buttons = ChangePatientButtons(self)\n", |
288 | 334 | "\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()" |
293 | 341 | ]
|
294 | 342 | },
|
295 | 343 | {
|
296 | 344 | "cell_type": "code",
|
297 |
| - "execution_count": 10, |
| 345 | + "execution_count": 28, |
298 | 346 | "metadata": {},
|
299 |
| - "outputs": [], |
| 347 | + "outputs": [ |
| 348 | + { |
| 349 | + "name": "stdout", |
| 350 | + "output_type": "stream", |
| 351 | + "text": [ |
| 352 | + "50\n" |
| 353 | + ] |
| 354 | + } |
| 355 | + ], |
300 | 356 | "source": [
|
301 | 357 | "if __name__ == \"__main__\":\n",
|
302 | 358 | " root = tk.Tk()\n",
|
|
0 commit comments