import platform
from Cura.util import meshLoader
+from wx.lib.pubsub import Publisher
+
class mainWindow(wx.Frame):
def __init__(self):
super(mainWindow, self).__init__(None, title=_('Cura - ') + version.getVersion())
self.updateSliceMode()
self.scene.SetFocus()
+ self.dialogframe = None
+ Publisher().subscribe(self.onPluginUpdate, "pluginupdate")
+
+ def onPluginUpdate(self,msg): #receives commands from the plugin thread
+ cmd = str(msg.data).split(";")
+ if cmd[0] == "OpenPluginProgressWindow":
+ if len(cmd)==1: #no titel received
+ cmd.append("Plugin")
+ if len(cmd)<3: #no message text received
+ cmd.append("Plugin is executed...")
+ dialogwidth = 300
+ dialogheight = 80
+ self.dialogframe = wx.Frame(self, -1, cmd[1],pos = ((wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X)-dialogwidth)/2,(wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)-dialogheight)/2), size=(dialogwidth,dialogheight), style = wx.STAY_ON_TOP)
+ self.dialogpanel = wx.Panel(self.dialogframe, -1, pos = (0,0), size = (dialogwidth,dialogheight))
+ self.dlgtext = wx.StaticText(self.dialogpanel, label = cmd[2], pos = (10,10), size = (280,40))
+ self.dlgbar = wx.Gauge(self.dialogpanel,-1, 100, pos = (10,50), size = (280,20), style = wx.GA_HORIZONTAL)
+ self.dialogframe.Show()
+
+ elif cmd[0] == "Progress":
+ number = int(cmd[1])
+ if number <= 100 and self.dialogframe is not None:
+ self.dlgbar.SetValue(number)
+ else:
+ self.dlgbar.SetValue(100)
+ elif cmd[0] == "ClosePluginProgressWindow":
+ self.dialogframe.Destroy()
+ self.dialogframe=None
+ else:
+ print "Unknown Plugin update received: " + cmd[0]
def onTimer(self, e):
#Check if there is something in the clipboard
from Cura.util import pluginInfo
from Cura.util import explorer
+class ListBoxEnh(wx.ListBox):
+ def GetValue(self):
+ return wx.ListBox.GetSelection(self)
+
class pluginPanel(wx.Panel):
def __init__(self, parent, callback):
wx.Panel.__init__(self, parent,-1)
pluginPanel.paramCtrls = {}
i = 0
for param in plugin.getParams():
- value = param['default']
+ if param['type'].lower() == 'bool': #check for type bool in plugin
+ if param['default'].lower() in ["true","false"]:
+ value = param['default'].lower()=="true" #sets default 'true'
+ else:
+ value = int(param['default'])
+ elif param['type'].lower() == 'list': #check for 'type' list in plugin
+ ListOfItems = param['default'].split(',') #prepares selection entries
+ value = 0 #sets default selection first entry
+ else:
+ value = param['default']
if param['name'] in pluginConfig['params']:
value = pluginConfig['params'][param['name']]
-
- ctrl = wx.TextCtrl(pluginPanel, -1, value)
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)
- s.Add(ctrl, pos=(3+i,2), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
-
- ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
+ if param['type'].lower() == 'bool': #checks for type boolean, displays checkbox and sets stored value
+ ctrl = wx.CheckBox(pluginPanel, -1, "")
+ ctrl.SetValue(value in {"TRUE",True,1})
+ s.Add(ctrl, pos=(3+i,2), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
+ ctrl.Bind(wx.EVT_CHECKBOX, self.OnSettingChange) #bind the checkbox event to the same method as for the standard text boxes
+ elif param['type'].lower() == 'list': #checks for 'type' list, displays listbox and sets stored value (integer)
+ ctrl = ListBoxEnh(pluginPanel, -1, wx.DefaultPosition, (-1,(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPixelSize()[1]+1)*len(ListOfItems)+6), ListOfItems)
+ ctrl.Select(value)
+ s.Add(ctrl, pos=(3+i,2), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
+ ctrl.Bind(wx.EVT_LISTBOX, self.OnSettingChange) #bind the listbox event to the same method as for the standard text boxes (derived class necessary due to usage of SetValue method)
+ else: #standard text box
+ ctrl = wx.TextCtrl(pluginPanel, -1, value)
+ s.Add(ctrl, pos=(3+i,2), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=3)
+ ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
pluginPanel.paramCtrls[param['name']] = ctrl
for panel in self.panelList:
idx = self.panelList.index(panel)
for k in panel.paramCtrls.keys():
- self.pluginConfig[idx]['params'][k] = panel.paramCtrls[k].GetValue()
+ if type(panel.paramCtrls[k].GetValue()) == bool:
+ self.pluginConfig[idx]['params'][k] = int(panel.paramCtrls[k].GetValue())
+ else:
+ self.pluginConfig[idx]['params'][k] = panel.paramCtrls[k].GetValue()
pluginInfo.setPostProcessPluginConfig(self.pluginConfig)
self.callback()