X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b792147db7e5ceb5da741f5f6e27fea79944a04c..d654745dc573bceda1e9c4c0dc0502f534166e1b:/wxPython/samples/ide/activegrid/tool/AbstractEditor.py diff --git a/wxPython/samples/ide/activegrid/tool/AbstractEditor.py b/wxPython/samples/ide/activegrid/tool/AbstractEditor.py index 1361b422e8..18fbf6d7fc 100644 --- a/wxPython/samples/ide/activegrid/tool/AbstractEditor.py +++ b/wxPython/samples/ide/activegrid/tool/AbstractEditor.py @@ -48,8 +48,17 @@ class CanvasView(wx.lib.docview.View): self._pt2 = None self._needEraseLasso = False self._propShape = None + self._maxWidth = 2000 + self._maxHeight = 16000 + def OnDraw(self, dc): + """ for Print Preview and Print """ + dc.BeginDrawing() + self._canvas.Redraw(dc) + dc.EndDrawing() + + def OnCreate(self, doc, flags): frame = wx.GetApp().CreateDocumentFrame(self, doc, flags) frame.Show() @@ -66,13 +75,18 @@ class CanvasView(wx.lib.docview.View): if activate and self._canvas: # In MDI mode just calling set focus doesn't work and in SDI mode using CallAfter causes an endless loop if self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI: - self._canvas.SetFocus() + self.SetFocus() else: - wx.CallAfter(self._canvas.SetFocus) + wx.CallAfter(self.SetFocus) + + + def SetFocus(self): + if self._canvas: + self._canvas.SetFocus() def OnFocus(self, event): - self._canvas.SetFocus() + self.SetFocus() self.FocusColorPropertyShape(True) event.Skip() @@ -82,6 +96,17 @@ class CanvasView(wx.lib.docview.View): event.Skip() + def HasFocus(self): + winWithFocus = wx.Window.FindFocus() + if not winWithFocus: + return False + while winWithFocus: + if winWithFocus == self._canvas: + return True + winWithFocus = winWithFocus.GetParent() + return False + + def OnClose(self, deleteWindow = True): statusC = wx.GetApp().CloseChildDocuments(self.GetDocument()) statusP = wx.lib.docview.View.OnClose(self, deleteWindow = deleteWindow) @@ -114,9 +139,7 @@ class CanvasView(wx.lib.docview.View): wx.EVT_KILL_FOCUS(self._canvas, self.OnKillFocus) wx.EVT_SET_FOCUS(self._canvas, self.OnFocus) - maxWidth = 2000 - maxHeight = 16000 - self._canvas.SetScrollbars(20, 20, maxWidth / 20, maxHeight / 20) + self._canvas.SetScrollbars(20, 20, self._maxWidth / 20, self._maxHeight / 20) self._canvas.SetBackgroundColour(wx.WHITE) self._diagram = ogl.Diagram() @@ -528,7 +551,10 @@ class CanvasView(wx.lib.docview.View): # draw new selection if self._propShape and self._propShape in self._diagram.GetShapeList(): - self._propShape.SetBrush(SELECT_BRUSH) + if self.HasFocus(): + self._propShape.SetBrush(SELECT_BRUSH) + else: + self._propShape.SetBrush(INACTIVE_SELECT_BRUSH) if (self._propShape._textColourName in ["BLACK", "WHITE"]): # Would use GetTextColour() but it is broken self._propShape.SetTextColour("WHITE", 0) self._propShape.Draw(dc) @@ -635,7 +661,16 @@ class EditorCanvasShapeEvtHandler(ogl.ShapeEvtHandler): self._view.SetSelection(model, keys == self.SHIFT_KEY or keys == self.CONTROL_KEY) + def OnMovePre(self, dc, x, y, oldX, oldY, display): + """ Prevent objects from being dragged outside of viewable area """ + if (x > self._view._maxWidth) or (y > self._view._maxHeight): + return False + + return ogl.ShapeEvtHandler.OnMovePre(self, dc, x, y, oldX, oldY, display) + + def OnMovePost(self, dc, x, y, oldX, oldY, display): + """ Update the model's record of where the shape should be. Also enable redo/undo. """ if x == oldX and y == oldY: return if not self._view.GetDocument():