fixed mem leak
[swftools.git] / wx / lib / utils.py
blob509c6be02171867ee708ec8c4e476b16cf044889
1 # coding: utf-8
2 import wx
4 def blank_bmp(w, h, color="white"):
5 bmp = wx.EmptyBitmap(max(w,1) , max(h,1))
6 clear_bmp(bmp, color)
7 return bmp
9 def clear_bmp(bmp, color):
10 dc = wx.MemoryDC()
11 dc.SelectObject(bmp)
12 dc.SetBackground(wx.Brush(color))
13 dc.Clear()
15 encodings = [
16 'UTF-8', #
17 #'US-ASCII', # (basic English)
18 #'ISO-8859-1', # (Western Europe)
19 #'ISO-8859-2', # (Central Europe)
20 #'ISO-8859-3', # (Southern Europe)
21 #'ISO-8859-4', # (Baltic)
22 #'ISO-8859-5', # (Cyrillic)
23 #'ISO-8859-6', # (Arabic)
24 #'ISO-8859-7', # (Greek)
25 #'ISO-8859-8', # (Hebrew)
26 #'ISO-8859-9', # (Turkish)
27 'ISO-8859-15', # (Latin 9)
28 #'Windows-1250', # (Central Europe)
29 #'Windows-1251', # (Cyrillic)
30 'Windows-1252', # (Western Europe)
31 #'Windows-1253', # (Greek)
32 #'Windows-1254', # (Turkish)
33 #'Windows-1255', # (Hebrew)
34 #'Windows-1256', # (Arabic)
35 #'Windows-1257', # (Baltic Rim)
36 #'Windows-1258', # (Vietnam)
37 #'SHIFT_JIS', # (Japanese, Win/Mac)
38 #'BIG5', # (Traditional Chinese)
39 #'GB18030', # (Simplified Chinese)
42 def force_unicode(s):
43 if isinstance(s, unicode):
44 return s
46 sane = repr(s)[1:-2]
47 for enc in encodings:
48 try:
49 sane = s.decode(enc)
50 break
51 except UnicodeDecodeError:
52 continue
53 return sane