Package teamwork :: Package examples :: Package Thespian :: Module gifimage
[hide private]
[frames] | no frames]

Source Code for Module teamwork.examples.Thespian.gifimage

  1  
 
  2  """
 
  3  __version__ = "$Revision: 1.24 $"
 
  4  __date__ = "$Date: 2004/08/11 01:58:03 $"
 
  5  """ 
  6  
 
  7  import wx 
  8  import wx.animate 
  9  
 
 10  from PythonCard import event, graphic, widget 
 11  
 
 12  USE_GENERIC = wx.Platform == '__WXGTK__' 
 13  
 
 14  GIFAnimationCtrl = wx.animate.GIFAnimationCtrl 
15 -class GifImageSpec(widget.WidgetSpec):
16 - def __init__(self):
17 events = [] 18 attributes = { 19 'file' : { 'presence' : 'optional', 'default':'' }, 20 # KEA shouldn't there be a 'file' attribute here 21 # could call it 'image' to match background above 22 # but it is mandatory 23 #'bitmap' : { 'presence' : 'optional', 'default' : None }, 24 # KEA kill border for now, until variations of what is possible are worked out 25 # use ImageButton if you want images with transparent border 26 #'border' : { 'presence' : 'optional', 'default' : '3d', 'values' : [ '3d', 'transparent', 'none' ] }, 27 'size' : { 'presence' : 'optional', 'default' : [ -1, -1 ] }, 28 } 29 widget.WidgetSpec.__init__( self, 'GifImage', 'Widget', events, attributes )
30 31
32 -class GifImage(widget.Widget, GIFAnimationCtrl):
33 """ 34 gif image. 35 """ 36 37 _spec = GifImageSpec() 38
39 - def __init__(self, aParent, aResource):
40 self._file = aResource.file 41 42 self._size = tuple(aResource.size) 43 w = aResource.size[0] 44 if w == -2: 45 w = self._bitmap.getWidth() 46 h = aResource.size[1] 47 if h == -2: 48 h = self._bitmap.getHeight() 49 size = (w, h) 50 #size = wx.Size( self._bitmap.GetWidth(), self._bitmap.GetHeight() ) 51 52 ##if aResource.border == 'transparent': 53 ## mask = wx.MaskColour(self._bitmap, wxBLACK) 54 ## self._bitmap.SetMask(mask) 55 56 ## StaticBitmap.__init__( 57 ## self, 58 ## aParent, 59 ## widget.makeNewId(aResource.id), 60 ## self._bitmap.getBits(), 61 ## aResource.position, 62 ## size, 63 ## style = wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_SIBLINGS, 64 ## name = aResource.name 65 ## ) 66 67 GIFAnimationCtrl.__init__( 68 self, 69 aParent, 70 widget.makeNewId(aResource.id), 71 self._file, 72 aResource.position, 73 size, 74 style = wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_SIBLINGS, 75 name = aResource.name 76 ) 77 78 self.Play() 79 ## GIFAnimationCtrl(self, id, ag_fname, pos=(10, 10)) 80 81 widget.Widget.__init__( self, aParent, aResource ) 82 83 wx.EVT_WINDOW_DESTROY(self, self._OnDestroy) 84 85 self._bindEvents(event.WIDGET_EVENTS)
86
87 - def _OnDestroy(self, event):
88 # memory leak cleanup 89 self._bitmap = None 90 event.Skip()
91 92 93 94 # KEA special handling for -2 size option
95 - def _setSize(self, aSize):
96 self._size = tuple(aSize) 97 w = aSize[0] 98 if w == -2: 99 w = self._bitmap.getWidth() 100 h = aSize[1] 101 if h == -2: 102 h = self._bitmap.getHeight() 103 self.SetSize((w, h))
104 105 # KEA 2001-08-02 106 # right now the image is loaded from a filename 107 # during initialization 108 # but later these might not make any sense 109 # if setBitmap is used directly in user code
110 - def _getFile( self ) :
111 return self._file
112 113 # KEA 2001-08-14 114 # if we're going to support setting the file 115 # after initialization, then this will need to handle the bitmap loading 116 # overhead
117 - def _setFile( self, aFile ) :
118 self._file = aFile 119 self._setBitmap(graphic.Bitmap(aFile))
120 121 122 123 ## backgroundColor = property(widget.Widget._getBackgroundColor, _setBackgroundColor) 124 file = property(_getFile, _setFile) 125 size = property(widget.Widget._getSize, _setSize)
126 127 128 import sys 129 from PythonCard import registry 130 registry.Registry.getInstance().register(sys.modules[__name__].GifImage) 131