def sql_connection(): try: con = sqlite3.connect(DB_FILE) return con except Error: show_message_box(f"Critical error: {Error}") sys.exit(1)
def __init__(self, tree_view): self.db_con = self.sql_connection() self.db_cursor = self.db_con.cursor() is_ok, msg = self.perform_db_sanity() if not is_ok: show_message_box( f"DB sanity failed with message: '{msg}'. Will try to recover") os.remove(DB_FILE) self.db_con = self.sql_connection() self.db_cursor = self.db_con.cursor() self.reset_items(update_tree_view=False) super().__init__(tree_view)
def cache_item(self): row = self.backend.get_selected_row() if row is None: return show_message_box("No backend item selected") self.cache.cache_row(row_id=row.row_id, parent_id=row.parent_id, text=row.text, level=row.level)
def add_item(self): row = self.cache.get_selected_row() if row is None: return show_message_box("No cache item selected") text, ok = TextDialog.getDateTime(parent=self, init_text='') print("{} {}".format(text, ok)) if ok: self.cache.create_row(row.row_id, text)
def edit_item(self): row = self.cache.get_selected_row() if row is None: return show_message_box("No cache item selected") init_text = row.text text, ok = TextDialog.getDateTime(parent=self, init_text=init_text) print("{} {}".format(text, ok)) if ok and text != init_text: self.cache.edit_row(row.row_id, text)
def delete_item(self, item): row = self.cache.get_selected_row() if row is None: return show_message_box("No cache item selected") self.cache.delete_row(row.row_id)