futurize stage1 vui

This commit is contained in:
Simon Forman 2020-04-23 23:22:45 -07:00
parent 89b4eb5e15
commit 00db0fd0ad
9 changed files with 2662 additions and 2653 deletions

View File

@ -28,6 +28,7 @@ passing, a "world" class that holds the main context for the system, and
a mainloop class that manages the, uh, main loop (the PyGame event queue.) a mainloop class that manages the, uh, main loop (the PyGame event queue.)
''' '''
from __future__ import print_function
from sys import stderr from sys import stderr
from traceback import format_exc from traceback import format_exc
import pygame import pygame
@ -172,7 +173,7 @@ class World(object):
try: try:
return stack_to_string(self.stack_holder[0]) return stack_to_string(self.stack_holder[0])
except: except:
print >> stderr, format_exc() print(format_exc(), file=stderr)
return str(self.stack_holder[0]) return str(self.stack_holder[0])
@ -250,8 +251,8 @@ class TheLoop(object):
except: except:
traceback = format_exc() traceback = format_exc()
self.remove_task(task_event_id) self.remove_task(task_event_id)
print >> stderr, traceback print(traceback, file=stderr)
print >> stderr, 'TASK removed due to ERROR', task print('TASK removed due to ERROR', task, file=stderr)
open_viewer_on_string(self, traceback, self.display.broadcast) open_viewer_on_string(self, traceback, self.display.broadcast)
def loop(self): def loop(self):

View File

@ -1,3 +1,4 @@
from __future__ import absolute_import
import sys, traceback import sys, traceback
# To enable "hot" reloading in the IDLE shell. # To enable "hot" reloading in the IDLE shell.
@ -7,7 +8,7 @@ for name in 'core main display viewer text_viewer stack_viewer persist_task'.spl
except KeyError: except KeyError:
pass pass
import main from . import main
try: try:
A = A # (screen, clock, pt), three things that we DON'T want to recreate A = A # (screen, clock, pt), three things that we DON'T want to recreate

View File

@ -29,6 +29,7 @@ Refer to Chapter 4 of the Project Oberon book for more information.
There is a Display object that manages a pygame surface and N vertical There is a Display object that manages a pygame surface and N vertical
tracks each of which manages zero or more viewers. tracks each of which manages zero or more viewers.
''' '''
from __future__ import print_function
from copy import copy from copy import copy
from sys import stderr from sys import stderr
from traceback import format_exc from traceback import format_exc
@ -283,14 +284,14 @@ class Display(object):
elif event.type in MOUSE_EVENTS: elif event.type in MOUSE_EVENTS:
self._mouse_event(event) self._mouse_event(event)
else: else:
print >> stderr, ( print((
'received event %s Use pygame.event.set_allowed().' 'received event %s Use pygame.event.set_allowed().'
% pygame.event.event_name(event.type) % pygame.event.event_name(event.type)
) ), file=stderr)
# Catch all exceptions and open a viewer. # Catch all exceptions and open a viewer.
except: except:
err = format_exc() err = format_exc()
print >> stderr, err # To be safe just print it right away. print(err, file=stderr) # To be safe just print it right away.
open_viewer_on_string(self, err, self.broadcast) open_viewer_on_string(self, err, self.broadcast)
def _keyboard_event(self, event): def _keyboard_event(self, event):

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Thun. If not see <http://www.gnu.org/licenses/>. # along with Thun. If not see <http://www.gnu.org/licenses/>.
# #
from __future__ import print_function
from StringIO import StringIO from StringIO import StringIO
import base64, zlib import base64, zlib
@ -183,4 +184,4 @@ lnalXc/9SsNb2vUirzS8pV0v8gJv/w/2vRht''')))
if __name__ == '__main__': if __name__ == '__main__':
print create() print(create())

View File

@ -28,6 +28,7 @@ file, so you can just do, e.g.:
init_joy_home.initialize(JOY_HOME) init_joy_home.initialize(JOY_HOME)
''' '''
from __future__ import print_function
import base64, os, StringIO, zipfile import base64, os, StringIO, zipfile
@ -272,4 +273,4 @@ c3RhY2sucGlja2xlUEsFBgAAAAAGAAYAUwEAACcwAAAAAA==''')))
if __name__ == '__main__': if __name__ == '__main__':
print create_data() print(create_data())

View File

@ -25,6 +25,7 @@ Main Module
Pulls everything together. Pulls everything together.
''' '''
from __future__ import print_function
import os, sys, traceback import os, sys, traceback
import pygame import pygame
from joy.library import initialize, DefinitionWrapper, SimpleFunctionWrapper from joy.library import initialize, DefinitionWrapper, SimpleFunctionWrapper
@ -67,9 +68,9 @@ def init():
* Create the PersistTask * Create the PersistTask
''' '''
print 'Initializing Pygame...' print('Initializing Pygame...')
pygame.init() pygame.init()
print 'Creating window...' print('Creating window...')
if FULLSCREEN: if FULLSCREEN:
screen = pygame.display.set_mode() screen = pygame.display.set_mode()
else: else:
@ -159,7 +160,7 @@ def main(screen, clock, pt):
def evaluate(stack): def evaluate(stack):
'''Evaluate the Python code text on the top of the stack.''' '''Evaluate the Python code text on the top of the stack.'''
code, stack = stack code, stack = stack
exec code in name_space.copy() exec(code, name_space.copy())
return stack return stack
name_space['D']['evaluate'] = evaluate name_space['D']['evaluate'] = evaluate

View File

@ -26,6 +26,7 @@ This module deals with persisting the "resources" (text files and the
stack) to the git repo in the ``JOY_HOME`` directory. stack) to the git repo in the ``JOY_HOME`` directory.
''' '''
from __future__ import print_function
import os, pickle, traceback import os, pickle, traceback
from collections import Counter from collections import Counter
from dulwich.errors import NotGitRepository from dulwich.errors import NotGitRepository
@ -42,7 +43,7 @@ def open_repo(repo_dir=None, initialize=False):
exception is raised, otherwise ``git init`` is effected in the dir. exception is raised, otherwise ``git init`` is effected in the dir.
''' '''
if not os.path.exists(repo_dir): if not os.path.exists(repo_dir):
os.makedirs(repo_dir, 0700) os.makedirs(repo_dir, 0o700)
return init_repo(repo_dir) return init_repo(repo_dir)
try: try:
return Repo(repo_dir) return Repo(repo_dir)
@ -95,14 +96,14 @@ class Resource(object):
def _to_file(self, f): def _to_file(self, f):
for line in self.thing: for line in self.thing:
print >> f, line print(line, file=f)
def persist(self, repo): def persist(self, repo):
''' '''
Save the lines to the file and stage the file in the repo. Save the lines to the file and stage the file in the repo.
''' '''
with open(self.filename, 'w') as f: with open(self.filename, 'w') as f:
os.chmod(self.filename, 0600) os.chmod(self.filename, 0o600)
self._to_file(f) self._to_file(f)
f.flush() f.flush()
os.fsync(f.fileno()) os.fsync(f.fileno())
@ -266,7 +267,7 @@ if __name__ == '__main__':
pt = PersistTask(JOY_HOME) pt = PersistTask(JOY_HOME)
content_id, thing = pt.open('stack.pickle') content_id, thing = pt.open('stack.pickle')
pt.persist(content_id) pt.persist(content_id)
print pt.counter print(pt.counter)
mm = core.ModifyMessage(None, None, content_id=content_id) mm = core.ModifyMessage(None, None, content_id=content_id)
pt.handle(mm) pt.handle(mm)
print pt.counter print(pt.counter)

View File

@ -23,6 +23,7 @@ Text Viewer
================= =================
''' '''
from __future__ import print_function
import string import string
import pygame import pygame
from joy.utils.stack import expression_to_string from joy.utils.stack import expression_to_string
@ -415,7 +416,7 @@ class TextViewer(MenuViewer):
self._printable_key(uch, mod, line, i) self._printable_key(uch, mod, line, i)
modified = True modified = True
else: else:
print '%r %i %s' % (uch, key, bin(mod)) print('%r %i %s' % (uch, key, bin(mod)))
if modified: if modified:
# The selection is fragile. # The selection is fragile.

View File

@ -23,6 +23,7 @@ Viewer
================= =================
''' '''
from __future__ import print_function
import pygame import pygame
from joy.vui.core import BACKGROUND, FOREGROUND from joy.vui.core import BACKGROUND, FOREGROUND
@ -227,7 +228,7 @@ class SomeViewer(MenuViewer):
def key_down(self, display, uch, key, mod): def key_down(self, display, uch, key, mod):
try: try:
print chr(key), print(chr(key), end=' ')
except ValueError: except ValueError:
pass pass