Native gui first steps: storage, box and companies are editable
This commit is contained in:
1 parent
1eea4058bf
commit
06a9834688
47 files changed
+3119
-883
No files matched your search
+75
-12
@@ -18,29 +18,42 @@ class CompaniesView(View):
|
||||
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)
|
||||
combobox.load_from_dict(self.combo['flt_type'], {-2: _("─── all ───"), -1: _("─── none ───")} | self.dd_comptype, -2)
|
||||
combobox.load_from_dict(self.combo['comptype'], self.dd_comptype, company.SUPPLIER)
|
||||
combobox.load_from_dict(self.combo['comptype2'], {-1: _("─── none ───")} | 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]))
|
||||
self.load_list()
|
||||
|
||||
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 load_list(self):
|
||||
selected_id = treeview.get_value(self.tree['companies'])
|
||||
self.lst_companies.clear()
|
||||
sql = (
|
||||
"SELECT compid, compname, comptype, remarks "
|
||||
"FROM company "
|
||||
"WHERE compid >= 0 "
|
||||
"ORDER BY compname"
|
||||
)
|
||||
self.db.cur.execute(sql)
|
||||
selection = self.tree['companies'].get_selection()
|
||||
for row in self.db.cur.fetchall():
|
||||
treeiter = self.lst_companies.append((row[0], row[1], self.dd_comptype[row[2]], row[3]))
|
||||
if row[0] == selected_id:
|
||||
# restore previous selected row
|
||||
selection.select_iter(treeiter)
|
||||
|
||||
def clear_record(self):
|
||||
self.entry['name'].set_text('')
|
||||
self.entry['compname'].set_text('')
|
||||
self.entry['shortname'].set_text('')
|
||||
self.entry['street'].set_text('')
|
||||
self.entry['zip'].set_text('')
|
||||
@@ -52,7 +65,7 @@ class CompaniesView(View):
|
||||
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['comptype'], company.SUPPLIER)
|
||||
combobox.activate_row(self.combo['comptype2'], -1)
|
||||
|
||||
def display_record(self):
|
||||
@@ -76,6 +89,8 @@ class CompaniesView(View):
|
||||
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)
|
||||
combobox.activate_row(self.combo['comptype'], self.comp.comptype)
|
||||
combobox.activate_row(self.combo['comptype2'], self.comp.comptype2)
|
||||
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 '')
|
||||
@@ -87,15 +102,44 @@ class CompaniesView(View):
|
||||
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 '')
|
||||
self.text['remarks'].get_buffer().set_text(self.comp.remarks or '')
|
||||
|
||||
def save_record(self):
|
||||
# fields must have been validated beforehand
|
||||
self.comp.compname = self.entry['compname'].get_text()
|
||||
self.comp.comptype = combobox.get_list_value(self.combo['comptype'])
|
||||
self.comp.comptype2 = combobox.get_list_value(self.combo['comptype2'])
|
||||
if self.comp.comptype2 < 0:
|
||||
self.comp.comptype2 = None
|
||||
self.comp.shortname = self.entry['shortname'].get_text()
|
||||
self.comp.street = self.entry['street'].get_text()
|
||||
self.comp.zip = self.entry['zip'].get_text()
|
||||
self.comp.city = self.entry['city'].get_text()
|
||||
self.comp.country = self.entry['country'].get_text()
|
||||
self.comp.contact = self.entry['contact'].get_text()
|
||||
self.comp.phone = self.entry['phone'].get_text()
|
||||
self.comp.email = self.entry['email'].get_text()
|
||||
self.comp.web = self.entry['web'].get_text()
|
||||
self.comp.customerno = self.entry['customerno'].get_text()
|
||||
self.comp.conractno = self.entry['contractno'].get_text()
|
||||
self.comp.remarks = gtkutils.get_text_contents(self.text['remarks'])
|
||||
|
||||
# buttons on list page
|
||||
def on_but_new_clicked(self, widget):
|
||||
self.newrecord = True
|
||||
self.label['title_edit'].set_text(_("Add new Company"))
|
||||
self.clear_record()
|
||||
self.topwidget.set_visible_child(self.box['comp_edit'])
|
||||
|
||||
def on_but_edit_clicked(self, widget):
|
||||
self.newrecord = False
|
||||
compid = treeview.get_value(self.tree['companies'], 0)
|
||||
if not compid:
|
||||
return
|
||||
self.comp.load(compid)
|
||||
self.edit_record()
|
||||
self.label['title_edit'].set_text(_("Edit Company"))
|
||||
|
||||
self.topwidget.set_visible_child(self.box['comp_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
@@ -118,11 +162,30 @@ class CompaniesView(View):
|
||||
self.topwidget.set_visible_child(self.box['companies'])
|
||||
|
||||
def on_but_delete_clicked(self, widget):
|
||||
answer = gtkutils.questionbox(
|
||||
_("Delete company!\n"
|
||||
"Are you sure?"), title="YMS"
|
||||
)
|
||||
if answer == False:
|
||||
return
|
||||
self.topwidget.set_visible_child(self.box['companies'])
|
||||
|
||||
# buttons on edit page
|
||||
def on_but_save_clicked(self, widget):
|
||||
pass
|
||||
# check mandatory fields:
|
||||
compname = self.entry['compname'].get_text().strip()
|
||||
# TODO type
|
||||
if not compname:
|
||||
# TODO error marker
|
||||
return
|
||||
self.save_record()
|
||||
print(self.comp)
|
||||
self.comp.save()
|
||||
if self.newrecord:
|
||||
self.load_list()
|
||||
self.newrecord = False
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['comp_detail'])
|
||||
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['companies'])
|
||||
Reference in new issue
Block a user