# SPDX-License-Identifier: WTFPL import os from gi.repository import Gtk from .view import View from yms import gtkutils, combobox, treeview from yms.lookup import Dropdown from yms.model import company class CompaniesView(View): def __init__(self, context): super().__init__(context, _("Companies"), "companies.ui") self.context = context self.comp = company.Company(context.db) # current record self.newrecord = False # company types self.db.cur.execute("SELECT ddval, ddtext FROM dropdown WHERE ddid=2 ORDER BY ddval") self.comptype = dict(self.db.cur.fetchall()) combobox.load_from_dict(self.combo['flt_type'], {-2: _("─── all ───")} | self.comptype, -2) self.dd_comptype = self.context.lookup.dropdown(Dropdown.COMPANY_TYPE) combobox.load_from_dict(self.combo['comptype'], self.dd_comptype) combobox.load_from_dict(self.combo['comptype2'], self.dd_comptype) self.dd_flags = context.lookup.enum('company.flags') # companies self.lst_companies = Gtk.ListStore(int, str, str, str) self.db.cur.execute("SELECT compid, compname, comptype, remarks FROM company ORDER BY compname") for row in self.db.cur.fetchall(): self.lst_companies.append((row[0], row[1], self.comptype[row[2]], row[3])) treeview.add_column(self.tree['companies'], _('ID'), 0) treeview.add_column(self.tree['companies'], _('Name'), 1) treeview.add_column(self.tree['companies'], _('Type'), 2) treeview.add_column(self.tree['companies'], _('Remarks'), 3) self.tree['companies'].set_model(self.lst_companies) def clear_record(self): self.entry['name'].set_text('') self.entry['shortname'].set_text('') self.entry['street'].set_text('') self.entry['zip'].set_text('') self.entry['city'].set_text('') self.entry['country'].set_text('') self.entry['contact'].set_text('') self.entry['phone'].set_text('') self.entry['email'].set_text('') self.entry['web'].set_text('') self.entry['customerno'].set_text('') self.entry['contractno'].set_text('') combobox.activate_row(self.combo['comptype'], -1) combobox.activate_row(self.combo['comptype2'], -1) def display_record(self): self.label['name'].set_text(self.comp.compname) self.label['shortname'].set_text(self.comp.shortname or '') self.label['type'].set_text(self.dd_comptype.get(self.comp.comptype, '')) self.label['type2'].set_text(self.dd_comptype.get(self.comp.comptype2, '')) self.label['street'].set_text(self.comp.street or '') self.label['zip'].set_text(self.comp.zip or '') self.label['city'].set_text(self.comp.city or '') self.label['country'].set_text(self.comp.country or '') self.label['phone'].set_text(self.comp.phone or '') self.label['email'].set_text(self.comp.email or '') self.label['web'].set_text(self.comp.web or '') self.label['customerno'].set_text(self.comp.customerno or '') self.label['contractno'].set_text(self.comp.contractno or '') self.label['flags'].set_text(self.comp.flags or '') self.label['remarks'].set_text(self.comp.remarks or '') def edit_record(self): self.entry['compname'].set_text(self.comp.compname) # Type self.dd_comptype.get(self.comp.comptype, -1) # Type2 self.dd_comptype.get(self.comp.comptype2, -1) self.entry['shortname'].set_text(self.comp.shortname or '') self.entry['street'].set_text(self.comp.street or '') self.entry['zip'].set_text(self.comp.zip or '') self.entry['city'].set_text(self.comp.city or '') self.entry['country'].set_text(self.comp.country or '') self.entry['contact'].set_text(self.comp.contact or '') self.entry['phone'].set_text(self.comp.phone or '') self.entry['email'].set_text(self.comp.email or '') self.entry['web'].set_text(self.comp.web or '') self.entry['customerno'].set_text(self.comp.customerno or '') self.entry['contractno'].set_text(self.comp.contractno or '') # buttons on list page def on_but_new_clicked(self, widget): self.topwidget.set_visible_child(self.box['comp_edit']) def on_but_edit_clicked(self, widget): compid = treeview.get_value(self.tree['companies'], 0) if not compid: return self.topwidget.set_visible_child(self.box['comp_edit']) def on_but_detail_clicked(self, widget): compid = treeview.get_value(self.tree['companies'], 0) if not compid: return self.comp.load(compid) self.display_record() self.topwidget.set_visible_child(self.box['comp_detail']) def on_tvw_companies_row_activated(self, widget, path, column): compid = treeview.get_value(widget, 0) self.comp.load(compid) self.display_record() self.topwidget.set_visible_child(self.box['comp_detail']) # buttons on detail page # edit2 uses edit callback def on_but_close_clicked(self, widget): self.topwidget.set_visible_child(self.box['companies']) def on_but_delete_clicked(self, widget): self.topwidget.set_visible_child(self.box['companies']) # buttons on edit page def on_but_save_clicked(self, widget): pass def on_but_cancel_clicked(self, widget): self.topwidget.set_visible_child(self.box['companies'])