Native gui usable for data editing. Lots of fixes and improvenemts
This commit is contained in:
1 parent
a6abdaa614
commit
09387280fc
52 files changed
+1579
-294
No files matched your search
@@ -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
|
||||
------------------
|
||||
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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'),
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+4
-1
@@ -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);
|
||||
@@ -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);
|
||||
Vendored
+14
@@ -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 <thomas@hoogi.de> Wed, 11 Nov 2026 19:00:00 +0200
|
||||
|
||||
yms (0.2.2-1) unstable; urgency=medium
|
||||
|
||||
* native gui: prepared list views for main objects
|
||||
|
||||
+1
-1
@@ -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']);
|
||||
|
||||
|
||||
@@ -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/
|
||||
|
||||
+38
-11
@@ -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,
|
||||
|
||||
@@ -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')
|
||||
|
||||
+4
-2
@@ -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)
|
||||
|
||||
+4
-3
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
+34
-14
@@ -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):
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
+3
-2
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
+4
-2
@@ -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)
|
||||
|
||||
+8
-7
@@ -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
|
||||
|
||||
@@ -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)
|
||||
+123
-15
@@ -23,12 +23,14 @@
|
||||
<property name="page-increment">10</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adj_dd_sort">
|
||||
<property name="upper">1000</property>
|
||||
<property name="lower">-128</property>
|
||||
<property name="upper">127</property>
|
||||
<property name="step-increment">1</property>
|
||||
<property name="page-increment">10</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adj_dd_val">
|
||||
<property name="upper">1000</property>
|
||||
<property name="lower">-128</property>
|
||||
<property name="upper">127</property>
|
||||
<property name="step-increment">1</property>
|
||||
<property name="page-increment">10</property>
|
||||
</object>
|
||||
@@ -59,8 +61,8 @@
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adj_sys_max_height">
|
||||
<property name="upper">4096</property>
|
||||
<property name="step-increment">10</property>
|
||||
<property name="page-increment">100</property>
|
||||
<property name="step-increment">8</property>
|
||||
<property name="page-increment">64</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adj_sys_max_width">
|
||||
<property name="upper">4096</property>
|
||||
@@ -1605,6 +1607,10 @@
|
||||
<object class="GtkTreeView" id="tvw_ddlists">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<signal name="row-activated" handler="on_tvw_ddlists_row_activated" swapped="no"/>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
@@ -1618,15 +1624,17 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">4</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="shadow-type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="tvw_list">
|
||||
<object class="GtkTreeView" id="tvw_ddlist">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<signal name="row-activated" handler="on_tvw_ddlist_row_activated" swapped="no"/>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
@@ -1634,7 +1642,7 @@
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
@@ -1644,11 +1652,15 @@
|
||||
<object class="GtkGrid" id="grd_dd_editor">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="margin-start">4</property>
|
||||
<property name="margin-end">4</property>
|
||||
<property name="row-spacing">4</property>
|
||||
<property name="column-spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">ddval</property>
|
||||
<property name="label" translatable="yes">Value</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -1659,7 +1671,7 @@
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">ddtext</property>
|
||||
<property name="label" translatable="yes">Text</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -1670,7 +1682,7 @@
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">ddshort</property>
|
||||
<property name="label" translatable="yes">Short</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -1681,6 +1693,8 @@
|
||||
<object class="GtkEntry" id="ent_dd_text">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="max-length">50</property>
|
||||
<property name="width-chars">30</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
@@ -1691,6 +1705,8 @@
|
||||
<object class="GtkEntry" id="ent_dd_short">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="max-length">4</property>
|
||||
<property name="width-chars">4</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
@@ -1701,7 +1717,7 @@
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">sort</property>
|
||||
<property name="label" translatable="yes">Sort</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -1712,7 +1728,7 @@
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">color</property>
|
||||
<property name="label" translatable="yes">Color</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -1727,6 +1743,8 @@
|
||||
<object class="GtkEntry" id="ent_dd_color">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<signal name="activate" handler="on_ent_dd_color_activate" swapped="no"/>
|
||||
<signal name="focus-out-event" handler="on_ent_dd_color_focus_out_event" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@@ -1739,6 +1757,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<signal name="color-set" handler="on_but_dd_color_set" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@@ -1756,7 +1775,7 @@
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">flags</property>
|
||||
<property name="label" translatable="yes">Flags</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -1805,6 +1824,7 @@
|
||||
<object class="GtkSpinButton" id="spi_dd_val">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="editable">False</property>
|
||||
<property name="adjustment">adj_dd_val</property>
|
||||
</object>
|
||||
<packing>
|
||||
@@ -1834,13 +1854,29 @@
|
||||
<object class="GtkButtonBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="spacing">4</property>
|
||||
<property name="layout-style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<object class="GtkButton" id="but_list_new">
|
||||
<property name="label" translatable="yes">New</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<signal name="clicked" handler="on_but_list_new_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="but_list_delete">
|
||||
<property name="label" translatable="yes">Delete</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<signal name="clicked" handler="on_but_list_delete_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
@@ -1850,11 +1886,12 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<object class="GtkButton" id="but_list_save">
|
||||
<property name="label" translatable="yes">Save</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<signal name="clicked" handler="on_but_list_save_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
@@ -1912,15 +1949,20 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<!-- n-columns=2 n-rows=3 -->
|
||||
<!-- n-columns=2 n-rows=4 -->
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="row-spacing">4</property>
|
||||
<property name="column-spacing">4</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Currency symbol</property>
|
||||
<style>
|
||||
<class name="field-name"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -1932,6 +1974,9 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Max image width</property>
|
||||
<style>
|
||||
<class name="field-name"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -1943,6 +1988,9 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Max image height</property>
|
||||
<style>
|
||||
<class name="field-name"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -1982,6 +2030,61 @@
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Debug mode</property>
|
||||
<style>
|
||||
<class name="field-name"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="opt_debug_on">
|
||||
<property name="label" translatable="yes">on</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
<property name="group">opt_debug_off</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="opt_debug_off">
|
||||
<property name="label" translatable="yes">off</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
@@ -2009,11 +2112,16 @@
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="row-spacing">4</property>
|
||||
<property name="column-spacing">4</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Date format</property>
|
||||
<style>
|
||||
<class name="field-name"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
|
||||
+66
-3
@@ -844,7 +844,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<!-- n-columns=2 n-rows=12 -->
|
||||
<!-- n-columns=2 n-rows=13 -->
|
||||
<object class="GtkGrid" id="grd_editor">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
@@ -1020,7 +1020,7 @@
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">11</property>
|
||||
<property name="top-attach">12</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -1083,7 +1083,7 @@
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">11</property>
|
||||
<property name="top-attach">12</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -1142,6 +1142,69 @@
|
||||
<property name="top-attach">7</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Flags</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">11</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="chk_ordered">
|
||||
<property name="label" translatable="yes">ordered</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="chk_removed">
|
||||
<property name="label" translatable="yes">removed</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="chk_deleted">
|
||||
<property name="label" translatable="yes">deleted</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">11</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
||||
+10
-2
@@ -531,6 +531,7 @@
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
@@ -742,10 +743,13 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<object class="GtkLabel" id="lbl_edit_storage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Storage</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="semibold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -753,10 +757,13 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<object class="GtkLabel" id="lbl_edit_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Box</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="semibold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -859,6 +866,7 @@
|
||||
<object class="GtkComboBox" id="cmb_conttype">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cmb_conttype_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
|
||||
@@ -273,6 +273,7 @@
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
</style>
|
||||
@@ -302,6 +303,7 @@
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
</style>
|
||||
@@ -416,6 +418,7 @@
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
</style>
|
||||
@@ -431,6 +434,7 @@
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
</style>
|
||||
@@ -446,6 +450,7 @@
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
</style>
|
||||
@@ -461,6 +466,7 @@
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
</style>
|
||||
@@ -476,6 +482,7 @@
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
</style>
|
||||
@@ -491,6 +498,7 @@
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
</style>
|
||||
@@ -507,6 +515,7 @@
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0</property>
|
||||
<style>
|
||||
<class name="field-value"/>
|
||||
|
||||
@@ -609,6 +609,9 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Name</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="semibold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -620,6 +623,9 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Responsible</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="semibold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.24"/>
|
||||
<object class="GtkAdjustment" id="adj_calories">
|
||||
<property name="upper">100</property>
|
||||
<property name="step-increment">1</property>
|
||||
<property name="page-increment">10</property>
|
||||
<property name="upper">99999</property>
|
||||
<property name="step-increment">10</property>
|
||||
<property name="page-increment">100</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adj_number">
|
||||
<property name="upper">100</property>
|
||||
<property name="upper">1000</property>
|
||||
<property name="step-increment">1</property>
|
||||
<property name="page-increment">10</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adj_price">
|
||||
<property name="upper">100</property>
|
||||
<property name="upper">1000</property>
|
||||
<property name="step-increment">1</property>
|
||||
<property name="page-increment">10</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adj_target">
|
||||
<property name="upper">100</property>
|
||||
<property name="upper">1000</property>
|
||||
<property name="step-increment">1</property>
|
||||
<property name="page-increment">10</property>
|
||||
</object>
|
||||
|
||||
+46
-7
@@ -26,6 +26,7 @@
|
||||
<object class="GtkNotebook" id="ntb_status">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<signal name="switch-page" handler="on_ntb_status_switch_page" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkBox" id="box_info">
|
||||
<property name="visible">True</property>
|
||||
@@ -48,9 +49,12 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">This is an early release of YMS native GUI.
|
||||
Please use the web frontend wich is already
|
||||
You can use also the web frontend wich is already
|
||||
in an usable state.
|
||||
|
||||
Feel free to report issues and test results as well as
|
||||
improvement suggestions.
|
||||
|
||||
For further assistance please consult the related
|
||||
thread in "Segeln Forum"</property>
|
||||
</object>
|
||||
@@ -87,18 +91,53 @@ thread in "Segeln Forum"</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<object class="GtkBox" id="box_tables">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="shadow-type">in</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="tvw_tables">
|
||||
<object class="GtkScrolledWindow" id="scw_tables">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
<property name="shadow-type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="tvw_tables">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButtonBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="layout-style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="but_tables_reload">
|
||||
<property name="label" translatable="yes">Reload</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<signal name="clicked" handler="on_but_tables_reload_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
|
||||
+1
-1
@@ -910,7 +910,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox" id="cmb_unit">
|
||||
<object class="GtkComboBox" id="cmb_capaunit">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
</object>
|
||||
|
||||
+336
-40
@@ -17,7 +17,7 @@ import json
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.lookup import Dropdown
|
||||
from yms.lookup import Dropdown, DDNAME
|
||||
from yms.model import user
|
||||
|
||||
class BaseView(View):
|
||||
@@ -50,7 +50,7 @@ class BaseView(View):
|
||||
key: f"{prefix} - {today.strftime(fmt)}"
|
||||
for key, (fmt, prefix) in context.datefmt_map.items()
|
||||
}
|
||||
self.datefmt = context.db.load_setting(2)[0] or 'Y-m-d'
|
||||
self.datefmt = context.db.load_setting(2, False)[0] or 'Y-m-d'
|
||||
combobox.load_from_dict(self.combo['datefmt'], datedict, self.datefmt)
|
||||
|
||||
# shipyard
|
||||
@@ -78,15 +78,14 @@ 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())
|
||||
storages = self.context.lookup.storage(self.context.vessel.vid)
|
||||
combobox.load_from_dict(self.combo['storage'], {-1: _("─── none ───")} | storages)
|
||||
self.dd_storage = self.context.lookup.storage(self.context.vessel.vid)
|
||||
combobox.load_from_dict(self.combo['storage'], {-1: _("─── none ───")} | self.dd_storage)
|
||||
self.context.subscribe("storage_modified", self.storage_modified)
|
||||
|
||||
# Vessel types
|
||||
self.dd_vtype = self.context.lookup.dropdown(Dropdown.VESSEL_TYPE)
|
||||
combobox.load_from_dict(self.combo['vtype'], {-1: _("─── none ───")} | self.dd_vtype, -1)
|
||||
self.context.subscribe("dd_vtype_modified", self.vtype_modified)
|
||||
|
||||
# Hull types
|
||||
self.dd_htype = self.context.lookup.enum('vessel.htype')
|
||||
@@ -97,44 +96,65 @@ class BaseView(View):
|
||||
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.context.lookup.vessel()
|
||||
combobox.load_from_dict(self.combo['vessel'], vessellist, self.context.vessel.vid)
|
||||
# vessel load triggered from combobox init
|
||||
if len(vessellist) > 0:
|
||||
combobox.load_from_dict(self.combo['vessel'], vessellist, self.context.vessel.vid)
|
||||
# TODO ? vessel load triggered from combobox init
|
||||
# self.context.publish("vessel_modified", self.context.EVENT_UPD, None)
|
||||
|
||||
# prepare lists
|
||||
self.lst_user = Gtk.ListStore(int, str)
|
||||
self.db.cur.execute("SELECT userid, login FROM user WHERE userid>0 ORDER BY login")
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_user.append(row)
|
||||
self.load_list_user()
|
||||
|
||||
treeview.add_column(self.tree['user'], 'ID', 0)
|
||||
treeview.add_column(self.tree['user'], 'Login', 1)
|
||||
self.tree['user'].set_model(self.lst_user)
|
||||
|
||||
# list of dropdown lists
|
||||
# list of dropdown lists (static!)
|
||||
self.lst_lists = Gtk.ListStore(int, str, int)
|
||||
# self.db.cur.execute("SELECT ddval, ddtext FROM dropdown WHERE ddid=0 AND ddval>0 ORDER BY ddval")
|
||||
sql = (
|
||||
"SELECT dd.ddval, dd.ddtext, COUNT(n.ddval) AS records "
|
||||
"SELECT dd.ddval, dd.ddtext, FIND_IN_SET('locked', dd.flags) AS locked, "
|
||||
"COUNT(n.ddval) AS records "
|
||||
"FROM dropdown AS dd LEFT JOIN dropdown AS n ON dd.ddval=n.ddid "
|
||||
"WHERE dd.ddid=0 "
|
||||
"GROUP BY dd.ddval, dd.ddtext "
|
||||
"ORDER BY dd.ddval"
|
||||
)
|
||||
self.db.cur.execute(sql)
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_lists.append(row)
|
||||
treeview.add_column(self.tree['ddlists'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['ddlists'], _('List'), 1)
|
||||
treeview.add_column(self.tree['ddlists'], _('Records'), 2)
|
||||
self.db.dcur.execute(sql)
|
||||
for row in self.db.dcur.fetchall():
|
||||
data = []
|
||||
data.append(row['ddval'])
|
||||
if row['locked']:
|
||||
# Unicode Lock-Symbol
|
||||
data.append("{} \U0001F512".format(row['ddtext']))
|
||||
else:
|
||||
data.append(row['ddtext'])
|
||||
data.append(row['records'])
|
||||
self.lst_lists.append(data)
|
||||
treeview.create_columns(
|
||||
self.tree['ddlists'],
|
||||
(_('ID'), _('List'), _('Records'))
|
||||
)
|
||||
self.tree['ddlists'].set_model(self.lst_lists)
|
||||
|
||||
self.lst_list = Gtk.ListStore(int, str, str, int, str, str)
|
||||
treeview.create_columns(
|
||||
self.tree['ddlist'],
|
||||
(_('ID'), _('Text'), _('Short'), _('Sort'), _('Color'), _('Flags'))
|
||||
)
|
||||
self.tree['ddlist'].set_model(self.lst_list)
|
||||
|
||||
# Select first list
|
||||
selection = self.tree['ddlists'].get_selection()
|
||||
path = Gtk.TreePath.new_from_indices([1])
|
||||
selection.select_path(path)
|
||||
|
||||
self.ddid_cur = None # Current selected dropdown entry
|
||||
self.ddval_cur = None
|
||||
self.ddid_iter = None # to easy update selected item
|
||||
self.ddval_iter = None # to easy update selected item
|
||||
self.dd_newrecord = False
|
||||
|
||||
# Settings date format selection list
|
||||
# self.context.datefmt_map
|
||||
|
||||
@@ -157,13 +177,68 @@ class BaseView(View):
|
||||
# WIP generic remarks handling
|
||||
self.text['vessel_remarks'].set_size_request(200, 70)
|
||||
|
||||
def load_list(self):
|
||||
# placeholder
|
||||
pass
|
||||
|
||||
def load_list_user(self):
|
||||
selected_id = treeview.get_value(self.tree['user'])
|
||||
self.lst_user.clear()
|
||||
self.db.cur.execute("SELECT userid, login FROM user WHERE userid>0 ORDER BY login")
|
||||
selection = self.tree['user'].get_selection()
|
||||
for row in self.db.cur.fetchall():
|
||||
treeiter = self.lst_user.append(row)
|
||||
if row[0] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def load_list_dropdown(self, listid):
|
||||
self.lst_list.clear()
|
||||
sql = (
|
||||
"SELECT ddval, ddtext, ddshort, sort, color, flags "
|
||||
"FROM dropdown "
|
||||
"WHERE ddid=%s "
|
||||
"ORDER BY ddval"
|
||||
)
|
||||
self.db.cur.execute(sql, (listid,))
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_list.append(row)
|
||||
|
||||
def load_dropdowns(self):
|
||||
# non static dropdown (re-)load feature
|
||||
# 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())
|
||||
combobox.refresh_dict(self.combo['storage'], {-1: _("─── none ───")} | storages)
|
||||
self.dd_storage = dict(self.db.cur.fetchall())
|
||||
combobox.refresh_dict(self.combo['storage'], {-1: _("─── none ───")} | self.dd_storage)
|
||||
|
||||
def vtype_modified(self, eventtype, data):
|
||||
self.dd_vtype[data[0]] = data[1]
|
||||
lst = self.combo['vtype'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def storage_modified(self, eventtype, data):
|
||||
self.dd_storage[data[0]] = data[1]
|
||||
lst = self.combo['storage'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def load_shapes(self):
|
||||
# TODO / WIP process shapeindex
|
||||
@@ -173,7 +248,7 @@ class BaseView(View):
|
||||
# load json
|
||||
with open(indexfile, "r", encoding="utf-8") as fh:
|
||||
sflist = json.load(fh)
|
||||
print("Shapefile found and loaded")
|
||||
print("Shapeindex file found and loaded")
|
||||
else:
|
||||
# create shapeindex (first simple version)
|
||||
sflist = {}
|
||||
@@ -328,7 +403,7 @@ class BaseView(View):
|
||||
self.db.conn.commit()
|
||||
# Refresh dependent data
|
||||
self.load_dropdowns()
|
||||
self.context.publish("vessel_changed", (self.context.vessel.pk_value, ))
|
||||
self.context.publish("vessel_modified", self.context.EVENT_UPD, (self.context.vessel.pk_value, ))
|
||||
# Show data
|
||||
self.display_vessel(self.context.vessel)
|
||||
|
||||
@@ -340,9 +415,13 @@ class BaseView(View):
|
||||
if answer == False:
|
||||
return
|
||||
self.context.vessel.create()
|
||||
print(self.context.vessel)
|
||||
model = self.combo['vessel'].get_model()
|
||||
model.append((self.context.vessel.vid, self.context.vessel.vesselname))
|
||||
combobox.activate_row(self.combo['vessel'], self.context.vessel.vid)
|
||||
if model is None:
|
||||
combobox.load_from_dict(self.combo['vessel'], {self.context.vessel.vid: self.context.vessel.vesselname}, self.context.vessel.vid)
|
||||
else:
|
||||
model.append((self.context.vessel.vid, self.context.vessel.vesselname))
|
||||
combobox.activate_row(self.combo['vessel'], self.context.vessel.vid)
|
||||
self.edit_vessel(self.context.vessel)
|
||||
self.stack['vessel'].set_visible_child(self.box['vessel_edit'])
|
||||
|
||||
@@ -377,19 +456,43 @@ class BaseView(View):
|
||||
vessel.shapefile = None
|
||||
vessel.remarks = gtkutils.get_text_contents(self.text['vessel_remarks'])
|
||||
vessel.save()
|
||||
self.context.publish("vessel_modified", self.context.EVENT_UPD, (vessel.vid, ))
|
||||
self.stack['vessel'].set_visible_child(self.box['vessel'])
|
||||
self.display_vessel(self.context.vessel)
|
||||
|
||||
def on_but_vessel_cancel_clicked(self, widget):
|
||||
self.stack['vessel'].set_visible_child(self.box['vessel'])
|
||||
|
||||
def on_but_vessel_delete_clicked(self, widget):
|
||||
pass
|
||||
# TODO check if there are no associated data with vessel
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete vessel!\n"
|
||||
"Are you sure?"
|
||||
), title="YMS")
|
||||
if answer == False:
|
||||
return
|
||||
# TODO
|
||||
|
||||
def on_but_settings_save_clicked(self, widget):
|
||||
print("Save settings")
|
||||
#self.entry['sys_currency']
|
||||
#self.spin['sys_max_width']
|
||||
#self.spin['sys_max_height']
|
||||
# System settings
|
||||
new_currency = self.entry['sys_currency'].get_text()
|
||||
if self.sys_currency != new_currency:
|
||||
self.db.save_setting(4, new_currency, None)
|
||||
self.sys_currency = new_currency
|
||||
new_max_width = self.spin['sys_max_width'].get_value_as_int()
|
||||
if self.sys_max_width != new_max_width:
|
||||
self.db.save_setting(20, None, new_max_width)
|
||||
self.sys_max_width = new_max_width
|
||||
new_max_height = self.spin['sys_max_height'].get_value_as_int()
|
||||
if self.sys_max_height != new_max_height:
|
||||
self.db.save_setting(21, None, new_max_height)
|
||||
self.sys_max_height = new_max_height
|
||||
# User settings
|
||||
new_datefmt = combobox.get_list_value(self.combo['datefmt'])
|
||||
if self.datefmt != new_datefmt:
|
||||
self.db.save_setting(2, new_datefmt, None)
|
||||
self.context.datefmt = new_datefmt
|
||||
self.db.conn.commit()
|
||||
|
||||
def display_vessel(self, vessel):
|
||||
self.label['vesselname'].set_text(vessel.vesselname)
|
||||
@@ -453,7 +556,6 @@ class BaseView(View):
|
||||
self.lst_user.append((self.context.user.user_id, self.context.user.login))
|
||||
|
||||
def on_but_user_del_clicked(self, widget):
|
||||
print("Delete user")
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete user!\n"
|
||||
"Are you sure?"
|
||||
@@ -503,3 +605,197 @@ class BaseView(View):
|
||||
else:
|
||||
# Password to short
|
||||
pass
|
||||
|
||||
def clear_dd_entry(self):
|
||||
# Clear list entry editor
|
||||
self.spin['dd_val'].set_text('')
|
||||
self.entry['dd_text'].set_text('')
|
||||
self.entry['dd_short'].set_text('')
|
||||
self.spin['dd_sort'].set_text('')
|
||||
self.entry['dd_color'].set_text('')
|
||||
# TODO set color button to undef shown as 100% transparent
|
||||
# self.button['dd_color']
|
||||
self.check['dd_fixed'].set_active(False)
|
||||
self.check['dd_locked'].set_active(False)
|
||||
|
||||
def on_but_dd_color_set(self, button):
|
||||
rgba = button.get_rgba()
|
||||
r = round(rgba.red * 255)
|
||||
g = round(rgba.green * 255)
|
||||
b = round(rgba.blue * 255)
|
||||
a = round(rgba.alpha * 255)
|
||||
if a > 0:
|
||||
self.entry['dd_color'].set_text(f"#{r:02X}{g:02X}{b:02X}")
|
||||
else:
|
||||
self.entry['dd_color'].set_text('')
|
||||
|
||||
def on_ent_dd_color_activate(self, entry):
|
||||
self.set_color_from_entry(entry, self.button['dd_color'])
|
||||
|
||||
def on_ent_dd_color_focus_out_event(self, entry, event):
|
||||
self.set_color_from_entry(entry, self.button['dd_color'])
|
||||
return False
|
||||
|
||||
def on_but_list_new_clicked(self, widget):
|
||||
self.dd_newrecord = True
|
||||
self.ddval_cur = None
|
||||
self.clear_dd_entry()
|
||||
# get next free value for ddid, ddval
|
||||
sql = (
|
||||
"SELECT MIN(n.ddval) AS nextval "
|
||||
"FROM ("
|
||||
"SELECT 1 AS ddval "
|
||||
"UNION ALL "
|
||||
"SELECT DISTINCT ddval+1 "
|
||||
"FROM dropdown "
|
||||
"WHERE ddid=%(ddid)s AND ddval>0"
|
||||
") AS n "
|
||||
"LEFT JOIN dropdown AS m ON m.ddval=n.ddval AND m.ddid=%(ddid)s "
|
||||
"WHERE m.ddval IS NULL"
|
||||
)
|
||||
self.db.cur.execute(sql, {'ddid': self.ddid_cur})
|
||||
self.ddval_cur = self.db.cur.fetchone()[0] or 1
|
||||
if not self.ddval_cur:
|
||||
# TODO message internal error to user
|
||||
print("internal error while creating new value")
|
||||
return
|
||||
self.spin['dd_val'].set_value(self.ddval_cur)
|
||||
self.button['list_save'].set_sensitive(True)
|
||||
self.entry['dd_text'].grab_focus()
|
||||
|
||||
def on_but_list_save_clicked(self, widget):
|
||||
if self.dd_newrecord:
|
||||
sql = (
|
||||
"INSERT INTO dropdown (ddid, ddval, ddtext, ddshort, sort, color, flags) "
|
||||
"VALUES (%s, %s, %s, %s, %s, %s, %s)"
|
||||
)
|
||||
values = (
|
||||
self.ddid_cur,
|
||||
self.spin['dd_val'].get_value_as_int(), # autogenerated by new button
|
||||
self.entry['dd_text'].get_text(),
|
||||
self.entry['dd_short'].get_text(),
|
||||
self.spin['dd_sort'].get_value_as_int(),
|
||||
self.entry['dd_color'].get_text().lstrip('#'),
|
||||
self.get_checks(('dd_locked', 'dd_fixed'), prefix='dd_')
|
||||
)
|
||||
if self.db.execute_write(sql, values, 1):
|
||||
self.db.conn.commit()
|
||||
else:
|
||||
# TODO message sql error to user
|
||||
print(self.db.last_error())
|
||||
print(sql, values)
|
||||
return
|
||||
# TODO
|
||||
# message success to user
|
||||
# refresh list
|
||||
data = (
|
||||
self.spin['dd_val'].get_value_as_int(),
|
||||
self.entry['dd_text'].get_text(),
|
||||
self.entry['dd_short'].get_text(),
|
||||
self.spin['dd_sort'].get_value_as_int(),
|
||||
self.entry['dd_color'].get_text().lstrip('#'),
|
||||
'' # TODO flags
|
||||
)
|
||||
treeiter = self.lst_list.append(data)
|
||||
selection = self.tree['ddlist'].get_selection()
|
||||
selection.select_iter(treeiter)
|
||||
# increase entry in main list
|
||||
count = treeview.get_value(self.tree['ddlists'], 2)
|
||||
treeview.set_value(self.tree['ddlists'], 2, count+1)
|
||||
# send event
|
||||
eventname = "dd_{}_modified".format(DDNAME[self.ddid_cur])
|
||||
self.context.publish(eventname, self.context.EVENT_ADD, (data[0], data[1]))
|
||||
else:
|
||||
if self.ddid_cur is None or self.ddval_cur is None:
|
||||
print("internal error: ids not set")
|
||||
return
|
||||
sql = (
|
||||
"UPDATE dropdown SET ddtext=%s, ddshort=%s, sort=%s, color=%s, flags=%s "
|
||||
"WHERE ddid=%s AND ddval=%s"
|
||||
)
|
||||
values = (
|
||||
self.entry['dd_text'].get_text(),
|
||||
self.entry['dd_short'].get_text(),
|
||||
self.spin['dd_sort'].get_value_as_int(),
|
||||
self.entry['dd_color'].get_text().lstrip('#'),
|
||||
self.get_checks(('dd_locked', 'dd_fixed'), prefix='dd_'),
|
||||
self.ddid_cur,
|
||||
self.ddval_cur
|
||||
)
|
||||
if self.db.execute_write(sql, values):
|
||||
self.db.conn.commit()
|
||||
else:
|
||||
# TODO message sql error to user
|
||||
print(self.db.last_error())
|
||||
print(sql, values)
|
||||
return
|
||||
# refresh list
|
||||
data = (
|
||||
self.spin['dd_val'].get_value_as_int(),
|
||||
self.entry['dd_text'].get_text(),
|
||||
self.entry['dd_short'].get_text(),
|
||||
self.spin['dd_sort'].get_value_as_int(),
|
||||
self.entry['dd_color'].get_text().lstrip('#'),
|
||||
'' # TODO flags
|
||||
)
|
||||
treeview.set_row_values(self.tree['ddlist'], data)
|
||||
# send event
|
||||
eventname = "dd_{}_modified".format(DDNAME[self.ddid_cur])
|
||||
self.context.publish(eventname, self.context.EVENT_UPD, (data[0], data[1]))
|
||||
|
||||
self.dd_newrecord = False
|
||||
|
||||
# TODO
|
||||
# message success to user
|
||||
# refresh list
|
||||
|
||||
def on_but_list_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete list entry!\n"
|
||||
"Are you sure?"
|
||||
), title="YMS")
|
||||
if answer == False:
|
||||
return
|
||||
|
||||
def on_tvw_ddlists_row_activated(self, widget, path, column):
|
||||
# load single list
|
||||
self.ddid_iter = widget.get_selection().get_selected()[1]
|
||||
self.ddid_cur = treeview.get_value(widget, 0)
|
||||
self.ddval_cur = None
|
||||
self.load_list_dropdown(self.ddid_cur)
|
||||
self.clear_dd_entry()
|
||||
self.button['list_save'].set_sensitive(False)
|
||||
|
||||
def on_tvw_ddlist_row_activated(self, widget, path, column):
|
||||
# load list entry details
|
||||
self.ddval_iter = widget.get_selection().get_selected()[1]
|
||||
self.ddval_cur = treeview.get_value(widget, 0)
|
||||
sql = (
|
||||
"SELECT ddtext, ddshort, sort, color, flags "
|
||||
"FROM dropdown "
|
||||
"WHERE ddid=%s AND ddval=%s "
|
||||
"ORDER BY ddval"
|
||||
)
|
||||
self.db.dcur.execute(sql, (self.ddid_cur, self.ddval_cur))
|
||||
row = self.db.dcur.fetchone()
|
||||
if not row:
|
||||
# internal error
|
||||
print(f"internal error ddval #{self.ddval_cur} not found")
|
||||
self.ddval_cur = None
|
||||
return
|
||||
|
||||
# fill edit fields
|
||||
self.spin['dd_val'].set_value(self.ddval_cur)
|
||||
self.entry['dd_text'].set_text(row['ddtext'] or '')
|
||||
self.entry['dd_short'].set_text(row['ddshort'] or '')
|
||||
if row['sort']:
|
||||
self.spin['dd_sort'].set_value(row['sort'])
|
||||
else:
|
||||
self.spin['dd_sort'].set_text('')
|
||||
self.entry['dd_color'].set_text(row['color'] or '')
|
||||
flags = (row['flags'] or '').split(',')
|
||||
self.check['dd_fixed'].set_active('fixed' in flags)
|
||||
self.check['dd_locked'].set_active('locked' in flags)
|
||||
|
||||
self.button['list_save'].set_sensitive(True)
|
||||
self.dd_newrecord = False
|
||||
+50
-14
@@ -33,8 +33,23 @@ class BoxesView(View):
|
||||
combobox.load_from_dict(self.combo['type'], {-1: _("─── none ───")} | self.dd_boxtype)
|
||||
|
||||
# subscribe to data change events
|
||||
self.context.subscribe("storage_added", self.storage_added)
|
||||
self.context.subscribe("storage_changed", self.storage_changed)
|
||||
self.context.subscribe("storage_modified", self.storage_modified)
|
||||
self.context.subscribe("dd_boxtype_modified", self.boxtype_modified)
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.sbox.boxid,
|
||||
self.sbox.label,
|
||||
self.sbox.content,
|
||||
self.sbox.remarks
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_box.append(self.get_list_row())
|
||||
self.tree['box'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['box'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['box'])
|
||||
@@ -53,22 +68,37 @@ class BoxesView(View):
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def storage_added(self, data):
|
||||
self.dd_storage[data[0]] = data[1]
|
||||
lst = self.combo['storage'].get_model()
|
||||
lst.append(data)
|
||||
def boxtype_modified(self, eventtype, data):
|
||||
self.dd_box[data[0]] = data[1]
|
||||
lst = self.combo['type'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def storage_changed(self, data):
|
||||
def storage_modified(self, eventtype, data):
|
||||
self.dd_storage[data[0]] = data[1]
|
||||
lst = self.combo['storage'].get_model()
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def clear_record(self):
|
||||
self.entry['label'].set_text('')
|
||||
combobox.activate_row(self.combo['storage'], 0)
|
||||
combobox.activate_row(self.combo['storage'], 1)
|
||||
combobox.activate_row(self.combo['type'], -1)
|
||||
self.entry['content'].set_text('')
|
||||
self.spin['wx'].set_value(0)
|
||||
@@ -104,7 +134,7 @@ 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['storage'], self.sbox.sid or 1)
|
||||
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)
|
||||
@@ -197,7 +227,13 @@ class BoxesView(View):
|
||||
pass
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
#self.load_list()
|
||||
self.add_row()
|
||||
self.context.publish("box_modified", self.context.EVENT_ADD, (self.sbox.pk_value, self.sbox.label))
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.context.publish("box_modified", self.context.EVENT_UPD, (self.sbox.pk_value, self.sbox.label))
|
||||
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['box_detail'])
|
||||
|
||||
+62
-6
@@ -41,6 +41,25 @@ class CablesView(View):
|
||||
self.dd_condition = self.context.lookup.enum('cable.cablecond')
|
||||
combobox.load_from_dict(self.combo['condition'], self.dd_condition, 'unknown')
|
||||
|
||||
# subscribe to data change events
|
||||
#self.context.subscribe("dd_type_modified", self.type_modified)
|
||||
#self.context.subscribe("dd_techname_modified", self.techname_modified)
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.cable.cableid,
|
||||
self.cable.cablename,
|
||||
self.dd_condition.get(self.cable.cablecond, ''),
|
||||
self.format_float(self.cable.length, suffix="m")
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_cables.append(self.get_list_row())
|
||||
self.tree['cables'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['cables'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['cables'])
|
||||
self.lst_cables.clear()
|
||||
@@ -64,6 +83,34 @@ class CablesView(View):
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def type_modified(self, eventtype, data):
|
||||
self.dd_type[data[0]] = data[1]
|
||||
lst = self.combo['type'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def techname_modified(self, eventtype, data):
|
||||
self.dd_techname[data[0]] = data[1]
|
||||
lst = self.combo['techname'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.cable.cablename or '')
|
||||
if self.cable.cabletype:
|
||||
@@ -74,11 +121,11 @@ class CablesView(View):
|
||||
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['length'].set_text(self.format_float(self.cable.length, suffix="m"))
|
||||
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))
|
||||
self.label['diameter'].set_text(self.format_float(self.cable.diameter, 1, suffix="mm"))
|
||||
self.label['xsection'].set_text(self.format_float(self.cable.xsection, 1, suffix="mm²"))
|
||||
self.label['weight'].set_text(self.format_float(self.cable.weight, suffix="kg/m"))
|
||||
if self.cable.color:
|
||||
self.label['color'].set_markup(f'#{self.cable.color} <span foreground="#{self.cable.color}">●</span>')
|
||||
else:
|
||||
@@ -219,8 +266,17 @@ class CablesView(View):
|
||||
return
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
#self.load_list()
|
||||
self.add_row()
|
||||
self.context.publish("cable_modified", self.context.EVENT_ADD,
|
||||
(self.cable.pk_value, self.cable.cablename)
|
||||
)
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.context.publish("cable_modified", self.context.EVENT_UPD,
|
||||
(self.cable.pk_value, self.cable.cablename)
|
||||
)
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['cable_detail'])
|
||||
|
||||
|
||||
+48
-2
@@ -35,6 +35,24 @@ class CompaniesView(View):
|
||||
treeview.add_column(self.tree['companies'], _('Remarks'), 3)
|
||||
self.tree['companies'].set_model(self.lst_companies)
|
||||
|
||||
# subscribe to data change events
|
||||
self.context.subscribe("dd_comptype_modified", self.comptype_modified)
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.comp.compid,
|
||||
self.comp.compname,
|
||||
self.dd_comptype.get(self.comp.comptype, ''),
|
||||
self.comp.remarks
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_companies.append(self.get_list_row())
|
||||
self.tree['companies'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['companies'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['companies'])
|
||||
self.lst_companies.clear()
|
||||
@@ -52,6 +70,25 @@ class CompaniesView(View):
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def comptype_modified(self, eventtype, data):
|
||||
self.dd_comptype[data[0]] = data[1]
|
||||
lst1 = self.combo['flt_type'].get_model()
|
||||
lst2 = self.combo['comptype'].get_model()
|
||||
lst3 = self.combo['comptype2'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for l in (lst1, lst2, lst3):
|
||||
for row in l:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst1.append(data)
|
||||
lst2.append(data)
|
||||
lst3.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def clear_record(self):
|
||||
self.comp.clear()
|
||||
self.entry['compname'].set_text('')
|
||||
@@ -128,7 +165,7 @@ class CompaniesView(View):
|
||||
self.comp.web = self.entry['web'].get_text()
|
||||
self.comp.customerno = self.entry['customerno'].get_text()
|
||||
self.comp.contractno = self.entry['contractno'].get_text()
|
||||
self.comp.flags = self.get_checks(('historic', 'ordered'))
|
||||
self.comp.flags = self.get_checks(('historic', 'deleted'))
|
||||
self.comp.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
@@ -193,7 +230,16 @@ class CompaniesView(View):
|
||||
pass
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
#self.load_list()
|
||||
self.add_row()
|
||||
self.context.publish("company_modified", self.context.EVENT_ADD,
|
||||
(self.comp.pk_value, self.comp.comptype, self.comp.compname)
|
||||
)
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.context.publish("company_modified", self.context.EVENT_UPD,
|
||||
(self.comp.pk_value, self.comp.comptype, self.comp.compname)
|
||||
)
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['comp_detail'])
|
||||
|
||||
+27
-1
@@ -53,6 +53,28 @@ class DocumentsView(View):
|
||||
self.dd_access = self.context.lookup.enum('document.roleaccess')
|
||||
combobox.load_from_dict(self.combo['accesslevel'], self.dd_access)
|
||||
|
||||
def get_refcount(self):
|
||||
if self.doc.docid is None:
|
||||
return 0
|
||||
self.db.cur.execute("SELECT COUNT(*) FROM docref WHERE docid=%s", (self.doc.docid,))
|
||||
return self.db.cur.fetchone()[0]
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.doc.docid,
|
||||
self.doc.doctype,
|
||||
self.doc.filename,
|
||||
self.doc.title,
|
||||
self.get_refcount()
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_documents.append(self.get_list_row())
|
||||
self.tree['documents'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['documents'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['documents'])
|
||||
self.lst_documents.clear()
|
||||
@@ -102,7 +124,7 @@ class DocumentsView(View):
|
||||
def display_record(self):
|
||||
print(self.doc)
|
||||
self.label['title'].set_text(self.doc.title or '')
|
||||
self.label['filename'].set_text(self.doc.filename)
|
||||
self.label['filename'].set_text(self.doc.filename or '')
|
||||
# self.label['extents'] -> see below
|
||||
self.label['mimetype'].set_text(self.doc.mimetype)
|
||||
self.label['filesize'].set_text(self.format_int(self.doc.docsize, suffix="Byte"))
|
||||
@@ -264,6 +286,10 @@ class DocumentsView(View):
|
||||
|
||||
def on_but_save_clicked(self, widget):
|
||||
print(self.doc)
|
||||
if self.newrecord:
|
||||
self.add_row()
|
||||
else:
|
||||
self.refresh_row()
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['documents'])
|
||||
|
||||
+30
-2
@@ -47,6 +47,9 @@ class EquipmentView(View):
|
||||
self.entry['purchdate'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_purchdate = DatePicker(self.entry['purchdate'], self.button['purchdate'], context.get_datefmt())
|
||||
|
||||
# subscribe to data change events
|
||||
self.context.subscribe("dd_ecat_modified", self.category_modified)
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.equip.eid,
|
||||
@@ -86,6 +89,20 @@ class EquipmentView(View):
|
||||
def on_page_activated(self):
|
||||
print("Equipment activated")
|
||||
|
||||
def category_modified(self, eventtype, data):
|
||||
self.dd_category[data[0]] = data[1]
|
||||
lst = self.combo['category'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def clear_record(self):
|
||||
self.equip.clear()
|
||||
self.entry['name'].set_text('')
|
||||
@@ -103,7 +120,7 @@ class EquipmentView(View):
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.equip.ename)
|
||||
self.label['name'].set_text(self.equip.ename or '')
|
||||
self.label['shortname'].set_text(self.equip.shortname or '')
|
||||
if self.equip.manufacturer:
|
||||
self.label['manufacturer'].set_text(self.dd_manufacturer[self.equip.manufacturer])
|
||||
@@ -123,7 +140,8 @@ class EquipmentView(View):
|
||||
else:
|
||||
self.label['category'].set_text('')
|
||||
self.label['flags'].set_text(self.equip.flags or '')
|
||||
self.label['condition'].set_text(pgettext("equipment.econd", self.equip.econd))
|
||||
#self.label['condition'].set_text(pgettext("equipment.econd", self.equip.econd))
|
||||
self.label['condition'].set_text(self.dd_condition[self.equip.econd])
|
||||
self.label['remarks'].set_text(self.equip.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
@@ -139,6 +157,9 @@ class EquipmentView(View):
|
||||
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')
|
||||
flags = (self.equip.flags or '').split(',')
|
||||
for flag in self.context.lookup.enum('equipment.flags'):
|
||||
self.check[flag].set_active(flag in flags)
|
||||
self.text['remarks'].get_buffer().set_text(self.equip.remarks or '')
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
@@ -166,6 +187,7 @@ class EquipmentView(View):
|
||||
if self.equip.ecat < 0:
|
||||
self.equip.ecat = None
|
||||
self.equip.econd = combobox.get_list_value(self.combo['condition'])
|
||||
self.equip.flags = self.get_checks(('ordered', 'removed', 'deleted'))
|
||||
self.equip.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
print(self.equip)
|
||||
|
||||
@@ -244,8 +266,14 @@ class EquipmentView(View):
|
||||
if self.newrecord:
|
||||
self.add_row()
|
||||
#self.load_list()
|
||||
self.context.publish("equipment_modified", self.context.EVENT_ADD,
|
||||
(self.equip.pk_value, self.equip.ename)
|
||||
)
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.context.publish("equipment_modified", self.context.EVENT_UPD,
|
||||
(self.equip.pk_value, self.equip.ename)
|
||||
)
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['equip_detail'])
|
||||
|
||||
+91
-6
@@ -38,6 +38,27 @@ class FusesView(View):
|
||||
self.dd_location = self.context.lookup.dropdown(Dropdown.FUSE_BLOCK)
|
||||
combobox.load_from_dict(self.combo['location'], {-1: _("─── unknown ───")} | self.dd_location)
|
||||
|
||||
# subscribe to data change events
|
||||
self.context.subscribe("equipment_modified", self.equipment_modified)
|
||||
self.context.subscribe("cable_modified", self.cable_modified)
|
||||
self.context.subscribe("dd_ftype_modified", self.ftype_modified)
|
||||
self.context.subscribe("dd_location_modified", self.location_modified)
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.fuse.fuseid,
|
||||
'F{}'.format(self.fuse.fnumber),
|
||||
self.format_float(self.fuse.current, 1, suffix="A"),
|
||||
self.fuse.description
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_fuses.append(self.get_list_row())
|
||||
self.tree['fuses'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['fuses'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['fuses'])
|
||||
self.lst_fuses.clear()
|
||||
@@ -61,6 +82,62 @@ class FusesView(View):
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def equipment_modified(self, eventtype, data):
|
||||
self.dd_equipment[data[0]] = data[1]
|
||||
lst = self.combo['equipment'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def cable_modified(self, eventtype, data):
|
||||
self.dd_cable[data[0]] = data[1]
|
||||
lst = self.combo['cable'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def ftype_modified(self, eventtype, data):
|
||||
self.dd_ftype[data[0]] = data[1]
|
||||
lst = self.combo['ftype'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def location_modified(self, eventtype, data):
|
||||
self.dd_location[data[0]] = data[1]
|
||||
lst = self.combo['location'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def clear_record(self):
|
||||
self.fuse.clear()
|
||||
self.spin['fnumber'].set_value(0)
|
||||
@@ -79,7 +156,7 @@ class FusesView(View):
|
||||
self.label['type'].set_text(self.dd_ftype[self.fuse.ftype] or '')
|
||||
else:
|
||||
self.label['type'].set_text('')
|
||||
self.label['current'].set_text(self.format_float(self.fuse.current, 2, suffix="A"))
|
||||
self.label['current'].set_text(self.format_float(self.fuse.current, 1, suffix="A"))
|
||||
if self.fuse.cableid:
|
||||
self.label['cable'].set_text(self.dd_cable[self.fuse.cableid])
|
||||
else:
|
||||
@@ -160,11 +237,11 @@ class FusesView(View):
|
||||
self.topwidget.set_visible_child(self.box['fuse_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
fuseid = treeview.get_value(self.tree['fuses'], 0)
|
||||
if fuseid is None:
|
||||
return
|
||||
self.label['title_edit'].set_text(_("Edit Fuse"))
|
||||
self.newrecord = False
|
||||
fuseid = treeview.get_value(self.tree['fuses'], 0)
|
||||
if not self.record_lock('fuse', fuseid):
|
||||
return
|
||||
self.fuse.load(fuseid)
|
||||
@@ -205,20 +282,28 @@ class FusesView(View):
|
||||
def on_but_save_clicked(self, widget):
|
||||
fnumber = self.spin['fnumber'].get_value_as_int()
|
||||
current = self.spin['current'].get_value()
|
||||
# TODO check for duplicate number!
|
||||
sql = "SELECT COUNT(fnumber) FROM fuse WHERE fnumber=%s"
|
||||
|
||||
if (fnumber == 0) or (current == 0):
|
||||
# TODO error marker
|
||||
return
|
||||
if self.newrecord:
|
||||
# TODO check for duplicate number!
|
||||
sql = "SELECT COUNT(fnumber) FROM fuse WHERE fnumber=%s"
|
||||
self.context.db.cur.execute(sql, (fnumber,))
|
||||
if self.context.db.cur.fetchone()[0] > 0:
|
||||
# Duplicate fuse number
|
||||
print("duplicate fuse number")
|
||||
return
|
||||
self.save_record()
|
||||
print(self.fuse)
|
||||
if not self.fuse.save():
|
||||
pass
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
#self.load_list()
|
||||
self.add_row()
|
||||
self.newrecord = False
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['fuse_detail'])
|
||||
|
||||
|
||||
+85
-15
@@ -5,7 +5,7 @@ from gi.repository import GLib, Gtk, Gdk
|
||||
from dateutil.parser import parse
|
||||
from gettext import pgettext
|
||||
|
||||
from .view import View
|
||||
from .view import View, DatePicker
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.lookup import Dropdown
|
||||
from yms.model import inventory
|
||||
@@ -52,6 +52,15 @@ class InventoryView(View):
|
||||
self.dd_condition = self.context.lookup.enum('inventory.invcond')
|
||||
combobox.load_from_dict(self.combo['condition'], self.dd_condition)
|
||||
|
||||
self.entry['purchdate'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
DatePicker(self.entry['purchdate'], self.button['purchdate'], context.get_datefmt())
|
||||
|
||||
# subscribe to data change events
|
||||
self.context.subscribe("storage_modified", self.storage_modified)
|
||||
self.context.subscribe("box_modified", self.box_modified)
|
||||
self.context.subscribe("equipment_modified", self.equipment_modified)
|
||||
self.context.subscribe("dd_invcat_modified", self.category_modified)
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['inventory'])
|
||||
self.lst_inventory.clear()
|
||||
@@ -71,13 +80,66 @@ class InventoryView(View):
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def storage_modified(self, eventtype, data):
|
||||
self.dd_storage[data[0]] = data[1]
|
||||
lst = self.combo['storage'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def box_modified(self, eventtype, data):
|
||||
self.dd_box[data[0]] = data[1]
|
||||
lst = self.combo['box'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
else:
|
||||
lst.append(data)
|
||||
|
||||
def equipment_modified(self, eventtype, data):
|
||||
self.dd_equipment[data[0]] = data[1]
|
||||
lst = self.combo['equipment'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def category_modified(self, eventtype, data):
|
||||
self.dd_category[data[0]] = data[1]
|
||||
lst = self.combo['category'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def on_page_activated(self):
|
||||
print("Inventory activated")
|
||||
|
||||
def clear_record(self):
|
||||
self.inv.clear()
|
||||
self.entry['name'].set_text('')
|
||||
combobox.activate_row(self.combo['conttype'], -1)
|
||||
combobox.activate_row(self.combo['conttype'], 'storage')
|
||||
combobox.activate_row(self.combo['storage'], -1)
|
||||
combobox.activate_row(self.combo['box'], -1)
|
||||
combobox.activate_row(self.combo['equipment'], -1)
|
||||
@@ -108,7 +170,7 @@ 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['flags'].set_text(self.inv.flags or '')
|
||||
self.label['remarks'].set_text(self.inv.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
@@ -123,7 +185,7 @@ class InventoryView(View):
|
||||
self.entry['purchdate'].set_text(self.format_date(self.inv.purchdate))
|
||||
combobox.activate_row(self.combo['condition'], self.inv.invcond)
|
||||
combobox.activate_row(self.combo['category'], self.inv.icat or -1)
|
||||
flags = self.inv.flags.split(',')
|
||||
flags = (self.inv.flags or '').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 '')
|
||||
@@ -134,15 +196,16 @@ class InventoryView(View):
|
||||
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:
|
||||
# only one of storage or box can be set depending of container type
|
||||
if self.inv.conttype == 'storage':
|
||||
self.inv.boxid = None
|
||||
else:
|
||||
self.inv.sid = 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.number = self.spin['number'].get_value_as_int()
|
||||
self.inv.weight = self.spin['weight'].get_value()
|
||||
self.inv.price = self.spin['price'].get_value()
|
||||
try:
|
||||
@@ -154,13 +217,7 @@ class InventoryView(View):
|
||||
self.inv.icat = combobox.get_list_value(self.combo['category'])
|
||||
if self.inv.icat == -1:
|
||||
self.inv.icat = None
|
||||
# TODO this could be a generic function operating on a list
|
||||
# of check controls
|
||||
flags = []
|
||||
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.flags = self.get_checks(('ordered', 'removed', 'deleted'))
|
||||
self.inv.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
@@ -196,6 +253,19 @@ class InventoryView(View):
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_detail'])
|
||||
|
||||
def on_cmb_conttype_changed(self, widget):
|
||||
print("contenttype changed")
|
||||
if combobox.get_list_value(widget) == 'storage':
|
||||
self.label['edit_storage'].set_visible(True)
|
||||
self.combo['storage'].set_visible(True)
|
||||
self.label['edit_box'].set_visible(False)
|
||||
self.combo['box'].set_visible(False)
|
||||
else:
|
||||
self.label['edit_storage'].set_visible(False)
|
||||
self.combo['storage'].set_visible(False)
|
||||
self.label['edit_box'].set_visible(True)
|
||||
self.combo['box'].set_visible(True)
|
||||
|
||||
# buttons on detail page
|
||||
# edit2 uses edit callback
|
||||
def on_but_close_clicked(self, widget):
|
||||
|
||||
+21
-6
@@ -44,6 +44,21 @@ class MaintenanceView(View):
|
||||
self.entry['completion'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_completion = DatePicker(self.entry['completion'], self.button['completion'], context.get_datefmt())
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.maint.maintid,
|
||||
self.maint.activities,
|
||||
self.dd_equipment.get(self.maint.eid, ''),
|
||||
self.maint.remarks
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_maintenance.append(self.get_list_row())
|
||||
self.tree['maintenance'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['maintenance'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['maintenance'])
|
||||
self.lst_maintenance.clear()
|
||||
@@ -81,7 +96,7 @@ class MaintenanceView(View):
|
||||
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['plandate'].set_text(self.format_date(self.maint.plan_date, self.maint.plan_precision))
|
||||
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 '')
|
||||
@@ -118,6 +133,7 @@ class MaintenanceView(View):
|
||||
self.maint.plan_date = parse(self.entry['plandate'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.maint.plan_date = None
|
||||
self.maint.plan_precision = combobox.get_list_value(self.combo['plan_precision'])
|
||||
try:
|
||||
self.maint.completion_date = parse(self.entry['completion'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
@@ -180,10 +196,7 @@ class MaintenanceView(View):
|
||||
if not self.entry['activities'].get_text().strip():
|
||||
# TODO error marker
|
||||
return
|
||||
if not self.save_record():
|
||||
pass
|
||||
if not self.record_lock('maintenance', self.maint.maintid):
|
||||
return
|
||||
self.save_record()
|
||||
print(self.maint)
|
||||
if not self.maint.save():
|
||||
print("Save error")
|
||||
@@ -192,8 +205,10 @@ class MaintenanceView(View):
|
||||
return
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.add_row()
|
||||
self.newrecord = False
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['maint_detail'])
|
||||
|
||||
|
||||
+80
-3
@@ -55,6 +55,38 @@ class MeasurementView(View):
|
||||
self.entry['date'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
DatePicker(self.entry['date'], self.button['date'], context.get_datefmt())
|
||||
|
||||
self.context.subscribe("dd_mcat_modified", self.category_modified)
|
||||
self.context.subscribe("dd_unit_modified", self.unit_modified)
|
||||
self.context.subscribe("equipment_modified", self.equipment_modified)
|
||||
|
||||
def get_list_row(self):
|
||||
unit = self.dd_unit[self.measure.unit]
|
||||
if self.measure.nval == 1:
|
||||
value = "{} {}".format(self.measure.val1, unit)
|
||||
elif self.measure.nval == 2:
|
||||
value = "{}x{} {}".format(self.measure.val1, self.measure.val2, unit)
|
||||
elif self.measure.nval == 3:
|
||||
value = "{}x{}x{} {}".format(self.measure.val1, self.measure.val2, self.measure.val3, unit)
|
||||
else:
|
||||
#invalid
|
||||
value = "#invalid"
|
||||
|
||||
return (
|
||||
self.measure.mid,
|
||||
self.measure.mname,
|
||||
value,
|
||||
self.measure.accuracy,
|
||||
self.dd_equipment.get(self.measure.eid, ''),
|
||||
self.measure.note
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_measurement.append(self.get_list_row())
|
||||
self.tree['measurement'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['measurement'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['measurement'])
|
||||
self.lst_measurement.clear()
|
||||
@@ -91,6 +123,48 @@ class MeasurementView(View):
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def equipment_modified(self, eventtype, data):
|
||||
self.dd_equipment[data[0]] = data[1]
|
||||
lst = self.combo['equipment'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def category_modified(self, eventtype, data):
|
||||
self.dd_category[data[0]] = data[1]
|
||||
lst = self.combo['category'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def unit_modified(self, eventtype, data):
|
||||
self.dd_unit[data[0]] = data[1]
|
||||
lst = self.combo['unit'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def clear_record(self):
|
||||
self.measure.clear()
|
||||
self.entry['name'].set_text('')
|
||||
@@ -146,8 +220,8 @@ class MeasurementView(View):
|
||||
combobox.activate_row(self.combo['unit'], self.measure.unit or 1)
|
||||
combobox.activate_row(self.combo['accuracy'], self.measure.accuracy)
|
||||
self.entry['date'].set_text(self.format_date(self.measure.mdate))
|
||||
combobox.activate_row(self.combo['equipment'], self.measure.eid)
|
||||
combobox.activate_row(self.combo['category'], self.measure.mcat)
|
||||
combobox.activate_row(self.combo['equipment'], self.measure.eid or -1)
|
||||
combobox.activate_row(self.combo['category'], self.measure.mcat or -1)
|
||||
self.text['note'].get_buffer().set_text(self.measure.note or '')
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
@@ -253,8 +327,11 @@ class MeasurementView(View):
|
||||
pass
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
#self.load_list()
|
||||
self.add_row()
|
||||
self.newrecord = False
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['measure_detail'])
|
||||
|
||||
|
||||
+33
-5
@@ -5,7 +5,7 @@ from gi.repository import Gtk
|
||||
from dateutil.parser import parse
|
||||
from gettext import pgettext
|
||||
|
||||
from .view import View
|
||||
from .view import View, DatePicker
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.model import project
|
||||
|
||||
@@ -37,6 +37,26 @@ class ProjectsView(View):
|
||||
self.dd_state = self.context.lookup.enum('project.projstate')
|
||||
combobox.load_from_dict(self.combo['status'], self.dd_state)
|
||||
|
||||
self.entry['date_start'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
DatePicker(self.entry['date_start'], self.button['date_start'], context.get_datefmt())
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.project.projid,
|
||||
self.project.projname,
|
||||
self.format_date(self.project.startdate),
|
||||
self.project.duration,
|
||||
self.dd_state.get(self.project.projstate, ''),
|
||||
self.project.remarks
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_projects.append(self.get_list_row())
|
||||
self.tree['projects'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['projects'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['projects'])
|
||||
self.lst_projects.clear()
|
||||
@@ -87,7 +107,7 @@ class ProjectsView(View):
|
||||
self.entry['name'].set_text(self.project.projname)
|
||||
combobox.activate_row(self.combo['responsible'], self.project.responsible)
|
||||
self.entry['date_start'].set_text(self.format_date(self.project.startdate))
|
||||
if self.project.costs_plan:
|
||||
if self.project.duration:
|
||||
self.spin['duration'].set_value(self.project.duration)
|
||||
else:
|
||||
self.spin['duration'].set_text('')
|
||||
@@ -108,8 +128,13 @@ class ProjectsView(View):
|
||||
self.project.vid = self.context.vessel.vid
|
||||
self.project.projname = self.entry['name'].get_text()
|
||||
self.project.responsible = combobox.get_list_value(self.combo['responsible'])
|
||||
self.project.costs_plan = int(self.spin['costs_plan'].get_value())
|
||||
self.project.costs_final = int(self.spin['costs_final'].get_value())
|
||||
try:
|
||||
self.project.startdate = parse(self.entry['date_start'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.project.startdate = None
|
||||
self.project.duration = self.spin['duration'].get_value_as_int()
|
||||
self.project.costs_plan = self.spin['costs_plan'].get_value_as_int()
|
||||
self.project.costs_final = self.spin['costs_final'].get_value_as_int()
|
||||
self.project.projstate = combobox.get_list_value(self.combo['status'])
|
||||
self.project.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
@@ -177,8 +202,11 @@ class ProjectsView(View):
|
||||
return
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
#self.load_list()
|
||||
self.add_row()
|
||||
self.newrecord = False
|
||||
else:
|
||||
self.refresh_row()
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['proj_detail'])
|
||||
|
||||
|
||||
+108
-21
@@ -49,6 +49,29 @@ class ProvisionsView(View):
|
||||
self.entry['shelflife'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_shelflife = DatePicker(self.entry['shelflife'], self.button['shelflife'], context.get_datefmt())
|
||||
|
||||
# subscribe to data change events
|
||||
self.context.subscribe("storage_modified", self.storage_modified)
|
||||
self.context.subscribe("box_modified", self.box_modified)
|
||||
self.context.subscribe("dd_provcat_modified", self.category_modified)
|
||||
self.context.subscribe("dd_provunit_modified", self.unit_modified)
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.prov.provid,
|
||||
self.prov.provname,
|
||||
self.prov.number,
|
||||
self.dd_unit[self.prov.unit] if self.prov.unit is not None else _("─── none ───"),
|
||||
self.format_date(self.prov.storedate),
|
||||
self.format_date(self.prov.shelflife)
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_provisions.append(self.get_list_row())
|
||||
self.tree['provisions'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['provisions'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['provisions'])
|
||||
self.lst_provisions.clear()
|
||||
@@ -73,6 +96,59 @@ class ProvisionsView(View):
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def storage_modified(self, eventtype, data):
|
||||
self.dd_storage[data[0]] = data[1]
|
||||
lst = self.combo['storage'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def box_modified(self, eventtype, data):
|
||||
self.dd_box[data[0]] = data[1]
|
||||
lst = self.combo['box'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
else:
|
||||
lst.append(data)
|
||||
|
||||
def category_modified(self, eventtype, data):
|
||||
self.dd_category[data[0]] = data[1]
|
||||
lst = self.combo['category'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def unit_modified(self, eventtype, data):
|
||||
self.dd_unit[data[0]] = data[1]
|
||||
lst = self.combo['unit'].get_model()
|
||||
if eventtype == self.context.EVENT_UPD:
|
||||
for row in lst:
|
||||
if row[0] == data[0]:
|
||||
row[1] = data[1]
|
||||
return
|
||||
elif eventtype == self.context.EVENT_ADD:
|
||||
lst.append(data)
|
||||
else:
|
||||
# not implemented
|
||||
pass
|
||||
|
||||
def clear_record(self):
|
||||
self.prov.clear()
|
||||
self.entry['name'].set_text('')
|
||||
@@ -92,19 +168,19 @@ class ProvisionsView(View):
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
def display_record(self):
|
||||
self.label['name'].set_text(self.prov.provname)
|
||||
self.label['category'].set_text(str(self.prov.provcat))
|
||||
self.label['storage'].set_text(str(self.prov.sid))
|
||||
self.label['box'].set_text(str(self.prov.boxid))
|
||||
self.label['number'].set_text(str(self.prov.number))
|
||||
self.label['target'].set_text(str(self.prov.target))
|
||||
self.label['unit'].set_text(str(self.prov.unit))
|
||||
self.label['name'].set_text(self.prov.provname or '')
|
||||
self.label['category'].set_text(self.dd_category.get(self.prov.provcat, ''))
|
||||
self.label['storage'].set_text(self.dd_storage.get(self.prov.sid, ''))
|
||||
self.label['box'].set_text(self.dd_box.get(self.prov.boxid, ''))
|
||||
self.label['number'].set_text(self.format_int(self.prov.number))
|
||||
self.label['target'].set_text(self.format_int(self.prov.target))
|
||||
self.label['unit'].set_text(self.dd_unit.get(self.prov.unit, ''))
|
||||
self.label['weight'].set_text(self.format_float(self.prov.weight, 2, suffix='kg'))
|
||||
self.label['weight_net'].set_text(self.format_float(self.prov.weight_net, 2, suffix='kg'))
|
||||
self.label['price'].set_text(self.format_float(self.prov.price, 2, suffix='€'))
|
||||
self.label['calories'].set_text(str(self.prov.calories))
|
||||
self.label['storedate'].set_text(self.prov.storedate or '')
|
||||
self.label['shelflife'].set_text(self.prov.shelflife or '')
|
||||
self.label['calories'].set_text(self.format_int(self.prov.calories, suffix='kCal'))
|
||||
self.label['storedate'].set_text(self.format_date(self.prov.storedate))
|
||||
self.label['shelflife'].set_text(self.format_date(self.prov.shelflife))
|
||||
self.label['remarks'].set_text(self.prov.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
@@ -115,14 +191,24 @@ class ProvisionsView(View):
|
||||
self.spin['number'].set_value(self.prov.number or 1)
|
||||
self.spin['target'].set_value(self.prov.target or 0)
|
||||
combobox.activate_row(self.combo['unit'], self.prov.unit or -1)
|
||||
self.spin['weight'].set_value(self.prov.weight or 0)
|
||||
self.spin['weight_net'].set_value(self.prov.weight_net or 0)
|
||||
self.spin['price'].set_value(self.prov.price or 0)
|
||||
self.spin['calories'].set_value(self.prov.calories or 0)
|
||||
self.entry['storedate'].set_text(self.prov.storedate or '')
|
||||
self.entry['shelflife'].set_text(self.prov.shelflife or '')
|
||||
# self.dt_storedate.set_date
|
||||
# self.dt_shelflife.set_date
|
||||
if not self.prov.weight:
|
||||
self.spin['weight'].set_text('')
|
||||
else:
|
||||
self.spin['weight'].set_value(self.prov.weight)
|
||||
if not self.prov.weight_net:
|
||||
self.spin['weight'].set_text('')
|
||||
else:
|
||||
self.spin['weight_net'].set_value(self.prov.weight_net)
|
||||
if not self.prov.price:
|
||||
self.spin['price'].set_text('')
|
||||
else:
|
||||
self.spin['price'].set_value(self.prov.price)
|
||||
if not self.prov.calories:
|
||||
self.spin['calories'].set_text('')
|
||||
else:
|
||||
self.spin['calories'].set_value(self.prov.calories)
|
||||
self.entry['storedate'].set_text(self.format_date(self.prov.storedate))
|
||||
self.entry['shelflife'].set_text(self.format_date(self.prov.shelflife))
|
||||
self.text['remarks'].get_buffer().set_text(self.prov.remarks or '')
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
@@ -140,6 +226,7 @@ class ProvisionsView(View):
|
||||
self.prov.boxid = None
|
||||
self.prov.number = self.spin['number'].get_value_as_int()
|
||||
self.prov.target = self.spin['target'].get_value_as_int()
|
||||
self.prov.price = self.spin['price'].get_value()
|
||||
self.prov.weight = self.spin['weight'].get_value()
|
||||
self.prov.weight_net = self.spin['weight_net'].get_value()
|
||||
self.prov.unit = combobox.get_list_value(self.combo['unit'])
|
||||
@@ -236,10 +323,10 @@ class ProvisionsView(View):
|
||||
pass
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
#self.load_list()
|
||||
self.add_row()
|
||||
else:
|
||||
pass
|
||||
# TODO aktuelle Listenzeile aktualisieren!
|
||||
self.refresh_row()
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['prov_detail'])
|
||||
|
||||
+40
-29
@@ -25,8 +25,7 @@ class StatusView:
|
||||
|
||||
# Load table status info
|
||||
self.lst_tables = Gtk.ListStore(str, int)
|
||||
for row in self.get_table_counts():
|
||||
self.lst_tables.append(row)
|
||||
self.load_table_counts()
|
||||
treeview.add_column(self.tree['tables'], 'Table', 0)
|
||||
treeview.add_column(self.tree['tables'], '# Records', 1)
|
||||
self.tree['tables'].set_model(self.lst_tables)
|
||||
@@ -53,9 +52,9 @@ class StatusView:
|
||||
self.load_svg()
|
||||
|
||||
# subscribe to data change events
|
||||
self.context.subscribe("vessel_changed", self.vessel_changed)
|
||||
self.context.subscribe("vessel_modified", self.vessel_modified)
|
||||
|
||||
def vessel_changed(self, data):
|
||||
def vessel_modified(self, eventtype, data):
|
||||
print(f"Vessel changed. New ID={data[0]}")
|
||||
self.load_svg()
|
||||
|
||||
@@ -92,9 +91,9 @@ class StatusView:
|
||||
for element in root.iter():
|
||||
if element.get("id") == "centerline":
|
||||
found = True
|
||||
print("\n--- centerline gefunden ---")
|
||||
print("Tag:", element.tag)
|
||||
print("Attribute:", element.attrib)
|
||||
#print("\n--- centerline gefunden ---")
|
||||
#print("Tag:", element.tag)
|
||||
#print("Attribute:", element.attrib)
|
||||
y1 = element.get("y1")
|
||||
y2 = element.get("y2")
|
||||
if y1 is not None and y2 is not None:
|
||||
@@ -106,7 +105,7 @@ class StatusView:
|
||||
self.centerline_y = (y1 + y2) / 2
|
||||
else:
|
||||
self.centerline_y = y1
|
||||
print(f"centerline: SVG Y = {self.centerline_y}")
|
||||
#print(f"centerline: SVG Y = {self.centerline_y}")
|
||||
return
|
||||
if not found:
|
||||
print("No centerline with id='centerline' found!")
|
||||
@@ -119,31 +118,36 @@ class StatusView:
|
||||
cr.set_source_rgb(0.92, 0.97, 1.0)
|
||||
cr.paint()
|
||||
|
||||
allocation = area.get_allocation()
|
||||
scale_x = allocation.width / self.svg_width
|
||||
scale_y = allocation.height / self.svg_height
|
||||
self.svg_scale = min(scale_x, scale_y)
|
||||
if self.svg:
|
||||
allocation = area.get_allocation()
|
||||
scale_x = allocation.width / self.svg_width
|
||||
scale_y = allocation.height / self.svg_height
|
||||
self.svg_scale = min(scale_x, scale_y)
|
||||
|
||||
width = self.svg_width * self.svg_scale
|
||||
height = self.svg_height * self.svg_scale
|
||||
width = self.svg_width * self.svg_scale
|
||||
height = self.svg_height * self.svg_scale
|
||||
|
||||
self.svg_x = (allocation.width - width) / 2
|
||||
self.svg_y = (allocation.height - height) / 2
|
||||
self.svg_x = (allocation.width - width) / 2
|
||||
self.svg_y = (allocation.height - height) / 2
|
||||
|
||||
cr.save()
|
||||
cr.translate(self.svg_x, self.svg_y)
|
||||
cr.scale(self.svg_scale, self.svg_scale)
|
||||
viewport = Rsvg.Rectangle()
|
||||
viewport.x = 0
|
||||
viewport.y = 0
|
||||
viewport.width = self.svg_width
|
||||
viewport.height = self.svg_height
|
||||
self.svg.render_document(cr, viewport)
|
||||
cr.restore()
|
||||
cr.save()
|
||||
cr.translate(self.svg_x, self.svg_y)
|
||||
cr.scale(self.svg_scale, self.svg_scale)
|
||||
viewport = Rsvg.Rectangle()
|
||||
viewport.x = 0
|
||||
viewport.y = 0
|
||||
viewport.width = self.svg_width
|
||||
viewport.height = self.svg_height
|
||||
self.svg.render_document(cr, viewport)
|
||||
cr.restore()
|
||||
else:
|
||||
# TODO paint placeholder image
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
def get_table_counts(self):
|
||||
def load_table_counts(self):
|
||||
self.lst_tables.clear()
|
||||
# Detect all tables in database
|
||||
sql= ("SELECT table_name "
|
||||
"FROM information_schema.tables "
|
||||
@@ -156,5 +160,12 @@ class StatusView:
|
||||
for table in tables:
|
||||
sql = f"SELECT COUNT(*) FROM {table}"
|
||||
self.context.db.cur.execute(sql)
|
||||
records.append((table, self.context.db.cur.fetchone()[0]))
|
||||
return records
|
||||
self.lst_tables.append((table, self.context.db.cur.fetchone()[0]))
|
||||
|
||||
def on_but_tables_reload_clicked(self, widget):
|
||||
self.load_table_counts()
|
||||
|
||||
def on_ntb_status_switch_page(self, notebook, page, page_num):
|
||||
#if Gtk.Buildable.get_name(page) == 'scw_tables':
|
||||
# self.load_table_counts()
|
||||
pass
|
||||
+22
-15
@@ -31,17 +31,23 @@ class StorageView(View):
|
||||
self.dd_stype = self.context.lookup.dropdown(Dropdown.STORAGE_TYPE)
|
||||
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'], {"-1": _("─── none ───")} | self.dd_unit)
|
||||
self.dd_capaunit = self.context.lookup.enum('storage.capaunit')
|
||||
combobox.load_from_dict(self.combo['capaunit'], {"-1": _("─── none ───")} | self.dd_capaunit)
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.storage.sid,
|
||||
self.storage.sname,
|
||||
f"{self.storage.x}, {self.storage.y}, {self.storage.z}",
|
||||
self.storage.remarks
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
pass
|
||||
treeiter = self.lst_storage.append(self.get_list_row())
|
||||
self.tree['storage'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
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)
|
||||
treeview.set_row_values(self.tree['storage'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['storage'])
|
||||
@@ -73,7 +79,7 @@ class StorageView(View):
|
||||
self.spin['angle'].set_value(0)
|
||||
self.spin['capacity'].set_value(0)
|
||||
combobox.activate_row(self.combo['type'], storage.GENERIC)
|
||||
combobox.activate_row(self.combo['unit'], "-1")
|
||||
combobox.activate_row(self.combo['capaunit'], "-1")
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
self.entry['sname'].grab_focus()
|
||||
|
||||
@@ -83,7 +89,7 @@ class StorageView(View):
|
||||
self.label['position'].set_text(f"({self.storage.x}, {self.storage.y}, {self.storage.z})")
|
||||
self.label['dimension'].set_text(f"({self.storage.wx}, {self.storage.wy}, {self.storage.wz})")
|
||||
self.label['angle'].set_text(f"{self.storage.angle}°")
|
||||
self.label['capacity'].set_text(f"{self.storage.capacity} {self.storage.capaunit}")
|
||||
self.label['capacity'].set_text(f"{self.storage.capacity} {self.storage.capaunit or ''}")
|
||||
if self.storage.color:
|
||||
self.label['color'].set_markup(f'#{self.storage.color} <span foreground="#{self.storage.color}">●</span>')
|
||||
else:
|
||||
@@ -102,7 +108,7 @@ class StorageView(View):
|
||||
self.spin['angle'].set_value(self.storage.angle)
|
||||
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 or -1)
|
||||
combobox.activate_row(self.combo['capaunit'], 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'))
|
||||
@@ -122,7 +128,7 @@ class StorageView(View):
|
||||
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'])
|
||||
self.storage.capaunit = combobox.get_list_value(self.combo['capaunit'])
|
||||
if self.storage.capaunit == '-1':
|
||||
self.storage.capaunit = None
|
||||
self.storage.color = self.entry['color'].get_text().lstrip('#')
|
||||
@@ -191,12 +197,13 @@ class StorageView(View):
|
||||
pass
|
||||
self.record_unlock()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.context.publish("storage_added", (self.storage.pk_value, self.storage.sname))
|
||||
#self.load_list()
|
||||
self.add_row()
|
||||
self.context.publish("storage_modified", self.context.EVENT_ADD, (self.storage.pk_value, self.storage.sname))
|
||||
self.newrecord = False
|
||||
else:
|
||||
self.context.publish("storage_changed", (self.storage.pk_value, self.storage.sname))
|
||||
# TODO aktuelle Listenzeile aktualisieren!
|
||||
self.refresh_row()
|
||||
self.context.publish("storage_modified", self.context.EVENT_UPD, (self.storage.pk_value, self.storage.sname))
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['stor_detail'])
|
||||
|
||||
|
||||
+16
-1
@@ -49,6 +49,21 @@ class TasksView(View):
|
||||
self.entry['duedate'].set_placeholder_text(context.get_datefmt_placeholder())
|
||||
self.dt_duedate = DatePicker(self.entry['duedate'], self.button['duedate'], context.get_datefmt())
|
||||
|
||||
def get_list_row(self):
|
||||
return (
|
||||
self.task.taskid,
|
||||
self.task.taskname,
|
||||
self.task.priority,
|
||||
self.task.responsible
|
||||
)
|
||||
|
||||
def add_row(self):
|
||||
treeiter = self.lst_tasks.append(self.get_list_row())
|
||||
self.tree['tasks'].get_selection().select_iter(treeiter)
|
||||
|
||||
def refresh_row(self):
|
||||
treeview.set_row_values(self.tree['tasks'], self.get_list_row())
|
||||
|
||||
def load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['tasks'])
|
||||
self.lst_tasks.clear()
|
||||
@@ -126,7 +141,7 @@ class TasksView(View):
|
||||
except ValueError:
|
||||
self.task.plandate = None
|
||||
try:
|
||||
self.task.duedate = parse(self.entry['plandate'].get_text(), dayfirst=True)
|
||||
self.task.duedate = parse(self.entry['duedate'].get_text(), dayfirst=True)
|
||||
except ValueError:
|
||||
self.task.duedate = None
|
||||
try:
|
||||
|
||||
+31
-13
@@ -89,10 +89,19 @@ class View:
|
||||
formatted += f"\u00A0{suffix}"
|
||||
return formatted
|
||||
|
||||
def format_date(self, dval, default=''):
|
||||
def format_date(self, dval, default='', precision='day'):
|
||||
if dval is None:
|
||||
return default
|
||||
return dval.strftime(self.context.get_datefmt())
|
||||
if precision == 'day':
|
||||
return dval.strftime(self.context.get_datefmt())
|
||||
elif precision == 'week':
|
||||
return "{}/{}".format(dval.isocalendar().week, dval.year)
|
||||
elif precision == 'month':
|
||||
return "{}/{}".format(dval.month, dval.year)
|
||||
elif precision == 'quarter':
|
||||
quarter = (dval.month - 1) // 3 + 1
|
||||
return "{}/{}".format(dval.month, dval.year)
|
||||
raise ValueError(f"invalid date precision given: {precision}")
|
||||
|
||||
def format_datetime(self, dtval, default=''):
|
||||
# we do not use seconds!
|
||||
@@ -111,7 +120,9 @@ class View:
|
||||
return f"#{r:02X}{g:02X}{b:02X}"
|
||||
|
||||
def on_textview_keypress(self, widget, event):
|
||||
# Generic limit length function
|
||||
"""
|
||||
Generic limit length function
|
||||
"""
|
||||
if event.state & Gdk.ModifierType.CONTROL_MASK:
|
||||
allowed_ctrl_keys = (
|
||||
Gdk.KEY_a,
|
||||
@@ -132,7 +143,6 @@ class View:
|
||||
Gdk.KEY_Page_Up,
|
||||
Gdk.KEY_Page_Down,
|
||||
)
|
||||
print("keypress")
|
||||
if event.keyval in allowed_keys:
|
||||
return False
|
||||
buf = widget.get_buffer()
|
||||
@@ -144,8 +154,9 @@ class View:
|
||||
return False
|
||||
|
||||
def on_textview_paste(self, widget):
|
||||
# Generic limit length function
|
||||
print("paste")
|
||||
"""
|
||||
Generic limit length function
|
||||
"""
|
||||
buf = widget.get_buffer()
|
||||
start = buf.get_start_iter()
|
||||
end = buf.get_end_iter()
|
||||
@@ -192,14 +203,17 @@ class View:
|
||||
else:
|
||||
self.set_entry_valid(entry, False)
|
||||
|
||||
def get_checks(self, checkboxlist):
|
||||
# checkbox helper function
|
||||
# self.check[] from ui file
|
||||
def get_checks(self, checkboxlist, prefix=None):
|
||||
"""
|
||||
checkbox helper function
|
||||
self.check[] from ui file
|
||||
optional remove prefix to convert from control name to database value
|
||||
"""
|
||||
checks = []
|
||||
for c in checkboxlist:
|
||||
if c in self.check and self.check[c].get_active():
|
||||
checks.append(c)
|
||||
return ','.join(checks)
|
||||
checks.append(c.removeprefix(prefix) if prefix else c)
|
||||
return ','.join(checks) or None
|
||||
|
||||
class DatePicker:
|
||||
def __init__(self, entry, button, datefmt='"%d.%m.%Y"'):
|
||||
@@ -232,14 +246,18 @@ class DatePicker:
|
||||
self.popover.hide()
|
||||
|
||||
def get_date(self):
|
||||
"""Liefert datetime.date oder None bei ungültiger Eingabe."""
|
||||
"""
|
||||
Returns datetime.date or None if the input is invalid.
|
||||
"""
|
||||
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."""
|
||||
"""
|
||||
Sets the date using a datetime.date object.
|
||||
"""
|
||||
if isinstance(value, date):
|
||||
self.entry.set_text(value.strftime(self.datefmt))
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ from yms.view.status import StatusView
|
||||
|
||||
__author__ = "Thomas Hooge"
|
||||
__copyright__ = "Copyright 2024-2026"
|
||||
__version__ = "0.2.2"
|
||||
__version__ = "0.3"
|
||||
__email__ = "thomas@hoogi.de"
|
||||
__status__ = "Development"
|
||||
|
||||
@@ -75,6 +75,7 @@ class AppContext:
|
||||
}
|
||||
|
||||
# mapping between PHP and Python
|
||||
# TODO week, month and quarter formats
|
||||
datefmt_map = {
|
||||
'Y-m-d': ('%Y-%m-%d', 'YYYY-MM-DD'), # ISO / international / technical
|
||||
'd.m.Y': ('%d.%m.%Y', 'DD.MM.YYYY'), # Germany / Central & Northern Europe
|
||||
@@ -86,6 +87,12 @@ class AppContext:
|
||||
'Y/m/d': ('%Y/%m/%d', 'YYYY/MM/DD') # Japan / China
|
||||
}
|
||||
|
||||
# Publish / Subscribe event variants
|
||||
EVENT_GENERIC = 0
|
||||
EVENT_ADD = 1
|
||||
EVENT_DEL = 2
|
||||
EVENT_UPD = 3
|
||||
|
||||
def __init__(self):
|
||||
self.__version__ = __version__
|
||||
self.db = None
|
||||
@@ -114,25 +121,19 @@ class AppContext:
|
||||
sql = "SELECT valstr FROM settings WHERE userid=0 AND sno=2"
|
||||
self.db.cur.execute(sql)
|
||||
row = self.db.cur.fetchone()
|
||||
if row is not None:
|
||||
try:
|
||||
self.datefmt = self.datefmt_map[row[0]]
|
||||
print(row[0])
|
||||
except KeyError:
|
||||
# almost impossible case where db value is not in mapping
|
||||
print("internal error: date format mapping missing ({})".format(row[0]))
|
||||
if row and row[0]:
|
||||
self.datefmt = row[0]
|
||||
else:
|
||||
# perhaps create missing record here?
|
||||
pass
|
||||
print("No dateformat setting found")
|
||||
self.lookup.load()
|
||||
self.init_scanner()
|
||||
|
||||
def subscribe(self, event, callback):
|
||||
self.callbacks.setdefault(event, []).append(callback)
|
||||
|
||||
def publish(self, event, data=None):
|
||||
def publish(self, event, eventtype, data=None):
|
||||
for callback in self.callbacks.get(event, []):
|
||||
callback(data)
|
||||
callback(eventtype, data)
|
||||
|
||||
def init_scanner(self):
|
||||
self.scan_enabled = False
|
||||
@@ -168,6 +169,8 @@ class AppContext:
|
||||
return ""
|
||||
|
||||
def get_datefmt(self):
|
||||
# TODO take precision into account
|
||||
# day, week, month, quarter
|
||||
return self.datefmt_map[self.datefmt][0]
|
||||
|
||||
def get_datefmt_placeholder(self):
|
||||
@@ -262,7 +265,8 @@ class Frontend:
|
||||
Table.TAGS: "tags"
|
||||
}
|
||||
# execute method from module
|
||||
self.modules[modulemap[row[0]]].load_list()
|
||||
if row[0] in modulemap:
|
||||
self.modules[modulemap[row[0]]].load_list()
|
||||
|
||||
self.db_poll_ts = self.db.get_timestamp()
|
||||
return True
|
||||
|
||||
Reference in new issue
Block a user