Native gui usable for data editing. Lots of fixes and improvenemts
This commit is contained in:
1 parent
a6abdaa614
commit
09387280fc
52 files changed
+1579
-294
No files matched your search
+91
-6
@@ -38,6 +38,27 @@ class FusesView(View):
|
||||
self.dd_location = self.context.lookup.dropdown(Dropdown.FUSE_BLOCK)
|
||||
combobox.load_from_dict(self.combo['location'], {-1: _("─── unknown ───")} | self.dd_location)
|
||||
|
||||
# subscribe to data change events
|
||||
self.context.subscribe("equipment_modified", self.equipment_modified)
|
||||
self.context.subscribe("cable_modified", self.cable_modified)
|
||||
self.context.subscribe("dd_ftype_modified", self.ftype_modified)
|
||||
self.context.subscribe("dd_location_modified", self.location_modified)
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.fuse.fuseid,
|
||||
'F{}'.format(self.fuse.fnumber),
|
||||
self.format_float(self.fuse.current, 1, suffix="A"),
|
||||
self.fuse.description
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_fuses.append(self.get_list_row())
|
||||
self.tree['fuses'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['fuses'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['fuses'])
|
||||
self.lst_fuses.clear()
|
||||
@@ -61,6 +82,62 @@ class FusesView(View):
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def equipment_modified(self, eventtype, data):
|
||||
self.dd_equipment[data[0]] = data[1]
|
||||
lst = self.combo['equipment'].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 cable_modified(self, eventtype, data):
|
||||
self.dd_cable[data[0]] = data[1]
|
||||
lst = self.combo['cable'].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 ftype_modified(self, eventtype, data):
|
||||
self.dd_ftype[data[0]] = data[1]
|
||||
lst = self.combo['ftype'].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 location_modified(self, eventtype, data):
|
||||
self.dd_location[data[0]] = data[1]
|
||||
lst = self.combo['location'].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 clear_record(self):
|
||||
self.fuse.clear()
|
||||
self.spin['fnumber'].set_value(0)
|
||||
@@ -79,7 +156,7 @@ class FusesView(View):
|
||||
self.label['type'].set_text(self.dd_ftype[self.fuse.ftype] or '')
|
||||
else:
|
||||
self.label['type'].set_text('')
|
||||
self.label['current'].set_text(self.format_float(self.fuse.current, 2, suffix="A"))
|
||||
self.label['current'].set_text(self.format_float(self.fuse.current, 1, suffix="A"))
|
||||
if self.fuse.cableid:
|
||||
self.label['cable'].set_text(self.dd_cable[self.fuse.cableid])
|
||||
else:
|
||||
@@ -160,11 +237,11 @@ class FusesView(View):
|
||||
self.topwidget.set_visible_child(self.box['fuse_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
fuseid = treeview.get_value(self.tree['fuses'], 0)
|
||||
if fuseid is None:
|
||||
return
|
||||
self.label['title_edit'].set_text(_("Edit Fuse"))
|
||||
self.newrecord = False
|
||||
fuseid = treeview.get_value(self.tree['fuses'], 0)
|
||||
if not self.record_lock('fuse', fuseid):
|
||||
return
|
||||
self.fuse.load(fuseid)
|
||||
@@ -205,20 +282,28 @@ class FusesView(View):
|
||||
def on_but_save_clicked(self, widget):
|
||||
fnumber = self.spin['fnumber'].get_value_as_int()
|
||||
current = self.spin['current'].get_value()
|
||||
# TODO check for duplicate number!
|
||||
sql = "SELECT COUNT(fnumber) FROM fuse WHERE fnumber=%s"
|
||||
|
||||
if (fnumber == 0) or (current == 0):
|
||||
# TODO error marker
|
||||
return
|
||||
if self.newrecord:
|
||||
# TODO check for duplicate number!
|
||||
sql = "SELECT COUNT(fnumber) FROM fuse WHERE fnumber=%s"
|
||||
self.context.db.cur.execute(sql, (fnumber,))
|
||||
if self.context.db.cur.fetchone()[0] > 0:
|
||||
# Duplicate fuse number
|
||||
print("duplicate fuse number")
|
||||
return
|
||||
self.save_record()
|
||||
print(self.fuse)
|
||||
if not self.fuse.save():
|
||||
pass
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
#self.load_list()
|
||||
self.add_row()
|
||||
self.newrecord = False
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['fuse_detail'])
|
||||
|
||||
|
||||
Reference in new issue
Block a user