Merge branch 'main' of ssh://game.ione15.com:9237/Ione_15/Ion-Todo-Planner

This commit is contained in:
Ione 15 2024-03-28 20:29:06 +01:00
commit 30d132d6a9
9 changed files with 112 additions and 289 deletions

245
.gitignore vendored
View file

@ -1,241 +1,4 @@
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# ---> JetBrains
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
.idea/*
.virt_env/*
todo.db
commands.sql

View file

@ -1,2 +1,3 @@
# Ion-Todo-Planner
Updates will break backwards compatibility for now!
## Updates will break backwards compatibility for now!
## To get started you should first run fresh_db.sh

View file

@ -1,3 +0,0 @@
INSERT INTO "main"."todo"("ID","TODO","CREATION_DATE","DUE_DATE","PRIO","IMP") VALUES (NULL,'example task 1','1711408035','1711408095',100,0);
INSERT INTO "main"."todo"("ID","TODO","CREATION_DATE","DUE_DATE","PRIO","IMP") VALUES (NULL,'example task 2','1711408035','1711408095',100,0);
INSERT INTO "main"."todo"("ID","TODO","CREATION_DATE","DUE_DATE","PRIO","IMP") VALUES (NULL,'example task 3','1711408035','1711408095',100,0);

View file

@ -4,7 +4,6 @@ CREATE TABLE "todo" (
"CREATION_DATE" INTEGER NOT NULL,
"DUE_DATE" INTEGER NOT NULL,
"PRIO" INTEGER NOT NULL,
"IMP" INTEGER NOT NULL,
PRIMARY KEY("ID" AUTOINCREMENT)
"IMP" INTEGER NOT NULL,
PRIMARY KEY("ID")
);

View file

@ -23,7 +23,7 @@ done < "$file"
for ((i=1; i<line_number; i++)); do
var="line_$i"
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
echo converted $file to sql statements
sqlite3 todo.db ".read commands.sql"

125
main.py
View file

@ -11,67 +11,146 @@ import sqlite3
from datetime import datetime
import time
import tkinter as tk
from collections import OrderedDict
con = sqlite3.connect("todo.db")
cur = con.cursor()
tasklist = OrderedDict()
def add_item():
def get_time():
return (datetime.now() - datetime(1970, 1, 1)).total_seconds() + time.timezone # timezone so we get utc time!
def add_item_dialog():
input_field = tk.Tk()
input_field.title("Add Item")
input_window_width = 640
input_window_height = 320
# find the center point
input_center_x = int(screen_width / 2 - input_window_width / 2)
input_center_y = int(screen_height / 2 - input_window_height / 2)
input_field.geometry(f'{input_window_width}x{input_window_height}+{input_center_x}+{input_center_y}')
# Create an entry for adding items
entry = tk.Entry(input_field, width=50)
entry.pack(padx=10, pady=5)
entry.focus()
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_field.mainloop()
def add_item(entry, priority_selection, input_field):
item = entry.get()
priority = priority_selection.get()
if item:
listbox.insert(tk.END, item)
entry.delete(0, tk.END) # deletes input
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() + 60, priority, 0))
con.commit()
update_list()
input_field.destroy()
def remove_item():
selected_index = listbox.curselection()
if selected_index:
if listbox.curselection():
selected_index = listbox.curselection()[0] # selection returns tupel
selected_task_id = list(tasklist.keys())[selected_index]
listbox.delete(selected_index)
cur.execute("DELETE FROM todo WHERE ID = %s" % selected_task_id)
print("DELETE FROM todo WHERE ID = %s" % selected_task_id)
con.commit()
update_list()
def update_list():
cur_time = (datetime.now() - datetime(1970, 1, 1)).total_seconds() + time.timezone
selected_task = listbox.curselection() # remember selection before rebuilding
listbox.delete(0, listbox.size()) # clear listbox
cur_time = get_time()
total_time = []
total_time = [] # cleanup and init
remaining_time = []
importance = []
tasklist.clear()
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])
remaining_time.append(res[i][3] - cur_time)
importance.append(total_time[i] / remaining_time[i] * res[i][4])
if int(importance[i]) == 0:
importance[i] = 1
print("UPDATE todo SET IMP = %s WHERE ID = %s" % (int(importance[i]), i + 1))
cur.execute("UPDATE todo SET IMP = %s WHERE ID = %s" % (int(importance[i]), i + 1))
print(i)
listbox.insert(tk.END, res[i][0])
importance.append((total_time[i] - remaining_time[i]) / total_time[i] * res[i][4] * 100)
cur.execute("UPDATE todo SET IMP = %s WHERE ID = %s" % (int(importance[i]), res[i][0]))
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(selected_task)
def redraw_list(selected_task):
listbox.delete(0, listbox.size()) # clear listbox
for task in tasklist.items():
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
root = tk.Tk()
root.title("Ion-Todo-Planner")
# get the screen dimension
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
window_width = 1280
window_height = 720
# find the center point
center_x = int(screen_width / 2 - window_width / 2)
center_y = int(screen_height / 2 - window_height / 2)
# set the position of the window to the center of the screen
root.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')
root.minsize(window_width, window_height) # prevent making it smaller than min size
# Create a listbox to display the items
listbox = tk.Listbox(root, width=100)
listbox.pack(padx=5, pady=5)
# Create an entry for adding items
entry = tk.Entry(root, width=50)
entry.pack(padx=10, pady=5)
listbox.pack(padx=5, pady=5, expand=True, fill=tk.BOTH)
# Create buttons to add and remove items
add_button = tk.Button(root, text="Add", command=add_item)
add_button = tk.Button(root, text="Add", command=add_item_dialog)
add_button.pack(side=tk.LEFT, padx=5, pady=5)
update_button = tk.Button(root, text="Reload", command=update_list)
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_button = tk.Button(root, text="Update", command=update_list)
update_button.pack(padx=5, pady=5)
update_list()
# 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()

View file

@ -1,16 +0,0 @@
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

BIN
todo.db

Binary file not shown.

View file

@ -20,6 +20,6 @@ done < "$file"
for ((i=1; i<line_number; i++)); do
var="line_$i"
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
echo converted $file to sql statements