Fixes for webgui and more native gui development
This commit is contained in:
+32
-3
@@ -14,6 +14,7 @@ from gi.repository import GLib, Gtk, Gdk, Rsvg
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.lookup import Dropdown
|
||||
|
||||
class BaseView(View):
|
||||
|
||||
@@ -63,7 +64,15 @@ class BaseView(View):
|
||||
self.db.cur.execute("INSERT INTO settings (userid, sno, valint) VALUES (0, 1, 0)")
|
||||
self.db.conn.commit()
|
||||
else:
|
||||
self.context.vessel.vid = row[0]
|
||||
# check if vessel from settings exist
|
||||
self.db.cur.execute("SELECT count(*) FROM vessel WHERE vid=%s", (row[0],))
|
||||
res = self.db.cur.fetchone()[0]
|
||||
if res > 0:
|
||||
self.context.vessel.vid = row[0]
|
||||
else:
|
||||
# TODO set vessel to first in list
|
||||
self.context.vessel.vid = 0
|
||||
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"
|
||||
@@ -75,7 +84,7 @@ class BaseView(View):
|
||||
vessellist = {}
|
||||
self.db.dcur.execute("SELECT vid, vesselname, model FROM vessel ORDER BY vid")
|
||||
for row in self.db.dcur.fetchall():
|
||||
vessellist[row['vid']] = (
|
||||
vessellist[row['vid']] = (
|
||||
row['vesselname'] if row['model'] is None
|
||||
else row['vesselname'] + " - " + row['model']
|
||||
)
|
||||
@@ -154,6 +163,15 @@ class BaseView(View):
|
||||
if answer == False:
|
||||
return
|
||||
self.context.vessel.create()
|
||||
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)
|
||||
self.edit_vessel(self.context.vessel)
|
||||
self.stack['vessel'].set_visible_child(self.box['vessel_edit'])
|
||||
|
||||
def on_but_vessel_edit_clicked(self, widget):
|
||||
self.edit_vessel(self.context.vessel)
|
||||
self.stack['vessel'].set_visible_child(self.box['vessel_edit'])
|
||||
|
||||
def on_but_vessel_save_clicked(self, widget):
|
||||
print("Save vessel")
|
||||
@@ -172,6 +190,13 @@ class BaseView(View):
|
||||
txtbuf = self.text['vessel_remarks'].get_buffer()
|
||||
vessel.remarks = txtbuf.get_text(txtbuf.get_start_iter(), txtbuf.get_end_iter(), True)
|
||||
vessel.save()
|
||||
self.stack['vessel'].set_visible_child(self.box['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
|
||||
|
||||
def on_but_comp_new_clicked(self, widget):
|
||||
print("New company")
|
||||
@@ -189,7 +214,11 @@ class BaseView(View):
|
||||
pass
|
||||
|
||||
def display_vessel(self, vessel):
|
||||
print("Display vessel")
|
||||
self.label['vesselname'].set_text(vessel.vesselname)
|
||||
self.label['model'].set_text(vessel.model or '')
|
||||
self.label['year_built'].set_text(self.format_int(vessel.year_built, default='n/a'))
|
||||
|
||||
def edit_vessel(self, vessel):
|
||||
self.entry['vesselname'].set_text(vessel.vesselname)
|
||||
self.entry['model'].set_text(vessel.model or '')
|
||||
self.spin['year_built'].set_value(vessel.year_built or 0)
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
# SPDX-License-Identifier: WTFPL
|
||||
|
||||
import os
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import GLib, Gtk, Gdk
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.model import box
|
||||
|
||||
class BoxesView(View):
|
||||
|
||||
def __init__(self, context):
|
||||
super().__init__(context, _("Box"), "boxes.ui")
|
||||
|
||||
# box already used for controls so other name here
|
||||
self.sbox = box.Box(context.db) # current record
|
||||
self.newrecord = False
|
||||
|
||||
self.lst_box = Gtk.ListStore(int, str, str, str)
|
||||
sql = (
|
||||
"SELECT b.boxid, b.label, b.content, b.remarks "
|
||||
"FROM box AS b JOIN storage AS s USING (sid) "
|
||||
"WHERE s.vid=%s "
|
||||
"ORDER BY b.label"
|
||||
)
|
||||
self.db.cur.execute(sql, (context.vessel.vid,))
|
||||
for row in self.db.cur.fetchall():
|
||||
self.lst_box.append(row)
|
||||
|
||||
treeview.add_column(self.tree['box'], _('ID'), 0)
|
||||
treeview.add_column(self.tree['box'], _('Label'), 1)
|
||||
treeview.add_column(self.tree['box'], _('Content'), 2)
|
||||
treeview.add_column(self.tree['box'], _('Remarks'), 3)
|
||||
self.tree['box'].set_model(self.lst_box)
|
||||
|
||||
|
||||
def load_list(self):
|
||||
pass
|
||||
|
||||
def display_record(self):
|
||||
self.label['label'].set_text(self.sbox.label)
|
||||
self.label['remarks'].set_text(self.sbox.remarks or '')
|
||||
|
||||
def edit_record(self):
|
||||
self.entry['label'].set_text(self.sbox.label)
|
||||
self.entry['content'].set_text(self.sbox.content or '')
|
||||
self.spin['wx'].set_value(self.sbox.wx or 0)
|
||||
self.spin['wy'].set_value(self.sbox.wy or 0)
|
||||
self.spin['wz'].set_value(self.sbox.wz or 0)
|
||||
self.text['remarks'].get_buffer().set_text(self.sbox.remarks or '')
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text("Add new Box")
|
||||
self.topwidget.set_visible_child(self.box['box_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text("Edit Box")
|
||||
sid = treeview.get_value(self.tree['box'], 0)
|
||||
self.sbox.load(sid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['box_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
sid = treeview.get_value(self.tree['box'], 0)
|
||||
self.sbox.load(sid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['box_detail'])
|
||||
|
||||
# buttons on detail page
|
||||
# edit2 uses edit callback
|
||||
def on_but_close_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['box'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['box'])
|
||||
self.newrecord = False
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
print("save not implemented yet")
|
||||
self.newrecord = False
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['box'])
|
||||
self.newrecord = False
|
||||
|
||||
def on_but_color_clicked(self, widget):
|
||||
pass
|
||||
|
||||
@@ -62,3 +62,9 @@ class CablesView(View):
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['cables'])
|
||||
|
||||
def display_record(self):
|
||||
pass
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
|
||||
@@ -59,3 +59,9 @@ class DocumentsView(View):
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['documents'])
|
||||
|
||||
def display_record(self):
|
||||
pass
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
|
||||
@@ -64,3 +64,9 @@ class FusesView(View):
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['fuses'])
|
||||
|
||||
def display_record(self):
|
||||
pass
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
|
||||
@@ -58,3 +58,9 @@ class MaintenanceView(View):
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['maintenance'])
|
||||
|
||||
def display_record(self):
|
||||
pass
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
|
||||
@@ -68,3 +68,9 @@ class ProjectsView(View):
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['projects'])
|
||||
|
||||
def display_record(self):
|
||||
pass
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ class StatusView:
|
||||
gtkutils.init_named_controls(self, builder)
|
||||
|
||||
# Generic information
|
||||
self.label['dbinfo'].set_text("Database: {}".format(context.cfg['db']))
|
||||
self.label['dbinfo'].set_text("Database: {} on {}".format(context.cfg['db'], context.cfg['host']))
|
||||
|
||||
# Load table status info
|
||||
self.lst_tables = Gtk.ListStore(str, int)
|
||||
|
||||
+17
-2
@@ -8,6 +8,7 @@ from gi.repository import GLib, Gtk, Gdk
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
from yms.model import storage
|
||||
from yms.lookup import Dropdown
|
||||
|
||||
class StorageView(View):
|
||||
|
||||
@@ -34,6 +35,14 @@ class StorageView(View):
|
||||
treeview.add_column(self.tree['storage'], _('Remarks'), 3)
|
||||
self.tree['storage'].set_model(self.lst_storage)
|
||||
|
||||
combodict = self.context.lookup.dropdown(Dropdown.STORAGE_TYPE)
|
||||
combobox.load_from_dict(self.combo['type'], combodict)
|
||||
|
||||
combodict = self.context.lookup.dropdown(Dropdown.STORAGE_TYPE)
|
||||
combobox.load_from_dict(self.combo['type'], combodict)
|
||||
|
||||
combodict = self.context.lookup.enum('storage.capaunit')
|
||||
combobox.load_from_dict(self.combo['unit'], combodict)
|
||||
|
||||
def load_list(self):
|
||||
pass
|
||||
@@ -56,9 +65,11 @@ class StorageView(View):
|
||||
self.topwidget.set_visible_child(self.box['stor_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
sid = treeview.get_value(self.tree['storage'], 0)
|
||||
if sid is None:
|
||||
return
|
||||
self.newrecord = False
|
||||
self.label['title_edit'].set_text("Edit Storage")
|
||||
sid = treeview.get_value(self.tree['storage'], 0)
|
||||
self.storage.load(sid)
|
||||
self.edit_record()
|
||||
self.topwidget.set_visible_child(self.box['stor_edit'])
|
||||
@@ -80,8 +91,12 @@ class StorageView(View):
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
print("save not implemented yet")
|
||||
self.newrecord = False
|
||||
# check mandatory fields
|
||||
sname = self.entry['sname'].get_text().strip()
|
||||
if not sname:
|
||||
return
|
||||
# here be dragons
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['storage'])
|
||||
|
||||
+6
-6
@@ -27,25 +27,25 @@ class View:
|
||||
self.topwidget = builder.get_object("topobject")
|
||||
gtkutils.init_named_controls(self, builder)
|
||||
|
||||
def format_int(self, ival, separator=True, suffix=None):
|
||||
def format_int(self, ival, separator=True, suffix=None, default=''):
|
||||
if ival is None:
|
||||
return ''
|
||||
return default
|
||||
formatted = locale.format_string("%d", ival, separator)
|
||||
if suffix:
|
||||
formatted += f"\u00A0{suffix}"
|
||||
return formatted
|
||||
|
||||
def format_float(self, fval, digits=2, grouping=True, suffix=None):
|
||||
def format_float(self, fval, digits=2, grouping=True, suffix=None, default=''):
|
||||
if fval is None:
|
||||
return ''
|
||||
return default
|
||||
formatted = locale.format_string(f"%.{digits}f", fval, grouping)
|
||||
if suffix:
|
||||
formatted += f"\u00A0{suffix}"
|
||||
return formatted
|
||||
|
||||
def format_date(self, dval):
|
||||
def format_date(self, dval, default=''):
|
||||
if dval is None:
|
||||
return ''
|
||||
return default
|
||||
return dval.strftime(self.context.datefmt)
|
||||
|
||||
def on_textview_keypress(self, widget, event):
|
||||
|
||||
Reference in New Issue
Block a user