From 5a61dbfb8a13ea4697abf5f5e0775db0a829f2de Mon Sep 17 00:00:00 2001 From: Werner F Bruhin Date: Wed, 11 Jun 2014 12:35:31 +0200 Subject: [PATCH] - add a unittest - get it to run on Py2.7 and Py3.3 - add flags --- demo/OGL.py | 1 - unittests/test_lib_ogl.py | 83 +++++++++++++++++++++++++++++++++++++++ wx/lib/ogl/__init__.py | 25 ++++-------- wx/lib/ogl/_basic.py | 15 ++++--- wx/lib/ogl/_bmpshape.py | 11 ++++-- wx/lib/ogl/_canvas.py | 18 +++++---- wx/lib/ogl/_composit.py | 32 ++++----------- wx/lib/ogl/_diagram.py | 8 +++- wx/lib/ogl/_divided.py | 13 +++--- wx/lib/ogl/_drawn.py | 13 +++--- wx/lib/ogl/_lines.py | 13 +++--- wx/lib/ogl/_oglmisc.py | 8 +++- 12 files changed, 163 insertions(+), 77 deletions(-) create mode 100644 unittests/test_lib_ogl.py diff --git a/demo/OGL.py b/demo/OGL.py index c15a5db3..eeea932d 100644 --- a/demo/OGL.py +++ b/demo/OGL.py @@ -183,7 +183,6 @@ class DividedShape(ogl.DividedShape): def OnSizingEndDragLeft(self, pt, x, y, keys, attch): - print "***", self ogl.DividedShape.OnSizingEndDragLeft(self, pt, x, y, keys, attch) self.SetRegionSizes() self.ReformatRegions() diff --git a/unittests/test_lib_ogl.py b/unittests/test_lib_ogl.py new file mode 100644 index 00000000..9e81fba8 --- /dev/null +++ b/unittests/test_lib_ogl.py @@ -0,0 +1,83 @@ +import imp_unittest, unittest +import wtc +import wx + +import wx.lib.ogl as ogl + + + +class lib_ogl_Tests(wtc.WidgetTestCase): + + def test_lib_oglCtor(self): + ogl.OGLInitialize() + osc = ogl.ShapeCanvas(self.frame) + self.diagram = ogl.Diagram() + osc.SetDiagram(self.diagram) + self.diagram.SetCanvas(osc) + + aShape = ogl.RectangleShape(w=50, h=50) + aShape.SetCanvas(osc) + self.diagram.AddShape(aShape) + + region1 = ogl.ShapeRegion() + region1.SetText('DividedShape') + region1.SetProportions(0.0, 0.2) + region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ) + aShape.AddRegion(region1) + + + def test_lib_ogl_Constants(self): + ogl.CONSTRAINT_CENTRED_VERTICALLY + ogl.CONSTRAINT_CENTRED_HORIZONTALLY + ogl.CONSTRAINT_CENTRED_BOTH + ogl.CONSTRAINT_LEFT_OF + ogl.CONSTRAINT_RIGHT_OF + ogl.CONSTRAINT_ABOVE + ogl.CONSTRAINT_BELOW + ogl.CONSTRAINT_ALIGNED_TOP + ogl.CONSTRAINT_ALIGNED_BOTTOM + ogl.CONSTRAINT_ALIGNED_LEFT + ogl.CONSTRAINT_ALIGNED_RIGHT + + # Like aligned, but with the objects centred on the respective edge + # of the reference object. + ogl.CONSTRAINT_MIDALIGNED_TOP + ogl.CONSTRAINT_MIDALIGNED_BOTTOM + ogl.CONSTRAINT_MIDALIGNED_LEFT + ogl.CONSTRAINT_MIDALIGNED_RIGHT + + # from _drawn + ogl.METAFLAGS_OUTLINE + ogl.METAFLAGS_ATTACHMENTS + + ogl.DRAWN_ANGLE_0 + ogl.DRAWN_ANGLE_90 + ogl.DRAWN_ANGLE_180 + ogl.DRAWN_ANGLE_270 + + # Drawing operations + ogl.DRAWOP_SET_PEN + ogl.DRAWOP_SET_BRUSH + ogl.DRAWOP_SET_FONT + ogl.DRAWOP_SET_TEXT_COLOUR + ogl.DRAWOP_SET_BK_COLOUR + ogl.DRAWOP_SET_BK_MODE + ogl.DRAWOP_SET_CLIPPING_RECT + ogl.DRAWOP_DESTROY_CLIPPING_RECT + + ogl.DRAWOP_DRAW_LINE + ogl.DRAWOP_DRAW_POLYLINE + ogl.DRAWOP_DRAW_POLYGON + ogl.DRAWOP_DRAW_RECT + ogl.DRAWOP_DRAW_ROUNDED_RECT + ogl.DRAWOP_DRAW_ELLIPSE + ogl.DRAWOP_DRAW_POINT + ogl.DRAWOP_DRAW_ARC + ogl.DRAWOP_DRAW_TEXT + ogl.DRAWOP_DRAW_SPLINE + ogl.DRAWOP_DRAW_ELLIPTIC_ARC + +#--------------------------------------------------------------------------- + +if __name__ == '__main__': + unittest.main() diff --git a/wx/lib/ogl/__init__.py b/wx/lib/ogl/__init__.py index 4629b2c6..7a8df2d4 100644 --- a/wx/lib/ogl/__init__.py +++ b/wx/lib/ogl/__init__.py @@ -3,20 +3,11 @@ The Object Graphics Library provides for simple drawing and manipulation of 2D objects. """ -from _basic import * -from _diagram import * -from _canvas import * -from _lines import * -from _bmpshape import * -from _divided import * -from _composit import * -from _drawn import * - - -# Set things up for documenting with epydoc. The __docfilter__ will -# prevent some things from being documented, and anything in __all__ -# will appear to actually exist in this module. -import wx._core as _wx -__docfilter__ = _wx.__DocFilter(globals()) -__all__ = [name for name in dir() if not name.startswith('_')] - +from ._basic import * +from ._diagram import * +from ._canvas import * +from ._lines import * +from ._bmpshape import * +from ._divided import * +from ._composit import * +from ._drawn import * diff --git a/wx/lib/ogl/_basic.py b/wx/lib/ogl/_basic.py index 4e9e44f3..094988dc 100644 --- a/wx/lib/ogl/_basic.py +++ b/wx/lib/ogl/_basic.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*-# +#!/usr/bin/env python #---------------------------------------------------------------------------- # Name: basic.py # Purpose: The basic OGL shapes @@ -8,12 +9,16 @@ # Created: 2004-05-08 # Copyright: (c) 2004 Pierre Hjälm - 1998 Julian Smart # Licence: wxWindows license +# Tags: phoenix-port, unittest, py3-port #---------------------------------------------------------------------------- +""" +The basic shapes for OGL +""" import wx import math -from _oglmisc import * +from ._oglmisc import * DragOffsetX = 0.0 DragOffsetY = 0.0 @@ -3173,6 +3178,6 @@ class PolygonControlPoint(ControlPoint): def OnEndDragLeft(self, x, y, keys = 0, attachment = 0): self._shape.GetEventHandler().OnSizingEndDragLeft(self, x, y, keys, attachment) -from _canvas import * -from _lines import * -from _composit import * +from ._canvas import * +from ._lines import * +from ._composit import * diff --git a/wx/lib/ogl/_bmpshape.py b/wx/lib/ogl/_bmpshape.py index 579b2900..0c83ff13 100644 --- a/wx/lib/ogl/_bmpshape.py +++ b/wx/lib/ogl/_bmpshape.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*-# +#!/usr/bin/env python #---------------------------------------------------------------------------- # Name: bmpshape.py # Purpose: Bitmap shape @@ -8,10 +9,12 @@ # Created: 2004-05-08 # Copyright: (c) 2004 Pierre Hjälm - 1998 Julian Smart # Licence: wxWindows license -# Tags: phoenix-port +# Tags: phoenix-port, unittest, py3-port #---------------------------------------------------------------------------- - -from _basic import RectangleShape +""" +The OGL Bitmap shape +""" +from ._basic import RectangleShape class BitmapShape(RectangleShape): diff --git a/wx/lib/ogl/_canvas.py b/wx/lib/ogl/_canvas.py index 5e1acc80..7a6dc59e 100644 --- a/wx/lib/ogl/_canvas.py +++ b/wx/lib/ogl/_canvas.py @@ -1,6 +1,7 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*-# +#!/usr/bin/env python #---------------------------------------------------------------------------- -# Name: canvas.py +# Name: _canvas.py # Purpose: The canvas class # # Author: Pierre Hjälm (from C++ original by Julian Smart) @@ -8,11 +9,14 @@ # Created: 2004-05-08 # Copyright: (c) 2004 Pierre Hjälm - 1998 Julian Smart # Licence: wxWindows license +# Tags: phoenix-port, unittest, py3-port #---------------------------------------------------------------------------- - +""" +The OGL canvas class +""" import wx -from _lines import LineShape -from _composit import * +from ._lines import LineShape +from ._composit import * NoDragging, StartDraggingLeft, ContinueDraggingLeft, StartDraggingRight, ContinueDraggingRight = 0, 1, 2, 3, 4 @@ -55,8 +59,8 @@ class ShapeCanvas(wx.ScrolledWindow): self._firstDragY = 0 self._checkTolerance = True - wx.EVT_PAINT(self, self.OnPaint) - wx.EVT_MOUSE_EVENTS(self, self.OnMouseEvent) + self.Bind(wx.EVT_PAINT, self.OnPaint) + self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseEvent) def SetDiagram(self, diag): self._shapeDiagram = diag diff --git a/wx/lib/ogl/_composit.py b/wx/lib/ogl/_composit.py index 9b0e5590..f89c8175 100644 --- a/wx/lib/ogl/_composit.py +++ b/wx/lib/ogl/_composit.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*-# +#!/usr/bin/env python #---------------------------------------------------------------------------- # Name: composit.py # Purpose: Composite class @@ -8,14 +9,16 @@ # Created: 2004-05-08 # Copyright: (c) 2004 Pierre Hjälm - 1998 Julian Smart # Licence: wxWindows license -# Tags: phoenix-port +# Tags: phoenix-port, unittest, py3-port #---------------------------------------------------------------------------- - +""" +The OGL composite class. +""" import sys import wx -from _basic import RectangleShape, Shape, ControlPoint -from _oglmisc import * +from ._basic import RectangleShape, Shape, ControlPoint +from ._oglmisc import * KEY_SHIFT, KEY_CTRL = 1, 2 @@ -42,25 +45,6 @@ CONSTRAINT_MIDALIGNED_LEFT = 14 CONSTRAINT_MIDALIGNED_RIGHT = 15 -# Backwards compatibility names. These should be removed eventually. -gyCONSTRAINT_CENTRED_VERTICALLY = CONSTRAINT_CENTRED_VERTICALLY -gyCONSTRAINT_CENTRED_HORIZONTALLY = CONSTRAINT_CENTRED_HORIZONTALLY -gyCONSTRAINT_CENTRED_BOTH = CONSTRAINT_CENTRED_BOTH -gyCONSTRAINT_LEFT_OF = CONSTRAINT_LEFT_OF -gyCONSTRAINT_RIGHT_OF = CONSTRAINT_RIGHT_OF -gyCONSTRAINT_ABOVE = CONSTRAINT_ABOVE -gyCONSTRAINT_BELOW = CONSTRAINT_BELOW -gyCONSTRAINT_ALIGNED_TOP = CONSTRAINT_ALIGNED_TOP -gyCONSTRAINT_ALIGNED_BOTTOM = CONSTRAINT_ALIGNED_BOTTOM -gyCONSTRAINT_ALIGNED_LEFT = CONSTRAINT_ALIGNED_LEFT -gyCONSTRAINT_ALIGNED_RIGHT = CONSTRAINT_ALIGNED_RIGHT -gyCONSTRAINT_MIDALIGNED_TOP = CONSTRAINT_MIDALIGNED_TOP -gyCONSTRAINT_MIDALIGNED_BOTTOM = CONSTRAINT_MIDALIGNED_BOTTOM -gyCONSTRAINT_MIDALIGNED_LEFT = CONSTRAINT_MIDALIGNED_LEFT -gyCONSTRAINT_MIDALIGNED_RIGHT = CONSTRAINT_MIDALIGNED_RIGHT - - - class ConstraintType(object): def __init__(self, theType, theName, thePhrase): self._type = theType diff --git a/wx/lib/ogl/_diagram.py b/wx/lib/ogl/_diagram.py index 37f42be7..e5ec2466 100644 --- a/wx/lib/ogl/_diagram.py +++ b/wx/lib/ogl/_diagram.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*-# +#!/usr/bin/env python #---------------------------------------------------------------------------- # Name: diagram.py # Purpose: Diagram class @@ -8,8 +9,11 @@ # Created: 2004-05-08 # Copyright: (c) 2004 Pierre Hjälm - 1998 Julian Smart # Licence: wxWindows license +# Tags: phoenix-port, unittest, py3-port #---------------------------------------------------------------------------- - +""" +The OGL diagram class. +""" import wx DEFAULT_MOUSE_TOLERANCE = 3 diff --git a/wx/lib/ogl/_divided.py b/wx/lib/ogl/_divided.py index 8219cd9a..71719ad6 100644 --- a/wx/lib/ogl/_divided.py +++ b/wx/lib/ogl/_divided.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*-# +#!/usr/bin/env python #---------------------------------------------------------------------------- # Name: divided.py # Purpose: DividedShape class @@ -8,14 +9,16 @@ # Created: 2004-05-08 # Copyright: (c) 2004 Pierre Hjälm - 1998 Julian Smart # Licence: wxWindows license -# Tags: phoenix-port +# Tags: phoenix-port, unittest, py3-port #---------------------------------------------------------------------------- - +""" +The OGL divided shape class. +""" import sys import wx -from _basic import ControlPoint, RectangleShape, Shape -from _oglmisc import * +from ._basic import ControlPoint, RectangleShape, Shape +from ._oglmisc import * diff --git a/wx/lib/ogl/_drawn.py b/wx/lib/ogl/_drawn.py index be500610..bf201408 100644 --- a/wx/lib/ogl/_drawn.py +++ b/wx/lib/ogl/_drawn.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*-# +#!/usr/bin/env python #---------------------------------------------------------------------------- # Name: drawn.py # Purpose: DrawnShape class @@ -8,13 +9,15 @@ # Created: 2004-08-25 # Copyright: (c) 2004 Pierre Hjälm - 1998 Julian Smart # License: wxWindows license -# Tags: phoenix-port +# Tags: phoenix-port, unittest, py3-port #---------------------------------------------------------------------------- - +""" +The OGL drawn shape class. +""" import os.path -from _basic import RectangleShape -from _oglmisc import * +from ._basic import RectangleShape +from ._oglmisc import * METAFLAGS_OUTLINE = 1 METAFLAGS_ATTACHMENTS = 2 diff --git a/wx/lib/ogl/_lines.py b/wx/lib/ogl/_lines.py index 90ae50a5..aa4ff02c 100644 --- a/wx/lib/ogl/_lines.py +++ b/wx/lib/ogl/_lines.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*-# +#!/usr/bin/env python #---------------------------------------------------------------------------- # Name: lines.py # Purpose: LineShape class @@ -8,14 +9,16 @@ # Created: 2004-05-08 # Copyright: (c) 2004 Pierre Hjälm - 1998 Julian Smart # Licence: wxWindows license -# Tags: phoenix-port +# Tags: phoenix-port, unittest, py3-port #---------------------------------------------------------------------------- - +""" +The OGL line shape class. +""" import sys import math -from _basic import Shape, ShapeRegion, ShapeTextLine, ControlPoint, RectangleShape -from _oglmisc import * +from ._basic import Shape, ShapeRegion, ShapeTextLine, ControlPoint, RectangleShape +from ._oglmisc import * # Line alignment flags # Vertical by default diff --git a/wx/lib/ogl/_oglmisc.py b/wx/lib/ogl/_oglmisc.py index 71842f66..f1be6b42 100644 --- a/wx/lib/ogl/_oglmisc.py +++ b/wx/lib/ogl/_oglmisc.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*-# +#!/usr/bin/env python #---------------------------------------------------------------------------- # Name: oglmisc.py # Purpose: Miscellaneous OGL support functions @@ -8,8 +9,11 @@ # Created: 2004-05-08 # Copyright: (c) 2004 Pierre Hjälm - 1998 Julian Smart # Licence: wxWindows license +# Tags: phoenix-port, unittest, py3-port #---------------------------------------------------------------------------- - +""" +The OGL miscellaneous support functions. +""" import math import wx