1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
6 from wx.lib import scrolledpanel
8 from Cura.util import profile
9 from Cura.util import explorer
11 class pluginPanel(wx.Panel):
12 def __init__(self, parent, callback):
13 wx.Panel.__init__(self, parent,-1)
15 self.pluginList = profile.getPluginList()
16 self.callback = callback
18 sizer = wx.GridBagSizer(2, 2)
22 for effect in self.pluginList:
23 effectStringList.append(effect['name'])
25 self.listbox = wx.ListBox(self, -1, choices=effectStringList)
26 title = wx.StaticText(self, -1, "Plugins:")
27 title.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
28 helpButton = wx.Button(self, -1, '?', style=wx.BU_EXACTFIT)
29 addButton = wx.Button(self, -1, 'V', style=wx.BU_EXACTFIT)
30 openPluginLocationButton = wx.Button(self, -1, 'Open plugin location')
31 sb = wx.StaticBox(self, label="Enabled plugins")
32 boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
33 self.pluginEnabledPanel = scrolledpanel.ScrolledPanel(self)
34 self.pluginEnabledPanel.SetupScrolling(False, True)
36 sizer.Add(title, (0,0), border=10, flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.TOP)
37 sizer.Add(helpButton, (0,1), border=10, flag=wx.ALIGN_RIGHT|wx.RIGHT|wx.TOP)
38 sizer.Add(self.listbox, (1,0), span=(2,2), border=10, flag=wx.EXPAND|wx.LEFT|wx.RIGHT)
39 sizer.Add(addButton, (3,0), span=(1,2), border=5, flag=wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_BOTTOM)
40 sizer.Add(boxsizer, (4,0), span=(4,2), border=10, flag=wx.EXPAND|wx.LEFT|wx.RIGHT)
41 sizer.Add(openPluginLocationButton, (8, 0), border=10, flag=wx.LEFT|wx.BOTTOM)
42 boxsizer.Add(self.pluginEnabledPanel, 1, flag=wx.EXPAND)
44 sizer.AddGrowableCol(0)
45 sizer.AddGrowableRow(1) # Plugins list box
46 sizer.AddGrowableRow(4) # Enabled plugins
47 sizer.AddGrowableRow(5) # Enabled plugins
48 sizer.AddGrowableRow(6) # Enabled plugins
50 sizer = wx.BoxSizer(wx.VERTICAL)
51 self.pluginEnabledPanel.SetSizer(sizer)
53 self.Bind(wx.EVT_BUTTON, self.OnAdd, addButton)
54 self.Bind(wx.EVT_BUTTON, self.OnGeneralHelp, helpButton)
55 self.Bind(wx.EVT_BUTTON, self.OnOpenPluginLocation, openPluginLocationButton)
56 self.listbox.Bind(wx.EVT_LEFT_DCLICK, self.OnAdd)
58 self.updateProfileToControls()
60 def updateProfileToControls(self):
61 self.pluginConfig = profile.getPluginConfig()
62 print 'pluginPanel::updateProfileToControls', self.pluginConfig
63 for p in self.panelList:
65 self.pluginEnabledPanel.GetSizer().Detach(p)
67 for pluginConfig in self.pluginConfig:
68 self._buildPluginPanel(pluginConfig)
70 def _buildPluginPanel(self, pluginConfig):
72 for pluginTest in self.pluginList:
73 if pluginTest['filename'] == pluginConfig['filename']:
78 pluginPanel = wx.Panel(self.pluginEnabledPanel)
79 s = wx.GridBagSizer(2, 2)
80 pluginPanel.SetSizer(s)
81 title = wx.StaticText(pluginPanel, -1, plugin['name'])
82 title.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
83 remButton = wx.Button(pluginPanel, -1, 'X', style=wx.BU_EXACTFIT)
84 helpButton = wx.Button(pluginPanel, -1, '?', style=wx.BU_EXACTFIT)
85 s.Add(title, pos=(0,1), span=(1,2), flag=wx.ALIGN_BOTTOM|wx.TOP|wx.LEFT|wx.RIGHT, border=5)
86 s.Add(helpButton, pos=(0,0), span=(1,1), flag=wx.TOP|wx.LEFT|wx.ALIGN_RIGHT, border=5)
87 s.Add(remButton, pos=(0,3), span=(1,1), flag=wx.TOP|wx.RIGHT|wx.ALIGN_RIGHT, border=5)
88 s.Add(wx.StaticLine(pluginPanel), pos=(1,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
89 info = wx.StaticText(pluginPanel, -1, plugin['info'])
91 s.Add(info, pos=(2,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
93 pluginPanel.paramCtrls = {}
95 for param in plugin['params']:
96 value = param['default']
97 if param['name'] in pluginConfig['params']:
98 value = pluginConfig['params'][param['name']]
100 ctrl = wx.TextCtrl(pluginPanel, -1, value)
101 s.Add(wx.StaticText(pluginPanel, -1, param['description']), pos=(3+i,0), span=(1,2), flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,border=3)
102 s.Add(ctrl, pos=(3+i,2), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
104 ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
106 pluginPanel.paramCtrls[param['name']] = ctrl
109 s.Add(wx.StaticLine(pluginPanel), pos=(3+i,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
111 self.Bind(wx.EVT_BUTTON, self.OnRem, remButton)
112 self.Bind(wx.EVT_BUTTON, self.OnHelp, helpButton)
115 pluginPanel.SetBackgroundColour(self.GetParent().GetBackgroundColour())
116 self.pluginEnabledPanel.GetSizer().Add(pluginPanel, flag=wx.EXPAND)
117 self.pluginEnabledPanel.Layout()
118 self.pluginEnabledPanel.SetSize((1,1))
120 self.pluginEnabledPanel.ScrollChildIntoView(pluginPanel)
121 self.panelList.append(pluginPanel)
124 def OnSettingChange(self, e):
125 print 'pluginPanel::OnSettingChange'
126 for panel in self.panelList:
127 idx = self.panelList.index(panel)
128 for k in panel.paramCtrls.keys():
129 self.pluginConfig[idx]['params'][k] = panel.paramCtrls[k].GetValue()
130 profile.setPluginConfig(self.pluginConfig)
134 if self.listbox.GetSelection() < 0:
135 wx.MessageBox('You need to select a plugin before you can add anything.', 'Error: no plugin selected', wx.OK | wx.ICON_INFORMATION)
137 plugin = self.pluginList[self.listbox.GetSelection()]
138 newConfig = {'filename': plugin['filename'], 'params': {}}
139 if not self._buildPluginPanel(newConfig):
141 self.pluginConfig.append(newConfig)
142 profile.setPluginConfig(self.pluginConfig)
146 panel = e.GetEventObject().GetParent()
147 sizer = self.pluginEnabledPanel.GetSizer()
148 idx = self.panelList.index(panel)
151 for p in self.panelList:
153 self.panelList.pop(idx)
154 for p in self.panelList:
155 sizer.Add(p, flag=wx.EXPAND)
157 self.pluginEnabledPanel.Layout()
158 self.pluginEnabledPanel.SetSize((1,1))
161 self.pluginConfig.pop(idx)
162 profile.setPluginConfig(self.pluginConfig)
166 panel = e.GetEventObject().GetParent()
167 sizer = self.pluginEnabledPanel.GetSizer()
168 idx = self.panelList.index(panel)
170 fname = self.pluginConfig[idx]['filename'].lower()
171 fname = fname[0].upper() + fname[1:]
172 fname = fname[:fname.rfind('.')]
173 webbrowser.open('http://wiki.ultimaker.com/CuraPlugin:_' + fname)
175 def OnGeneralHelp(self, e):
176 webbrowser.open('http://wiki.ultimaker.com/Category:CuraPlugin')
178 def OnOpenPluginLocation(self, e):
179 explorer.openExplorerPath(profile.getPluginBasePaths()[0])