diff --git a/pymlac/pymlac b/pymlac/pymlac index 2f8632c..d357e3a 100755 --- a/pymlac/pymlac +++ b/pymlac/pymlac @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python """ The Python Imlac emulator (pymlac). @@ -8,7 +8,7 @@ Console-only version import sys import os -import wx +import wx from Globals import * import Imlac @@ -35,7 +35,7 @@ def abort(msg): def check_int(value, msg): """Check that a value is a valid 16 bit positive value. - + We allow decimal and octal number representations. """ @@ -216,7 +216,7 @@ def usage(): def main(): - """Start of the Imlac emulator.""" + """Start of the emulator.""" # get operations list ops = handle_options() @@ -302,7 +302,7 @@ class Led_1(object): self.led.Enable() else: self.led.Disable() - + class Led_16(object): def __init__(self, parent, label, x, y, off, on): @@ -334,9 +334,9 @@ class Led_16(object): else: l.Disable() mask = mask >> 1 - -class MyFrame(wx.Frame): + +class PymlacFrame(wx.Frame): """a frame with two panels""" WIDTH_SCREEN = 1024 @@ -358,8 +358,8 @@ class MyFrame(wx.Frame): INC = 0.01 - def __init__(self, parent=None, id=-1, title=None): - wx.Frame.__init__(self, parent, id, title) + def __init__(self, parent=None, id=-1, title=None): + wx.Frame.__init__(self, parent, id, title) self.make_gui() self.run() @@ -367,11 +367,11 @@ class MyFrame(wx.Frame): def make_gui(self): self.screen = wx.Panel(self, size=(self.WIDTH_SCREEN, self.HEIGHT_SCREEN), - pos=(0,0)) + pos=(0,0)) self.screen.SetBackgroundColour(self.SCREEN_COLOUR) self.console = wx.Panel(self, style=wx.SIMPLE_BORDER, size=(self.WIDTH_CONSOLE, self.HEIGHT_SCREEN), - pos=(self.WIDTH_SCREEN,0)) + pos=(self.WIDTH_SCREEN,0)) self.console.SetBackgroundColour(self.CONSOLE_COLOUR) python_png = wx.Image('images/PythonPowered.png', @@ -454,16 +454,16 @@ class MyFrame(wx.Frame): self.y_offset = 0 self.y_sign = +1 - self.Fit() + self.Fit() def run(self): # get operations list ops = handle_options() - + # Initialize the emulator. boot_rom = 'ptr' # default ROM loader Imlac.init(0, TRACE_FILENAME, None, None, boot_rom, CORE_FILENAME) - + # now perform operations for (operation, args) in ops: if operation == 'boot': @@ -539,7 +539,7 @@ class MyFrame(wx.Frame): self.on_paint() else: abort('Invalid internal operation: %s' % operation) - + Imlac.close(CORE_FILENAME) @@ -593,248 +593,7 @@ class MyFrame(wx.Frame): pass -# test it ... -app = wx.PySimpleApp() -frame1 = MyFrame(title='pymlac 0.1') -frame1.Center() -frame1.Show() -app.MainLoop() - -sys.exit(0) - - -#import profile -#profile.run('main()', 'profile.out') - -main() - - - - - - -sys.exit(0) - - -count = 1 - -class Led_1(object): - def __init__(self, parent, label, x, y, off, on): - wx.StaticText(parent, -1, label, pos=(x, y)) - y += 15 - wx.StaticBitmap(parent, -1, off, pos=(x-1, y)) - self.led = wx.StaticBitmap(parent, -1, on, pos=(x-1, y)) - self.set_value(0) - - def set_value(self, value): - if value: - self.led.Enable() - else: - self.led.Disable() - - -class Led_16(object): - def __init__(self, parent, label, x, y, off, on): - led_width = off.GetWidth() - led_height = off.GetHeight() - wx.StaticText(parent, -1, label, pos=(x, y)) - y += 15 - self.leds = [] - mark_count = 2 - ticks = [(x-17+led_width,y+led_height/2+5)] - dc = wx.PaintDC(parent) - for i in range(16): - wx.StaticBitmap(parent, -1, off, pos=(x-1+i*17, y)) - led = wx.StaticBitmap(parent, -1, on, pos=(x-1+i*17, y)) - self.leds.append(led) - mark_count += 1 - if mark_count >= 3: - mark_count = 0 - ticks.append((x+i*17 + led_width, y+led_height/2+5)) - - self.set_value(0) - self.ticks = ticks - - def set_value(self, value): - mask = 0x8000 - for l in self.leds: - if value & mask: - l.Enable() - else: - l.Disable() - mask = mask >> 1 - - -class MyFrame(wx.Frame): - """a frame with two panels""" - - WIDTH_SCREEN = 1024 - HEIGHT_SCREEN = 1024 - WIDTH_CONSOLE = 330 # 400 # 256 - HEIGHT_CONSOLE = HEIGHT_SCREEN - - SCREEN_COLOUR = (0, 0, 0) - CONSOLE_COLOUR = (255, 223, 169) - PHOSPHOR_COLOUR = '#F0F000' # yellow - #PHOSPHOR_COLOUR = '#40FF40' # green - - V_MARGIN = 20 - CTL_MARGIN = 15 - LED_MARGIN = 5 - - IMAGE_LED_OFF = 'images/led_off.png' - IMAGE_LED_ON = 'images/led_on.png' - - def __init__(self, parent=None, id=-1, title=None): - wx.Frame.__init__(self, parent, id, title) - - self.make_gui() -# self.run() - - def make_gui(self): - self.screen = wx.Panel(self, - size=(self.WIDTH_SCREEN, self.HEIGHT_SCREEN), - pos=(0,0)) - self.screen.SetBackgroundColour(self.SCREEN_COLOUR) - self.console = wx.Panel(self, style=wx.SIMPLE_BORDER, - size=(self.WIDTH_CONSOLE, self.HEIGHT_SCREEN), - pos=(self.WIDTH_SCREEN,0)) - self.console.SetBackgroundColour(self.CONSOLE_COLOUR) - - python_png = wx.Image('images/PythonPowered.png', - wx.BITMAP_TYPE_PNG).ConvertToBitmap() - python_height = python_png.GetHeight() - python_width = python_png.GetWidth() - - wxpython_png = wx.Image('images/wxPython2.png', - wx.BITMAP_TYPE_PNG).ConvertToBitmap() - wxpython_height = wxpython_png.GetHeight() - wxpython_width = wxpython_png.GetWidth() - - h_margin = (self.WIDTH_CONSOLE - wxpython_width - python_width) / 3 - - png_height = max(python_height, wxpython_height) + self.V_MARGIN - - v_margin = (png_height - python_height)/2 - python_ypos = self.HEIGHT_CONSOLE - png_height + v_margin - v_margin = (png_height - wxpython_height)/2 - wxpython_ypos = self.HEIGHT_CONSOLE - png_height + v_margin - - wx.StaticBitmap(self.console, -1, python_png, - pos=(h_margin, python_ypos)) - wx.StaticBitmap(self.console, -1, wxpython_png, - pos=(python_width + 2*h_margin, wxpython_ypos)) - - self.png_height = png_height - - led_off = wx.Image('images/led_off.png', - wx.BITMAP_TYPE_PNG).ConvertToBitmap() - led_on = wx.Image('images/led_on.png', - wx.BITMAP_TYPE_PNG).ConvertToBitmap() - - y_pos = 8 - self.led_l = Led_1(self.console, 'l', self.CTL_MARGIN, y_pos, - led_off, led_on) - self.led_ac = Led_16(self.console, 'ac', 3*self.CTL_MARGIN, y_pos, - led_off, led_on) - y_pos += 35 - self.led_pc = Led_16(self.console, 'pc', 3*self.CTL_MARGIN, y_pos, - led_off, led_on) - - y_pos = 305 - wx.StaticText(self.console, -1, 'ptr', pos=(self.CTL_MARGIN, y_pos)) - y_pos += 15 - self.txt_ptrFile = wx.TextCtrl(self.console, -1, - pos=(self.CTL_MARGIN, y_pos), - size=(self.WIDTH_CONSOLE-2*self.CTL_MARGIN, 25)) - y_pos += 30 - - wx.StaticText(self.console, -1, 'ptp', pos=(self.CTL_MARGIN, y_pos)) - y_pos += 15 - self.txt_ptpFile = wx.TextCtrl(self.console, -1, - pos=(self.CTL_MARGIN, y_pos), - size=(self.WIDTH_CONSOLE-2*self.CTL_MARGIN, 25)) - y_pos += 15 - - dc = wx.PaintDC(self.console) - dc.SetPen(wx.Pen('black', 1)) - dc.DrawLine(0, self.HEIGHT_CONSOLE - self.png_height, - self.WIDTH_CONSOLE-1, self.HEIGHT_CONSOLE - self.png_height) - - for (x, y) in self.led_ac.ticks: - dc.DrawLine(x, y, x, y+5) - first = self.led_ac.ticks[0] - last = self.led_ac.ticks[-1] - (x1, y1) = first - (x2, y2) = last - dc.DrawLine(x1, y2+5, x2, y2+5) - - for (x, y) in self.led_pc.ticks: - dc.DrawLine(x, y, x, y+5) - first = self.led_pc.ticks[0] - last = self.led_pc.ticks[-1] - (x1, y1) = first - (x2, y2) = last - dc.DrawLine(x1, y2+5, x2, y2+5) - - self.y_offset = 0 - self.y_sign = +1 - - self.Fit() - - self.screen.Bind(wx.EVT_PAINT, self.on_paint) - self.console.Bind(wx.EVT_PAINT, self.on_paint) - - def on_paint(self, event): - global count - - # establish the painting surface - dc = wx.PaintDC(self.screen) - dc.SetBackground(wx.Brush(self.SCREEN_COLOUR, 1)) - dc.SetPen(wx.Pen(self.PHOSPHOR_COLOUR, 1)) - dc.Clear() - if self.y_sign > 0: - self.y_offset = self.y_offset + self.INC - if self.y_offset > self.HEIGHT_SCREEN-1: - self.y_sign = -1 - self.y_offset = self.HEIGHT_SCREEN-1 - else: - self.y_offset = self.y_offset - self.INC - if self.y_offset < 0: - self.y_sign = +1 - self.y_offset = 0 - dc.DrawLine(0, int(self.y_offset), self.WIDTH_SCREEN-1, int(self.HEIGHT_SCREEN-self.y_offset-1)) - dc.DrawLine(0, int(self.HEIGHT_SCREEN-self.y_offset-1), self.WIDTH_SCREEN-1, int(self.y_offset)) - - dc = wx.PaintDC(self.console) - #dc.SetPen(wx.Pen('black', wx.DOT)) - dc.SetPen(wx.Pen('black', 1)) - dc.DrawLine(0, self.HEIGHT_CONSOLE - self.png_height, - self.WIDTH_CONSOLE-1, self.HEIGHT_CONSOLE - self.png_height) - - for (x, y) in self.led_ac.ticks: - dc.DrawLine(x, y, x, y+5) - first = self.led_ac.ticks[0] - last = self.led_ac.ticks[-1] - (x1, y1) = first - (x2, y2) = last - dc.DrawLine(x1, y2+5, x2, y2+5) - - for (x, y) in self.led_pc.ticks: - dc.DrawLine(x, y, x, y+5) - first = self.led_pc.ticks[0] - last = self.led_pc.ticks[-1] - (x1, y1) = first - (x2, y2) = last - dc.DrawLine(x1, y2+5, x2, y2+5) - - count += 1 - self.led_ac.set_value(count) - - -# test it ... -app = wx.PySimpleApp() -frame1 = MyFrame(title='pymlac 0.1') -frame1.Center() -frame1.Show() +# run it ... +app = wx.App() +PymlacFrame(title='pymlac 0.1').Show() app.MainLoop()