import os\r
\r
from wx import glcanvas\r
-from wx.lib import buttons\r
import wx\r
try:\r
import OpenGL\r
hasOpenGLlibs = False\r
\r
from gui import opengl\r
+from gui import toolbarUtil\r
\r
from util import profile\r
from util import gcodeInterpreter\r
from util import stl\r
from util import util3d\r
\r
-class ToggleButton(buttons.GenBitmapToggleButton):\r
- def __init__(self, parent, popupParent, profileSetting, bitmapFilenameOn, bitmapFilenameOff,\r
- helpText='', id=-1, size=(20,20)):\r
- self.bitmapOn = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOn))\r
- self.bitmapOff = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOff))\r
-\r
- buttons.GenBitmapToggleButton.__init__(self, parent, id, self.bitmapOff, size=size)\r
-\r
- self.popupParent = popupParent\r
- self.profileSetting = profileSetting\r
- self.helpText = helpText\r
-\r
- self.bezelWidth = 1\r
- self.useFocusInd = False\r
-\r
- if self.profileSetting != '':\r
- self.SetValue(profile.getProfileSetting(self.profileSetting) == 'True')\r
- self.Bind(wx.EVT_BUTTON, self.OnButtonProfile)\r
- else:\r
- self.Bind(wx.EVT_BUTTON, self.OnButton)\r
-\r
- self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)\r
- self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)\r
-\r
- def SetBitmap(self, bool):\r
- if bool:\r
- buttons.GenBitmapToggleButton.SetBitmapLabel(self, self.bitmapOn, False)\r
- else:\r
- buttons.GenBitmapToggleButton.SetBitmapLabel(self, self.bitmapOff, False)\r
-\r
- def SetValue(self, bool):\r
- self.SetBitmap(bool)\r
- buttons.GenBitmapToggleButton.SetValue(self, bool)\r
-\r
- def OnButton(self, event):\r
- self.SetBitmap(buttons.GenBitmapToggleButton.GetValue(self))\r
- event.Skip()\r
-\r
- def OnButtonProfile(self, event):\r
- if buttons.GenBitmapToggleButton.GetValue(self):\r
- self.SetBitmap(True)\r
- profile.putProfileSetting(self.profileSetting, 'True')\r
- else:\r
- self.SetBitmap(False)\r
- profile.putProfileSetting(self.profileSetting, 'False')\r
- self.popupParent.updateModelTransform()\r
- event.Skip()\r
-\r
- def OnMouseEnter(self, event):\r
- self.popupParent.OnPopupDisplay(event)\r
- event.Skip()\r
-\r
- def OnMouseLeave(self, event):\r
- self.popupParent.OnPopupHide(event)\r
- event.Skip()\r
-\r
-class NormalButton(buttons.GenBitmapButton):\r
- def __init__(self, parent, popupParent, bitmapFilename,\r
- helpText='', id=-1, size=(20,20)):\r
- self.bitmap = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilename))\r
- buttons.GenBitmapButton.__init__(self, parent, id, self.bitmap, size=size)\r
-\r
- self.popupParent = popupParent\r
- self.helpText = helpText\r
-\r
- self.bezelWidth = 1\r
- self.useFocusInd = False\r
-\r
- self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)\r
- self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)\r
-\r
- def OnMouseEnter(self, event):\r
- self.popupParent.OnPopupDisplay(event)\r
- event.Skip()\r
-\r
- def OnMouseLeave(self, event):\r
- self.popupParent.OnPopupHide(event)\r
- event.Skip()\r
-\r
class previewPanel(wx.Panel):\r
def __init__(self, parent):\r
- wx.Panel.__init__(self, parent,-1)\r
+ super(previewPanel, self).__init__(parent,-1)\r
\r
self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DDKSHADOW))\r
self.SetMinSize((440,320))\r
\r
- # Create popup window\r
- self.popup = wx.PopupWindow(self, flags=wx.BORDER_SIMPLE)\r
- self.popup.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK))\r
- self.popup.text = wx.StaticText(self.popup, -1, '')\r
- self.popup.sizer = wx.BoxSizer()\r
- self.popup.sizer.Add(self.popup.text, flag=wx.EXPAND|wx.ALL, border=1)\r
- self.popup.SetSizer(self.popup.sizer)\r
- self.popupOwner = None\r
- \r
self.glCanvas = PreviewGLCanvas(self)\r
self.init = 0\r
self.triangleMesh = None\r
self.machineSize = util3d.Vector3(float(profile.getPreference('machine_width')), float(profile.getPreference('machine_depth')), float(profile.getPreference('machine_height')))\r
self.machineCenter = util3d.Vector3(float(profile.getProfileSetting('machine_center_x')), float(profile.getProfileSetting('machine_center_y')), 0)\r
\r
- self.toolbar = wx.ToolBar( self, -1 )\r
- self.toolbar.SetToolBitmapSize( ( 21, 21 ) )\r
+ self.toolbar = toolbarUtil.Toolbar(self)\r
\r
button = wx.Button(self.toolbar, -1, "3D", size=(21*2,21))\r
self.toolbar.AddControl(button)\r
self.toolbar.AddControl(self.layerSpin)\r
self.Bind(wx.EVT_SPINCTRL, self.OnLayerNrChange, self.layerSpin)\r
\r
- self.scaleMax = NormalButton(self.toolbar, self, 'object-max-size.png', 'Scale object to fix machine size')\r
- self.scaleMax.Bind(wx.EVT_BUTTON, self.OnScaleMax)\r
- self.toolbar.AddControl(self.scaleMax)\r
+ self.scaleMax = toolbarUtil.NormalButton(self.toolbar, self.OnScaleMax, 'object-max-size.png', 'Scale object to fix machine size')\r
\r
- self.toolbar2 = wx.ToolBar( self, -1, style = wx.TB_HORIZONTAL | wx.NO_BORDER )\r
- self.toolbar2.SetToolBitmapSize( ( 21, 21 ) )\r
+ self.toolbar2 = toolbarUtil.Toolbar(self)\r
\r
# Mirror\r
- self.mirrorX = ToggleButton(self.toolbar2, self, 'flip_x', 'object-mirror-x-on.png', 'object-mirror-x-off.png', 'Mirror X')\r
- self.toolbar2.AddControl(self.mirrorX)\r
-\r
- self.mirrorY = ToggleButton(self.toolbar2, self, 'flip_y', 'object-mirror-y-on.png', 'object-mirror-y-off.png', 'Mirror Y')\r
- self.toolbar2.AddControl(self.mirrorY)\r
-\r
- self.mirrorZ = ToggleButton(self.toolbar2, self, 'flip_z', 'object-mirror-z-on.png', 'object-mirror-z-off.png', 'Mirror Z')\r
- self.toolbar2.AddControl(self.mirrorZ)\r
-\r
+ self.mirrorX = toolbarUtil.ToggleButton(self.toolbar2, 'flip_x', 'object-mirror-x-on.png', 'object-mirror-x-off.png', 'Mirror X', callback=self.updateModelTransform)\r
+ self.mirrorY = toolbarUtil.ToggleButton(self.toolbar2, 'flip_y', 'object-mirror-y-on.png', 'object-mirror-y-off.png', 'Mirror Y', callback=self.updateModelTransform)\r
+ self.mirrorZ = toolbarUtil.ToggleButton(self.toolbar2, 'flip_z', 'object-mirror-z-on.png', 'object-mirror-z-off.png', 'Mirror Z', callback=self.updateModelTransform)\r
self.toolbar2.AddSeparator()\r
\r
# Swap\r
- self.swapXZ = ToggleButton(self.toolbar2, self, 'swap_xz', 'object-swap-xz-on.png', 'object-swap-xz-off.png', 'Swap XZ')\r
- self.toolbar2.AddControl(self.swapXZ)\r
-\r
- self.swapYZ = ToggleButton(self.toolbar2, self, 'swap_yz', 'object-swap-yz-on.png', 'object-swap-yz-off.png', 'Swap YZ')\r
- self.toolbar2.AddControl(self.swapYZ)\r
- \r
+ self.swapXZ = toolbarUtil.ToggleButton(self.toolbar2, 'swap_xz', 'object-swap-xz-on.png', 'object-swap-xz-off.png', 'Swap XZ', callback=self.updateModelTransform)\r
+ self.swapYZ = toolbarUtil.ToggleButton(self.toolbar2, 'swap_yz', 'object-swap-yz-on.png', 'object-swap-yz-off.png', 'Swap YZ', callback=self.updateModelTransform)\r
self.toolbar2.AddSeparator()\r
\r
# Scale\r
- self.scaleReset = NormalButton(self.toolbar2, self, 'object-scale.png', 'Reset model scale')\r
- self.scaleReset.Bind(wx.EVT_BUTTON, self.OnScaleReset)\r
- self.toolbar2.AddControl(self.scaleReset)\r
+ self.scaleReset = toolbarUtil.NormalButton(self.toolbar2, self.OnScaleReset, 'object-scale.png', 'Reset model scale')\r
self.scale = wx.TextCtrl(self.toolbar2, -1, profile.getProfileSetting('model_scale'), size=(21*2,21))\r
self.toolbar2.AddControl(self.scale)\r
self.scale.Bind(wx.EVT_TEXT, self.OnScale)\r
self.toolbar2.AddSeparator()\r
\r
# Multiply\r
- self.mulXadd = NormalButton(self.toolbar2, self, 'object-mul-x-add.png', 'Increase number of models on X axis')\r
- self.mulXadd.Bind(wx.EVT_BUTTON, self.OnMulXAddClick)\r
- self.toolbar2.AddControl(self.mulXadd)\r
-\r
- self.mulXsub = NormalButton(self.toolbar2, self, 'object-mul-x-sub.png', 'Decrease number of models on X axis')\r
- self.mulXsub.Bind(wx.EVT_BUTTON, self.OnMulXSubClick)\r
- self.toolbar2.AddControl(self.mulXsub)\r
-\r
- self.mulYadd = NormalButton(self.toolbar2, self, 'object-mul-y-add.png', 'Increase number of models on Y axis')\r
- self.mulYadd.Bind(wx.EVT_BUTTON, self.OnMulYAddClick)\r
- self.toolbar2.AddControl(self.mulYadd)\r
-\r
- self.mulYsub = NormalButton(self.toolbar2, self, 'object-mul-y-sub.png', 'Decrease number of models on Y axis')\r
- self.mulYsub.Bind(wx.EVT_BUTTON, self.OnMulYSubClick)\r
- self.toolbar2.AddControl(self.mulYsub)\r
+ self.mulXadd = toolbarUtil.NormalButton(self.toolbar2, self.OnMulXAddClick, 'object-mul-x-add.png', 'Increase number of models on X axis')\r
+ self.mulXsub = toolbarUtil.NormalButton(self.toolbar2, self.OnMulXSubClick, 'object-mul-x-sub.png', 'Decrease number of models on X axis')\r
+ self.mulYadd = toolbarUtil.NormalButton(self.toolbar2, self.OnMulYAddClick, 'object-mul-y-add.png', 'Increase number of models on Y axis')\r
+ self.mulYsub = toolbarUtil.NormalButton(self.toolbar2, self.OnMulYSubClick, 'object-mul-y-sub.png', 'Decrease number of models on Y axis')\r
\r
self.toolbar2.AddSeparator()\r
\r
# Rotate\r
- self.rotateReset = NormalButton(self.toolbar2, self, 'object-rotate.png', 'Reset model rotation')\r
- self.rotateReset.Bind(wx.EVT_BUTTON, self.OnRotateReset)\r
- self.toolbar2.AddControl(self.rotateReset)\r
+ self.rotateReset = toolbarUtil.NormalButton(self.toolbar2, self.OnRotateReset, 'object-rotate.png', 'Reset model rotation')\r
self.rotate = wx.SpinCtrl(self.toolbar2, -1, profile.getProfileSetting('model_rotate_base'), size=(21*3,21), style=wx.SP_WRAP|wx.SP_ARROW_KEYS)\r
self.rotate.SetRange(0, 360)\r
self.Bind(wx.EVT_TEXT, self.OnRotate)\r
sizer.Add(self.glCanvas, 1, flag=wx.EXPAND)\r
sizer.Add(self.toolbar2, 0, flag=wx.EXPAND|wx.BOTTOM|wx.LEFT|wx.RIGHT, border=1)\r
self.SetSizer(sizer)\r
-\r
- def OnPopupDisplay(self, e):\r
- self.UpdatePopup(e.GetEventObject())\r
- self.popup.Show(True)\r
- \r
- def OnPopupHide(self, e):\r
- if self.popupOwner == e.GetEventObject():\r
- self.popup.Show(False)\r
\r
- def UpdatePopup(self, control):\r
- self.popupOwner = control\r
- self.popup.text.SetLabel(control.helpText)\r
- self.popup.text.Wrap(350)\r
- self.popup.Fit();\r
- if os.name == 'darwin':\r
- x, y = self.ClientToScreenXY(0, 0)\r
- sx, sy = self.GetClientSizeTuple()\r
- else:\r
- x, y = control.ClientToScreenXY(0, 0)\r
- sx, sy = control.GetSizeTuple()\r
- self.popup.SetPosition((x, y+sy))\r
-\r
def OnMulXAddClick(self, e):\r
profile.putProfileSetting('model_multiply_x', str(max(1, int(profile.getProfileSetting('model_multiply_x'))+1)))\r
self.updateModelTransform()\r
--- /dev/null
+from __future__ import division
+
+import os
+
+import wx
+from wx.lib import buttons
+
+from util import profile
+
+#######################################################
+# toolbarUtil contains help classes and functions for
+# toolbar buttons.
+#######################################################
+
+class Toolbar(wx.ToolBar):
+ def __init__(self, parent):
+ super(Toolbar, self).__init__(parent, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)
+ self.SetToolBitmapSize( ( 21, 21 ) )
+
+ if not hasattr(parent, 'popup'):
+ # Create popup window
+ parent.popup = wx.PopupWindow(parent, flags=wx.BORDER_SIMPLE)
+ parent.popup.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK))
+ parent.popup.text = wx.StaticText(parent.popup, -1, '')
+ parent.popup.sizer = wx.BoxSizer()
+ parent.popup.sizer.Add(parent.popup.text, flag=wx.EXPAND|wx.ALL, border=1)
+ parent.popup.SetSizer(parent.popup.sizer)
+ parent.popup.owner = None
+
+ def OnPopupDisplay(self, e):
+ self.UpdatePopup(e.GetEventObject())
+ self.GetParent().popup.Show(True)
+
+ def OnPopupHide(self, e):
+ if self.GetParent().popup.owner == e.GetEventObject():
+ self.GetParent().popup.Show(False)
+
+ def UpdatePopup(self, control):
+ popup = self.GetParent().popup
+ popup.owner = control
+ popup.text.SetLabel(control.helpText)
+ popup.text.Wrap(350)
+ popup.Fit();
+ if os.name == 'darwin':
+ x, y = self.GetParent().ClientToScreenXY(0, 0)
+ sx, sy = self.GetParent().GetClientSizeTuple()
+ else:
+ x, y = control.ClientToScreenXY(0, 0)
+ sx, sy = control.GetSizeTuple()
+ popup.SetPosition((x, y+sy))
+
+class ToggleButton(buttons.GenBitmapToggleButton):
+ def __init__(self, parent, profileSetting, 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(ToggleButton, self).__init__(parent, id, self.bitmapOff, size=size)
+
+ self.callback = callback
+ self.profileSetting = profileSetting
+ self.helpText = helpText
+
+ self.SetBezelWidth(1)
+ self.SetUseFocusIndicator(False)
+
+ if self.profileSetting != '':
+ self.SetValue(profile.getProfileSetting(self.profileSetting) == 'True')
+ self.Bind(wx.EVT_BUTTON, self.OnButtonProfile)
+ else:
+ 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:
+ buttons.GenBitmapToggleButton.SetBitmapLabel(self, self.bitmapOn, False)
+ else:
+ buttons.GenBitmapToggleButton.SetBitmapLabel(self, self.bitmapOff, False)
+
+ def SetValue(self, boolValue):
+ self.SetBitmap(boolValue)
+ buttons.GenBitmapToggleButton.SetValue(self, boolValue)
+
+ def OnButton(self, event):
+ self.SetBitmap(buttons.GenBitmapToggleButton.GetValue(self))
+ event.Skip()
+
+ def OnButtonProfile(self, event):
+ if buttons.GenBitmapToggleButton.GetValue(self):
+ self.SetBitmap(True)
+ profile.putProfileSetting(self.profileSetting, 'True')
+ else:
+ self.SetBitmap(False)
+ profile.putProfileSetting(self.profileSetting, 'False')
+ 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)):
+ self.bitmap = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilename))
+ super(NormalButton, self).__init__(parent, id, self.bitmap, size=size)
+
+ self.helpText = helpText
+
+ self.SetBezelWidth(1)
+ self.SetUseFocusIndicator(False)
+
+ self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
+ self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
+
+ self.Bind(wx.EVT_BUTTON, callback)
+
+ parent.AddControl(self)
+
+ def OnMouseEnter(self, event):
+ self.GetParent().OnPopupDisplay(event)
+ event.Skip()
+
+ def OnMouseLeave(self, event):
+ self.GetParent().OnPopupHide(event)
+ event.Skip()
+