From 4b5ba85a77003c748fec09f596efb9da05106079 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Tue, 9 Apr 2024 14:03:13 +0100 Subject: [PATCH] Native gui some more code --- yms/gtkutils.py | 32 +++++++++ yms/ui/main.ui | 180 ++++++++++++++++++++++++++++++++++++++++++++++++ ymsgui.py | 39 +++++++++-- 3 files changed, 247 insertions(+), 4 deletions(-) create mode 100644 yms/gtkutils.py create mode 100644 yms/ui/main.ui diff --git a/yms/gtkutils.py b/yms/gtkutils.py new file mode 100644 index 0000000..120e2a3 --- /dev/null +++ b/yms/gtkutils.py @@ -0,0 +1,32 @@ +from gi.repository import Gtk + +def init_named_controls(window, builder): + ctrltype = { + 'lbl': 'label', + 'ent': 'entry', + 'but': 'button', + 'cmb': 'combo', + 'tvw': 'tree', + 'spi': 'spin', + 'txt': 'text', + 'chk': 'check', + 'opt': 'radio', + 'vbx': 'vbox', + 'hbx': 'hbox', + 'box': 'box', + 'tbl': 'table', + 'mnu': 'menu', + 'img': 'image', + 'drw': 'area' + } + for ctrl in ctrltype.values(): + setattr(window, ctrl, {}) + for widget in builder.get_objects(): + if type(widget) in (Gtk.Adjustment, Gtk.CellRendererText, Gtk.TreeSelection): + continue + widgetname = Gtk.Buildable.get_name(widget) + nameparts = widgetname.partition('_') + if (not nameparts[0] in ctrltype.keys()) or (not nameparts[2]): + continue + var = getattr(window, ctrltype[nameparts[0]]) + var[nameparts[2]] = widget diff --git a/yms/ui/main.ui b/yms/ui/main.ui new file mode 100644 index 0000000..c99ecab --- /dev/null +++ b/yms/ui/main.ui @@ -0,0 +1,180 @@ + + + + + + False + YMS + + + + True + False + + + True + False + vertical + True + start + + + Vessel + True + True + True + + + True + True + 0 + + + + + Companies + True + True + True + + + True + True + 1 + + + + + Equipment + True + True + True + + + True + True + 2 + + + + + Inventory + True + True + True + + + True + True + 3 + + + + + Provisions + True + True + True + + + True + True + 4 + + + + + Projects + True + True + True + + + True + True + 5 + + + + + Documents + True + True + True + + + True + True + 6 + + + + + False + True + 0 + + + + + True + False + vertical + + + True + False + empty + + + False + True + 0 + + + + + True + True + in + + + True + True + + + + + + + + False + True + 1 + + + + + Ok + True + True + True + + + + False + True + 2 + + + + + False + True + 1 + + + + + + diff --git a/ymsgui.py b/ymsgui.py index b0c2eeb..7bd5b7c 100755 --- a/ymsgui.py +++ b/ymsgui.py @@ -21,6 +21,7 @@ gi.require_version("Gtk", "3.0") from gi.repository import GLib, Gtk from yms import database +from yms import gtkutils cfg = { 'cfgfile': '~/.config/ymsgui.conf', @@ -29,16 +30,46 @@ cfg = { 'user': 'yms' } -class Frontend(Gtk.Window): +class Frontend(): def __init__(self): - super().__init__() - self.connect("destroy", self.on_destroy) + builder = Gtk.Builder() + builder.add_from_file("yms/ui/main.ui") + builder.connect_signals(self) + self.window = builder.get_object("wnd_main") + gtkutils.init_named_controls(self, builder) + + # get current vessel id + db.cur.execute("SELECT valint FROM settings WHERE userid=0 AND sno=1") + row = db.cur.fetchone() + if not row: + self.vid = 0 + self.vname = "Ghost" + db.cur.execute("INSERT INTO settings (userid, sno, valint) VALUES (0, 1, 0)") + db.conn.commit() + else: + self.vid = row[0] + # get vessel infos + if self.vid > 0: + db.cur.execute("SELECT vesselname, model FROM vessel WHERE vid=%s", (self.vid, )) + self.vessel = db.cur.fetchone() + print(self.vessel['sesselname']) + else: + self.vname = "Ghost(0)" def run(self): - self.show_all() + self.label['vessel'].set_text(self.vname) + self.window.show_all() Gtk.main() + def on_but_info_clicked(self, widget): + + # Userlist + sql = ("SELECT userid, login FROM user ORDER BY login") + db.cur.execute(sql) + for row in db.cur.fetchall(): + print(row) + def on_destroy(self, widget, data=None): Gtk.main_quit()