from util import stl\r
from util import util3d\r
\r
-IdMirrorX2 = 10\r
+class ToggleButton(buttons.GenBitmapToggleButton):\r
+ def __init__(self, parent, popupParent, profileSetting, bitmapOn, bitmapOff,\r
+ helpText='', id=-1, size=(20,20)):\r
+ buttons.GenBitmapToggleButton.__init__(self, parent, id, bitmapOff, size=size)\r
+\r
+ self.popupParent = popupParent\r
+ self.profileSetting = profileSetting\r
+ self.bitmapOn = bitmapOn\r
+ self.bitmapOff = bitmapOff\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 previewPanel(wx.Panel):\r
def __init__(self, parent):\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.toolbar2 = wx.ToolBar( self, -1, style = wx.TB_HORIZONTAL | wx.NO_BORDER )\r
self.toolbar2.SetToolBitmapSize( ( 21, 21 ) )\r
\r
- self.mirrorX = buttons.GenBitmapToggleButton(self.toolbar2, -1, wx.Bitmap('Cura/images/object-mirror-x-off.png'), style=0, size=(20,20))\r
- self.mirrorX.SetBezelWidth(1)\r
- self.mirrorX.SetUseFocusIndicator(False)\r
- self.mirrorX.SetValue(profile.getProfileSetting('flip_x') == 'True')\r
- if self.mirrorX.GetValue():\r
- self.mirrorX.SetBitmapLabel(wx.Bitmap('Cura/images/object-mirror-x-on.png'))\r
- self.mirrorX.helpText = 'Mirror X'\r
- self.mirrorX.Bind(wx.EVT_ENTER_WINDOW, self.OnPopupDisplay)\r
- self.mirrorX.Bind(wx.EVT_LEAVE_WINDOW, self.OnPopupHide)\r
- self.mirrorX.Bind(wx.EVT_BUTTON, self.OnFlipXClick)\r
+ self.mirrorX = ToggleButton(self.toolbar2, self, 'flip_x', wx.Bitmap('Cura/images/object-mirror-x-on.png'), wx.Bitmap('Cura/images/object-mirror-x-off.png'), 'Mirror X')\r
self.toolbar2.AddControl(self.mirrorX)\r
\r
- self.mirrorY = buttons.GenBitmapToggleButton(self.toolbar2, -1, wx.Bitmap('Cura/images/object-mirror-y-off.png'), size=(20,20))\r
- self.mirrorY.SetBezelWidth(1)\r
- self.mirrorY.SetUseFocusIndicator(False)\r
- self.mirrorY.SetValue(profile.getProfileSetting('flip_y') == 'True')\r
- if self.mirrorY.GetValue():\r
- self.mirrorY.SetBitmapLabel(wx.Bitmap('Cura/images/object-mirror-x-on.png'))\r
- self.mirrorY.helpText = 'Mirror Y'\r
- self.mirrorY.Bind(wx.EVT_ENTER_WINDOW, self.OnPopupDisplay)\r
- self.mirrorY.Bind(wx.EVT_LEAVE_WINDOW, self.OnPopupHide)\r
- self.mirrorY.Bind(wx.EVT_BUTTON, self.OnFlipYClick)\r
+ self.mirrorY = ToggleButton(self.toolbar2, self, 'flip_y', wx.Bitmap('Cura/images/object-mirror-y-on.png'), wx.Bitmap('Cura/images/object-mirror-y-off.png'), 'Mirror Y')\r
self.toolbar2.AddControl(self.mirrorY)\r
\r
- self.mirrorZ = buttons.GenBitmapToggleButton(self.toolbar2, -1, wx.Bitmap('Cura/images/object-mirror-z-off.png'), size=(20,20))\r
- self.mirrorZ.SetBezelWidth(1)\r
- self.mirrorZ.SetUseFocusIndicator(False)\r
- self.mirrorZ.SetValue(profile.getProfileSetting('flip_z') == 'True')\r
- if self.mirrorZ.GetValue():\r
- self.mirrorZ.SetBitmapLabel(wx.Bitmap('Cura/images/object-mirror-z-on.png'))\r
- self.mirrorZ.helpText = 'Mirror Z'\r
- self.mirrorZ.Bind(wx.EVT_ENTER_WINDOW, self.OnPopupDisplay)\r
- self.mirrorZ.Bind(wx.EVT_LEAVE_WINDOW, self.OnPopupHide)\r
- self.mirrorZ.Bind(wx.EVT_BUTTON, self.OnFlipZClick)\r
+ self.mirrorZ = ToggleButton(self.toolbar2, self, 'flip_z', wx.Bitmap('Cura/images/object-mirror-z-on.png'), wx.Bitmap('Cura/images/object-mirror-z-off.png'), 'Mirror Z')\r
self.toolbar2.AddControl(self.mirrorZ)\r
\r
self.toolbar2.AddSeparator()\r
\r
- self.swapXZ = buttons.GenBitmapToggleButton(self.toolbar2, -1, wx.Bitmap('Cura/images/object-swap-xz-off.png'), size=(20,20))\r
- self.swapXZ.SetBezelWidth(1)\r
- self.swapXZ.SetUseFocusIndicator(False)\r
- self.swapXZ.SetValue(profile.getProfileSetting('swap_xz') == 'True')\r
- if self.swapXZ.GetValue():\r
- self.swapXZ.SetBitmapLabel(wx.Bitmap('Cura/images/object-swap-xz-on.png'))\r
- self.swapXZ.helpText = 'Swap XZ'\r
- self.swapXZ.Bind(wx.EVT_ENTER_WINDOW, self.OnPopupDisplay)\r
- self.swapXZ.Bind(wx.EVT_LEAVE_WINDOW, self.OnPopupHide)\r
- self.Bind(wx.EVT_BUTTON, self.OnSwapXZClick, self.swapXZ)\r
+ self.swapXZ = ToggleButton(self.toolbar2, self, 'swap_xz', wx.Bitmap('Cura/images/object-swap-xz-on.png'), wx.Bitmap('Cura/images/object-swap-xz-off.png'), 'Swap XZ')\r
self.toolbar2.AddControl(self.swapXZ)\r
\r
- self.swapYZ = buttons.GenBitmapToggleButton(self.toolbar2, -1, wx.Bitmap('Cura/images/object-swap-yz-off.png'), size=(20,20))\r
- self.swapYZ.SetBezelWidth(1)\r
- self.swapYZ.SetUseFocusIndicator(False)\r
- self.swapYZ.SetValue(profile.getProfileSetting('swap_yz') == 'True')\r
- if self.swapYZ.GetValue():\r
- self.swapYZ.SetBitmapLabel(wx.Bitmap('Cura/images/object-swap-yz-on.png'))\r
- self.swapYZ.helpText = 'Swap YZ'\r
- self.swapYZ.Bind(wx.EVT_ENTER_WINDOW, self.OnPopupDisplay)\r
- self.swapYZ.Bind(wx.EVT_LEAVE_WINDOW, self.OnPopupHide)\r
- self.Bind(wx.EVT_BUTTON, self.OnSwapYZClick, self.swapYZ)\r
+ self.swapYZ = ToggleButton(self.toolbar2, self, 'swap_yz', wx.Bitmap('Cura/images/object-swap-yz-on.png'), wx.Bitmap('Cura/images/object-swap-yz-off.png'), 'Swap YZ')\r
self.toolbar2.AddControl(self.swapYZ)\r
\r
self.toolbar2.InsertSeparator(self.toolbar2.GetToolsCount())\r
self.popup.Show(True)\r
\r
def OnPopupHide(self, e):\r
- self.popup.Show(False)\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
x, y = control.ClientToScreenXY(0, 0)\r
sx, sy = control.GetSizeTuple()\r
self.popup.SetPosition((x, y+sy))\r
- \r
- def OnFlipXClick(self, e):\r
- profile.putProfileSetting('flip_x', str(self.mirrorX.GetValue()))\r
- if self.mirrorX.GetValue():\r
- self.mirrorX.SetBitmapLabel(wx.Bitmap('Cura/images/object-mirror-x-on.png'))\r
- else:\r
- self.mirrorX.SetBitmapLabel(wx.Bitmap('Cura/images/object-mirror-x-off.png'))\r
- self.updateModelTransform()\r
- \r
- def OnFlipYClick(self, e):\r
- profile.putProfileSetting('flip_y', str(self.mirrorY.GetValue()))\r
- if self.mirrorY.GetValue():\r
- self.mirrorY.SetBitmapLabel(wx.Bitmap('Cura/images/object-mirror-y-on.png'))\r
- else:\r
- self.mirrorY.SetBitmapLabel(wx.Bitmap('Cura/images/object-mirror-y-off.png'))\r
- self.updateModelTransform()\r
-\r
- def OnFlipZClick(self, e):\r
- profile.putProfileSetting('flip_z', str(self.mirrorZ.GetValue()))\r
- if self.mirrorZ.GetValue():\r
- self.mirrorZ.SetBitmapLabel(wx.Bitmap('Cura/images/object-mirror-z-on.png'))\r
- else:\r
- self.mirrorZ.SetBitmapLabel(wx.Bitmap('Cura/images/object-mirror-z-off.png'))\r
- self.updateModelTransform()\r
-\r
- def OnSwapXZClick(self, e):\r
- profile.putProfileSetting('swap_xz', str(self.swapXZ.GetValue()))\r
- if self.swapXZ.GetValue():\r
- self.swapXZ.SetBitmapLabel(wx.Bitmap('Cura/images/object-swap-xz-on.png'))\r
- else:\r
- self.swapXZ.SetBitmapLabel(wx.Bitmap('Cura/images/object-swap-xz-off.png'))\r
- self.updateModelTransform()\r
-\r
- def OnSwapYZClick(self, e):\r
- profile.putProfileSetting('swap_yz', str(self.swapYZ.GetValue()))\r
- if self.swapYZ.GetValue():\r
- self.swapYZ.SetBitmapLabel(wx.Bitmap('Cura/images/object-swap-yz-on.png'))\r
- else:\r
- self.swapYZ.SetBitmapLabel(wx.Bitmap('Cura/images/object-swap-yz-off.png'))\r
- self.updateModelTransform()\r
\r
def OnMulXAddClick(self, e):\r
profile.putProfileSetting('model_multiply_x', str(max(1, int(profile.getProfileSetting('model_multiply_x'))+1)))\r