94 lines
3.2 KiB
Python
94 lines
3.2 KiB
Python
# SPDX-License-Identifier: WTFPL
|
|
|
|
import os
|
|
from gi.repository import Gtk
|
|
|
|
from .view import View
|
|
from yms import gtkutils, combobox, treeview
|
|
from yms.lookup import Dropdown
|
|
from yms.model import fuse
|
|
|
|
class FusesView(View):
|
|
|
|
def __init__(self, context):
|
|
super().__init__(context, _("Fuses"), "fuses.ui")
|
|
|
|
self.fuse = fuse.Fuse(context.db) # current record
|
|
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)
|
|
|
|
treeview.add_column(self.tree['fuses'], _('ID'), 0)
|
|
treeview.add_column(self.tree['fuses'], _('Name'), 1)
|
|
treeview.add_column(self.tree['fuses'], _('Current'), 2)
|
|
treeview.add_column(self.tree['fuses'], _('Description'), 3)
|
|
self.tree['fuses'].set_model(self.lst_fuses)
|
|
|
|
self.dd_type = self.context.lookup.dropdown(Dropdown.FUSE_TYPE)
|
|
|
|
# buttons on list page
|
|
def on_but_new_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['fuse_edit'])
|
|
|
|
def on_but_edit_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['fuse_edit'])
|
|
|
|
def on_but_detail_clicked(self, widget):
|
|
fuseid = treeview.get_value(self.tree['fuses'], 0)
|
|
if not fuseid:
|
|
return
|
|
self.fuse.load(fuseid)
|
|
self.display_record()
|
|
self.topwidget.set_visible_child(self.box['fuse_detail'])
|
|
self.button['close'].grab_focus()
|
|
|
|
def on_tvw_fuses_row_activated(self, widget, path, column):
|
|
fuseid = treeview.get_value(widget, 0)
|
|
self.fuse.load(fuseid)
|
|
self.display_record()
|
|
self.topwidget.set_visible_child(self.box['fuse_detail'])
|
|
self.button['close'].grab_focus()
|
|
|
|
# buttons on detail page
|
|
# edit2 uses edit callback
|
|
def on_but_close_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['fuses'])
|
|
|
|
def on_but_delete_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['fuses'])
|
|
|
|
# buttons on edit page
|
|
def on_but_save_clicked(self, widget):
|
|
pass
|
|
|
|
def on_but_cancel_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['fuses'])
|
|
|
|
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])
|
|
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))
|
|
self.label['description'].set_text(str(self.fuse.description or ''))
|
|
self.label['remarks'].set_text(str(self.fuse.remarks or ''))
|
|
|
|
def edit_record(self):
|
|
pass
|