Ditch unicurses, go back to curses
This commit is contained in:
parent
1328629617
commit
0348e715cb
114
.gitignore
vendored
Normal file
114
.gitignore
vendored
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
*.ipynb
|
||||||
|
.pytype
|
||||||
|
.DS_Store
|
||||||
|
.vscode
|
||||||
|
mypy_report
|
||||||
|
docs/build
|
||||||
|
docs/source/_build
|
||||||
|
tools/*.txt
|
||||||
|
playground/
|
||||||
|
|
||||||
|
# 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/
|
||||||
|
*.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/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
|
# celery beat schedule file
|
||||||
|
celerybeat-schedule
|
||||||
|
|
||||||
|
# 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/
|
142
main.py
142
main.py
|
@ -1,13 +1,13 @@
|
||||||
#!/home/pi/protovac/env/bin/python
|
#!/home/tanner/protovac/env/bin/python
|
||||||
|
|
||||||
from unicurses import *
|
import curses
|
||||||
from curses.textpad import Textbox, rectangle
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
ENTER_KEY = 10
|
ENTER_KEY = 10
|
||||||
BACKSPACE_KEY = 263
|
BACKSPACE_KEY = 263
|
||||||
ESCAPE_KEY = 27
|
ESCAPE_KEY = 27
|
||||||
|
|
||||||
|
|
||||||
def sign_send(to_send):
|
def sign_send(to_send):
|
||||||
try:
|
try:
|
||||||
data = dict(sign=to_send, on_behalf_of='protovac')
|
data = dict(sign=to_send, on_behalf_of='protovac')
|
||||||
|
@ -27,9 +27,8 @@ def fetch_stats():
|
||||||
|
|
||||||
skip_input = False
|
skip_input = False
|
||||||
current_screen = 'home'
|
current_screen = 'home'
|
||||||
|
prev_screen = current_screen
|
||||||
|
|
||||||
highlight = 1
|
|
||||||
choice = 0
|
|
||||||
c = 0
|
c = 0
|
||||||
|
|
||||||
# highlighting:
|
# highlighting:
|
||||||
|
@ -37,95 +36,101 @@ c = 0
|
||||||
#mvwaddstr(menu_win, y, x, choices[i])
|
#mvwaddstr(menu_win, y, x, choices[i])
|
||||||
#wattroff(menu_win, A_REVERSE)
|
#wattroff(menu_win, A_REVERSE)
|
||||||
|
|
||||||
stdscr = initscr()
|
stdscr = curses.initscr()
|
||||||
clear()
|
curses.noecho()
|
||||||
noecho()
|
curses.cbreak()
|
||||||
cbreak()
|
stdscr.keypad(True)
|
||||||
curs_set(0)
|
curses.curs_set(0)
|
||||||
|
|
||||||
keypad(stdscr, True)
|
|
||||||
|
|
||||||
sign_to_send = ''
|
sign_to_send = ''
|
||||||
stats = {}
|
stats = {}
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if current_screen == 'home':
|
if current_screen == 'home':
|
||||||
mvaddstr(1, 1, 'PROTOVAC - can you smell the phosphorus?')
|
stdscr.addstr(1, 1, ' _______ _______ ___ _________ ___ ____ ____ _ ______ ')
|
||||||
mvaddstr(4, 4, '[T] Stats')
|
stdscr.addstr(2, 1, '|_ __ \|_ __ \ .\' `. | _ _ | .\' `.|_ _| |_ _|/ \ .\' ___ |')
|
||||||
mvaddstr(6, 4, '[S] Sign')
|
stdscr.addstr(3, 1, ' | |__) | | |__) | / .-. \|_/ | | \_|/ .-. \ \ \ / / / _ \ / .\' \_|')
|
||||||
#mvaddstr(8, 4, '[C] Classes')
|
stdscr.addstr(4, 1, ' | ___/ | __ / | | | | | | | | | | \ \ / / / ___ \ | | ')
|
||||||
#mvaddstr(10, 4, '[F] Forum')
|
stdscr.addstr(5, 1, ' _| |_ _| | \ \_\ `-\' / _| |_ \ `-\' / \ \' /_/ / \ \_\ `.___.\'\\')
|
||||||
|
stdscr.addstr(6, 1, '|_____| |____| |___|`.___.\' |_____| `.___.\' \_/|____| |____|`.____ .\'')
|
||||||
|
|
||||||
mvaddstr(23, 1, '')
|
stdscr.addstr(9, 4, '[T] Stats')
|
||||||
clrtoeol()
|
stdscr.addstr(11, 4, '[S] Sign')
|
||||||
refresh()
|
#stdscr.addstr(8, 4, '[C] Classes')
|
||||||
|
#stdscr.addstr(10, 4, '[F] Forum')
|
||||||
|
|
||||||
|
stdscr.addstr(23, 1, ' Copyright (c) 1985 Bikeshed Computer Systems Corp.')
|
||||||
|
stdscr.clrtoeol()
|
||||||
|
stdscr.refresh()
|
||||||
elif current_screen == 'debug':
|
elif current_screen == 'debug':
|
||||||
mvaddstr(1, 1, 'PROTOVAC')
|
stdscr.addstr(1, 1, 'PROTOVAC')
|
||||||
mvaddstr(3, 1, 'Debug Mode')
|
stdscr.addstr(3, 1, 'Debug Mode')
|
||||||
mvaddstr(4, 1, '==========')
|
stdscr.addstr(4, 1, '==========')
|
||||||
mvaddstr(6, 1, str.format('Character pressed = {0}', c))
|
stdscr.addstr(6, 1, str.format('Character pressed = {0}', c))
|
||||||
clrtoeol()
|
stdscr.clrtoeol()
|
||||||
|
|
||||||
mvaddstr(23, 1, '[B] Back')
|
stdscr.addstr(23, 1, '[B] Back')
|
||||||
clrtoeol()
|
stdscr.clrtoeol()
|
||||||
refresh()
|
stdscr.refresh()
|
||||||
elif current_screen == 'stats':
|
elif current_screen == 'stats':
|
||||||
mvaddstr(1, 1, 'PROTOVAC')
|
stdscr.addstr(1, 1, 'PROTOVAC')
|
||||||
mvaddstr(3, 1, 'Protospace Stats')
|
stdscr.addstr(3, 1, 'Protospace Stats')
|
||||||
mvaddstr(4, 1, '================')
|
stdscr.addstr(4, 1, '================')
|
||||||
if stats:
|
if stats:
|
||||||
mvaddstr(6 , 1, 'Next meeting: {}'.format(stats['next_meeting']))
|
stdscr.addstr(6 , 1, 'Next meeting: {}'.format(stats['next_meeting']))
|
||||||
mvaddstr(8 , 1, 'Next clean: {}'.format(stats['next_clean']))
|
stdscr.addstr(8 , 1, 'Next clean: {}'.format(stats['next_clean']))
|
||||||
mvaddstr(10, 1, 'Next class: {}'.format(stats['next_class']['datetime']))
|
stdscr.addstr(10, 1, 'Next class: {}'.format(stats['next_class']['datetime']))
|
||||||
mvaddstr(11, 1, ' {}'.format(stats['next_class']['name']))
|
stdscr.addstr(11, 1, ' {}'.format(stats['next_class']['name']))
|
||||||
mvaddstr(13, 1, 'Last class: {}'.format(stats['prev_class']['datetime']))
|
stdscr.addstr(13, 1, 'Last class: {}'.format(stats['prev_class']['datetime']))
|
||||||
mvaddstr(14, 1, ' {}'.format(stats['prev_class']['name']))
|
stdscr.addstr(14, 1, ' {}'.format(stats['prev_class']['name']))
|
||||||
|
|
||||||
mvaddstr(16, 1, 'Member count: {} Green: {} Paused / expired: {}'.format(
|
stdscr.addstr(16, 1, 'Member count: {} Green: {} Paused / expired: {}'.format(
|
||||||
stats['member_count'],
|
stats['member_count'],
|
||||||
stats['green_count'],
|
stats['green_count'],
|
||||||
stats['paused_count'],
|
stats['paused_count'],
|
||||||
))
|
))
|
||||||
mvaddstr(18, 1, 'Card scans: {}'.format(stats['card_scans']))
|
stdscr.addstr(18, 1, 'Card scans: {}'.format(stats['card_scans']))
|
||||||
else:
|
else:
|
||||||
mvaddstr(6, 1, 'Loading...')
|
stdscr.addstr(6, 1, 'Loading...')
|
||||||
|
|
||||||
mvaddstr(23, 1, '[B] Back')
|
stdscr.addstr(23, 1, '[B] Back')
|
||||||
clrtoeol()
|
stdscr.clrtoeol()
|
||||||
refresh()
|
stdscr.refresh()
|
||||||
|
|
||||||
if not stats:
|
if not stats:
|
||||||
stats = fetch_stats()
|
stats = fetch_stats()
|
||||||
skip_input = True
|
skip_input = True
|
||||||
elif current_screen == 'sign':
|
elif current_screen == 'sign':
|
||||||
mvaddstr(1, 1, 'PROTOVAC')
|
stdscr.addstr(1, 1, 'PROTOVAC')
|
||||||
mvaddstr(3, 1, 'Protospace Sign')
|
stdscr.addstr(3, 1, 'Protospace Sign')
|
||||||
mvaddstr(4, 1, '===============')
|
stdscr.addstr(4, 1, '===============')
|
||||||
mvaddstr(6, 1, 'Send a message to the sign in the welcome room and classroom.')
|
stdscr.addstr(6, 1, 'Send a message to the sign in the welcome room and classroom.')
|
||||||
|
stdscr.addstr(7, 1, 'After sending, turn your head right and wait.')
|
||||||
|
|
||||||
if sign_to_send:
|
if sign_to_send:
|
||||||
mvaddstr(8, 4, sign_to_send)
|
stdscr.addstr(9, 4, sign_to_send)
|
||||||
mvaddstr(23, 1, '[ENTER] Send [ESC] Cancel')
|
stdscr.clrtoeol()
|
||||||
|
stdscr.addstr(23, 1, '[ENTER] Send [ESC] Cancel')
|
||||||
else:
|
else:
|
||||||
mvaddstr(8, 4, '[E] Edit message')
|
stdscr.addstr(9, 4, '[E] Edit message')
|
||||||
mvaddstr(23, 1, '[B] Back')
|
stdscr.addstr(23, 1, '[B] Back')
|
||||||
|
|
||||||
clrtoeol()
|
stdscr.clrtoeol()
|
||||||
refresh()
|
stdscr.refresh()
|
||||||
|
|
||||||
|
stdscr.move(23, 79)
|
||||||
|
|
||||||
if skip_input:
|
if skip_input:
|
||||||
skip_input = False
|
skip_input = False
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
c = wgetch(stdscr)
|
c = stdscr.getch()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
refresh()
|
|
||||||
endwin()
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if c == KEY_UP:
|
if c == curses.KEY_UP:
|
||||||
pass
|
pass
|
||||||
elif c == KEY_DOWN:
|
elif c == curses.KEY_DOWN:
|
||||||
pass
|
pass
|
||||||
elif c == 10: # ENTER is pressed
|
elif c == 10: # ENTER is pressed
|
||||||
pass
|
pass
|
||||||
|
@ -135,18 +140,14 @@ while True:
|
||||||
if current_screen == 'home':
|
if current_screen == 'home':
|
||||||
if button == 't':
|
if button == 't':
|
||||||
current_screen = 'stats'
|
current_screen = 'stats'
|
||||||
clear()
|
|
||||||
elif button == 's':
|
elif button == 's':
|
||||||
current_screen = 'sign'
|
current_screen = 'sign'
|
||||||
clear()
|
|
||||||
elif button == 'd':
|
elif button == 'd':
|
||||||
current_screen = 'debug'
|
current_screen = 'debug'
|
||||||
clear()
|
|
||||||
elif current_screen == 'stats':
|
elif current_screen == 'stats':
|
||||||
if button == 'b':
|
if button == 'b':
|
||||||
current_screen = 'home'
|
current_screen = 'home'
|
||||||
stats = {}
|
stats = {}
|
||||||
clear()
|
|
||||||
elif current_screen == 'sign':
|
elif current_screen == 'sign':
|
||||||
if sign_to_send:
|
if sign_to_send:
|
||||||
if c == BACKSPACE_KEY:
|
if c == BACKSPACE_KEY:
|
||||||
|
@ -155,18 +156,25 @@ while True:
|
||||||
sign_to_send = ''
|
sign_to_send = ''
|
||||||
elif c == ENTER_KEY:
|
elif c == ENTER_KEY:
|
||||||
if len(sign_to_send) > 1:
|
if len(sign_to_send) > 1:
|
||||||
mvaddstr(10, 4, 'Sending...')
|
stdscr.addstr(15, 4, 'Sending...')
|
||||||
refresh()
|
stdscr.refresh()
|
||||||
sign_send(sign_to_send[:-1])
|
sign_send(sign_to_send[:-1])
|
||||||
|
stdscr.erase()
|
||||||
sign_to_send = ''
|
sign_to_send = ''
|
||||||
else:
|
else:
|
||||||
if c < 127 and c > 31:
|
if c < 127 and c > 31:
|
||||||
sign_to_send = sign_to_send[:-1] + chr(c) + '_'
|
sign_to_send = sign_to_send[:-1] + chr(c) + '_'
|
||||||
clear()
|
|
||||||
elif button == 'b':
|
elif button == 'b':
|
||||||
current_screen = 'home'
|
current_screen = 'home'
|
||||||
clear()
|
|
||||||
elif button == 'e':
|
elif button == 'e':
|
||||||
sign_to_send = '_'
|
sign_to_send = '_'
|
||||||
clear()
|
|
||||||
|
|
||||||
|
if current_screen != prev_screen:
|
||||||
|
prev_screen = current_screen
|
||||||
|
stdscr.erase()
|
||||||
|
|
||||||
|
|
||||||
|
curses.nocbreak()
|
||||||
|
stdscr.keypad(False)
|
||||||
|
curses.echo()
|
||||||
|
curses.endwin()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user