X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f780e48af479e7bf9a07eaaa1ab6b41f1ffb17b..d8746da256e827b700aaf173669bd5bbc97025c7:/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 8bda44696d..f8e9d16e4e 100644 --- a/wxPython/samples/ide/activegrid/tool/AbstractEditor.py +++ b/wxPython/samples/ide/activegrid/tool/AbstractEditor.py @@ -21,6 +21,7 @@ _ = wx.GetTranslation SELECT_BRUSH = wx.Brush("BLUE", wx.SOLID) SHAPE_BRUSH = wx.Brush("WHEAT", wx.SOLID) LINE_BRUSH = wx.BLACK_BRUSH +INACTIVE_SELECT_BRUSH = wx.Brush("LIGHT BLUE", wx.SOLID) def GetRawModel(model): @@ -47,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() @@ -59,15 +69,46 @@ class CanvasView(wx.lib.docview.View): frame.Layout() self.Activate() return True - + def OnActivateView(self, activate, activeView, deactiveView): 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.FocusColorPropertyShape(True) + event.Skip() + + + def FocusOnClick(self, event): + self.SetFocus() + event.Skip() + + + def OnKillFocus(self, event): + self.FocusColorPropertyShape(False) + 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): @@ -90,10 +131,19 @@ class CanvasView(wx.lib.docview.View): wx.EVT_MOTION(self._canvas, self.OnLeftDrag) wx.EVT_LEFT_DCLICK(self._canvas, self.OnLeftDoubleClick) wx.EVT_KEY_DOWN(self._canvas, self.OnKeyPressed) + + # need this otherwise mouse clicks don't set focus to this view + wx.EVT_LEFT_DOWN(self._canvas, self.FocusOnClick) + wx.EVT_LEFT_DCLICK(self._canvas, self.FocusOnClick) + wx.EVT_RIGHT_DOWN(self._canvas, self.FocusOnClick) + wx.EVT_RIGHT_DCLICK(self._canvas, self.FocusOnClick) + wx.EVT_MIDDLE_DOWN(self._canvas, self.FocusOnClick) + wx.EVT_MIDDLE_DCLICK(self._canvas, self.FocusOnClick) + + 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() @@ -351,7 +401,7 @@ class CanvasView(wx.lib.docview.View): shape.SetBrush(brush) if text: shape.AddText(text) - shape.SetShadowMode(ogl.SHADOW_RIGHT) + shape.SetShadowMode(ogl.SHADOW_NONE) self._diagram.AddShape(shape) shape.Show(True) if not eventHandler: @@ -371,9 +421,28 @@ class CanvasView(wx.lib.docview.View): if shape: shape.Select(False) + for line in shape.GetLines(): + shape.RemoveLine(line) + self._diagram.RemoveShape(line) + for obj in self._diagram.GetShapeList(): + for line in obj.GetLines(): + if self.IsShapeContained(shape, line.GetTo()) or self.IsShapeContained(shape, line.GetFrom()): + obj.RemoveLine(line) + self._diagram.RemoveShape(line) + if line == shape: + obj.RemoveLine(line) + + shape.RemoveFromCanvas(self._canvas) self._diagram.RemoveShape(shape) - if isinstance(shape, ogl.CompositeShape): - shape.RemoveFromCanvas(self._canvas) + + + def IsShapeContained(self, parent, shape): + if parent == shape: + return True + elif shape.GetParent(): + return self.IsShapeContained(parent, shape.GetParent()) + + return False def UpdateShape(self, model): @@ -505,7 +574,36 @@ 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) + + dc.EndDrawing() + + + def FocusColorPropertyShape(self, gotFocus=False): + # no need to change highlight if no PropertyService is running + propertyService = wx.GetApp().GetService(PropertyService.PropertyService) + if not propertyService: + return + + if not self._propShape: + return + + dc = wx.ClientDC(self._canvas) + self._canvas.PrepareDC(dc) + dc.BeginDrawing() + + # draw deactivated selection + if self._propShape and self._propShape in self._diagram.GetShapeList(): + if gotFocus: + 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) @@ -586,7 +684,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():