From 3eaf18dce3e096fcb79c3a6e6ad71168e999630f Mon Sep 17 00:00:00 2001 From: Ross Wilson Date: Thu, 18 Jun 2015 16:04:56 +0700 Subject: [PATCH] Change screen size to 2048x2048 --- pymlac/Display.py | 192 ++++++----------------------------------- pymlac/test_Display.py | 6 +- 2 files changed, 30 insertions(+), 168 deletions(-) diff --git a/pymlac/Display.py b/pymlac/Display.py index 40b58fb..7c6fea4 100644 --- a/pymlac/Display.py +++ b/pymlac/Display.py @@ -39,6 +39,10 @@ class _BufferedCanvas(wx.Panel): # The backing buffer buffer = None + # max coordinates of scaled display + ScaleMaxX = 2048 + ScaleMaxY = 2048 + def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.NO_FULL_REPAINT_ON_RESIZE): """Initialise the canvas. @@ -114,18 +118,21 @@ class _BufferedCanvas(wx.Panel): self.Update() +################################################################################ +# The actual pymlc display widget. +################################################################################ + class Display(_BufferedCanvas): BackgroundColour = 'black' - DrawColour = '#ffff00' + DrawColour = '#ffff88' SYNC_HZ = 40 SYNC_40HZ_CYCLE_COUNT = int(CYCLES_PER_SECOND / SYNC_HZ) # max coorcinates of pymlac display - ScaleMaxX = 1024 - ScaleMaxY = 1024 - + ScaleMaxX = 2048 + ScaleMaxY = 2048 def __init__(self, parent, **kwargs): @@ -141,14 +148,15 @@ class Display(_BufferedCanvas): self.OnSize() - def draw(self, x1, y1, x2, y2): + def draw(self, sd, x1, y1, x2, y2): """Draw a line on the screen. - + + sd True if solid line, False if dotted x1, y1 start coordinates x2, y2 end coordinates """ - self.drawlist.append((x1, y1, x2, y2)) + self.drawlist.append((sd, x1, y1, x2, y2)) self.Update() def Draw(self, dc): @@ -157,9 +165,18 @@ class Display(_BufferedCanvas): # there's some code in super.Draw() we need super(Display, self).Draw(dc) - if self.drawlist: - dc.SetPen(wx.Pen(self.DrawColour)) - dc.DrawLineList(self.drawlist) + pen = wx.Pen(self.DrawColour) + + for (sd, x1, y1, x2, y2) in self.drawlist: + if sd: + pen.SetStyle(wx.SOLID) + pen.SetWidth(2) + else: + pen.SetStyle(wx.DOT) + pen.SetWidth(3) + dc.SetPen(pen) + + dc.DrawLine(x1, y1, x2, y2) def syncclear(self): self.Sync40hz = 0 @@ -177,158 +194,3 @@ class Display(_BufferedCanvas): self.Sync40hz = 1 self.cycle_count = 0 -############################################################################### -# Define the events that are raised by the display widget. -############################################################################### - -# display stop -_myEVT_DISPLAY_STOP = wx.NewEventType() -EVT_DISPLAY_STOP = wx.PyEventBinder(_myEVT_DISPLAY_STOP, 1) - -class _DisplayEvent(wx.PyCommandEvent): - """Event sent from the display widget.""" - - def __init__(self, eventType, id): - """Construct a display event. - - eventType type of event - id unique event number - - Event will be adorned with attributes by raising code. - """ - - wx.PyCommandEvent.__init__(self, eventType, id) - -############################################################################### -# The display widget proper -############################################################################### - -class PymlacDisplay(_BufferedCanvas): - """A widget to display pymlac draw lists.""" - - # line colour - DrawColour = '#ffff00' - - # panel background colour - BackgroundColour = '#000000' - - # max coorcinates of pymlac display - ScaleMaxX = 1024 - ScaleMaxY = 1024 - - def __init__(self, parent, **kwargs): - """Initialise a display instance. - - parent reference to parent object - **kwargs keyword args for Panel - """ - - # create and initialise the base panel - _BufferedCanvas.__init__(self, parent=parent, **kwargs) - self.SetBackgroundColour(PymlacDisplay.BackgroundColour) - - # set some internal state - self.default_cursor = wx.CURSOR_DEFAULT - self.drawlist = None # list of (x1,y1,x2,y2) - - # set callback when parent resizes -# self.onSizeCallback = self.ResizeCallback - - # force a resize, which sets up the rest of the state - # eventually calls ResizeCallback() - self.OnSize() - - ###### - # GUI stuff - ###### - - def OnKeyDown(self, event): - pass - - def OnKeyUp(self, event): - pass - - def OnLeftUp(self, event): - """Left mouse button up. - """ - - pass - - def OnMiddleUp(self, event): - """Middle mouse button up. Do nothing in this version.""" - - pass - - def OnRightUp(self, event): - """Right mouse button up. - - Note that when we iterate through the layer_z_order list we must - iterate on a *copy* as the user select process can modify - self.layer_z_order. - - THIS CODE HASN'T BEEN LOOKED AT IN A LONG, LONG TIME. - """ - - pass - - def Draw(self, dc): - """Do actual widget drawing. - Overrides the _BufferedCanvas.draw() method. - - dc device context to draw on - - Draws the current drawlist to the screen. - """ - - scaleX = self.view_width*1.0 / self.ScaleMaxX - scaleY = self.view_height*1.0 / self.ScaleMaxY - dc.SetUserScale(min(scaleX,scaleY), min(scaleX,scaleY)) - - if self.drawlist: - dc.SetPen(wx.Pen(self.DrawColour)) - dc.DrawLineList(self.drawlist) - - ###### - # Change the drawlist - ###### - - def Drawlist(self, dl): - self.drawlist = dl - self.Update() - - ###### - # Routines for display events - ###### - - def RaiseEventStop(self): - """Raise a display stop event.""" - - event = _DisplayEvent(_myEVT_DISPLAY_STOP, self.GetId()) - self.GetEventHandler().ProcessEvent(event) - - def info(self, msg): - """Display an information message, log and graphically.""" - - log_msg = '# ' + msg - length = len(log_msg) - prefix = '#### Information ' - banner = prefix + '#'*(80 - len(log_msg) - len(prefix)) - log(banner) - log(log_msg) - log(banner) - - wx.MessageBox(msg, 'Warning', wx.OK | wx.ICON_INFORMATION) - - def warn(self, msg): - """Display a warning message, log and graphically.""" - - log_msg = '# ' + msg - length = len(log_msg) - prefix = '#### Warning ' - banner = prefix + '#'*(80 - len(log_msg) - len(prefix)) - log(banner) - log(log_msg) - log(banner) - - wx.MessageBox(msg, 'Warning', wx.OK | wx.ICON_ERROR) - diff --git a/pymlac/test_Display.py b/pymlac/test_Display.py index bc0aff7..c39da69 100755 --- a/pymlac/test_Display.py +++ b/pymlac/test_Display.py @@ -25,7 +25,7 @@ except ImportError: ###### WindowTitleHeight = 22 -DefaultAppSize = (600, 600+WindowTitleHeight) +DefaultAppSize = (200, 200+WindowTitleHeight) ################################################################################ # The main application frame @@ -55,8 +55,8 @@ class TestFrame(wx.Frame): self.Refresh() - self.display.draw(0, 0, 1023, 1023) - self.display.draw(1023, 0, 0, 1023) + self.display.draw(True, 0, 0, 2047, 2047) + self.display.draw(False, 2047, 0, 0, 2047) def OnSize(self, event): """Maintain square window."""