]> git.datanom.net - lensdatabase.git/blame - notebook.py
update .gitignore and add setup tools
[lensdatabase.git] / notebook.py
CommitLineData
29f0e748
MR
1import gi
2gi.require_version("Gtk", "3.0")
3from gi.repository import Gtk
4from newlensdialog import NewlensDialog
5
6pages = {}
7
8class Notebook:
9 __instance = None
10 def __new__(cls, *args, **kwargs):
11 if (cls.__instance is None):
12 cls.__instance = super(Notebook, cls).__new__(cls)
13 return cls.__instance
14
15 def __init__(self, builder, db):
16 self.builder = builder
17 self.db = db
18 self.nb = self.builder.get_object("lens_maker_notebook")
19
20 def setDB(self, db):
21 self.db = db
22
23 def addPage(self, name):
24 if pages.get(name) is not None:
25 raise Exception("{page}: Page exists".format(page = name))
26 label = Gtk.Label()
27 label.set_text(name)
28 liststore = Gtk.ListStore(int, str, str, int)
29 treeview = Gtk.TreeView()
30 treeview.connect("row-activated", self.on_row_activated)
31 treeview.set_model(liststore)
32 for i, title in enumerate(["Serial No", "Lens", "Notes"]):
33 renderer = Gtk.CellRendererText()
34 column = Gtk.TreeViewColumn(title, renderer, text=i)
35 treeview.append_column(column)
36 scrollable_treelist = Gtk.ScrolledWindow()
37 scrollable_treelist.set_vexpand(True)
38 scrollable_treelist.add(treeview)
39 index = self.nb.append_page(scrollable_treelist, label)
40 if index < 0:
41 raise Exception("{page}: Page not added".format(page = name))
42 if self.db is not None:
43 self.db.addMaker(name)
44 pages[name] = liststore
45 self.nb.show_all()
46
47 def addRow(self, tab, tuple):
48 page = pages.get(tab)
49 if page is None:
50 raise Exception("{name}: Page does not exist".format(name = tab))
51 try:
52 if self.db is not None:
53 id = self.db.addLens(tab, tuple)
54 page.append(tuple + (id, ))
55 else:
56 page.append(tuple)
57 except Exception as err:
58 print(err)
59 raise
60
61 def updateRow(self, path, tuple):
62 try:
63 model = path[0]
64 row = path[1]
65 for i in range(0, len(tuple)):
66 model[row][i] = tuple[i]
67 if self.db is not None:
68 self.db.updateLens(tuple)
69 except Exception as err:
70 print(err)
71 raise
72
73 def deleteRow(self, path, id):
74 try:
75 model = path[0]
76 iter = model.get_iter(path[1])
77 model.remove(iter)
78 if self.db is not None:
79 self.db.deleteLens(id)
80 except Exception as err:
81 print(err)
82 raise
83
84 def deletePage(self, pagenum):
85 self.nb.remove_page(pagenum)
86
87 def getCurrentPage(self):
88 return self.nb.get_current_page()
89
90 def getCurrentPageLabel(self):
91 page = self.nb.get_nth_page(self.getCurrentPage())
92 label = self.nb.get_tab_label_text(page)
93 return label
94
95 def on_row_activated(self, widget, row, col):
96 model = widget.get_model()
97 lensdata = []
98 for i in range(0, 4):
99 lensdata.append(model[row][i])
100 lensDialog = NewlensDialog(self.builder, self.db, (model, row))
101 lensDialog.setText(lensdata)
This page took 0.080321 seconds and 5 git commands to generate.