Add radio toolbar buttons for 3D/Top view. Some minor cleanup in toggle button code.

This commit is contained in:
daid 2012-04-18 12:39:05 +02:00
parent e92506cd5a
commit b09f2f1837
2 changed files with 65 additions and 13 deletions

View File

@ -46,13 +46,10 @@ class previewPanel(wx.Panel):
self.toolbar = toolbarUtil.Toolbar(self)
button = wx.Button(self.toolbar, -1, "3D", size=(21*2,21))
self.toolbar.AddControl(button)
self.Bind(wx.EVT_BUTTON, self.On3DClick, button)
button = wx.Button(self.toolbar, -1, "Top", size=(21*2,21))
self.toolbar.AddControl(button)
self.Bind(wx.EVT_BUTTON, self.OnTopClick, button)
group = []
toolbarUtil.RadioButton(self.toolbar, group, 'object-mirror-x-on.png', 'object-mirror-x-off.png', '3D view', callback=self.On3DClick).SetValue(True)
toolbarUtil.RadioButton(self.toolbar, group, 'object-mirror-x-on.png', 'object-mirror-x-off.png', 'Topdown view', callback=self.OnTopClick)
self.toolbar.AddSeparator()
self.viewSelect = wx.ComboBox(self.toolbar, -1, 'Model - Normal', choices=['Model - Normal', 'Model - Transparent', 'Model - X-Ray', 'GCode', 'Mixed'], style=wx.CB_DROPDOWN|wx.CB_READONLY)
self.toolbar.AddControl(self.viewSelect)
@ -157,14 +154,14 @@ class previewPanel(wx.Panel):
profile.putProfileSetting('model_rotate_base', self.rotate.GetValue())
self.updateModelTransform()
def On3DClick(self, e):
def On3DClick(self):
self.glCanvas.yaw = 30
self.glCanvas.pitch = 60
self.glCanvas.zoom = 150
self.glCanvas.view3D = True
self.glCanvas.Refresh()
def OnTopClick(self, e):
def OnTopClick(self):
self.glCanvas.view3D = False
self.glCanvas.zoom = 100
self.glCanvas.offsetX = 0

View File

@ -77,16 +77,16 @@ class ToggleButton(buttons.GenBitmapToggleButton):
def SetBitmap(self, boolValue):
if boolValue:
buttons.GenBitmapToggleButton.SetBitmapLabel(self, self.bitmapOn, False)
self.SetBitmapLabel(self.bitmapOn, False)
else:
buttons.GenBitmapToggleButton.SetBitmapLabel(self, self.bitmapOff, False)
self.SetBitmapLabel(self.bitmapOff, False)
def SetValue(self, boolValue):
self.SetBitmap(boolValue)
buttons.GenBitmapToggleButton.SetValue(self, boolValue)
super(ToggleButton, self).SetValue(boolValue)
def OnButton(self, event):
self.SetBitmap(buttons.GenBitmapToggleButton.GetValue(self))
self.SetBitmap(self.GetValue())
event.Skip()
def OnButtonProfile(self, event):
@ -107,6 +107,61 @@ class ToggleButton(buttons.GenBitmapToggleButton):
self.GetParent().OnPopupHide(event)
event.Skip()
class RadioButton(buttons.GenBitmapButton):
def __init__(self, parent, group, bitmapFilenameOn, bitmapFilenameOff,
helpText='', id=-1, callback=None, size=(20,20)):
self.bitmapOn = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOn))
self.bitmapOff = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOff))
super(RadioButton, self).__init__(parent, id, self.bitmapOff, size=size)
self.group = group
group.append(self)
self.callback = callback
self.helpText = helpText
self._value = False
self.SetBezelWidth(1)
self.SetUseFocusIndicator(False)
self.Bind(wx.EVT_BUTTON, self.OnButton)
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
parent.AddControl(self)
def SetBitmap(self, boolValue):
if boolValue:
self.SetBitmapLabel(self.bitmapOn, False)
else:
self.SetBitmapLabel(self.bitmapOff, False)
self.Refresh()
def SetValue(self, boolValue):
self._value = boolValue
self.SetBitmap(self.GetValue())
if boolValue == True:
for other in self.group:
if other != self:
other.SetValue(False)
def GetValue(self):
return self._value
def OnButton(self, event):
self.SetValue(True)
self.callback()
event.Skip()
def OnMouseEnter(self, event):
self.GetParent().OnPopupDisplay(event)
event.Skip()
def OnMouseLeave(self, event):
self.GetParent().OnPopupHide(event)
event.Skip()
class NormalButton(buttons.GenBitmapButton):
def __init__(self, parent, callback, bitmapFilename,
helpText='', id=-1, size=(20,20)):