From 3d779590e9e393d329760e76c1f2ca59a055d523 Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 28 Apr 2021 17:53:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D0=B0=D1=8F=20=D0=BA=D0=BD=D0=BE?= =?UTF-8?q?=D0=BF=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/todo_tk.py | 2 +- frontend/user.py | 12 ++++----- frontend/workspace.py | 58 +++++++++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/frontend/todo_tk.py b/frontend/todo_tk.py index 0336afd..50a43e5 100644 --- a/frontend/todo_tk.py +++ b/frontend/todo_tk.py @@ -11,7 +11,7 @@ if "win" in sys.platform.lower(): else: DEFAULT_URL = "http://0.0.0.0:8000" -BASE_W = 580 +BASE_W = 600 BASE_H = 400 TITLE_APP = "ToDo Application" diff --git a/frontend/user.py b/frontend/user.py index 7c58714..588dac8 100644 --- a/frontend/user.py +++ b/frontend/user.py @@ -57,7 +57,7 @@ class ToDoList(object): def remove(self, index): """ - Remove item at index from db + Remove item AT INDEX from db """ item = self.items_[index] self.items_.remove(item) @@ -85,10 +85,10 @@ class ToDoList(object): def dispose(self): print(f"To-do list id '{self.id}' is being disposed of...") - if "DEBUG" in os.environ: - return for item in self.items_: item.dispose() + if "DEBUG" in os.environ: + return self.user.lists_delete(self.id) def sync(self): @@ -229,12 +229,12 @@ class User(UserApi): def removeUserList(self, id): """ - Remove existing user to-do list from the serverreturns: + Remove existing user to-do list BY ID from the serverreturns: """ to_remove = [item for item in self.lists_ if item.id == id][0] self.lists_.remove(to_remove) - if not ("DEBUG" in os.environ): - to_remove.dispose() + # if not ("DEBUG" in os.environ): + to_remove.dispose() return self.lists_ def appendUserList(self, title): diff --git a/frontend/workspace.py b/frontend/workspace.py index 8a488bc..eaabd0a 100644 --- a/frontend/workspace.py +++ b/frontend/workspace.py @@ -82,7 +82,7 @@ class ToDoListWidget(tk.Frame): add = tk.Button(self, text="Добавить заметку", command=self.add_command) add.pack(side="top") - delete = tk.Button(self, text="Удалить лист", command=placeholder) + delete = tk.Button(self, text="Удалить лист", command=self.master.delete_list) delete.pack(side="top") def update(self, itemList=None): @@ -106,6 +106,17 @@ class ToDoListWidget(tk.Frame): class WorkSpaceFrame(tk.Frame): + def delete_list(self, *args): + selection = self.listBox.curselection() + cur = selection[0] + self.user.removeUserList(self.lists[cur].id) + self.lists = self.user.fetchUserLists() + self.update_lists() + if len(self.lists) > 1: + self.listBox.selection_set(first=cur - 1) + elif len(self.lists) > 0: + self.listBox.selection_set(first=0) + def __init__(self, user, master=None, url=None) -> None: """ Функция инициаизации класса @@ -154,16 +165,36 @@ class WorkSpaceFrame(tk.Frame): # add scroll bar to list box self.listBox.config(yscrollcommand=scrollbar.set) - # fill list box + # init list view + self.update_lists() + + # canvas for todo lists + # canvas = tk.Canvas(self) + # canvas.pack(side="left", fill="both", expand=1) + # scrollbar = tk.Scrollbar(self, orient="vertical") + # scrollbar.config(command=canvas.yview) + # scrollbar.pack(side="left", fill="y") + # canvas.configure(yscrollcommand=scrollbar.set) + + # todo lists + self.toDoList = ToDoListWidget(self) + # self.toDoList = ToDoListWidget(canvas) + self.toDoList.pack(side="left", fill="y") + # canvas.bind('', lambda *argv: print(self.toDoList.winfo_height())) + # canvas.create_window((0,0), window=self.toDoList, anchor='nw') + + # select list! + if len(self.lists) > 0: + self.listBox.selection_set(first=0) + self.listBox_selected() + + def update_lists(self): + self.listBox.delete(0, "end") for item in self.lists: s = f"{str(item)}: {item.created_at.strftime('%Y-%m-%d %H:%M:%S')}" self.listBox.insert(tk.END, s) self.listBox.pack() - len(self.lists) > 0 and self.listBox.selection_set(first=0) - - # todo lists - self.toToList = ToDoListWidget(self) - self.toToList.pack(side="left", fill="both", expand=1) + return len(self.lists) def add_list(self, *args): text = self.add_list_text.get(1.0, "end").strip() @@ -174,18 +205,13 @@ class WorkSpaceFrame(tk.Frame): self.lists = self.user.fetchUserLists() # fill list box - self.listBox.delete(0, "end") - for item in self.lists: - s = f"{str(item)}: {item.created_at.strftime('%Y-%m-%d %H:%M:%S')}" - self.listBox.insert(tk.END, s) - self.listBox.pack() - len(self.lists) > 0 and self.listBox.selection_set(first=0) + self.update_lists() + len(self.lists) > 0 and self.listBox.selection_set(first=len(self.lists) - 1) def listBox_selected(self, *args): - - self.toToList.clear() + self.toDoList.clear() selection = self.listBox.curselection() cur = selection[0] - self.toToList.fill(self.lists[cur]) + self.toDoList.fill(self.lists[cur])