Beremiz.py
changeset 28 848ce4b1f9e4
parent 25 fa7503684c28
child 33 59b84ab7bf8b
equal deleted inserted replaced
27:1db681d34579 28:848ce4b1f9e4
   200         self.Bind(wx.EVT_MENU, self.OnAboutMenu,
   200         self.Bind(wx.EVT_MENU, self.OnAboutMenu,
   201               id=ID_BEREMIZHELPMENUITEMS1)
   201               id=ID_BEREMIZHELPMENUITEMS1)
   202     
   202     
   203     def _init_coll_menuBar1_Menus(self, parent):
   203     def _init_coll_menuBar1_Menus(self, parent):
   204         parent.Append(menu=self.FileMenu, title=u'File')
   204         parent.Append(menu=self.FileMenu, title=u'File')
   205         parent.Append(menu=self.EditMenu, title=u'Edit')
   205         #parent.Append(menu=self.EditMenu, title=u'Edit')
   206         parent.Append(menu=self.RunMenu, title=u'Run')
   206         #parent.Append(menu=self.RunMenu, title=u'Run')
   207         parent.Append(menu=self.HelpMenu, title=u'Help')
   207         parent.Append(menu=self.HelpMenu, title=u'Help')
   208     
   208     
   209     def _init_utils(self):
   209     def _init_utils(self):
   210         self.menuBar1 = wx.MenuBar()
   210         self.menuBar1 = wx.MenuBar()
   211         self.FileMenu = wx.Menu(title=u'')
   211         self.FileMenu = wx.Menu(title=u'')
   212         self.EditMenu = wx.Menu(title=u'')
   212         #self.EditMenu = wx.Menu(title=u'')
   213         self.RunMenu = wx.Menu(title=u'')
   213         #self.RunMenu = wx.Menu(title=u'')
   214         self.HelpMenu = wx.Menu(title=u'')
   214         self.HelpMenu = wx.Menu(title=u'')
   215         
   215         
   216         self._init_coll_menuBar1_Menus(self.menuBar1)
   216         self._init_coll_menuBar1_Menus(self.menuBar1)
   217         self._init_coll_FileMenu_Items(self.FileMenu)
   217         self._init_coll_FileMenu_Items(self.FileMenu)
   218         self._init_coll_EditMenu_Items(self.EditMenu)
   218         #self._init_coll_EditMenu_Items(self.EditMenu)
   219         self._init_coll_RunMenu_Items(self.RunMenu)
   219         #self._init_coll_RunMenu_Items(self.RunMenu)
   220         self._init_coll_HelpMenu_Items(self.HelpMenu)
   220         self._init_coll_HelpMenu_Items(self.HelpMenu)
   221     
   221     
   222     def _init_coll_LeftGridSizer_Items(self, parent):
   222     def _init_coll_LeftGridSizer_Items(self, parent):
   223         parent.AddWindow(self.PluginTree, 0, border=0, flag=wx.GROW)
   223         parent.AddWindow(self.PluginTree, 0, border=0, flag=wx.GROW)
   224         parent.AddSizer(self.ButtonGridSizer, 0, border=0, flag=wx.GROW)
   224         parent.AddSizer(self.ButtonGridSizer, 0, border=0, flag=wx.GROW)
   485     
   485     
   486     def GetChoiceCallBackFunction(self, choicectrl, path):
   486     def GetChoiceCallBackFunction(self, choicectrl, path):
   487         def OnChoiceChanged(event):
   487         def OnChoiceChanged(event):
   488             plugin = self.GetSelectedPlugin()
   488             plugin = self.GetSelectedPlugin()
   489             if plugin:
   489             if plugin:
   490                 plugin.SetParamsAttribute(path, choicectrl.GetStringSelection())
   490                 res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log)
       
   491                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
       
   492                 choicectrl.SetStringSelection(res)
   491             event.Skip()
   493             event.Skip()
   492         return OnChoiceChanged
   494         return OnChoiceChanged
   493     
   495     
   494     def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path):
   496     def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path):
   495         def OnChoiceContentChanged(event):
   497         def OnChoiceContentChanged(event):
   496             plugin = self.GetSelectedPlugin()
   498             plugin = self.GetSelectedPlugin()
   497             if plugin:
   499             if plugin:
   498                 plugin.SetParamsAttribute(path, choicectrl.GetStringSelection())
   500                 res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log)
       
   501                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
       
   502                 choicectrl.SetStringSelection(res)
   499                 infos = self.PluginRoot.GetParamsAttributes(path)
   503                 infos = self.PluginRoot.GetParamsAttributes(path)
   500                 staticbox = staticboxsizer.GetStaticBox()
   504                 staticbox = staticboxsizer.GetStaticBox()
   501                 staticbox.SetLabel("%(name)s - %(value)s"%infos)
   505                 staticbox.SetLabel("%(name)s - %(value)s"%infos)
   502                 self.ParamsPanel.Freeze()
   506                 self.ParamsPanel.Freeze()
   503                 self.RefreshSizerElement(staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]))
   507                 self.RefreshSizerElement(staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]))
   509     
   513     
   510     def GetTextCtrlCallBackFunction(self, textctrl, path):
   514     def GetTextCtrlCallBackFunction(self, textctrl, path):
   511         def OnTextCtrlChanged(event):
   515         def OnTextCtrlChanged(event):
   512             plugin = self.GetSelectedPlugin()
   516             plugin = self.GetSelectedPlugin()
   513             if plugin:
   517             if plugin:
   514                 plugin.SetParamsAttribute(path, textctrl.GetValue())
   518                 res, StructChanged = plugin.SetParamsAttribute(path, textctrl.GetValue(), self.Log)
       
   519                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
       
   520                 textctrl.SetValue(res)
   515             event.Skip()
   521             event.Skip()
   516         return OnTextCtrlChanged
   522         return OnTextCtrlChanged
   517     
   523     
   518     def GetCheckBoxCallBackFunction(self, textctrl, path):
   524     def GetCheckBoxCallBackFunction(self, chkbx, path):
   519         def OnCheckBoxChanged(event):
   525         def OnCheckBoxChanged(event):
   520             plugin = self.GetSelectedPlugin()
   526             plugin = self.GetSelectedPlugin()
   521             if plugin:
   527             if plugin:
   522                 plugin.SetParamsAttribute(path, textctrl.IsChecked())
   528                 res, StructChanged = plugin.SetParamsAttribute(path, chkbx.IsChecked(), self.Log)
       
   529                 if StructChanged: wx.CallAfter(self.RefreshPluginTree)
       
   530                 chkbx.SetValue(res)
   523             event.Skip()
   531             event.Skip()
   524         return OnCheckBoxChanged
   532         return OnCheckBoxChanged
   525     
   533     
   526     def ClearSizer(self, sizer):
   534     def ClearSizer(self, sizer):
   527         staticboxes = []
   535         staticboxes = []
   574                     callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, element_path)
   582                     callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, element_path)
   575                 else:
   583                 else:
   576                     for choice in element_infos["type"]:
   584                     for choice in element_infos["type"]:
   577                         choicectrl.Append(choice)
   585                         choicectrl.Append(choice)
   578                     callback = self.GetChoiceCallBackFunction(choicectrl, element_path)
   586                     callback = self.GetChoiceCallBackFunction(choicectrl, element_path)
   579                 choicectrl.Bind(wx.EVT_CHOICE, callback, id=id)
       
   580                 if element_infos["value"]:
   587                 if element_infos["value"]:
   581                     choicectrl.SetStringSelection(element_infos["value"])
   588                     choicectrl.SetStringSelection(element_infos["value"])
       
   589                 choicectrl.Bind(wx.EVT_CHOICE, callback, id=id)
   582             elif isinstance(element_infos["type"], types.DictType):
   590             elif isinstance(element_infos["type"], types.DictType):
   583                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   591                 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   584                 if first:
   592                 if first:
   585                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
   593                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
   586                 else:
   594                 else:
   598                     scmax = element_infos["type"]["max"]
   606                     scmax = element_infos["type"]["max"]
   599                 spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
   607                 spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
   600                     pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
   608                     pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
   601                 spinctrl.SetRange(scmin,scmax)
   609                 spinctrl.SetRange(scmin,scmax)
   602                 boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
   610                 boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
       
   611                 spinctrl.SetValue(element_infos["value"])
   603                 spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
   612                 spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
   604                 spinctrl.SetValue(element_infos["value"])
       
   605             elif element_infos["type"] == "element":
   613             elif element_infos["type"] == "element":
   606                 staticbox = wx.StaticBox(id=-1, label=element_infos["name"], 
   614                 staticbox = wx.StaticBox(id=-1, label=element_infos["name"], 
   607                     name='%s_staticbox'%element_infos["name"], parent=self.ParamsPanel,
   615                     name='%s_staticbox'%element_infos["name"], parent=self.ParamsPanel,
   608                     pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
   616                     pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
   609                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   617                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   625                 id = wx.NewId()
   633                 id = wx.NewId()
   626                 if element_infos["type"] == "boolean":
   634                 if element_infos["type"] == "boolean":
   627                     checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
   635                     checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
   628                         pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
   636                         pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
   629                     boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
   637                     boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
       
   638                     checkbox.SetValue(element_infos["value"])
   630                     checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path), id=id)
   639                     checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path), id=id)
   631                     checkbox.SetValue(element_infos["value"])
       
   632                 elif element_infos["type"] in ["unsignedLong", "long","integer"]:
   640                 elif element_infos["type"] in ["unsignedLong", "long","integer"]:
   633                     if element_infos["type"].startswith("unsigned"):
   641                     if element_infos["type"].startswith("unsigned"):
   634                         scmin = 0
   642                         scmin = 0
   635                     else:
   643                     else:
   636                         scmin = -(2**31)
   644                         scmin = -(2**31)
   637                     scmax = 2**31-1
   645                     scmax = 2**31-1
   638                     spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
   646                     spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
   639                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
   647                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
   640                     spinctrl.SetRange(scmin, scmax)
   648                     spinctrl.SetRange(scmin, scmax)
   641                     boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
   649                     boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
       
   650                     spinctrl.SetValue(element_infos["value"])
   642                     spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
   651                     spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
   643                     spinctrl.SetValue(element_infos["value"])
       
   644                 else:
   652                 else:
   645                     textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
   653                     textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
   646                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=0)
   654                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.TE_PROCESS_ENTER)
   647                     boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
   655                     boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
   648                     textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, element_path), id=id)
       
   649                     textctrl.SetValue(str(element_infos["value"]))
   656                     textctrl.SetValue(str(element_infos["value"]))
       
   657                     textctrl.Bind(wx.EVT_TEXT_ENTER, self.GetTextCtrlCallBackFunction(textctrl, element_path), id=id)
       
   658                     textctrl.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(textctrl, element_path))
   650             first = False
   659             first = False
   651     
   660     
   652     def OnNewProjectMenu(self, event):
   661     def OnNewProjectMenu(self, event):
   653         defaultpath = self.PluginRoot.GetProjectPath()
   662         defaultpath = self.PluginRoot.GetProjectPath()
   654         if not defaultpath:
   663         if not defaultpath:
   759     def AddPlugin(self, PluginType):
   768     def AddPlugin(self, PluginType):
   760         dialog = wx.TextEntryDialog(self, "Please enter a name for plugin:", "Add Plugin", "", wx.OK|wx.CANCEL)
   769         dialog = wx.TextEntryDialog(self, "Please enter a name for plugin:", "Add Plugin", "", wx.OK|wx.CANCEL)
   761         if dialog.ShowModal() == wx.ID_OK:
   770         if dialog.ShowModal() == wx.ID_OK:
   762             PluginName = dialog.GetValue()
   771             PluginName = dialog.GetValue()
   763             plugin = self.GetSelectedPlugin()
   772             plugin = self.GetSelectedPlugin()
   764             plugin.PlugAddChild(PluginName, PluginType)
   773             plugin.PlugAddChild(PluginName, PluginType, self.Log)
   765             self.RefreshPluginTree()
   774             self.RefreshPluginTree()
   766         dialog.Destroy()
   775         dialog.Destroy()
   767     
   776     
   768     def DeletePlugin(self):
   777     def DeletePlugin(self):
   769         pass
   778         pass