chiark / gitweb /
Plugin enhancements
authorDim3nsioneer <Dim3nsioneer@gmx.ch>
Thu, 16 Oct 2014 09:43:14 +0000 (11:43 +0200)
committerDim3nsioneer <Dim3nsioneer@gmx.ch>
Thu, 16 Oct 2014 09:43:14 +0000 (11:43 +0200)
- allows for checkboxes in plugins (type bool)
- allows for listboxes in plugins (type list)
- allows for progress bar window during plugin execution

Cura/gui/mainWindow.py
Cura/gui/pluginPanel.py

index 5bf0d97f388f1b899e78d9859713bc7abc496b56..d10d728f3922c85b579fbe5f7e987cf0c42a3b15 100644 (file)
@@ -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
index ce3fe041e2b6023e3e8d0f2e65c0579a9611a7db..68b65e9abc2cc9e94034d82874e69d642b5480ef 100644 (file)
@@ -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()