cleaned up.
fixed unable to delete index 0
This commit is contained in:
parent
62c289c130
commit
f685ada2a5
1 changed files with 19 additions and 14 deletions
27
main.py
27
main.py
|
@ -29,6 +29,7 @@ def add_item_dialog():
|
||||||
# Create an entry for adding items
|
# Create an entry for adding items
|
||||||
entry = tk.Entry(input_field, width=50)
|
entry = tk.Entry(input_field, width=50)
|
||||||
entry.pack(padx=10, pady=5)
|
entry.pack(padx=10, pady=5)
|
||||||
|
entry.focus()
|
||||||
|
|
||||||
input_confirm = tk.Button(input_field, text="Confirm", command=lambda: add_item(entry, input_field))
|
input_confirm = tk.Button(input_field, text="Confirm", command=lambda: add_item(entry, input_field))
|
||||||
input_confirm.pack(side=tk.BOTTOM, padx=5, pady=5)
|
input_confirm.pack(side=tk.BOTTOM, padx=5, pady=5)
|
||||||
|
@ -41,19 +42,18 @@ def add_item(entry, input_field):
|
||||||
if item:
|
if item:
|
||||||
listbox.insert(tk.END, item)
|
listbox.insert(tk.END, item)
|
||||||
cur.execute("INSERT INTO todo(\"ID\",\"TODO\",\"CREATION_DATE\",\"DUE_DATE\",\"PRIO\",\"IMP\") VALUES (NULL, "
|
cur.execute("INSERT INTO todo(\"ID\",\"TODO\",\"CREATION_DATE\",\"DUE_DATE\",\"PRIO\",\"IMP\") VALUES (NULL, "
|
||||||
"'%s', '%s','%s', '%s', '%s' )" % (item, get_time(), get_time(), 100, 0))
|
"'%s', '%s','%s', '%s', '%s' )" % (item, get_time(), get_time() + 600, 100, 0))
|
||||||
con.commit()
|
con.commit()
|
||||||
input_field.destroy()
|
|
||||||
update_list()
|
update_list()
|
||||||
|
input_field.destroy()
|
||||||
|
|
||||||
|
|
||||||
def remove_item():
|
def remove_item():
|
||||||
selected_index = listbox.curselection()
|
selected_index = listbox.curselection()[0] # selection returns tupel
|
||||||
if selected_index:
|
selected_task_id = list(tasklist.keys())[selected_index]
|
||||||
listbox.delete(selected_index)
|
listbox.delete(selected_index)
|
||||||
print(selected_index[0])
|
cur.execute("DELETE FROM todo WHERE ID = %s" % selected_task_id)
|
||||||
cur.execute("DELETE FROM todo WHERE ID = %s" % list(tasklist.keys())[selected_index[0]])
|
print("DELETE FROM todo WHERE ID = %s" % selected_task_id)
|
||||||
print("DELETE FROM todo WHERE ID = %s" % list(tasklist.keys())[selected_index[0]])
|
|
||||||
con.commit()
|
con.commit()
|
||||||
update_list()
|
update_list()
|
||||||
|
|
||||||
|
@ -68,21 +68,24 @@ def update_list():
|
||||||
tasklist.clear()
|
tasklist.clear()
|
||||||
|
|
||||||
res = cur.execute("SELECT * FROM todo").fetchall()
|
res = cur.execute("SELECT * FROM todo").fetchall()
|
||||||
for i, tmp1 in enumerate(res):
|
for i, _tmp1 in enumerate(res):
|
||||||
total_time.append(res[i][3] - res[i][2])
|
total_time.append(res[i][3] - res[i][2])
|
||||||
remaining_time.append(res[i][3] - cur_time)
|
remaining_time.append(res[i][3] - cur_time)
|
||||||
importance.append(total_time[i] / remaining_time[i] * res[i][4])
|
importance.append(total_time[i] / remaining_time[i] * res[i][4])
|
||||||
if int(importance[i]) == 0:
|
if int(importance[i]) == 0:
|
||||||
importance[i] = 1
|
importance[i] = 1
|
||||||
print("Priority of Task ID " + str(i + 1) + " Set to: " + str(importance[i])) # res [i][0] = ID
|
print("Priority of Task ID " + str(res[i][0]) + " Set to: " + str(importance[i])) # res [i][0] = ID
|
||||||
cur.execute("UPDATE todo SET IMP = %s WHERE ID = %s" % (int(importance[i]), res[i][0]))
|
cur.execute("UPDATE todo SET IMP = %s WHERE ID = %s" % (int(importance[i]), res[i][0]))
|
||||||
tasklist[res[i][0]] = res[i][1] # create dictionary with id and the task
|
|
||||||
con.commit()
|
con.commit()
|
||||||
|
res = cur.execute("SELECT * FROM todo ORDER BY IMP DESC").fetchall()
|
||||||
|
for i, _tmp2 in enumerate(res):
|
||||||
|
tasklist[res[i][0]] = res[i][1] # create dictionary with id and the task
|
||||||
redraw_list()
|
redraw_list()
|
||||||
|
|
||||||
|
|
||||||
def redraw_list():
|
def redraw_list():
|
||||||
listbox.delete(0, listbox.size()) # clear listbox
|
listbox.delete(0, listbox.size()) # clear listbox
|
||||||
|
print(tasklist)
|
||||||
for task in tasklist.items():
|
for task in tasklist.items():
|
||||||
listbox.insert(tk.END, task[1]) # [0] = id
|
listbox.insert(tk.END, task[1]) # [0] = id
|
||||||
|
|
||||||
|
@ -118,8 +121,10 @@ add_button.pack(side=tk.LEFT, padx=5, pady=5)
|
||||||
remove_button = tk.Button(root, text="Remove", command=remove_item)
|
remove_button = tk.Button(root, text="Remove", command=remove_item)
|
||||||
remove_button.pack(side=tk.LEFT, padx=5, pady=5)
|
remove_button.pack(side=tk.LEFT, padx=5, pady=5)
|
||||||
|
|
||||||
update_button = tk.Button(root, text="Update", command=update_list)
|
update_button = tk.Button(root, text="Reload", command=update_list)
|
||||||
update_button.pack(side=tk.LEFT, padx=5, pady=5)
|
update_button.pack(side=tk.LEFT, padx=5, pady=5)
|
||||||
|
|
||||||
|
update_list()
|
||||||
|
|
||||||
# Run the Tkinter event loop
|
# Run the Tkinter event loop
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
Reference in a new issue