utils.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """!
  2. @package psmap.utils
  3. @brief utilities for wxpsmap
  4. Classes:
  5. - utils::Rect2D
  6. - utils::Rect2DPP
  7. - utils::Rect2DPS
  8. (C) 2012 by Anna Kratochvilova, and the GRASS Development Team
  9. This program is free software under the GNU General Public License
  10. (>=v2). Read the file COPYING that comes with GRASS for details.
  11. @author Anna Kratochvilova <kratochanna gmail.com>
  12. """
  13. import wx
  14. class Rect2D(wx.Rect2D):
  15. """!Class representing rectangle with floating point values.
  16. Overrides wx.Rect2D to unify Rect access methods, which are
  17. different (e.g. wx.Rect.GetTopLeft() x wx.Rect2D.GetLeftTop()).
  18. More methods can be added depending on needs.
  19. """
  20. def __init__(self, x = 0, y = 0, width = 0, height = 0):
  21. wx.Rect2D.__init__(self, x = x, y = y, w = width, h = height)
  22. def GetX(self):
  23. return self.x
  24. def GetY(self):
  25. return self.y
  26. def GetWidth(self):
  27. return self.width
  28. def SetWidth(self, width):
  29. self.width = width
  30. def GetHeight(self):
  31. return self.height
  32. def SetHeight(self, height):
  33. self.height = height
  34. class Rect2DPP(Rect2D):
  35. """!Rectangle specified by 2 points (with floating point values).
  36. @see Rect2D, Rect2DPS
  37. """
  38. def __init__(self, topLeft = wx.Point2D(), bottomRight = wx.Point2D()):
  39. Rect2D.__init__(self, x = 0, y = 0, width = 0, height = 0)
  40. x1, y1 = topLeft[0], topLeft[1]
  41. x2, y2 = bottomRight[0], bottomRight[1]
  42. self.SetLeft(min(x1, x2))
  43. self.SetTop(min(y1, y2))
  44. self.SetRight(max(x1, x2))
  45. self.SetBottom(max(y1, y2))
  46. class Rect2DPS(Rect2D):
  47. """!Rectangle specified by point and size (with floating point values).
  48. @see Rect2D, Rect2DPP
  49. """
  50. def __init__(self, pos = wx.Point2D(), size = (0, 0)):
  51. Rect2D.__init__(self, x = pos[0], y = pos[1], width = size[0], height = size[1])