📄 _basic.py
字号:
# -*- coding: iso-8859-1 -*-
#----------------------------------------------------------------------------
# Name: basic.py
# Purpose: The basic OGL shapes
#
# Author: Pierre Hj鋖m (from C++ original by Julian Smart)
#
# Created: 2004-05-08
# RCS-ID: $Id: _basic.py,v 1.17 2006/05/05 19:09:04 RD Exp $
# Copyright: (c) 2004 Pierre Hj鋖m - 1998 Julian Smart
# Licence: wxWindows license
#----------------------------------------------------------------------------
import wx
import math
from _oglmisc import *
DragOffsetX = 0.0
DragOffsetY = 0.0
def OGLInitialize():
global WhiteBackgroundPen, WhiteBackgroundBrush, TransparentPen
global BlackForegroundPen, NormalFont
WhiteBackgroundPen = wx.Pen(wx.WHITE, 1, wx.SOLID)
WhiteBackgroundBrush = wx.Brush(wx.WHITE, wx.SOLID)
TransparentPen = wx.Pen(wx.WHITE, 1, wx.TRANSPARENT)
BlackForegroundPen = wx.Pen(wx.BLACK, 1, wx.SOLID)
NormalFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)
def OGLCleanUp():
pass
class ShapeTextLine(object):
def __init__(self, the_x, the_y, the_line):
self._x = the_x
self._y = the_y
self._line = the_line
def GetX(self):
return self._x
def GetY(self):
return self._y
def SetX(self, x):
self._x = x
def SetY(self, y):
self._y = y
def SetText(self, text):
self._line = text
def GetText(self):
return self._line
class ShapeEvtHandler(object):
def __init__(self, prev = None, shape = None):
self._previousHandler = prev
self._handlerShape = shape
def __del__(self):
pass
def SetShape(self, sh):
self._handlerShape = sh
def GetShape(self):
return self._handlerShape
def SetPreviousHandler(self, handler):
self._previousHandler = handler
def GetPreviousHandler(self):
return self._previousHandler
def OnDelete(self):
if self!=self.GetShape():
del self
def OnDraw(self, dc):
if self._previousHandler:
self._previousHandler.OnDraw(dc)
def OnMoveLinks(self, dc):
if self._previousHandler:
self._previousHandler.OnMoveLinks(dc)
def OnMoveLink(self, dc, moveControlPoints = True):
if self._previousHandler:
self._previousHandler.OnMoveLink(dc, moveControlPoints)
def OnDrawContents(self, dc):
if self._previousHandler:
self._previousHandler.OnDrawContents(dc)
def OnDrawBranches(self, dc, erase = False):
if self._previousHandler:
self._previousHandler.OnDrawBranches(dc, erase = erase)
def OnSize(self, x, y):
if self._previousHandler:
self._previousHandler.OnSize(x, y)
def OnMovePre(self, dc, x, y, old_x, old_y, display = True):
if self._previousHandler:
return self._previousHandler.OnMovePre(dc, x, y, old_x, old_y, display)
else:
return True
def OnMovePost(self, dc, x, y, old_x, old_y, display = True):
if self._previousHandler:
return self._previousHandler.OnMovePost(dc, x, y, old_x, old_y, display)
else:
return True
def OnErase(self, dc):
if self._previousHandler:
self._previousHandler.OnErase(dc)
def OnEraseContents(self, dc):
if self._previousHandler:
self._previousHandler.OnEraseContents(dc)
def OnHighlight(self, dc):
if self._previousHandler:
self._previousHandler.OnHighlight(dc)
def OnLeftClick(self, x, y, keys, attachment):
if self._previousHandler:
self._previousHandler.OnLeftClick(x, y, keys, attachment)
def OnLeftDoubleClick(self, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnLeftDoubleClick(x, y, keys, attachment)
def OnRightClick(self, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnRightClick(x, y, keys, attachment)
def OnDragLeft(self, draw, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnDragLeft(draw, x, y, keys, attachment)
def OnBeginDragLeft(self, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnBeginDragLeft(x, y, keys, attachment)
def OnEndDragLeft(self, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnEndDragLeft(x, y, keys, attachment)
def OnDragRight(self, draw, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnDragRight(draw, x, y, keys, attachment)
def OnBeginDragRight(self, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnBeginDragRight(x, y, keys, attachment)
def OnEndDragRight(self, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnEndDragRight(x, y, keys, attachment)
# Control points ('handles') redirect control to the actual shape,
# to make it easier to override sizing behaviour.
def OnSizingDragLeft(self, pt, draw, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnSizingDragLeft(pt, draw, x, y, keys, attachment)
def OnSizingBeginDragLeft(self, pt, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnSizingBeginDragLeft(pt, x, y, keys, attachment)
def OnSizingEndDragLeft(self, pt, x, y, keys = 0, attachment = 0):
if self._previousHandler:
self._previousHandler.OnSizingEndDragLeft(pt, x, y, keys, attachment)
def OnBeginSize(self, w, h):
pass
def OnEndSize(self, w, h):
pass
def OnDrawOutline(self, dc, x, y, w, h):
if self._previousHandler:
self._previousHandler.OnDrawOutline(dc, x, y, w, h)
def OnDrawControlPoints(self, dc):
if self._previousHandler:
self._previousHandler.OnDrawControlPoints(dc)
def OnEraseControlPoints(self, dc):
if self._previousHandler:
self._previousHandler.OnEraseControlPoints(dc)
# Can override this to prevent or intercept line reordering.
def OnChangeAttachment(self, attachment, line, ordering):
if self._previousHandler:
self._previousHandler.OnChangeAttachment(attachment, line, ordering)
class Shape(ShapeEvtHandler):
"""OGL base class
Shape(canvas = None)
The wxShape is the top-level, abstract object that all other objects
are derived from. All common functionality is represented by wxShape's
members, and overriden members that appear in derived classes and have
behaviour as documented for wxShape, are not documented separately.
"""
GraphicsInSizeToContents = False
def __init__(self, canvas = None):
ShapeEvtHandler.__init__(self)
self._eventHandler = self
self.SetShape(self)
self._id = 0
self._formatted = False
self._canvas = canvas
self._xpos = 0.0
self._ypos = 0.0
self._pen = wx.Pen(wx.BLACK, 1, wx.SOLID)
self._brush = wx.WHITE_BRUSH
self._font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)
self._textColour = wx.BLACK
self._textColourName = wx.BLACK
self._visible = False
self._selected = False
self._attachmentMode = ATTACHMENT_MODE_NONE
self._spaceAttachments = True
self._disableLabel = False
self._fixedWidth = False
self._fixedHeight = False
self._drawHandles = True
self._sensitivity = OP_ALL
self._draggable = True
self._parent = None
self._formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT
self._shadowMode = SHADOW_NONE
self._shadowOffsetX = 6
self._shadowOffsetY = 6
self._shadowBrush = wx.BLACK_BRUSH
self._textMarginX = 5
self._textMarginY = 5
self._regionName = "0"
self._centreResize = True
self._maintainAspectRatio = False
self._highlighted = False
self._rotation = 0.0
self._branchNeckLength = 10
self._branchStemLength = 10
self._branchSpacing = 10
self._branchStyle = BRANCHING_ATTACHMENT_NORMAL
self._regions = []
self._lines = []
self._controlPoints = []
self._attachmentPoints = []
self._text = []
self._children = []
# Set up a default region. Much of the above will be put into
# the region eventually (the duplication is for compatibility)
region = ShapeRegion()
region.SetName("0")
region.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL))
region.SetFormatMode(FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT)
region.SetColour("BLACK")
self._regions.append(region)
def __str__(self):
return "<%s.%s>" % (self.__class__.__module__, self.__class__.__name__)
def GetClassName(self):
return str(self.__class__).split(".")[-1][:-2]
def Delete(self):
"""
Fully disconnect this shape from parents, children, the
canvas, etc.
"""
if self._parent:
self._parent.GetChildren().remove(self)
for child in self.GetChildren():
child.Delete()
self.ClearText()
self.ClearRegions()
self.ClearAttachments()
self._handlerShape = None
if self._canvas:
self.RemoveFromCanvas(self._canvas)
if self.GetEventHandler():
self.GetEventHandler().OnDelete()
self._eventHandler = None
def __del__(self):
ShapeEvtHandler.__del__(self)
def Draggable(self):
"""TRUE if the shape may be dragged by the user."""
return True
def SetShape(self, sh):
self._handlerShape = sh
def GetCanvas(self):
"""Get the internal canvas."""
return self._canvas
def GetBranchStyle(self):
return self._branchStyle
def GetRotation(self):
"""Return the angle of rotation in radians."""
return self._rotation
def SetRotation(self, rotation):
self._rotation = rotation
def SetHighlight(self, hi, recurse = False):
"""Set the highlight for a shape. Shape highlighting is unimplemented."""
self._highlighted = hi
if recurse:
for shape in self._children:
shape.SetHighlight(hi, recurse)
def SetSensitivityFilter(self, sens = OP_ALL, recursive = False):
"""Set the shape to be sensitive or insensitive to specific mouse
operations.
sens is a bitlist of the following:
* OP_CLICK_LEFT
* OP_CLICK_RIGHT
* OP_DRAG_LEFT
* OP_DRAG_RIGHT
* OP_ALL (equivalent to a combination of all the above).
"""
self._draggable = sens & OP_DRAG_LEFT
self._sensitivity = sens
if recursive:
for shape in self._children:
shape.SetSensitivityFilter(sens, True)
def SetDraggable(self, drag, recursive = False):
"""Set the shape to be draggable or not draggable."""
self._draggable = drag
if drag:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -