Рерганизация кода и начало нового приёма

This commit is contained in:
Бородин Роман 2019-12-12 19:47:08 +03:00
parent 318de06602
commit ac0a237b19
14 changed files with 345 additions and 197 deletions

190
app.py
View File

@ -1,73 +1,17 @@
import gi import gi
import os
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gdk from gi.repository import Gtk
from mods.db import db, Patient, Reception, Catalog, List from mods.db import db, Patient, Catalog, List
from mods.settings import s_get_reception_list, s_set_reception_list from mods.catalogs import create_new_catalog_win, build_catalog_row, catalog_sort_func, catalog_filter_func
from mods.catalogs import add_catalog, search_catalogs
from mods.patients import build_patient_row, patient_sort_func, patient_filter_func_factory, create_new_patient_win, create_open_patient_win from mods.patients import build_patient_row, patient_sort_func, patient_filter_func_factory, create_new_patient_win, create_open_patient_win
from mods.receptions import create_new_reception_win, build_reception_row from mods.patients import search_patients
from mods.lists import create_open_list_win from mods.receptions import create_new_reception_win, redraw_reception_list, create_reception_list_settings_win
from mods.files import list_row_ui_str from mods.lists import create_open_list_win, build_list_row
from mods.utils import show_msg, ConditionalFilter, enable_widget, disable_widget from mods.root import builder
from datetime import datetime, timedelta from mods.utils import enable_widget, disable_widget, ConditionalFilter
import peewee from datetime import datetime
import re
# Variables patient_filter = ConditionalFilter(search_patients)
resource_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res')
ui_dir = os.path.join(resource_dir, 'ui')
main_win_file = os.path.join(ui_dir, 'main_win.glade')
reception_list_settings_win_file = os.path.join(ui_dir, 'reception_list_settings.glade')
new_catalog_win_file = os.path.join(ui_dir, 'new_catalog_win.glade')
catalog_row_file = os.path.join(ui_dir, 'catalog_list_row.glade')
with open(catalog_row_file, 'r') as f:
catalog_row_ui_str = f.read()
############
builder = Gtk.Builder()
def get_reception_timelist(rec_date):
s = s_get_reception_list()
dstart = datetime(rec_date.year, rec_date.month, rec_date.day, s.day_start[0], s.day_start[1])
dend = datetime(rec_date.year, rec_date.month, rec_date.day, s.day_end[0], s.day_end[1])
work_day_minutes_total = (dend.hour - dstart.hour) * 60 + dend.minute - dstart.minute
shift_minutes_range = range(0, work_day_minutes_total, s.interval)
return [dstart + timedelta(minutes=x) for x in shift_minutes_range]
catalog_filter = ConditionalFilter(search_catalogs)
class CatalogRow(Gtk.ListBoxRow):
@GObject.Property
def db_id(self):
return self._db_id
@db_id.setter
def db_id_setter(self, value):
self._db_id = value
@GObject.Property
def name(self):
return self._name
@name.setter
def name_setter(self, value):
self._name = value
class ListRow(Gtk.ListBoxRow):
@GObject.Property
def db_id(self):
return self._db_id
@db_id.setter
def db_id_setter(self, value):
self._db_id = value
@GObject.Property
def name(self):
return self._name
@name.setter
def name_setter(self, value):
self._name = value
class MainWinHandler: class MainWinHandler:
def main_win_close(self, *args): def main_win_close(self, *args):
@ -82,20 +26,23 @@ class MainWinHandler:
cal = builder.get_object('reception_cal') cal = builder.get_object('reception_cal')
cal_date = cal.get_date() cal_date = cal.get_date()
d = datetime(cal_date.year, cal_date.month + 1, cal_date.day) d = datetime(cal_date.year, cal_date.month + 1, cal_date.day)
rl = builder.get_object('reception_list')
rl.unselect_all()
self.reception_list_unselected()
redraw_reception_list(d) redraw_reception_list(d)
def show_reception_list_settings_win(self, button): def show_reception_list_settings_win(self, button):
reception_list_settings_win = create_reception_list_settings_win() reception_list_settings_win = create_reception_list_settings_win()
reception_list_settings_win.show_all() reception_list_settings_win.show_all()
def show_new_reception_win(self, button): def show_new_reception_win(self, button):
new_reception_win = create_new_reception_win(builder) new_reception_win = create_new_reception_win()
new_reception_win.show_all() new_reception_win.show_all()
def show_new_patient_win(self, button): def show_new_patient_win(self, button):
new_patient_win = create_new_patient_win(patient_list) new_patient_win = create_new_patient_win()
new_patient_win.show_all() new_patient_win.show_all()
def show_open_patient_win(self, button): def show_open_patient_win(self, button):
pl = builder.get_object('patient_list') pl = builder.get_object('patient_list')
row = pl.get_selected_row() row = pl.get_selected_row()
open_patient_win = create_open_patient_win(row.props.db_id, patient_list) open_patient_win = create_open_patient_win(row.props.db_id)
open_patient_win.show_all() open_patient_win.show_all()
def show_open_list_win(self, button): def show_open_list_win(self, button):
ll = builder.get_object('list_list') ll = builder.get_object('list_list')
@ -103,19 +50,25 @@ class MainWinHandler:
open_list_win = create_open_list_win(row.props.db_id) open_list_win = create_open_list_win(row.props.db_id)
open_list_win.show_all() open_list_win.show_all()
def show_new_catalog_win(self, button): def show_new_catalog_win(self, button):
new_catalog_win = create_new_catalog_win() new_catalog_win = create_new_catalog_win(catalog_list)
new_catalog_win.show_all() new_catalog_win.show_all()
def reception_list_selected(self, *a): def reception_list_selected(self, *a):
rl = builder.get_object('reception_list') rl = builder.get_object('reception_list')
new_button = builder.get_object('new_reception_button') new_button = builder.get_object('new_reception_button')
edit_button = builder.get_object('edit_reception_button') edit_button = builder.get_object('edit_reception_button')
row = rl.get_selected_row() row = rl.get_selected_row()
if not row:
return
if row.props.scheduled: if row.props.scheduled:
enable_widget([edit_button]) enable_widget([edit_button])
disable_widget([new_button]) disable_widget([new_button])
else: else:
enable_widget([new_button]) enable_widget([new_button])
disable_widget([edit_button]) disable_widget([edit_button])
def reception_list_unselected(self, *a):
new_button = builder.get_object('new_reception_button')
edit_button = builder.get_object('edit_reception_button')
disable_widget([new_button, edit_button])
def patient_list_selected(self, *a): def patient_list_selected(self, *a):
button = builder.get_object('patient_open_button') button = builder.get_object('patient_open_button')
enable_widget([button]) enable_widget([button])
@ -144,67 +97,20 @@ class MainWinHandler:
self.catalog_list_unselected() self.catalog_list_unselected()
cl.invalidate_filter() cl.invalidate_filter()
def build_list_row(list_o):
b = Gtk.Builder()
b.add_from_string(list_row_ui_str)
win = b.get_object('win')
box = b.get_object('list_box')
b.get_object('name').set_text(list_o.name)
row = ListRow()
row.props.db_id = list_o.id
row.name = list_o.name
win.remove(win.get_children()[0])
row.add(box)
return row
def build_catalog_row(catalog):
b = Gtk.Builder()
b.add_from_string(catalog_row_ui_str)
win = b.get_object('win')
box = b.get_object('catalog_box')
b.get_object('name').set_text(catalog.name)
row = CatalogRow()
row.props.db_id = catalog.id
row.name = catalog.name
win.remove(win.get_children()[0])
row.add(box)
return row
def list_sort_func(row1, row2, *a): def list_sort_func(row1, row2, *a):
text1 = row1.props.name text1 = row1.props.name
text2 = row2.props.name text2 = row2.props.name
return (text1 > text2) - (text1 < text2) return (text1 > text2) - (text1 < text2)
def catalog_sort_func(row1, row2, *a):
text1 = row1.props.name
text2 = row2.props.name
return (text1 > text2) - (text1 < text2)
def catalog_filter_func(row):
fstr = builder.get_object('catalog_filter').get_text().strip()
if not fstr:
catalog_filter.reset()
return True
return row.props.db_id in catalog_filter.filter(fstr)
def redraw_reception_list(selected_date):
reception_timelist = get_reception_timelist(selected_date)
reception_list = builder.get_object('reception_list')
for c in reception_list.get_children():
reception_list.remove(c)
for d in reception_timelist:
reception_list.add(build_reception_row(d))
reception_list.show_all()
builder.add_from_file(main_win_file)
builder.connect_signals(MainWinHandler()) builder.connect_signals(MainWinHandler())
##### #####
redraw_reception_list(datetime.now()) redraw_reception_list(datetime.now())
##### #####
patient_list = builder.get_object('patient_list') patient_list = builder.get_object('patient_list')
patient_list.set_sort_func(patient_sort_func) patient_list.set_sort_func(patient_sort_func)
patient_list.set_filter_func(patient_filter_func_factory(builder)) patient_list.set_filter_func(patient_filter_func_factory(patient_filter, builder))
with db.atomic(): with db.atomic():
for p in Patient.select(): for p in Patient.select():
patient_list.add(build_patient_row(p)) patient_list.add(build_patient_row(p))
@ -222,54 +128,6 @@ with db.atomic():
for c in Catalog.select(): for c in Catalog.select():
catalog_list.add(build_catalog_row(c)) catalog_list.add(build_catalog_row(c))
def create_reception_list_settings_win():
b = Gtk.Builder()
class ReceptionListSettingsHandler:
def save_settings(self, *a):
start_hour = int(b.get_object('start_hour').get_value())
start_minute = int(b.get_object('start_minute').get_value())
end_hour = int(b.get_object('end_hour').get_value())
end_minute = int(b.get_object('end_minute').get_value())
interval = int(b.get_object('interval').get_value())
s_set_reception_list([start_hour, start_minute], [end_hour, end_minute], interval)
redraw_reception_list(datetime.now())
b.get_object('reception_list_settings_win').close()
b.add_from_file(reception_list_settings_win_file)
b.connect_signals(ReceptionListSettingsHandler())
s = s_get_reception_list()
b.get_object('start_hour').set_value(s.day_start[0])
b.get_object('start_minute').set_value(s.day_start[1])
b.get_object('end_hour').set_value(s.day_end[0])
b.get_object('end_minute').set_value(s.day_end[1])
b.get_object('interval').set_value(s.interval)
w = b.get_object('reception_list_settings_win')
return w
def create_new_catalog_win():
b = Gtk.Builder()
class NewCatalogHandler:
def save_catalog(self, *a):
catname = re.sub(r'\s+', ' ', b.get_object('catalog_name').get_text()).strip()
if not len(catname):
return show_msg('Не указано имя справочника', 'Данное поле должно быть заполнено', level='warn')
try:
catalog = add_catalog(catname)
except peewee.IntegrityError:
return show_msg('Данный справочник уже существует', 'Справочник с указанным названием уже есть с базе данных', level='warn')
row = build_catalog_row(catalog)
catalog_list.add(row)
catalog_list.select_row(row)
catalog_list.show_all()
b.get_object('new_catalog_window').close()
b.add_from_file(new_catalog_win_file)
b.connect_signals(NewCatalogHandler())
w = b.get_object('new_catalog_window')
return w
main_win = builder.get_object('main_window') main_win = builder.get_object('main_window')
main_win.show_all() main_win.show_all()
Gtk.main() Gtk.main()

View File

@ -1,5 +1,26 @@
from mods.db import db, Catalog, CatalogIndex from mods.db import db, Catalog, CatalogIndex
import re import re
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
from mods.utils import show_msg, ConditionalFilter
from mods.files import catalog_row_ui_str, new_catalog_win_file
from mods.root import builder
import peewee
class CatalogRow(Gtk.ListBoxRow):
@GObject.Property
def db_id(self):
return self._db_id
@db_id.setter
def db_id_setter(self, value):
self._db_id = value
@GObject.Property
def name(self):
return self._name
@name.setter
def name_setter(self, value):
self._name = value
def add_catalog(name): def add_catalog(name):
with db.atomic(): with db.atomic():
@ -23,3 +44,52 @@ def search_catalogs(q):
.where(CatalogIndex.match(q)) .where(CatalogIndex.match(q))
.order_by(CatalogIndex.bm25())) .order_by(CatalogIndex.bm25()))
catalog_filter = ConditionalFilter(search_catalogs)
###########################################################################
def build_catalog_row(catalog):
b = Gtk.Builder()
b.add_from_string(catalog_row_ui_str)
win = b.get_object('win')
box = b.get_object('catalog_box')
b.get_object('name').set_text(catalog.name)
row = CatalogRow()
row.props.db_id = catalog.id
row.name = catalog.name
win.remove(win.get_children()[0])
row.add(box)
return row
def create_new_catalog_win(catalog_list):
b = Gtk.Builder()
class NewCatalogHandler:
def save_catalog(self, *a):
catname = re.sub(r'\s+', ' ', b.get_object('catalog_name').get_text()).strip()
if not len(catname):
return show_msg('Не указано имя справочника', 'Данное поле должно быть заполнено', level='warn')
try:
catalog = add_catalog(catname)
except peewee.IntegrityError:
return show_msg('Данный справочник уже существует', 'Справочник с указанным названием уже есть с базе данных', level='warn')
row = build_catalog_row(catalog)
catalog_list.add(row)
catalog_list.select_row(row)
catalog_list.show_all()
b.get_object('new_catalog_window').close()
b.add_from_file(new_catalog_win_file)
b.connect_signals(NewCatalogHandler())
w = b.get_object('new_catalog_window')
return w
def catalog_sort_func(row1, row2, *a):
text1 = row1.props.name
text2 = row2.props.name
return (text1 > text2) - (text1 < text2)
def catalog_filter_func(row):
fstr = builder.get_object('catalog_filter').get_text().strip()
if not fstr:
catalog_filter.reset()
return True
return row.props.db_id in catalog_filter.filter(fstr)

View File

@ -22,8 +22,15 @@ with open(female_patient_row_file, 'r') as f:
reception_row_file = os.path.join(ui_dir, 'reception_row.glade') reception_row_file = os.path.join(ui_dir, 'reception_row.glade')
with open(reception_row_file, 'r') as f: with open(reception_row_file, 'r') as f:
reception_row_ui_str = f.read() reception_row_ui_str = f.read()
catalog_row_file = os.path.join(ui_dir, 'catalog_list_row.glade')
with open(catalog_row_file, 'r') as f:
catalog_row_ui_str = f.read()
main_win_file = os.path.join(ui_dir, 'main_win.glade')
new_patient_win_file = os.path.join(ui_dir, 'new_patient_win.glade') new_patient_win_file = os.path.join(ui_dir, 'new_patient_win.glade')
open_patient_win_file = os.path.join(ui_dir, 'open_patient_win.glade') open_patient_win_file = os.path.join(ui_dir, 'open_patient_win.glade')
edit_patient_win_file = os.path.join(ui_dir, 'edit_patient_win.glade') edit_patient_win_file = os.path.join(ui_dir, 'edit_patient_win.glade')
new_reception_win_file = os.path.join(ui_dir, 'new_reception_win.glade') new_reception_win_file = os.path.join(ui_dir, 'new_reception_win.glade')
reception_list_settings_win_file = os.path.join(ui_dir, 'reception_list_settings.glade')
new_catalog_win_file = os.path.join(ui_dir, 'new_catalog_win.glade')
choose_patient_win_file = os.path.join(ui_dir, 'choose_patient_win.glade')

View File

@ -2,7 +2,7 @@ import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gdk from gi.repository import Gtk, GObject, Gdk
from mods.db import db, List, ListRecord, ListRecordIndex from mods.db import db, List, ListRecord, ListRecordIndex
from mods.files import open_list_win_file, listrecord_row_ui_str, editable_row_ui_str from mods.files import open_list_win_file, listrecord_row_ui_str, editable_row_ui_str, list_row_ui_str
from mods.utils import show_msg, disable_widget, enable_widget, ConditionalFilter from mods.utils import show_msg, disable_widget, enable_widget, ConditionalFilter
import re import re
import peewee import peewee
@ -27,6 +27,20 @@ class ListRecFilter(ConditionalFilter):
self.ids = list(map(lambda x: x.id, self.search_func(list_id, query))) self.ids = list(map(lambda x: x.id, self.search_func(list_id, query)))
return self.ids return self.ids
class ListRow(Gtk.ListBoxRow):
@GObject.Property
def db_id(self):
return self._db_id
@db_id.setter
def db_id_setter(self, value):
self._db_id = value
@GObject.Property
def name(self):
return self._name
@name.setter
def name_setter(self, value):
self._name = value
class ListRecordRow(Gtk.ListBoxRow): class ListRecordRow(Gtk.ListBoxRow):
@GObject.Property @GObject.Property
def db_id(self): def db_id(self):
@ -87,6 +101,18 @@ def search_list_record(list_id, q):
.where((ListRecord.list == list_o) & (ListRecordIndex.match(q))) .where((ListRecord.list == list_o) & (ListRecordIndex.match(q)))
.order_by(ListRecordIndex.bm25())) .order_by(ListRecordIndex.bm25()))
##################################################################################################################### #####################################################################################################################
def build_list_row(list_o):
b = Gtk.Builder()
b.add_from_string(list_row_ui_str)
win = b.get_object('win')
box = b.get_object('list_box')
b.get_object('name').set_text(list_o.name)
row = ListRow()
row.props.db_id = list_o.id
row.name = list_o.name
win.remove(win.get_children()[0])
row.add(box)
return row
def build_listrecord_row(listrec_o): def build_listrecord_row(listrec_o):
b = Gtk.Builder() b = Gtk.Builder()
b.add_from_string(listrecord_row_ui_str) b.add_from_string(listrecord_row_ui_str)
@ -124,6 +150,8 @@ def create_open_list_win(list_id):
if ev.keyval == Gdk.KEY_Escape: if ev.keyval == Gdk.KEY_Escape:
lr_list.remove(row) lr_list.remove(row)
row.destroy() row.destroy()
lr_list.unselect_all()
self.listrec_row_unselected()
def row_edit_cancel(self, entry, ev, edit_row): def row_edit_cancel(self, entry, ev, edit_row):
if ev.keyval == Gdk.KEY_Escape: if ev.keyval == Gdk.KEY_Escape:
rec = get_listrecord(edit_row.props.db_id) rec = get_listrecord(edit_row.props.db_id)

View File

@ -2,9 +2,10 @@ import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject from gi.repository import Gtk, GObject
import os import os
from mods.files import gender_ui_str, icon_dir, open_patient_win_file, new_patient_win_file, edit_patient_win_file from mods.files import gender_ui_str, icon_dir, open_patient_win_file, new_patient_win_file, edit_patient_win_file, choose_patient_win_file
from mods.utils import ConditionalFilter, show_msg, gender_dict, doc_type_dict from mods.utils import ConditionalFilter, show_msg, gender_dict, doc_type_dict, enable_widget, disable_widget
from mods.db import db, Patient, PatientIndex from mods.db import db, Patient, PatientIndex
from mods.root import builder
from datetime import date from datetime import date
import re import re
import peewee import peewee
@ -39,8 +40,9 @@ def search_patients(q):
on=(Patient.id == PatientIndex.rowid)) on=(Patient.id == PatientIndex.rowid))
.where(PatientIndex.match(q)) .where(PatientIndex.match(q))
.order_by(PatientIndex.bm25())) .order_by(PatientIndex.bm25()))
def get_all_patients():
patient_filter = ConditionalFilter(search_patients) with db.atomic():
return Patient.select()
class PatientRow(Gtk.ListBoxRow): class PatientRow(Gtk.ListBoxRow):
@GObject.Property @GObject.Property
@ -155,8 +157,9 @@ def set_patient_win_values(patient_id, b, edit=False):
b.get_object('snils_number').set_text(pat.snils_number) b.get_object('snils_number').set_text(pat.snils_number)
b.get_object('notes_buffer').set_text(pat.notes) b.get_object('notes_buffer').set_text(pat.notes)
def create_open_patient_win(patient_id, patient_list): def create_open_patient_win(patient_id):
b = Gtk.Builder() b = Gtk.Builder()
patient_list = builder.get_object('patient_list')
class OpenPatientWinHandler: class OpenPatientWinHandler:
def show_edit_patient_win(self, *a): def show_edit_patient_win(self, *a):
edit_patient_win = create_edit_patient_win(patient_id, patient_list) edit_patient_win = create_edit_patient_win(patient_id, patient_list)
@ -170,8 +173,9 @@ def create_open_patient_win(patient_id, patient_list):
set_patient_win_values(patient_id, b) set_patient_win_values(patient_id, b)
return w return w
def create_edit_patient_win(patient_id, patient_list): def create_edit_patient_win(patient_id):
b = Gtk.Builder() b = Gtk.Builder()
patient_list = builder.get_object('patient_list')
class EditPatientWinHandler: class EditPatientWinHandler:
def edit_patient_win_close(self, *args): def edit_patient_win_close(self, *args):
w.destroy() w.destroy()
@ -205,9 +209,9 @@ def create_edit_patient_win(patient_id, patient_list):
set_patient_win_values(patient_id, b, edit=True) set_patient_win_values(patient_id, b, edit=True)
return w return w
def create_new_patient_win():
def create_new_patient_win(patient_list):
b = Gtk.Builder() b = Gtk.Builder()
patient_list = builder.get_object('patient_list')
class NewPatienWinHandler: class NewPatienWinHandler:
def only_digits(self, entry): def only_digits(self, entry):
text = entry.get_text() text = entry.get_text()
@ -232,11 +236,40 @@ def create_new_patient_win(patient_list):
b.connect_signals(NewPatienWinHandler()) b.connect_signals(NewPatienWinHandler())
w = b.get_object('new_patient_window') w = b.get_object('new_patient_window')
return w return w
def create_choose_patient_win(new_reception_b):
b = Gtk.Builder()
patient_cont = new_reception_b.get_object('patient')
patient_filter = ConditionalFilter(search_patients)
class ChoosePatientWinHandler:
def patient_filter_changed(self, filter_widget):
pl.unselect_all()
self.patient_list_unselected()
pl.invalidate_filter()
def patient_list_selected(self, *a):
accept_button = b.get_object('accept_button')
enable_widget([accept_button])
def patient_list_unselected(self, *a):
accept_button = b.get_object('accept_button')
disable_widget([accept_button])
b.add_from_file(choose_patient_win_file)
b.connect_signals(ChoosePatientWinHandler())
pl = b.get_object('patient_list')
pl.set_sort_func(patient_sort_func)
pl.set_filter_func(patient_filter_func_factory(patient_filter, b))
###
for p in get_all_patients():
pl.add(build_patient_row(p))
###
w = b.get_object('choose_patient_window')
return w
def patient_sort_func(row1, row2, *a): def patient_sort_func(row1, row2, *a):
text1 = row1.props.fio text1 = row1.props.fio
text2 = row2.props.fio text2 = row2.props.fio
return (text1 > text2) - (text1 < text2) return (text1 > text2) - (text1 < text2)
def patient_filter_func_factory(b):
def patient_filter_func_factory(patient_filter, b):
def patient_filter_func(row): def patient_filter_func(row):
fstr = b.get_object('patient_filter').get_text().strip() fstr = b.get_object('patient_filter').get_text().strip()
if not fstr: if not fstr:
@ -244,3 +277,4 @@ def patient_filter_func_factory(b):
return True return True
return row.props.db_id in patient_filter.filter(fstr) return row.props.db_id in patient_filter.filter(fstr)
return patient_filter_func return patient_filter_func

View File

@ -2,7 +2,18 @@ import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gdk from gi.repository import Gtk, GObject, Gdk
from mods.db import db, Reception from mods.db import db, Reception
from mods.files import new_reception_win_file, reception_row_ui_str from mods.files import new_reception_win_file, reception_row_ui_str, reception_list_settings_win_file
from mods.settings import s_get_reception_list, s_set_reception_list
from mods.root import builder
from datetime import datetime, timedelta
def get_reception_timelist(rec_date):
s = s_get_reception_list()
dstart = datetime(rec_date.year, rec_date.month, rec_date.day, s.day_start[0], s.day_start[1])
dend = datetime(rec_date.year, rec_date.month, rec_date.day, s.day_end[0], s.day_end[1])
work_day_minutes_total = (dend.hour - dstart.hour) * 60 + dend.minute - dstart.minute
shift_minutes_range = range(0, work_day_minutes_total, s.interval)
return [dstart + timedelta(minutes=x) for x in shift_minutes_range]
class ReceptionRow(Gtk.ListBoxRow): class ReceptionRow(Gtk.ListBoxRow):
@GObject.Property @GObject.Property
@ -23,6 +34,13 @@ class ReceptionRow(Gtk.ListBoxRow):
@scheduled.setter @scheduled.setter
def scheduled_setter(self, value): def scheduled_setter(self, value):
self._scheduled = value self._scheduled = value
class NewReceptionPatientLabel(Gtk.Label):
@GObject.Property
def patient_db_id(self):
return self._patient_db_id
@patient_db_id.setter
def db_id_setter(self, value):
self._patient_db_id = value
def build_reception_row(reception_datetime): def build_reception_row(reception_datetime):
b = Gtk.Builder() b = Gtk.Builder()
@ -50,11 +68,57 @@ def build_reception_row(reception_datetime):
row.add(box) row.add(box)
return row return row
def create_new_reception_win(root_builder): def create_new_reception_win():
b = Gtk.Builder() b = Gtk.Builder()
reception_list = builder.get_object('reception_list')
row = reception_list.get_selected_row()
class NewReceptionWinHandler: class NewReceptionWinHandler:
pass def show_choose_patient_win(self, button):
from mods.patients import create_choose_patient_win
choose_patient_win = create_choose_patient_win(b)
choose_patient_win.show_all()
b.add_from_file(new_reception_win_file) b.add_from_file(new_reception_win_file)
b.connect_signals(NewReceptionWinHandler()) b.connect_signals(NewReceptionWinHandler())
#####
patient_label = NewReceptionPatientLabel()
patient_label.props.patient_db_id = -1
#patient_label.set_markup('<span size="xx-large">test</span>')
#####
patient_cont = b.get_object('patient')
patient_cont.pack_start(patient_label, True, True, 0)
patient_cont.reorder_child(patient_label, 0)
w = b.get_object('new_reception_window') w = b.get_object('new_reception_window')
dt_label = b.get_object('datetime')
dt_label.set_text(row.props.datetime.strftime('%m.%d.%Y - %H:%M'))
return w return w
def create_reception_list_settings_win():
b = Gtk.Builder()
class ReceptionListSettingsHandler:
def save_settings(self, *a):
start_hour = int(b.get_object('start_hour').get_value())
start_minute = int(b.get_object('start_minute').get_value())
end_hour = int(b.get_object('end_hour').get_value())
end_minute = int(b.get_object('end_minute').get_value())
interval = int(b.get_object('interval').get_value())
s_set_reception_list([start_hour, start_minute], [end_hour, end_minute], interval)
redraw_reception_list(datetime.now())
b.get_object('reception_list_settings_win').close()
b.add_from_file(reception_list_settings_win_file)
b.connect_signals(ReceptionListSettingsHandler())
s = s_get_reception_list()
b.get_object('start_hour').set_value(s.day_start[0])
b.get_object('start_minute').set_value(s.day_start[1])
b.get_object('end_hour').set_value(s.day_end[0])
b.get_object('end_minute').set_value(s.day_end[1])
b.get_object('interval').set_value(s.interval)
w = b.get_object('reception_list_settings_win')
return w
def redraw_reception_list(selected_date):
reception_timelist = get_reception_timelist(selected_date)
reception_list = builder.get_object('reception_list')
for c in reception_list.get_children():
reception_list.remove(c)
for d in reception_timelist:
reception_list.add(build_reception_row(d))
reception_list.show_all()

7
mods/root.py Normal file
View File

@ -0,0 +1,7 @@
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from mods.files import main_win_file
builder = Gtk.Builder()
builder.add_from_file(main_win_file)

View File

@ -2,7 +2,7 @@
<!-- Generated with glade 3.22.1 --> <!-- Generated with glade 3.22.1 -->
<interface> <interface>
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="choose_patioent_window"> <object class="GtkWindow" id="choose_patient_window">
<property name="width_request">600</property> <property name="width_request">600</property>
<property name="height_request">500</property> <property name="height_request">500</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -32,10 +32,16 @@
</child> </child>
</object> </object>
</child> </child>
<child>
<object class="GtkBox" id="patients_page">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child> <child>
<object class="GtkScrolledWindow"> <object class="GtkScrolledWindow">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property> <property name="shadow_type">in</property>
<child> <child>
<object class="GtkViewport"> <object class="GtkViewport">
@ -45,11 +51,70 @@
<object class="GtkListBox" id="patient_list"> <object class="GtkListBox" id="patient_list">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<signal name="row-selected" handler="patient_list_selected" swapped="no"/>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
</object> </object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">3</property>
<property name="margin_bottom">3</property>
<child>
<object class="GtkFixed">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSearchEntry" id="patient_filter">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<signal name="changed" handler="patient_filter_changed" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFixed">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child> </child>
</object> </object>
</interface> </interface>

View File

@ -4,6 +4,8 @@
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkTextBuffer" id="notes_buffer"/> <object class="GtkTextBuffer" id="notes_buffer"/>
<object class="GtkWindow" id="edit_patient_window"> <object class="GtkWindow" id="edit_patient_window">
<property name="width_request">500</property>
<property name="height_request">290</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="modal">True</property> <property name="modal">True</property>
<property name="window_position">center</property> <property name="window_position">center</property>

View File

@ -3,14 +3,19 @@
<interface> <interface>
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkApplicationWindow" id="main_window"> <object class="GtkApplicationWindow" id="main_window">
<property name="width_request">800</property>
<property name="height_request">500</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="title">ElDoc</property> <property name="window_position">center</property>
<property name="default_width">800</property>
<property name="default_height">500</property>
<property name="icon_name">accessories-character-map</property> <property name="icon_name">accessories-character-map</property>
<signal name="destroy" handler="main_win_close" swapped="no"/> <signal name="destroy" handler="main_win_close" swapped="no"/>
<child> <child type="titlebar">
<placeholder/> <object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Электронный Доктор</property>
<property name="show_close_button">True</property>
</object>
</child> </child>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
@ -51,6 +56,7 @@
<property name="label" translatable="yes">Создать</property> <property name="label" translatable="yes">Создать</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="icon_name">list-add</property> <property name="icon_name">list-add</property>
<signal name="clicked" handler="show_new_reception_win" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -121,6 +127,7 @@
<object class="GtkListBox" id="reception_list"> <object class="GtkListBox" id="reception_list">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<signal name="row-selected" handler="reception_list_selected" swapped="no"/>
</object> </object>
</child> </child>
</object> </object>

View File

@ -4,6 +4,8 @@
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkTextBuffer" id="notes_buffer"/> <object class="GtkTextBuffer" id="notes_buffer"/>
<object class="GtkWindow" id="new_patient_window"> <object class="GtkWindow" id="new_patient_window">
<property name="width_request">500</property>
<property name="height_request">290</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="modal">True</property> <property name="modal">True</property>
<property name="window_position">center</property> <property name="window_position">center</property>

View File

@ -101,12 +101,13 @@
<property name="margin_top">5</property> <property name="margin_top">5</property>
<property name="margin_bottom">5</property> <property name="margin_bottom">5</property>
<child> <child>
<object class="GtkLabel" id="patient_fio"> <object class="GtkBox" id="patient">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<attributes> <property name="orientation">vertical</property>
<attribute name="scale" value="2"/> <child>
</attributes> <placeholder/>
</child>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
@ -120,6 +121,7 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
<signal name="clicked" handler="show_choose_patient_win" swapped="no"/>
<child> <child>
<object class="GtkImage"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>

View File

@ -3,6 +3,8 @@
<interface> <interface>
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="open_list_window"> <object class="GtkWindow" id="open_list_window">
<property name="width_request">600</property>
<property name="height_request">500</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="modal">True</property> <property name="modal">True</property>
<property name="window_position">center</property> <property name="window_position">center</property>

View File

@ -4,6 +4,8 @@
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkTextBuffer" id="notes_buffer"/> <object class="GtkTextBuffer" id="notes_buffer"/>
<object class="GtkWindow" id="open_patient_window"> <object class="GtkWindow" id="open_patient_window">
<property name="width_request">500</property>
<property name="height_request">400</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="modal">True</property> <property name="modal">True</property>
<property name="window_position">center</property> <property name="window_position">center</property>
@ -608,8 +610,6 @@
<property name="left_padding">12</property> <property name="left_padding">12</property>
<child> <child>
<object class="GtkListBox" id="reception_list"> <object class="GtkListBox" id="reception_list">
<property name="width_request">400</property>
<property name="height_request">150</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
</object> </object>