From: Dim3nsioneer Date: Thu, 16 Oct 2014 09:43:14 +0000 (+0200) Subject: Plugin enhancements X-Git-Tag: lulzbot-14.12~63 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a803faf0db101da7e227537c38ab56a1574f01fe;p=cura.git Plugin enhancements - allows for checkboxes in plugins (type bool) - allows for listboxes in plugins (type list) - allows for progress bar window during plugin execution --- diff --git a/Cura/gui/mainWindow.py b/Cura/gui/mainWindow.py index ff569bda..5765ef20 100644 --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@ -25,6 +25,8 @@ from Cura.util import version 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()) @@ -273,6 +275,35 @@ class mainWindow(wx.Frame): 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 diff --git a/Cura/gui/pluginPanel.py b/Cura/gui/pluginPanel.py index ce3fe041..68b65e9a 100644 --- a/Cura/gui/pluginPanel.py +++ b/Cura/gui/pluginPanel.py @@ -9,6 +9,10 @@ from Cura.util import profile 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) @@ -93,15 +97,33 @@ class pluginPanel(wx.Panel): 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 @@ -125,7 +147,10 @@ class pluginPanel(wx.Panel): 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()