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 for p in self.panelList:
64 self.pluginEnabledPanel.GetSizer().Detach(p)
66 for pluginConfig in self.pluginConfig:
67 self._buildPluginPanel(pluginConfig)
69 def _buildPluginPanel(self, pluginConfig):
71 for pluginTest in self.pluginList:
72 if pluginTest['filename'] == pluginConfig['filename']:
77 pluginPanel = wx.Panel(self.pluginEnabledPanel)
78 s = wx.GridBagSizer(2, 2)
79 pluginPanel.SetSizer(s)
80 title = wx.StaticText(pluginPanel, -1, plugin['name'])
81 title.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
82 remButton = wx.Button(pluginPanel, -1, 'X', style=wx.BU_EXACTFIT)
83 helpButton = wx.Button(pluginPanel, -1, '?', style=wx.BU_EXACTFIT)
84 s.Add(title, pos=(0,1), span=(1,2), flag=wx.ALIGN_BOTTOM|wx.TOP|wx.LEFT|wx.RIGHT, border=5)
85 s.Add(helpButton, pos=(0,0), span=(1,1), flag=wx.TOP|wx.LEFT|wx.ALIGN_RIGHT, border=5)
86 s.Add(remButton, pos=(0,3), span=(1,1), flag=wx.TOP|wx.RIGHT|wx.ALIGN_RIGHT, border=5)
87 s.Add(wx.StaticLine(pluginPanel), pos=(1,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
88 info = wx.StaticText(pluginPanel, -1, plugin['info'])
90 s.Add(info, pos=(2,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
92 pluginPanel.paramCtrls = {}
94 for param in plugin['params']:
95 value = param['default']
96 if param['name'] in pluginConfig['params']:
97 value = pluginConfig['params'][param['name']]
99 ctrl = wx.TextCtrl(pluginPanel, -1, value)
100 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)
101 s.Add(ctrl, pos=(3+i,2), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
103 ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
105 pluginPanel.paramCtrls[param['name']] = ctrl
108 s.Add(wx.StaticLine(pluginPanel), pos=(3+i,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
110 self.Bind(wx.EVT_BUTTON, self.OnRem, remButton)
111 self.Bind(wx.EVT_BUTTON, self.OnHelp, helpButton)
114 pluginPanel.SetBackgroundColour(self.GetParent().GetBackgroundColour())
115 self.pluginEnabledPanel.GetSizer().Add(pluginPanel, flag=wx.EXPAND)
116 self.pluginEnabledPanel.Layout()
117 self.pluginEnabledPanel.SetSize((1,1))
119 self.pluginEnabledPanel.ScrollChildIntoView(pluginPanel)
120 self.panelList.append(pluginPanel)
123 def OnSettingChange(self, e):
124 for panel in self.panelList:
125 idx = self.panelList.index(panel)
126 for k in panel.paramCtrls.keys():
127 self.pluginConfig[idx]['params'][k] = panel.paramCtrls[k].GetValue()
128 profile.setPluginConfig(self.pluginConfig)
132 if self.listbox.GetSelection() < 0:
133 wx.MessageBox('You need to select a plugin before you can add anything.', 'Error: no plugin selected', wx.OK | wx.ICON_INFORMATION)
135 plugin = self.pluginList[self.listbox.GetSelection()]
136 newConfig = {'filename': plugin['filename'], 'params': {}}
137 if not self._buildPluginPanel(newConfig):
139 self.pluginConfig.append(newConfig)
140 profile.setPluginConfig(self.pluginConfig)
144 panel = e.GetEventObject().GetParent()
145 sizer = self.pluginEnabledPanel.GetSizer()
146 idx = self.panelList.index(panel)
149 for p in self.panelList:
151 self.panelList.pop(idx)
152 for p in self.panelList:
153 sizer.Add(p, flag=wx.EXPAND)
155 self.pluginEnabledPanel.Layout()
156 self.pluginEnabledPanel.SetSize((1,1))
159 self.pluginConfig.pop(idx)
160 profile.setPluginConfig(self.pluginConfig)
164 panel = e.GetEventObject().GetParent()
165 sizer = self.pluginEnabledPanel.GetSizer()
166 idx = self.panelList.index(panel)
168 fname = self.pluginConfig[idx]['filename'].lower()
169 fname = fname[0].upper() + fname[1:]
170 fname = fname[:fname.rfind('.')]
171 webbrowser.open('http://wiki.ultimaker.com/CuraPlugin:_' + fname)
173 def OnGeneralHelp(self, e):
174 webbrowser.open('http://wiki.ultimaker.com/Category:CuraPlugin')
176 def OnOpenPluginLocation(self, e):
177 explorer.openExplorerPath(profile.getPluginBasePaths()[0])