More work on native gui. Make data editable.

This commit is contained in:
thooge committed 2026-10-29 18:59:21 +01:00
1 parent 5641e1706f
commit 7aa5d2af3b
43 files changed
+2686 -1037

No files matched your search

+20 -4
View File
@@ -84,9 +84,13 @@ class BaseView(View):
storages = self.context.lookup.storage(self.context.vessel.vid)
combobox.load_from_dict(self.combo['storage'], {-1: _("─── none ───")} | storages)
# Vessel types
self.dd_vtype = self.context.lookup.dropdown(Dropdown.VESSEL_TYPE)
combobox.load_from_dict(self.combo['vtype'], {-1: _("─── none ───")} | self.dd_vtype, -1)
# Hull types
self.dd_htype = self.context.lookup.enum('vessel.htype')
combobox.load_from_dict(self.combo['htype'], self.dd_htype)
combobox.load_from_dict(self.combo['htype'], self.dd_htype, 'mono')
# List of available shapes for combobox selection
shapes = self.load_shapes()
@@ -150,7 +154,6 @@ class BaseView(View):
#viewport.height = 240
#self._svg.render_document(ctx, viewport)
# WIP generic remarks handling
self.text['vessel_remarks'].set_size_request(200, 70)
@@ -350,7 +353,14 @@ class BaseView(View):
vessel = self.context.vessel
vessel.vesselname = self.entry['vesselname'].get_text()
vessel.model = self.entry['model'].get_text()
vessel.vtype = combobox.get_list_value(self.combo['vtype'])
if vessel.vtype == -1:
vessel.vtype = None
vessel.year_built = self.spin['year_built'].get_value_as_int()
vessel.hull_number = self.entry['hull_number'].get_text()
vessel.shipyard = combobox.get_list_value(self.combo['shipyard'])
if vessel.shipyard == -1:
vessel.shipyard = None
vessel.loa = self.spin['loa'].get_value()
vessel.lwl = self.spin['lwl'].get_value()
vessel.beam = self.spin['beam'].get_value()
@@ -360,7 +370,10 @@ class BaseView(View):
vessel.ballast = self.spin['ballast'].get_value_as_int()
vessel.beltpos_bow = self.spin['belt_bow'].get_value()
vessel.beltpos_aft = self.spin['belt_aft'].get_value()
vessel.htype = combobox.get_list_value(self.combo['htype'])
vessel.shapefile = combobox.get_list_value(self.combo['hull_shape'])
if vessel.shapefile == '-1':
vessel.shapefile = None
vessel.remarks = gtkutils.get_text_contents(self.text['vessel_remarks'])
vessel.save()
self.stack['vessel'].set_visible_child(self.box['vessel'])
@@ -399,7 +412,10 @@ class BaseView(View):
def edit_vessel(self, vessel):
self.entry['vesselname'].set_text(vessel.vesselname)
self.entry['model'].set_text(vessel.model or '')
combobox.activate_row(self.combo['vtype'], vessel.vtype or -1)
self.spin['year_built'].set_value(vessel.year_built or 0)
self.entry['hull_number'].set_text(vessel.hull_number or '')
combobox.activate_row(self.combo['shipyard'], vessel.shipyard or -1)
self.spin['loa'].set_value(vessel.loa or 0)
self.spin['lwl'].set_value(vessel.lwl or 0)
self.spin['beam'].set_value(vessel.beam or 0)
@@ -409,11 +425,11 @@ class BaseView(View):
self.spin['ballast'].set_value(vessel.ballast or 0)
self.spin['belt_bow'].set_value(vessel.beltpos_bow or 0)
self.spin['belt_aft'].set_value(vessel.beltpos_aft or 0)
combobox.activate_row(self.combo['shipyard'], vessel.shipyard or -1)
self.entry['hull_number'].set_text(vessel.hull_number or '')
combobox.activate_row(self.combo['htype'], vessel.htype)
combobox.activate_row(self.combo['hull_shape'], vessel.shapefile or "-1")
combobox.activate_row(self.combo['storage'], vessel.sid_default or -1)
self.text['vessel_remarks'].get_buffer().set_text(vessel.remarks or '')
self.entry['vesselname'].grab_focus()
def display_user(self, user):
self.entry['user_login'].set_text(user.login)
+2
View File
@@ -65,6 +65,7 @@ class BoxesView(View):
self.spin['weight'].set_value(0)
self.spin['weight_net'].set_value(0)
self.text['remarks'].get_buffer().set_text('')
self.entry['label'].grab_focus()
def display_record(self):
self.label['label'].set_text(self.sbox.label)
@@ -100,6 +101,7 @@ class BoxesView(View):
self.spin['weight'].set_value(self.sbox.weight or 0)
self.spin['weight_net'].set_value(self.sbox.weight_net or 0)
self.text['remarks'].get_buffer().set_text(self.sbox.remarks or '')
self.entry['label'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
+40 -16
View File
@@ -17,13 +17,38 @@ class CablesView(View):
self.newrecord = False
self.lst_cables = Gtk.ListStore(int, str, str)
self.load_list()
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)
# Cable type
self.dd_type = self.context.lookup.dropdown(Dropdown.CABLE_TYPE)
combobox.load_from_dict(self.combo['type'], {-1: _("─── none ───")} | self.dd_type)
# Cable tech type
self.dd_tech = self.context.lookup.dropdown(Dropdown.CABLE_TECHNAME)
combobox.load_from_dict(self.combo['techname'], {-1: _("─── none ───")} | self.dd_tech)
# Supplier
self.dd_supplier = self.context.lookup.company(1)
combobox.load_from_dict(self.combo['supplier'], {-1: _("─── none ───")} | self.dd_supplier)
# Manufacturer
self.dd_manufacturer = self.context.lookup.company(2)
combobox.load_from_dict(self.combo['manufacturer'], {-1: _("─── none ───")} | self.dd_manufacturer)
# Condition
self.dd_condition = self.context.lookup.enum('cable.cablecond')
combobox.load_from_dict(self.combo['condition'], self.dd_condition, 'unknown')
def load_list(self):
self.lst_cables.clear()
sql = (
"SELECT cableid, cablename, cablecond "
"FROM cable "
"WHERE vid=%s "
"ORDER BY cableid"
)
self.db.dcur.execute(sql, (context.vessel.vid,))
self.db.dcur.execute(sql, (self.context.vessel.vid,))
for row in self.db.dcur.fetchall():
data = (
row['cableid'],
@@ -32,17 +57,12 @@ class CablesView(View):
)
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)
def display_record(self):
self.label['name'].set_text(self.cable.cablename)
self.label['type'].set_text(self.dd_type[self.cable.cabletype])
self.label['name'].set_text(self.cable.cablename or '')
if self.cable.cabletype:
self.label['type'].set_text(self.dd_type[self.cable.cabletype])
else:
self.label['type'].set_text('')
if self.cable.techname:
self.label['techname'].set_text(self.dd_tech[self.cable.techname])
else:
@@ -64,8 +84,8 @@ class CablesView(View):
def edit_record(self):
# fill UI fields from database record
self.entry['name'].set_text(self.cable.cablename)
combobox.activate_row(self.combo['type'], self.cable.cabletype)
combobox.activate_row(self.combo['techname'], self.cable.techname)
combobox.activate_row(self.combo['type'], self.cable.cabletype or -1)
combobox.activate_row(self.combo['techname'], self.cable.techname or -1)
self.spin['length'].set_value(self.cable.length or 0)
self.spin['consuctors'].set_value(self.cable.conductors or 0)
self.spin['diameter'].set_value(self.cable.diameter or 0)
@@ -75,10 +95,11 @@ class CablesView(View):
rgba = Gdk.RGBA()
rgba.parse('#' + self.cable.color)
self.button['color'].set_rgba(rgba)
combobox.activate_row(self.combo['supplier'], self.cable.supplier)
combobox.activate_row(self.combo['manufacturer'], self.cable.manufacturer)
combobox.activate_row(self.combo['consition'], self.cable.cablecond)
combobox.activate_row(self.combo['supplier'], self.cable.supplier or -1)
combobox.activate_row(self.combo['manufacturer'], self.cable.manufacturer or -1)
combobox.activate_row(self.combo['consition'], self.cable.cablecond or 'unknown')
self.text['remarks'].get_buffer().set_text(self.sbox.remarks or '')
self.entry['name'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
@@ -95,6 +116,9 @@ class CablesView(View):
# buttons on list page
def on_but_new_clicked(self, widget):
self.newrecord = True
self.cable.clear()
self.edit_record()
self.topwidget.set_visible_child(self.box['cable_edit'])
def on_but_edit_clicked(self, widget):
+10 -4
View File
@@ -67,6 +67,7 @@ class CompaniesView(View):
self.entry['contractno'].set_text('')
combobox.activate_row(self.combo['comptype'], company.SUPPLIER)
combobox.activate_row(self.combo['comptype2'], -1)
self.entry['compname'].grab_focus()
def display_record(self):
self.label['name'].set_text(self.comp.compname)
@@ -77,20 +78,20 @@ class CompaniesView(View):
self.label['zip'].set_text(self.comp.zip or '')
self.label['city'].set_text(self.comp.city or '')
self.label['country'].set_text(self.comp.country or '')
self.label['contact'].set_text(self.comp.contact or '')
self.label['phone'].set_text(self.comp.phone or '')
self.label['email'].set_text(self.comp.email or '')
self.label['web'].set_text(self.comp.web or '')
self.label['customerno'].set_text(self.comp.customerno or '')
self.label['contractno'].set_text(self.comp.contractno or '')
self.label['flags'].set_text(self.comp.flags or '')
# TODO translation
self.label['remarks'].set_text(self.comp.remarks or '')
def edit_record(self):
self.entry['compname'].set_text(self.comp.compname)
# Type self.dd_comptype.get(self.comp.comptype, -1)
# Type2 self.dd_comptype.get(self.comp.comptype2, -1)
combobox.activate_row(self.combo['comptype'], self.comp.comptype)
combobox.activate_row(self.combo['comptype2'], self.comp.comptype2)
combobox.activate_row(self.combo['comptype2'], self.comp.comptype2 or -1)
self.entry['shortname'].set_text(self.comp.shortname or '')
self.entry['street'].set_text(self.comp.street or '')
self.entry['zip'].set_text(self.comp.zip or '')
@@ -102,7 +103,11 @@ class CompaniesView(View):
self.entry['web'].set_text(self.comp.web or '')
self.entry['customerno'].set_text(self.comp.customerno or '')
self.entry['contractno'].set_text(self.comp.contractno or '')
flags = (self.comp.flags or '').split(',')
for flag in self.dd_flags:
self.check[flag].set_active(flag in flags)
self.text['remarks'].get_buffer().set_text(self.comp.remarks or '')
self.entry['compname'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
@@ -121,7 +126,8 @@ class CompaniesView(View):
self.comp.email = self.entry['email'].get_text()
self.comp.web = self.entry['web'].get_text()
self.comp.customerno = self.entry['customerno'].get_text()
self.comp.conractno = self.entry['contractno'].get_text()
self.comp.contractno = self.entry['contractno'].get_text()
self.comp.flags = self.get_checks(('historic', 'ordered'))
self.comp.remarks = gtkutils.get_text_contents(self.text['remarks'])
# buttons on list page
+18 -3
View File
@@ -19,8 +19,10 @@ class DocumentsView(View):
self.newrecord = False
self.scandialog = self.builder.get_object("dlg_scanner")
print(self.scandialog)
# TODO self.uploaddialog = self.builder.get_object("dlg_upload")
self.scandialog.set_title("Scan new document")
self.uploaddialog = self.builder.get_object("dlg_upload")
self.uploaddialog.set_title("Upload new document")
self.lst_documents = Gtk.ListStore(int, str, str, str, int)
sql = (
@@ -54,6 +56,7 @@ class DocumentsView(View):
self.entry['filename'].set_text('')
combobox.activate_row(self.combo['accesslevel'], 'captain')
self.text['remarks'].get_buffer().set_text('')
self.entry['title'].grab_focus()
def pdf_to_pixbuf(self, filename, max_width=400, max_height=400):
doc = fitz.open(filename)
@@ -122,6 +125,7 @@ class DocumentsView(View):
combobox.activate_row(self.combo['doctype'], self.doc.doctype)
self.entry['title'].set_text(self.doc.title or '')
self.entry['filename'].set_text(self.doc.filename or '')
self.entry['title'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
@@ -223,8 +227,19 @@ class DocumentsView(View):
# sane.exit()
pass
def on_but_scan_close_clicked(self, widget):
self.scandialog.response(Gtk.ResponseType.CLOSE)
def on_but_upload_clicked(self, widget):
pass
response = self.uploaddialog.run()
self.uploaddialog.hide()
if response == Gtk.ResponseType.OK:
print("Upload OK")
else:
print("Upload Not OK")
def on_but_upload_close_clicked(self, widget):
self.uploaddialog.response(Gtk.ResponseType.CLOSE)
def on_but_save_clicked(self, widget):
print(self.doc)
+10 -2
View File
@@ -3,6 +3,7 @@
import os
from gi.repository import GLib, Gtk, Gdk
from dateutil.parser import parse
from gettext import pgettext
from .view import View
from yms import gtkutils, combobox, treeview
@@ -71,6 +72,7 @@ class EquipmentView(View):
combobox.activate_row(self.combo['category'], -1)
combobox.activate_row(self.combo['condition'], 'unknown')
self.text['remarks'].get_buffer().set_text('')
self.entry['name'].grab_focus()
def display_record(self):
print(self.equip)
@@ -94,6 +96,7 @@ class EquipmentView(View):
else:
self.label['category'].set_text('')
self.label['flags'].set_text(self.equip.flags or '')
self.label['condition'].set_text(pgettext("equipment.econd", self.equip.econd))
self.label['remarks'].set_text(self.equip.remarks or '')
def edit_record(self):
@@ -110,8 +113,7 @@ class EquipmentView(View):
combobox.activate_row(self.combo['category'], self.equip.ecat or -1)
combobox.activate_row(self.combo['condition'], self.equip.econd or 'unknown')
self.text['remarks'].get_buffer().set_text(self.equip.remarks or '')
print("Edit record")
print(self.equip)
self.entry['name'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
@@ -125,12 +127,18 @@ class EquipmentView(View):
self.equip.serial = self.entry['serial'].get_text()
self.equip.weight = self.spin['weight'].get_value()
self.equip.price = self.spin['price'].get_value()
try:
# TODO respect configured date format
self.equip.purchdate = parse(self.entry['purchdate'].get_text(), dayfirst=True)
except ValueError:
self.equip.purchdate = None
self.equip.supplier = combobox.get_list_value(self.combo['supplier'])
if self.equip.supplier < 0:
self.equip.supplier = None
self.equip.ecat = combobox.get_list_value(self.combo['category'])
if self.equip.ecat < 0:
self.equip.ecat = None
self.equip.econd = combobox.get_list_value(self.combo['condition'])
self.equip.remarks = gtkutils.get_text_contents(self.text['remarks'])
print(self.equip)
+2
View File
@@ -59,6 +59,7 @@ class FusesView(View):
combobox.activate_row(self.combo['equipment'], -1)
self.entry['location'].set_text('')
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}")
@@ -79,6 +80,7 @@ class FusesView(View):
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 '')
self.spin['fnumber'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
+25 -13
View File
@@ -1,10 +1,9 @@
# SPDX-License-Identifier: WTFPL
import os
from gi.repository import GLib, Gtk, Gdk
from dateutil.parser import parse
from gettext import pgettext
from .view import View
from yms import gtkutils, combobox, treeview
@@ -53,7 +52,7 @@ class InventoryView(View):
combobox.load_from_dict(self.combo['equipment'], {-1: _("─── none ───")} | self.dd_equipment)
# Condition
self.dd_condition = self.context.lookup.enum('inventory.invcond')
combobox.load_from_dict(self.combo['condition'], {"-1": _("─── none ───")} | self.dd_condition)
combobox.load_from_dict(self.combo['condition'], self.dd_condition)
def load_list(self):
self.lst_inventory.clear()
@@ -90,19 +89,22 @@ class InventoryView(View):
combobox.activate_row(self.combo['condition'], 'unknown')
combobox.activate_row(self.combo['category'], -1)
self.text['remarks'].get_buffer().set_text('')
self.entry['name'].grab_focus()
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))
container = pgettext("inventory.conttype", self.inv.conttype)
if self.inv.conttype == 'storage':
self.label['conttype'].set_text("{}: {}".format(container, self.dd_storage[self.inv.sid]))
else:
self.label['conttype'].set_text("{}: {}".format(container, self.dd_box[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['condition'].set_text(pgettext("inventory.invcond", self.inv.invcond))
if self.inv.icat is not None:
self.label['category'].set_text(self.dd_category[self.inv.icat])
else:
@@ -113,19 +115,20 @@ class InventoryView(View):
def edit_record(self):
self.entry['name'].set_text(self.inv.invname)
combobox.activate_row(self.combo['conttype'], self.inv.conttype)
combobox.activate_row(self.combo['storage'], self.inv.sid)
combobox.activate_row(self.combo['box'], self.inv.boxid)
combobox.activate_row(self.combo['equipment'], self.inv.eid)
combobox.activate_row(self.combo['storage'], self.inv.sid or -1)
combobox.activate_row(self.combo['box'], self.inv.boxid or -1)
combobox.activate_row(self.combo['equipment'], self.inv.eid or -1)
self.spin['number'].set_value(self.inv.number)
self.spin['weight'].set_value(self.inv.weight or 0)
self.spin['price'].set_value(self.inv.price or 0)
self.entry['purchdate'].set_text(self.inv.purchdate or '')
self.entry['purchdate'].set_text(self.format_date(self.inv.purchdate))
combobox.activate_row(self.combo['condition'], self.inv.invcond)
combobox.activate_row(self.combo['category'], self.inv.icat)
combobox.activate_row(self.combo['category'], self.inv.icat or -1)
flags = self.inv.flags.split(',')
for flag in self.context.lookup.enum('inventory.flags'):
self.check[flag].set_active(flag in flags)
self.text['remarks'].get_buffer().set_text(self.inv.remarks or '')
self.entry['name'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
@@ -150,6 +153,8 @@ class InventoryView(View):
self.inv.purchdate = None
self.inv.invcond = combobox.get_list_value(self.combo['condition'])
self.inv.icat = combobox.get_list_value(self.combo['category'])
if self.inv.icat == -1:
self.inv.icat = None
# TODO this could be a generic function operating on a list
# of check controls
flags = []
@@ -251,7 +256,14 @@ class InventoryView(View):
self.save_record()
print(self.inv)
self.inv.save()
self.context.db.conn.commit()
if self.newrecord:
self.load_list()
self.newrecord = False
else:
pass
# TODO aktuelle Listenzeile aktualisieren!
self.display_record()
self.topwidget.set_visible_child(self.box['inv_detail'])
def on_but_cancel_clicked(self, widget):
if not self.newrecord:
+2
View File
@@ -43,6 +43,7 @@ class MaintenanceView(View):
self.entry['completion'].set_text('')
combobox.activate_row(self.combo['status'], 'new')
self.text['remarks'].get_buffer().set_text('')
self.entry['activities'].grab_focus()
def display_record(self):
self.label['activities'].set_text(self.maint.activities)
@@ -65,6 +66,7 @@ class MaintenanceView(View):
self.entry['completion'].set_text(self.maint.completion_date)
combobox.activate_row(self.combo['status'], self.maint.maintstate)
self.text['remarks'].get_buffer().set_text(self.maint.remarks or '')
self.entry['activities'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
+7 -4
View File
@@ -26,7 +26,6 @@ class MeasurementView(View):
# measurement units
self.dd_unit = self.context.lookup.dropdown(Dropdown.UNIT)
print("Unit: {self.dd_unit}")
combobox.load_from_dict(self.combo['unit'], self.dd_unit, 1)
# equipment
@@ -86,6 +85,7 @@ class MeasurementView(View):
combobox.activate_row(self.combo['equipment'], -1)
combobox.activate_row(self.combo['category'], -1)
self.text['note'].get_buffer().set_text('')
self.entry['name'].grab_focus()
def display_record(self):
self.label['name'].set_text(self.measure.mname)
@@ -115,14 +115,15 @@ class MeasurementView(View):
combobox.activate_row(self.combo['equipment'], self.measure.eid)
combobox.activate_row(self.combo['category'], self.measure.mcat)
self.text['note'].get_buffer().set_text(self.task.note or '')
self.entry['name'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
self.measure.mname = self.entry['name'].get_text()
self.measure.nval = combobox.get_list_value(self.combo['dimensions'])
self.measure.val1 = int(self.spin['val1'].get_value())
self.measure.val2 = int(self.spin['val2'].get_value())
self.measure.val3 = int(self.spin['val3'].get_value())
self.measure.val1 = self.spin['val1'].get_value_as_int()
self.measure.val2 = self.spin['val2'].get_value_as_int()
self.measure.val3 = self.spin['val3'].get_value_as_int()
self.measure.accuracy = combobox.get_list_value(self.combo['accurace'])
self.measure.mdate = self.entry['date'].get_text()
self.measure.eid = combobox.get_list_value(self.combo['equipment'])
@@ -185,6 +186,8 @@ class MeasurementView(View):
self.save_record()
print(self.measure)
self.measure.save()
self.display_record()
self.topwidget.set_visible_child(self.box['measure_detail'])
def on_but_cancel_clicked(self, widget):
self.topwidget.set_visible_child(self.box['measurement'])
+4 -1
View File
@@ -2,6 +2,7 @@
import os
from gi.repository import Gtk
from gettext import pgettext
from .view import View
from yms import gtkutils, combobox, treeview
@@ -60,6 +61,7 @@ class ProjectsView(View):
self.spin['costs_final'].set_value(0)
combobox.activate_row(self.combo['status'], 'new')
self.text['remarks'].get_buffer().set_text('')
self.entry['name'].grab_focus()
def display_record(self):
self.label['name'].set_text(self.project.projname)
@@ -68,7 +70,7 @@ class ProjectsView(View):
self.label['duration'].set_text(self.format_int(self.project.duration, suffix="Days"))
self.label['costs_plan'].set_text(self.format_float(self.project.costs_plan, 2, suffix="€"))
self.label['costs_final'].set_text(self.format_float(self.project.costs_final, 2, suffix="€"))
self.label['status'].set_text(self.project.projstate)
self.label['status'].set_text(pgettext("project.projstate", self.project.projstate))
self.label['remarks'].set_text(self.project.remarks or '')
def edit_record(self):
@@ -79,6 +81,7 @@ class ProjectsView(View):
self.spin['costs_final'].set_value(self.project.costs_final)
combobox.activate_row(self.combo['status'], self.project.projstate)
self.text['remarks'].get_buffer().set_text(self.project.remarks or '')
self.entry['name'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
+117 -39
View File
@@ -8,6 +8,7 @@ from datetime import datetime
from .view import View, DatePicker
from yms import gtkutils, combobox, treeview
from yms.model import provision
from yms.lookup import Dropdown
class ProvisionsView(View):
@@ -18,25 +19,21 @@ class ProvisionsView(View):
self.prov = provision.Provision(context.db) # current record
self.newrecord = False
self.load_dropdown()
# Category
self.dd_category = self.context.lookup.dropdown(Dropdown.PROVISION_CATEGORY)
combobox.load_from_dict(self.combo['category'], {-1: _("─── none ───")} | self.dd_category, -1)
# Storage
self.dd_storage = self.context.lookup.storage(context.vessel.vid)
combobox.load_from_dict(self.combo['storage'], {-1: _("─── none ───")} | self.dd_storage)
# Box
self.dd_box = self.context.lookup.box(context.vessel.vid)
combobox.load_from_dict(self.combo['box'], {-1: _("─── none ───")} | self.dd_box)
# Provision unit
self.dd_unit = self.context.lookup.dropdown(Dropdown.PROVISION_UNIT)
combobox.load_from_dict(self.combo['unit'], {-1: _("─── none ───")} | self.dd_unit, -1)
self.lst_provisions = Gtk.ListStore(int, str, int, str, str, str)
sql = (
"SELECT p.provid, p.provname, p.number, p.unit, p.storedate, p.shelflife "
"FROM provisions AS p LEFT OUTER JOIN storage AS s USING (sid) "
"WHERE s.vid=%s OR vid IS NULL"
)
self.db.dcur.execute(sql, (context.vessel.vid,))
for row in self.db.dcur.fetchall():
data = (
row['provid'],
row['provname'],
row['number'],
self.prov_unit[row['unit']],
self.format_date(row['storedate']),
self.format_date(row['shelflife'])
)
self.lst_provisions.append(data)
self.load_list()
treeview.add_column(self.tree['provisions'], _('ID'), 0)
treeview.add_column(self.tree['provisions'], _('Description'), 1)
@@ -49,54 +46,117 @@ class ProvisionsView(View):
# TODO Date format
self.entry['storedate'].set_placeholder_text("TT.MM.JJJJ")
self.dt_storedate = DatePicker(self.entry['storedate'], self.button['storedate'], context.datefmt)
self.entry['shelflife'].set_placeholder_text("TT.MM.JJJJ")
self.dt_shelflife = DatePicker(self.entry['shelflife'], self.button['shelflife'], context.datefmt)
def load_list(self):
selected_id = treeview.get_value(self.tree['provisions'])
self.lst_provisions.clear()
sql = (
"SELECT p.provid, p.provname, p.number, p.unit, p.storedate, p.shelflife "
"FROM provisions AS p LEFT OUTER JOIN storage AS s USING (sid) "
"WHERE s.vid=%s OR vid IS NULL"
)
self.db.dcur.execute(sql, (self.context.vessel.vid,))
for row in self.db.dcur.fetchall():
data = (
row['provid'],
row['provname'],
row['number'],
self.dd_unit[row['unit']] if row['unit'] is not None else _("─── none ───"),
self.format_date(row['storedate']),
self.format_date(row['shelflife'])
)
treeiter = self.lst_provisions.append(data)
if row['provid'] == selected_id:
# restore previous selected row
selection.select_iter(treeiter)
def clear_record(self):
self.prov.clear()
self.entry['name'].set_text('')
combobox.activate_row(self.combo['category'], -1)
combobox.activate_row(self.combo['storage'], -1)
combobox.activate_row(self.combo['box'], -1)
self.spin['number'].set_value(1)
self.spin['target'].set_value(0)
combobox.activate_row(self.combo['unit'], -1)
self.spin['weight'].set_value(0)
self.spin['weight_net'].set_value(0)
self.spin['price'].set_value(0)
self.spin['calories'].set_value(0)
self.entry['storedate'].set_text('')
self.entry['shelflife'].set_text('')
self.text['remarks'].get_buffer().set_text( '')
self.entry['name'].grab_focus()
def display_record(self):
self.label['name'].set_text(self.prov.provname)
self.label['category'].set_text(str(self.prov.provcat))
self.label['storage'].set_text(str(self.prov.sid))
self.label['box'].set_text(str(self.prov.boxid))
self.label['number'].set_text(str(self.prov.number))
self.label['unit'].set_text(str(self.prov.unit))
self.label['target'].set_text(str(self.prov.target))
self.label['unit'].set_text(str(self.prov.unit))
self.label['weight'].set_text(self.format_float(self.prov.weight, 2, suffix='kg'))
self.label['weight_net'].set_text(self.format_float(self.prov.weight_net, 2, suffix='kg'))
self.label['price'].set_text(self.format_float(self.prov.price, 2, suffix='€'))
self.label['calories'].set_text(str(self.prov.calories))
self.label['storedate'].set_text(self.prov.storedate or '')
self.label['shelflife'].set_text(self.prov.shelflife or '')
self.label['remarks'].set_text(self.prov.remarks or '')
def edit_record(self):
self.entry['name'].set_text(self.prov.provname)
combobox.activate_row(self.combo['category'], self.prov.provcat)
combobox.activate_row(self.combo['storage'], self.prov.sid)
combobox.activate_row(self.combo['box'], self.prov.boxid)
self.spin['number'].set_value(self.prov.number)
combobox.activate_row(self.combo['category'], self.prov.provcat or -1)
combobox.activate_row(self.combo['storage'], self.prov.sid or -1)
combobox.activate_row(self.combo['box'], self.prov.boxid or -1)
self.spin['number'].set_value(self.prov.number or 1)
self.spin['target'].set_value(self.prov.target or 0)
combobox.activate_row(self.combo['unit'], self.prov.unit or -1)
self.spin['weight'].set_value(self.prov.weight or 0)
self.spin['weight_net'].set_value(self.prov.weight_net or 0)
combobox.activate_row(self.combo['unit'], self.prov.unit)
self.spin['price'].set_value(self.prov.price or 0)
self.spin['calories'].set_value(self.prov.calories or 0)
self.entry['storedate'].set_text(self.prov.storedate or '')
self.entry['shelflife'].set_text(self.prov.shelflife or '')
# self.dt_storedate.set_date
# self.dt_shelflife.set_date
self.text['remarks'].get_buffer().set_text(self.prov.remarks or '')
self.entry['name'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
self.prov.provname = self.entry['name'].get_text()
self.prov.provcat = combobox.get_list_value(self.combo['category'])
if self.prov.provcat == -1:
self.prov.provcat = None
self.prov.sid = combobox.get_list_value(self.combo['storage'])
if self.prov.sid == -1:
self.prov.sid = None
self.prov.boxid = combobox.get_list_value(self.combo['box'])
self.prov.number = int(self.spin['number'].get_value())
if self.prov.boxid == -1:
self.prov.boxid = None
self.prov.number = self.spin['number'].get_value_as_int()
self.prov.target = self.spin['target'].get_value_as_int()
self.prov.weight = self.spin['weight'].get_value()
self.prov.weight_net = self.spin['wehigt_net'].get_value()
self.prov.weight_net = self.spin['weight_net'].get_value()
self.prov.unit = combobox.get_list_value(self.combo['unit'])
self.prov.storedate = self.entry['storedate'].get_text()
self.prov.shelflife = self.entry['shelflife'].get_text()
if self.prov.unit == -1:
self.prov.unit = None
# TODO respect configured date format
# self.prov.storedate = self.dt_storedate.get_date()
# self.prov.shelflife = self.dt_shelflife.get_date()
try:
self.prov.storedate = parse(self.entry['storedate'].get_text(), dayfirst=True)
except ValueError:
self.prov.shelfstoredatelife = None
try:
self.prov.shelflife = parse(self.entry['shelflife'].get_text(), dayfirst=True)
except ValueError:
self.prov.shelflife = None
self.prov.remarks = gtkutils.get_text_contents(self.text['remarks'])
def load_dropdown(self):
self.db.cur.execute("SELECT ddval, ddtext FROM dropdown WHERE ddid=6 ORDER BY ddval")
self.prov_unit = dict(self.db.cur.fetchall())
# buttons on list page
def on_but_new_clicked(self, widget):
self.newrecord = True
@@ -144,21 +204,39 @@ class ProvisionsView(View):
# buttons on edit page
def on_but_storedate_clicked(self, widget):
try:
curdate = parse(self.entry['storedate'].get_text())
except:
curdate = datetime.date.today()
selected_date = self.calendar_dialog(None, self.entry['storedate'], curdate)
self.entry['storedate'].set_text(self.format_date(selected_date, curdate))
#try:
# curdate = parse(self.entry['storedate'].get_text())
#except:
# curdate = datetime.today()
#selected_date = self.calendar_dialog(None, self.entry['storedate'], curdate)
#self.entry['storedate'].set_text(self.format_date(selected_date, curdate))
pass
def on_but_shelflife_clicked(self, widget):
#try:
# curdate = parse(self.entry['shelflife'].get_text())
#except:
# curdate = datetime.today()
#selected_date = self.calendar_dialog(None, self.entry['shelflife'], curdate)
#self.entry['shelflife'].set_text(self.format_date(selected_date, curdate))
pass
def on_but_save_clicked(self, widget):
# check mandatory fields
if not self.entry['provname'].get_text().strip():
if not self.entry['name'].get_text().strip():
# TODO error marker
return
self.save_record()
print(self.prov)
self.prov.save()
if self.newrecord:
self.load_list()
else:
pass
# TODO aktuelle Listenzeile aktualisieren!
self.newrecord = False
self.display_record()
self.topwidget.set_visible_child(self.box['prov_detail'])
def on_but_cancel_clicked(self, widget):
self.topwidget.set_visible_child(self.box['provisions'])
+4 -2
View File
@@ -76,6 +76,7 @@ class StorageView(View):
combobox.activate_row(self.combo['type'], storage.GENERIC)
combobox.activate_row(self.combo['unit'], "-1")
self.text['remarks'].get_buffer().set_text('')
self.entry['sname'].grab_focus()
def display_record(self):
self.label['name'].set_text(self.storage.sname)
@@ -108,6 +109,7 @@ class StorageView(View):
rgba.parse('#' + (self.storage.color or '000000'))
self.button['color'].set_rgba(rgba)
self.text['remarks'].get_buffer().set_text(self.storage.remarks or '')
self.entry['sname'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
@@ -187,10 +189,10 @@ class StorageView(View):
self.storage.save()
if self.newrecord:
self.load_list()
self.newrecord = False
else:
pass
# TODO aktuelle Listenzeile aktualisieren!
self.newrecord = False
self.display_record()
self.topwidget.set_visible_child(self.box['stor_detail'])
@@ -206,7 +208,7 @@ class StorageView(View):
self.set_color_from_entry(entry)
def on_ent_color_focus_out_event(self, entry, event):
self.set_color_from_entry(entry)
self.set_color_from_entry(entry, self.button['color'])
return False
def on_but_cancel_clicked(self, widget):
+43 -18
View File
@@ -17,23 +17,7 @@ class TasksView(View):
self.newrecord = False
self.lst_tasks = Gtk.ListStore(int, str, str, str, str)
sql = (
"SELECT t.taskid, t.taskname, t.priority, t.taskstate, "
"u.displayname AS responsible "
"FROM task AS t JOIN user AS u ON (t.responsible=u.userid)"
"WHERE t.vid=%s "
"ORDER BY t.taskid"
)
self.db.dcur.execute(sql, (context.vessel.vid,))
for row in self.db.dcur.fetchall():
data = (
row['taskid'],
row['taskname'],
row['priority'],
row['taskstate'],
row['responsible']
)
self.lst_tasks.append(data)
self.load_list()
treeview.add_column(self.tree['tasks'], _('ID'), 0)
treeview.add_column(self.tree['tasks'], _('Name'), 1)
@@ -58,6 +42,25 @@ class TasksView(View):
self.dd_user = context.lookup.user()
combobox.load_from_dict(self.combo['responsible'], self.dd_user)
def load_list(self):
sql = (
"SELECT t.taskid, t.taskname, t.priority, t.taskstate, "
"u.displayname AS responsible "
"FROM task AS t JOIN user AS u ON (t.responsible=u.userid)"
"WHERE t.vid=%s "
"ORDER BY t.taskid"
)
self.db.dcur.execute(sql, (self.context.vessel.vid,))
for row in self.db.dcur.fetchall():
data = (
row['taskid'],
row['taskname'],
row['priority'],
row['taskstate'],
row['responsible']
)
self.lst_tasks.append(data)
def clear_record(self):
self.task.clear()
self.entry['name'].set_text('')
@@ -70,6 +73,7 @@ class TasksView(View):
combobox.activate_row(self.combo['status'], 'new')
combobox.activate_row(self.combo['responsible'], 0)
self.text['remarks'].get_buffer().set_text('')
self.entry['name'].grab_focus()
def display_record(self):
self.label['name'].set_text(self.task.taskname)
@@ -88,6 +92,7 @@ class TasksView(View):
combobox.activate_row(self.combo['taskstate'], self.task.taskstate)
combobox.activate_row(self.combo['responsible'], self.task.responsible)
self.text['remarks'].get_buffer().set_text(self.task.remarks or '')
self.entry['name'].grab_focus()
def save_record(self):
# fields must have been validated beforehand
@@ -151,12 +156,32 @@ class TasksView(View):
# buttons on edit page
def on_but_save_clicked(self, widget):
# check mandatory fields
if not self.entry['taskname'].get_text().strip():
if not self.entry['name'].get_text().strip():
# TODO error marker
return
self.save_record()
print(self.task)
self.task.save()
if self.newrecord:
self.load_list()
self.newrecord = False
else:
pass
# TODO aktuelle Listenzeile aktualisieren!
self.display_record()
self.topwidget.set_visible_child(self.box['task_detail'])
def on_but_plandate_clicked(self, widget):
pass
def on_but_duedate_clicked(self, widget):
pass
def on_but_started_clicked(self, widget):
pass
def on_but_finished_clicked(self, widget):
pass
def on_but_cancel_clicked(self, widget):
self.topwidget.set_visible_child(self.box['tasks'])
+15 -19
View File
@@ -32,20 +32,6 @@ class View:
self.topwidget = self.builder.get_object("topobject")
gtkutils.init_named_controls(self, self.builder)
css = Gtk.CssProvider()
css.load_from_data(b"""
.invalid {
color: #cc0000;
background-color: #ffdddd;
}
""")
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
css,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
def format_int(self, ival, separator=True, suffix=None, default=''):
if ival is None:
return default
@@ -133,16 +119,26 @@ class View:
else:
context.add_class("invalid")
def set_color_from_entry(self, entry):
def set_color_from_entry(self, entry, colorbutton):
# TODO this was a fast hack!
text = entry.get_text().strip()
rgba = Gdk.RGBA()
if len(text) == 7 and rgba.parse(text):
self.last_valid_rgb = text.lstrip('#')
self.entry['color'].set_text(text)
self.button['color'].set_rgba(rgba)
self.set_entry_valid(self.entry['color'], True)
self.entry.set_text(text)
colorbutton.set_rgba(rgba)
self.set_entry_valid(entry, True)
else:
self.set_entry_valid(self.entry['color'], False)
self.set_entry_valid(entry, False)
def get_checks(self, checkboxlist):
# checkbox helper function
# self.check[] from ui file
checks = []
for c in checkboxlist:
if c in self.check and self.check[c].get_active():
checks.append(c)
return ','.join(checks)
class DatePicker:
def __init__(self, entry, button, datefmt='"%d.%m.%Y"'):