]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/mac/gdi.py
Committing in .
[wxWidgets.git] / wxPython / src / mac / gdi.py
index c79782389b7bed448a510cbaf64553a84639335f..792e9fb40d08db939a1c69810f60820d8c6b62c6 100644 (file)
@@ -4,13 +4,17 @@ import gdic
 from misc import *
 
 from fonts import *
+import wx
 class wxGDIObjectPtr(wxObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxGDIObject(self)
+    def __del__(self, delfunc=gdic.delete_wxGDIObject):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def GetVisible(self, *_args, **_kwargs):
         val = apply(gdic.wxGDIObject_GetVisible,(self,) + _args, _kwargs)
         return val
@@ -34,9 +38,12 @@ class wxBitmapPtr(wxGDIObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxBitmap(self)
+    def __del__(self, delfunc=gdic.delete_wxBitmap):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def GetPalette(self, *_args, **_kwargs):
         val = apply(gdic.wxBitmap_GetPalette,(self,) + _args, _kwargs)
         if val: val = wxPalettePtr(val) 
@@ -85,13 +92,10 @@ class wxBitmapPtr(wxGDIObjectPtr):
     def __repr__(self):
         return "<C wxBitmap instance at %s>" % (self.this,)
     
-    def __del__(self,gdic=gdic):
-        try:
-            if self.thisown == 1 :
-                gdic.delete_wxBitmap(self)
-        except:
-            pass
-
+    def SetMaskColour(self, colour):
+        mask = wxMaskColour(self, colour)
+        self.SetMask(mask)
+    
 class wxBitmap(wxBitmapPtr):
     def __init__(self,*_args,**_kwargs):
         self.this = apply(gdic.new_wxBitmap,_args,_kwargs)
@@ -121,9 +125,12 @@ class wxIconPtr(wxGDIObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxIcon(self)
+    def __del__(self, delfunc=gdic.delete_wxIcon):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def Ok(self, *_args, **_kwargs):
         val = apply(gdic.wxIcon_Ok,(self,) + _args, _kwargs)
         return val
@@ -150,14 +157,6 @@ class wxIconPtr(wxGDIObjectPtr):
         return val
     def __repr__(self):
         return "<C wxIcon instance at %s>" % (self.this,)
-    
-    def __del__(self,gdic=gdic):
-        try:
-            if self.thisown == 1 :
-                gdic.delete_wxIcon(self)
-        except:
-            pass
-
 class wxIcon(wxIconPtr):
     def __init__(self,*_args,**_kwargs):
         self.this = apply(gdic.new_wxIcon,_args,_kwargs)
@@ -170,9 +169,12 @@ class wxIconBundlePtr :
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxIconBundle(self)
+    def __del__(self, delfunc=gdic.delete_wxIconBundle):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def AddIcon(self, *_args, **_kwargs):
         val = apply(gdic.wxIconBundle_AddIcon,(self,) + _args, _kwargs)
         return val
@@ -207,9 +209,12 @@ class wxCursorPtr(wxGDIObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxCursor(self)
+    def __del__(self, delfunc=gdic.delete_wxCursor):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def Ok(self, *_args, **_kwargs):
         val = apply(gdic.wxCursor_Ok,(self,) + _args, _kwargs)
         return val
@@ -226,9 +231,12 @@ class wxColourPtr(wxObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxColour(self)
+    def __del__(self, delfunc=gdic.delete_wxColour):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def Red(self, *_args, **_kwargs):
         val = apply(gdic.wxColour_Red,(self,) + _args, _kwargs)
         return val
@@ -247,11 +255,22 @@ class wxColourPtr(wxObjectPtr):
     def Get(self, *_args, **_kwargs):
         val = apply(gdic.wxColour_Get,(self,) + _args, _kwargs)
         return val
+    def __eq__(self, *_args, **_kwargs):
+        val = apply(gdic.wxColour___eq__,(self,) + _args, _kwargs)
+        return val
+    def __ne__(self, *_args, **_kwargs):
+        val = apply(gdic.wxColour___ne__,(self,) + _args, _kwargs)
+        return val
     def __repr__(self):
         return "<C wxColour instance at %s>" % (self.this,)
     asTuple = Get
-    def __str__(self): return str(self.asTuple())
-    def __repr__(self): return str(self.asTuple())
+    def __str__(self):                  return str(self.asTuple())
+    def __repr__(self):                 return 'wxColour:' + str(self.asTuple())
+    def __nonzero__(self):              return self.Ok()
+    def __getinitargs__(self):          return ()
+    def __getstate__(self):             return self.asTuple()
+    def __setstate__(self, state):      self.Set(*state)
+
 class wxColour(wxColourPtr):
     def __init__(self,*_args,**_kwargs):
         self.this = apply(gdic.new_wxColour,_args,_kwargs)
@@ -287,9 +306,12 @@ class wxPenPtr(wxGDIObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxPen(self)
+    def __del__(self, delfunc=gdic.delete_wxPen):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def GetCap(self, *_args, **_kwargs):
         val = apply(gdic.wxPen_GetCap,(self,) + _args, _kwargs)
         return val
@@ -327,6 +349,9 @@ class wxPenPtr(wxGDIObjectPtr):
     def SetDashes(self, *_args, **_kwargs):
         val = apply(gdic.wxPen_SetDashes,(self,) + _args, _kwargs)
         return val
+    def GetDashes(self, *_args, **_kwargs):
+        val = apply(gdic.wxPen_GetDashes,(self,) + _args, _kwargs)
+        return val
     def __repr__(self):
         return "<C wxPen instance at %s>" % (self.this,)
 class wxPen(wxPenPtr):
@@ -341,9 +366,12 @@ class wxPyPenPtr(wxPenPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxPyPen(self)
+    def __del__(self, delfunc=gdic.delete_wxPyPen):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def SetDashes(self, *_args, **_kwargs):
         val = apply(gdic.wxPyPen_SetDashes,(self,) + _args, _kwargs)
         return val
@@ -387,9 +415,12 @@ class wxBrushPtr(wxGDIObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxBrush(self)
+    def __del__(self, delfunc=gdic.delete_wxBrush):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def GetColour(self, *_args, **_kwargs):
         val = apply(gdic.wxBrush_GetColour,(self,) + _args, _kwargs)
         if val: val = wxColourPtr(val) ; val.thisown = 1
@@ -453,9 +484,12 @@ class wxDCPtr(wxObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxDC(self)
+    def __del__(self, delfunc=gdic.delete_wxDC):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def BeginDrawing(self, *_args, **_kwargs):
         val = apply(gdic.wxDC_BeginDrawing,(self,) + _args, _kwargs)
         return val
@@ -520,6 +554,9 @@ class wxDCPtr(wxObjectPtr):
     def DrawRectangle(self, *_args, **_kwargs):
         val = apply(gdic.wxDC_DrawRectangle,(self,) + _args, _kwargs)
         return val
+    def DrawRectangleRect(self, *_args, **_kwargs):
+        val = apply(gdic.wxDC_DrawRectangleRect,(self,) + _args, _kwargs)
+        return val
     def DrawRotatedText(self, *_args, **_kwargs):
         val = apply(gdic.wxDC_DrawRotatedText,(self,) + _args, _kwargs)
         return val
@@ -606,6 +643,9 @@ class wxDCPtr(wxObjectPtr):
     def GetFullTextExtent(self, *_args, **_kwargs):
         val = apply(gdic.wxDC_GetFullTextExtent,(self,) + _args, _kwargs)
         return val
+    def GetMultiLineTextExtent(self, *_args, **_kwargs):
+        val = apply(gdic.wxDC_GetMultiLineTextExtent,(self,) + _args, _kwargs)
+        return val
     def GetTextForeground(self, *_args, **_kwargs):
         val = apply(gdic.wxDC_GetTextForeground,(self,) + _args, _kwargs)
         if val: val = wxColourPtr(val) ; val.thisown = 1
@@ -655,6 +695,9 @@ class wxDCPtr(wxObjectPtr):
     def SetClippingRegionAsRegion(self, *_args, **_kwargs):
         val = apply(gdic.wxDC_SetClippingRegionAsRegion,(self,) + _args, _kwargs)
         return val
+    def SetClippingRect(self, *_args, **_kwargs):
+        val = apply(gdic.wxDC_SetClippingRect,(self,) + _args, _kwargs)
+        return val
     def SetPalette(self, *_args, **_kwargs):
         val = apply(gdic.wxDC_SetPalette,(self,) + _args, _kwargs)
         return val
@@ -737,6 +780,18 @@ class wxDCPtr(wxObjectPtr):
     def _DrawLineList(self, *_args, **_kwargs):
         val = apply(gdic.wxDC__DrawLineList,(self,) + _args, _kwargs)
         return val
+    def _DrawRectangleList(self, *_args, **_kwargs):
+        val = apply(gdic.wxDC__DrawRectangleList,(self,) + _args, _kwargs)
+        return val
+    def _DrawEllipseList(self, *_args, **_kwargs):
+        val = apply(gdic.wxDC__DrawEllipseList,(self,) + _args, _kwargs)
+        return val
+    def _DrawPolygonList(self, *_args, **_kwargs):
+        val = apply(gdic.wxDC__DrawPolygonList,(self,) + _args, _kwargs)
+        return val
+    def _DrawTextList(self, *_args, **_kwargs):
+        val = apply(gdic.wxDC__DrawTextList,(self,) + _args, _kwargs)
+        return val
     def __repr__(self):
         return "<C wxDC instance at %s>" % (self.this,)
     
@@ -747,7 +802,8 @@ class wxDCPtr(wxObjectPtr):
            pens = [pens]
         elif len(pens) != len(points):
            raise ValueError('points and pens must have same length')
-        return self._DrawPointList(points, pens)
+        return self._DrawPointList(points, pens, [])
+
 
     def DrawLineList(self, lines, pens=None):
         if pens is None:
@@ -756,7 +812,83 @@ class wxDCPtr(wxObjectPtr):
            pens = [pens]
         elif len(pens) != len(lines):
            raise ValueError('lines and pens must have same length')
-        return self._DrawLineList(lines, pens)
+        return self._DrawLineList(lines, pens, [])
+
+
+    def DrawRectangleList(self, rectangles, pens=None, brushes=None):
+        if pens is None:
+           pens = []
+        elif isinstance(pens, wxPenPtr):
+           pens = [pens]
+        elif len(pens) != len(rectangles):
+           raise ValueError('rectangles and pens must have same length')
+        if brushes is None:
+           brushes = []
+        elif isinstance(brushes, wxBrushPtr):
+           brushes = [brushes]
+        elif len(brushes) != len(rectangles):
+           raise ValueError('rectangles and brushes must have same length')
+        return self._DrawRectangleList(rectangles, pens, brushes)
+
+
+    def DrawEllipseList(self, ellipses, pens=None, brushes=None):
+        if pens is None:
+           pens = []
+        elif isinstance(pens, wxPenPtr):
+           pens = [pens]
+        elif len(pens) != len(ellipses):
+           raise ValueError('ellipses and pens must have same length')
+        if brushes is None:
+           brushes = []
+        elif isinstance(brushes, wxBrushPtr):
+           brushes = [brushes]
+        elif len(brushes) != len(ellipses):
+           raise ValueError('ellipses and brushes must have same length')
+        return self._DrawEllipseList(ellipses, pens, brushes)
+
+
+    def DrawPolygonList(self, polygons, pens=None, brushes=None):
+        ## Note: This does not currently support fill style or offset
+        ## you can always use the non-List version if need be.
+        ## I really would like to support fill-style, however,
+        ## but wxODDEVEN_RULE does not appear to be defined at the Python level
+        ## [It's in wx.py... --Robin]
+        if pens is None:
+           pens = []
+        elif isinstance(pens, wxPenPtr):
+           pens = [pens]
+        elif len(pens) != len(polygons):
+           raise ValueError('polygons and pens must have same length')
+        if brushes is None:
+           brushes = []
+        elif isinstance(brushes, wxBrushPtr):
+           brushes = [brushes]
+        elif len(brushes) != len(polygons):
+           raise ValueError('polygons and brushes must have same length')
+        return self._DrawPolygonList(polygons, pens, brushes)
+
+
+    def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None, fonts = None):
+        ## NOTE: this does not currently support changing the font
+        ##       Make sure you set Background mode to wxSolid (DC.SetBackgroundMode)
+        ##       If you want backgounds to do anything.
+        if type(textList) == type(''):
+           textList = [textList]
+        elif len(textList) != len(coords):
+           raise ValueError('textlist and coords must have same length')
+        if foregrounds is None:
+           foregrounds = []
+        elif isinstance(foregrounds, wxColourPtr):
+           foregrounds = [foregrounds]
+        elif len(foregrounds) != len(coords):
+           raise ValueError('foregrounds and coords must have same length')
+        if backgrounds is None:
+           backgrounds = []
+        elif isinstance(backgrounds, wxColourPtr):
+           backgrounds = [backgrounds]
+        elif len(backgrounds) != len(coords):
+           raise ValueError('backgrounds and coords must have same length')
+        return  self._DrawTextList(textList, coords, foregrounds, backgrounds)
 
 class wxDC(wxDCPtr):
     def __init__(self,this):
@@ -786,18 +918,23 @@ class wxBufferedDCPtr(wxMemoryDCPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
+    def UnMask(self, *_args, **_kwargs):
+        val = apply(gdic.wxBufferedDC_UnMask,(self,) + _args, _kwargs)
+        return val
     def __repr__(self):
         return "<C wxBufferedDC instance at %s>" % (self.this,)
 class wxBufferedDC(wxBufferedDCPtr):
     def __init__(self,*_args,**_kwargs):
         self.this = apply(gdic.new_wxBufferedDC,_args,_kwargs)
         self.thisown = 1
+        self._dc = _args[0] # save a ref so the other dc won't be deleted before self
 
 
 
 def wxBufferedDCInternalBuffer(*_args,**_kwargs):
     val = wxBufferedDCPtr(apply(gdic.new_wxBufferedDCInternalBuffer,_args,_kwargs))
     val.thisown = 1
+    val._dc = _args[0] # save a ref so the other dc won't be deleted before self
     return val
 
 
@@ -884,9 +1021,12 @@ class wxPalettePtr(wxGDIObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxPalette(self)
+    def __del__(self, delfunc=gdic.delete_wxPalette):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def GetPixel(self, *_args, **_kwargs):
         val = apply(gdic.wxPalette_GetPixel,(self,) + _args, _kwargs)
         return val
@@ -910,9 +1050,12 @@ class wxImageListPtr(wxObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxImageList(self)
+    def __del__(self, delfunc=gdic.delete_wxImageList):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def Add(self, *_args, **_kwargs):
         val = apply(gdic.wxImageList_Add,(self,) + _args, _kwargs)
         return val
@@ -954,9 +1097,12 @@ class wxRegionPtr(wxGDIObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxRegion(self)
+    def __del__(self, delfunc=gdic.delete_wxRegion):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def Clear(self, *_args, **_kwargs):
         val = apply(gdic.wxRegion_Clear,(self,) + _args, _kwargs)
         return val
@@ -1029,9 +1175,12 @@ class wxRegionIteratorPtr(wxObjectPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
-    def __del__(self,gdic=gdic):
-        if self.thisown == 1 :
-            gdic.delete_wxRegionIterator(self)
+    def __del__(self, delfunc=gdic.delete_wxRegionIterator):
+        if self.thisown == 1:
+            try:
+                delfunc(self)
+            except:
+                pass
     def GetX(self, *_args, **_kwargs):
         val = apply(gdic.wxRegionIterator_GetX,(self,) + _args, _kwargs)
         return val
@@ -1122,6 +1271,11 @@ def wxStockCursor(*_args, **_kwargs):
     if val: val = wxCursorPtr(val); val.thisown = 1
     return val
 
+def wxCursorFromImage(*_args, **_kwargs):
+    val = apply(gdic.wxCursorFromImage,_args,_kwargs)
+    if val: val = wxCursorPtr(val); val.thisown = 1
+    return val
+
 def wxNamedColour(*_args, **_kwargs):
     val = apply(gdic.wxNamedColour,_args,_kwargs)
     if val: val = wxColourPtr(val); val.thisown = 1