From 09387280fcd176ff3fbf09bdcb8266a2d3472795 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Wed, 11 Nov 2026 18:57:15 +0100 Subject: [PATCH] Native gui usable for data editing. Lots of fixes and improvenemts --- CHANGELOG | 13 ++ db/generic.sql | 1 - db/generic_en.sql | 1 - db/mariadb.sql | 2 +- db/minimal.sql | 5 +- db/minimal_en.sql | 3 + debian/changelog | 14 ++ webgui/globals.inc | 2 +- yms.1 | 4 +- yms/database.py | 49 +++-- yms/lookup.py | 18 ++ yms/model/box.py | 6 +- yms/model/cable.py | 7 +- yms/model/company.py | 7 +- yms/model/dbrecord.py | 48 +++-- yms/model/document.py | 3 +- yms/model/equipment.py | 7 +- yms/model/fuse.py | 5 +- yms/model/inventory.py | 5 +- yms/model/maintenance.py | 7 +- yms/model/measurement.py | 5 +- yms/model/project.py | 5 +- yms/model/provision.py | 7 +- yms/model/storage.py | 3 +- yms/model/task.py | 6 +- yms/model/vessel.py | 15 +- yms/treeview.py | 35 ++++ yms/ui/base.ui | 138 ++++++++++++-- yms/ui/equipment.ui | 69 ++++++- yms/ui/inventory.ui | 12 +- yms/ui/maintenance.ui | 9 + yms/ui/projects.ui | 6 + yms/ui/provisions.ui | 12 +- yms/ui/status.ui | 53 +++++- yms/ui/storage.ui | 2 +- yms/view/base.py | 376 ++++++++++++++++++++++++++++++++++----- yms/view/boxes.py | 64 +++++-- yms/view/cables.py | 68 ++++++- yms/view/companies.py | 50 +++++- yms/view/documents.py | 28 ++- yms/view/equipment.py | 32 +++- yms/view/fuses.py | 97 +++++++++- yms/view/inventory.py | 100 +++++++++-- yms/view/maintenance.py | 27 ++- yms/view/measurement.py | 83 ++++++++- yms/view/projects.py | 38 +++- yms/view/provisions.py | 129 +++++++++++--- yms/view/status.py | 69 ++++--- yms/view/storage.py | 37 ++-- yms/view/tasks.py | 17 +- yms/view/view.py | 44 +++-- ymsgui.py | 30 ++-- 52 files changed, 1579 insertions(+), 294 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 59a5f1e..b532d3a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,19 @@ CHANGELOG ========= +0.3.0 - 2026-11-11 +------------------ + + * native gui: can create and edit all kind of records + * native gui: implemented record locking + * updater script for web gui + * many bugs fixed in webgui + * prepare list revision feature (reload support) + * database localization tool + * new property table for generic key/value store + * webgui: set file access rights + * fix debian packaging + 0.2.2 - 2026-09-21 ------------------ diff --git a/db/generic.sql b/db/generic.sql index 6fecb6b..6888c46 100644 --- a/db/generic.sql +++ b/db/generic.sql @@ -94,7 +94,6 @@ INSERT INTO dropdown (ddid, ddval, ddtext, ddshort) VALUES (7, 12, 'Streifensicherung', 'Str'); INSERT INTO dropdown (ddid, ddval, ddtext, ddshort) VALUES -(8, 1, 'Millimeter', 'mm'), (8, 2, 'Zentimeter', 'cm'), (8, 3, 'Meter', 'm'), (8, 4, 'Gramm', 'g'), diff --git a/db/generic_en.sql b/db/generic_en.sql index 3eb4e77..7747aaa 100644 --- a/db/generic_en.sql +++ b/db/generic_en.sql @@ -92,7 +92,6 @@ INSERT INTO dropdown (ddid, ddval, ddtext, ddshort) VALUES (7, 12, 'Strip fuse', 'Str'); INSERT INTO dropdown (ddid, ddval, ddshort, ddtext) VALUES -(8, 1, 'mm', 'Millimetre'), (8, 2, 'cm', 'Centimetre'), (8, 3, 'g', 'Gram'), (8, 4, 'kg', 'Kilogram'), diff --git a/db/mariadb.sql b/db/mariadb.sql index 4e475bd..7f6a120 100644 --- a/db/mariadb.sql +++ b/db/mariadb.sql @@ -64,7 +64,7 @@ CREATE TABLE dropdown ( ddtext varchar(50) NOT NULL, ddshort varchar(4) DEFAULT NULL, color char(6) DEFAULT NULL, - flags enum('locked','fixed') DEFAULT NULL, + flags set('locked','fixed') DEFAULT NULL, PRIMARY KEY (ddid, ddval) ) ENGINE=InnoDB; diff --git a/db/minimal.sql b/db/minimal.sql index a302750..4b94db1 100644 --- a/db/minimal.sql +++ b/db/minimal.sql @@ -65,7 +65,7 @@ INSERT INTO settings (userid, sno, valstr) VALUES /* List of lists is always required */ INSERT INTO dropdown (ddid, ddval, ddtext, flags) VALUES -(0, 0, 'Liste der Listen', NULL), +(0, 0, 'Liste der Listen', 'locked'), (0, 1, 'Bootstypen', NULL), (0, 2, 'Firmentypen', NULL), (0, 3, 'Stauraumtypen', NULL), @@ -93,5 +93,8 @@ INSERT INTO dropdown (ddid, ddval, ddtext, flags) VALUES (3, 1, 'Tank', 'fixed'), (3, 2, 'Extern', 'fixed'); -- not on board +INSERT INTO dropdown (ddid, ddval, ddtext, ddshort, flags) VALUES +(8, 1, 'Millimeter', 'mm', 'fixed'); + INSERT INTO company (compid, compname, comptype) VALUES (-3, 'Eigenbau', 3); diff --git a/db/minimal_en.sql b/db/minimal_en.sql index 4c94054..8d30b83 100644 --- a/db/minimal_en.sql +++ b/db/minimal_en.sql @@ -92,5 +92,8 @@ INSERT INTO dropdown (ddid, ddval, ddtext, flags) VALUES (3, 1, 'Tank', 'fixed'), (3, 2, 'External', 'fixed'); +INSERT INTO dropdown (ddid, ddval, ddtext, ddshort, flags) VALUES +(8, 1, 'mm', 'Millimetre', 'fixed'); + INSERT INTO company (compid, compname, comptype) VALUES (-3, 'Custom built', 3); diff --git a/debian/changelog b/debian/changelog index 0802c0f..5a8c7d0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,17 @@ +yms (0.3.0-1) unstable; urgency=medium + + * native gui: can create and edit all kind of records + * native gui: implemented record locking + * updater script for web gui + * many bugs fixed in webgui + * prepare list revision feature (reload support) + * database localization tool + * new property table for generic key/value store + * webgui: set file access rights + * fix debian packaging + + -- Thomas Hooge Wed, 11 Nov 2026 19:00:00 +0200 + yms (0.2.2-1) unstable; urgency=medium * native gui: prepared list views for main objects diff --git a/webgui/globals.inc b/webgui/globals.inc index 29c1bd9..84d7051 100644 --- a/webgui/globals.inc +++ b/webgui/globals.inc @@ -80,7 +80,7 @@ define('TBL_TAGS', 11); // ========== PAGE START CODE ================================================= // global version string -$g_version = 'v0.2.2'; +$g_version = 'v0.3'; $g_scriptname = basename($_SERVER['SCRIPT_NAME']); diff --git a/yms.1 b/yms.1 index 7e6754b..9b81705 100644 --- a/yms.1 +++ b/yms.1 @@ -1,4 +1,4 @@ -.TH YMS 1 "September 2026" "YMS 0.2" "User Commands" +.TH YMS 1 "November 2026" "YMS 0.3" "User Commands" .SH NAME yms - Yacht Management Software .SH SYNOPSIS @@ -80,7 +80,7 @@ The source code is available from the YMS Git repository: .UR https://git.hoogi.de/thooge/YMS .UE .SH VERSION -This manual describes YMS version 0.2. +This manual describes YMS version 0.3. .SH PROJECT The YMS project homepage is available at: .UR https://yms.hoogi.de/ diff --git a/yms/database.py b/yms/database.py index 27c7c37..6efc0ca 100644 --- a/yms/database.py +++ b/yms/database.py @@ -63,11 +63,18 @@ class Database: def last_error(self): if not self.error: - return(0, '') - code = self.error.args[0] - text = self.error.args[1] + return('UnknownType', 0, '') + + etype = type(self.error).__name__ + ecode = 0 + etext = str(self.error) + + if len(self.error.args) >= 2 and isinstance(self.error.args[0], int): + ecode = self.error.args[0] + etext = str(self.error.args[1]) + self.error = None - return(code, text) + return(etype, ecode, etext) def load_enum(self, table, column): """ @@ -133,14 +140,15 @@ class Database: self.conn.commit() return self.cur.rowcount == 1 - def load_setting(self, sno): + def load_setting(self, sno, autocreate=True): sql = "SELECT valstr, valint FROM settings WHERE userid=0 AND sno=%s" self.cur.execute(sql, (sno,)) row = self.cur.fetchone() if not row: - sql = "INSERT INTO settings (userid, sno) VALUES (0, %s)" - self.cur.execute(sql, (sno,)) - self.conn.commit() + if autocreate: + sql = "INSERT INTO settings (userid, sno) VALUES (0, %s)" + self.cur.execute(sql, (sno,)) + self.conn.commit() return (None, None) return row @@ -149,22 +157,41 @@ class Database: values = (valstr, valint, sno) return self.execute_write(sql, values, 1) + def get_free_number(self, table, column): + """ + Get first free number from column, so gaps are filled + """ + sql = ( + "SELECT MIN(n.{col}) AS nextval " + "FROM (" + "SELECT 1 AS {col} " + "UNION ALL " + "SELECT DISTINCT {col} + 1 " + "FROM {tbl} " + "WHERE {col} > 0" + ") AS n " + "LEFT JOIN {tbl} AS m ON m.{col}=n.{col} " + "WHERE m.{col} IS NULL" + ).format(tbl=table, col=column) + self.cur.execute(sql) + return self.cur.fetchone()[0] or 1 + def execute_write(self, sql, values=(), expected_rows=None): """ Execute an INSERT, UPDATE, or DELETE statement. expected_rows: None = do not check the number of affected rows 1 = expect exactly one affected row - 0 = expect no affected rows + 0 = expect no affected rows / no data changed """ try: self.cur.execute(sql, values) except MySQLdb.Error as e: - self.rollback() + self.conn.rollback() self.error = e return False if (expected_rows is not None and self.cur.rowcount != expected_rows): - self.rollback() + self.conn.rollback() self.error = RuntimeError( "Expected {} affected rows, got {}".format( expected_rows, diff --git a/yms/lookup.py b/yms/lookup.py index c986556..55cd899 100644 --- a/yms/lookup.py +++ b/yms/lookup.py @@ -32,6 +32,24 @@ class Dropdown(IntEnum): BBN_VESSELDATA = 14 MEASUREMENT_CATEGORY = 15 +DDNAME = { + Dropdown.VESSEL_TYPE: "vtype", + Dropdown.COMPANY_TYPE: "comptype", + Dropdown.STORAGE_TYPE: "stype", + Dropdown.EQUIPMENT_CATEGORY: "ecat", + Dropdown.PROVISION_CATEGORY: "provcat", + Dropdown.PROVISION_UNIT: "provunit", + Dropdown.FUSE_TYPE: "ftype", + Dropdown.UNIT: "unit", + Dropdown.BOX_TYPE: "boxtype", + Dropdown.FUSE_BLOCK: "location", + Dropdown.CABLE_TYPE: "cabletype", + Dropdown.CABLE_TECHNAME: "techname", + Dropdown.INVENTORY_CATEGORY: "invcat", + Dropdown.BBN_VESSELDATA: "bbndata", + Dropdown.MEASUREMENT_CATEGORY: "mcat" +} + DropdownDeps = { Dropdown.VESSEL_TYPE: ( ('vessel', 'vtype') diff --git a/yms/model/box.py b/yms/model/box.py index c7d9152..e4620be 100644 --- a/yms/model/box.py +++ b/yms/model/box.py @@ -7,8 +7,10 @@ class Box(DbRecord): table = "box" pk_field = "boxid" - fields = ('boxid', 'sid', 'boxtype', 'parent', 'label', 'color', 'content', - 'wx', 'wy', 'wz', 'weight', 'weight_net', 'price', 'remarks') + pk_is_auto = True + fields = ('boxid', 'sid', 'boxtype', 'parent', 'label', 'color', + 'content', 'wx', 'wy', 'wz', 'weight', 'weight_net', 'price', + 'remarks') def __init__(self, db, boxid=None): super().__init__(db, boxid) diff --git a/yms/model/cable.py b/yms/model/cable.py index 2018e41..b2246df 100644 --- a/yms/model/cable.py +++ b/yms/model/cable.py @@ -7,9 +7,10 @@ class Cable(DbRecord): table = "cable" pk_field = "cableid" - fields = ('vid', 'cablename', 'cabletype', 'techname', 'length', - 'conductors', 'diameter', 'xsection', 'weight', 'color', 'supplier', - 'manufacturer', 'cablecond', 'remarks') + pk_is_auto = True + fields = ('cableid', 'vid', 'cablename', 'cabletype', 'techname', + 'length', 'conductors', 'diameter', 'xsection', 'weight', 'color', + 'supplier', 'manufacturer', 'cablecond', 'remarks') def __init__(self, db, cableid=None): super().__init__(db, cableid) diff --git a/yms/model/company.py b/yms/model/company.py index 21723c3..54c0ad1 100644 --- a/yms/model/company.py +++ b/yms/model/company.py @@ -13,9 +13,10 @@ class Company(DbRecord): table = "company" pk_field = "compid" - fields = ('compid', 'compname', 'comptype', 'comptype2', 'shortname', - 'street', 'zip', 'city', 'country', 'contact', 'phone', 'email', - 'web', 'customerno', 'contractno', 'remarks', 'flags' ) + pk_is_auto = True + fields = ('compid', 'compname', 'comptype', 'comptype2', + 'shortname', 'street', 'zip', 'city', 'country', 'contact', 'phone', + 'email', 'web', 'customerno', 'contractno', 'remarks', 'flags') def __init__(self, db, compid=None): super().__init__(db, compid) diff --git a/yms/model/dbrecord.py b/yms/model/dbrecord.py index d967c14..b3c2e0c 100644 --- a/yms/model/dbrecord.py +++ b/yms/model/dbrecord.py @@ -3,20 +3,24 @@ """ No commits here: Has to be done elsewhere to support transactions! +Fields has to be a tuple to have fixed order which simplifies debugging + +TODO primary keys can be multiple fields, stored as tuple + do not include pk auto fields in inserts and updates! """ from datetime import datetime class DbRecord: - def __init__(self, db, record_id=None): - if not hasattr(self, "table"): - raise TypeError("DbRecord subclass must define 'table'") - if not hasattr(self, "pk_field"): - raise TypeError("DbRecord subclass must define 'pk_field'") - if not hasattr(self, "fields"): - raise TypeError("DbRecord subclass must define 'fields'") + REQUIRED = ('table', 'pk_field', 'pk_is_auto', 'fields') + def __init_subclass__(cls, **kwargs): + for variable in DbRecord.REQUIRED: + if variable not in cls.__dict__: + raise TypeError(f"{cls.__name__} subclass must define '{variable}'") + + def __init__(self, db, record_id=None): self.db = db self.cur = db.cur self.dcur = db.dcur @@ -25,6 +29,7 @@ class DbRecord: self._title = _("DbRecord({})") # for pretty print + self.pk_value = None if record_id is not None: self.pk_value = int(record_id) self.load() @@ -81,7 +86,14 @@ class DbRecord: def _update(self): sqlfield = [] values = [] - for field in self.fields: + if self.pk_is_auto: + if type(self.pk_field) == tuple: + flist = set(self.fields) - set(self.pk_field) + else: + flist = set(self.fields) - {self.pk_field} + else: + flist = self.fields + for field in flist: newdata = getattr(self, field) if self.data[field] != newdata: sqlfield.append("{}=%s".format(field)) @@ -94,7 +106,7 @@ class DbRecord: ) values.append(self.pk_value) try: - self.dcur.execute(sql, values) + self.cur.execute(sql, values) except Exception as e: print(e) print(sql) @@ -106,28 +118,36 @@ class DbRecord: return True def _insert(self): + if self.pk_is_auto: + if type(self.pk_field) == tuple: + flist = set(self.fields) - set(self.pk_field) + else: + flist = set(self.fields) - {self.pk_field} + else: + flist = self.fields sql = ( "INSERT INTO {} ({}) " "VALUES ({})" ).format( self.table, - ','.join(self.fields), - ','.join(["%s"] * len(self.fields)) + ','.join(flist), + ','.join(["%s"] * len(flist)) ) values = [] - for field in self.fields: + for field in flist: newdata = getattr(self, field) values.append(newdata) self.data[field] = newdata try: - self.dcur.execute(sql, values) + self.cur.execute(sql, values) except Exception as e: print(e) print(sql) print(values) self.db.error = e return False - self.pk_value = self.dcur.lastrowid + self.pk_value = self.cur.lastrowid + setattr(self, self.pk_field, self.pk_value) return True def delete(self, record_id=None): diff --git a/yms/model/document.py b/yms/model/document.py index 751f5b9..c03ad21 100644 --- a/yms/model/document.py +++ b/yms/model/document.py @@ -6,7 +6,8 @@ class Document(DbRecord): table = "document" pk_field = "docid" - fields = ('doctype', 'mimetype', 'filename', 'extension', + pk_is_auto = True + fields = ('docid', 'doctype', 'mimetype', 'filename', 'extension', 'hash', 'docsize', 'doctime', 'docdate', 'title', 'pages', 'remarks', 'roleaccess') diff --git a/yms/model/equipment.py b/yms/model/equipment.py index 11ccd5e..01ea847 100644 --- a/yms/model/equipment.py +++ b/yms/model/equipment.py @@ -7,9 +7,10 @@ class Equipment(DbRecord): table = "equipment" pk_field = "eid" - fields = ('eid', 'vid', 'ename', 'shortname', 'model', 'ecat', 'serial', - 'supplier', 'manufacturer', 'purchdate', 'price', 'weight', 'remarks', - 'econd', 'flags') + pk_is_auto = True + fields = ('eid', 'vid', 'ename', 'shortname', 'model', 'ecat', + 'serial', 'supplier', 'manufacturer', 'purchdate', 'price', 'weight', + 'remarks', 'econd', 'flags') def __init__(self, db, eid=None): super().__init__(db, eid) diff --git a/yms/model/fuse.py b/yms/model/fuse.py index 369c644..2fcc94c 100644 --- a/yms/model/fuse.py +++ b/yms/model/fuse.py @@ -7,8 +7,9 @@ class Fuse(DbRecord): table = "fuse" pk_field = "fuseid" - fields = ('fuseid', 'vid', 'fnumber', 'ftype', 'current', 'cableid', - 'eid', 'location', 'description', 'color', 'remarks') + pk_is_auto = True + fields = ('fuseid', 'vid', 'fnumber', 'ftype', 'current', + 'cableid', 'eid', 'location', 'description', 'color', 'remarks') def __init__(self, db, fuseid=None): super().__init__(db, fuseid) diff --git a/yms/model/inventory.py b/yms/model/inventory.py index d17e3e5..aac8d58 100644 --- a/yms/model/inventory.py +++ b/yms/model/inventory.py @@ -7,8 +7,9 @@ class Inventory(DbRecord): table = "inventory" pk_field = "invid" - fields = ('invid', 'invname', 'icat', 'conttype', 'sid', 'boxid', 'eid', - 'number', 'weight', 'price', 'purchdate', 'invcond', 'remarks', + pk_is_auto = True + fields = ('invid', 'invname', 'icat', 'conttype', 'sid', 'boxid', + 'eid', 'number', 'weight', 'price', 'purchdate', 'invcond', 'remarks', 'flags') def __init__(self, db, invid=None): diff --git a/yms/model/maintenance.py b/yms/model/maintenance.py index a341969..d63553f 100644 --- a/yms/model/maintenance.py +++ b/yms/model/maintenance.py @@ -6,9 +6,10 @@ class Maintenance(DbRecord): table = "maintenance" pk_field = "maintid" - fields = ('maintid', 'vid', 'eid', 'series', 'activities', 'plan_date', - 'plan_precision', 'completion_date', 'interval_hours', 'last_hours', - 'remarks', 'maintstate') + pk_is_auto = True + fields = ('maintid', 'vid', 'eid', 'series', 'activities', + 'plan_date', 'plan_precision', 'completion_date', 'interval_hours', + 'last_hours', 'remarks', 'maintstate') def __init__(self, db, maintid=None): super().__init__(db, maintid) diff --git a/yms/model/measurement.py b/yms/model/measurement.py index db555fd..cb9cc9c 100644 --- a/yms/model/measurement.py +++ b/yms/model/measurement.py @@ -6,8 +6,9 @@ class Measurement(DbRecord): table = "measurement" pk_field = "mid" - fields = ('mid', 'mname', 'vid', 'eid', 'nval', 'val1', 'val2', 'val3', - 'unit', 'accuracy', 'mdate', 'mcat', 'note') + pk_is_auto = True + fields = ('mid', 'mname', 'vid', 'eid', 'nval', 'val1', 'val2', + 'val3', 'unit', 'accuracy', 'mdate', 'mcat', 'note') def __init__(self, db, mid=None): super().__init__(db, mid) diff --git a/yms/model/project.py b/yms/model/project.py index 04d1b87..e6426ab 100644 --- a/yms/model/project.py +++ b/yms/model/project.py @@ -7,8 +7,9 @@ class Project(DbRecord): table = "project" pk_field = "projid" - fields = ('projname', 'vid', 'responsible', 'startdate', 'duration', - 'costs_plan', 'costs_final', 'remarks', 'projstate') + pk_is_auto = True + fields = ('projid', 'projname', 'vid', 'responsible', 'startdate', + 'duration', 'costs_plan', 'costs_final', 'remarks', 'projstate') def __init__(self, db, projid=None): super().__init__(db, projid) diff --git a/yms/model/provision.py b/yms/model/provision.py index eea7686..51e5ed1 100644 --- a/yms/model/provision.py +++ b/yms/model/provision.py @@ -6,9 +6,10 @@ class Provision(DbRecord): table = "provisions" pk_field = "provid" - fields = ('provid', 'provname', 'provcat', 'sid', 'boxid', 'number', - 'target', 'weight', 'weight_net', 'unit', 'calories', 'storedate', - 'shelflife', 'price', 'remarks') + pk_is_auto = True + fields = ('provid', 'provname', 'provcat', 'sid', 'boxid', + 'number','target', 'weight', 'weight_net', 'unit', 'calories', + 'storedate', 'shelflife', 'price', 'remarks') def __init__(self, db, provid=None): super().__init__(db, provid) diff --git a/yms/model/storage.py b/yms/model/storage.py index 5be2415..3594e5a 100644 --- a/yms/model/storage.py +++ b/yms/model/storage.py @@ -12,7 +12,8 @@ class Storage(DbRecord): table = "storage" pk_field = "sid" - fields = ('vid', 'sname', 'stype', 'capacity', 'capaunit', + pk_is_auto = True + fields = ('sid', 'vid', 'sname', 'stype', 'capacity', 'capaunit', 'x', 'y', 'z', 'wx', 'wy', 'wz', 'angle', 'color', 'remarks') def __init__(self, db, sid=None): diff --git a/yms/model/task.py b/yms/model/task.py index 2d743c6..67cc6ed 100644 --- a/yms/model/task.py +++ b/yms/model/task.py @@ -6,8 +6,10 @@ class Task(DbRecord): table = "task" pk_field = "taskid" - fields = ('vid', 'projid', 'taskname', 'priority', 'taskstate', 'state_ts', - 'plandate', 'duedate', 'started', 'finished', 'responsible', 'remarks') + pk_is_auto = True + fields = ('taskid', 'vid', 'projid', 'taskname', 'priority', + 'taskstate', 'state_ts', 'plandate', 'duedate', 'started', 'finished', + 'responsible', 'remarks') def __init__(self, db, taskid=None): super().__init__(db, taskid) diff --git a/yms/model/vessel.py b/yms/model/vessel.py index cd5052f..decfc0a 100644 --- a/yms/model/vessel.py +++ b/yms/model/vessel.py @@ -6,18 +6,20 @@ class Vessel(DbRecord): table = "vessel" pk_field = "vid" - fields = ('vid', 'vtype', 'htype', 'vesselname', 'model', 'shipyard', 'hull_number', - 'loa', 'lwl', 'beam', 'draught', 'draught_min', 'displacement', 'ballast', - 'beltpos_aft', 'beltpos_bow', 'shapefile', 'sid_default', 'year_built', - 'remarks') + pk_is_auto = True + fields = ('vid', 'vtype', 'htype', 'vesselname', 'model', + 'shipyard', 'hull_number', 'loa', 'lwl', 'beam', 'draught', + 'draught_min', 'displacement', 'ballast', 'beltpos_aft', 'beltpos_bow', + 'shapefile', 'sid_default', 'year_built', 'remarks') def __init__(self, db, vid=None): super().__init__(db, vid) self.title = _("Vessel({})") def create(self): + self.clear() sql = ( - "SELECT MIN(v1.vid+1) AS newid " + "SELECT IFNULL(MIN(v1.vid+1), 1) AS newid " "FROM vessel AS v1 LEFT JOIN vessel AS v2 ON v2.vid=v1.vid+1 " "WHERE v1.vid>=0 AND v2.vid IS NULL" ) @@ -29,9 +31,8 @@ class Vessel(DbRecord): else: # create additional vessel self.pk_value = row['newid'] - self.clear() self.vid = self.pk_value - self.vesselname = f"Vessel #{self.pk_value}" + self.vesselname = "Vessel #{}".format(self.pk_value) self.htype = 'mono' self._insert() # set list change marker diff --git a/yms/treeview.py b/yms/treeview.py index b2d36f0..e9ccf37 100644 --- a/yms/treeview.py +++ b/yms/treeview.py @@ -15,6 +15,31 @@ def add_column(treeview, label, index, xalign=None, col_fg=None, col_bg=None, vi col.add_attribute(cell, 'background', col_bg) treeview.append_column(col) +def create_columns(treeview, columns, keys=0, alignments=None): + """ + columns - is a list of column titles + keys - is the number of the first visible column from the left containing + the identifying column key + alignments - l, c or r + """ + i = 0 + visible_cols = len(columns) - keys + if alignments: + alignments = alignments.lower() + if len(alignments) < visible_cols: + alignments += "l" * (visible_cols - len(alignments)) + for column in columns: + if not alignments: + add_column(treeview, column, i + keys) + else: + if alignments[i] == 'r': + add_column(treeview, column, i + keys, 1.0) + elif alignments[i] == 'c': + add_column(treeview, column, i + keys, 0.5) + else: + add_column(treeview, column, i + keys) + i += 1 + def get_value(treeview, column=0): """ Returns the value of the specified column of the linked model @@ -65,3 +90,13 @@ def set_row_values(treeview, data): model.set_value(iter, column, value) column += 1 return True + +def remove_selected_rows(treeview): + """ + Removes the currently selected rows from the model + """ + selection = treeview.get_selection() + model, paths = selection.get_selected_rows() + for path in paths: + it = model.get_iter(path) + model.remove(it) diff --git a/yms/ui/base.ui b/yms/ui/base.ui index 8fc1cdc..5eb369a 100644 --- a/yms/ui/base.ui +++ b/yms/ui/base.ui @@ -23,12 +23,14 @@ 10 - 1000 + -128 + 127 1 10 - 1000 + -128 + 127 1 10 @@ -59,8 +61,8 @@ 4096 - 10 - 100 + 8 + 64 4096 @@ -1605,6 +1607,10 @@ True True + + + + @@ -1618,15 +1624,17 @@ True False vertical + 4 True True in - + True True + @@ -1634,7 +1642,7 @@ - False + True True 0 @@ -1644,11 +1652,15 @@ True False + 4 + 4 + 4 + 6 True False - ddval + Value 0 @@ -1659,7 +1671,7 @@ True False - ddtext + Text 0 @@ -1670,7 +1682,7 @@ True False - ddshort + Short 0 @@ -1681,6 +1693,8 @@ True True + 50 + 30 1 @@ -1691,6 +1705,8 @@ True True + 4 + 4 1 @@ -1701,7 +1717,7 @@ True False - sort + Sort 0 @@ -1712,7 +1728,7 @@ True False - color + Color 0 @@ -1727,6 +1743,8 @@ True True + + False @@ -1739,6 +1757,7 @@ True True True + False @@ -1756,7 +1775,7 @@ True False - flags + Flags 0 @@ -1805,6 +1824,7 @@ True True + False adj_dd_val @@ -1834,13 +1854,29 @@ True False + 4 end - + + New + True + True + True + + + + True + True + 0 + + + + Delete True True True + True @@ -1850,11 +1886,12 @@ - + Save True True True + True @@ -1912,15 +1949,20 @@ - + True False + 4 + 4 True False Currency symbol + 0 @@ -1932,6 +1974,9 @@ True False Max image width + 0 @@ -1943,6 +1988,9 @@ True False Max image height + 0 @@ -1982,6 +2030,61 @@ 2 + + + True + False + Debug mode + + + + 0 + 3 + + + + + True + False + + + on + True + True + False + True + True + opt_debug_off + + + False + True + 0 + + + + + off + True + True + False + True + True + + + False + True + 1 + + + + + 1 + 3 + + True @@ -2009,11 +2112,16 @@ True False + 4 + 4 True False Date format + 0 diff --git a/yms/ui/equipment.ui b/yms/ui/equipment.ui index 4881134..df1cdb2 100644 --- a/yms/ui/equipment.ui +++ b/yms/ui/equipment.ui @@ -844,7 +844,7 @@ - + True False @@ -1020,7 +1020,7 @@ 0 - 11 + 12 @@ -1083,7 +1083,7 @@ 1 - 11 + 12 @@ -1142,6 +1142,69 @@ 7 + + + True + False + Flags + + + 0 + 11 + + + + + True + False + + + ordered + True + True + False + True + + + False + True + 0 + + + + + removed + True + True + False + True + + + False + True + 1 + + + + + deleted + True + True + False + True + + + False + True + 2 + + + + + 1 + 11 + + False diff --git a/yms/ui/inventory.ui b/yms/ui/inventory.ui index 30f7cf7..48ed953 100644 --- a/yms/ui/inventory.ui +++ b/yms/ui/inventory.ui @@ -531,6 +531,7 @@ True True True + 0 0 @@ -302,6 +303,7 @@ False True True + 0 @@ -416,6 +418,7 @@ False True True + 0 @@ -431,6 +434,7 @@ False True True + 0 @@ -446,6 +450,7 @@ False True True + 0 @@ -461,6 +466,7 @@ False True True + 0 @@ -476,6 +482,7 @@ False True True + 0 @@ -491,6 +498,7 @@ False True True + 0 @@ -507,6 +515,7 @@ True True True + 0 0