From e31baa0d8e8429c194720a76c4cca1d23974af2f Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 26 Apr 2013 06:41:06 +0000 Subject: [PATCH] Patch updating FloatCanvas for Phoenix git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73859 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wx/lib/floatcanvas/FloatCanvas.py | 97 ++++++++++++++++--------------- wx/lib/floatcanvas/GUIMode.py | 44 +++++++------- wx/lib/floatcanvas/NavCanvas.py | 4 +- wx/lib/floatcanvas/Resources.py | 4 +- wx/lib/floatcanvas/ScreenShot.py | 4 +- 5 files changed, 78 insertions(+), 75 deletions(-) diff --git a/wx/lib/floatcanvas/FloatCanvas.py b/wx/lib/floatcanvas/FloatCanvas.py index 04a32e9c..681361a2 100644 --- a/wx/lib/floatcanvas/FloatCanvas.py +++ b/wx/lib/floatcanvas/FloatCanvas.py @@ -82,7 +82,7 @@ class _MouseEvent(wx.PyCommandEvent): """ def __init__(self, EventType, NativeEvent, WinID, Coords = None): - wx.PyCommandEvent.__init__(self) + super(_MouseEvent, self).__init__() self.SetEventType( EventType ) self._NativeEvent = NativeEvent @@ -92,8 +92,12 @@ class _MouseEvent(wx.PyCommandEvent): return self.Coords def __getattr__(self, name): + d = self._getAttrDict() + if name in d: + return d[name] return getattr(self._NativeEvent, name) + ## fixme: This should probably be re-factored into a class _testBitmap = None _testDC = None @@ -111,7 +115,7 @@ def _cycleidxs(indexcount, maxvalue, step): if not mac: dc = _testDC if not B: - B = _testBitmap = wx.EmptyBitmap(1, 1) + B = _testBitmap = wx.Bitmap(1, 1) if not mac: dc = _testDC = wx.MemoryDC() if mac: @@ -1093,9 +1097,9 @@ class Rectangle(RectEllipse): HTdc) WH[N.abs(WH) < self.MinSize] = self.MinSize if not( self.DisappearWhenSmall and N.abs(WH).min() <= self.MinSize) : # don't try to draw it too tiny - dc.DrawRectanglePointSize(XY, WH) + dc.DrawRectangle(XY, WH) if HTdc and self.HitAble: - HTdc.DrawRectanglePointSize(XY, WH) + HTdc.DrawRectangle(XY, WH) class Ellipse(RectEllipse): @@ -1107,9 +1111,9 @@ class Ellipse(RectEllipse): HTdc) WH[N.abs(WH) < self.MinSize] = self.MinSize if not( self.DisappearWhenSmall and N.abs(WH).min() <= self.MinSize) : # don't try to draw it too tiny - dc.DrawEllipsePointSize(XY, WH) + dc.DrawEllipse(XY, WH) if HTdc and self.HitAble: - HTdc.DrawEllipsePointSize(XY, WH) + HTdc.DrawEllipse(XY, WH) class Circle(XYObjectMixin, LineAndFillMixin, DrawObject): def __init__(self, XY, Diameter, @@ -1157,9 +1161,9 @@ class Circle(XYObjectMixin, LineAndFillMixin, DrawObject): WH[N.abs(WH) < self.MinSize] = self.MinSize if not( self.DisappearWhenSmall and N.abs(WH).min() <= self.MinSize) : # don't try to draw it too tiny - dc.DrawCirclePoint(XY, WH[0]) + dc.DrawCircle(XY, WH[0]) if HTdc and self.HitAble: - HTdc.DrawCirclePoint(XY, WH[0]) + HTdc.DrawCircle(XY, WH[0]) class TextObjectMixin(XYObjectMixin): @@ -1331,11 +1335,11 @@ class Text(TextObjectMixin, DrawObject, ): if self.TextWidth is None or self.TextHeight is None: (self.TextWidth, self.TextHeight) = dc.GetTextExtent(self.String) XY = self.ShiftFun(XY[0], XY[1], self.TextWidth, self.TextHeight) - dc.DrawTextPoint(self.String, XY) + dc.DrawText(self.String, XY) if HTdc and self.HitAble: HTdc.SetPen(self.HitPen) HTdc.SetBrush(self.HitBrush) - HTdc.DrawRectanglePointSize(XY, (self.TextWidth, self.TextHeight) ) + HTdc.DrawRectangle(XY, (self.TextWidth, self.TextHeight) ) class ScaledText(TextObjectMixin, DrawObject, ): ##fixme: this can be depricated and jsut use ScaledTextBox with different defaults. @@ -1456,7 +1460,7 @@ class ScaledText(TextObjectMixin, DrawObject, ): def CalcBoundingBox(self): ## this isn't exact, as fonts don't scale exactly. dc = wx.MemoryDC() - bitmap = wx.EmptyBitmap(1, 1) + bitmap = wx.Bitmap(1, 1) dc.SelectObject(bitmap) #wxMac needs a Bitmap selected for GetTextExtent to work. DrawingSize = 40 # pts This effectively determines the resolution that the BB is computed to. ScaleFactor = float(self.Size) / DrawingSize @@ -1494,13 +1498,12 @@ class ScaledText(TextObjectMixin, DrawObject, ): # This had to be put in here, because it changes with Zoom, as # fonts don't scale exactly. xy = self.ShiftFun(X, Y, w, h) - - dc.DrawTextPoint(self.String, xy) + dc.DrawText(self.String, xy) if HTdc and self.HitAble: HTdc.SetPen(self.HitPen) HTdc.SetBrush(self.HitBrush) - HTdc.DrawRectanglePointSize(xy, (w, h) ) + HTdc.DrawRectangle(xy, (w, h)) class ScaledTextBox(TextObjectMixin, DrawObject): """ @@ -1648,7 +1651,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): def WrapToWidth(self): dc = wx.MemoryDC() - bitmap = wx.EmptyBitmap(1, 1) + bitmap = wx.Bitmap(1, 1) dc.SelectObject(bitmap) #wxMac needs a Bitmap selected for GetTextExtent to work. DrawingSize = self.LayoutFontSize # pts This effectively determines the resolution that the BB is computed to. ScaleFactor = float(self.Size) / DrawingSize @@ -1697,7 +1700,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): self.WrapToWidth() dc = wx.MemoryDC() - bitmap = wx.EmptyBitmap(1, 1) + bitmap = wx.Bitmap(1, 1) dc.SelectObject(bitmap) #wxMac needs a Bitmap selected for GetTextExtent to work. DrawingSize = self.LayoutFontSize # pts This effectively determines the resolution that the BB is computed to. @@ -1794,7 +1797,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): if (self.LineStyle and self.LineColor) or self.BackgroundColor: dc.SetBrush(self.Brush) dc.SetPen(self.Pen) - dc.DrawRectanglePointSize(xy , wh) + dc.DrawRectangle(xy , wh) # Draw the Text if not( self.DisappearWhenSmall and Size <= self.MinFontSize) : # don't try to draw a zero sized font! @@ -1808,7 +1811,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): if HTdc and self.HitAble: HTdc.SetPen(self.HitPen) HTdc.SetBrush(self.HitBrush) - HTdc.DrawRectanglePointSize(xy, wh) + HTdc.DrawRectangle(xy, wh) class Bitmap(TextObjectMixin, DrawObject, ): """ @@ -1851,7 +1854,7 @@ class Bitmap(TextObjectMixin, DrawObject, ): if HTdc and self.HitAble: HTdc.SetPen(self.HitPen) HTdc.SetBrush(self.HitBrush) - HTdc.DrawRectanglePointSize(XY, (self.Width, self.Height) ) + HTdc.DrawRectangle(XY, (self.Width, self.Height) ) class ScaledBitmap(TextObjectMixin, DrawObject, ): """ @@ -1916,7 +1919,7 @@ class ScaledBitmap(TextObjectMixin, DrawObject, ): if HTdc and self.HitAble: HTdc.SetPen(self.HitPen) HTdc.SetBrush(self.HitBrush) - HTdc.DrawRectanglePointSize(XY, (W, H) ) + HTdc.DrawRectangle(XY, (W, H) ) class ScaledBitmap2(TextObjectMixin, DrawObject, ): """ @@ -2002,7 +2005,7 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ): if HTdc and self.HitAble: HTdc.SetPen(self.HitPen) HTdc.SetBrush(self.HitBrush) - HTdc.DrawRectanglePointSize(XY, (W, H) ) + HTdc.DrawRectangle(XY, (W, H) ) def _DrawSubBitmap(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc): """ @@ -2073,7 +2076,7 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ): if HTdc and self.HitAble: HTdc.SetPen(self.HitPen) HTdc.SetBrush(self.HitBrush) - HTdc.DrawRectanglePointSize(XYs, (Ws, Hs) ) + HTdc.DrawRectangle(XYs, (Ws, Hs) ) def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None): BBworld = BBox.asBBox(self._Canvas.ViewPortBB) @@ -2363,28 +2366,28 @@ class FloatCanvas(wx.Panel): self.Debug = Debug - wx.EVT_PAINT(self, self.OnPaint) - wx.EVT_SIZE(self, self.OnSize) + self.Bind(wx.EVT_PAINT, self.OnPaint) + self.Bind(wx.EVT_SIZE, self.OnSize) - wx.EVT_LEFT_DOWN(self, self.LeftDownEvent) - wx.EVT_LEFT_UP(self, self.LeftUpEvent) - wx.EVT_LEFT_DCLICK(self, self.LeftDoubleClickEvent) - wx.EVT_MIDDLE_DOWN(self, self.MiddleDownEvent) - wx.EVT_MIDDLE_UP(self, self.MiddleUpEvent) - wx.EVT_MIDDLE_DCLICK(self, self.MiddleDoubleClickEvent) - wx.EVT_RIGHT_DOWN(self, self.RightDownEvent) - wx.EVT_RIGHT_UP(self, self.RightUpEvent) - wx.EVT_RIGHT_DCLICK(self, self.RightDoubleCLickEvent) - wx.EVT_MOTION(self, self.MotionEvent) - wx.EVT_MOUSEWHEEL(self, self.WheelEvent) - wx.EVT_KEY_DOWN(self, self.KeyDownEvent) - wx.EVT_KEY_UP(self, self.KeyUpEvent) + self.Bind(wx.EVT_LEFT_DOWN, self.LeftDownEvent) + self.Bind(wx.EVT_LEFT_UP, self.LeftUpEvent) + self.Bind(wx.EVT_LEFT_DCLICK, self.LeftDoubleClickEvent) + self.Bind(wx.EVT_MIDDLE_DOWN, self.MiddleDownEvent) + self.Bind(wx.EVT_MIDDLE_UP, self.MiddleUpEvent) + self.Bind(wx.EVT_MIDDLE_DCLICK, self.MiddleDoubleClickEvent) + self.Bind(wx.EVT_RIGHT_DOWN, self.RightDownEvent) + self.Bind(wx.EVT_RIGHT_UP, self.RightUpEvent) + self.Bind(wx.EVT_RIGHT_DCLICK, self.RightDoubleCLickEvent) + self.Bind(wx.EVT_MOTION, self.MotionEvent) + self.Bind(wx.EVT_MOUSEWHEEL, self.WheelEvent) + self.Bind(wx.EVT_KEY_DOWN, self.KeyDownEvent) + self.Bind(wx.EVT_KEY_UP, self.KeyUpEvent) ## CHB: I'm leaving these out for now. - #wx.EVT_ENTER_WINDOW(self, self. ) - #wx.EVT_LEAVE_WINDOW(self, self. ) - + #self.Bind(wx.EVT_ENTER_WINDOW, self. ) + #self.Bind(wx.EVT_LEAVE_WINDOW, self. ) + self.SetProjectionFun(ProjectionFun) self.GUIMode = None # making sure the arrribute exists @@ -2678,9 +2681,9 @@ class FloatCanvas(wx.Panel): ##fixme: this looks like tortured logic! self._BackgroundDirty = True # Make new offscreen bitmap: - self._Buffer = wx.EmptyBitmap(*self.PanelSize) + self._Buffer = wx.Bitmap(*self.PanelSize) if self._ForeDrawList: - self._ForegroundBuffer = wx.EmptyBitmap(*self.PanelSize) + self._ForegroundBuffer = wx.Bitmap(*self.PanelSize) if self.UseHitTest: self.MakeNewForegroundHTBitmap() else: @@ -2700,7 +2703,7 @@ class FloatCanvas(wx.Panel): Off screen Bitmap used for Hit tests on background objects """ - self._HTBitmap = wx.EmptyBitmap(self.PanelSize[0], + self._HTBitmap = wx.Bitmap(self.PanelSize[0], self.PanelSize[1], depth=self.HitTestBitmapDepth) @@ -2712,7 +2715,7 @@ class FloatCanvas(wx.Panel): Off screen Bitmap used for Hit tests on foreground objects """ - self._ForegroundHTBitmap = wx.EmptyBitmap(self.PanelSize[0], + self._ForegroundHTBitmap = wx.Bitmap(self.PanelSize[0], self.PanelSize[1], depth=self.HitTestBitmapDepth) @@ -2725,7 +2728,7 @@ class FloatCanvas(wx.Panel): self.Draw() def InitializePanel(self): - PanelSize = N.array(self.GetClientSizeTuple(), N.int32) + PanelSize = N.array(self.GetClientSize(), N.int32) self.PanelSize = N.maximum(PanelSize, (2,2)) ## OS-X sometimes gives a Size event when the panel is size (0,0) self.HalfPanelSize = self.PanelSize / 2 # lrk: added for speed in WorldToPixel self.AspectRatio = float(self.PanelSize[0]) / self.PanelSize[1] @@ -2802,7 +2805,7 @@ class FloatCanvas(wx.Panel): if self._ForeDrawList: ## If an object was just added to the Foreground, there might not yet be a buffer if self._ForegroundBuffer is None: - self._ForegroundBuffer = wx.EmptyBitmap(self.PanelSize[0], + self._ForegroundBuffer = wx.Bitmap(self.PanelSize[0], self.PanelSize[1]) dc = wx.MemoryDC() ## I got some strange errors (linewidths wrong) if I didn't make a new DC here @@ -3091,7 +3094,6 @@ class FloatCanvas(wx.Panel): device context. """ dc.SetBackground(self.BackgroundBrush) - dc.BeginDrawing() #i = 0 PanelSize0, PanelSize1 = self.PanelSize # for speed WorldToPixel = self.WorldToPixel # for speed @@ -3103,7 +3105,6 @@ class FloatCanvas(wx.Panel): Object._Draw(dc, WorldToPixel, ScaleWorldToPixel, HTdc) if (i+1) % NumBetweenBlits == 0: Blit(0, 0, PanelSize0, PanelSize1, dc, 0, 0) - dc.EndDrawing() def SaveAsImage(self, filename, ImageType=wx.BITMAP_TYPE_PNG): """ diff --git a/wx/lib/floatcanvas/GUIMode.py b/wx/lib/floatcanvas/GUIMode.py index 13fae967..1545a9a5 100644 --- a/wx/lib/floatcanvas/GUIMode.py +++ b/wx/lib/floatcanvas/GUIMode.py @@ -24,31 +24,31 @@ class Cursors(object): """ def __init__(self): if "wxMac" in wx.PlatformInfo: # use 16X16 cursors for wxMac - self.HandCursor = wx.CursorFromImage(Resources.getHand16Image()) - self.GrabHandCursor = wx.CursorFromImage(Resources.getGrabHand16Image()) + self.HandCursor = wx.Cursor(Resources.getHand16Image()) + self.GrabHandCursor = wx.Cursor(Resources.getGrabHand16Image()) img = Resources.getMagPlus16Image() - img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 6) - img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 6) - self.MagPlusCursor = wx.CursorFromImage(img) + img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 6) + img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 6) + self.MagPlusCursor = wx.Cursor(img) img = Resources.getMagMinus16Image() - img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 6) - img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 6) - self.MagMinusCursor = wx.CursorFromImage(img) + img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 6) + img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 6) + self.MagMinusCursor = wx.Cursor(img) else: # use 24X24 cursors for GTK and Windows - self.HandCursor = wx.CursorFromImage(Resources.getHandImage()) - self.GrabHandCursor = wx.CursorFromImage(Resources.getGrabHandImage()) + self.HandCursor = wx.Cursor(Resources.getHandImage()) + self.GrabHandCursor = wx.Cursor(Resources.getGrabHandImage()) img = Resources.getMagPlusImage() - img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 9) - img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 9) - self.MagPlusCursor = wx.CursorFromImage(img) + img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 9) + img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 9) + self.MagPlusCursor = wx.Cursor(img) img = Resources.getMagMinusImage() - img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 9) - img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 9) - self.MagMinusCursor = wx.CursorFromImage(img) + img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 9) + img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 9) + self.MagMinusCursor = wx.Cursor(img) class GUIBase(object): @@ -224,7 +224,6 @@ class GUIMove(GUIBase): wh = self.Canvas.PanelSize xy_tl = xy1 - self.StartMove dc = wx.ClientDC(self.Canvas) - dc.BeginDrawing() x1,y1 = self.PrevMoveXY x2,y2 = xy_tl w,h = self.Canvas.PanelSize @@ -272,10 +271,9 @@ class GUIMove(GUIBase): dc.DrawRectangle(xb, yb, wb, hb) self.PrevMoveXY = xy_tl if self.Canvas._ForeDrawList: - dc.DrawBitmapPoint(self.Canvas._ForegroundBuffer,xy_tl) + dc.DrawBitmap(self.Canvas._ForegroundBuffer,xy_tl) else: - dc.DrawBitmapPoint(self.Canvas._Buffer,xy_tl) - dc.EndDrawing() + dc.DrawBitmap(self.Canvas._Buffer,xy_tl) #self.Canvas.Update() def OnWheel(self, event): @@ -327,15 +325,13 @@ class GUIZoomIn(GUIBase): wh[1] = int(wh[0] / self.Canvas.AspectRatio) xy_c = (xy0 + xy1) / 2 dc = wx.ClientDC(self.Canvas) - dc.BeginDrawing() dc.SetPen(wx.Pen('WHITE', 2, wx.SHORT_DASH)) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetLogicalFunction(wx.XOR) if self.PrevRBBox: - dc.DrawRectanglePointSize(*self.PrevRBBox) + dc.DrawRectangle(*self.PrevRBBox) self.PrevRBBox = ( xy_c - wh/2, wh ) - dc.DrawRectanglePointSize( *self.PrevRBBox ) - dc.EndDrawing() + dc.DrawRectangle( *self.PrevRBBox ) def UpdateScreen(self): """ diff --git a/wx/lib/floatcanvas/NavCanvas.py b/wx/lib/floatcanvas/NavCanvas.py index 8c31b10c..a74467ce 100644 --- a/wx/lib/floatcanvas/NavCanvas.py +++ b/wx/lib/floatcanvas/NavCanvas.py @@ -60,7 +60,9 @@ class NavCanvas(wx.Panel): def AddToolbarModeButtons(self, tb, Modes): self.ModesDict = {} for Mode in Modes: - tool = tb.AddRadioTool(wx.ID_ANY, shortHelp=Mode[0], bitmap=Mode[2]) + tool = tb.AddTool(wx.ID_ANY, label=Mode[0], + shortHelp=Mode[0], bitmap=Mode[2], + kind=wx.ITEM_RADIO) self.Bind(wx.EVT_TOOL, self.SetMode, tool) self.ModesDict[tool.GetId()]=Mode[1] #self.ZoomOutTool = tb.AddRadioTool(wx.ID_ANY, bitmap=Resources.getMagMinusBitmap(), shortHelp = "Zoom Out") diff --git a/wx/lib/floatcanvas/Resources.py b/wx/lib/floatcanvas/Resources.py index d3208ee6..5842890a 100644 --- a/wx/lib/floatcanvas/Resources.py +++ b/wx/lib/floatcanvas/Resources.py @@ -1,7 +1,9 @@ #---------------------------------------------------------------------- # This file was generated by /usr/local/bin/img2py # -from wx import ImageFromStream, BitmapFromImage +from wx import Image as ImageFromStream +from wx import Bitmap as BitmapFromImage + import cStringIO, zlib diff --git a/wx/lib/floatcanvas/ScreenShot.py b/wx/lib/floatcanvas/ScreenShot.py index 5f211404..8d1c9dcc 100644 --- a/wx/lib/floatcanvas/ScreenShot.py +++ b/wx/lib/floatcanvas/ScreenShot.py @@ -1,7 +1,9 @@ #---------------------------------------------------------------------- # This file was generated by /usr/local/bin/img2py # -from wx import ImageFromStream, BitmapFromImage +from wx import Image as ImageFromStream +from wx import BitmapFromImage + import cStringIO, zlib