Files

103 lines
3.7 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 cable
class CablesView(View):
def __init__(self, context):
super().__init__(context, _("Cables"), "cables.ui")
self.cable = cable.Cable(context.db) # current record
self.newrecord = False
self.lst_cables = Gtk.ListStore(int, str, str)
sql = (
"SELECT cableid, cablename, cablecond "
"FROM cable "
"WHERE vid=%s "
"ORDER BY cableid"
)
self.db.dcur.execute(sql, (context.vessel.vid,))
for row in self.db.dcur.fetchall():
data = (
row['cableid'],
row['cablename'],
row['cablecond']
)
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)
# buttons on list page
def on_but_new_clicked(self, widget):
self.topwidget.set_visible_child(self.box['cable_edit'])
def on_but_edit_clicked(self, widget):
self.topwidget.set_visible_child(self.box['cable_edit'])
def on_but_detail_clicked(self, widget):
cableid = treeview.get_value(self.tree['cables'], 0)
if not cableid:
return
self.cable.load(cableid)
self.display_record()
self.topwidget.set_visible_child(self.box['cable_detail'])
self.button['close'].grab_focus()
def on_tvw_cables_row_activated(self, widget, path, column):
cableid = treeview.get_value(widget, 0)
self.cable.load(cableid)
self.display_record()
self.topwidget.set_visible_child(self.box['cable_detail'])
# buttons on detail page
# edit2 uses edit callback
def on_but_close_clicked(self, widget):
self.topwidget.set_visible_child(self.box['cables'])
def on_but_delete_clicked(self, widget):
self.topwidget.set_visible_child(self.box['cables'])
# 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['cables'])
def display_record(self):
self.label['name'].set_text(self.cable.cablename)
self.label['type'].set_text(self.dd_type[self.cable.cabletype])
if self.cable.techname:
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['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))
if self.cable.color:
self.label['color'].set_markup(f'#{self.cable.color} <span foreground="#{self.cable.color}">●</span>')
else:
self.label['color'].set_text('')
self.label['supplier'].set_text(str(self.cable.supplier))
self.label['manufacturer'].set_text(str(self.cable.manufacturer))
self.label['condition'].set_text(self.cable.cablecond)
self.label['remarks'].set_text(self.cable.remarks or '')
def edit_record(self):
pass