Beremiz.py
changeset 94 c7fac98c9351
parent 93 d53a02609e5f
child 97 9c6fdf60ad2e
equal deleted inserted replaced
93:d53a02609e5f 94:c7fac98c9351
   514                     bsizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
   514                     bsizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
   515                 
   515                 
   516                 plugin_infos = plugin.GetParamsAttributes()
   516                 plugin_infos = plugin.GetParamsAttributes()
   517 
   517 
   518                 psizer = wx.BoxSizer(wx.HORIZONTAL)
   518                 psizer = wx.BoxSizer(wx.HORIZONTAL)
   519                 self.RefreshSizerElement(window, psizer, plugin_infos, None, True, root)
   519                 self.RefreshSizerElement(window, psizer, plugin, plugin_infos, None, True, root)
   520 
   520 
   521                 msizer = wx.BoxSizer(wx.VERTICAL)
   521                 msizer = wx.BoxSizer(wx.VERTICAL)
   522                 msizer.AddSizer(bsizer, 0, border=0, flag=wx.GROW)
   522                 msizer.AddSizer(bsizer, 0, border=0, flag=wx.GROW)
   523                 if len(plugin.PluginMethods) > 0: #and plugin != self.PluginRoot 
   523                 if len(plugin.PluginMethods) > 0: #and plugin != self.PluginRoot 
   524                     for plugin_method in plugin.PluginMethods:
   524                     for plugin_method in plugin.PluginMethods:
   597             item, root_cookie = self.PluginTree.GetFirstChild(root)
   597             item, root_cookie = self.PluginTree.GetFirstChild(root)
   598             while item is not None and item.IsOk() :
   598             while item is not None and item.IsOk() :
   599                 res.extend(self.ResizePluginTreeWindow_r(item, sz, pt))
   599                 res.extend(self.ResizePluginTreeWindow_r(item, sz, pt))
   600                 item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   600                 item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   601         return res
   601         return res
   602 
       
   603 
   602 
   604     def GetSelectedPluginName(self, selected = None):
   603     def GetSelectedPluginName(self, selected = None):
   605         if selected is None:
   604         if selected is None:
   606             selected = self.PluginTree.GetSelection()
   605             selected = self.PluginTree.GetSelection()
   607         if selected is None or not selected.IsOk():
   606         if selected is None or not selected.IsOk():
   787             infos = plugin.GetParamsAttributes()
   786             infos = plugin.GetParamsAttributes()
   788             if len(self.MenuSizer.GetChildren()) > 1:
   787             if len(self.MenuSizer.GetChildren()) > 1:
   789                 self.ClearSizer(self.MenuSizer.GetChildren()[1].GetSizer())
   788                 self.ClearSizer(self.MenuSizer.GetChildren()[1].GetSizer())
   790                 self.MenuSizer.Remove(1)
   789                 self.MenuSizer.Remove(1)
   791             self.ClearSizer(self.ParamsPanelMainSizer)
   790             self.ClearSizer(self.ParamsPanelMainSizer)
   792             self.RefreshSizerElement(self.ParamsPanel, self.ParamsPanelMainSizer, infos, None, False)
   791             self.RefreshSizerElement(self.ParamsPanel, self.ParamsPanelMainSizer, plugin, infos, None, False)
   793             if plugin != self.PluginRoot and len(plugin.PluginMethods) > 0:
   792             if plugin != self.PluginRoot and len(plugin.PluginMethods) > 0:
   794                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   793                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   795                 self.MenuSizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
   794                 self.MenuSizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
   796                 for plugin_infos in plugin.PluginMethods:
   795                 for plugin_infos in plugin.PluginMethods:
   797                     if "method" in plugin_infos:
   796                     if "method" in plugin_infos:
   828         def OnButtonClick(event):
   827         def OnButtonClick(event):
   829             method(plugin, self.Log)
   828             method(plugin, self.Log)
   830             event.Skip()
   829             event.Skip()
   831         return OnButtonClick
   830         return OnButtonClick
   832     
   831     
   833     def GetChoiceCallBackFunction(self, choicectrl, path, selected=None):
   832     def GetChoiceCallBackFunction(self, choicectrl, plugin, path, selected=None):
   834         def OnChoiceChanged(event):
   833         def OnChoiceChanged(event):
   835             plugin = self.GetSelectedPlugin(selected)
       
   836             if plugin:
   834             if plugin:
   837                 res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log)
   835                 res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log)
   838                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
   836                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
   839                 choicectrl.SetStringSelection(res)
   837                 choicectrl.SetStringSelection(res)
   840             event.Skip()
   838             event.Skip()
   841         return OnChoiceChanged
   839         return OnChoiceChanged
   842     
   840     
   843     def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path, selected=None):
   841     def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, plugin, path, selected=None):
   844         def OnChoiceContentChanged(event):
   842         def OnChoiceContentChanged(event):
   845             plugin = self.GetSelectedPlugin(selected)
       
   846             if plugin:
   843             if plugin:
   847                 res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log)
   844                 res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log)
   848                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
   845                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
   849                 choicectrl.SetStringSelection(res)
   846                 choicectrl.SetStringSelection(res)
   850                 infos = self.PluginRoot.GetParamsAttributes(path)
   847                 infos = self.PluginRoot.GetParamsAttributes(path)
   851                 staticbox = staticboxsizer.GetStaticBox()
   848                 staticbox = staticboxsizer.GetStaticBox()
   852                 staticbox.SetLabel("%(name)s - %(value)s"%infos)
   849                 staticbox.SetLabel("%(name)s - %(value)s"%infos)
   853                 if wx.VERSION < (2, 8, 0):
   850                 if wx.VERSION < (2, 8, 0):
   854                     self.ParamsPanel.Freeze()
   851                     self.ParamsPanel.Freeze()
   855                     self.RefreshSizerElement(self.ParamsPanel, staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]), selected=selected)
   852                     self.RefreshSizerElement(self.ParamsPanel, staticboxsizer, plugin, infos["children"], "%s.%s"%(path, infos["name"]), selected=selected)
   856                     self.ParamsPanelMainSizer.Layout()
   853                     self.ParamsPanelMainSizer.Layout()
   857                     self.ParamsPanel.Thaw()
   854                     self.ParamsPanel.Thaw()
   858                     self.ParamsPanel.Refresh()
   855                     self.ParamsPanel.Refresh()
   859                 else:
   856                 else:
   860                     wx.CallAfter(self.RefreshPluginTree)
   857                     wx.CallAfter(self.RefreshPluginTree)
   861             event.Skip()
   858             event.Skip()
   862         return OnChoiceContentChanged
   859         return OnChoiceContentChanged
   863     
   860     
   864     def GetTextCtrlCallBackFunction(self, textctrl, path, selected=None):
   861     def GetTextCtrlCallBackFunction(self, textctrl, plugin, path, selected=None):
   865         def OnTextCtrlChanged(event):
   862         def OnTextCtrlChanged(event):
   866             plugin = self.GetSelectedPlugin(selected)
       
   867             if plugin:
   863             if plugin:
   868                 res, StructChanged = plugin.SetParamsAttribute(path, textctrl.GetValue(), self.Log)
   864                 res, StructChanged = plugin.SetParamsAttribute(path, textctrl.GetValue(), self.Log)
   869                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
   865                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
   870                 textctrl.SetValue(res)
   866                 textctrl.SetValue(res)
   871             event.Skip()
   867             event.Skip()
   872         return OnTextCtrlChanged
   868         return OnTextCtrlChanged
   873     
   869     
   874     def GetCheckBoxCallBackFunction(self, chkbx, path, selected=None):
   870     def GetCheckBoxCallBackFunction(self, chkbx, plugin, path, selected=None):
   875         def OnCheckBoxChanged(event):
   871         def OnCheckBoxChanged(event):
   876             plugin = self.GetSelectedPlugin(selected)
       
   877             if plugin:
   872             if plugin:
   878                 res, StructChanged = plugin.SetParamsAttribute(path, chkbx.IsChecked(), self.Log)
   873                 res, StructChanged = plugin.SetParamsAttribute(path, chkbx.IsChecked(), self.Log)
   879                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
   874                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
   880                 chkbx.SetValue(res)
   875                 chkbx.SetValue(res)
   881             event.Skip()
   876             event.Skip()
   891                     staticboxes.append(item_sizer.GetStaticBox())
   886                     staticboxes.append(item_sizer.GetStaticBox())
   892         sizer.Clear(True)
   887         sizer.Clear(True)
   893         for staticbox in staticboxes:
   888         for staticbox in staticboxes:
   894             staticbox.Destroy()
   889             staticbox.Destroy()
   895                 
   890                 
   896     def RefreshSizerElement(self, parent, sizer, elements, path, clean = True, selected = None):
   891     def RefreshSizerElement(self, parent, sizer, plugin, elements, path, clean = True, selected = None):
   897         if clean:
   892         if clean:
   898             sizer.Clear(True)
   893             sizer.Clear(True)
   899         first = True
   894         first = True
   900         for element_infos in elements:
   895         for element_infos in elements:
   901             if path:
   896             if path:
   929                     staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, 
   924                     staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, 
   930                         name='%s_staticbox'%element_infos["name"], parent=parent,
   925                         name='%s_staticbox'%element_infos["name"], parent=parent,
   931                         pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
   926                         pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
   932                     staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   927                     staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   933                     sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
   928                     sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
   934                     self.RefreshSizerElement(parent, staticboxsizer, element_infos["children"], element_path, selected)
   929                     self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path, selected)
   935                     callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, element_path, selected)
   930                     callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, plugin, element_path, selected)
   936                 else:
   931                 else:
   937                     for choice in element_infos["type"]:
   932                     for choice in element_infos["type"]:
   938                         choicectrl.Append(choice)
   933                         choicectrl.Append(choice)
   939                     callback = self.GetChoiceCallBackFunction(choicectrl, element_path, selected)
   934                     callback = self.GetChoiceCallBackFunction(choicectrl, plugin, element_path, selected)
   940                 if element_infos["value"]:
   935                 if element_infos["value"]:
   941                     choicectrl.SetStringSelection(element_infos["value"])
   936                     choicectrl.SetStringSelection(element_infos["value"])
   942                 choicectrl.Bind(wx.EVT_CHOICE, callback, id=id)
   937                 choicectrl.Bind(wx.EVT_CHOICE, callback, id=id)
   943             elif isinstance(element_infos["type"], types.DictType):
   938             elif isinstance(element_infos["type"], types.DictType):
   944                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   939                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   966                 spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
   961                 spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
   967                     pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
   962                     pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
   968                 spinctrl.SetRange(scmin,scmax)
   963                 spinctrl.SetRange(scmin,scmax)
   969                 boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
   964                 boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
   970                 spinctrl.SetValue(element_infos["value"])
   965                 spinctrl.SetValue(element_infos["value"])
   971                 spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path, selected), id=id)
   966                 spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path, selected), id=id)
   972             elif element_infos["type"] == "element":
   967             elif element_infos["type"] == "element":
   973                 staticbox = wx.StaticBox(id=-1, label=element_infos["name"], 
   968                 staticbox = wx.StaticBox(id=-1, label=element_infos["name"], 
   974                     name='%s_staticbox'%element_infos["name"], parent=parent,
   969                     name='%s_staticbox'%element_infos["name"], parent=parent,
   975                     pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
   970                     pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
   976                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   971                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   977                 if first:
   972                 if first:
   978                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
   973                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
   979                 else:
   974                 else:
   980                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW)
   975                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW)
   981                 self.RefreshSizerElement(parent, staticboxsizer, element_infos["children"], element_path, selected)
   976                 self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path, False, selected)
   982             else:
   977             else:
   983                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   978                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   984                 if first:
   979                 if first:
   985                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
   980                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
   986                 else:
   981                 else:
   999                 if element_infos["type"] == "boolean":
   994                 if element_infos["type"] == "boolean":
  1000                     checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, 
   995                     checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, 
  1001                         pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
   996                         pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
  1002                     boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
   997                     boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
  1003                     checkbox.SetValue(element_infos["value"])
   998                     checkbox.SetValue(element_infos["value"])
  1004                     checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path, selected), id=id)
   999                     checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path, selected), id=id)
  1005                 elif element_infos["type"] in ["unsignedLong", "long","integer"]:
  1000                 elif element_infos["type"] in ["unsignedLong", "long","integer"]:
  1006                     if element_infos["type"].startswith("unsigned"):
  1001                     if element_infos["type"].startswith("unsigned"):
  1007                         scmin = 0
  1002                         scmin = 0
  1008                     else:
  1003                     else:
  1009                         scmin = -(2**31)
  1004                         scmin = -(2**31)
  1011                     spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
  1006                     spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
  1012                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
  1007                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
  1013                     spinctrl.SetRange(scmin, scmax)
  1008                     spinctrl.SetRange(scmin, scmax)
  1014                     boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
  1009                     boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
  1015                     spinctrl.SetValue(element_infos["value"])
  1010                     spinctrl.SetValue(element_infos["value"])
  1016                     spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path, selected), id=id)
  1011                     spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path, selected), id=id)
  1017                 else:
  1012                 else:
  1018                     textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=parent, 
  1013                     textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=parent, 
  1019                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.TE_PROCESS_ENTER)
  1014                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.TE_PROCESS_ENTER)
  1020                     boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
  1015                     boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
  1021                     textctrl.SetValue(str(element_infos["value"]))
  1016                     textctrl.SetValue(str(element_infos["value"]))
  1022                     textctrl.Bind(wx.EVT_TEXT_ENTER, self.GetTextCtrlCallBackFunction(textctrl, element_path, selected), id=id)
  1017                     textctrl.Bind(wx.EVT_TEXT_ENTER, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path, selected), id=id)
  1023                     textctrl.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(textctrl, element_path, selected))
  1018                     textctrl.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path, selected))
  1024             first = False
  1019             first = False
  1025     
  1020     
  1026     def OnNewProjectMenu(self, event):
  1021     def OnNewProjectMenu(self, event):
  1027         defaultpath = self.PluginRoot.GetProjectPath()
  1022         defaultpath = self.PluginRoot.GetProjectPath()
  1028         if not defaultpath:
  1023         if not defaultpath: