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 dialog_modify(self, source, data): item = data[0] perishable = data[1] builder = Gtk.Builder.new_from_file(utils.get_template("subitem_modify.glade")) dialog = builder.get_object("dialog") name = builder.get_object("name") name.set_text(item["name"]) quantity = builder.get_object("quantity") quantity.set_value(item["quantity"]) 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, item, perishable, builder) builder.expose_object("exp_date", exp_date) date_display = item["exp_date"].strftime("%Y-%m-%d") exp_date.get_buffer().set_text(date_display, len(date_display)) if item["remark"]: remark = builder.get_object("remark") remark.set_text(item["remark"]) if item["nc"]: remark = builder.get_object("nc") remark.set_text(item["nc"]) builder.connect_signals({ "on-response": (self.response_modify, dialog, item, perishable, builder), "on-cancel": (utils.dialog_destroy, dialog) }) dialog.set_transient_for(self.window) dialog.run() dialog.destroy()