X-Git-Url: http://git.datanom.net/lensdatabase.git/blobdiff_plain/365c79d46c3804dd4b3f796bd2fcd4e3ddf1186b..29f0e748a8cd062a091bc4cca710fa91f720c11c:/searchwindow.py?ds=inline diff --git a/searchwindow.py b/searchwindow.py new file mode 100644 index 0000000..6ef2785 --- /dev/null +++ b/searchwindow.py @@ -0,0 +1,57 @@ +import gi +gi.require_version("Gtk", "3.0") +from gi.repository import Gtk + +class SearchResultDialog(): + def __init__(self, builder, db): + self.db = db + self.window = builder.get_object("search_result_window") + self.window.set_title("Lenses matching search") + self.window.connect("destroy", self.on_destroy) + self.window.set_default_size(600, 300) + self.okBtn = builder.get_object("search_result_ok_btn") + self.okBtn.connect("clicked", self.on_ok_btn_clicked) + box = builder.get_object("search_result_content") + self.liststore = Gtk.ListStore(str, int, str, str, int) + treeview = Gtk.TreeView() + treeview.set_model(self.liststore) + for i, title in enumerate(["Maker", "Serial No", "Lens", "Notes"]): + renderer = Gtk.CellRendererText() + column = Gtk.TreeViewColumn(title, renderer, text=i) + treeview.append_column(column) + self.scrollable_treelist = Gtk.ScrolledWindow() + self.scrollable_treelist.set_vexpand(True) + self.scrollable_treelist.add(treeview) + box.add(self.scrollable_treelist) + self.window.show_all() + self.okBtn.grab_focus() + + def addLensData(self, searchData): + if self.emptyString(searchData[0]) == True and self.emptyString(searchData[1]) == False: + rows = self.db.getLensByPattern(searchData[1]) + elif self.emptyString(searchData[0]) == False and self.emptyString(searchData[1]) == False: + rows = self.db.getLensByMakerPattern(searchData[0], searchData[1]) + elif self.emptyString(searchData[0]) == False and self.emptyString(searchData[1]) == True: + rows = self.db.getLensByMaker(searchData[0]) + else: + rows = None + if rows is not None: + for row in rows: + self.liststore.append(row) + + def emptyString(self, str): +# if not(str and not str.strip()): +# return True +# else: +# return False + return not (str and str.strip()) + + def on_ok_btn_clicked(self, button): + self.on_destroy(self) + + def on_ok_clicked(self, button): + self.on_destroy(self) + + def on_destroy(self, window): + self.scrollable_treelist.destroy() + self.window.hide()