def open_viewer(self): """Loads the data for your selection, opens and populates a view window with that data""" choice = self.thoughts_lst.get(tk.ACTIVE) subject = self.refference[choice] tbl = self.home_table[subject] view = kit.SQL_pull('*', tbl, 'subject_id = "{}"'.format(subject)) obj = kit.class_fill(tbl, view[0]) self.session = tk.Toplevel(self.master, **jt.bframe_style) jv.Viewer(self.session, obj)
def checked(self, tbl, big=True, array=''): """Is used to check or uncheck search boxes conditionally. For the Big Bools - denoted by Big = True - checking it should check all the sub-boxes, and vice versa. For the sub-boxes - denoted by Big = False - unchecking it should uncheck the Big Bool and checking it should check the Big Bool if all the other sub-boxes are already checked. Finally, it updates the counter message with the new count.""" selectall = self.BIG[tbl] counter = self.catcounts[tbl] rtag = self.rcols[tbl] if big: array = self.boxes[tbl] all_bools = [i.get() for i in array.values()] if sum(all_bools) in [0, len(all_bools)] or selectall.get(): for bvar in array.values(): bvar.set(selectall.get()) else: all_bools = [array[k].get() for k in array] if selectall.get(): selectall.set(False) elif not selectall.get() and sum(all_bools) == len(all_bools): selectall.set(True) if selectall.get(): num = len(kit.SQL_pull('*', tbl)) else: to_count = [key for key in array if array[key].get()] in_str = '("' + '", "'.join(to_count) + '")' code = '{} IN {}'.format(rtag, in_str) num = len(kit.SQL_pull('*', tbl, code)) if tbl == 'tvshows': label = 'TV Shows' else: label = tbl.capitalize() counter.configure(text='{} {}'.format(num, label))
def array_update(self, table_list): """Takes a list of tables and refreshes self.refference and self.home_tables with all the entries in those tables""" for tbl in table_list: x = kit.SQL_pull('name, subject_id', tbl) r = {i[0]: i[1] for i in x} h = {i[1]: tbl for i in x} self.refference.update(r) self.home_table.update(h) self.counts[tbl] = len(x)
def opinion_save(self): """Saves the information to the SQLite database""" current_raw = kit.SQL_pull('subject_id', self.source.tbl) current = [i for t in current_raw for i in t] if self.vstate.get(): if self.source.subject_id in current: self.source.SQL_save('update') self.master.destroy() else: self.source.SQL_save('new') self.master.destroy() else: please = 'Please verify that you are\nfinished writing your thoughts' messagebox.showinfo('Please Verify', please)
def filter_thoughts(self): """Refreshes self.refference and self.home_table with only the subjects that match the checked search boxes""" relevant_tbls = ['movies', 'tvshows', 'books', 'restaurants'] relevant_bool = [ self.all_movies.get(), self.all_tv.get(), self.all_books.get(), self.all_food.get() ] filtered_tbls = [ relevant_tbls[i] for i in range(len(relevant_tbls)) if relevant_bool[i] ] self.refference = {} self.home_table = {} self.array_update(filtered_tbls) relevant_cols = ['genre', 'genre', 'genre', 'cuisine'] tag_filter = [ self.movie_boxes, self.tv_boxes, self.book_boxes, self.food_boxes ] for array in tag_filter: dex = tag_filter.index(array) tbl = relevant_tbls[dex] col = relevant_cols[dex] allowed_tags = [] for key in array: if array[key].get(): allowed_tags.append(key) in_str = '("' + '", "'.join(allowed_tags) + '")' code = '{} IN {}'.format(col, in_str) filtered = kit.SQL_pull('name, subject_id', tbl, code) r = {i[0]: i[1] for i in filtered} h = {i[1]: tbl for i in filtered} self.refference.update(r) self.home_table.update(h) if len(self.refference) == 0: self.array_update(jt.sql_tables) self.thoughts_lst.delete(0, tk.END) for thought in sorted(self.refference.keys()): self.thoughts_lst.insert(tk.END, thought)
def populate_filter(self, src, col, tbl): """Creates one checkbox for each item in a SQLite table column. Returns an array where these items are mapped to their respective BooleanVars. Checkboxes are empowered with the same Checked function as the BIG BOOL boxes except we pass a couple more arguments to change its effect.""" sub_cats = set([c for l in kit.SQL_pull(col, tbl) for c in l]) select = {g: tk.BooleanVar() for g in sub_cats} for key in select: select[key].set(True) line = 1 for g in sub_cats: line += 1 tk.Checkbutton( src, text=g, variable=select[g], command=lambda x=tbl, y=False, z=select: self.checked(x, y, z), **jt.filter_style).grid(row=line, sticky=tk.W) return select