Created
April 3, 2022 14:19
-
-
Save cerisara/90259aa9eb35f63c9a9910c8feb71b6c to your computer and use it in GitHub Desktop.
calcuse on android with termux-gui and git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import termuxgui as tg | |
import sys | |
import time | |
import threading | |
import os | |
import datetime | |
import calendar | |
with tg.Connection() as c: | |
a = tg.Activity(c) | |
# For each View or Layout you create you can specify the parent Layout to create a hiearachy. | |
# If you don't specify a parent, it will replace the current root View. | |
# We first create a LinearLayout as our root View. | |
root = tg.LinearLayout(a) | |
# Then we create a TextView that we will use as a title | |
title = tg.TextView(a, "Calendar", root) | |
title.setmargin(5) | |
# We set the font size a bit bigger | |
title.settextsize(30) | |
contenttext = "loading from git..." | |
# Now we create a TextView for the main content | |
content = tg.TextView(a, contenttext, root) | |
hours = tg.LinearLayout(a, root, False) | |
eth = tg.EditText(a, "14", hours) | |
emi = tg.EditText(a, "00", hours) | |
est = tg.EditText(a, " ", hours) | |
buttons = tg.LinearLayout(a, root, False) | |
prev = tg.Button(a, "prev", buttons) | |
next = tg.Button(a, "next", buttons) | |
add = tg.Button(a, "add", buttons) | |
push = tg.Button(a, "push", buttons) | |
quit = tg.Button(a, "quit", buttons) | |
today = datetime.datetime.today() | |
tgtday = today + datetime.timedelta(days=7) | |
sdat=str(tgtday.month)+"/"+str(tgtday.day)+"/"+str(tgtday.year) | |
title.settext(sdat+" "+calendar.day_name[tgtday.weekday()]) | |
os.system('cd git/LORIA/calcurse; git pull; calcurse -c ./apts -d "'+sdat+'" > $HOME/tt') | |
with open("tt") as f: ll = f.readlines() | |
ll=' '.join(ll) | |
content.settext(ll) | |
# Now we give the Layout priority to our content Textview so it is bigger than the Button and the title. | |
content.setlinearlayoutparams(10) | |
# create a thread to handle the events, so we can still exit the program after 5 seconds no matter what | |
for ev in c.events(): # waits for events from the gui | |
if ev.type == tg.Event.destroy and ev.value["finishing"]: | |
sys.exit() | |
if ev.type == tg.Event.click and ev.value["id"] == quit: | |
a.finish() | |
if ev.type == tg.Event.click and ev.value["id"] == next: | |
tgtday = tgtday + datetime.timedelta(days=1) | |
sdat=str(tgtday.month)+"/"+str(tgtday.day)+"/"+str(tgtday.year) | |
title.settext(sdat+" "+calendar.day_name[tgtday.weekday()]) | |
os.system('cd git/LORIA/calcurse; calcurse -c ./apts -d "'+sdat+'" > $HOME/tt') | |
with open("tt") as f: ll = f.readlines() | |
ll=' '.join(ll) | |
content.settext(ll) | |
if ev.type == tg.Event.click and ev.value["id"] == prev: | |
tgtday = tgtday + datetime.timedelta(days=-1) | |
sdat=str(tgtday.month)+"/"+str(tgtday.day)+"/"+str(tgtday.year) | |
title.settext(sdat+" "+calendar.day_name[tgtday.weekday()]) | |
os.system('cd git/LORIA/calcurse; calcurse -c ./apts -d "'+sdat+'" > $HOME/tt') | |
with open("tt") as f: ll = f.readlines() | |
ll=' '.join(ll) | |
content.settext(ll) | |
if ev.type == tg.Event.click and ev.value["id"] == add: | |
hh = int(eth.gettext().strip()) | |
mm = int(emi.gettext().strip()) | |
ss = est.gettext().strip() | |
xx = str(tgtday.month)+"/"+str(tgtday.day)+"/"+str(tgtday.year)+" @ "+str(hh)+":"+str(mm)+\ | |
" -> "+str(tgtday.month)+"/"+str(tgtday.day)+"/"+str(tgtday.year)+" @ "+str(hh+1)+":"+str(mm)+\ | |
"|"+ss+"\n" | |
with open("git/LORIA/calcurse/apts","a") as f: | |
f.write(xx) | |
content.settext("apt saved") | |
if ev.type == tg.Event.click and ev.value["id"] == push: | |
os.system('cd git/LORIA/calcurse; git commit -am "caland"; git push') | |
content.settext("push done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment