1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import os.path
20
21 import wx
22
23 from timelinelib.wxgui.components.propertyeditors.baseeditor import BaseEditor
24
25
27
29 self.MAX_SIZE = (128, 128)
30
32 try:
33 image = wx.EmptyImage(0, 0)
34 success = image.LoadFile(path)
35
36 if success:
37
38 (w, h) = image.GetSize()
39 (W, H) = self.MAX_SIZE
40 if w > W:
41 factor = float(W) / float(w)
42 w = w * factor
43 h = h * factor
44 if h > H:
45 factor = float(H) / float(h)
46 w = w * factor
47 h = h * factor
48 image = image.Scale(w, h, wx.IMAGE_QUALITY_HIGH)
49 return image.ConvertToBitmap()
50 except:
51 pass
52
53
55
58
60 return wx.GridBagSizer(5, 5)
61
63 self.MAX_SIZE = (128, 128)
64 self.img_icon = self._create_icon()
65 description = self._create_description()
66 btn_select = self._create_select_button()
67 btn_clear = self._create_clear_button()
68 return (description, btn_select, btn_clear, self.img_icon)
69
71 description, btn_select, btn_clear, img_icon = controls
72 sizer.Add(description, wx.GBPosition(0, 0), wx.GBSpan(1, 2))
73 sizer.Add(btn_select, wx.GBPosition(1, 0), wx.GBSpan(1, 1))
74 sizer.Add(btn_clear, wx.GBPosition(1, 1), wx.GBSpan(1, 1))
75 sizer.Add(img_icon, wx.GBPosition(0, 2), wx.GBSpan(2, 1))
76
81
86
88 label = _("Images will be scaled to fit inside a %ix%i box.")
89 return wx.StaticText(self, label=label % self.MAX_SIZE)
90
92 return wx.StaticBitmap(self, size=self.MAX_SIZE)
93
94
95 -class IconEditor(BaseEditor, IconEditorGuiCreator):
96
97 - def __init__(self, parent, editor, name=""):
102
105
108
111
113 self.bmp = bmp
114 if self.bmp is None:
115 self.img_icon.SetBitmap(wx.EmptyBitmap(1, 1))
116 else:
117 self.img_icon.SetBitmap(bmp)
118 self.GetSizer().Layout()
119
122
125
127 dialog = wx.FileDialog(self, message=_("Select Icon"),
128 wildcard="*", style=wx.FD_OPEN)
129 if dialog.ShowModal() == wx.ID_OK:
130 try:
131 bitmap = FileToBitmapConverter().convert(dialog.GetPath())
132 self.set_icon(bitmap)
133 except:
134 pass
135 dialog.Destroy()
136
139