]>
Commit | Line | Data |
---|---|---|
1 | import gi | |
2 | gi.require_version("Gtk", "3.0") | |
3 | from gi.repository import Gtk | |
4 | ||
5 | class SearchResultDialog(): | |
6 | def __init__(self, builder, db): | |
7 | self.db = db | |
8 | self.window = builder.get_object("search_result_window") | |
9 | self.window.set_title("Lenses matching search") | |
10 | self.window.connect("destroy", self.on_destroy) | |
11 | self.window.set_default_size(600, 300) | |
12 | self.okBtn = builder.get_object("search_result_ok_btn") | |
13 | self.okBtn.connect("clicked", self.on_ok_btn_clicked) | |
14 | box = builder.get_object("search_result_content") | |
15 | self.liststore = Gtk.ListStore(str, int, str, str, int) | |
16 | treeview = Gtk.TreeView() | |
17 | treeview.set_model(self.liststore) | |
18 | for i, title in enumerate(["Maker", "Serial No", "Lens", "Notes"]): | |
19 | renderer = Gtk.CellRendererText() | |
20 | column = Gtk.TreeViewColumn(title, renderer, text=i) | |
21 | treeview.append_column(column) | |
22 | self.scrollable_treelist = Gtk.ScrolledWindow() | |
23 | self.scrollable_treelist.set_vexpand(True) | |
24 | self.scrollable_treelist.add(treeview) | |
25 | box.add(self.scrollable_treelist) | |
26 | self.window.show_all() | |
27 | self.okBtn.grab_focus() | |
28 | ||
29 | def addLensData(self, searchData): | |
30 | if self.emptyString(searchData[0]) == True and self.emptyString(searchData[1]) == False: | |
31 | rows = self.db.getLensByPattern(searchData[1]) | |
32 | elif self.emptyString(searchData[0]) == False and self.emptyString(searchData[1]) == False: | |
33 | rows = self.db.getLensByMakerPattern(searchData[0], searchData[1]) | |
34 | elif self.emptyString(searchData[0]) == False and self.emptyString(searchData[1]) == True: | |
35 | rows = self.db.getLensByMaker(searchData[0]) | |
36 | else: | |
37 | rows = None | |
38 | if rows is not None: | |
39 | for row in rows: | |
40 | self.liststore.append(row) | |
41 | ||
42 | def emptyString(self, str): | |
43 | # if not(str and not str.strip()): | |
44 | # return True | |
45 | # else: | |
46 | # return False | |
47 | return not (str and str.strip()) | |
48 | ||
49 | def on_ok_btn_clicked(self, button): | |
50 | self.on_destroy(self) | |
51 | ||
52 | def on_ok_clicked(self, button): | |
53 | self.on_destroy(self) | |
54 | ||
55 | def on_destroy(self, window): | |
56 | self.scrollable_treelist.destroy() | |
57 | self.window.hide() |