Native gui first steps: storage, box and companies are editable
This commit is contained in:
1 parent
1eea4058bf
commit
06a9834688
47 files changed
+3119
-883
No files matched your search
+62
-12
@@ -12,6 +12,8 @@ from gi.repository import GLib, Gtk, Gdk, Rsvg
|
||||
from datetime import datetime
|
||||
import subprocess
|
||||
import locale
|
||||
import xml.etree.ElementTree as ET
|
||||
import json
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
@@ -76,19 +78,29 @@ class BaseView(View):
|
||||
self.context.vessel.vesselname = "Ghost"
|
||||
|
||||
# default storage for current vessel
|
||||
sql = "SELECT sid, sname FROM storage WHERE stype=0 AND vid=%s ORDER BY sname"
|
||||
self.db.cur.execute(sql, (self.context.vessel.vid,))
|
||||
storages = dict(self.db.cur.fetchall())
|
||||
#sql = "SELECT sid, sname FROM storage WHERE stype=0 AND vid=%s ORDER BY sname"
|
||||
#self.db.cur.execute(sql, (self.context.vessel.vid,))
|
||||
#storages = dict(self.db.cur.fetchall())
|
||||
storages = self.context.lookup.storage(self.context.vessel.vid)
|
||||
combobox.load_from_dict(self.combo['storage'], {-1: _("─── none ───")} | storages)
|
||||
|
||||
# Hull types
|
||||
self.dd_htype = self.context.lookup.enum('vessel.htype')
|
||||
combobox.load_from_dict(self.combo['htype'], self.dd_htype)
|
||||
|
||||
# List of available shapes for combobox selection
|
||||
shapes = self.load_shapes()
|
||||
combobox.load_from_dict(self.combo['hull_shape'], {"-1": _("─── none ───")} | shapes)
|
||||
|
||||
# get list of vessels
|
||||
vessellist = {}
|
||||
self.db.dcur.execute("SELECT vid, vesselname, model FROM vessel ORDER BY vid")
|
||||
for row in self.db.dcur.fetchall():
|
||||
vessellist[row['vid']] = (
|
||||
row['vesselname'] if row['model'] is None
|
||||
else row['vesselname'] + " - " + row['model']
|
||||
)
|
||||
#vessellist = {}
|
||||
#self.db.dcur.execute("SELECT vid, vesselname, model FROM vessel ORDER BY vid")
|
||||
#for row in self.db.dcur.fetchall():
|
||||
# vessellist[row['vid']] = (
|
||||
# row['vesselname'] if row['model'] is None
|
||||
# else row['vesselname'] + " - " + row['model']
|
||||
# )
|
||||
vessellist = self.context.lookup.vessel()
|
||||
combobox.load_from_dict(self.combo['vessel'], vessellist, self.context.vessel.vid)
|
||||
# vessel load triggered from combobox init
|
||||
|
||||
@@ -138,6 +150,7 @@ 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)
|
||||
|
||||
@@ -149,6 +162,36 @@ class BaseView(View):
|
||||
storages = dict(self.db.cur.fetchall())
|
||||
combobox.refresh_dict(self.combo['storage'], {-1: _("─── none ───")} | storages)
|
||||
|
||||
def load_shapes(self):
|
||||
# TODO / WIP process shapeindex
|
||||
# returns dict of filename: title
|
||||
indexfile = os.path.join(self.context.cfg['docpath'], "shapeindex.json")
|
||||
if os.path.isfile(indexfile):
|
||||
# load json
|
||||
with open(indexfile, "r", encoding="utf-8") as fh:
|
||||
sflist = json.load(fh)
|
||||
print("Shapefile found and loaded")
|
||||
else:
|
||||
# create shapeindex (first simple version)
|
||||
sflist = {}
|
||||
for fname in os.listdir(self.context.cfg['shapedir']):
|
||||
if fname.lower().endswith(".svg"):
|
||||
shapefile = os.path.join(self.context.cfg['shapedir'], fname)
|
||||
try:
|
||||
root = ET.parse(shapefile).getroot()
|
||||
title_element = root.find("{http://www.w3.org/2000/svg}title")
|
||||
if title_element is not None and title_element.text:
|
||||
title = title_element.text.strip()
|
||||
else:
|
||||
title = os.path.splitext(fname)[0]
|
||||
except ET.ParseError:
|
||||
title = os.path.splitext(fname)[0]
|
||||
sflist[fname] = title
|
||||
with open(indexfile, "w", encoding="utf-8") as fh:
|
||||
json.dump(sflist, fh, ensure_ascii=False, indent=4)
|
||||
print("Created new shapeindex file")
|
||||
return sflist
|
||||
|
||||
def find_usb_sticks(self):
|
||||
result = []
|
||||
for name in os.listdir("/sys/block"):
|
||||
@@ -304,7 +347,6 @@ class BaseView(View):
|
||||
self.stack['vessel'].set_visible_child(self.box['vessel_edit'])
|
||||
|
||||
def on_but_vessel_save_clicked(self, widget):
|
||||
print("Save vessel")
|
||||
vessel = self.context.vessel
|
||||
vessel.vesselname = self.entry['vesselname'].get_text()
|
||||
vessel.model = self.entry['model'].get_text()
|
||||
@@ -316,6 +358,9 @@ class BaseView(View):
|
||||
vessel.draught_min = self.spin['draught_min'].get_value()
|
||||
vessel.displacement = self.spin['displacement'].get_value_as_int()
|
||||
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.shapefile = combobox.get_list_value(self.combo['hull_shape'])
|
||||
vessel.remarks = gtkutils.get_text_contents(self.text['vessel_remarks'])
|
||||
vessel.save()
|
||||
self.stack['vessel'].set_visible_child(self.box['vessel'])
|
||||
@@ -337,6 +382,7 @@ class BaseView(View):
|
||||
self.label['model'].set_text(vessel.model or '')
|
||||
self.label['shipyard'].set_text(str(vessel.shipyard))
|
||||
self.label['year_built'].set_text(self.format_int(vessel.year_built, False, default='n/a'))
|
||||
self.label['hull_number'].set_text(vessel.hull_number or '')
|
||||
self.label['loa'].set_text(self.format_float(vessel.loa, 2, suffix="m"))
|
||||
self.label['lwl'].set_text(self.format_float(vessel.lwl, 2, suffix="m"))
|
||||
self.label['beam'].set_text(self.format_float(vessel.beam, 2, suffix="m"))
|
||||
@@ -361,9 +407,13 @@ class BaseView(View):
|
||||
self.spin['draught_min'].set_value(vessel.draught_min or 0)
|
||||
self.spin['displacement'].set_value(vessel.displacement or 0)
|
||||
self.spin['ballast'].set_value(vessel.ballast or 0)
|
||||
self.text['vessel_remarks'].get_buffer().set_text(vessel.remarks or '')
|
||||
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['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 '')
|
||||
|
||||
def display_user(self, user):
|
||||
self.entry['user_login'].set_text(user.login)
|
||||
|
||||
+95
-24
@@ -19,15 +19,7 @@ class BoxesView(View):
|
||||
self.newrecord = False
|
||||
|
||||
self.lst_box = Gtk.ListStore(int, str, str, str)
|
||||
sql = (
|
||||
"SELECT b.boxid, b.label, b.content, b.remarks "
|
||||
"FROM box AS b JOIN storage AS s USING (sid) "
|
||||
"WHERE s.vid=%s "
|
||||
"ORDER BY b.label"
|
||||
)
|
||||
self.db.cur.execute(sql, (context.vessel.vid,))
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_box.append(row)
|
||||
self.load_list()
|
||||
|
||||
treeview.add_column(self.tree['box'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['box'], _('Label'), 1)
|
||||
@@ -35,25 +27,53 @@ class BoxesView(View):
|
||||
treeview.add_column(self.tree['box'], _('Remarks'), 3)
|
||||
self.tree['box'].set_model(self.lst_box)
|
||||
|
||||
self.dd_storage = self.context.lookup.storage(context.vessel.vid)
|
||||
combobox.load_from_dict(self.combo['storage'], {-1: _("─── none ───")} | self.dd_storage)
|
||||
self.dd_boxtype = self.context.lookup.dropdown(Dropdown.BOX_TYPE)
|
||||
combobox.load_from_dict(self.combo['type'], self.dd_boxtype)
|
||||
combobox.load_from_dict(self.combo['type'], {-1: _("─── none ───")} | self.dd_boxtype)
|
||||
|
||||
def load_list(self):
|
||||
pass
|
||||
selected_id = treeview.get_value(self.tree['box'])
|
||||
self.lst_box.clear()
|
||||
sql = (
|
||||
"SELECT b.boxid, b.label, b.content, b.remarks "
|
||||
"FROM box AS b JOIN storage AS s USING (sid) "
|
||||
"WHERE s.vid=%s "
|
||||
"ORDER BY b.label"
|
||||
)
|
||||
self.db.cur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['box'].get_selection()
|
||||
for row in self.db.cur.fetchall():
|
||||
treeiter = self.lst_box.append(row)
|
||||
if row[0] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.entry['label'].set_text('')
|
||||
combobox.activate_row(self.combo['storage'], 0)
|
||||
combobox.activate_row(self.combo['type'], -1)
|
||||
self.entry['content'].set_text('')
|
||||
self.spin['wx'].set_value(0)
|
||||
self.spin['wy'].set_value(0)
|
||||
self.spin['wz'].set_value(0)
|
||||
self.entry['color'].set_text('#000000')
|
||||
rgba = Gdk.RGBA()
|
||||
rgba.parse('#000000')
|
||||
self.button['color'].set_rgba(rgba)
|
||||
self.spin['price'].set_value(0)
|
||||
self.spin['weight'].set_value(0)
|
||||
self.spin['weight_net'].set_value(0)
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
|
||||
def display_record(self):
|
||||
self.label['label'].set_text(self.sbox.label)
|
||||
# storage sid
|
||||
self.label['content'].set_text(self.sbox.content or '')
|
||||
self.label['type'].set_text(self.dd_boxtype[self.sbox.boxtype])
|
||||
if self.sbox.boxtype > 0:
|
||||
self.label['type'].set_text(self.dd_boxtype[self.sbox.boxtype])
|
||||
else:
|
||||
self.label['type'].set_text('')
|
||||
self.label['color'].set_text(self.sbox.color or '')
|
||||
if self.sbox.color:
|
||||
self.label['color'].set_markup(f'#{self.sbox.color} <span foreground="#{self.sbox.color}">●</span>')
|
||||
@@ -66,23 +86,50 @@ class BoxesView(View):
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['label'].set_text(self.sbox.label)
|
||||
combobox.activate_row(self.combo['storage'], self.sbox.sid)
|
||||
combobox.activate_row(self.combo['type'], self.sbox.boxtype)
|
||||
self.entry['content'].set_text(self.sbox.content or '')
|
||||
self.spin['wx'].set_value(self.sbox.wx or 0)
|
||||
self.spin['wy'].set_value(self.sbox.wy or 0)
|
||||
self.spin['wz'].set_value(self.sbox.wz or 0)
|
||||
self.entry['color'].set_text('#' + self.sbox.color)
|
||||
rgba = Gdk.RGBA()
|
||||
rgba.parse('#' + self.sbox.color)
|
||||
self.button['color'].set_rgba(rgba)
|
||||
self.spin['price'].set_value(self.sbox.price or 0)
|
||||
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 '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.sbox.label = self.entry['label'].get_text()
|
||||
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.color = self.entry['color'].get_text().lstrip('#')
|
||||
self.sbox.price = self.spin['price'].get_value()
|
||||
self.sbox.weight = self.spin['weight'].get_value()
|
||||
self.sbox.weight_net = self.spin['weight_net'].get_value()
|
||||
self.sbox.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text("Add new Box")
|
||||
self.label['title_edit'].set_text(_("Add new Box"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['box_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text("Edit Box")
|
||||
sid = treeview.get_value(self.tree['box'], 0)
|
||||
self.sbox.load(sid)
|
||||
self.label['title_edit'].set_text(_("Edit Box"))
|
||||
boxid = treeview.get_value(self.tree['box'], 0)
|
||||
if not boxid:
|
||||
return
|
||||
self.sbox.load(boxid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['box_edit'])
|
||||
|
||||
@@ -105,24 +152,48 @@ class BoxesView(View):
|
||||
# buttons on detail page
|
||||
# edit2 uses edit callback
|
||||
def on_but_close_clicked(self, widget):
|
||||
boxid = treeview.get_value(self.tree['box'], 0)
|
||||
if not boxid:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['box'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete box!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['box'])
|
||||
self.newrecord = False
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
print("save not implemented yet")
|
||||
# check mandatory fields
|
||||
if not self.entry['label'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.sbox)
|
||||
self.sbox.save()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['box_detail'])
|
||||
|
||||
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)
|
||||
#self.last_valid_rgb = f"{r:02X}{g:02X}{b:02X}"
|
||||
self.entry['color'].set_text(f"#{r:02X}{g:02X}{b:02X}")
|
||||
|
||||
def on_ent_color_activate(self, entry):
|
||||
self.set_color_from_entry(entry)
|
||||
|
||||
def on_ent_color_focus_out_event(self, entry, event):
|
||||
self.set_color_from_entry(entry)
|
||||
return False
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['box'])
|
||||
self.newrecord = False
|
||||
|
||||
def on_but_color_clicked(self, widget):
|
||||
pass
|
||||
|
||||
+67
-24
@@ -40,6 +40,59 @@ class CablesView(View):
|
||||
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])
|
||||
if self.cable.techname:
|
||||
self.label['techname'].set_text(self.dd_tech[self.cable.techname])
|
||||
else:
|
||||
self.label['techname'].set_text('')
|
||||
self.label['length'].set_text(self.format_int(self.cable.length))
|
||||
self.label['conductors'].set_text(self.format_int(self.cable.conductors))
|
||||
self.label['diameter'].set_text(self.format_float(self.cable.diameter, 1))
|
||||
self.label['xsection'].set_text(self.format_float(self.cable.xsection, 1))
|
||||
self.label['weight'].set_text(self.format_float(self.cable.weight))
|
||||
if self.cable.color:
|
||||
self.label['color'].set_markup(f'#{self.cable.color} <span foreground="#{self.cable.color}">●</span>')
|
||||
else:
|
||||
self.label['color'].set_text('')
|
||||
self.label['supplier'].set_text(str(self.cable.supplier))
|
||||
self.label['manufacturer'].set_text(str(self.cable.manufacturer))
|
||||
self.label['condition'].set_text(self.cable.cablecond)
|
||||
self.label['remarks'].set_text(self.cable.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
# 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)
|
||||
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)
|
||||
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.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)
|
||||
self.text['remarks'].get_buffer().set_text(self.sbox.remarks or '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.cable.cablename = self.entry['name'].get_text().strip()
|
||||
self.cable.cabletype = combobox.get_list_value(self.combo['type'])
|
||||
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())
|
||||
self.cable.supplier = combobox.get_list_value(self.combo['supplier'])
|
||||
self.cable.manufacturer = combobox.get_list_value(self.combo['manufacturer'])
|
||||
self.cable.condition = combobox.get_list_value(self.combo['condition'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['cable_edit'])
|
||||
@@ -68,35 +121,25 @@ class CablesView(View):
|
||||
self.topwidget.set_visible_child(self.box['cables'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete cable!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['cables'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
# check mandatory fields:
|
||||
# name, type, length, conductors, xsection
|
||||
cname = self.entry['name'].get_text().strip()
|
||||
if not cname:
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.cable)
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['cables'])
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.cable.cablename)
|
||||
self.label['type'].set_text(self.dd_type[self.cable.cabletype])
|
||||
if self.cable.techname:
|
||||
self.label['techname'].set_text(self.dd_tech[self.cable.techname])
|
||||
else:
|
||||
self.label['techname'].set_text('')
|
||||
self.label['length'].set_text(self.format_int(self.cable.length))
|
||||
self.label['conductors'].set_text(self.format_int(self.cable.conductors))
|
||||
self.label['diameter'].set_text(self.format_float(self.cable.diameter, 1))
|
||||
self.label['xsection'].set_text(self.format_float(self.cable.xsection, 1))
|
||||
self.label['weight'].set_text(self.format_float(self.cable.weight))
|
||||
if self.cable.color:
|
||||
self.label['color'].set_markup(f'#{self.cable.color} <span foreground="#{self.cable.color}">●</span>')
|
||||
else:
|
||||
self.label['color'].set_text('')
|
||||
self.label['supplier'].set_text(str(self.cable.supplier))
|
||||
self.label['manufacturer'].set_text(str(self.cable.manufacturer))
|
||||
self.label['condition'].set_text(self.cable.cablecond)
|
||||
self.label['remarks'].set_text(self.cable.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
+75
-12
@@ -18,29 +18,42 @@ class CompaniesView(View):
|
||||
self.newrecord = False
|
||||
|
||||
# company types
|
||||
self.db.cur.execute("SELECT ddval, ddtext FROM dropdown WHERE ddid=2 ORDER BY ddval")
|
||||
self.comptype = dict(self.db.cur.fetchall())
|
||||
combobox.load_from_dict(self.combo['flt_type'], {-2: _("─── all ───")} | self.comptype, -2)
|
||||
|
||||
self.dd_comptype = self.context.lookup.dropdown(Dropdown.COMPANY_TYPE)
|
||||
combobox.load_from_dict(self.combo['comptype'], self.dd_comptype)
|
||||
combobox.load_from_dict(self.combo['comptype2'], self.dd_comptype)
|
||||
combobox.load_from_dict(self.combo['flt_type'], {-2: _("─── all ───"), -1: _("─── none ───")} | self.dd_comptype, -2)
|
||||
combobox.load_from_dict(self.combo['comptype'], self.dd_comptype, company.SUPPLIER)
|
||||
combobox.load_from_dict(self.combo['comptype2'], {-1: _("─── none ───")} | self.dd_comptype)
|
||||
|
||||
self.dd_flags = context.lookup.enum('company.flags')
|
||||
|
||||
# companies
|
||||
self.lst_companies = Gtk.ListStore(int, str, str, str)
|
||||
self.db.cur.execute("SELECT compid, compname, comptype, remarks FROM company ORDER BY compname")
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_companies.append((row[0], row[1], self.comptype[row[2]], row[3]))
|
||||
self.load_list()
|
||||
|
||||
treeview.add_column(self.tree['companies'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['companies'], _('Name'), 1)
|
||||
treeview.add_column(self.tree['companies'], _('Type'), 2)
|
||||
treeview.add_column(self.tree['companies'], _('Remarks'), 3)
|
||||
self.tree['companies'].set_model(self.lst_companies)
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['companies'])
|
||||
self.lst_companies.clear()
|
||||
sql = (
|
||||
"SELECT compid, compname, comptype, remarks "
|
||||
"FROM company "
|
||||
"WHERE compid >= 0 "
|
||||
"ORDER BY compname"
|
||||
)
|
||||
self.db.cur.execute(sql)
|
||||
selection = self.tree['companies'].get_selection()
|
||||
for row in self.db.cur.fetchall():
|
||||
treeiter = self.lst_companies.append((row[0], row[1], self.dd_comptype[row[2]], row[3]))
|
||||
if row[0] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.entry['name'].set_text('')
|
||||
self.entry['compname'].set_text('')
|
||||
self.entry['shortname'].set_text('')
|
||||
self.entry['street'].set_text('')
|
||||
self.entry['zip'].set_text('')
|
||||
@@ -52,7 +65,7 @@ class CompaniesView(View):
|
||||
self.entry['web'].set_text('')
|
||||
self.entry['customerno'].set_text('')
|
||||
self.entry['contractno'].set_text('')
|
||||
combobox.activate_row(self.combo['comptype'], -1)
|
||||
combobox.activate_row(self.combo['comptype'], company.SUPPLIER)
|
||||
combobox.activate_row(self.combo['comptype2'], -1)
|
||||
|
||||
def display_record(self):
|
||||
@@ -76,6 +89,8 @@ class CompaniesView(View):
|
||||
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)
|
||||
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 '')
|
||||
@@ -87,15 +102,44 @@ 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 '')
|
||||
self.text['remarks'].get_buffer().set_text(self.comp.remarks or '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.comp.compname = self.entry['compname'].get_text()
|
||||
self.comp.comptype = combobox.get_list_value(self.combo['comptype'])
|
||||
self.comp.comptype2 = combobox.get_list_value(self.combo['comptype2'])
|
||||
if self.comp.comptype2 < 0:
|
||||
self.comp.comptype2 = None
|
||||
self.comp.shortname = self.entry['shortname'].get_text()
|
||||
self.comp.street = self.entry['street'].get_text()
|
||||
self.comp.zip = self.entry['zip'].get_text()
|
||||
self.comp.city = self.entry['city'].get_text()
|
||||
self.comp.country = self.entry['country'].get_text()
|
||||
self.comp.contact = self.entry['contact'].get_text()
|
||||
self.comp.phone = self.entry['phone'].get_text()
|
||||
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.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text(_("Add new Company"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['comp_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
compid = treeview.get_value(self.tree['companies'], 0)
|
||||
if not compid:
|
||||
return
|
||||
self.comp.load(compid)
|
||||
self.edit_record()
|
||||
self.label['title_edit'].set_text(_("Edit Company"))
|
||||
|
||||
self.topwidget.set_visible_child(self.box['comp_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
@@ -118,11 +162,30 @@ class CompaniesView(View):
|
||||
self.topwidget.set_visible_child(self.box['companies'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete company!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['companies'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
# check mandatory fields:
|
||||
compname = self.entry['compname'].get_text().strip()
|
||||
# TODO type
|
||||
if not compname:
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.comp)
|
||||
self.comp.save()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['comp_detail'])
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['companies'])
|
||||
+130
-34
@@ -3,6 +3,7 @@
|
||||
import os
|
||||
from gi.repository import GLib, Gtk, Gdk, GdkPixbuf, Rsvg
|
||||
import fitz
|
||||
import sane
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
@@ -17,6 +18,10 @@ class DocumentsView(View):
|
||||
self.doc = document.Document(context.db) # current record
|
||||
self.newrecord = False
|
||||
|
||||
self.scandialog = self.builder.get_object("dlg_scanner")
|
||||
print(self.scandialog)
|
||||
# TODO self.uploaddialog = self.builder.get_object("dlg_upload")
|
||||
|
||||
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 "
|
||||
@@ -35,41 +40,20 @@ class DocumentsView(View):
|
||||
treeview.add_column(self.tree['documents'], _('References'), 3)
|
||||
self.tree['documents'].set_model(self.lst_documents)
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['doc_edit'])
|
||||
# Status
|
||||
self.dd_type = self.context.lookup.enum('document.doctype')
|
||||
combobox.load_from_dict(self.combo['doctype'], self.dd_type)
|
||||
# Roleaccess
|
||||
self.dd_access = self.context.lookup.enum('document.roleaccess')
|
||||
combobox.load_from_dict(self.combo['accesslevel'], self.dd_access)
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['doc_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
docid = treeview.get_value(self.tree['documents'], 0)
|
||||
self.doc.load(docid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['doc_detail'])
|
||||
self.button['close'].grab_focus()
|
||||
|
||||
def on_tvw_documents_row_activated(self, widget, path, column):
|
||||
docid = treeview.get_value(widget, 0)
|
||||
self.doc.load(docid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['doc_detail'])
|
||||
self.button['close'].grab_focus()
|
||||
|
||||
# buttons on detail page
|
||||
# edit2 uses edit callback
|
||||
def on_but_close_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['documents'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['documents'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['documents'])
|
||||
def clear_record(self):
|
||||
self.doc.clear()
|
||||
combobox.activate_row(self.combo['doctype'], 'generic')
|
||||
self.entry['title'].set_text('')
|
||||
self.entry['filename'].set_text('')
|
||||
combobox.activate_row(self.combo['accesslevel'], 'captain')
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
|
||||
def pdf_to_pixbuf(self, filename, max_width=400, max_height=400):
|
||||
doc = fitz.open(filename)
|
||||
@@ -135,4 +119,116 @@ class DocumentsView(View):
|
||||
self.image['preview'].clear()
|
||||
|
||||
def edit_record(self):
|
||||
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 '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.doc.doctype = combobox.get_list_value(self.combo['type'])
|
||||
self.doc.title = self.entry['title'].get_text()
|
||||
self.doc.filename = self.entry['filename'].get_text()
|
||||
self.doc.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text(_("Add new Document"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['doc_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
docid = treeview.get_value(self.tree['documents'], 0)
|
||||
if docid is None:
|
||||
return
|
||||
self.doc.load(docid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['doc_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
docid = treeview.get_value(self.tree['documents'], 0)
|
||||
if docid is None:
|
||||
return
|
||||
self.doc.load(docid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['doc_detail'])
|
||||
self.button['close'].grab_focus()
|
||||
|
||||
def on_tvw_documents_row_activated(self, widget, path, column):
|
||||
docid = treeview.get_value(widget, 0)
|
||||
self.doc.load(docid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['doc_detail'])
|
||||
self.button['close'].grab_focus()
|
||||
|
||||
# buttons on detail page
|
||||
# edit2 uses edit callback
|
||||
def on_but_close_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['documents'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete document!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['documents'])
|
||||
|
||||
def scan_progress(self, current_line, total_lines):
|
||||
print(f"Fortschritt: {current_line} / {total_lines}")
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_scan_clicked(self, widget):
|
||||
"""
|
||||
# python sane
|
||||
tl-x: X-Koordinate der linken oberen Ecke
|
||||
tl-y: Y-Koordinate der linken oberen Ecke
|
||||
br-x: X-Koordinate der rechten unteren Ecke
|
||||
br-y: Y-Koordinate der rechten unteren Ecke
|
||||
verfügbarer bereich ist über constraints ermittelbar
|
||||
verfügbare resolution auch über constraints
|
||||
verfügbare modes auch über constraints
|
||||
Einheit: sane.UNIT_MM
|
||||
scanner.tl_x = 10.0
|
||||
scanner.tl_y = 10.0
|
||||
scanner.br_x = 100.0
|
||||
scanner.br_y = 150.0
|
||||
"""
|
||||
|
||||
response = self.scandialog.run()
|
||||
self.scandialog.hide()
|
||||
if response == Gtk.ResponseType.OK:
|
||||
print("OK")
|
||||
else:
|
||||
print("Not OK")
|
||||
|
||||
# sane.init()
|
||||
# devices = sane.get_devices()
|
||||
# if more than one device: Show device selector
|
||||
# device_name = devices[0][0]
|
||||
# scanner = sane.open(device_name)
|
||||
# scanner.get_options()
|
||||
# Options: index, name, title, desc, opt_type, unit, size, cap, constraint
|
||||
# option.is_active()
|
||||
# option.is_settable()
|
||||
# scanner.get_parameters()
|
||||
# format, last_frame, (pixels_per_line, lines), depth = scanner.get_parameters()
|
||||
# scanner.mode = "Color"
|
||||
# scanner.resolution = 150
|
||||
# image = scanner.scan(progress=self.scan_progress)
|
||||
# image.save("scan.png")
|
||||
# scanner.close()
|
||||
# sane.exit()
|
||||
pass
|
||||
|
||||
def on_but_upload_clicked(self, widget):
|
||||
pass
|
||||
|
||||
def on_but_save_clicked(self, widget):
|
||||
print(self.doc)
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['documents'])
|
||||
|
||||
+145
-34
@@ -2,6 +2,7 @@
|
||||
|
||||
import os
|
||||
from gi.repository import GLib, Gtk, Gdk
|
||||
from dateutil.parser import parse
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
@@ -18,16 +19,7 @@ class EquipmentView(View):
|
||||
self.newrecord = False
|
||||
|
||||
self.lst_equipment = Gtk.ListStore(int, str, str, str, str, str, str)
|
||||
sql = (
|
||||
"SELECT e.eid, e.ename, c.compname, e.model, e.serial, "
|
||||
"DATE_FORMAT(e.purchdate, '{}'), e.remarks "
|
||||
"FROM equipment AS e LEFT OUTER JOIN company AS c ON (e.manufacturer=c.compid) "
|
||||
"WHERE e.vid=%s "
|
||||
"ORDER BY e.ename"
|
||||
).format("%%d.%%m.%%Y") # TODO format from settings via mapping
|
||||
self.db.cur.execute(sql, (context.vessel.vid,))
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_equipment.append(row)
|
||||
self.load_list()
|
||||
|
||||
treeview.add_column(self.tree['equipment'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['equipment'], _('Name'), 1)
|
||||
@@ -38,23 +30,132 @@ class EquipmentView(View):
|
||||
treeview.add_column(self.tree['equipment'], _('Remarks'), 6)
|
||||
self.tree['equipment'].set_model(self.lst_equipment)
|
||||
|
||||
# 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)
|
||||
# Category
|
||||
self.dd_category = self.context.lookup.dropdown(Dropdown.EQUIPMENT_CATEGORY)
|
||||
#combobox.load_from_dict(self.combo['unit'], self.dd_unit)
|
||||
combobox.load_from_dict(self.combo['category'], {-1: _("─── none ───")} | self.dd_category)
|
||||
# Condition
|
||||
self.dd_condition = self.context.lookup.enum('equipment.econd')
|
||||
combobox.load_from_dict(self.combo['condition'], self.dd_condition, 'unknown')
|
||||
|
||||
def load_list(self):
|
||||
self.lst_equipment.clear()
|
||||
sql = (
|
||||
"SELECT e.eid, e.ename, c.compname, e.model, e.serial, "
|
||||
"DATE_FORMAT(e.purchdate, '{}'), e.remarks "
|
||||
"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
|
||||
self.db.cur.execute(sql, (self.context.vessel.vid,))
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_equipment.append(row)
|
||||
|
||||
def clear_record(self):
|
||||
self.equip.clear()
|
||||
self.entry['name'].set_text('')
|
||||
self.entry['shortname'].set_text('')
|
||||
combobox.activate_row(self.combo['manufacturer'], -1)
|
||||
self.entry['model'].set_text('')
|
||||
self.entry['serial'].set_text('')
|
||||
self.spin['weight'].set_value(0)
|
||||
self.spin['price'].set_value(0)
|
||||
self.entry['purchdate'].set_text('')
|
||||
combobox.activate_row(self.combo['supplier'], -1)
|
||||
combobox.activate_row(self.combo['category'], -1)
|
||||
combobox.activate_row(self.combo['condition'], 'unknown')
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
|
||||
def display_record(self):
|
||||
print(self.equip)
|
||||
self.label['name'].set_text(self.equip.ename)
|
||||
self.label['shortname'].set_text(self.equip.shortname or '')
|
||||
if self.equip.manufacturer:
|
||||
self.label['manufacturer'].set_text(self.dd_manufacturer[self.equip.manufacturer])
|
||||
else:
|
||||
self.label['manufacturer'].set_text('')
|
||||
self.label['model'].set_text(self.equip.model or '')
|
||||
self.label['serial'].set_text(self.equip.serial or '')
|
||||
self.label['weight'].set_text(self.format_float(self.equip.weight, 2, suffix='kg'))
|
||||
self.label['price'].set_text(self.format_float(self.equip.price, 2, suffix='€'))
|
||||
self.label['purchdate'].set_text(self.format_date(self.equip.purchdate))
|
||||
if self.equip.supplier:
|
||||
self.label['supplier'].set_text(self.dd_supplier[self.equip.supplier])
|
||||
else:
|
||||
self.label['supplier'].set_text('')
|
||||
if self.equip.ecat:
|
||||
self.label['category'].set_text(self.dd_category[self.equip.ecat])
|
||||
else:
|
||||
self.label['category'].set_text('')
|
||||
self.label['flags'].set_text(self.equip.flags or '')
|
||||
self.label['remarks'].set_text(self.equip.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['name'].set_text(self.equip.ename)
|
||||
self.entry['shortname'].set_text(self.equip.shortname or '')
|
||||
combobox.activate_row(self.combo['manufacturer'], self.equip.manufacturer or -1)
|
||||
self.entry['model'].set_text(self.equip.model or '')
|
||||
self.entry['serial'].set_text(self.equip.serial or '')
|
||||
self.spin['weight'].set_value(self.equip.weight or 0)
|
||||
self.spin['price'].set_value(self.equip.price or 0)
|
||||
self.entry['purchdate'].set_text(self.format_date(self.equip.purchdate))
|
||||
self.text['remarks'].get_buffer().set_text(self.equip.remarks or '')
|
||||
combobox.activate_row(self.combo['supplier'], self.equip.supplier or -1)
|
||||
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)
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
print(self.equip)
|
||||
self.equip.ename = self.entry['name'].get_text()
|
||||
self.equip.shortname = self.entry['shortname'].get_text()
|
||||
self.equip.manufacturer = combobox.get_list_value(self.combo['manufacturer'])
|
||||
if self.equip.manufacturer < 0:
|
||||
self.equip.manufacturer = None
|
||||
self.equip.model = self.entry['model'].get_text()
|
||||
self.equip.serial = self.entry['serial'].get_text()
|
||||
self.equip.weight = self.spin['weight'].get_value()
|
||||
self.equip.price = self.spin['price'].get_value()
|
||||
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.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
print(self.equip)
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_editor'].set_text(_("Add new Equipment"))
|
||||
self.label['title_edit'].set_text(_("Add new Equipment"))
|
||||
self.clear_record()
|
||||
self.equip.vid = self.context.vessel.vid
|
||||
self.topwidget.set_visible_child(self.box['equip_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
eid = treeview.get_value(self.tree['equipment'], 0)
|
||||
if eid is None:
|
||||
return
|
||||
self.label['title_edit'].set_text(_("Edit Equipment"))
|
||||
self.equip.load(eid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['equip_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
eid = treeview.get_value(self.tree['equipment'], 0)
|
||||
if eid is None:
|
||||
return
|
||||
self.equip.load(eid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['equip_detail'])
|
||||
@@ -71,34 +172,44 @@ class EquipmentView(View):
|
||||
def on_but_close_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['equipment'])
|
||||
|
||||
def on_but_convert_clicked(self, widget):
|
||||
# convert equipment to inventory
|
||||
answer = gtkutils.questionbox(
|
||||
_("Convert equipment to inventory?\n"
|
||||
"Some properties will be lost!\n\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
# TODO
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete equipment!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['equipment'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
# check mandatory fields
|
||||
if not self.entry['name'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.equip)
|
||||
self.equip.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['equip_detail'])
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['equipment'])
|
||||
|
||||
def display_record(self):
|
||||
print(self.equip)
|
||||
self.label['name'].set_text(self.equip.ename)
|
||||
self.label['shortname'].set_text(self.equip.shortname or '')
|
||||
#lookup self.label['manufacturer'].set_text(self.equip.manufacturer)
|
||||
self.label['model'].set_text(self.equip.model or '')
|
||||
self.label['serial'].set_text(self.equip.serial or '')
|
||||
self.label['weight'].set_text(self.format_float(self.equip.weight, 2, suffix='kg'))
|
||||
self.label['price'].set_text(self.format_float(self.equip.price, 2, suffix='€'))
|
||||
self.label['date_purch'].set_text(self.equip.purchdate or '')
|
||||
#lookup self.label['supplier'].set_text(self.equip.supplier)
|
||||
self.label['category'].set_text(self.dd_category[self.equip.ecat])
|
||||
self.label['flags'].set_text(self.equip.flags or '')
|
||||
self.label['remarks'].set_text(self.equip.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['sname'].set_text(self.storage.sname)
|
||||
self.spin['x'].set_value(self.storage.x)
|
||||
self.spin['y'].set_value(self.storage.y)
|
||||
self.spin['z'].set_value(self.storage.z)
|
||||
self.text['remarks'].get_buffer().set_text(self.storage.remarks or '')
|
||||
+66
-13
@@ -39,13 +39,72 @@ class FusesView(View):
|
||||
treeview.add_column(self.tree['fuses'], _('Description'), 3)
|
||||
self.tree['fuses'].set_model(self.lst_fuses)
|
||||
|
||||
self.dd_type = self.context.lookup.dropdown(Dropdown.FUSE_TYPE)
|
||||
# Fuse Type
|
||||
self.dd_ftype = self.context.lookup.dropdown(Dropdown.FUSE_TYPE)
|
||||
combobox.load_from_dict(self.combo['ftype'], 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)
|
||||
|
||||
def clear_record(self):
|
||||
self.fuse.clear()
|
||||
self.spin['fnumber'].set_value(0)
|
||||
self.entry['description'].set_text('')
|
||||
combobox.activate_row(self.combo['ftype'], -1)
|
||||
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('')
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
|
||||
def display_record(self):
|
||||
self.label['fnumber'].set_text(f"F{self.fuse.fnumber}")
|
||||
self.label['type'].set_text(self.dd_type[self.fuse.ftype])
|
||||
self.label['current'].set_text(self.format_float(self.fuse.current, 2, suffix="A"))
|
||||
self.label['cable'].set_text(str(self.fuse.cableid))
|
||||
self.label['equipment'].set_text(str(self.fuse.eid))
|
||||
self.label['location'].set_text(str(self.fuse.location))
|
||||
self.label['description'].set_text(str(self.fuse.description or ''))
|
||||
self.label['remarks'].set_text(str(self.fuse.remarks or ''))
|
||||
|
||||
def edit_record(self):
|
||||
self.spin['fnumber'].set_value(self.fuse.fnumber)
|
||||
self.entry['description'].set_text(self.fuse.description)
|
||||
combobox.activate_row(self.combo['ftype'], self.fuse.ftype)
|
||||
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 '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.fuse.number = int(self.spin['fnumber'].get_value())
|
||||
self.fuse.description = self.entry['description'].get_text()
|
||||
self.fuse.ftype = combobox.get_list_value(self.combo['ftype'])
|
||||
self.fuse.cableid = combobox.get_list_value(self.combo['cable'])
|
||||
self.fuse.eid = combobox.get_list_value(self.combo['equipment'])
|
||||
self.fuse.location = self.entry['location'].get_text()
|
||||
self.fuse.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text(_("Add new Fuse"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['fuse_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
fuseid = treeview.get_value(self.tree['fuses'], 0)
|
||||
if fuseid is None:
|
||||
return
|
||||
self.label['title_edit'].set_text(_("Edit Fuse"))
|
||||
self.fuse.load(fuseid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['fuse_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
@@ -70,6 +129,12 @@ class FusesView(View):
|
||||
self.topwidget.set_visible_child(self.box['fuses'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete fuse!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['fuses'])
|
||||
|
||||
# buttons on edit page
|
||||
@@ -79,15 +144,3 @@ class FusesView(View):
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['fuses'])
|
||||
|
||||
def display_record(self):
|
||||
self.label['fnumber'].set_text(f"F{self.fuse.fnumber}")
|
||||
self.label['type'].set_text(self.dd_type[self.fuse.ftype])
|
||||
self.label['current'].set_text(self.format_float(self.fuse.current, 2, suffix="A"))
|
||||
self.label['cable'].set_text(str(self.fuse.cableid))
|
||||
self.label['equipment'].set_text(str(self.fuse.eid))
|
||||
self.label['location'].set_text(str(self.fuse.location))
|
||||
self.label['description'].set_text(str(self.fuse.description or ''))
|
||||
self.label['remarks'].set_text(str(self.fuse.remarks or ''))
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
+209
-49
@@ -1,12 +1,16 @@
|
||||
# SPDX-License-Identifier: WTFPL
|
||||
|
||||
|
||||
|
||||
import os
|
||||
from gi.repository import GLib, Gtk, Gdk
|
||||
from dateutil.parser import parse
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.lookup import Dropdown
|
||||
from yms.model import inventory
|
||||
from yms.model import equipment
|
||||
|
||||
class InventoryView(View):
|
||||
|
||||
@@ -15,22 +19,14 @@ class InventoryView(View):
|
||||
|
||||
self.inv = inventory.Inventory(context.db) # current record
|
||||
self.newrecord = False
|
||||
self.token = None # record locking
|
||||
self.timer_id = None
|
||||
|
||||
# Inventory gets vessel assignment via
|
||||
# - storage direct
|
||||
# - or via box which is assigned to a storage
|
||||
self.lst_inventory = Gtk.ListStore(int, str, str, int, str, str)
|
||||
sql = (
|
||||
"SELECT i.invid, i.invname, s.sname AS container, i.number, i.invcond, i.remarks "
|
||||
"FROM inventory AS i JOIN storage AS s ON (i.conttype='storage' AND i.sid=s.sid) "
|
||||
"WHERE s.vid=%s "
|
||||
"UNION SELECT i.invid, i.invname, b.label AS container, i.number, i.invcond, i.remarks "
|
||||
"FROM inventory AS i JOIN box AS b ON (i.conttype='box' AND i.boxid=b.boxid) JOIN storage AS s ON (b.sid=s.sid) "
|
||||
"WHERE s.vid=%s"
|
||||
)
|
||||
self.db.cur.execute(sql, (context.vessel.vid, context.vessel.vid))
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_inventory.append(row)
|
||||
self.load_list()
|
||||
|
||||
treeview.add_column(self.tree['inventory'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['inventory'], _('Name'), 1)
|
||||
@@ -40,42 +36,60 @@ class InventoryView(View):
|
||||
treeview.add_column(self.tree['inventory'], _('Remarks'), 5)
|
||||
self.tree['inventory'].set_model(self.lst_inventory)
|
||||
|
||||
# Container type
|
||||
self.dd_conttype = self.context.lookup.enum('inventory.conttype')
|
||||
combobox.load_from_dict(self.combo['conttype'], self.dd_conttype)
|
||||
# Inventory category
|
||||
self.dd_category = self.context.lookup.dropdown(Dropdown.INVENTORY_CATEGORY)
|
||||
combobox.load_from_dict(self.combo['category'], {-1: _("─── none ───")} | self.dd_category)
|
||||
# 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)
|
||||
# Equipment
|
||||
self.dd_equipment = self.context.lookup.equipment(context.vessel.vid)
|
||||
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)
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['inv_edit'])
|
||||
def load_list(self):
|
||||
self.lst_inventory.clear()
|
||||
sql = (
|
||||
"SELECT i.invid, i.invname, s.sname AS container, i.number, i.invcond, i.remarks "
|
||||
"FROM inventory AS i JOIN storage AS s ON (i.conttype='storage' AND i.sid=s.sid) "
|
||||
"WHERE s.vid=%s "
|
||||
"UNION SELECT i.invid, i.invname, b.label AS container, i.number, i.invcond, i.remarks "
|
||||
"FROM inventory AS i JOIN box AS b ON (i.conttype='box' AND i.boxid=b.boxid) JOIN storage AS s ON (b.sid=s.sid) "
|
||||
"WHERE s.vid=%s"
|
||||
)
|
||||
self.db.cur.execute(sql, (self.context.vessel.vid, self.context.vessel.vid))
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_inventory.append(row)
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['inv_edit'])
|
||||
def lock_timer(self):
|
||||
self.context.db.lock_refresh(self.token)
|
||||
return True # continue timer
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
invid = treeview.get_value(self.tree['inventory'], 0)
|
||||
self.inv.load(invid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_detail'])
|
||||
self.button['close'].grab_focus()
|
||||
def on_page_activated(self):
|
||||
print("Inventory activated")
|
||||
|
||||
def on_tvw_inventory_row_activated(self, widget, path, column):
|
||||
invid = treeview.get_value(widget, 0)
|
||||
self.inv.load(invid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_detail'])
|
||||
|
||||
# buttons on detail page
|
||||
# edit2 uses edit callback
|
||||
def on_but_close_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['inventory'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['inventory'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['inventory'])
|
||||
def clear_record(self):
|
||||
self.inv.clear()
|
||||
self.entry['name'].set_text('')
|
||||
combobox.activate_row(self.combo['conttype'], -1)
|
||||
combobox.activate_row(self.combo['storage'], -1)
|
||||
combobox.activate_row(self.combo['box'], -1)
|
||||
combobox.activate_row(self.combo['equipment'], -1)
|
||||
self.spin['number'].set_value(1)
|
||||
self.spin['weight'].set_value(0)
|
||||
self.spin['price'].set_value(0)
|
||||
self.entry['purchdate'].set_text('')
|
||||
combobox.activate_row(self.combo['condition'], 'unknown')
|
||||
combobox.activate_row(self.combo['category'], -1)
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
|
||||
def display_record(self):
|
||||
# TODO nice formatting
|
||||
@@ -93,13 +107,159 @@ class InventoryView(View):
|
||||
self.label['category'].set_text(self.dd_category[self.inv.icat])
|
||||
else:
|
||||
self.label['category'].set_text('')
|
||||
self.label['flags'].set_text(self.inv.flags)
|
||||
self.label['remarks'].set_text(self.inv.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['user_login'].set_text(user.login)
|
||||
self.entry['user_displayname'].set_text(user.displayname)
|
||||
combobox.activate_row(self.combo['user_role'], user.role)
|
||||
combobox.activate_row(self.combo['user_lang'], user.language)
|
||||
self.check['user_locked'].set_active('locked' in user.flags)
|
||||
self.check['user_deleted'].set_active('deleted' in user.flags)
|
||||
self.entry['user_pass'].set_text('')
|
||||
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)
|
||||
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 '')
|
||||
combobox.activate_row(self.combo['condition'], self.inv.invcond)
|
||||
combobox.activate_row(self.combo['category'], self.inv.icat)
|
||||
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 '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.inv.invname = self.entry['name'].get_text()
|
||||
self.inv.conttype = combobox.get_list_value(self.combo['conttype'])
|
||||
self.inv.sid = combobox.get_list_value(self.combo['storage'])
|
||||
if self.inv.sid < 0:
|
||||
self.inv.sid = None
|
||||
self.inv.boxid = combobox.get_list_value(self.combo['box'])
|
||||
if self.inv.boxid < 0:
|
||||
self.inv.boxid = None
|
||||
self.inv.eid = combobox.get_list_value(self.combo['equipment'])
|
||||
if self.inv.eid < 0:
|
||||
self.inv.eid = None
|
||||
self.inv.number = self.spin['number'].get_value()
|
||||
self.inv.weight = self.spin['weight'].get_value()
|
||||
self.inv.price = self.spin['price'].get_value()
|
||||
try:
|
||||
# TODO respect configured date format
|
||||
self.inv.purchdate = parse(self.entry['purchdate'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.inv.purchdate = None
|
||||
self.inv.invcond = combobox.get_list_value(self.combo['condition'])
|
||||
self.inv.icat = combobox.get_list_value(self.combo['category'])
|
||||
# TODO this could be a generic function operating on a list
|
||||
# of check controls
|
||||
flags = []
|
||||
if self.check['ordered'].get_active(): flags.append('ordered')
|
||||
if self.check['removed'].get_active(): flags.append('removed')
|
||||
if self.check['deleted'].get_active(): flags.append('deleted')
|
||||
self.inv.flags = ','.join(flags)
|
||||
self.inv.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text(_("Add new Inventory"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
invid = treeview.get_value(self.tree['inventory'], 0)
|
||||
if invid is None:
|
||||
return
|
||||
self.token = self.context.db.lock_acquire('inventory', invid, self.user.user_id)
|
||||
if self.token is None:
|
||||
gtkutils.messagebox(
|
||||
_("Record is locked!\n"
|
||||
"Edit prohibited."), title="YMS"
|
||||
)
|
||||
return
|
||||
self.timer_id = GLib.timeout_add(120000, self.lock_timer) # 2 minutes lock refresh timer
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text(_("Edit Inventory"))
|
||||
self.inv.load(invid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_edit'])
|
||||
# TODO start timer to refresh record lock
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
invid = treeview.get_value(self.tree['inventory'], 0)
|
||||
self.inv.load(invid)
|
||||
print(self.inv)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_detail'])
|
||||
self.button['close'].grab_focus()
|
||||
|
||||
def on_tvw_inventory_row_activated(self, widget, path, column):
|
||||
invid = treeview.get_value(widget, 0)
|
||||
self.inv.load(invid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_detail'])
|
||||
|
||||
# buttons on detail page
|
||||
# edit2 uses edit callback
|
||||
def on_but_close_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['inventory'])
|
||||
|
||||
def on_but_convert_clicked(self, widget):
|
||||
# convert equipment to inventory
|
||||
answer = gtkutils.questionbox(
|
||||
_("Convert inventory to equipment?\n"
|
||||
"Some properties will be lost!\n\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
# TODO / WIP
|
||||
"""
|
||||
lost fields: icat number conttype sid boxid
|
||||
"""
|
||||
equip = equipment.Equipment(self.context.db)
|
||||
equip.ename = self.inv.name
|
||||
equip.shortname = ''
|
||||
equip.manufacturer = None
|
||||
equip.model = ''
|
||||
equip.serial = ''
|
||||
equip.weight = self.inv.weight
|
||||
equip.price = self.inv.price
|
||||
equip.purchdate = self.inv.purchdate
|
||||
equip.supplier = None
|
||||
equip.ecat = None
|
||||
equip.econd = self.inv.invcond
|
||||
equip.remarks = self.inv.remarks
|
||||
equip.flags = self.inv.flags
|
||||
print(equip)
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete inventory!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['inventory'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
# check mandatory fields
|
||||
if not self.entry['name'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.inv)
|
||||
self.inv.save()
|
||||
self.context.db.conn.commit()
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
if not self.newrecord:
|
||||
if self.timer_id is not None:
|
||||
# remove locking timer
|
||||
GLib.source_remove(self.timer_id)
|
||||
self.timer_id = None
|
||||
if not self.token is None:
|
||||
if not self.context.db.lock_release(self.token):
|
||||
print("Error while releasing lock!")
|
||||
self.topwidget.set_visible_child(self.box['inventory'])
|
||||
+66
-16
@@ -32,11 +32,64 @@ class MaintenanceView(View):
|
||||
treeview.add_column(self.tree['maintenance'], _('Remarks'), 3)
|
||||
self.tree['maintenance'].set_model(self.lst_maintenance)
|
||||
|
||||
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.entry['plandate'].set_text('')
|
||||
self.entry['completion'].set_text('')
|
||||
combobox.activate_row(self.combo['status'], 'new')
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
|
||||
def display_record(self):
|
||||
self.label['activities'].set_text(self.maint.activities)
|
||||
self.label['equipment'].set_text(str(self.maint.eid))
|
||||
self.label['series'].set_text(str(self.maint.series))
|
||||
self.label['interval'].set_text(self.format_int(self.maint.interval_hours))
|
||||
self.label['last'].set_text(self.format_int(self.maint.last_hours))
|
||||
self.label['plandate'].set_text(self.format_date(self.maint.plan_date))
|
||||
self.label['completion'].set_text(self.format_date(self.maint.completion_date))
|
||||
self.label['status'].set_text(self.maint.maintstate)
|
||||
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.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)
|
||||
combobox.activate_row(self.combo['status'], self.maint.maintstate)
|
||||
self.text['remarks'].get_buffer().set_text(self.maint.remarks or '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
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()
|
||||
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.topwidget.set_visible_child(self.box['maint_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text(_("Edit Maintenance"))
|
||||
maintid = treeview.get_value(self.tree['maintenance'], 0)
|
||||
if not maintid:
|
||||
return
|
||||
self.maint.load(maintid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['maint_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
@@ -61,26 +114,23 @@ class MaintenanceView(View):
|
||||
self.topwidget.set_visible_child(self.box['maintenance'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete maintenance!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['maintenance'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
# check mandatory fields
|
||||
if not self.entry['activities'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.maint)
|
||||
self.maint.save()
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['maintenance'])
|
||||
|
||||
def display_record(self):
|
||||
self.label['activities'].set_text(self.maint.activities)
|
||||
self.label['equipment'].set_text(str(self.maint.eid))
|
||||
self.label['series'].set_text(str(self.maint.series))
|
||||
self.label['interval'].set_text(self.format_int(self.maint.interval_hours))
|
||||
self.label['last'].set_text(self.format_int(self.maint.last_hours))
|
||||
self.label['plandate'].set_text(self.format_date(self.maint.plan_date))
|
||||
self.label['completion'].set_text(self.format_date(self.maint.completion_date))
|
||||
self.label['status'].set_text(self.maint.maintstate)
|
||||
self.label['remarks'].set_text(self.maint.remarks or '')
|
||||
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
+96
-8
@@ -16,8 +16,26 @@ class MeasurementView(View):
|
||||
self.measure = measurement.Measurement(context.db) # current record
|
||||
self.newrecord = False
|
||||
|
||||
# dimensions
|
||||
self.dd_dimensions = { 1: "1D", 2: "2D", 3: "3D"}
|
||||
combobox.load_from_dict(self.combo['dimensions'], self.dd_dimensions, 1)
|
||||
|
||||
# accuracy
|
||||
self.dd_accuracy = self.context.lookup.enum('measurement.accuracy')
|
||||
combobox.load_from_dict(self.combo['accuracy'], {"-1": _("─── none ───")} | self.dd_accuracy)
|
||||
|
||||
# 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
|
||||
self.dd_equipment = self.context.lookup.equipment(context.vessel.vid)
|
||||
combobox.load_from_dict(self.combo['equipment'], {-1: _("─── none ───")} | self.dd_equipment)
|
||||
|
||||
# category
|
||||
self.dd_category = self.context.lookup.dropdown(Dropdown.MEASUREMENT_CATEGORY)
|
||||
combobox.load_from_dict(self.combo['category'], {-1: _("─── none ───")} | self.dd_category)
|
||||
|
||||
self.lst_measurement = Gtk.ListStore(int, str, str, str, str, str)
|
||||
sql = (
|
||||
@@ -56,11 +74,76 @@ class MeasurementView(View):
|
||||
treeview.add_column(self.tree['measurement'], _('Note'), 5)
|
||||
self.tree['measurement'].set_model(self.lst_measurement)
|
||||
|
||||
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['accuracy'], 'unknown')
|
||||
self.entry['date'].set_text('')
|
||||
combobox.activate_row(self.combo['equipment'], -1)
|
||||
combobox.activate_row(self.combo['category'], -1)
|
||||
self.text['note'].get_buffer().set_text('')
|
||||
|
||||
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)
|
||||
if self.measure.nval >= 2:
|
||||
self.label['val2'].set_text(self.measure.val2 or '')
|
||||
else:
|
||||
self.label['val2'].set_text('n/a')
|
||||
if self.measure.nval == 3:
|
||||
self.label['val3'].set_text(self.measure.val3 or '')
|
||||
else:
|
||||
self.label['val3'].set_text('n/a')
|
||||
# TODO
|
||||
# unit
|
||||
# accuracy
|
||||
# category
|
||||
|
||||
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)
|
||||
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)
|
||||
combobox.activate_row(self.combo['category'], self.measure.mcat)
|
||||
self.text['note'].get_buffer().set_text(self.task.note or '')
|
||||
|
||||
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.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'])
|
||||
self.measure.mcat = combobox.get_list_value(self.combo['category'])
|
||||
self.measure.note = gtkutils.get_text_contents(self.text['note'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text(_("Add new Measurement"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['measure_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text(_("Edit Measurement"))
|
||||
mid = treeview.get_value(self.tree['measurement'], 0)
|
||||
if not mid:
|
||||
return
|
||||
self.measure.load(mid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['measure_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
@@ -85,18 +168,23 @@ class MeasurementView(View):
|
||||
self.topwidget.set_visible_child(self.box['measurement'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete measurement!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['measurement'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
# check mandatory fields
|
||||
if not self.entry['mname'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.measure)
|
||||
self.measure.save()
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['measurement'])
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.measure.mname)
|
||||
self.label['note'].set_text(self.measure.note or '')
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
+66
-14
@@ -43,14 +43,67 @@ class ProjectsView(View):
|
||||
treeview.add_column(self.tree['projects'], _('Remarks'), 5)
|
||||
self.tree['projects'].set_model(self.lst_projects)
|
||||
|
||||
# Responsible
|
||||
self.dd_user = context.lookup.user()
|
||||
combobox.load_from_dict(self.combo['responsible'], self.dd_user)
|
||||
|
||||
# Status
|
||||
self.dd_state = self.context.lookup.enum('project.projstate')
|
||||
combobox.load_from_dict(self.combo['status'], self.dd_state)
|
||||
|
||||
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)
|
||||
combobox.activate_row(self.combo['status'], 'new')
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.project.projname)
|
||||
self.label['responsible'].set_text(self.dd_user[self.project.responsible])
|
||||
self.label['date_start'].set_text(self.format_date(self.project.startdate))
|
||||
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['remarks'].set_text(self.project.remarks or '')
|
||||
|
||||
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)
|
||||
combobox.activate_row(self.combo['status'], self.project.projstate)
|
||||
self.text['remarks'].get_buffer().set_text(self.project.remarks or '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
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())
|
||||
self.project.costs_final = int(self.spin['costs_final'].get_value())
|
||||
self.project.projstate = combobox.get_list_value(self.combo['status'])
|
||||
self.project.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text(_("Add new Project"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['proj_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text(_("Edit Project"))
|
||||
projid = treeview.get_value(self.tree['projects'], 0)
|
||||
if not projidid:
|
||||
return
|
||||
self.measure.load(mid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['proj_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
@@ -75,24 +128,23 @@ class ProjectsView(View):
|
||||
self.topwidget.set_visible_child(self.box['projects'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete project!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['projects'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
# check mandatory fields
|
||||
if not self.entry['projname'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.project)
|
||||
self.project.save()
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['projects'])
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.project.projname)
|
||||
self.label['responsible'].set_text(self.dd_user[self.project.responsible])
|
||||
self.label['date_start'].set_text(self.format_date(self.project.startdate))
|
||||
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['remarks'].set_text(self.project.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
+81
-19
@@ -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 provision
|
||||
|
||||
@@ -44,15 +46,72 @@ class ProvisionsView(View):
|
||||
treeview.add_column(self.tree['provisions'], _('Best before'), 5)
|
||||
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)
|
||||
|
||||
def clear_record(self):
|
||||
self.prov.clear()
|
||||
|
||||
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['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['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)
|
||||
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.entry['storedate'].set_text(self.prov.storedate or '')
|
||||
self.entry['shelflife'].set_text(self.prov.shelflife or '')
|
||||
self.text['remarks'].get_buffer().set_text(self.prov.remarks or '')
|
||||
|
||||
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'])
|
||||
self.prov.sid = combobox.get_list_value(self.combo['storage'])
|
||||
self.prov.boxid = combobox.get_list_value(self.combo['box'])
|
||||
self.prov.number = int(self.spin['number'].get_value())
|
||||
self.prov.weight = self.spin['weight'].get_value()
|
||||
self.prov.weight_net = self.spin['wehigt_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()
|
||||
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
|
||||
self.label['title_edit'].set_text(_("Add new Provision"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['prov_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text(_("Edit Provision"))
|
||||
provid = treeview.get_value(self.tree['provisions'], 0)
|
||||
if not provid:
|
||||
return
|
||||
self.prov.load(provid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['prov_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
@@ -75,28 +134,31 @@ class ProvisionsView(View):
|
||||
self.topwidget.set_visible_child(self.box['provisions'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete provision!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['provisions'])
|
||||
|
||||
# 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))
|
||||
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
# check mandatory fields
|
||||
if not self.entry['provname'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.prov)
|
||||
self.prov.save()
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['provisions'])
|
||||
|
||||
def display_record(self):
|
||||
print(self.prov)
|
||||
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['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['remarks'].set_text(self.prov.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
+6
-2
@@ -105,6 +105,10 @@ class StatusView:
|
||||
print("No centerline with id='centerline' found!")
|
||||
|
||||
def on_drw_status_draw(self, area, cr):
|
||||
if self.context.vessel.pk_value is None:
|
||||
# no vessel defined
|
||||
return
|
||||
|
||||
cr.set_source_rgb(0.92, 0.97, 1.0)
|
||||
cr.paint()
|
||||
|
||||
@@ -136,9 +140,9 @@ class StatusView:
|
||||
# Detect all tables in database
|
||||
sql= ("SELECT table_name "
|
||||
"FROM information_schema.tables "
|
||||
"WHERE table_schema='yms' AND table_type='BASE TABLE' "
|
||||
"WHERE table_schema=%s AND table_type='BASE TABLE' "
|
||||
"ORDER BY table_name")
|
||||
self.context.db.cur.execute(sql)
|
||||
self.context.db.cur.execute(sql, (self.context.db.schema,))
|
||||
tables = [row[0] for row in self.context.db.cur.fetchall()]
|
||||
# Loop over tables and get current record count
|
||||
records = []
|
||||
|
||||
+75
-28
@@ -17,6 +17,8 @@ class StorageView(View):
|
||||
self.storage = storage.Storage(context.db) # current record
|
||||
self.newrecord = False
|
||||
|
||||
self.last_valid_rgb = "#3498DB"
|
||||
|
||||
self.lst_storage = Gtk.ListStore(int, str, str, str)
|
||||
self.load_list()
|
||||
|
||||
@@ -27,29 +29,39 @@ class StorageView(View):
|
||||
self.tree['storage'].set_model(self.lst_storage)
|
||||
|
||||
self.dd_stype = self.context.lookup.dropdown(Dropdown.STORAGE_TYPE)
|
||||
combobox.load_from_dict(self.combo['type'], self.dd_stype)
|
||||
combobox.load_from_dict(self.combo['type'], self.dd_stype, storage.GENERIC)
|
||||
|
||||
self.dd_unit = self.context.lookup.enum('storage.capaunit')
|
||||
combobox.load_from_dict(self.combo['unit'], self.dd_unit)
|
||||
combobox.load_from_dict(self.combo['unit'], {"-1": _("─── none ───")} | self.dd_unit)
|
||||
|
||||
def add_row(self):
|
||||
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)
|
||||
treeview.set_value(self.tree['storage'], 3, self.storage.remarks)
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['storage'])
|
||||
self.lst_storage.clear()
|
||||
sql = (
|
||||
"SELECT sid, sname, CONCAT(x, ',', y, ',', z) AS position, remarks "
|
||||
"SELECT sid, sname, CONCAT(x, ',', y, ',', z) AS position, "
|
||||
" IF(CHAR_LENGTH(remarks)>40, CONCAT(LEFT(remarks, 40), '\u2026'), remarks) AS remarks "
|
||||
"FROM storage "
|
||||
"WHERE vid=%s "
|
||||
"ORDER BY sname"
|
||||
)
|
||||
self.db.cur.execute(sql, (self.context.vessel.vid,))
|
||||
selection = self.tree['storage'].get_selection()
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_storage.append(row)
|
||||
|
||||
treeiter = self.lst_storage.append(row)
|
||||
if row[0] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.storage.clear()
|
||||
self.entry['sname'].set_text('')
|
||||
@@ -61,8 +73,8 @@ class StorageView(View):
|
||||
self.spin['wz'].set_value(0)
|
||||
self.spin['angle'].set_value(0)
|
||||
self.spin['capacity'].set_value(0)
|
||||
combobox.activate_row(self.combo['type'], -1)
|
||||
combobox.activate_row(self.combo['unit'], -1)
|
||||
combobox.activate_row(self.combo['type'], storage.GENERIC)
|
||||
combobox.activate_row(self.combo['unit'], "-1")
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
|
||||
def display_record(self):
|
||||
@@ -79,6 +91,7 @@ class StorageView(View):
|
||||
self.label['remarks'].set_text(self.storage.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.last_valid_rgb = self.storage.color
|
||||
self.entry['sname'].set_text(self.storage.sname)
|
||||
self.spin['x'].set_value(self.storage.x)
|
||||
self.spin['y'].set_value(self.storage.y)
|
||||
@@ -87,17 +100,38 @@ class StorageView(View):
|
||||
self.spin['wy'].set_value(self.storage.wy)
|
||||
self.spin['wz'].set_value(self.storage.wz)
|
||||
self.spin['angle'].set_value(self.storage.angle)
|
||||
self.spin['capacity'].set_value(self.storage.capacity)
|
||||
self.spin['capacity'].set_value(self.storage.capacity or 0)
|
||||
combobox.activate_row(self.combo['type'], self.storage.stype)
|
||||
combobox.activate_row(self.combo['unit'], self.storage.capaunit)
|
||||
# flags
|
||||
combobox.activate_row(self.combo['unit'], self.storage.capaunit or -1)
|
||||
self.entry['color'].set_text('#' + (self.storage.color or '000000'))
|
||||
rgba = Gdk.RGBA()
|
||||
rgba.parse('#' + (self.storage.color or '000000'))
|
||||
self.button['color'].set_rgba(rgba)
|
||||
self.text['remarks'].get_buffer().set_text(self.storage.remarks or '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.storage.sname = self.entry['sname'].get_text()
|
||||
self.storage.stype = combobox.get_list_value(self.combo['type'])
|
||||
self.storage.x = self.spin['x'].get_value_as_int()
|
||||
self.storage.y = self.spin['y'].get_value_as_int()
|
||||
self.storage.z = self.spin['z'].get_value_as_int()
|
||||
self.storage.wx = self.spin['wx'].get_value_as_int()
|
||||
self.storage.wy = self.spin['wy'].get_value_as_int()
|
||||
self.storage.wz = self.spin['wz'].get_value_as_int()
|
||||
self.storage.angle = self.spin['angle'].get_value_as_int()
|
||||
self.storage.capacity = self.spin['capacity'].get_value_as_int()
|
||||
self.storage.capaunit = combobox.get_list_value(self.combo['unit'])
|
||||
if self.storage.capaunit == '-1':
|
||||
self.storage.capaunit = None
|
||||
self.storage.color = self.entry['color'].get_text().lstrip('#')
|
||||
self.storage.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text("Add new Storage")
|
||||
self.clear_record()
|
||||
self.label['title_edit'].set_text(_("Add new Storage"))
|
||||
self.storage.vid = self.context.vessel.vid
|
||||
self.topwidget.set_visible_child(self.box['stor_edit'])
|
||||
|
||||
@@ -106,7 +140,7 @@ class StorageView(View):
|
||||
if sid is None:
|
||||
return
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text("Edit Storage")
|
||||
self.label['title_edit'].set_text(_("Edit Storage"))
|
||||
self.storage.load(sid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['stor_edit'])
|
||||
@@ -133,34 +167,47 @@ class StorageView(View):
|
||||
self.topwidget.set_visible_child(self.box['storage'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete storage!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['storage'])
|
||||
self.newrecord = False
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
# check mandatory fields
|
||||
sname = self.entry['sname'].get_text().strip()
|
||||
if not sname:
|
||||
if not self.entry['sname'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
# get fields from ui form
|
||||
self.storage.sname = sname
|
||||
self.storage.stype = combobox.get_list_value(self.combo['type'])
|
||||
self.storage.x = self.spin['x'].get_value()
|
||||
self.storage.y = self.spin['y'].get_value()
|
||||
self.storage.z = self.spin['z'].get_value()
|
||||
self.storage.wx = self.spin['wx'].get_value()
|
||||
self.storage.wy = self.spin['wy'].get_value()
|
||||
self.storage.wz = self.spin['wz'].get_value()
|
||||
self.storage.angle = self.spin['angle'].get_value()
|
||||
self.storage.capacity = self.spin['capacity'].get_value()
|
||||
self.storage.capaunit = combobox.get_list_value(self.combo['unit'])
|
||||
self.storage.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
self.save_record()
|
||||
print(self.storage)
|
||||
self.storage.save()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
else:
|
||||
pass
|
||||
# TODO aktuelle Listenzeile aktualisieren!
|
||||
self.newrecord = False
|
||||
self.topwidget.set_visible_child(self.box['storage'])
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['stor_detail'])
|
||||
|
||||
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)
|
||||
self.last_valid_rgb = f"{r:02X}{g:02X}{b:02X}"
|
||||
self.entry['color'].set_text(f"#{r:02X}{g:02X}{b:02X}")
|
||||
|
||||
def on_ent_color_activate(self, entry):
|
||||
self.set_color_from_entry(entry)
|
||||
|
||||
def on_ent_color_focus_out_event(self, entry, event):
|
||||
self.set_color_from_entry(entry)
|
||||
return False
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['storage'])
|
||||
|
||||
+83
-10
@@ -42,11 +42,81 @@ class TasksView(View):
|
||||
treeview.add_column(self.tree['tasks'], _('Responsible'), 4)
|
||||
self.tree['tasks'].set_model(self.lst_tasks)
|
||||
|
||||
# Project
|
||||
self.dd_project = context.lookup.project(self.context.vessel.vid)
|
||||
combobox.load_from_dict(self.combo['project'], {-1: _("─── none ───")} | self.dd_project)
|
||||
|
||||
# Priority
|
||||
self.dd_priority = self.context.lookup.enum('task.priority')
|
||||
combobox.load_from_dict(self.combo['priority'], self.dd_priority)
|
||||
|
||||
# Status
|
||||
self.dd_state = self.context.lookup.enum('task.taskstate')
|
||||
combobox.load_from_dict(self.combo['status'], self.dd_state)
|
||||
|
||||
# Responsible
|
||||
self.dd_user = context.lookup.user()
|
||||
combobox.load_from_dict(self.combo['responsible'], self.dd_user)
|
||||
|
||||
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)
|
||||
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['responsible'], 0)
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.task.taskname)
|
||||
self.label['responsible'].set_text('')
|
||||
self.label['status'].set_text(self.task.taskstate)
|
||||
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)
|
||||
combobox.activate_row(self.combo['responsible'], self.task.responsible)
|
||||
self.text['remarks'].get_buffer().set_text(self.task.remarks or '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
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'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text(_("Add new Task"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['task_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text(_("Edit Task"))
|
||||
taskid = treeview.get_value(self.tree['tasks'], 0)
|
||||
if not taskid:
|
||||
return
|
||||
self.task.load(taskid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['task_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
@@ -70,20 +140,23 @@ class TasksView(View):
|
||||
self.topwidget.set_visible_child(self.box['tasks'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete task!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['tasks'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
# check mandatory fields
|
||||
if not self.entry['taskname'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.task)
|
||||
self.task.save()
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['tasks'])
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.task.taskname)
|
||||
self.label['responsible'].set_text('')
|
||||
self.label['status'].set_text(self.task.taskstate)
|
||||
self.label['remarks'].set_text(self.task.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
+105
-7
@@ -2,12 +2,14 @@
|
||||
|
||||
"""
|
||||
Generic view object
|
||||
- with own glade ui file
|
||||
|
||||
SPDX-License-Identifier: WTFPL
|
||||
"""
|
||||
|
||||
import os
|
||||
import locale
|
||||
from gi.repository import GLib, Gtk, Gdk
|
||||
from datetime import date, datetime
|
||||
from yms import gtkutils
|
||||
|
||||
class View:
|
||||
@@ -18,12 +20,31 @@ class View:
|
||||
self.vessel = context.vessel
|
||||
self.user = context.user
|
||||
self._title = title
|
||||
builder = Gtk.Builder()
|
||||
builder.set_translation_domain(context.textdomain)
|
||||
builder.add_from_file(os.path.join(context.ui_path, ui_file))
|
||||
builder.connect_signals(self)
|
||||
self.topwidget = builder.get_object("topobject")
|
||||
gtkutils.init_named_controls(self, builder)
|
||||
|
||||
locale.bindtextdomain(context.textdomain, context.localedir)
|
||||
locale.textdomain(context.textdomain)
|
||||
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.set_translation_domain(context.textdomain)
|
||||
self.builder.add_from_file(os.path.join(context.ui_path, ui_file))
|
||||
self.builder.connect_signals(self)
|
||||
|
||||
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:
|
||||
@@ -104,3 +125,80 @@ class View:
|
||||
buf.delete(sel_start, sel_end)
|
||||
buf.insert_at_cursor(text)
|
||||
return True
|
||||
|
||||
def set_entry_valid(self, entry, valid):
|
||||
context = entry.get_style_context()
|
||||
if valid:
|
||||
context.remove_class("invalid")
|
||||
else:
|
||||
context.add_class("invalid")
|
||||
|
||||
def set_color_from_entry(self, entry):
|
||||
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)
|
||||
else:
|
||||
self.set_entry_valid(self.entry['color'], False)
|
||||
|
||||
class DatePicker:
|
||||
def __init__(self, entry, button, datefmt='"%d.%m.%Y"'):
|
||||
self.entry = entry
|
||||
self.button = button
|
||||
self.datefmt = datefmt
|
||||
self.popover = Gtk.Popover.new(self.button)
|
||||
self.popover.set_position(Gtk.PositionType.BOTTOM)
|
||||
content = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
|
||||
content.set_border_width(10)
|
||||
self.calendar = Gtk.Calendar()
|
||||
self.calendar.set_display_options(
|
||||
Gtk.CalendarDisplayOptions.SHOW_HEADING
|
||||
| Gtk.CalendarDisplayOptions.SHOW_DAY_NAMES
|
||||
| Gtk.CalendarDisplayOptions.SHOW_WEEK_NUMBERS
|
||||
)
|
||||
content.pack_start(self.calendar, True, True, 0)
|
||||
buttons = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
|
||||
buttons.set_halign(Gtk.Align.END)
|
||||
self.but_cancel = Gtk.Button(label="Abbrechen")
|
||||
self.but_apply = Gtk.Button(label="Übernehmen")
|
||||
buttons.pack_start(self.but_cancel, False, False, 0)
|
||||
buttons.pack_start(self.but_apply, False, False, 0)
|
||||
content.pack_start(buttons, False, False, 0)
|
||||
self.popover.add(content)
|
||||
self.button.connect("clicked", self._on_open)
|
||||
self.but_apply.connect("clicked", self._on_apply)
|
||||
self.but_cancel.connect("clicked", self._on_cancel)
|
||||
self.popover.show_all()
|
||||
self.popover.hide()
|
||||
|
||||
def get_date(self):
|
||||
"""Liefert datetime.date oder None bei ungültiger Eingabe."""
|
||||
try:
|
||||
return datetime.strptime(self.entry.get_text().strip(), self.datefmt).date()
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
def set_date(self, value):
|
||||
"""Setzt das Datum mit einem datetime.date-Objekt."""
|
||||
if isinstance(value, date):
|
||||
self.entry.set_text(value.strftime(self.datefmt))
|
||||
|
||||
def _on_open(self, button):
|
||||
selected = self.get_date() or date.today()
|
||||
self.calendar.select_month(
|
||||
selected.month - 1,
|
||||
selected.year
|
||||
)
|
||||
self.calendar.select_day(selected.day)
|
||||
self.popover.show_all()
|
||||
|
||||
def _on_apply(self, button):
|
||||
year, month, day = self.calendar.get_date()
|
||||
self.set_date(date(year, month + 1, day))
|
||||
self.popover.popdown()
|
||||
|
||||
def _on_cancel(self, button):
|
||||
self.popover.popdown()
|
||||
Reference in new issue
Block a user