def build_kits(self, kits=None): data = parser(self.params, kits) query_count_all() for kit in data: # Create a page child_builder = Gtk.Builder.new_from_file(utils.get_template("first_aid_kit.glade")) # child = child_builder.get_object("main-box") child = child_builder.get_object("child-scrolled") child_builder.connect_signals({ "btn-save-clicked": (self.save_kit, child_builder, kit), "btn-cancel-clicked": (self.cancel, child_builder), "btn-modify-clicked": (self.enable_modify, child_builder) }) name = child_builder.get_object("name") name.set_text(kit["name"]) name.set_sensitive(False) location_combo = child_builder.get_object("location") location_combo.set_sensitive(False) utils.location_combo( combo=location_combo, locations=self.params.locations, active=kit["location_id"] ) btn_save = child_builder.get_object("btn-save") btn_save.hide() self.toggled[kit["id"]] = False self.build_grid(child_builder, kit) self.stack.add_titled(child, "first-aid-kit-{0}".format(kit["id"]), kit["name"]) self.children[kit["id"]] = child_builder
def dialog_modify(self, source, data): builder = Gtk.Builder.new_from_file(utils.get_template("location_add.glade")) dialog = builder.get_object("dialog") location_combo = builder.get_object("parent") utils.location_combo( location_combo, locations=self.params.locations, active=data["parent"], empty=True, exclude=[data["id"]] ) name = builder.get_object("name") name.set_text(data["sequence"][-1]) btn_modify = builder.get_object("btn_response") btn_modify.set_label(_("Modify this location")) builder.connect_signals({ "on-response": (self.response_modify, data["id"], dialog, builder), "on-cancel": (utils.dialog_destroy, dialog) }) query_count_all() dialog.set_transient_for(self.window) dialog.run() dialog.destroy()
def dialog_modify(self, source, medicine): builder = Gtk.Builder.new_from_file( utils.get_template("medicine_add.glade")) dialog = builder.get_object("dialog") label = builder.get_object("molecule") label.set_text(medicine["molecule"]["name"]) btn_add = builder.get_object("btn_response") btn_add.set_label(_("Modify the medicine")) location_combo = builder.get_object("location") utils.location_combo(combo=location_combo, locations=self.params.locations, active=medicine["location"]["id"]) # Set the current values name = builder.get_object("name") name.set_text(medicine["name"]) quantity = builder.get_object("quantity") quantity.set_value(medicine["quantity"]) # exp_date = builder.get_object("exp_date") exp_date = builder.get_object("exp_date_raw") exp_date = utils.grid_replace(exp_date, widgets.EntryMasked(mask=DATE_MASK)) builder.expose_object("exp_date", exp_date) date_display = medicine["exp_date"].strftime("%Y-%m-%d") exp_date.get_buffer().set_text(date_display, len(date_display)) if medicine["remark"]: remark = builder.get_object("remark") remark.set_text(medicine["remark"]) if medicine["nc_composition"]: nc_composition = builder.get_object("nc_composition") nc_composition.set_text(medicine["nc_composition"]) if medicine["nc_molecule"]: nc_molecule = builder.get_object("nc_molecule") nc_molecule.set_text(medicine["nc_molecule"]) # If nc_molecule or nc_composition, open the expander if medicine["nc_molecule"] or medicine["nc_composition"]: nc_expander = builder.get_object("nc_expander") nc_expander.set_expanded(True) # Connect signals builder.connect_signals({ "on-response": (self.response_modify, dialog, medicine, builder), "on-cancel": (utils.dialog_destroy, dialog) }) dialog.set_transient_for(self.window) dialog.run() dialog.destroy()
def dialog_modify(self, source, article): builder = Gtk.Builder.new_from_file( utils.get_template("article_add.glade")) dialog = builder.get_object("dialog") label = builder.get_object("equipment") label.set_text(article["equipment"]["name"]) btn_add = builder.get_object("btn_response") btn_add.set_label(_("Modify the article")) location_combo = builder.get_object("location") utils.location_combo(combo=location_combo, locations=self.params.locations, active=article["location"]["id"]) # Set the current values name = builder.get_object("name") name.set_text(article["name"]) quantity = builder.get_object("quantity") quantity.set_value(article["quantity"]) # Expiration date widget custom exp_date = builder.get_object("exp_date_raw") exp_date = utils.grid_replace(exp_date, widgets.EntryMasked(mask=DATE_MASK)) exp_date.connect("activate", self.response_modify, dialog, article, builder) builder.expose_object("exp_date", exp_date) if article["exp_date"]: date_display = article["exp_date"].strftime("%Y-%m-%d") exp_date.get_buffer().set_text(date_display, len(date_display)) if article["remark"]: remark = builder.get_object("remark") remark.set_text(article["remark"]) if article["nc_packaging"]: nc_packaging = builder.get_object("nc_packaging") nc_packaging.set_text(article["nc_packaging"]) nc_expander = builder.get_object("nc_expander") nc_expander.set_expanded(True) # Connect signals builder.connect_signals({ "on-response": (self.response_modify, dialog, article, builder), "on-cancel": (utils.dialog_destroy, dialog), }) dialog.set_transient_for(self.window) dialog.run() dialog.destroy()
def dialog_add(self, source, equipment): builder = Gtk.Builder.new_from_file( utils.get_template("article_add.glade")) dialog = builder.get_object("dialog") label = builder.get_object("equipment") label.set_text("{0} ({1})".format(equipment["name"], equipment["packaging"])) # Check if equipment has previous locations to input the latest one as # default to ease the input active_location = None equipment_obj = models.Equipment.objects.get(id=equipment["id"]) try: latest_article = equipment_obj.articles.latest("exp_date") except models.Article.DoesNotExist: latest_article = None # except ObjectDoesNotExist: # latest_article = None if latest_article: active_location = latest_article.location.id log.debug("Found last location: %s", active_location) location_combo = builder.get_object("location") utils.location_combo(combo=location_combo, locations=self.params.locations, active=active_location) # By default name = equipment name name = builder.get_object("name") name.set_text(equipment["name"]) # Expiry date input mask workaround exp_date = builder.get_object("exp_date_raw") exp_date = utils.grid_replace(exp_date, widgets.EntryMasked(mask=DATE_MASK)) # exp_date.connect("activate", self.response_add, dialog, equipment, builder) builder.expose_object("exp_date", exp_date) # Connect signals # builder.connect_signals({ # "on_entry_activate": (self.response_add, dialog, equipment, builder) # }) builder.connect_signals({ "on-response": (self.response_add, dialog, equipment, builder), "on-cancel": (utils.dialog_destroy, dialog) }) query_count_all() dialog.set_transient_for(self.window) dialog.run() dialog.destroy()
def dialog_add(self, source, molecule): builder = Gtk.Builder.new_from_file( utils.get_template("medicine_add.glade")) dialog = builder.get_object("dialog") label = builder.get_object("molecule") label.set_text("{0} ({1} - {2})".format(molecule["name"], molecule["dosage_form"], molecule["composition"])) # Check if molecule has previous locations to input the latest one as # default to ease the input active_location = None molecule_obj = models.Molecule.objects.get(id=molecule["id"]) try: latest_medicine = molecule_obj.medicines.latest("exp_date") except models.Medicine.DoesNotExist: latest_medicine = None if latest_medicine: active_location = latest_medicine.location.id log.debug("Found last location: %s", active_location) location_combo = builder.get_object("location") utils.location_combo(combo=location_combo, locations=self.params.locations, active=active_location) # By default name = molecule name name = builder.get_object("name") name.set_text(molecule["name"]) # Expiry date input mask workaround exp_date = builder.get_object("exp_date_raw") exp_date = utils.grid_replace(exp_date, widgets.EntryMasked(mask=DATE_MASK)) # exp_date.connect("activate", self.response_add, dialog, molecule, builder) builder.expose_object("exp_date", exp_date) # Connect signals builder.connect_signals({ # "on-entry-activate": (self.response_add, dialog, molecule, builder), "on-response": (self.response_add, dialog, molecule, builder), "on-cancel": (utils.dialog_destroy, dialog) }) query_count_all() dialog.set_transient_for(self.window) dialog.run() dialog.destroy()
def build_bags(self, data, bags): # Get the location_id of all bags to avoid the possibility to select a # bag as a location. exclude_ids = bags.values_list("location_id", flat=True) for bag in bags: # Create a page child_builder = Gtk.Builder.new_from_file( utils.get_template("rescue_bag.glade")) # child = child_builder.get_object("main-box") child = child_builder.get_object("child-scrolled") child_builder.connect_signals({ "btn-save-clicked": (self.save_bag, child_builder, bag), "btn-cancel-clicked": (self.cancel, child_builder), "btn-modify-clicked": (self.enable_modify, child_builder) }) name = child_builder.get_object("name") name.set_text(bag.name) name.set_sensitive(False) location_combo = child_builder.get_object("location") location_combo.set_sensitive(False) utils.location_combo(combo=location_combo, locations=self.params.locations, active=bag.location.parent_id, exclude=exclude_ids) btn_save = child_builder.get_object("btn-save") btn_save.hide() self.toggled[bag.id] = False self.build_grid(child_builder, data, bag) self.stack.add_titled(child, "rescue-bag-{0}".format(bag.id), bag.name) self.children[bag.id] = child_builder
def dialog_add(self, source): log.debug("Add location") builder = Gtk.Builder.new_from_file(utils.get_template("location_add.glade")) dialog = builder.get_object("dialog") location_combo = builder.get_object("parent") utils.location_combo( location_combo, locations=self.params.locations, empty=True ) builder.connect_signals({ "on-response": (self.response_add, dialog, builder), "on-cancel": (utils.dialog_destroy, dialog) }) query_count_all() dialog.set_transient_for(self.window) dialog.run() dialog.destroy()