class SearchBarCompare(TextInput): def __init__(self, alpha): super().__init__(hint_text="Company...", background_color=(0, 0, 0, 0), foreground_color=(1, 1, 1, 1), cursor_color=(0, 1, 0, 1), multiline=False) self.crossRefs = pickle.load(open("res/catDict.p", 'rb')) searchables = list(self.crossRefs.keys()) self.searchRecs = SearchTree(searchables) self.alpha = alpha self.scrollView = None self.searchRecLayout = None self.bind(focus=self.updateAFBox) self.bind(text=self.autofill) def updateAFBox(self, *args): if args[-1]: #print(args) #generateAFBox() self.searchRecLayout = GridLayout(cols=1, size_hint_y=None, height=Window.height * 1) if self.text: self.autofill(self.text) self.alpha.swap(self.searchRecLayout) else: self.alpha.swap() def autofill(self, *args): if self.searchRecLayout and args[-1]: #print("trying to populate") self.searchRecLayout = GridLayout(cols=1, size_hint_y=None, height=Window.height * 1) recommend = self.searchRecs.relateItem(args[-1].upper()) for cat in recommend: #print(r) b = Button(text=cat, height=Window.height * .1, size_hint_max_y=Window.height * .1, size_hint_min_y=Window.height * .1) b.cat = cat def useRec(itself): self.text = itself.cat self.alpha.updateList() b.bind(on_press=useRec) self.searchRecLayout.add_widget(b) self.alpha.swap(self.searchRecLayout)
class SearchBar(TextInput): def __init__(self, master, activity, searchDB=None): #db = (searchables, SearchTree) super().__init__(hint_text="Company...", background_color=(0, 0, 0, 0), foreground_color=(1, 1, 1, 1), cursor_color=(0, 1, 0, 1), multiline=False, size_hint_y=None, size_hint_x=.7, height=Window.height * .1) if not searchDB: searchables = pickle.load(open("res/searchables.p", 'rb')) self.crossRefs = pickle.load(open("res/crossMark6.p", 'rb')) self.searchRecs = SearchTree(searchables) else: self.crossRefs = searchDB[0] self.searchRecs = searchDB[1] self.activity = activity self.master = master self.scrollView = None self.searchRecLayout = None #self.bind(focus = self.updateAFBox) self.bind(text=self.autofill) def updateAFBox(self, *args): if args[-1]: self.searchRecLayout = GridLayout(cols=1, size_hint_y=None, height=Window.height * 1) if self.text: self.autofill(self.text) if self.master.searchRecLayout: self.master.remove_widget(self.master.searchRecLayout) self.master.add_widget(self.searchRecLayout) self.master.searchRecLayout = self.searchRecLayout # else: # self.activity.swap() def autofill(self, *args): if args[-1]: self.searchRecLayout = GridLayout(cols=1, size_hint_y=None, height=Window.height * 1) recommend = self.searchRecs.relateItem(args[-1].upper()) txts = [] for r in recommend: cross = "" if r in self.crossRefs: cross = self.crossRefs[r] abbr = cross name = r if len(r) < len(cross) or not cross: abbr = r name = cross elif len(r) == len(cross) and r < cross: abbr = r name = cross if "(the)" in name.lower(): name = "The " + name[0:-6] txt = abbr + ": " + name if txt in txts: continue txts.append(txt) b = Button(text=txt, height=Window.height * .1, halign="center", font_name="res/Aldrich", font_hinting="light", size_hint_max_y=Window.height * .1, size_hint_min_y=Window.height * .1) b.text_size[0] = Window.width b.abbr = abbr b.name = name def useRec(itself): #self.text = itself.abbr self.master.master.portfolio.addStock( itself.abbr, itself.name) self.activity.titleLabel.text = self.master.master.portfolio.name + "'s Stocks" self.activity.swap( PortfolioEditorLayout(self.master.master.portfolio, self.activity)) b.bind(on_press=useRec) self.searchRecLayout.add_widget(b) self.searchRecLayout.height = Window.height * .1 * len(recommend) if self.master.searchRecLayout: self.master.remove_widget(self.master.searchRecLayout) self.master.add_widget(self.searchRecLayout) self.master.searchRecLayout = self.searchRecLayout
class SearchBar(TextInput): def __init__(self, alpha, searchDB): super().__init__(hint_text="Company...", background_color=(0, 0, 0, 0), foreground_color=(1, 1, 1, 1), cursor_color=(0, 1, 0, 1), multiline=False) if not searchDB: searchables = pickle.load(open("res/searchables.p", 'rb')) self.crossRefs = pickle.load(open("res/crossMark6.p", 'rb')) self.searchRecs = SearchTree(searchables) else: self.crossRefs = searchDB[0] self.searchRecs = searchDB[1] self.alpha = alpha self.scrollView = None self.searchRecLayout = None self.bind(focus=self.updateAFBox) self.bind(text=self.autofill) def updateAFBox(self, *args): if args[-1]: self.searchRecLayout = GridLayout(cols=1, size_hint_y=None, height=Window.height * 1) if self.text: self.autofill(self.text) self.alpha.swap(self.searchRecLayout) # else: # self.alpha.swap() def autofill(self, *args): if self.searchRecLayout and args[-1]: self.searchRecLayout = GridLayout(cols=1, size_hint_y=None, height=Window.height * 1) recommend = self.searchRecs.relateItem(args[-1].upper()) txts = [] for r in recommend: cross = "" if r in self.crossRefs: cross = self.crossRefs[r] abbr = cross name = r if len(r) < len(cross) or not cross: abbr = r name = cross elif len(r) == len(cross) and r < cross: abbr = r name = cross if "(the)" in name.lower(): name = "The " + name[0:-6] txt = abbr + ": " + name if txt in txts: continue txts.append(txt) b = Button(text=txt, height=Window.height * .1, halign="center", font_name="res/Aldrich", font_hinting="light", size_hint_max_y=Window.height * .1, size_hint_min_y=Window.height * .1) b.text_size[0] = Window.width b.abbr = abbr def useRec(itself): self.text = itself.abbr self.alpha.swap() self.alpha.updateLoader() b.bind(on_press=useRec) self.searchRecLayout.add_widget(b) self.searchRecLayout.height = Window.height * .1 * len(recommend) self.alpha.swap(self.searchRecLayout)