2 from __future__ import absolute_import
3 from __future__ import division
6 from wx.lib import buttons
8 from util import profile
9 from util.resources import getPathForImage
12 #######################################################
13 # toolbarUtil contains help classes and functions for
15 #######################################################
17 class Toolbar(wx.ToolBar):
18 def __init__(self, parent):
19 super(Toolbar, self).__init__(parent, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)
20 self.SetToolBitmapSize(( 21, 21 ))
22 if not hasattr(parent, 'popup'):
24 parent.popup = wx.PopupWindow(parent, flags=wx.BORDER_SIMPLE)
25 parent.popup.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK))
26 parent.popup.text = wx.StaticText(parent.popup, -1, '')
27 parent.popup.sizer = wx.BoxSizer()
28 parent.popup.sizer.Add(parent.popup.text, flag=wx.EXPAND | wx.ALL, border=1)
29 parent.popup.SetSizer(parent.popup.sizer)
30 parent.popup.owner = None
32 def OnPopupDisplay(self, e):
33 self.UpdatePopup(e.GetEventObject())
34 self.GetParent().popup.Show(True)
36 def OnPopupHide(self, e):
37 if self.GetParent().popup.owner == e.GetEventObject():
38 self.GetParent().popup.Show(False)
40 def UpdatePopup(self, control):
41 popup = self.GetParent().popup
43 popup.text.SetLabel(control.helpText)
46 x, y = control.ClientToScreenXY(0, 0)
47 sx, sy = control.GetSizeTuple()
48 popup.SetPosition((x, y + sy))
51 class ToggleButton(buttons.GenBitmapToggleButton):
52 def __init__(self, parent, profileSetting, bitmapFilenameOn, bitmapFilenameOff,
53 helpText='', id=-1, callback=None, size=(20, 20)):
54 self.bitmapOn = wx.Bitmap(getPathForImage(bitmapFilenameOn))
55 self.bitmapOff = wx.Bitmap(getPathForImage(bitmapFilenameOff))
57 super(ToggleButton, self).__init__(parent, id, self.bitmapOff, size=size)
59 self.callback = callback
60 self.profileSetting = profileSetting
61 self.helpText = helpText
64 self.SetUseFocusIndicator(False)
66 if self.profileSetting != '':
67 self.SetValue(profile.getProfileSetting(self.profileSetting) == 'True')
68 self.Bind(wx.EVT_BUTTON, self.OnButtonProfile)
70 self.Bind(wx.EVT_BUTTON, self.OnButton)
72 self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
73 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
75 parent.AddControl(self)
77 def SetBitmap(self, boolValue):
79 self.SetBitmapLabel(self.bitmapOn, False)
81 self.SetBitmapLabel(self.bitmapOff, False)
83 def SetValue(self, boolValue):
84 self.SetBitmap(boolValue)
85 super(ToggleButton, self).SetValue(boolValue)
87 def OnButton(self, event):
88 self.SetBitmap(self.GetValue())
89 if self.callback != None:
93 def OnButtonProfile(self, event):
94 if buttons.GenBitmapToggleButton.GetValue(self):
96 profile.putProfileSetting(self.profileSetting, 'True')
99 profile.putProfileSetting(self.profileSetting, 'False')
100 if self.callback != None:
104 def OnMouseEnter(self, event):
105 self.GetParent().OnPopupDisplay(event)
110 def OnMouseLeave(self, event):
111 self.GetParent().OnPopupHide(event)
112 self.SetBitmap(self.GetValue())
117 class RadioButton(buttons.GenBitmapButton):
118 def __init__(self, parent, group, bitmapFilenameOn, bitmapFilenameOff,
119 helpText='', id=-1, callback=None, size=(20, 20)):
120 self.bitmapOn = wx.Bitmap(getPathForImage(bitmapFilenameOn))
121 self.bitmapOff = wx.Bitmap(getPathForImage(bitmapFilenameOff))
123 super(RadioButton, self).__init__(parent, id, self.bitmapOff, size=size)
127 self.callback = callback
128 self.helpText = helpText
131 self.SetBezelWidth(1)
132 self.SetUseFocusIndicator(False)
134 self.Bind(wx.EVT_BUTTON, self.OnButton)
136 self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
137 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
142 parent.AddControl(self)
144 def SetBitmap(self, boolValue):
146 self.SetBitmapLabel(self.bitmapOn, False)
148 self.SetBitmapLabel(self.bitmapOff, False)
151 def SetValue(self, boolValue):
152 self._value = boolValue
153 self.SetBitmap(self.GetValue())
154 if boolValue == True:
155 for other in self.group:
157 other.SetValue(False)
162 def OnButton(self, event):
167 def OnMouseEnter(self, event):
168 self.GetParent().OnPopupDisplay(event)
173 def OnMouseLeave(self, event):
174 self.GetParent().OnPopupHide(event)
175 self.SetBitmap(self.GetValue())
180 class NormalButton(buttons.GenBitmapButton):
181 def __init__(self, parent, callback, bitmapFilename,
182 helpText='', id=-1, size=(20, 20)):
183 self.bitmap = wx.Bitmap(getPathForImage(bitmapFilename))
184 super(NormalButton, self).__init__(parent, id, self.bitmap, size=size)
186 self.helpText = helpText
187 self.callback = callback
189 self.SetBezelWidth(1)
190 self.SetUseFocusIndicator(False)
192 self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
193 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
195 self.Bind(wx.EVT_BUTTON, self.OnButton)
197 parent.AddControl(self)
199 def OnButton(self, event):
200 self.GetParent().OnPopupHide(event)
203 def OnMouseEnter(self, event):
204 self.GetParent().OnPopupDisplay(event)
207 def OnMouseLeave(self, event):
208 self.GetParent().OnPopupHide(event)