2019-10-26 21:13:07 +03:00
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
2019-12-12 19:47:08 +03:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from mods.db import db, Patient, Catalog, List
|
|
|
|
from mods.catalogs import create_new_catalog_win, build_catalog_row, catalog_sort_func, catalog_filter_func
|
2019-12-04 17:16:40 +03:00
|
|
|
from mods.patients import build_patient_row, patient_sort_func, patient_filter_func_factory, create_new_patient_win, create_open_patient_win
|
2019-12-12 19:47:08 +03:00
|
|
|
from mods.patients import search_patients
|
2019-12-13 23:42:46 +03:00
|
|
|
from mods.receptions import create_new_reception_win, redraw_reception_list, create_reception_list_settings_win, create_open_reception_win
|
2019-12-12 19:47:08 +03:00
|
|
|
from mods.lists import create_open_list_win, build_list_row
|
|
|
|
from mods.root import builder
|
|
|
|
from mods.utils import enable_widget, disable_widget, ConditionalFilter
|
|
|
|
from datetime import datetime
|
2019-10-26 21:13:07 +03:00
|
|
|
|
2019-12-12 19:47:08 +03:00
|
|
|
patient_filter = ConditionalFilter(search_patients)
|
2019-11-12 19:30:17 +03:00
|
|
|
|
2019-10-28 21:30:21 +03:00
|
|
|
class MainWinHandler:
|
|
|
|
def main_win_close(self, *args):
|
|
|
|
Gtk.main_quit()
|
2019-11-12 19:30:17 +03:00
|
|
|
def set_reception_list_today(self, *a):
|
|
|
|
cal = builder.get_object('reception_cal')
|
|
|
|
d = datetime.now()
|
|
|
|
cal.select_month(d.month - 1, d.year)
|
|
|
|
cal.select_day(d.day)
|
|
|
|
redraw_reception_list(d)
|
|
|
|
def change_reception_list_day(self, *a):
|
|
|
|
cal = builder.get_object('reception_cal')
|
|
|
|
cal_date = cal.get_date()
|
|
|
|
d = datetime(cal_date.year, cal_date.month + 1, cal_date.day)
|
2019-12-12 19:47:08 +03:00
|
|
|
rl = builder.get_object('reception_list')
|
|
|
|
rl.unselect_all()
|
|
|
|
self.reception_list_unselected()
|
2019-11-12 19:30:17 +03:00
|
|
|
redraw_reception_list(d)
|
|
|
|
def show_reception_list_settings_win(self, button):
|
|
|
|
reception_list_settings_win = create_reception_list_settings_win()
|
|
|
|
reception_list_settings_win.show_all()
|
2019-12-04 17:16:40 +03:00
|
|
|
def show_new_reception_win(self, button):
|
2019-12-12 19:47:08 +03:00
|
|
|
new_reception_win = create_new_reception_win()
|
2019-12-04 17:16:40 +03:00
|
|
|
new_reception_win.show_all()
|
2019-12-13 23:42:46 +03:00
|
|
|
def show_open_reception_win(self, button):
|
|
|
|
open_reception_win = create_open_reception_win()
|
|
|
|
open_reception_win.show_all()
|
2019-10-28 21:30:21 +03:00
|
|
|
def show_new_patient_win(self, button):
|
2019-12-12 19:47:08 +03:00
|
|
|
new_patient_win = create_new_patient_win()
|
2019-10-28 21:30:21 +03:00
|
|
|
new_patient_win.show_all()
|
2019-11-05 19:40:50 +03:00
|
|
|
def show_open_patient_win(self, button):
|
|
|
|
pl = builder.get_object('patient_list')
|
|
|
|
row = pl.get_selected_row()
|
2019-12-12 19:47:08 +03:00
|
|
|
open_patient_win = create_open_patient_win(row.props.db_id)
|
2019-11-05 19:40:50 +03:00
|
|
|
open_patient_win.show_all()
|
2019-11-23 23:36:26 +03:00
|
|
|
def show_open_list_win(self, button):
|
|
|
|
ll = builder.get_object('list_list')
|
|
|
|
row = ll.get_selected_row()
|
|
|
|
open_list_win = create_open_list_win(row.props.db_id)
|
|
|
|
open_list_win.show_all()
|
2019-11-12 21:39:26 +03:00
|
|
|
def show_new_catalog_win(self, button):
|
2019-12-12 19:47:08 +03:00
|
|
|
new_catalog_win = create_new_catalog_win(catalog_list)
|
2019-11-12 21:39:26 +03:00
|
|
|
new_catalog_win.show_all()
|
2019-12-04 17:16:40 +03:00
|
|
|
def reception_list_selected(self, *a):
|
|
|
|
rl = builder.get_object('reception_list')
|
|
|
|
new_button = builder.get_object('new_reception_button')
|
|
|
|
edit_button = builder.get_object('edit_reception_button')
|
2019-12-13 23:42:46 +03:00
|
|
|
remove_button = builder.get_object('remove_reception_button')
|
2019-12-04 17:16:40 +03:00
|
|
|
row = rl.get_selected_row()
|
2019-12-12 19:47:08 +03:00
|
|
|
if not row:
|
2019-12-13 23:42:46 +03:00
|
|
|
return True
|
2019-12-04 17:16:40 +03:00
|
|
|
if row.props.scheduled:
|
2019-12-13 23:42:46 +03:00
|
|
|
enable_widget([edit_button, remove_button])
|
2019-12-04 17:16:40 +03:00
|
|
|
disable_widget([new_button])
|
|
|
|
else:
|
|
|
|
enable_widget([new_button])
|
2019-12-13 23:42:46 +03:00
|
|
|
disable_widget([edit_button, remove_button])
|
2019-12-12 19:47:08 +03:00
|
|
|
def reception_list_unselected(self, *a):
|
|
|
|
new_button = builder.get_object('new_reception_button')
|
|
|
|
edit_button = builder.get_object('edit_reception_button')
|
2019-12-13 23:42:46 +03:00
|
|
|
remove_button = builder.get_object('remove_reception_button')
|
|
|
|
disable_widget([new_button, edit_button, remove_button])
|
2019-11-05 19:40:50 +03:00
|
|
|
def patient_list_selected(self, *a):
|
|
|
|
button = builder.get_object('patient_open_button')
|
2019-12-04 17:16:40 +03:00
|
|
|
enable_widget([button])
|
2019-11-05 19:40:50 +03:00
|
|
|
def patient_list_unselected(self, *a):
|
|
|
|
button = builder.get_object('patient_open_button')
|
2019-12-04 17:16:40 +03:00
|
|
|
disable_widget([button])
|
2019-10-30 20:17:14 +03:00
|
|
|
def patient_filter_changed(self, filter_widget):
|
|
|
|
pl = builder.get_object('patient_list')
|
|
|
|
pl.unselect_all()
|
2019-11-05 19:40:50 +03:00
|
|
|
self.patient_list_unselected()
|
2019-10-30 20:17:14 +03:00
|
|
|
pl.invalidate_filter()
|
2019-11-23 23:36:26 +03:00
|
|
|
def list_list_selected(self, *a):
|
|
|
|
open_button = builder.get_object('list_open_button')
|
2019-12-04 17:16:40 +03:00
|
|
|
enable_widget([open_button])
|
2019-11-19 15:37:53 +03:00
|
|
|
def catalog_list_selected(self, *a):
|
|
|
|
open_button = builder.get_object('catalog_open_button')
|
|
|
|
rename_button = builder.get_object('catalog_rename_button')
|
2019-12-04 17:16:40 +03:00
|
|
|
enable_widget([open_button, rename_button])
|
2019-11-19 15:37:53 +03:00
|
|
|
def catalog_list_unselected(self, *a):
|
|
|
|
open_button = builder.get_object('catalog_open_button')
|
|
|
|
rename_button = builder.get_object('catalog_rename_button')
|
2019-12-04 17:16:40 +03:00
|
|
|
disable_widget([open_button, rename_button])
|
2019-11-12 21:39:26 +03:00
|
|
|
def catalog_filter_changed(self, filter_widget):
|
|
|
|
cl = builder.get_object('catalog_list')
|
|
|
|
cl.unselect_all()
|
2019-11-19 15:37:53 +03:00
|
|
|
self.catalog_list_unselected()
|
2019-11-12 21:39:26 +03:00
|
|
|
cl.invalidate_filter()
|
2019-10-30 20:17:14 +03:00
|
|
|
|
2019-11-23 23:36:26 +03:00
|
|
|
def list_sort_func(row1, row2, *a):
|
|
|
|
text1 = row1.props.name
|
|
|
|
text2 = row2.props.name
|
|
|
|
return (text1 > text2) - (text1 < text2)
|
2019-11-08 21:18:38 +03:00
|
|
|
|
2019-10-28 21:30:21 +03:00
|
|
|
builder.connect_signals(MainWinHandler())
|
2019-11-08 21:18:38 +03:00
|
|
|
#####
|
|
|
|
redraw_reception_list(datetime.now())
|
|
|
|
#####
|
2019-10-30 20:17:14 +03:00
|
|
|
patient_list = builder.get_object('patient_list')
|
|
|
|
patient_list.set_sort_func(patient_sort_func)
|
2019-12-12 19:47:08 +03:00
|
|
|
patient_list.set_filter_func(patient_filter_func_factory(patient_filter, builder))
|
2019-11-19 15:37:53 +03:00
|
|
|
with db.atomic():
|
|
|
|
for p in Patient.select():
|
2019-10-30 20:17:14 +03:00
|
|
|
patient_list.add(build_patient_row(p))
|
2019-11-12 19:30:17 +03:00
|
|
|
#####
|
2019-11-23 23:36:26 +03:00
|
|
|
list_list = builder.get_object('list_list')
|
|
|
|
list_list.set_sort_func(list_sort_func)
|
|
|
|
with db.atomic():
|
|
|
|
for l in List.select():
|
|
|
|
list_list.add(build_list_row(l))
|
|
|
|
#####
|
2019-11-12 19:30:17 +03:00
|
|
|
catalog_list = builder.get_object('catalog_list')
|
2019-11-12 21:39:26 +03:00
|
|
|
catalog_list.set_sort_func(catalog_sort_func)
|
|
|
|
catalog_list.set_filter_func(catalog_filter_func)
|
2019-11-19 15:37:53 +03:00
|
|
|
with db.atomic():
|
|
|
|
for c in Catalog.select():
|
2019-11-12 19:30:17 +03:00
|
|
|
catalog_list.add(build_catalog_row(c))
|
2019-10-30 20:17:14 +03:00
|
|
|
|
2019-10-26 21:13:07 +03:00
|
|
|
main_win = builder.get_object('main_window')
|
|
|
|
main_win.show_all()
|
|
|
|
Gtk.main()
|