Native gui: ongoing work, cables and fuses
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
# SPDX-License-Identifier: WTFPL
|
||||
|
||||
import os
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
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)
|
||||
|
||||
# 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):
|
||||
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'])
|
||||
@@ -46,6 +46,15 @@ class EquipmentView(View):
|
||||
self.topwidget.set_visible_child(self.box['equip_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
eid = treeview.get_value(self.tree['equipment'], 0)
|
||||
self.equip.load(eid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['equip_detail'])
|
||||
|
||||
def on_tvw_equipment_row_activated(self, widget, path, column):
|
||||
eid = treeview.get_value(widget, 0)
|
||||
self.equip.load(eid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['equip_detail'])
|
||||
|
||||
# buttons on detail page
|
||||
@@ -62,3 +71,15 @@ class EquipmentView(View):
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['equipment'])
|
||||
|
||||
def display_record(self):
|
||||
print(self.equip)
|
||||
#self.label['name'].set_text(self.equip.sname)
|
||||
self.label['remarks'].set_text(self.equip.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['sname'].set_text(self.storage.sname)
|
||||
self.spin['x'].set_value(self.storage.x)
|
||||
self.spin['y'].set_value(self.storage.y)
|
||||
self.spin['z'].set_value(self.storage.z)
|
||||
self.text['remarks'].get_buffer().set_text(self.storage.remarks or '')
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
# SPDX-License-Identifier: WTFPL
|
||||
|
||||
import os
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
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)
|
||||
|
||||
# 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):
|
||||
self.topwidget.set_visible_child(self.box['fuse_detail'])
|
||||
|
||||
# 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'])
|
||||
@@ -49,6 +49,15 @@ class InventoryView(View):
|
||||
self.topwidget.set_visible_child(self.box['inv_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
invid = treeview.get_value(self.tree['inventory'], 0)
|
||||
self.inv.load(invid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_detail'])
|
||||
|
||||
def on_tvw_inventory_row_activated(self, widget, path, column):
|
||||
invid = treeview.get_value(widget, 0)
|
||||
self.inv.load(invid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_detail'])
|
||||
|
||||
# buttons on detail page
|
||||
@@ -65,3 +74,26 @@ class InventoryView(View):
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['inventory'])
|
||||
|
||||
def display_record(self):
|
||||
# TODO nice formatting
|
||||
self.label['name'].set_text(self.inv.invname)
|
||||
self.label['conttype'].set_text(self.inv.conttype)
|
||||
self.label['storage'].set_text(str(self.inv.sid))
|
||||
self.label['box'].set_text(str(self.inv.boxid))
|
||||
self.label['equipment'].set_text(str(self.inv.eid))
|
||||
self.label['number'].set_text(self.format_int(self.inv.number))
|
||||
self.label['weight'].set_text(self.format_float(self.inv.weight, suffix='kg'))
|
||||
self.label['price'].set_text(self.format_float(self.inv.price, suffix='€'))
|
||||
self.label['purchdate'].set_text(self.format_date(self.inv.purchdate))
|
||||
self.label['condition'].set_text(self.inv.invcond)
|
||||
self.label['remarks'].set_text(self.inv.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['user_login'].set_text(user.login)
|
||||
self.entry['user_displayname'].set_text(user.displayname)
|
||||
combobox.activate_row(self.combo['user_role'], user.role)
|
||||
combobox.activate_row(self.combo['user_lang'], user.language)
|
||||
self.check['user_locked'].set_active('locked' in user.flags)
|
||||
self.check['user_deleted'].set_active('deleted' in user.flags)
|
||||
self.entry['user_pass'].set_text('')
|
||||
|
||||
+20
-3
@@ -6,6 +6,7 @@ Generic view object
|
||||
SPDX-License-Identifier: WTFPL
|
||||
"""
|
||||
import os
|
||||
import locale
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import GLib, Gtk, Gdk
|
||||
@@ -26,10 +27,26 @@ class View:
|
||||
self.topwidget = builder.get_object("topobject")
|
||||
gtkutils.init_named_controls(self, builder)
|
||||
|
||||
def format_date(self, dateval):
|
||||
if dateval is None:
|
||||
def format_int(self, ival, separator=True, suffix=None):
|
||||
if ival is None:
|
||||
return ''
|
||||
return dateval.strftime(self.context.datefmt)
|
||||
formatted = locale.format_string("%d", ival, separator)
|
||||
if suffix:
|
||||
formatted += f"\u00A0{suffix}"
|
||||
return formatted
|
||||
|
||||
def format_float(self, fval, digits=2, grouping=True, suffix=None):
|
||||
if fval is None:
|
||||
return ''
|
||||
formatted = locale.format_string(f"%.{digits}f", fval, grouping)
|
||||
if suffix:
|
||||
formatted += f"\u00A0{suffix}"
|
||||
return formatted
|
||||
|
||||
def format_date(self, dval):
|
||||
if dval is None:
|
||||
return ''
|
||||
return dval.strftime(self.context.datefmt)
|
||||
|
||||
def on_textview_keypress(self, widget, event):
|
||||
# Generic limit length function
|
||||
|
||||
Reference in New Issue
Block a user