Work on native gui: list views for objects; set version to 0.2.2

This commit is contained in:
2026-09-21 19:07:59 +02:00
parent d61faf2e71
commit 0adb07d75b
34 changed files with 3199 additions and 1133 deletions
+65 -16
View File
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: WTFPL
import os
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import GLib, Gtk, Gdk
from .view import View
@@ -15,19 +13,13 @@ class StorageView(View):
def __init__(self, context):
super().__init__(context, _("Storage"), "storage.ui")
self.context = context
self.storage = storage.Storage(context.db) # current record
self.newrecord = False
self.lst_storage = Gtk.ListStore(int, str, str, str)
sql = (
"SELECT sid, sname, CONCAT(x, ',', y, ',', z) AS position, remarks "
"FROM storage "
"WHERE vid=%s "
"ORDER BY sname"
)
self.db.cur.execute(sql, (context.vessel.vid,))
for row in self.db.cur.fetchall():
self.lst_storage.append(row)
self.load_list()
treeview.add_column(self.tree['storage'], _('ID'), 0)
treeview.add_column(self.tree['storage'], _('Name'), 1)
@@ -35,18 +27,34 @@ class StorageView(View):
treeview.add_column(self.tree['storage'], _('Remarks'), 3)
self.tree['storage'].set_model(self.lst_storage)
combodict = self.context.lookup.dropdown(Dropdown.STORAGE_TYPE)
combobox.load_from_dict(self.combo['type'], combodict)
#combodict = self.context.lookup.dropdown(Dropdown.STORAGE_TYPE)
#combobox.load_from_dict(self.combo['type'], combodict)
combodict = self.context.lookup.dropdown(Dropdown.STORAGE_TYPE)
print(combodict)
combobox.load_from_dict(self.combo['type'], combodict)
combodict = self.context.lookup.enum('storage.capaunit')
combobox.load_from_dict(self.combo['unit'], combodict)
def load_list(self):
def add_row(self):
pass
def refresh_row(self):
pass
def load_list(self):
self.lst_storage.clear()
sql = (
"SELECT sid, sname, CONCAT(x, ',', y, ',', z) AS position, remarks "
"FROM storage "
"WHERE vid=%s "
"ORDER BY sname"
)
self.db.cur.execute(sql, (self.context.vessel.vid,))
for row in self.db.cur.fetchall():
self.lst_storage.append(row)
def display_record(self):
self.label['name'].set_text(self.storage.sname)
self.label['remarks'].set_text(self.storage.remarks or '')
@@ -56,12 +64,36 @@ class StorageView(View):
self.spin['x'].set_value(self.storage.x)
self.spin['y'].set_value(self.storage.y)
self.spin['z'].set_value(self.storage.z)
self.spin['wx'].set_value(self.storage.wx)
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)
combobox.activate_row(self.combo['type'], self.storage.stype)
combobox.activate_row(self.combo['unit'], self.storage.capaunit)
self.text['remarks'].get_buffer().set_text(self.storage.remarks or '')
def clear_record(self):
self.storage.clear()
self.entry['sname'].set_text('')
self.spin['x'].set_value(0)
self.spin['y'].set_value(0)
self.spin['z'].set_value(0)
self.spin['wx'].set_value(0)
self.spin['wy'].set_value(0)
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)
self.text['remarks'].get_buffer().set_text('')
# 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.storage.vid = self.context.vessel.vid
self.topwidget.set_visible_child(self.box['stor_edit'])
def on_but_edit_clicked(self, widget):
@@ -91,12 +123,29 @@ class StorageView(View):
# buttons on edit page
def on_but_save_clicked(self, widget):
self.newrecord = False
# check mandatory fields
sname = self.entry['sname'].get_text().strip()
if not sname:
# TODO error marker
return
# here be dragons
# 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.storage.save()
if self.newrecord:
self.load_list()
self.newrecord = False
self.topwidget.set_visible_child(self.box['storage'])
def on_but_cancel_clicked(self, widget):
self.topwidget.set_visible_child(self.box['storage'])