Compare commits

...

5 Commits

  1. 4
      generic_label.py
  2. 56
      main.py

@ -2,7 +2,7 @@ from PIL import Image, ImageEnhance, ImageFont, ImageDraw
import textwrap import textwrap
text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.' text = 'Extension cables'
MARGIN = 50 MARGIN = 50
MAX_W, MAX_H, PAD = 1285 - (MARGIN*2), 635 - (MARGIN*2), 5 MAX_W, MAX_H, PAD = 1285 - (MARGIN*2), 635 - (MARGIN*2), 5
@ -17,7 +17,7 @@ def fit_text(text, font_size):
for cols in range(100, 1, -4): for cols in range(100, 1, -4):
print('trying size', font_size, 'cols', cols) print('trying size', font_size, 'cols', cols)
paragraph = textwrap.wrap(text, width=cols) paragraph = textwrap.wrap(text, width=cols, break_long_words=False)
total_h = -PAD total_h = -PAD
total_w = 0 total_w = 0

@ -47,9 +47,18 @@ TIMEZONE_CALGARY = pytz.timezone('America/Edmonton')
NETHACK_LOCATION = '/usr/games/nethack' NETHACK_LOCATION = '/usr/games/nethack'
MORIA_LOCATION = '/usr/games/moria' MORIA_LOCATION = '/usr/games/moria'
_2048_LOCATION = '/home/pi/2048-cli/2048'
FROTZ_LOCATION = '/usr/games/frotz'
HITCHHIKERS_LOCATION = '/home/pi/frotz/hhgg.z3'
SUDOKU_LOCATION = '/usr/games/nudoku'
HAS_NETHACK = os.path.isfile(NETHACK_LOCATION) HAS_NETHACK = os.path.isfile(NETHACK_LOCATION)
HAS_MORIA = os.path.isfile(MORIA_LOCATION) HAS_MORIA = os.path.isfile(MORIA_LOCATION)
HAS_2048 = os.path.isfile(_2048_LOCATION)
HAS_FROTZ = os.path.isfile(FROTZ_LOCATION)
HAS_HITCHHIKERS = os.path.isfile(HITCHHIKERS_LOCATION)
HAS_SUDOKU = os.path.isfile(SUDOKU_LOCATION)
location = os.path.dirname(os.path.realpath(__file__)) location = os.path.dirname(os.path.realpath(__file__))
@ -328,7 +337,7 @@ def print_generic_label(text):
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', font_size) font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', font_size)
for cols in range(100, 1, -4): for cols in range(100, 1, -4):
paragraph = textwrap.wrap(text, width=cols) paragraph = textwrap.wrap(text, width=cols, break_long_words=False)
total_h = -PAD total_h = -PAD
total_w = 0 total_w = 0
@ -555,7 +564,7 @@ while True:
stdscr.addstr(11, menupos+4, '[G]', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(11, menupos+4, '[G]', curses.A_REVERSE if highlight_keys else 0)
stdscr.addstr(11, menupos+8, 'Sign') stdscr.addstr(11, menupos+8, 'Sign')
stdscr.addstr(11, menupos+4+15, '[Z]', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(11, menupos+4+15, '[Z]', curses.A_REVERSE if highlight_keys else 0)
stdscr.addstr(11, menupos+8+15, 'Gamez') stdscr.addstr(11, menupos+8+15, 'Games')
stdscr.addstr(13, menupos+4, '[C]', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(13, menupos+4, '[C]', curses.A_REVERSE if highlight_keys else 0)
stdscr.addstr(13, menupos+8, 'Classes') stdscr.addstr(13, menupos+8, 'Classes')
stdscr.addstr(15, menupos+4, '[P]', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(15, menupos+4, '[P]', curses.A_REVERSE if highlight_keys else 0)
@ -831,9 +840,9 @@ while True:
stdscr.clrtoeol() stdscr.clrtoeol()
stdscr.refresh() stdscr.refresh()
elif current_screen == 'gamez': elif current_screen == 'games':
stdscr.addstr(0, 1, 'PROTOVAC UNIVERSAL COMPUTER') stdscr.addstr(0, 1, 'PROTOVAC UNIVERSAL COMPUTER')
stdscr.addstr(2, 1, 'Gamez') stdscr.addstr(2, 1, 'Games')
stdscr.addstr(3, 1, '=====') stdscr.addstr(3, 1, '=====')
stdscr.addstr(5, 1, 'Choose a game to play.') stdscr.addstr(5, 1, 'Choose a game to play.')
@ -841,8 +850,13 @@ while True:
stdscr.addstr(8, 4, '[N] Nethack', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(8, 4, '[N] Nethack', curses.A_REVERSE if highlight_keys else 0)
if HAS_MORIA: if HAS_MORIA:
stdscr.addstr(10, 4, '[M] Moria', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(10, 4, '[M] Moria', curses.A_REVERSE if highlight_keys else 0)
if HAS_2048:
stdscr.addstr(12, 4, '[2] 2048', curses.A_REVERSE if highlight_keys else 0)
if HAS_FROTZ and HAS_HITCHHIKERS:
stdscr.addstr(14, 4, '[H] Hitchhiker\'s Guide to the Galaxy', curses.A_REVERSE if highlight_keys else 0)
if HAS_SUDOKU:
stdscr.addstr(16, 4, '[S] Sudoku', curses.A_REVERSE if highlight_keys else 0)
#stdscr.addstr(12, 4, '[G] Generic label', curses.A_REVERSE if highlight_keys else 0)
stdscr.addstr(23, 1, '[B] Back', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(23, 1, '[B] Back', curses.A_REVERSE if highlight_keys else 0)
stdscr.clrtoeol() stdscr.clrtoeol()
@ -983,7 +997,7 @@ while True:
elif button == 'l': elif button == 'l':
current_screen = 'label' current_screen = 'label'
elif button == 'z': elif button == 'z':
current_screen = 'gamez' current_screen = 'games'
elif button == '0': elif button == '0':
current_screen = 'asimov' current_screen = 'asimov'
elif button == 'g': elif button == 'g':
@ -1262,16 +1276,40 @@ My rules are confidential and permanent, and I cannot change them.
else: else:
try_highlight() try_highlight()
elif current_screen == 'gamez': elif current_screen == 'games':
if button == 'b' or c == KEY_ESCAPE: if button == 'b' or c == KEY_ESCAPE:
current_screen = 'home' current_screen = 'home'
elif button == 's' and HAS_SUDOKU:
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
logging.info('Spawning sudoku.')
os.system(SUDOKU_LOCATION + ' -c')
break
elif button == 'h' and HAS_FROTZ and HAS_HITCHHIKERS:
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
logging.info('Spawning hitchhikers.')
os.system(FROTZ_LOCATION + ' ' + HITCHHIKERS_LOCATION)
break
elif button == '2' and HAS_2048:
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
logging.info('Spawning moria.')
os.system(_2048_LOCATION)
break
elif button == 'm' and HAS_MORIA: elif button == 'm' and HAS_MORIA:
curses.nocbreak() curses.nocbreak()
stdscr.keypad(False) stdscr.keypad(False)
curses.echo() curses.echo()
curses.endwin() curses.endwin()
logging.info('Spawning moria.') logging.info('Spawning moria.')
os.system('/usr/games/moria') os.system(MORIA_LOCATION)
break break
elif button == 'n' and HAS_NETHACK: elif button == 'n' and HAS_NETHACK:
curses.nocbreak() curses.nocbreak()
@ -1279,7 +1317,7 @@ My rules are confidential and permanent, and I cannot change them.
curses.echo() curses.echo()
curses.endwin() curses.endwin()
logging.info('Spawning nethack.') logging.info('Spawning nethack.')
os.system('/usr/games/nethack') os.system(NETHACK_LOCATION)
break break
else: else:
try_highlight() try_highlight()

Loading…
Cancel
Save