1 from __future__ import absolute_import
5 from wx.lib import scrolledpanel
7 from Cura.util import profile
8 from Cura.util import explorer
10 class pluginPanel(wx.Panel):
11 def __init__(self, parent):
12 wx.Panel.__init__(self, parent,-1)
14 self.pluginList = profile.getPluginList()
16 sizer = wx.GridBagSizer(2, 2)
20 for effect in self.pluginList:
21 effectStringList.append(effect['name'])
23 self.listbox = wx.ListBox(self, -1, choices=effectStringList)
24 title = wx.StaticText(self, -1, "Plugins:")
25 title.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
26 helpButton = wx.Button(self, -1, '?', style=wx.BU_EXACTFIT)
27 addButton = wx.Button(self, -1, 'V', style=wx.BU_EXACTFIT)
28 openPluginLocationButton = wx.Button(self, -1, 'Open plugin location')
29 sb = wx.StaticBox(self, label="Enabled plugins")
30 boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
31 self.pluginEnabledPanel = scrolledpanel.ScrolledPanel(self)
32 self.pluginEnabledPanel.SetupScrolling(False, True)
34 sizer.Add(title, (0,0), border=10, flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.TOP)
35 sizer.Add(helpButton, (0,1), border=10, flag=wx.ALIGN_RIGHT|wx.RIGHT|wx.TOP)
36 sizer.Add(self.listbox, (1,0), span=(2,2), border=10, flag=wx.EXPAND|wx.LEFT|wx.RIGHT)
37 sizer.Add(addButton, (3,0), span=(1,2), border=5, flag=wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_BOTTOM)
38 sizer.Add(boxsizer, (4,0), span=(4,2), border=10, flag=wx.EXPAND|wx.LEFT|wx.RIGHT)
39 sizer.Add(openPluginLocationButton, (8, 0), border=10, flag=wx.LEFT|wx.BOTTOM)
40 boxsizer.Add(self.pluginEnabledPanel, 1, flag=wx.EXPAND)
42 sizer.AddGrowableCol(0)
43 sizer.AddGrowableRow(1) # Plugins list box
44 sizer.AddGrowableRow(4) # Enabled plugins
45 sizer.AddGrowableRow(5) # Enabled plugins
46 sizer.AddGrowableRow(6) # Enabled plugins
48 sizer = wx.BoxSizer(wx.VERTICAL)
49 self.pluginEnabledPanel.SetSizer(sizer)
51 self.Bind(wx.EVT_BUTTON, self.OnAdd, addButton)
52 self.Bind(wx.EVT_BUTTON, self.OnGeneralHelp, helpButton)
53 self.Bind(wx.EVT_BUTTON, self.OnOpenPluginLocation, openPluginLocationButton)
54 self.listbox.Bind(wx.EVT_LEFT_DCLICK, self.OnAdd)
56 self.updateProfileToControls()
58 def updateProfileToControls(self):
59 self.pluginConfig = profile.getPluginConfig()
60 for p in self.panelList:
62 self.pluginEnabledPanel.GetSizer().Detach(p)
64 for pluginConfig in self.pluginConfig:
65 self._buildPluginPanel(pluginConfig)
67 def _buildPluginPanel(self, pluginConfig):
69 for pluginTest in self.pluginList:
70 if pluginTest['filename'] == pluginConfig['filename']:
75 pluginPanel = wx.Panel(self.pluginEnabledPanel)
76 s = wx.GridBagSizer(2, 2)
77 pluginPanel.SetSizer(s)
78 title = wx.StaticText(pluginPanel, -1, plugin['name'])
79 title.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
80 remButton = wx.Button(pluginPanel, -1, 'X', style=wx.BU_EXACTFIT)
81 helpButton = wx.Button(pluginPanel, -1, '?', style=wx.BU_EXACTFIT)
82 s.Add(title, pos=(0,1), span=(1,2), flag=wx.ALIGN_BOTTOM|wx.TOP|wx.LEFT|wx.RIGHT, border=5)
83 s.Add(helpButton, pos=(0,0), span=(1,1), flag=wx.TOP|wx.LEFT|wx.ALIGN_RIGHT, border=5)
84 s.Add(remButton, pos=(0,3), span=(1,1), flag=wx.TOP|wx.RIGHT|wx.ALIGN_RIGHT, border=5)
85 s.Add(wx.StaticLine(pluginPanel), pos=(1,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
86 info = wx.StaticText(pluginPanel, -1, plugin['info'])
88 s.Add(info, pos=(2,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
90 pluginPanel.paramCtrls = {}
92 for param in plugin['params']:
93 value = param['default']
94 if param['name'] in pluginConfig['params']:
95 value = pluginConfig['params'][param['name']]
97 ctrl = wx.TextCtrl(pluginPanel, -1, value)
98 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)
99 s.Add(ctrl, pos=(3+i,2), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
101 ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
103 pluginPanel.paramCtrls[param['name']] = ctrl
106 s.Add(wx.StaticLine(pluginPanel), pos=(3+i,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
108 self.Bind(wx.EVT_BUTTON, self.OnRem, remButton)
109 self.Bind(wx.EVT_BUTTON, self.OnHelp, helpButton)
112 pluginPanel.SetBackgroundColour(self.GetParent().GetBackgroundColour())
113 self.pluginEnabledPanel.GetSizer().Add(pluginPanel, flag=wx.EXPAND)
114 self.pluginEnabledPanel.Layout()
115 self.pluginEnabledPanel.SetSize((1,1))
117 self.pluginEnabledPanel.ScrollChildIntoView(pluginPanel)
118 self.panelList.append(pluginPanel)
121 def OnSettingChange(self, e):
122 for panel in self.panelList:
123 idx = self.panelList.index(panel)
124 for k in panel.paramCtrls.keys():
125 self.pluginConfig[idx]['params'][k] = panel.paramCtrls[k].GetValue()
126 profile.setPluginConfig(self.pluginConfig)
129 if self.listbox.GetSelection() < 0:
130 wx.MessageBox('You need to select a plugin before you can add anything.', 'Error: no plugin selected', wx.OK | wx.ICON_INFORMATION)
132 plugin = self.pluginList[self.listbox.GetSelection()]
133 newConfig = {'filename': plugin['filename'], 'params': {}}
134 if not self._buildPluginPanel(newConfig):
136 self.pluginConfig.append(newConfig)
137 profile.setPluginConfig(self.pluginConfig)
140 panel = e.GetEventObject().GetParent()
141 sizer = self.pluginEnabledPanel.GetSizer()
142 idx = self.panelList.index(panel)
145 for p in self.panelList:
147 self.panelList.pop(idx)
148 for p in self.panelList:
149 sizer.Add(p, flag=wx.EXPAND)
151 self.pluginEnabledPanel.Layout()
152 self.pluginEnabledPanel.SetSize((1,1))
155 self.pluginConfig.pop(idx)
156 profile.setPluginConfig(self.pluginConfig)
159 panel = e.GetEventObject().GetParent()
160 sizer = self.pluginEnabledPanel.GetSizer()
161 idx = self.panelList.index(panel)
163 fname = self.pluginConfig[idx]['filename'].lower()
164 fname = fname[0].upper() + fname[1:]
165 fname = fname[:fname.rfind('.')]
166 webbrowser.open('http://wiki.ultimaker.com/CuraPlugin:_' + fname)
168 def OnGeneralHelp(self, e):
169 webbrowser.open('http://wiki.ultimaker.com/Category:CuraPlugin')
171 def OnOpenPluginLocation(self, e):
172 explorer.openExplorerPath(profile.getPluginBasePaths()[0])