import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GObject, Gdk from mods.db import db, Reception from mods.files import new_reception_win_file, reception_row_ui_str class ReceptionRow(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 datetime(self): return self._datetime @datetime.setter def datetime_setter(self, value): self._datetime = value @GObject.Property def scheduled(self): return self._scheduled @scheduled.setter def scheduled_setter(self, value): self._scheduled = value def build_reception_row(reception_datetime): b = Gtk.Builder() b.add_from_string(reception_row_ui_str) win = b.get_object('win') box = b.get_object('reception_box') b.get_object('hour').set_text(reception_datetime.strftime('%H')) b.get_object('minute').set_text(reception_datetime.strftime('%M')) with db.atomic(): reception = Reception.select().where(Reception.time == reception_datetime) row = ReceptionRow() if len(reception): row.props.scheduled = True row.props.db_id = reception.id reception_cont = b.get_object('reception_cont') reception_cont.props.border_width = 2 reception_cont.override_background_color(Gtk.StateFlags(0), Gdk.RGBA(red=0.5, green=0.7, blue=0.5, alpha=1.0)) reception_patient = Gtk.Label() reception_patient.set_text(' '.join([reception.patient.last_name, reception.patient.first_name, reception.patient.middle_name])) reception_cont.add(reception_patient) else: row.props.scheduled = False win.remove(win.get_children()[0]) row.props.datetime = reception_datetime row.add(box) return row def create_new_reception_win(root_builder): b = Gtk.Builder() class NewReceptionWinHandler: pass b.add_from_file(new_reception_win_file) b.connect_signals(NewReceptionWinHandler()) w = b.get_object('new_reception_window') return w