Added Priorities, Auto List refresh
This commit is contained in:
parent
5bacd13f9c
commit
fd0a78215d
3 changed files with 41 additions and 24 deletions
|
@ -23,7 +23,7 @@ done < "$file"
|
||||||
for ((i=1; i<line_number; i++)); do
|
for ((i=1; i<line_number; i++)); do
|
||||||
var="line_$i"
|
var="line_$i"
|
||||||
date=$(date +%s)
|
date=$(date +%s)
|
||||||
echo "INSERT INTO \"main\".\"todo\"(\"ID\",\"TODO\",\"CREATION_DATE\",\"DUE_DATE\",\"PRIO\",\"IMP\") VALUES (NULL,'${!var}','$date','$(($date+60))',100,0);" >> commands.sql
|
echo "INSERT INTO \"main\".\"todo\"(\"ID\",\"TODO\",\"CREATION_DATE\",\"DUE_DATE\",\"PRIO\",\"IMP\") VALUES (NULL,'${!var}','$date','$(($date+60))',1,0);" >> commands.sql
|
||||||
done
|
done
|
||||||
echo converted $file to sql statements
|
echo converted $file to sql statements
|
||||||
sqlite3 todo.db ".read commands.sql"
|
sqlite3 todo.db ".read commands.sql"
|
||||||
|
|
61
main.py
61
main.py
|
@ -31,34 +31,44 @@ def add_item_dialog():
|
||||||
entry.pack(padx=10, pady=5)
|
entry.pack(padx=10, pady=5)
|
||||||
entry.focus()
|
entry.focus()
|
||||||
|
|
||||||
input_confirm = tk.Button(input_field, text="Confirm", command=lambda: add_item(entry, input_field))
|
priority_selection_frame = tk.Frame(input_field) # container for prio and scale
|
||||||
|
priority_selection_frame.pack()
|
||||||
|
priority_label = tk.Label(priority_selection_frame, text="Priority:")
|
||||||
|
priority_label.pack(side=tk.LEFT, padx=25, pady=25)
|
||||||
|
priority_selection = tk.Scale(priority_selection_frame, from_=1, to=3, orient=tk.HORIZONTAL, width=20)
|
||||||
|
priority_selection.pack()
|
||||||
|
|
||||||
|
input_confirm = tk.Button(input_field, text="Confirm",
|
||||||
|
command=lambda: add_item(entry, priority_selection, input_field))
|
||||||
input_confirm.pack(side=tk.BOTTOM, padx=5, pady=5)
|
input_confirm.pack(side=tk.BOTTOM, padx=5, pady=5)
|
||||||
input_field.mainloop()
|
input_field.mainloop()
|
||||||
|
|
||||||
|
|
||||||
def add_item(entry, input_field):
|
def add_item(entry, priority_selection, input_field):
|
||||||
item = entry.get()
|
item = entry.get()
|
||||||
print("added " + item)
|
priority = priority_selection.get()
|
||||||
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() + 600, 100, 0))
|
"'%s', '%s','%s', '%s', '%s' )" % (item, get_time(), get_time() + 60, priority, 0))
|
||||||
con.commit()
|
con.commit()
|
||||||
update_list()
|
update_list()
|
||||||
input_field.destroy()
|
input_field.destroy()
|
||||||
|
|
||||||
|
|
||||||
def remove_item():
|
def remove_item():
|
||||||
selected_index = listbox.curselection()[0] # selection returns tupel
|
if listbox.curselection():
|
||||||
selected_task_id = list(tasklist.keys())[selected_index]
|
selected_index = listbox.curselection()[0] # selection returns tupel
|
||||||
listbox.delete(selected_index)
|
selected_task_id = list(tasklist.keys())[selected_index]
|
||||||
cur.execute("DELETE FROM todo WHERE ID = %s" % selected_task_id)
|
listbox.delete(selected_index)
|
||||||
print("DELETE FROM todo WHERE ID = %s" % selected_task_id)
|
cur.execute("DELETE FROM todo WHERE ID = %s" % selected_task_id)
|
||||||
con.commit()
|
print("DELETE FROM todo WHERE ID = %s" % selected_task_id)
|
||||||
update_list()
|
con.commit()
|
||||||
|
update_list()
|
||||||
|
|
||||||
|
|
||||||
def update_list():
|
def update_list():
|
||||||
|
selected_task = listbox.curselection() # remember selection before rebuilding
|
||||||
listbox.delete(0, listbox.size()) # clear listbox
|
listbox.delete(0, listbox.size()) # clear listbox
|
||||||
cur_time = get_time()
|
cur_time = get_time()
|
||||||
|
|
||||||
|
@ -71,23 +81,21 @@ def update_list():
|
||||||
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])/total_time[i] * res[i][4])
|
importance.append((total_time[i] - remaining_time[i]) / total_time[i] * res[i][4] * 100)
|
||||||
if int(importance[i]) == 0:
|
|
||||||
importance[i] = 1
|
|
||||||
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]))
|
||||||
con.commit()
|
con.commit()
|
||||||
res = cur.execute("SELECT * FROM todo ORDER BY IMP DESC").fetchall()
|
res = cur.execute("SELECT * FROM todo ORDER BY IMP DESC").fetchall()
|
||||||
for i, _tmp2 in enumerate(res):
|
for i, _tmp2 in enumerate(res):
|
||||||
tasklist[res[i][0]] = res[i][1] # create dictionary with id and the task
|
tasklist[res[i][0]] = res[i][1] # create dictionary with id and the task
|
||||||
redraw_list()
|
redraw_list(selected_task)
|
||||||
|
|
||||||
|
|
||||||
def redraw_list():
|
def redraw_list(selected_task):
|
||||||
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
|
||||||
|
if selected_task:
|
||||||
|
listbox.selection_set(selected_task) # restore selection before refresh, if existing
|
||||||
|
|
||||||
|
|
||||||
# Create the main window
|
# Create the main window
|
||||||
|
@ -112,19 +120,28 @@ root.minsize(window_width, window_height) # prevent making it smaller than min
|
||||||
|
|
||||||
# Create a listbox to display the items
|
# Create a listbox to display the items
|
||||||
listbox = tk.Listbox(root, width=100)
|
listbox = tk.Listbox(root, width=100)
|
||||||
listbox.pack(padx=5, pady=5)
|
listbox.pack(padx=5, pady=5, expand=True, fill=tk.BOTH)
|
||||||
|
|
||||||
# Create buttons to add and remove items
|
# Create buttons to add and remove items
|
||||||
add_button = tk.Button(root, text="Add", command=add_item_dialog)
|
add_button = tk.Button(root, text="Add", command=add_item_dialog)
|
||||||
add_button.pack(side=tk.LEFT, padx=5, pady=5)
|
add_button.pack(side=tk.LEFT, padx=5, pady=5)
|
||||||
|
|
||||||
remove_button = tk.Button(root, text="Remove", command=remove_item)
|
|
||||||
remove_button.pack(side=tk.LEFT, padx=5, pady=5)
|
|
||||||
|
|
||||||
update_button = tk.Button(root, text="Reload", 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)
|
||||||
|
|
||||||
|
remove_button = tk.Button(root, text="Remove", command=remove_item)
|
||||||
|
remove_button.pack(side=tk.LEFT, padx=5, pady=5)
|
||||||
|
|
||||||
update_list()
|
update_list()
|
||||||
|
|
||||||
# Run the Tkinter event loop
|
# Run the Tkinter event loop
|
||||||
|
refresh_time = 15
|
||||||
|
|
||||||
|
|
||||||
|
def refresh_ever_x_seconds():
|
||||||
|
update_list()
|
||||||
|
current_time = root.after(1000 * refresh_time, refresh_ever_x_seconds)
|
||||||
|
|
||||||
|
|
||||||
|
refresh_ever_x_seconds()
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
|
@ -20,6 +20,6 @@ done < "$file"
|
||||||
for ((i=1; i<line_number; i++)); do
|
for ((i=1; i<line_number; i++)); do
|
||||||
var="line_$i"
|
var="line_$i"
|
||||||
date=$(date +%s)
|
date=$(date +%s)
|
||||||
echo "INSERT INTO \"main\".\"todo\"(\"ID\",\"TODO\",\"CREATION_DATE\",\"DUE_DATE\",\"PRIO\",\"IMP\") VALUES (NULL,'${!var}','$date','$(($date+60))',100,0);" >> commands.sql
|
echo "INSERT INTO \"main\".\"todo\"(\"ID\",\"TODO\",\"CREATION_DATE\",\"DUE_DATE\",\"PRIO\",\"IMP\") VALUES (NULL,'${!var}','$date','$(($date+60))',1,0);" >> commands.sql
|
||||||
done
|
done
|
||||||
echo converted $file to sql statements
|
echo converted $file to sql statements
|
||||||
|
|
Reference in a new issue