diff --git a/examples/frotz.prez b/examples/frotz.prez new file mode 100644 index 0000000..a437be9 --- /dev/null +++ b/examples/frotz.prez @@ -0,0 +1,86 @@ + +rComment(""" +FROTZ V2.55 +An interpreter for all Infocom and other Z-Machine games. +Complies with the Z-Machine Standard version 1.1. + +Originally written by Stefan Jokisch in 1995-1997. +Ported to Unix by Galen Hazelwood. +Reference code Unix and DOS ports are maintained by David Griffith. +IIgs .console port by Kelvin Sherlock. + +Frotz is free software; you can redistribute it and/or modify it \ +under the terms of the GNU General Public License as published by \ +the Free Software Foundation; either version 2 of the License, or \ +(at your option) any later version. +""") + + +rVersion( '0.0.0a2', verUS, "Frotz 2.55", "Kelvin Sherlock\nDavid Griffith, et alia") + +rToolStartup( + mode640 | fFastPortAware | fUseShadowing, + 3, (4, 0x0308), 5, 6, 11, 14, 15, 16, 18, 20, 21, 22, 23, 27, 28, 30, + export="kStartStop" +) + +rMenuBar( + rMenu("@", + rMenuItem("About Frotz…", export="kAboutMenuItem"), + rMenuItem("Preferences…", ",", export="kPreferencesMenuItem"), + DividerMenuItem(), + export="kAppleMenu" + ), + rMenu(" File ", + # rMenuItem("New ", "Nn", export="kNewMenuItem"), + rMenuItem("Open…", "Oo", export="kOpenMenuItem"), + rMenuItem("Restart", "Rr", export="kRestartMenuItem"), + # rMenuItem("Save", "Ss", disabled=True, export="kSaveMenuItem"), + # DividerMenuItem(), + # rMenuItem("Close", "Ww", id=0xff, export="kCloseMenuItem"), + DividerMenuItem(), + rMenuItem("Quit", "Qq", export="kQuitMenuItem"), + export = "kFileMenu" + ), + rMenu(" Edit ", + UndoMenuItem(), # shortcut for doing it manually, + DividerMenuItem(), + CutMenuItem(), + CopyMenuItem(), + PasteMenuItem(), + ClearMenuItem(), + export = "kEditMenu" + ), + export = "kMenuBar" +) + +AboutRect = rect(x = 0, y = 0, height = 100, width = 400) + +rWindParam1( + + AboutRect.center(), None, + + rStatTextControl( + + AboutRect, + + rTextForLETextBox2( + TBCenterJust, + TBFont, TBVenice, b"\x00", b"\x18", # Venice 24-point + "Frotz", + TBFont, TBMonaco, b"\x00", b"\x09", # monaco, 9-point + "\nv 2.55\n", + "Stefan Jokisch, Galen Hazel, David Griffith, et alia\n", + "IIgs version by Kelvin Sherlock (alpha 2)" + ) + + ), + + frameBits = fVis, + export = "kAboutWindow" +) + + + + + diff --git a/test.prez b/examples/test.prez similarity index 100% rename from test.prez rename to examples/test.prez diff --git a/prez.py b/prez.py new file mode 100644 index 0000000..8adddec --- /dev/null +++ b/prez.py @@ -0,0 +1,5 @@ +# this exists so we can "python3 prez.py" while developing. + +if __name__ == '__main__': + from prez.cli import main + main() diff --git a/prez/__init__.py b/prez/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/base.py b/prez/base.py similarity index 98% rename from base.py rename to prez/base.py index 6d1ce60..22bb1fc 100644 --- a/base.py +++ b/prez/base.py @@ -1,12 +1,11 @@ import struct -from bisect import bisect_left -from rect import * -from utils import * import sys +from bisect import bisect_left -from resource_writer import ResourceWriter - -from constants import * +from . rect import * +from . utils import * +from . resource_writer import ResourceWriter +from . constants import * __all__ = ["rObject", "rText", "rTextBlock", "rTextForLETextBox2", "rAlertString", "rErrorString", "rComment", "rPString", diff --git a/cli.py b/prez/cli.py similarity index 63% rename from cli.py rename to prez/cli.py index b4207b6..254e40d 100644 --- a/cli.py +++ b/prez/cli.py @@ -3,10 +3,12 @@ import sys import io import argparse import time -from open_rfork import open_rfork import traceback +import importlib + +from . open_rfork import open_rfork +from . base import rObject -from base import rObject # from base import * # from window import * @@ -19,20 +21,21 @@ from base import rObject def rez_scope(): # import all the resource types and constants into # a dictionary to be the exec() local scope - import base - import window - import control - import menu - import sound - import rect - import version - import tool_startup - import icon - import constants + # import prez.base + # import prez.window + # import prez.control + # import prez.menu + # import prez.sound + # import prez.rect + # import prez.version + # import prez.tool_startup + # import prez.icon + # import prez.constants # could do: mod = importlib.import_module("base"), etc. scope = {} - for mod in (base, window, control, menu, sound, rect, version, tool_startup, icon, constants): + for m in ('base', 'window', 'control', 'menu', 'sound', 'rect', 'version', 'tool_startup', 'icon', 'constants'): + mod = importlib.import_module('.' + m, 'prez') if hasattr(mod, '__all__'): keys = mod.__all__ else: keys = [x for x in dir(mod) if x[0] != '_'] @@ -56,20 +59,20 @@ def execute(filename, scope): print(traceback.format_exc()) return False -if __name__ == '__main__': +def main(): + p = argparse.ArgumentParser(prog='prez') p.add_argument('files', metavar='file', type=str, nargs='+') p.add_argument('--rez', action='store_true', help="Generate REZ code") - p.add_argument('-x', action="store_true", help="Generate REZ data") + p.add_argument('--hex', action="store_true", help="Generate REZ data") p.add_argument('-D', type=str, nargs='+', help='define a variable') - p.add_argument('--df', action="store_true", help="Write to a regular file") + p.add_argument('--data-fork', action="store_true", help="Write to a regular file") p.add_argument('-o', metavar='file', type=str, help="Specify output file") opts = p.parse_args() - - df = opts.df or not sys.platform in ("win32", "darwin") + opts.data_fork = opts.data_fork or not sys.platform in ("win32", "darwin") scope = rez_scope() @@ -81,19 +84,20 @@ if __name__ == '__main__': if errors > 0 : sys.exit(1) if not opts.o: opts.rez = True - if opts.x: opts.rez = True - if df or opts.rez: - open_rfork = io.open - - if opts.rez: + if opts.rez or opts.hex: print("/* Generated on {} */".format(time.ctime())) print('#include "types.rez"\n') - if opts.x: rObject.dump_hex() + if opts.hex: rObject.dump_hex() else: rObject.dump_rez() else: - with open_rfork(opts.o, "wb") as io: - rObject.save_resources(io) + opener = open_rfork + if opts.data_fork: opener = io.open + with opener(opts.o, "wb") as f: + rObject.save_resources(f) rObject.dump_exports() sys.exit(0) + +if __name__ == '__main__': + main() diff --git a/colors.py b/prez/colors.py similarity index 100% rename from colors.py rename to prez/colors.py diff --git a/constants.py b/prez/constants.py similarity index 100% rename from constants.py rename to prez/constants.py diff --git a/control.py b/prez/control.py similarity index 99% rename from control.py rename to prez/control.py index 0c939f2..8ecc35d 100644 --- a/control.py +++ b/prez/control.py @@ -1,8 +1,9 @@ -from base import rObject, rList, rPString, rTextForLETextBox2 import struct -from rect import * -from colors import * -from utils import * + +from . base import rObject, rList, rPString, rTextForLETextBox2 +from . rect import * +from . colors import * +from . utils import * __all__ = [ diff --git a/icon.py b/prez/icon.py similarity index 98% rename from icon.py rename to prez/icon.py index 66e0817..13cf0fd 100644 --- a/icon.py +++ b/prez/icon.py @@ -1,6 +1,7 @@ -from base import rObject import struct +from . base import rObject + __all__ = ["rIcon"] diff --git a/key_equivalent.py b/prez/key_equivalent.py similarity index 98% rename from key_equivalent.py rename to prez/key_equivalent.py index 102429f..21d7730 100644 --- a/key_equivalent.py +++ b/prez/key_equivalent.py @@ -1,8 +1,9 @@ # key equivalants import enum -from utils import * import struct +from . utils import * + __all__ = ["KeyEquivalent"] def export_enum(cls): diff --git a/menu.py b/prez/menu.py similarity index 99% rename from menu.py rename to prez/menu.py index f8350b5..a41c16e 100644 --- a/menu.py +++ b/prez/menu.py @@ -1,10 +1,11 @@ - -from base import * -from utils import * -from icon import rIcon import struct import enum +from . base import * +from . utils import * +from . icon import rIcon + + __all__ = [ 'rMenuBar', 'rMenu', diff --git a/open_rfork.py b/prez/open_rfork.py similarity index 100% rename from open_rfork.py rename to prez/open_rfork.py diff --git a/rect.py b/prez/rect.py similarity index 95% rename from rect.py rename to prez/rect.py index 36e17ac..f59b0be 100644 --- a/rect.py +++ b/prez/rect.py @@ -104,7 +104,7 @@ class size_class: self.width = 0 if len(args) == 2: - self.height, self.width = args + self._assign(*args) return if len(args) == 1: @@ -115,7 +115,7 @@ class size_class: return if is_listy(other) and len(other) == 2: - self.height, self.width = other + self._assign(*other) return if not args: @@ -126,9 +126,22 @@ class size_class: raise ValueError("bad size parameter") + def _assign(self, height, width): + self.height = height + self.width = width + def __eq__(self, other): return type(other) == size_class and self.height == other.height and self.width == other.width + def __str__(self): + return "{{ {:d}, {:d} }}".format(self.height, self.width) + + def __bytes__(self): + return struct.pack("2H", self.height, self.width) + + def __iter__(self): + return (self.height, self.width).__iter__() + def old_size(*args, height=None, width=None): diff --git a/resource_writer.py b/prez/resource_writer.py similarity index 100% rename from resource_writer.py rename to prez/resource_writer.py diff --git a/rezpy.py b/prez/rezpy.py similarity index 100% rename from rezpy.py rename to prez/rezpy.py diff --git a/sound.py b/prez/sound.py similarity index 99% rename from sound.py rename to prez/sound.py index d50d335..d7c43ec 100644 --- a/sound.py +++ b/prez/sound.py @@ -1,5 +1,3 @@ - -from base import rObject import audioop import struct import re @@ -7,6 +5,8 @@ import sys import os from math import log2 +from . base import rObject + __all__ = ["rSoundSample"] # See: IIgs TechNote #76 Miscellaneous Resource Formats diff --git a/tool_startup.py b/prez/tool_startup.py similarity index 97% rename from tool_startup.py rename to prez/tool_startup.py index a75a3b0..812f05e 100644 --- a/tool_startup.py +++ b/prez/tool_startup.py @@ -1,9 +1,10 @@ - -from base import rObject -from utils import * import enum import struct +from . base import rObject +from . utils import * + + __all__ = ["rToolStartup"] # can't be in utils since that's a different __all__ diff --git a/utils.py b/prez/utils.py similarity index 100% rename from utils.py rename to prez/utils.py diff --git a/version.py b/prez/version.py similarity index 98% rename from version.py rename to prez/version.py index 73dd583..9b9818a 100644 --- a/version.py +++ b/prez/version.py @@ -1,10 +1,10 @@ - -from base import rObject -from utils import * import enum import struct import re +from . base import rObject +from . utils import * + __all__ = ["rVersion"] diff --git a/window.py b/prez/window.py similarity index 97% rename from window.py rename to prez/window.py index eed9a37..6e84701 100644 --- a/window.py +++ b/prez/window.py @@ -1,13 +1,12 @@ -from base import * -from control import rControlTemplate, rControlList -from utils import * - import struct +from . base import * +from . control import rControlTemplate, rControlList +from . utils import * + + __all__ = ['rWindParam1'] - - fHilited = 0x0001 fZoomed = 0x0002 fAllocated = 0x0004 @@ -37,7 +36,6 @@ class rWindParam1(rObject): rType = 0x800e def __init__(self, position, title=None, *controls, - frameBits = 0, refCon = 0, zoomRect = (0, 0, 0, 0), diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2ae15ac --- /dev/null +++ b/setup.py @@ -0,0 +1,11 @@ +from setuptools import setup + +setup( + name = 'prez', + packages = ['prez'], + author = 'Kelvin Sherlock', + entry_points = { + 'console_scripts': ['prez=prez.cli:main'] + + }, +) \ No newline at end of file