def toggle_item(self, source, grid, element, row_num, kit_id): # If already toggled, destroy the toggled part if self.toggled[kit_id] and self.toggled[kit_id][0] > 0: # Remove the active-row CSS class of the parent item utils.grid_row_class(grid, self.toggled[kit_id][0] - 1, 5, False) for i in range(self.toggled[kit_id][1] - self.toggled[kit_id][0] + 1): grid.remove_row(self.toggled[kit_id][0]) # No need to recreate the widget, we just want to hide if row_num + 1 == self.toggled[kit_id][0]: self.toggled[kit_id] = False return True # Add the active-row CSS class utils.grid_row_class(grid, row_num, 5) # Need to create the content new_row = row_num + 1 grid.insert_row(new_row) # Header row label = Gtk.Label(_("Commercial Name"), xalign=0) label.set_hexpand(True) label.get_style_context().add_class("article-header-cell") grid.attach(label, 0, 0 + new_row, 1, 1) label = Gtk.Label(_("Remarks"), xalign=0) label.get_style_context().add_class("article-header-cell") grid.attach(label, 1, 0 + new_row, 1, 1) label = Gtk.Label(_("Expiry"), xalign=0.5) label.get_style_context().add_class("article-header-cell") grid.attach(label, 2, 0 + new_row, 1, 1) label = Gtk.Label(_("Quantity"), xalign=0.5) label.get_style_context().add_class("article-header-cell") grid.attach(label, 3, 0 + new_row, 1, 1) label = Gtk.Label(_("Actions"), xalign=1) label.get_style_context().add_class("article-header-cell") grid.attach(label, 4, 0 + new_row, 1, 1) # Get related articles i = new_row for item in element["contents"]: i += 1 grid.insert_row(i) label = Gtk.Label(item["name"], xalign=0) label.set_hexpand(True) label.get_style_context().add_class("article-item-cell-name") label.get_style_context().add_class("article-item-cell") grid.attach(label, 0, i, 1, 1) # Remark field (mainly used for non-compliance) remark_text = [] if item["nc"]: nc_obj = json.loads(item["nc"]) if "packaging" in nc_obj and nc_obj["packaging"]: remark_text.append(NC_TEXT_TEMPLATE.format(_("Non-compliant packaging:"), nc_obj["packaging"])) if "composition" in nc_obj and nc_obj["composition"]: remark_text.append(NC_TEXT_TEMPLATE.format(_("Non-compliant composition:"), nc_obj["composition"])) if "molecule" in nc_obj and nc_obj["molecule"]: remark_text.append(NC_TEXT_TEMPLATE.format(_("Non-compliant molecule:"), nc_obj["molecule"])) if item["remark"]: remark_text.append(item["remark"]) label = Gtk.Label(xalign=0) label.set_markup("\n".join(remark_text)) label.get_style_context().add_class("article-item-cell") label.get_style_context().add_class("article-remark") grid.attach(label, 1, i, 1, 1) if item["exp_date"]: label = Gtk.Label(item["exp_date"].strftime("%Y-%m-%d"), xalign=0.5) label.get_style_context().add_class("text-mono") else: label = Gtk.Label() label.get_style_context().add_class("article-item-cell") # If expiry is soon or due, affect corresponding style if item["expired"]: label.get_style_context().add_class("article-expired") elif item["warning"]: label.get_style_context().add_class("article-warning") grid.attach(label, 2, i, 1, 1) label = Gtk.Label(item["quantity"], xalign=0.5) label.get_style_context().add_class("article-item-cell") label.get_style_context().add_class("text-mono") grid.attach(label, 3, i, 1, 1) # Button box for actions linked_btn = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) linked_btn.get_style_context().add_class("linked") linked_btn.get_style_context().add_class("article-item-buttons") # linked_btn.set_halign(Gtk.Align.END) grid.attach(linked_btn, 4, i, 1, 1) # Use btn_use = widgets.ButtonWithImage("edit-redo-symbolic", tooltip="Use", connect=self.dialog_use, data=item) linked_btn.pack_end(btn_use, False, True, 0) # Modify btn_modify = widgets.ButtonWithImage("document-edit-symbolic", tooltip="Modify", connect=self.dialog_modify, data=(item, element["perishable"])) linked_btn.pack_end(btn_modify, False, True, 0) # Delete btn_delete = widgets.ButtonWithImage("edit-delete-symbolic", tooltip="Delete", connect=self.dialog_delete, data=item) btn_delete.get_style_context().add_class("article-btn-delete") linked_btn.pack_end(btn_delete, False, True, 0) i += 1 grid.insert_row(i) box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) button = Gtk.Button() label = Gtk.Label(_("Add an article"), xalign=0) button.add(label) button.set_relief(Gtk.ReliefStyle.NONE) button.get_style_context().add_class("article-btn-add") button.connect("clicked", self.dialog_add, element) box.add(button) box.get_style_context().add_class("article-item-cell-add") grid.attach(box, 0, i, 1, 1) # Empty row for styling purpose label = Gtk.Label("") label.get_style_context().add_class("article-item-cell-add") grid.attach(label, 1, i, 4, 1) grid.show_all() self.toggled[kit_id] = (new_row, i) query_count_all()
def toggle_article(self, source, grid, equipment, row_num): # If already toggled, destroy the toggled part if self.toggled and self.toggled[0] > 0: # Remove the active-row CSS class of the parent item utils.grid_row_class(grid, self.toggled[0] - 1, 7, False) for i in range(self.toggled[1] - self.toggled[0] + 1): grid.remove_row(self.toggled[0]) # No need to recreate the widget, we just want to hide if row_num + 1 == self.toggled[0]: self.toggled = False return True # Add the active-row CSS class utils.grid_row_class(grid, row_num, 7) # Need to create the content new_row = row_num + 1 grid.insert_row(new_row) # Header row label = Gtk.Label(_("Commercial Name"), xalign=0) label.set_hexpand(True) label.get_style_context().add_class("article-header-cell") grid.attach(label, 0, 0 + new_row, 1, 1) label = Gtk.Label(_("Remarks"), xalign=0) label.get_style_context().add_class("article-header-cell") grid.attach(label, 1, 0 + new_row, 2, 1) label = Gtk.Label(_("Location"), xalign=0) label.get_style_context().add_class("article-header-cell") grid.attach(label, 3, 0 + new_row, 1, 1) label = Gtk.Label(_("Expiry"), xalign=0.5) label.get_style_context().add_class("article-header-cell") grid.attach(label, 4, 0 + new_row, 1, 1) label = Gtk.Label(_("Quantity"), xalign=0.5) label.get_style_context().add_class("article-header-cell") grid.attach(label, 5, 0 + new_row, 1, 1) label = Gtk.Label(_("Actions"), xalign=1) label.get_style_context().add_class("article-header-cell") grid.attach(label, 6, 0 + new_row, 1, 1) # Get related articles articles = equipment["articles"] i = new_row for article in articles: i += 1 grid.insert_row(i) label = Gtk.Label(article["name"], xalign=0) label.set_hexpand(True) label.get_style_context().add_class("article-item-cell-name") label.get_style_context().add_class("article-item-cell") grid.attach(label, 0, i, 1, 1) # Remark field (mainly used for non-compliance) remark_text = [] if article["nc_packaging"]: remark_text.append( NC_TEXT_TEMPLATE.format(_("Non-compliant packaging:"), article["nc_packaging"])) if article["remark"]: remark_text.append(article["remark"]) label = Gtk.Label(xalign=0) label.set_markup("\n".join(remark_text)) label.get_style_context().add_class("article-item-cell") label.get_style_context().add_class("article-remark") grid.attach(label, 1, i, 2, 1) label = Gtk.Label(xalign=0) label.get_style_context().add_class("article-item-cell") sequence = article["location"]["sequence"] if len(sequence) > 1: parents = " > ".join(sequence[:-1]) location_display = "<span foreground=\"#555\">{0} > </span>{1}".format( parents, sequence[-1]) else: location_display = sequence[0] label.set_markup(location_display) label.set_line_wrap(True) label.set_lines(1) label.set_line_wrap_mode(2) grid.attach(label, 3, i, 1, 1) if article["exp_date"]: label = Gtk.Label(article["exp_date"].strftime("%Y-%m-%d"), xalign=0.5) label.get_style_context().add_class("text-mono") else: label = Gtk.Label() label.get_style_context().add_class("article-item-cell") # If expiry is soon or due, affect corresponding style if article["expired"]: label.get_style_context().add_class("article-expired") elif article["warning"]: label.get_style_context().add_class("article-warning") grid.attach(label, 4, i, 1, 1) label = Gtk.Label(article["quantity"], xalign=0.5) label.get_style_context().add_class("article-item-cell") label.get_style_context().add_class("text-mono") grid.attach(label, 5, i, 1, 1) # Button box for actions linked_btn = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) linked_btn.get_style_context().add_class("linked") linked_btn.get_style_context().add_class("article-item-buttons") # linked_btn.set_halign(Gtk.Align.END) grid.attach(linked_btn, 6, i, 1, 1) # Use if equipment["consumable"]: btn_use = widgets.ButtonWithImage("edit-redo-symbolic", tooltip=_("Use"), connect=self.dialog_use, data=article) linked_btn.pack_end(btn_use, False, True, 0) # Modify btn_modify = widgets.ButtonWithImage("document-edit-symbolic", tooltip=_("Modify"), connect=self.dialog_modify, data=article) linked_btn.pack_end(btn_modify, False, True, 0) # Delete btn_delete = widgets.ButtonWithImage("edit-delete-symbolic", tooltip=_("Delete"), connect=self.dialog_delete, data=article) btn_delete.get_style_context().add_class("article-btn-delete") linked_btn.pack_end(btn_delete, False, True, 0) i += 1 grid.insert_row(i) box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) button = Gtk.Button() label = Gtk.Label(_("Add an article"), xalign=0) button.add(label) button.set_relief(Gtk.ReliefStyle.NONE) button.get_style_context().add_class("article-btn-add") button.connect("clicked", self.dialog_add, equipment) box.add(button) box.get_style_context().add_class("article-item-cell-add") grid.attach(box, 0, i, 1, 1) # Empty row for styling purpose label = Gtk.Label("") label.get_style_context().add_class("article-item-cell-add") grid.attach(label, 1, i, 6, 1) grid.show_all() self.toggled = (new_row, i) query_count_all()
def toggle_item(self, source, grid, element, row_num, bag_id=0): # If already toggled, destroy the toggled part if self.toggled[bag_id] and self.toggled[bag_id][0] > 0: # Remove the active-row CSS class of the parent item utils.grid_row_class(grid, self.toggled[bag_id][0] - 1, 5, False) for i in range(self.toggled[bag_id][1] - self.toggled[bag_id][0] + 1): grid.remove_row(self.toggled[bag_id][0]) # No need to recreate the widget, we just want to hide if row_num + 1 == self.toggled[bag_id][0]: self.toggled[bag_id] = False return True # Add the active-row CSS class utils.grid_row_class(grid, row_num, 5) # Need to create the content new_row = row_num + 1 grid.insert_row(new_row) # Header row label = Gtk.Label(_("Commercial Name"), xalign=0) label.set_hexpand(True) label.get_style_context().add_class("article-header-cell") grid.attach(label, 0, 0 + new_row, 1, 1) label = Gtk.Label(_("Remarks"), xalign=0) label.get_style_context().add_class("article-header-cell") grid.attach(label, 1, 0 + new_row, 1, 1) label = Gtk.Label(_("Expiry"), xalign=0.5) label.get_style_context().add_class("article-header-cell") grid.attach(label, 2, 0 + new_row, 1, 1) label = Gtk.Label(_("Quantity"), xalign=0.5) label.get_style_context().add_class("article-header-cell") grid.attach(label, 3, 0 + new_row, 1, 1) label = Gtk.Label("", xalign=1) label.get_style_context().add_class("article-header-cell") grid.attach(label, 4, 0 + new_row, 1, 1) # Get related articles i = new_row for item in element["contents"]: i += 1 grid.insert_row(i) label = Gtk.Label(item["name"], xalign=0) label.set_hexpand(True) label.get_style_context().add_class("article-item-cell-name") label.get_style_context().add_class("article-item-cell") grid.attach(label, 0, i, 1, 1) # Remark field (mainly used for non-compliance) remark_text = [] if "packaging" in item["nc"] and item["nc"]["packaging"]: remark_text.append( NC_TEXT_TEMPLATE.format(_("Non-compliant packaging:"), item["nc"]["packaging"])) if "composition" in item["nc"] and item["nc"]["composition"]: remark_text.append( NC_TEXT_TEMPLATE.format(_("Non-compliant composition:"), item["nc"]["composition"])) if "molecule" in item["nc"] and item["nc"]["molecule"]: remark_text.append( NC_TEXT_TEMPLATE.format(_("Non-compliant molecule:"), item["nc"]["molecule"])) if item["remark"]: remark_text.append(item["remark"]) label = Gtk.Label(xalign=0) label.set_markup("\n".join(remark_text)) label.get_style_context().add_class("article-item-cell") label.get_style_context().add_class("article-remark") grid.attach(label, 1, i, 1, 1) if item["exp_date"]: label = Gtk.Label(item["exp_date"].strftime("%Y-%m-%d"), xalign=0.5) label.get_style_context().add_class("text-mono") else: label = Gtk.Label() label.get_style_context().add_class("article-item-cell") # If expiry is soon or due, affect corresponding style if item["expired"]: label.get_style_context().add_class("article-expired") elif item["warning"]: label.get_style_context().add_class("article-warning") grid.attach(label, 2, i, 1, 1) label = Gtk.Label(item["quantity"], xalign=0.5) label.get_style_context().add_class("article-item-cell") label.get_style_context().add_class("text-mono") grid.attach(label, 3, i, 1, 1) label = Gtk.Label("", xalign=1) label.get_style_context().add_class("article-item-cell") grid.attach(label, 4, i, 1, 1) i += 1 grid.insert_row(i) box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) button = Gtk.Button() button.set_relief(Gtk.ReliefStyle.NONE) button.get_style_context().add_class("article-btn-add") if element["type"] == "molecule": button.set_action_name("app.medicines") button.set_action_target_value(GLib.Variant("i", element["id"])) label = Gtk.Label(_("Update in the medicine view"), xalign=0) elif element["type"] == "equipment": button.set_action_name("app.equipment") button.set_action_target_value(GLib.Variant("i", element["id"])) label = Gtk.Label(_("Update in the equipment view"), xalign=0) else: label = Gtk.Label(_("Edit this item in the dedicated view"), xalign=0) button.add(label) box.add(button) box.get_style_context().add_class("article-item-cell-add") grid.attach(box, 0, i, 1, 1) # Empty row for styling purpose label = Gtk.Label("") label.get_style_context().add_class("article-item-cell-add") grid.attach(label, 1, i, 4, 1) grid.show_all() self.toggled[bag_id] = (new_row, i) # log.info("Size %s, %s", linked_btn.get_preferred_size().minimum_size.width, linked_btn.get_preferred_size().natural_size.width) query_count_all()