Native gui first steps: storage, box and companies are editable

This commit is contained in:
thooge committed 2026-10-21 17:16:55 +02:00
1 parent 1eea4058bf
commit 06a9834688
47 files changed
+3119 -883

No files matched your search

+75 -28
View File
@@ -17,6 +17,8 @@ class StorageView(View):
self.storage = storage.Storage(context.db) # current record
self.newrecord = False
self.last_valid_rgb = "#3498DB"
self.lst_storage = Gtk.ListStore(int, str, str, str)
self.load_list()
@@ -27,29 +29,39 @@ class StorageView(View):
self.tree['storage'].set_model(self.lst_storage)
self.dd_stype = self.context.lookup.dropdown(Dropdown.STORAGE_TYPE)
combobox.load_from_dict(self.combo['type'], self.dd_stype)
combobox.load_from_dict(self.combo['type'], self.dd_stype, storage.GENERIC)
self.dd_unit = self.context.lookup.enum('storage.capaunit')
combobox.load_from_dict(self.combo['unit'], self.dd_unit)
combobox.load_from_dict(self.combo['unit'], {"-1": _("─── none ───")} | self.dd_unit)
def add_row(self):
pass
def refresh_row(self):
pass
treeview.set_value(self.tree['storage'], 1, self.storage.name)
position = f"({self.storage.x}, {self.storage.y}, {self.storage.z})"
treeview.set_value(self.tree['storage'], 2, position)
treeview.set_value(self.tree['storage'], 3, self.storage.remarks)
def load_list(self):
selected_id = treeview.get_value(self.tree['storage'])
self.lst_storage.clear()
sql = (
"SELECT sid, sname, CONCAT(x, ',', y, ',', z) AS position, remarks "
"SELECT sid, sname, CONCAT(x, ',', y, ',', z) AS position, "
" IF(CHAR_LENGTH(remarks)>40, CONCAT(LEFT(remarks, 40), '\u2026'), remarks) AS remarks "
"FROM storage "
"WHERE vid=%s "
"ORDER BY sname"
)
self.db.cur.execute(sql, (self.context.vessel.vid,))
selection = self.tree['storage'].get_selection()
for row in self.db.cur.fetchall():
self.lst_storage.append(row)
treeiter = self.lst_storage.append(row)
if row[0] == selected_id:
# restore previous selected row
selection.select_iter(treeiter)
def clear_record(self):
self.storage.clear()
self.entry['sname'].set_text('')
@@ -61,8 +73,8 @@ class StorageView(View):
self.spin['wz'].set_value(0)
self.spin['angle'].set_value(0)
self.spin['capacity'].set_value(0)
combobox.activate_row(self.combo['type'], -1)
combobox.activate_row(self.combo['unit'], -1)
combobox.activate_row(self.combo['type'], storage.GENERIC)
combobox.activate_row(self.combo['unit'], "-1")
self.text['remarks'].get_buffer().set_text('')
def display_record(self):
@@ -79,6 +91,7 @@ class StorageView(View):
self.label['remarks'].set_text(self.storage.remarks or '')
def edit_record(self):
self.last_valid_rgb = self.storage.color
self.entry['sname'].set_text(self.storage.sname)
self.spin['x'].set_value(self.storage.x)
self.spin['y'].set_value(self.storage.y)
@@ -87,17 +100,38 @@ class StorageView(View):
self.spin['wy'].set_value(self.storage.wy)
self.spin['wz'].set_value(self.storage.wz)
self.spin['angle'].set_value(self.storage.angle)
self.spin['capacity'].set_value(self.storage.capacity)
self.spin['capacity'].set_value(self.storage.capacity or 0)
combobox.activate_row(self.combo['type'], self.storage.stype)
combobox.activate_row(self.combo['unit'], self.storage.capaunit)
# flags
combobox.activate_row(self.combo['unit'], self.storage.capaunit or -1)
self.entry['color'].set_text('#' + (self.storage.color or '000000'))
rgba = Gdk.RGBA()
rgba.parse('#' + (self.storage.color or '000000'))
self.button['color'].set_rgba(rgba)
self.text['remarks'].get_buffer().set_text(self.storage.remarks or '')
def save_record(self):
# fields must have been validated beforehand
self.storage.sname = self.entry['sname'].get_text()
self.storage.stype = combobox.get_list_value(self.combo['type'])
self.storage.x = self.spin['x'].get_value_as_int()
self.storage.y = self.spin['y'].get_value_as_int()
self.storage.z = self.spin['z'].get_value_as_int()
self.storage.wx = self.spin['wx'].get_value_as_int()
self.storage.wy = self.spin['wy'].get_value_as_int()
self.storage.wz = self.spin['wz'].get_value_as_int()
self.storage.angle = self.spin['angle'].get_value_as_int()
self.storage.capacity = self.spin['capacity'].get_value_as_int()
self.storage.capaunit = combobox.get_list_value(self.combo['unit'])
if self.storage.capaunit == '-1':
self.storage.capaunit = None
self.storage.color = self.entry['color'].get_text().lstrip('#')
self.storage.remarks = gtkutils.get_text_contents(self.text['remarks'])
# buttons on list page
def on_but_new_clicked(self, widget):
self.newrecord = True
self.label['title_edit'].set_text("Add new Storage")
self.clear_record()
self.label['title_edit'].set_text(_("Add new Storage"))
self.storage.vid = self.context.vessel.vid
self.topwidget.set_visible_child(self.box['stor_edit'])
@@ -106,7 +140,7 @@ class StorageView(View):
if sid is None:
return
self.newrecord = False
self.label['title_edit'].set_text("Edit Storage")
self.label['title_edit'].set_text(_("Edit Storage"))
self.storage.load(sid)
self.edit_record()
self.topwidget.set_visible_child(self.box['stor_edit'])
@@ -133,34 +167,47 @@ class StorageView(View):
self.topwidget.set_visible_child(self.box['storage'])
def on_but_delete_clicked(self, widget):
answer = gtkutils.questionbox(
_("Delete storage!\n"
"Are you sure?"), title="YMS"
)
if answer == False:
return
self.topwidget.set_visible_child(self.box['storage'])
self.newrecord = False
# buttons on edit page
def on_but_save_clicked(self, widget):
# check mandatory fields
sname = self.entry['sname'].get_text().strip()
if not sname:
if not self.entry['sname'].get_text().strip():
# TODO error marker
return
# get fields from ui form
self.storage.sname = sname
self.storage.stype = combobox.get_list_value(self.combo['type'])
self.storage.x = self.spin['x'].get_value()
self.storage.y = self.spin['y'].get_value()
self.storage.z = self.spin['z'].get_value()
self.storage.wx = self.spin['wx'].get_value()
self.storage.wy = self.spin['wy'].get_value()
self.storage.wz = self.spin['wz'].get_value()
self.storage.angle = self.spin['angle'].get_value()
self.storage.capacity = self.spin['capacity'].get_value()
self.storage.capaunit = combobox.get_list_value(self.combo['unit'])
self.storage.remarks = gtkutils.get_text_contents(self.text['remarks'])
self.save_record()
print(self.storage)
self.storage.save()
if self.newrecord:
self.load_list()
else:
pass
# TODO aktuelle Listenzeile aktualisieren!
self.newrecord = False
self.topwidget.set_visible_child(self.box['storage'])
self.display_record()
self.topwidget.set_visible_child(self.box['stor_detail'])
def on_but_color_set(self, button):
rgba = button.get_rgba()
r = round(rgba.red * 255)
g = round(rgba.green * 255)
b = round(rgba.blue * 255)
self.last_valid_rgb = f"{r:02X}{g:02X}{b:02X}"
self.entry['color'].set_text(f"#{r:02X}{g:02X}{b:02X}")
def on_ent_color_activate(self, entry):
self.set_color_from_entry(entry)
def on_ent_color_focus_out_event(self, entry, event):
self.set_color_from_entry(entry)
return False
def on_but_cancel_clicked(self, widget):
self.topwidget.set_visible_child(self.box['storage'])