Native gui usable for data editing. Lots of fixes and improvenemts

This commit is contained in:
thooge committed 2026-11-11 18:58:02 +01:00
1 parent a6abdaa614
commit 09387280fc
52 files changed
+1579 -294

No files matched your search

+62 -6
View File
@@ -41,6 +41,25 @@ class CablesView(View):
self.dd_condition = self.context.lookup.enum('cable.cablecond')
combobox.load_from_dict(self.combo['condition'], self.dd_condition, 'unknown')
# subscribe to data change events
#self.context.subscribe("dd_type_modified", self.type_modified)
#self.context.subscribe("dd_techname_modified", self.techname_modified)
def get_list_row(self):
return (
self.cable.cableid,
self.cable.cablename,
self.dd_condition.get(self.cable.cablecond, ''),
self.format_float(self.cable.length, suffix="m")
)
def add_row(self):
treeiter = self.lst_cables.append(self.get_list_row())
self.tree['cables'].get_selection().select_iter(treeiter)
def refresh_row(self):
treeview.set_row_values(self.tree['cables'], self.get_list_row())
def load_list(self):
selected_id = treeview.get_value(self.tree['cables'])
self.lst_cables.clear()
@@ -64,6 +83,34 @@ class CablesView(View):
# restore previous selected row
selection.select_iter(treeiter)
def type_modified(self, eventtype, data):
self.dd_type[data[0]] = data[1]
lst = self.combo['type'].get_model()
if eventtype == self.context.EVENT_UPD:
for row in lst:
if row[0] == data[0]:
row[1] = data[1]
return
elif eventtype == self.context.EVENT_ADD:
lst.append(data)
else:
# not implemented
pass
def techname_modified(self, eventtype, data):
self.dd_techname[data[0]] = data[1]
lst = self.combo['techname'].get_model()
if eventtype == self.context.EVENT_UPD:
for row in lst:
if row[0] == data[0]:
row[1] = data[1]
return
elif eventtype == self.context.EVENT_ADD:
lst.append(data)
else:
# not implemented
pass
def display_record(self):
self.label['name'].set_text(self.cable.cablename or '')
if self.cable.cabletype:
@@ -74,11 +121,11 @@ class CablesView(View):
self.label['techname'].set_text(self.dd_tech[self.cable.techname])
else:
self.label['techname'].set_text('')
self.label['length'].set_text(self.format_int(self.cable.length))
self.label['length'].set_text(self.format_float(self.cable.length, suffix="m"))
self.label['conductors'].set_text(self.format_int(self.cable.conductors))
self.label['diameter'].set_text(self.format_float(self.cable.diameter, 1))
self.label['xsection'].set_text(self.format_float(self.cable.xsection, 1))
self.label['weight'].set_text(self.format_float(self.cable.weight))
self.label['diameter'].set_text(self.format_float(self.cable.diameter, 1, suffix="mm"))
self.label['xsection'].set_text(self.format_float(self.cable.xsection, 1, suffix="mm²"))
self.label['weight'].set_text(self.format_float(self.cable.weight, suffix="kg/m"))
if self.cable.color:
self.label['color'].set_markup(f'#{self.cable.color} <span foreground="#{self.cable.color}">●</span>')
else:
@@ -219,8 +266,17 @@ class CablesView(View):
return
self.record_unlock()
if self.newrecord:
self.load_list()
self.newrecord = False
#self.load_list()
self.add_row()
self.context.publish("cable_modified", self.context.EVENT_ADD,
(self.cable.pk_value, self.cable.cablename)
)
else:
self.refresh_row()
self.context.publish("cable_modified", self.context.EVENT_UPD,
(self.cable.pk_value, self.cable.cablename)
)
self.newrecord = False
self.display_record()
self.topwidget.set_visible_child(self.box['cable_detail'])