129 lines
4.6 KiB
Python
129 lines
4.6 KiB
Python
# SPDX-License-Identifier: WTFPL
|
|
|
|
import os
|
|
from gi.repository import GLib, Gtk, Gdk
|
|
|
|
from .view import View
|
|
from yms import gtkutils, combobox, treeview
|
|
from yms.lookup import Dropdown
|
|
from yms.model import box
|
|
|
|
class BoxesView(View):
|
|
|
|
def __init__(self, context):
|
|
super().__init__(context, _("Boxes"), "boxes.ui")
|
|
self.context = context
|
|
|
|
# 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)
|
|
|
|
self.dd_boxtype = self.context.lookup.dropdown(Dropdown.BOX_TYPE)
|
|
combobox.load_from_dict(self.combo['type'], self.dd_boxtype)
|
|
|
|
def load_list(self):
|
|
pass
|
|
|
|
def clear_record(self):
|
|
self.entry['label'].set_text('')
|
|
self.entry['content'].set_text('')
|
|
self.spin['wx'].set_value(0)
|
|
self.spin['wy'].set_value(0)
|
|
self.spin['wz'].set_value(0)
|
|
self.text['remarks'].get_buffer().set_text('')
|
|
|
|
def display_record(self):
|
|
self.label['label'].set_text(self.sbox.label)
|
|
# storage sid
|
|
self.label['content'].set_text(self.sbox.content or '')
|
|
self.label['type'].set_text(self.dd_boxtype[self.sbox.boxtype])
|
|
self.label['color'].set_text(self.sbox.color or '')
|
|
if self.sbox.color:
|
|
self.label['color'].set_markup(f'#{self.sbox.color} <span foreground="#{self.sbox.color}">●</span>')
|
|
else:
|
|
self.label['color'].set_text('')
|
|
self.label['weight'].set_text(self.format_float(self.sbox.weight, 2, suffix='kg'))
|
|
self.label['weight_net'].set_text(self.format_float(self.sbox.weight_net, 2, suffix='kg'))
|
|
self.label['price'].set_text(self.format_float(self.sbox.price, 2, suffix='€'))
|
|
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):
|
|
boxid = treeview.get_value(self.tree['box'], 0)
|
|
if not boxid:
|
|
return
|
|
self.sbox.load(boxid)
|
|
self.display_record()
|
|
self.topwidget.set_visible_child(self.box['box_detail'])
|
|
self.button['close'].grab_focus()
|
|
|
|
def on_tvw_box_row_activated(self, widget, path, column):
|
|
boxid = treeview.get_value(widget, 0)
|
|
self.sbox.load(boxid)
|
|
self.display_record()
|
|
self.topwidget.set_visible_child(self.box['box_detail'])
|
|
self.button['close'].grab_focus()
|
|
|
|
# buttons on detail page
|
|
# edit2 uses edit callback
|
|
def on_but_close_clicked(self, widget):
|
|
boxid = treeview.get_value(self.tree['box'], 0)
|
|
if not boxid:
|
|
return
|
|
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
|
|
|