2 import sys, math, threading, os, webbrowser
3 from wx.lib import scrolledpanel
5 from util import profile
6 from util import exporer
8 class pluginPanel(wx.Panel):
9 def __init__(self, parent):
10 wx.Panel.__init__(self, parent,-1)
12 self.pluginList = profile.getPluginList()
14 sizer = wx.GridBagSizer(2, 2)
18 for effect in self.pluginList:
19 effectStringList.append(effect['name'])
21 self.listbox = wx.ListBox(self, -1, choices=effectStringList)
22 title = wx.StaticText(self, -1, "Plugins:")
23 title.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
24 helpButton = wx.Button(self, -1, '?', style=wx.BU_EXACTFIT)
25 addButton = wx.Button(self, -1, '>', style=wx.BU_EXACTFIT)
26 openPluginLocationButton = wx.Button(self, -1, 'Open plugin location')
27 sb = wx.StaticBox(self, label="Enabled plugins")
28 boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
29 self.pluginEnabledPanel = scrolledpanel.ScrolledPanel(self)
30 self.pluginEnabledPanel.SetupScrolling(False, True)
32 sizer.Add(title, (0,0), border=10, flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.TOP)
33 sizer.Add(helpButton, (0,1), border=10, flag=wx.ALIGN_RIGHT|wx.RIGHT|wx.TOP)
34 sizer.Add(self.listbox, (1,0), span=(2,2), border=10, flag=wx.EXPAND|wx.LEFT|wx.RIGHT)
35 sizer.Add(addButton, (1,2), border=5, flag=wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_BOTTOM)
36 sizer.Add(boxsizer, (1,3), span=(2,1), border=10, flag=wx.EXPAND|wx.LEFT|wx.RIGHT)
37 sizer.Add(openPluginLocationButton, (3, 0), span=(1,2), border=10, flag=wx.LEFT|wx.BOTTOM)
38 boxsizer.Add(self.pluginEnabledPanel, 1, flag=wx.EXPAND)
40 sizer.AddGrowableCol(3)
41 sizer.AddGrowableRow(1)
42 sizer.AddGrowableRow(2)
44 sizer = wx.BoxSizer(wx.VERTICAL)
45 self.pluginEnabledPanel.SetSizer(sizer)
47 self.Bind(wx.EVT_BUTTON, self.OnAdd, addButton)
48 self.Bind(wx.EVT_BUTTON, self.OnGeneralHelp, helpButton)
49 self.Bind(wx.EVT_BUTTON, self.OnOpenPluginLocation, openPluginLocationButton)
50 self.listbox.Bind(wx.EVT_LEFT_DCLICK, self.OnAdd)
52 self.updateProfileToControls()
54 def updateProfileToControls(self):
55 self.pluginConfig = profile.getPluginConfig()
56 for p in self.panelList:
58 self.pluginEnabledPanel.GetSizer().Detach(p)
60 for pluginConfig in self.pluginConfig:
61 self._buildPluginPanel(pluginConfig)
63 def _buildPluginPanel(self, pluginConfig):
65 for pluginTest in self.pluginList:
66 if pluginTest['filename'] == pluginConfig['filename']:
71 pluginPanel = wx.Panel(self.pluginEnabledPanel)
72 s = wx.GridBagSizer(2, 2)
73 pluginPanel.SetSizer(s)
74 title = wx.StaticText(pluginPanel, -1, plugin['name'])
75 title.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize(), wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
76 remButton = wx.Button(pluginPanel, -1, 'X', style=wx.BU_EXACTFIT)
77 helpButton = wx.Button(pluginPanel, -1, '?', style=wx.BU_EXACTFIT)
78 s.Add(title, pos=(0,1), span=(1,2), flag=wx.ALIGN_BOTTOM|wx.TOP|wx.LEFT|wx.RIGHT, border=5)
79 s.Add(helpButton, pos=(0,0), span=(1,1), flag=wx.TOP|wx.LEFT|wx.ALIGN_RIGHT, border=5)
80 s.Add(remButton, pos=(0,3), span=(1,1), flag=wx.TOP|wx.RIGHT|wx.ALIGN_RIGHT, border=5)
81 s.Add(wx.StaticLine(pluginPanel), pos=(1,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
82 info = wx.StaticText(pluginPanel, -1, plugin['info'])
84 s.Add(info, pos=(2,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
86 pluginPanel.paramCtrls = {}
88 for param in plugin['params']:
89 value = param['default']
90 if param['name'] in pluginConfig['params']:
91 value = pluginConfig['params'][param['name']]
93 ctrl = wx.TextCtrl(pluginPanel, -1, value)
94 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)
95 s.Add(ctrl, pos=(3+i,2), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
97 ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
99 pluginPanel.paramCtrls[param['name']] = ctrl
102 s.Add(wx.StaticLine(pluginPanel), pos=(3+i,0), span=(1,4), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
104 self.Bind(wx.EVT_BUTTON, self.OnRem, remButton)
105 self.Bind(wx.EVT_BUTTON, self.OnHelp, helpButton)
108 pluginPanel.SetBackgroundColour(self.GetParent().GetBackgroundColour())
109 self.pluginEnabledPanel.GetSizer().Add(pluginPanel, flag=wx.EXPAND)
110 self.pluginEnabledPanel.Layout()
111 self.pluginEnabledPanel.SetSize((1,1))
113 self.pluginEnabledPanel.ScrollChildIntoView(pluginPanel)
114 self.panelList.append(pluginPanel)
117 def OnSettingChange(self, e):
118 for panel in self.panelList:
119 idx = self.panelList.index(panel)
120 for k in panel.paramCtrls.keys():
121 self.pluginConfig[idx]['params'][k] = panel.paramCtrls[k].GetValue()
122 profile.setPluginConfig(self.pluginConfig)
125 if self.listbox.GetSelection() < 0:
127 plugin = self.pluginList[self.listbox.GetSelection()]
128 newConfig = {'filename': plugin['filename'], 'params': {}}
129 if not self._buildPluginPanel(newConfig):
131 self.pluginConfig.append(newConfig)
132 profile.setPluginConfig(self.pluginConfig)
135 panel = e.GetEventObject().GetParent()
136 sizer = self.pluginEnabledPanel.GetSizer()
137 idx = self.panelList.index(panel)
140 for p in self.panelList:
142 self.panelList.pop(idx)
143 for p in self.panelList:
144 sizer.Add(p, flag=wx.EXPAND)
146 self.pluginEnabledPanel.Layout()
147 self.pluginEnabledPanel.SetSize((1,1))
150 self.pluginConfig.pop(idx)
151 profile.setPluginConfig(self.pluginConfig)
154 panel = e.GetEventObject().GetParent()
155 sizer = self.pluginEnabledPanel.GetSizer()
156 idx = self.panelList.index(panel)
158 fname = self.pluginConfig[idx]['filename'].lower()
159 fname = fname[0].upper() + fname[1:]
160 fname = fname[:fname.rfind('.')]
161 webbrowser.open('http://wiki.ultimaker.com/CuraPlugin:_' + fname)
163 def OnGeneralHelp(self, e):
164 webbrowser.open('http://wiki.ultimaker.com/Category:CuraPlugin')
166 def OnOpenPluginLocation(self, e):
167 exporer.openExporerPath(profile.getPluginBasePaths()[0])