Native gui make almost every data editable
This commit is contained in:
1 parent
b8ac8d0185
commit
1a6674c819
48 files changed
+2168
-737
No files matched your search
+98
-26
@@ -17,21 +17,7 @@ class FusesView(View):
|
||||
self.newrecord = False
|
||||
|
||||
self.lst_fuses = Gtk.ListStore(int, str, str, str)
|
||||
sql = (
|
||||
"SELECT fuseid, fnumber, current, description "
|
||||
"FROM fuse "
|
||||
"WHERE vid=%s "
|
||||
"ORDER BY fuseid"
|
||||
)
|
||||
self.db.dcur.execute(sql, (context.vessel.vid,))
|
||||
for row in self.db.dcur.fetchall():
|
||||
data = (
|
||||
row['fuseid'],
|
||||
'F{}'.format(row['fnumber']),
|
||||
'{} A'.format(row['current']), # TODO better formatting
|
||||
row['description']
|
||||
)
|
||||
self.lst_fuses.append(data)
|
||||
self.load_list()
|
||||
|
||||
treeview.add_column(self.tree['fuses'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['fuses'], _('Name'), 1)
|
||||
@@ -41,13 +27,39 @@ class FusesView(View):
|
||||
|
||||
# Fuse Type
|
||||
self.dd_ftype = self.context.lookup.dropdown(Dropdown.FUSE_TYPE)
|
||||
combobox.load_from_dict(self.combo['ftype'], self.dd_ftype)
|
||||
combobox.load_from_dict(self.combo['ftype'], {-1: _("─── unknown ───")} | self.dd_ftype)
|
||||
# Cables
|
||||
self.dd_cable = self.context.lookup.cable(context.vessel.vid)
|
||||
combobox.load_from_dict(self.combo['cable'], {-1: _("─── none ───")} | self.dd_cable)
|
||||
# Equipment
|
||||
self.dd_equipment = self.context.lookup.equipment(context.vessel.vid)
|
||||
combobox.load_from_dict(self.combo['equipment'], {-1: _("─── none ───")} | self.dd_equipment)
|
||||
# Location
|
||||
self.dd_location = self.context.lookup.dropdown(Dropdown.FUSE_BLOCK)
|
||||
combobox.load_from_dict(self.combo['location'], {-1: _("─── unknown ───")} | self.dd_location)
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['fuses'])
|
||||
self.lst_fuses.clear()
|
||||
sql = (
|
||||
"SELECT fuseid, fnumber, current, description "
|
||||
"FROM fuse "
|
||||
"WHERE vid=%s "
|
||||
"ORDER BY fuseid"
|
||||
)
|
||||
self.db.dcur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['fuses'].get_selection()
|
||||
for row in self.db.dcur.fetchall():
|
||||
data = (
|
||||
row['fuseid'],
|
||||
'F{}'.format(row['fnumber']),
|
||||
'{} A'.format(row['current']), # TODO better formatting
|
||||
row['description']
|
||||
)
|
||||
treeiter = self.lst_fuses.append(data)
|
||||
if row['fuseid'] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.fuse.clear()
|
||||
@@ -57,18 +69,34 @@ class FusesView(View):
|
||||
self.spin['current'].set_value(0)
|
||||
combobox.activate_row(self.combo['cable'], -1)
|
||||
combobox.activate_row(self.combo['equipment'], -1)
|
||||
self.entry['location'].set_text('')
|
||||
combobox.activate_row(self.combo['location'], -1)
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
self.spin['fnumber'].grab_focus()
|
||||
|
||||
def display_record(self):
|
||||
self.label['fnumber'].set_text(f"F{self.fuse.fnumber}")
|
||||
self.label['type'].set_text(self.dd_type[self.fuse.ftype])
|
||||
if self.fuse.ftype:
|
||||
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['cable'].set_text(str(self.fuse.cableid))
|
||||
self.label['equipment'].set_text(str(self.fuse.eid))
|
||||
self.label['location'].set_text(str(self.fuse.location))
|
||||
if self.fuse.cableid:
|
||||
self.label['cable'].set_text(self.dd_cable[self.fuse.cableid])
|
||||
else:
|
||||
self.label['cable'].set_text('')
|
||||
if self.fuse.eid:
|
||||
self.label['equipment'].set_text(self.dd_equipment[self.fuse.eid])
|
||||
else:
|
||||
self.label['equipment'].set_text('')
|
||||
if self.fuse.location:
|
||||
self.label['location'].set_text(self.dd_location[self.fuse.location])
|
||||
else:
|
||||
self.label['location'].set_text('')
|
||||
self.label['description'].set_text(str(self.fuse.description or ''))
|
||||
if self.fuse.color:
|
||||
self.label['color'].set_markup(f'#{self.cable.color} <span foreground="#{self.fuse.color}">●</span>')
|
||||
else:
|
||||
self.label['color'].set_text('')
|
||||
self.label['remarks'].set_text(str(self.fuse.remarks or ''))
|
||||
|
||||
def edit_record(self):
|
||||
@@ -78,20 +106,52 @@ class FusesView(View):
|
||||
self.spin['current'].set_value(self.fuse.current)
|
||||
combobox.activate_row(self.combo['cable'], self.fuse.cableid)
|
||||
combobox.activate_row(self.combo['equipment'], self.fuse.eid)
|
||||
self.entry['location'].set_text(self.fuse.location)
|
||||
self.text['remarks'].get_buffer().set_text(self.prov.remarks or '')
|
||||
combobox.activate_row(self.combo['location'], self.fuse.location)
|
||||
self.text['remarks'].get_buffer().set_text(self.fuse.remarks or '')
|
||||
self.spin['fnumber'].grab_focus()
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.fuse.number = int(self.spin['fnumber'].get_value())
|
||||
self.fuse.vid = self.context.vessel.vid
|
||||
self.fuse.fnumber = self.spin['fnumber'].get_value_as_int()
|
||||
self.fuse.current = self.spin['current'].get_value()
|
||||
self.fuse.description = self.entry['description'].get_text()
|
||||
self.fuse.ftype = combobox.get_list_value(self.combo['ftype'])
|
||||
if self.fuse.ftype == -1:
|
||||
self.fuse.ftype = None
|
||||
self.fuse.cableid = combobox.get_list_value(self.combo['cable'])
|
||||
if self.fuse.cableid == -1:
|
||||
self.fuse.cableid = None
|
||||
self.fuse.eid = combobox.get_list_value(self.combo['equipment'])
|
||||
self.fuse.location = self.entry['location'].get_text()
|
||||
if self.fuse.eid == -1:
|
||||
self.fuse.eid = None
|
||||
self.fuse.location = combobox.get_list_value(self.combo['location'])
|
||||
if self.fuse.location == -1:
|
||||
self.fuse.location = None
|
||||
if self.button['color'].get_rgba().alpha > 0:
|
||||
self.fuse.color = self.entry['color'].get_text().lstrip('#')
|
||||
else:
|
||||
self.fuse.color = None
|
||||
self.fuse.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
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)
|
||||
a = round(rgba.alpha * 255)
|
||||
if a > 0:
|
||||
self.entry['color'].set_text(f"#{r:02X}{g:02X}{b:02X}")
|
||||
else:
|
||||
self.entry['color'].set_text('')
|
||||
|
||||
def on_ent_color_activate(self, entry):
|
||||
self.set_color_from_entry(entry, self.button['color'])
|
||||
|
||||
def on_ent_color_focus_out_event(self, entry, event):
|
||||
self.set_color_from_entry(entry, self.button['color'])
|
||||
return False
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
@@ -141,7 +201,19 @@ class FusesView(View):
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
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
|
||||
self.save_record()
|
||||
print(self.fuse)
|
||||
self.fuse.save()
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['fuse_detail'])
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['fuses'])
|
||||
|
||||
Reference in new issue
Block a user