93 lines
3.0 KiB
Python
93 lines
3.0 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.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
|
|
|