Translation update done using Pootle.
[wammu.git] / Wammu / Image.py
blobd0f22627f7f29cb6a74ae52687e411e8a9ed8337
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 Image displaying classes to be embdeded inside wxHTML
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2010 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 '''
26 import wx
27 import wx.lib.throbber
28 import base64
30 defaultbmp = [
31 '20 20 2 1',
32 '. c Black',
33 ' c None',
34 ' ',
35 ' .. .. ',
36 ' ... ... ',
37 ' ... ... ',
38 ' ... ... ',
39 ' ... ... ',
40 ' ... ... ',
41 ' ... ... ',
42 ' ...... ',
43 ' .... ',
44 ' .... ',
45 ' ...... ',
46 ' ... ... ',
47 ' ... ... ',
48 ' ... ... ',
49 ' ... ... ',
50 ' ... ... ',
51 ' ... ... ',
52 ' .. .. ',
53 ' ']
55 class MemoryInputStream(wx.InputStream):
56 def __init__(self, data):
57 import cStringIO
58 wx.InputStream.__init__(self,cStringIO.StringIO(data))
60 class EncodedBitmap(wx.StaticBitmap):
61 def __init__(self, parent, tooltip = 'Image', image = defaultbmp, size = None, scale = 1):
62 image = wx.ImageFromStream(MemoryInputStream(base64.b64decode(image)))
63 if scale > 1:
64 bitmap = wx.BitmapFromImage(image.Scale(bitmap.GetWidth() * scale, bitmap.GetHeight() * scale))
65 else:
66 bitmap = wx.BitmapFromImage(image)
67 wx.StaticBitmap.__init__(self, parent, -1, bitmap, (0,0))
68 self.SetToolTipString(tooltip)
70 class Bitmap(wx.StaticBitmap):
71 def __init__(self, parent, tooltip = 'Image', image = defaultbmp, size = None, scale = 1):
72 bitmap = wx.BitmapFromXPMData(image)
73 if scale > 1:
74 img = wx.ImageFromBitmap(bitmap)
75 bitmap = wx.BitmapFromImage(img.Scale(bitmap.GetWidth() * scale, bitmap.GetHeight() * scale))
76 wx.StaticBitmap.__init__(self, parent, -1, bitmap, (0,0))
77 self.SetToolTipString(tooltip)
79 class Throbber(wx.lib.throbber.Throbber):
80 def __init__(self, parent, tooltip = 'Animation', images = [defaultbmp], size = None, scale = 1, delay = 0.1):
81 bitmaps = []
82 for im in images:
83 bitmap = wx.BitmapFromXPMData(im)
84 if scale > 1:
85 img = wx.ImageFromBitmap(bitmap)
86 bitmap = wx.BitmapFromImage(img.Scale(bitmap.GetWidth() * scale, bitmap.GetHeight() * scale))
87 bitmaps.append(bitmap)
88 wx.lib.throbber.Throbber.__init__(self, parent, -1, bitmaps, frameDelay = delay)
89 self.SetToolTipString(tooltip)