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
+3
-2
@@ -1,8 +1,8 @@
|
||||
# SPDX-License-Identifier: WTFPL
|
||||
|
||||
"""
|
||||
Spezial:
|
||||
Notebook mit Vessel, User, Lists, Settings
|
||||
Special:
|
||||
Notebook with Vessel, User, Lists, Settings
|
||||
|
||||
"""
|
||||
|
||||
@@ -328,6 +328,7 @@ class BaseView(View):
|
||||
self.db.conn.commit()
|
||||
# Refresh dependent data
|
||||
self.load_dropdowns()
|
||||
self.context.publish("vessel_changed", (self.context.vessel.pk_value, ))
|
||||
# Show data
|
||||
self.display_vessel(self.context.vessel)
|
||||
|
||||
|
||||
+8
-4
@@ -126,9 +126,9 @@ class BoxesView(View):
|
||||
self.sbox.sid = combobox.get_list_value(self.combo['storage'])
|
||||
self.sbox.boxtype = combobox.get_list_value(self.combo['type'])
|
||||
self.sbox.content = self.entry['content'].get_text()
|
||||
self.sbox.wx = int(self.spin['wx'].get_value())
|
||||
self.sbox.wy = int(self.spin['wy'].get_value())
|
||||
self.sbox.wz = int(self.spin['wz'].get_value())
|
||||
self.sbox.wx = self.spin['wx'].get_value_as_int()
|
||||
self.sbox.wy = self.spin['wy'].get_value_as_int()
|
||||
self.sbox.wz = self.spin['wz'].get_value_as_int()
|
||||
self.sbox.color = self.entry['color'].get_text().lstrip('#')
|
||||
self.sbox.price = self.spin['price'].get_value()
|
||||
self.sbox.weight = self.spin['weight'].get_value()
|
||||
@@ -203,8 +203,12 @@ class BoxesView(View):
|
||||
r = round(rgba.red * 255)
|
||||
g = round(rgba.green * 255)
|
||||
b = round(rgba.blue * 255)
|
||||
a = round(rgba.alpha * 255)
|
||||
#self.last_valid_rgb = f"{r:02X}{g:02X}{b:02X}"
|
||||
self.entry['color'].set_text(f"#{r:02X}{g:02X}{b:02X}")
|
||||
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)
|
||||
|
||||
+70
-13
@@ -1,7 +1,7 @@
|
||||
# SPDX-License-Identifier: WTFPL
|
||||
|
||||
import os
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gtk, Gdk
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
@@ -16,12 +16,13 @@ class CablesView(View):
|
||||
self.cable = cable.Cable(context.db) # current record
|
||||
self.newrecord = False
|
||||
|
||||
self.lst_cables = Gtk.ListStore(int, str, str)
|
||||
self.lst_cables = Gtk.ListStore(int, str, 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)
|
||||
treeview.add_column(self.tree['cables'], _('Length'), 3)
|
||||
self.tree['cables'].set_model(self.lst_cables)
|
||||
|
||||
# Cable type
|
||||
@@ -41,21 +42,27 @@ class CablesView(View):
|
||||
combobox.load_from_dict(self.combo['condition'], self.dd_condition, 'unknown')
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['cables'])
|
||||
self.lst_cables.clear()
|
||||
sql = (
|
||||
"SELECT cableid, cablename, cablecond "
|
||||
"SELECT cableid, cablename, cablecond, length "
|
||||
"FROM cable "
|
||||
"WHERE vid=%s "
|
||||
"ORDER BY cableid"
|
||||
)
|
||||
self.db.dcur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['cables'].get_selection()
|
||||
for row in self.db.dcur.fetchall():
|
||||
data = (
|
||||
row['cableid'],
|
||||
row['cablename'],
|
||||
row['cablecond']
|
||||
row['cablecond'],
|
||||
self.format_float(row['length'], suffix='m')
|
||||
)
|
||||
self.lst_cables.append(data)
|
||||
treeiter = self.lst_cables.append(data)
|
||||
if row['cableid'] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.cable.cablename or '')
|
||||
@@ -83,36 +90,69 @@ class CablesView(View):
|
||||
|
||||
def edit_record(self):
|
||||
# fill UI fields from database record
|
||||
self.entry['name'].set_text(self.cable.cablename)
|
||||
self.entry['name'].set_text(self.cable.cablename or '')
|
||||
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['conductors'].set_value(self.cable.conductors or 0)
|
||||
self.spin['diameter'].set_value(self.cable.diameter or 0)
|
||||
self.spin['xsection'].set_value(self.cable.xsection or 0)
|
||||
self.spin['weight'].set_value(self.cable.weight or 0)
|
||||
self.entry['color'].set_text('#' + self.cable.color)
|
||||
rgba = Gdk.RGBA()
|
||||
rgba.parse('#' + self.cable.color)
|
||||
self.entry['color'].set_text(self.format_color(self.cable.color))
|
||||
if self.cable.color is None:
|
||||
rgba = Gdk.RGBA(0, 0, 0, 0)
|
||||
else:
|
||||
rgba = Gdk.RGBA()
|
||||
rgba.parse('#' + self.cable.color)
|
||||
self.button['color'].set_rgba(rgba)
|
||||
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 '')
|
||||
combobox.activate_row(self.combo['condition'], self.cable.cablecond or 'unknown')
|
||||
self.text['remarks'].get_buffer().set_text(self.cable.remarks or '')
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.cable.vid = self.context.vessel.vid
|
||||
self.cable.cablename = self.entry['name'].get_text().strip()
|
||||
self.cable.cabletype = combobox.get_list_value(self.combo['type'])
|
||||
if self.cable.cabletype == -1:
|
||||
self.cable.cabletype = None
|
||||
self.cable.length = int(self.spin['length'].get_value())
|
||||
self.cable.conductors = int(self.spin['conductors'].get_value())
|
||||
self.cable.diameter = self.spin['diameter'].get_value()
|
||||
self.cable.xsection = self.spin['xsection'].get_value()
|
||||
self.cable.weight = int(self.spin['weight'].get_value())
|
||||
if self.button['color'].get_rgba().alpha > 0:
|
||||
self.cable.color = self.entry['color'].get_text().lstrip('#')
|
||||
else:
|
||||
self.cable.color = None
|
||||
self.cable.supplier = combobox.get_list_value(self.combo['supplier'])
|
||||
if self.cable.supplier == -1:
|
||||
self.cable.supplier = None
|
||||
self.cable.manufacturer = combobox.get_list_value(self.combo['manufacturer'])
|
||||
self.cable.condition = combobox.get_list_value(self.combo['condition'])
|
||||
if self.cable.manufacturer == -1:
|
||||
self.cable.manufacturer = None
|
||||
self.cable.cablecond = combobox.get_list_value(self.combo['condition'])
|
||||
self.cable.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):
|
||||
@@ -122,6 +162,13 @@ class CablesView(View):
|
||||
self.topwidget.set_visible_child(self.box['cable_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text(_("Edit Cable"))
|
||||
cableid = treeview.get_value(self.tree['cables'], 0)
|
||||
if not cableid:
|
||||
return
|
||||
self.cable.load(cableid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['cable_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
@@ -163,6 +210,16 @@ class CablesView(View):
|
||||
return
|
||||
self.save_record()
|
||||
print(self.cable)
|
||||
if not self.cable.save():
|
||||
print("ERROR saving cable")
|
||||
# TODO error in infobox
|
||||
print(self.context.db.last_error())
|
||||
return
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['cable_detail'])
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['cables'])
|
||||
|
||||
+19
-10
@@ -37,21 +37,13 @@ class DocumentsView(View):
|
||||
self.uploaddialog.set_title("Upload new document")
|
||||
|
||||
self.lst_documents = Gtk.ListStore(int, str, str, str, int)
|
||||
sql = (
|
||||
"SELECT d.docid, d.doctype, d.filename, d.title, COUNT(r.drid) AS refcount "
|
||||
"FROM document AS d LEFT OUTER JOIN docref AS r USING (docid) "
|
||||
"GROUP BY d.docid, d.doctype, d.filename, d.title "
|
||||
"ORDER BY d.docid"
|
||||
)
|
||||
self.db.cur.execute(sql)
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_documents.append(row)
|
||||
self.load_list()
|
||||
|
||||
treeview.add_column(self.tree['documents'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['documents'], _('Type'), 1)
|
||||
treeview.add_column(self.tree['documents'], _('Filename'), 2)
|
||||
treeview.add_column(self.tree['documents'], _('Title'), 3)
|
||||
treeview.add_column(self.tree['documents'], _('References'), 3)
|
||||
treeview.add_column(self.tree['documents'], _('References'), 4)
|
||||
self.tree['documents'].set_model(self.lst_documents)
|
||||
|
||||
# Status
|
||||
@@ -61,6 +53,23 @@ class DocumentsView(View):
|
||||
self.dd_access = self.context.lookup.enum('document.roleaccess')
|
||||
combobox.load_from_dict(self.combo['accesslevel'], self.dd_access)
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['documents'])
|
||||
self.lst_documents.clear()
|
||||
sql = (
|
||||
"SELECT d.docid, d.doctype, d.filename, d.title, COUNT(r.drid) AS refcount "
|
||||
"FROM document AS d LEFT OUTER JOIN docref AS r USING (docid) "
|
||||
"GROUP BY d.docid, d.doctype, d.filename, d.title "
|
||||
"ORDER BY d.docid"
|
||||
)
|
||||
self.db.cur.execute(sql)
|
||||
selection = self.tree['documents'].get_selection()
|
||||
for row in self.db.cur.fetchall():
|
||||
treeiter = self.lst_documents.append(row)
|
||||
if row['docid'] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.doc.clear()
|
||||
combobox.activate_row(self.combo['doctype'], 'generic')
|
||||
|
||||
+39
-9
@@ -5,7 +5,7 @@ from gi.repository import GLib, Gtk, Gdk
|
||||
from dateutil.parser import parse
|
||||
from gettext import pgettext
|
||||
|
||||
from .view import View
|
||||
from .view import View, DatePicker
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.lookup import Dropdown
|
||||
from yms.model import equipment
|
||||
@@ -44,7 +44,29 @@ class EquipmentView(View):
|
||||
self.dd_condition = self.context.lookup.enum('equipment.econd')
|
||||
combobox.load_from_dict(self.combo['condition'], self.dd_condition, 'unknown')
|
||||
|
||||
self.entry['purchdate'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_purchdate = DatePicker(self.entry['purchdate'], self.button['purchdate'], context.get_datefmt())
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.equip.eid,
|
||||
self.equip.ename,
|
||||
self.dd_manufacturer.get(self.equip.manufacturer, ''),
|
||||
self.equip.model,
|
||||
self.equip.serial,
|
||||
self.format_date(self.equip.purchdate),
|
||||
self.equip.remarks
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_equipment.append(self.get_list_row())
|
||||
# TODO self.tree['equipment'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['equipment'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['equipment'])
|
||||
self.lst_equipment.clear()
|
||||
sql = (
|
||||
"SELECT e.eid, e.ename, c.compname, e.model, e.serial, "
|
||||
@@ -52,11 +74,17 @@ class EquipmentView(View):
|
||||
"FROM equipment AS e LEFT OUTER JOIN company AS c ON (e.manufacturer=c.compid) "
|
||||
"WHERE e.vid=%s "
|
||||
"ORDER BY e.ename"
|
||||
).format(self.context.datefmt.replace('%', '%%'))
|
||||
# ).format("%%d.%%m.%%Y") # TODO format from settings via mapping
|
||||
).format(self.context.get_datefmt().replace('%', '%%'))
|
||||
self.db.cur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['equipment'].get_selection()
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_equipment.append(row)
|
||||
treeiter = self.lst_equipment.append(row)
|
||||
if row[0] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def on_page_activated(self):
|
||||
print("Equipment activated")
|
||||
|
||||
def clear_record(self):
|
||||
self.equip.clear()
|
||||
@@ -208,12 +236,14 @@ class EquipmentView(View):
|
||||
return
|
||||
self.save_record()
|
||||
print(self.equip)
|
||||
self.equip.save()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
else:
|
||||
if not self.equip.save():
|
||||
# TODO error handling
|
||||
pass
|
||||
# TODO aktuelle Listenzeile aktualisieren!
|
||||
if self.newrecord:
|
||||
self.add_row()
|
||||
#self.load_list()
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['equip_detail'])
|
||||
|
||||
+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'])
|
||||
|
||||
+11
-5
@@ -55,6 +55,7 @@ class InventoryView(View):
|
||||
combobox.load_from_dict(self.combo['condition'], self.dd_condition)
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['inventory'])
|
||||
self.lst_inventory.clear()
|
||||
sql = (
|
||||
"SELECT i.invid, i.invname, s.sname AS container, i.number, i.invcond, i.remarks "
|
||||
@@ -65,9 +66,13 @@ class InventoryView(View):
|
||||
"WHERE s.vid=%s"
|
||||
)
|
||||
self.db.cur.execute(sql, (self.context.vessel.vid, self.context.vessel.vid))
|
||||
selection = self.tree['inventory'].get_selection()
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_inventory.append(row)
|
||||
|
||||
treeiter = self.lst_inventory.append(row)
|
||||
if row[0] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def lock_timer(self):
|
||||
self.context.db.lock_refresh(self.token)
|
||||
return True # continue timer
|
||||
@@ -96,9 +101,9 @@ class InventoryView(View):
|
||||
self.label['name'].set_text(self.inv.invname)
|
||||
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]))
|
||||
self.label['conttype'].set_text("{}: {}".format(container, self.dd_storage.get(self.inv.sid, '')))
|
||||
else:
|
||||
self.label['conttype'].set_text("{}: {}".format(container, self.dd_box[self.inv.boxid]))
|
||||
self.label['conttype'].set_text("{}: {}".format(container, self.dd_box.get(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'))
|
||||
@@ -255,7 +260,8 @@ class InventoryView(View):
|
||||
return
|
||||
self.save_record()
|
||||
print(self.inv)
|
||||
self.inv.save()
|
||||
if not self.inv.save():
|
||||
pass
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
|
||||
+81
-24
@@ -2,9 +2,12 @@
|
||||
|
||||
import os
|
||||
from gi.repository import Gtk
|
||||
from dateutil.parser import parse
|
||||
from datetime import datetime
|
||||
|
||||
from .view import View
|
||||
from .view import View, DatePicker
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.lookup import Dropdown
|
||||
from yms.model import maintenance
|
||||
|
||||
class MaintenanceView(View):
|
||||
@@ -16,15 +19,7 @@ class MaintenanceView(View):
|
||||
self.newrecord = False
|
||||
|
||||
self.lst_maintenance = Gtk.ListStore(int, str, str, str)
|
||||
sql = (
|
||||
"SELECT m.maintid, m.activities, e.ename, m.remarks "
|
||||
"FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid) "
|
||||
"WHERE m.vid=%s "
|
||||
"ORDER BY m.maintid"
|
||||
)
|
||||
self.db.cur.execute(sql, (context.vessel.vid,))
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_maintenance.append(row)
|
||||
self.load_list()
|
||||
|
||||
treeview.add_column(self.tree['maintenance'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['maintenance'], _('Activities'), 1)
|
||||
@@ -32,14 +27,49 @@ class MaintenanceView(View):
|
||||
treeview.add_column(self.tree['maintenance'], _('Remarks'), 3)
|
||||
self.tree['maintenance'].set_model(self.lst_maintenance)
|
||||
|
||||
# Equipment
|
||||
self.dd_equipment = self.context.lookup.equipment(context.vessel.vid)
|
||||
combobox.load_from_dict(self.combo['equipment'], {-1: _("─── none ───")} | self.dd_equipment)
|
||||
|
||||
# Plan date precision
|
||||
self.dd_precision = self.context.lookup.enum('maintenance.plan_precision')
|
||||
combobox.load_from_dict(self.combo['plan_precision'], self.dd_precision, 'month')
|
||||
|
||||
# Status
|
||||
self.dd_status = self.context.lookup.enum('maintenance.maintstate')
|
||||
combobox.load_from_dict(self.combo['status'], self.dd_status, 'new')
|
||||
|
||||
self.entry['plandate'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_plandate = DatePicker(self.entry['plandate'], self.button['plandate'], context.get_datefmt())
|
||||
self.entry['completion'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_completion = DatePicker(self.entry['completion'], self.button['completion'], context.get_datefmt())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['maintenance'])
|
||||
self.lst_maintenance.clear()
|
||||
sql = (
|
||||
"SELECT m.maintid, m.activities, e.ename, m.remarks "
|
||||
"FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid) "
|
||||
"WHERE m.vid=%s "
|
||||
"ORDER BY m.maintid"
|
||||
)
|
||||
self.db.cur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['maintenance'].get_selection()
|
||||
for row in self.db.cur.fetchall():
|
||||
treeiter = self.lst_maintenance.append(row)
|
||||
if row[0] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.maint.clear()
|
||||
self.entry['activities'].set_text('')
|
||||
combobox.activate_row(self.combo['equipment'], -1)
|
||||
self.spin['series'].set_value(0)
|
||||
self.spin['interval'].set_value(0)
|
||||
self.spin['last'].set_value(0)
|
||||
self.spin['series'].set_text('')
|
||||
self.spin['interval'].set_text('')
|
||||
self.spin['last_hours'].set_text('')
|
||||
self.entry['plandate'].set_text('')
|
||||
combobox.activate_row(self.combo['plan_precision'], 'month')
|
||||
self.entry['completion'].set_text('')
|
||||
combobox.activate_row(self.combo['status'], 'new')
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
@@ -57,31 +87,49 @@ class MaintenanceView(View):
|
||||
self.label['remarks'].set_text(self.maint.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['activities'].set_text(self.maint.activities)
|
||||
combobox.activate_row(self.combo['equipment'], self.maint.eid)
|
||||
self.entry['activities'].set_text(self.maint.activities or '')
|
||||
combobox.activate_row(self.combo['equipment'], self.maint.eid or -1)
|
||||
self.spin['series'].set_value(self.maint.series or 0)
|
||||
self.spin['interval'].set_value(self.maint.interval_hours or 0)
|
||||
self.spin['last'].set_value(self.maint.last_hours or 0)
|
||||
self.entry['plandate'].set_text(self.maint.plan_date)
|
||||
self.entry['completion'].set_text(self.maint.completion_date)
|
||||
self.spin['last_hours'].set_value(self.maint.last_hours or 0)
|
||||
self.entry['plandate'].set_text(self.format_date(self.maint.plan_date))
|
||||
self.entry['completion'].set_text(self.format_date(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
|
||||
self.maint.vid = self.context.vessel.vid
|
||||
self.maint.activities = self.entry['activities'].get_text()
|
||||
self.maint.eid = combobox.get_list_value(self.combo['equipment'])
|
||||
self.maint.series = int(self.spin['series'].get_value())
|
||||
self.maint.interval_hours = int(self.spin['interval'].get_value())
|
||||
self.maint.last_hours = int(self.spin['last'].get_value())
|
||||
self.maint.plan_date = self.entry['plandate'].get_text()
|
||||
self.maint.completion_date = self.entry['completion'].get_text()
|
||||
if self.maint.eid == -1:
|
||||
self.maint.eid = None
|
||||
self.maint.series = self.spin['series'].get_value_as_int()
|
||||
if self.maint.series == -1:
|
||||
self.maint.series = None
|
||||
self.maint.interval_hours = self.spin['interval'].get_value_as_int()
|
||||
if self.maint.interval_hours == 0:
|
||||
self.maint.interval_hours = None
|
||||
self.maint.last_hours = self.spin['last_hours'].get_value_as_int()
|
||||
if self.maint.last_hours == 0:
|
||||
self.maint.last_hours = None
|
||||
try:
|
||||
self.maint.plan_date = parse(self.entry['plandate'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.maint.plan_date = None
|
||||
try:
|
||||
self.maint.completion_date = parse(self.entry['completion'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.maint.completion_date = None
|
||||
self.maint.maintstate = combobox.get_list_value(self.combo['status'])
|
||||
self.maint.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.clear_record()
|
||||
self.newrecord = True
|
||||
print("New:Datefmt={}".format(self.context.datefmt))
|
||||
self.topwidget.set_visible_child(self.box['maint_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
@@ -132,7 +180,16 @@ class MaintenanceView(View):
|
||||
return
|
||||
self.save_record()
|
||||
print(self.maint)
|
||||
self.maint.save()
|
||||
if not self.maint.save():
|
||||
print("Save error")
|
||||
# TODO error in infobox
|
||||
print(self.context.db.last_error())
|
||||
return
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['maint_detail'])
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['maintenance'])
|
||||
+80
-28
@@ -12,6 +12,9 @@ class MeasurementView(View):
|
||||
|
||||
def __init__(self, context):
|
||||
super().__init__(context, _("Measurements"), "measurement.ui")
|
||||
self.infobar.set_revealed(False)
|
||||
self.infobar_label = Gtk.Label()
|
||||
self.infobar.get_content_area().add(self.infobar_label)
|
||||
|
||||
self.measure = measurement.Measurement(context.db) # current record
|
||||
self.newrecord = False
|
||||
@@ -22,9 +25,10 @@ class MeasurementView(View):
|
||||
|
||||
# accuracy
|
||||
self.dd_accuracy = self.context.lookup.enum('measurement.accuracy')
|
||||
combobox.load_from_dict(self.combo['accuracy'], {"-1": _("─── none ───")} | self.dd_accuracy)
|
||||
combobox.load_from_dict(self.combo['accuracy'], self.dd_accuracy, 'unknown')
|
||||
|
||||
# measurement units
|
||||
# ATTENTION: Minimum one element in list has to be defined!
|
||||
self.dd_unit = self.context.lookup.dropdown(Dropdown.UNIT)
|
||||
combobox.load_from_dict(self.combo['unit'], self.dd_unit, 1)
|
||||
|
||||
@@ -37,6 +41,19 @@ class MeasurementView(View):
|
||||
combobox.load_from_dict(self.combo['category'], {-1: _("─── none ───")} | self.dd_category)
|
||||
|
||||
self.lst_measurement = Gtk.ListStore(int, str, str, str, str, str)
|
||||
self.load_list()
|
||||
|
||||
treeview.add_column(self.tree['measurement'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['measurement'], _('Measurement'), 1)
|
||||
treeview.add_column(self.tree['measurement'], _('Value'), 2)
|
||||
treeview.add_column(self.tree['measurement'], _('Accuracy'), 3)
|
||||
treeview.add_column(self.tree['measurement'], _('Equipment'), 4)
|
||||
treeview.add_column(self.tree['measurement'], _('Note'), 5)
|
||||
self.tree['measurement'].set_model(self.lst_measurement)
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['measurement'])
|
||||
self.lst_measurement.clear()
|
||||
sql = (
|
||||
"SELECT m.mid, m.mname, m.nval, m.val1, m.val2, m.val3, m.unit, "
|
||||
"m.accuracy, m.note, e.ename "
|
||||
@@ -44,7 +61,8 @@ class MeasurementView(View):
|
||||
"WHERE m.vid=%s "
|
||||
"ORDER BY m.mid"
|
||||
)
|
||||
self.db.dcur.execute(sql, (context.vessel.vid,))
|
||||
self.db.dcur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['measurement'].get_selection()
|
||||
for row in self.db.dcur.fetchall():
|
||||
if row['nval'] == 1:
|
||||
value = "{} {}".format(row['val1'], row['unit'])
|
||||
@@ -63,23 +81,18 @@ class MeasurementView(View):
|
||||
row['ename'],
|
||||
row['note'] or ''
|
||||
)
|
||||
self.lst_measurement.append(data)
|
||||
|
||||
treeview.add_column(self.tree['measurement'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['measurement'], _('Measurement'), 1)
|
||||
treeview.add_column(self.tree['measurement'], _('Value'), 2)
|
||||
treeview.add_column(self.tree['measurement'], _('Accuracy'), 3)
|
||||
treeview.add_column(self.tree['measurement'], _('Equipment'), 4)
|
||||
treeview.add_column(self.tree['measurement'], _('Note'), 5)
|
||||
self.tree['measurement'].set_model(self.lst_measurement)
|
||||
treeiter = self.lst_measurement.append(data)
|
||||
if row[0] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.measure.clear()
|
||||
self.entry['name'].set_text('')
|
||||
combobox.activate_row(self.combo['dimensions'], -1)
|
||||
self.spin['val1'].set_value(0)
|
||||
self.spin['val2'].set_value(0)
|
||||
self.spin['val3'].set_value(0)
|
||||
combobox.activate_row(self.combo['dimensions'], 1)
|
||||
self.spin['val1'].set_text('')
|
||||
self.spin['val2'].set_text('')
|
||||
self.spin['val3'].set_text('')
|
||||
combobox.activate_row(self.combo['accuracy'], 'unknown')
|
||||
self.entry['date'].set_text('')
|
||||
combobox.activate_row(self.combo['equipment'], -1)
|
||||
@@ -87,29 +100,45 @@ class MeasurementView(View):
|
||||
self.text['note'].get_buffer().set_text('')
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
self.label['edit_val2'].set_visible(False)
|
||||
self.spin['val2'].set_visible(False)
|
||||
self.label['edit_val3'].set_visible(False)
|
||||
self.spin['val3'].set_visible(False)
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.measure.mname)
|
||||
self.label['dimensions'].set_text(self.measure.nval)
|
||||
self.label['val1'].set_text(self.measure.val1)
|
||||
self.label['dimensions'].set_text(self.dd_dimensions[self.measure.nval])
|
||||
self.label['val1'].set_text(self.format_int(self.measure.val1))
|
||||
if self.measure.nval >= 2:
|
||||
self.label['val2'].set_text(self.measure.val2 or '')
|
||||
self.label['val2'].set_text(self.format_int(self.measure.val2))
|
||||
else:
|
||||
self.label['val2'].set_text('n/a')
|
||||
if self.measure.nval == 3:
|
||||
self.label['val3'].set_text(self.measure.val3 or '')
|
||||
self.label['val3'].set_text(self.format_int(self.measure.val3))
|
||||
else:
|
||||
self.label['val3'].set_text('n/a')
|
||||
# TODO
|
||||
# unit
|
||||
# accuracy
|
||||
# category
|
||||
self.label['unit'].set_text(self.dd_unit.get(self.measure.unit, ''))
|
||||
self.label['accuracy'].set_text(self.dd_accuracy[self.measure.accuracy])
|
||||
self.label['date'].set_text(self.format_date(self.measure.mdate))
|
||||
self.label['category'].set_text(self.dd_category[self.measure.mcat])
|
||||
self.label['note'].set_text(self.measure.note or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['name'].set_text(self.measure.mname)
|
||||
combobox.activate_row(self.combo['dimensions'], self.measure.nval)
|
||||
self.spin['val1'].set_value(self.measure.val1)
|
||||
self.spin['val2'].set_value(self.measure.val2 or 0)
|
||||
self.spin['val3'].set_value(self.measure.val3 or 0)
|
||||
if self.measure.val1 is None:
|
||||
self.spin['val1'].set_text('')
|
||||
else:
|
||||
self.spin['val1'].set_value(self.measure.val1)
|
||||
if self.measure.val2 is None:
|
||||
self.spin['val2'].set_text('')
|
||||
else:
|
||||
self.spin['val2'].set_value(self.measure.val2)
|
||||
if self.measure.val3 is None:
|
||||
self.spin['val3'].set_text('')
|
||||
else:
|
||||
self.spin['val3'].set_value(self.measure.val3)
|
||||
combobox.activate_row(self.combo['unit'], self.measure.unit or 1)
|
||||
combobox.activate_row(self.combo['accuracy'], self.measure.accuracy)
|
||||
self.entry['date'].set_text(self.measure.mdate)
|
||||
combobox.activate_row(self.combo['equipment'], self.measure.eid)
|
||||
@@ -117,6 +146,11 @@ class MeasurementView(View):
|
||||
self.text['note'].get_buffer().set_text(self.task.note or '')
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
self.label['edit_val2'].set_visible(self.measure.nval > 1)
|
||||
self.spin['val2'].set_visible(self.measure.nval > 1)
|
||||
self.label['edit_val3'].set_visible(self.measure.nval > 2)
|
||||
self.spin['val3'].set_visible(self.measure.nval > 2)
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.measure.mname = self.entry['name'].get_text()
|
||||
@@ -124,7 +158,7 @@ class MeasurementView(View):
|
||||
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.accuracy = combobox.get_list_value(self.combo['accuracy'])
|
||||
self.measure.mdate = self.entry['date'].get_text()
|
||||
self.measure.eid = combobox.get_list_value(self.combo['equipment'])
|
||||
self.measure.mcat = combobox.get_list_value(self.combo['category'])
|
||||
@@ -163,6 +197,13 @@ class MeasurementView(View):
|
||||
self.topwidget.set_visible_child(self.box['measure_detail'])
|
||||
self.button['close'].grab_focus()
|
||||
|
||||
def on_cmb_dimensions_changed(self, widget):
|
||||
ndim = combobox.get_list_value(widget)
|
||||
self.label['edit_val2'].set_visible(ndim > 1)
|
||||
self.spin['val2'].set_visible(ndim > 1)
|
||||
self.label['edit_val3'].set_visible(ndim > 2)
|
||||
self.spin['val3'].set_visible(ndim > 2)
|
||||
|
||||
# buttons on detail page
|
||||
# edit2 uses edit callback
|
||||
def on_but_close_clicked(self, widget):
|
||||
@@ -180,12 +221,23 @@ class MeasurementView(View):
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
# check mandatory fields
|
||||
if not self.entry['mname'].get_text().strip():
|
||||
if not self.entry['name'].get_text().strip():
|
||||
# TODO error marker
|
||||
print("Save error mandatory fields missing")
|
||||
self.infobar.set_message_type(Gtk.MessageType.WARNING)
|
||||
self.infobar_label.set_text("Save error mandatory fields missing")
|
||||
self.infobar.set_revealed(True)
|
||||
return
|
||||
else:
|
||||
self.infobar_label.set_text('')
|
||||
self.infobar.set_revealed(False)
|
||||
self.save_record()
|
||||
print(self.measure)
|
||||
self.measure.save()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['measure_detail'])
|
||||
|
||||
|
||||
+55
-26
@@ -18,23 +18,7 @@ class ProjectsView(View):
|
||||
self.newrecord = False
|
||||
|
||||
self.lst_projects = Gtk.ListStore(int, str, str, int, str, str)
|
||||
sql = (
|
||||
"SELECT projid, projname, startdate, duration, projstate, remarks "
|
||||
"FROM project "
|
||||
"WHERE vid=%s "
|
||||
"ORDER BY projid"
|
||||
)
|
||||
self.db.dcur.execute(sql, (context.vessel.vid,))
|
||||
for row in self.db.dcur.fetchall():
|
||||
data = (
|
||||
row['projid'],
|
||||
row['projname'],
|
||||
self.format_date(row['startdate']),
|
||||
row['duration'],
|
||||
row['projstate'],
|
||||
row['remarks']
|
||||
)
|
||||
self.lst_projects.append(data)
|
||||
self.load_list()
|
||||
|
||||
treeview.add_column(self.tree['projects'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['projects'], _('Name'), 1)
|
||||
@@ -52,13 +36,38 @@ class ProjectsView(View):
|
||||
self.dd_state = self.context.lookup.enum('project.projstate')
|
||||
combobox.load_from_dict(self.combo['status'], self.dd_state)
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['projects'])
|
||||
self.lst_projects.clear()
|
||||
sql = (
|
||||
"SELECT projid, projname, startdate, duration, projstate, remarks "
|
||||
"FROM project "
|
||||
"WHERE vid=%s "
|
||||
"ORDER BY projid"
|
||||
)
|
||||
self.db.dcur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['projects'].get_selection()
|
||||
for row in self.db.dcur.fetchall():
|
||||
data = (
|
||||
row['projid'],
|
||||
row['projname'],
|
||||
self.format_date(row['startdate']),
|
||||
row['duration'],
|
||||
row['projstate'],
|
||||
row['remarks']
|
||||
)
|
||||
treeiter = self.lst_projects.append(data)
|
||||
if row['projid'] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.project.clear()
|
||||
self.entry['name'].set_text('')
|
||||
combobox.activate_row(self.combo['responsible'], 0)
|
||||
self.entry['date_start'].set_text('')
|
||||
self.spin['costs_plan'].set_value(0)
|
||||
self.spin['costs_final'].set_value(0)
|
||||
self.spin['costs_plan'].set_text('')
|
||||
self.spin['costs_final'].set_text('')
|
||||
combobox.activate_row(self.combo['status'], 'new')
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
self.entry['name'].grab_focus()
|
||||
@@ -76,15 +85,26 @@ class ProjectsView(View):
|
||||
def edit_record(self):
|
||||
self.entry['name'].set_text(self.project.projname)
|
||||
combobox.activate_row(self.combo['responsible'], self.project.responsible)
|
||||
self.entry['date_start'].set_text(self.project.startdate)
|
||||
self.spin['costs_plan'].set_value(self.project.costs_plan)
|
||||
self.spin['costs_final'].set_value(self.project.costs_final)
|
||||
self.entry['date_start'].set_text(self.format_date(self.project.startdate))
|
||||
if self.project.costs_plan:
|
||||
self.spin['duration'].set_value(self.project.duration)
|
||||
else:
|
||||
self.spin['duration'].set_text('')
|
||||
if self.project.costs_plan:
|
||||
self.spin['costs_plan'].set_value(self.project.costs_plan)
|
||||
else:
|
||||
self.spin['costs_plan'].set_text('')
|
||||
if self.project.costs_final:
|
||||
self.spin['costs_final'].set_value(self.project.costs_final)
|
||||
else:
|
||||
self.spin['costs_final'].set_text('')
|
||||
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
|
||||
self.project.vid = self.context.vessel.vid
|
||||
self.project.projname = self.entry['name'].get_text()
|
||||
self.project.responsible = combobox.get_list_value(self.combo['responsible'])
|
||||
self.project.costs_plan = int(self.spin['costs_plan'].get_value())
|
||||
@@ -103,9 +123,9 @@ class ProjectsView(View):
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text(_("Edit Project"))
|
||||
projid = treeview.get_value(self.tree['projects'], 0)
|
||||
if not projidid:
|
||||
if not projid:
|
||||
return
|
||||
self.measure.load(mid)
|
||||
self.project.load(projid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['proj_edit'])
|
||||
|
||||
@@ -142,12 +162,21 @@ class ProjectsView(View):
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
# check mandatory fields
|
||||
if not self.entry['projname'].get_text().strip():
|
||||
if not self.entry['name'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.project)
|
||||
self.project.save()
|
||||
if not self.project.save():
|
||||
print("Project save error")
|
||||
# TODO error in infobox
|
||||
print(self.context.db.last_error())
|
||||
return
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['proj_detail'])
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['projects'])
|
||||
@@ -44,10 +44,10 @@ class ProvisionsView(View):
|
||||
self.tree['provisions'].set_model(self.lst_provisions)
|
||||
|
||||
# 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)
|
||||
self.entry['storedate'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_storedate = DatePicker(self.entry['storedate'], self.button['storedate'], context.get_datefmt())
|
||||
self.entry['shelflife'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_shelflife = DatePicker(self.entry['shelflife'], self.button['shelflife'], context.get_datefmt())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['provisions'])
|
||||
@@ -58,6 +58,7 @@ class ProvisionsView(View):
|
||||
"WHERE s.vid=%s OR vid IS NULL"
|
||||
)
|
||||
self.db.dcur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['provisions'].get_selection()
|
||||
for row in self.db.dcur.fetchall():
|
||||
data = (
|
||||
row['provid'],
|
||||
@@ -144,13 +145,14 @@ class ProvisionsView(View):
|
||||
self.prov.unit = combobox.get_list_value(self.combo['unit'])
|
||||
if self.prov.unit == -1:
|
||||
self.prov.unit = None
|
||||
self.prov.calories = self.spin['calories'].get_value_as_int()
|
||||
# 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
|
||||
self.prov.storedate = None
|
||||
try:
|
||||
self.prov.shelflife = parse(self.entry['shelflife'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
|
||||
@@ -52,6 +52,13 @@ class StatusView:
|
||||
self.svg_centerline_y = 0.0
|
||||
self.load_svg()
|
||||
|
||||
# subscribe to data change events
|
||||
self.context.subscribe("vessel_changed", self.vessel_changed)
|
||||
|
||||
def vessel_changed(self, data):
|
||||
print(f"Vessel changed. New ID={data[0]}")
|
||||
self.load_svg()
|
||||
|
||||
def load_svg(self):
|
||||
if not self.context.vessel.shapefile:
|
||||
print("No Shapefile defined for current vessel")
|
||||
|
||||
@@ -38,7 +38,6 @@ class StorageView(View):
|
||||
pass
|
||||
|
||||
def refresh_row(self):
|
||||
pass
|
||||
treeview.set_value(self.tree['storage'], 1, self.storage.name)
|
||||
position = f"({self.storage.x}, {self.storage.y}, {self.storage.z})"
|
||||
treeview.set_value(self.tree['storage'], 2, position)
|
||||
|
||||
+55
-21
@@ -2,8 +2,10 @@
|
||||
|
||||
import os
|
||||
from gi.repository import Gtk
|
||||
from dateutil.parser import parse
|
||||
from datetime import datetime
|
||||
|
||||
from .view import View
|
||||
from .view import View, DatePicker
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.model import task
|
||||
|
||||
@@ -32,17 +34,24 @@ class TasksView(View):
|
||||
|
||||
# Priority
|
||||
self.dd_priority = self.context.lookup.enum('task.priority')
|
||||
combobox.load_from_dict(self.combo['priority'], self.dd_priority)
|
||||
combobox.load_from_dict(self.combo['priority'], self.dd_priority, 'low')
|
||||
|
||||
# Status
|
||||
self.dd_state = self.context.lookup.enum('task.taskstate')
|
||||
combobox.load_from_dict(self.combo['status'], self.dd_state)
|
||||
combobox.load_from_dict(self.combo['status'], self.dd_state, 'pending')
|
||||
|
||||
# Responsible
|
||||
self.dd_user = context.lookup.user()
|
||||
combobox.load_from_dict(self.combo['responsible'], self.dd_user)
|
||||
combobox.load_from_dict(self.combo['responsible'], self.dd_user, 0)
|
||||
|
||||
self.entry['plandate'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_plandate = DatePicker(self.entry['plandate'], self.button['plandate'], context.get_datefmt())
|
||||
self.entry['duedate'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_duedate = DatePicker(self.entry['duedate'], self.button['duedate'], context.get_datefmt())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['tasks'])
|
||||
self.lst_tasks.clear()
|
||||
sql = (
|
||||
"SELECT t.taskid, t.taskname, t.priority, t.taskstate, "
|
||||
"u.displayname AS responsible "
|
||||
@@ -51,6 +60,7 @@ class TasksView(View):
|
||||
"ORDER BY t.taskid"
|
||||
)
|
||||
self.db.dcur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['tasks'].get_selection()
|
||||
for row in self.db.dcur.fetchall():
|
||||
data = (
|
||||
row['taskid'],
|
||||
@@ -59,53 +69,77 @@ class TasksView(View):
|
||||
row['taskstate'],
|
||||
row['responsible']
|
||||
)
|
||||
self.lst_tasks.append(data)
|
||||
treeiter = self.lst_tasks.append(data)
|
||||
if row['taskid'] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.task.clear()
|
||||
self.entry['name'].set_text('')
|
||||
combobox.activate_row(self.combo['project'], -1)
|
||||
combobox.activate_row(self.combo['priority'], -1)
|
||||
combobox.activate_row(self.combo['priority'], 'low')
|
||||
self.entry['plandate'].set_text('')
|
||||
self.entry['duedate'].set_text('')
|
||||
self.entry['started'].set_text('')
|
||||
self.entry['finished'].set_text('')
|
||||
combobox.activate_row(self.combo['status'], 'new')
|
||||
combobox.activate_row(self.combo['status'], 'pending')
|
||||
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)
|
||||
self.label['responsible'].set_text('')
|
||||
self.label['project'].set_text(self.dd_project.get(self.task.projid, ''))
|
||||
self.label['priority'].set_text(self.dd_priority[self.task.priority])
|
||||
self.label['plandate'].set_text(self.format_date(self.task.plandate))
|
||||
self.label['duedate'].set_text(self.format_date(self.task.duedate))
|
||||
self.label['started'].set_text(self.format_datetime(self.task.started))
|
||||
self.label['finished'].set_text(self.format_datetime(self.task.finished))
|
||||
self.label['status'].set_text(self.task.taskstate)
|
||||
self.label['responsible'].set_text('')
|
||||
self.label['remarks'].set_text(self.task.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['name'].set_text(self.task.taskname)
|
||||
combobox.activate_row(self.combo['project'], self.task.projid)
|
||||
combobox.activate_row(self.combo['priority'], self.task.priority)
|
||||
self.entry['plandate'].set_text(self.task.plandate)
|
||||
self.entry['duedate'].set_text(self.task.duedate)
|
||||
self.entry['started'].set_text(self.task.started)
|
||||
self.entry['finished'].set_text(self.task.finsihed)
|
||||
combobox.activate_row(self.combo['taskstate'], self.task.taskstate)
|
||||
self.entry['plandate'].set_text(self.format_date(self.task.plandate))
|
||||
self.entry['duedate'].set_text(self.format_date(self.task.duedate))
|
||||
self.entry['started'].set_text(self.format_datetime(self.task.started))
|
||||
self.entry['finished'].set_text(self.format_datetime(self.task.finished))
|
||||
combobox.activate_row(self.combo['status'], 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
|
||||
self.task.vid = self.context.vessel.vid
|
||||
self.task.taskname = self.entry['name'].get_text()
|
||||
self.task.projid = combobox.get_list_value(self.combo['project'])
|
||||
self.task.priority = combobox.get_list_value(self.combo['project'])
|
||||
self.task.plandate = self.entry['plandate'].get_text()
|
||||
self.task.duedate = self.entry['duedate'].get_text()
|
||||
self.task.started = self.entry['started'].get_text()
|
||||
self.task.finished = self.entry['finished'].get_text()
|
||||
self.task.taskstate = combobox.get_list_value(self.combo['taskstate'])
|
||||
self.task.resposible = combobox.get_list_value(self.combo['responsible'])
|
||||
self.project.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
if self.task.projid == -1:
|
||||
self.task.projid = None
|
||||
self.task.priority = combobox.get_list_value(self.combo['priority'])
|
||||
try:
|
||||
self.task.plandate = parse(self.entry['plandate'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.task.plandate = None
|
||||
try:
|
||||
self.task.duedate = parse(self.entry['plandate'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.task.duedate = None
|
||||
try:
|
||||
self.task.started = parse(self.entry['started'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.task.started = None
|
||||
try:
|
||||
self.task.finished = parse(self.entry['finished'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.task.finished = None
|
||||
self.task.taskstate = combobox.get_list_value(self.combo['status'])
|
||||
self.task.responsible = combobox.get_list_value(self.combo['responsible'])
|
||||
self.task.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
|
||||
+27
-3
@@ -30,6 +30,10 @@ class View:
|
||||
self.builder.connect_signals(self)
|
||||
|
||||
self.topwidget = self.builder.get_object("topobject")
|
||||
self.infobar = self.builder.get_object("infobar")
|
||||
if self.infobar:
|
||||
self.infobar.set_revealed(False)
|
||||
|
||||
gtkutils.init_named_controls(self, self.builder)
|
||||
|
||||
def format_int(self, ival, separator=True, suffix=None, default=''):
|
||||
@@ -51,7 +55,23 @@ class View:
|
||||
def format_date(self, dval, default=''):
|
||||
if dval is None:
|
||||
return default
|
||||
return dval.strftime(self.context.datefmt)
|
||||
return dval.strftime(self.context.get_datefmt())
|
||||
|
||||
def format_datetime(self, dtval, default=''):
|
||||
# we do not use seconds!
|
||||
if dtval is None:
|
||||
return default
|
||||
return dtval.strftime(self.context.get_datefmt() + ' %H:%M')
|
||||
|
||||
def format_color(self, color, default=''):
|
||||
# alpha only for "no color"
|
||||
if not color or color.alpha == 0:
|
||||
return default
|
||||
else:
|
||||
r = round(color.red * 255)
|
||||
g = round(color.green * 255)
|
||||
b = round(color.blue * 255)
|
||||
return f"#{r:02X}{g:02X}{b:02X}"
|
||||
|
||||
def on_textview_keypress(self, widget, event):
|
||||
# Generic limit length function
|
||||
@@ -120,14 +140,18 @@ class View:
|
||||
context.add_class("invalid")
|
||||
|
||||
def set_color_from_entry(self, entry, colorbutton):
|
||||
# TODO this was a fast hack!
|
||||
text = entry.get_text().strip()
|
||||
if len(text) == 6:
|
||||
text = '#' + text
|
||||
rgba = Gdk.RGBA()
|
||||
if len(text) == 7 and rgba.parse(text):
|
||||
self.last_valid_rgb = text.lstrip('#')
|
||||
self.entry.set_text(text)
|
||||
entry.set_text(text.upper())
|
||||
colorbutton.set_rgba(rgba)
|
||||
self.set_entry_valid(entry, True)
|
||||
elif len(text) == 0:
|
||||
# set color to "no color" means: black with alpha=0
|
||||
colorbutton.set_rgba(Gdk.RGBA(0, 0, 0, 0))
|
||||
else:
|
||||
self.set_entry_valid(entry, False)
|
||||
|
||||
|
||||
Reference in new issue
Block a user