More work on native gui. Make data editable.

This commit is contained in:
thooge committed 2026-10-29 18:59:21 +01:00
1 parent 5641e1706f
commit 7aa5d2af3b
43 files changed
+2686 -1037

No files matched your search

+40 -16
View File
@@ -17,13 +17,38 @@ class CablesView(View):
self.newrecord = False
self.lst_cables = Gtk.ListStore(int, str, str)
self.load_list()
treeview.add_column(self.tree['cables'], _('ID'), 0)
treeview.add_column(self.tree['cables'], _('Name'), 1)
treeview.add_column(self.tree['cables'], _('Condition'), 2)
self.tree['cables'].set_model(self.lst_cables)
# Cable type
self.dd_type = self.context.lookup.dropdown(Dropdown.CABLE_TYPE)
combobox.load_from_dict(self.combo['type'], {-1: _("─── none ───")} | self.dd_type)
# Cable tech type
self.dd_tech = self.context.lookup.dropdown(Dropdown.CABLE_TECHNAME)
combobox.load_from_dict(self.combo['techname'], {-1: _("─── none ───")} | self.dd_tech)
# Supplier
self.dd_supplier = self.context.lookup.company(1)
combobox.load_from_dict(self.combo['supplier'], {-1: _("─── none ───")} | self.dd_supplier)
# Manufacturer
self.dd_manufacturer = self.context.lookup.company(2)
combobox.load_from_dict(self.combo['manufacturer'], {-1: _("─── none ───")} | self.dd_manufacturer)
# Condition
self.dd_condition = self.context.lookup.enum('cable.cablecond')
combobox.load_from_dict(self.combo['condition'], self.dd_condition, 'unknown')
def load_list(self):
self.lst_cables.clear()
sql = (
"SELECT cableid, cablename, cablecond "
"FROM cable "
"WHERE vid=%s "
"ORDER BY cableid"
)
self.db.dcur.execute(sql, (context.vessel.vid,))
self.db.dcur.execute(sql, (self.context.vessel.vid,))
for row in self.db.dcur.fetchall():
data = (
row['cableid'],
@@ -32,17 +57,12 @@ class CablesView(View):
)
self.lst_cables.append(data)
treeview.add_column(self.tree['cables'], _('ID'), 0)
treeview.add_column(self.tree['cables'], _('Name'), 1)
treeview.add_column(self.tree['cables'], _('Condition'), 2)
self.tree['cables'].set_model(self.lst_cables)
self.dd_type = self.context.lookup.dropdown(Dropdown.CABLE_TYPE)
self.dd_tech = self.context.lookup.dropdown(Dropdown.CABLE_TECHNAME)
def display_record(self):
self.label['name'].set_text(self.cable.cablename)
self.label['type'].set_text(self.dd_type[self.cable.cabletype])
self.label['name'].set_text(self.cable.cablename or '')
if self.cable.cabletype:
self.label['type'].set_text(self.dd_type[self.cable.cabletype])
else:
self.label['type'].set_text('')
if self.cable.techname:
self.label['techname'].set_text(self.dd_tech[self.cable.techname])
else:
@@ -64,8 +84,8 @@ class CablesView(View):
def edit_record(self):
# fill UI fields from database record
self.entry['name'].set_text(self.cable.cablename)
combobox.activate_row(self.combo['type'], self.cable.cabletype)
combobox.activate_row(self.combo['techname'], self.cable.techname)
combobox.activate_row(self.combo['type'], self.cable.cabletype or -1)
combobox.activate_row(self.combo['techname'], self.cable.techname or -1)
self.spin['length'].set_value(self.cable.length or 0)
self.spin['consuctors'].set_value(self.cable.conductors or 0)
self.spin['diameter'].set_value(self.cable.diameter or 0)
@@ -75,10 +95,11 @@ class CablesView(View):
rgba = Gdk.RGBA()
rgba.parse('#' + self.cable.color)
self.button['color'].set_rgba(rgba)
combobox.activate_row(self.combo['supplier'], self.cable.supplier)
combobox.activate_row(self.combo['manufacturer'], self.cable.manufacturer)
combobox.activate_row(self.combo['consition'], self.cable.cablecond)
combobox.activate_row(self.combo['supplier'], self.cable.supplier or -1)
combobox.activate_row(self.combo['manufacturer'], self.cable.manufacturer or -1)
combobox.activate_row(self.combo['consition'], self.cable.cablecond or 'unknown')
self.text['remarks'].get_buffer().set_text(self.sbox.remarks or '')
self.entry['name'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
@@ -95,6 +116,9 @@ class CablesView(View):
# buttons on list page
def on_but_new_clicked(self, widget):
self.newrecord = True
self.cable.clear()
self.edit_record()
self.topwidget.set_visible_child(self.box['cable_edit'])
def on_but_edit_clicked(self, widget):