More work on native gui. Make data editable.
This commit is contained in:
1 parent
5641e1706f
commit
7aa5d2af3b
43 files changed
+2686
-1037
No files matched your search
+25
-13
@@ -1,10 +1,9 @@
|
||||
# SPDX-License-Identifier: WTFPL
|
||||
|
||||
|
||||
|
||||
import os
|
||||
from gi.repository import GLib, Gtk, Gdk
|
||||
from dateutil.parser import parse
|
||||
from gettext import pgettext
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
@@ -53,7 +52,7 @@ class InventoryView(View):
|
||||
combobox.load_from_dict(self.combo['equipment'], {-1: _("─── none ───")} | self.dd_equipment)
|
||||
# Condition
|
||||
self.dd_condition = self.context.lookup.enum('inventory.invcond')
|
||||
combobox.load_from_dict(self.combo['condition'], {"-1": _("─── none ───")} | self.dd_condition)
|
||||
combobox.load_from_dict(self.combo['condition'], self.dd_condition)
|
||||
|
||||
def load_list(self):
|
||||
self.lst_inventory.clear()
|
||||
@@ -90,19 +89,22 @@ class InventoryView(View):
|
||||
combobox.activate_row(self.combo['condition'], 'unknown')
|
||||
combobox.activate_row(self.combo['category'], -1)
|
||||
self.text['remarks'].get_buffer().set_text('')
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
def display_record(self):
|
||||
# TODO nice formatting
|
||||
self.label['name'].set_text(self.inv.invname)
|
||||
self.label['conttype'].set_text(self.inv.conttype)
|
||||
self.label['storage'].set_text(str(self.inv.sid))
|
||||
self.label['box'].set_text(str(self.inv.boxid))
|
||||
container = pgettext("inventory.conttype", self.inv.conttype)
|
||||
if self.inv.conttype == 'storage':
|
||||
self.label['conttype'].set_text("{}: {}".format(container, self.dd_storage[self.inv.sid]))
|
||||
else:
|
||||
self.label['conttype'].set_text("{}: {}".format(container, self.dd_box[self.inv.boxid]))
|
||||
self.label['equipment'].set_text(str(self.inv.eid))
|
||||
self.label['number'].set_text(self.format_int(self.inv.number))
|
||||
self.label['weight'].set_text(self.format_float(self.inv.weight, suffix='kg'))
|
||||
self.label['price'].set_text(self.format_float(self.inv.price, suffix='€'))
|
||||
self.label['purchdate'].set_text(self.format_date(self.inv.purchdate))
|
||||
self.label['condition'].set_text(self.inv.invcond)
|
||||
self.label['condition'].set_text(pgettext("inventory.invcond", self.inv.invcond))
|
||||
if self.inv.icat is not None:
|
||||
self.label['category'].set_text(self.dd_category[self.inv.icat])
|
||||
else:
|
||||
@@ -113,19 +115,20 @@ class InventoryView(View):
|
||||
def edit_record(self):
|
||||
self.entry['name'].set_text(self.inv.invname)
|
||||
combobox.activate_row(self.combo['conttype'], self.inv.conttype)
|
||||
combobox.activate_row(self.combo['storage'], self.inv.sid)
|
||||
combobox.activate_row(self.combo['box'], self.inv.boxid)
|
||||
combobox.activate_row(self.combo['equipment'], self.inv.eid)
|
||||
combobox.activate_row(self.combo['storage'], self.inv.sid or -1)
|
||||
combobox.activate_row(self.combo['box'], self.inv.boxid or -1)
|
||||
combobox.activate_row(self.combo['equipment'], self.inv.eid or -1)
|
||||
self.spin['number'].set_value(self.inv.number)
|
||||
self.spin['weight'].set_value(self.inv.weight or 0)
|
||||
self.spin['price'].set_value(self.inv.price or 0)
|
||||
self.entry['purchdate'].set_text(self.inv.purchdate or '')
|
||||
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)
|
||||
combobox.activate_row(self.combo['category'], self.inv.icat or -1)
|
||||
flags = self.inv.flags.split(',')
|
||||
for flag in self.context.lookup.enum('inventory.flags'):
|
||||
self.check[flag].set_active(flag in flags)
|
||||
self.text['remarks'].get_buffer().set_text(self.inv.remarks or '')
|
||||
self.entry['name'].grab_focus()
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
@@ -150,6 +153,8 @@ class InventoryView(View):
|
||||
self.inv.purchdate = None
|
||||
self.inv.invcond = combobox.get_list_value(self.combo['condition'])
|
||||
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 = []
|
||||
@@ -251,7 +256,14 @@ class InventoryView(View):
|
||||
self.save_record()
|
||||
print(self.inv)
|
||||
self.inv.save()
|
||||
self.context.db.conn.commit()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
else:
|
||||
pass
|
||||
# TODO aktuelle Listenzeile aktualisieren!
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['inv_detail'])
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
if not self.newrecord:
|
||||
|
||||
Reference in new issue
Block a user