Beremiz.py
changeset 89 0ab2868c6aa6
parent 88 6d3bd16ab508
child 90 f3205d5acdf4
equal deleted inserted replaced
88:6d3bd16ab508 89:0ab2868c6aa6
   101                 wx.Yield()
   101                 wx.Yield()
   102                 time.sleep(0.01)
   102                 time.sleep(0.01)
   103 
   103 
   104         input = []
   104         input = []
   105         p = wxPopen3(Command, input, output, errors, fin, self.output)
   105         p = wxPopen3(Command, input, output, errors, fin, self.output)
   106         spin(p)
   106         if p.pid:
       
   107         	spin(p)
   107 
   108 
   108         return (self.exitcode, self.outdata, self.errdata)
   109         return (self.exitcode, self.outdata, self.errdata)
   109 
   110 
   110 [ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, 
   111 [ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, 
   111  ID_BEREMIZSECONDSPLITTER, ID_BEREMIZLEFTPANEL, 
   112  ID_BEREMIZSECONDSPLITTER, ID_BEREMIZLEFTPANEL, 
   351             
   352             
   352             self.PluginTree = CT.CustomTreeCtrl(id=ID_BEREMIZPLUGINTREE,
   353             self.PluginTree = CT.CustomTreeCtrl(id=ID_BEREMIZPLUGINTREE,
   353               name='PluginTree', parent=self, pos=wx.Point(0, 0),
   354               name='PluginTree', parent=self, pos=wx.Point(0, 0),
   354               size=wx.Size(-1, -1), style=CT.TR_HAS_BUTTONS|CT.TR_EDIT_LABELS|CT.TR_HAS_VARIABLE_ROW_HEIGHT|CT.TR_NO_LINES|wx.TR_SINGLE|wx.SUNKEN_BORDER)
   355               size=wx.Size(-1, -1), style=CT.TR_HAS_BUTTONS|CT.TR_EDIT_LABELS|CT.TR_HAS_VARIABLE_ROW_HEIGHT|CT.TR_NO_LINES|wx.TR_SINGLE|wx.SUNKEN_BORDER)
   355             self.PluginTree.Bind(wx.EVT_RIGHT_UP, self.OnPluginTreeRightUp)
   356             self.PluginTree.Bind(wx.EVT_RIGHT_UP, self.OnPluginTreeRightUp)
       
   357             self.PluginTree.Bind(wx.EVT_SIZE, self.OnPluginTreeResize)
       
   358             self.PluginTree.Bind(wx.EVT_IDLE, self.OnPluginTreeIdle)
   356             self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnPluginTreeItemSelected,
   359             self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnPluginTreeItemSelected,
   357                   id=ID_BEREMIZPLUGINTREE)
   360                   id=ID_BEREMIZPLUGINTREE)
   358             self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.OnPluginTreeItemChecked,
   361             self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.OnPluginTreeItemChecked,
   359                   id=ID_BEREMIZPLUGINTREE)
   362                   id=ID_BEREMIZPLUGINTREE)
   360             self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnPluginTreeItemBeginEdit,
   363             self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnPluginTreeItemBeginEdit,
   384         self.DisableEvents = False
   387         self.DisableEvents = False
   385         
   388         
   386         if projectOpen:
   389         if projectOpen:
   387             self.PluginRoot.LoadProject(projectOpen, self.Log)
   390             self.PluginRoot.LoadProject(projectOpen, self.Log)
   388             self.RefreshPluginTree()
   391             self.RefreshPluginTree()
       
   392             self.RefreshPluginToolBar()
   389             self.PluginTree.SelectItem(self.PluginTree.GetRootItem())
   393             self.PluginTree.SelectItem(self.PluginTree.GetRootItem())
   390         
   394         
   391         if wx.VERSION < (2, 8, 0):
   395         if wx.VERSION < (2, 8, 0):
   392             self.RefreshPluginParams()
   396             self.RefreshPluginParams()
   393             self.RefreshButtons()
   397             self.RefreshButtons()
   437         
   441         
   438         if wx.VERSION < (2, 8, 0):
   442         if wx.VERSION < (2, 8, 0):
   439             self.RefreshPluginParams()
   443             self.RefreshPluginParams()
   440         
   444         
   441         self.DisableEvents = False
   445         self.DisableEvents = False
       
   446         self.MustRecalTreeSizes = True
   442 
   447 
   443     def SelectedPluginByName(self, root, name):
   448     def SelectedPluginByName(self, root, name):
   444         if name:
   449         if name:
   445             toks = name.split('.', 1)
   450             toks = name.split('.', 1)
   446             item, root_cookie = self.PluginTree.GetFirstChild(root)
   451             item, root_cookie = self.PluginTree.GetFirstChild(root)
   464             if plugin is not None:
   469             if plugin is not None:
   465                 old_window = self.PluginTree.GetItemWindow(root)
   470                 old_window = self.PluginTree.GetItemWindow(root)
   466                 if old_window is not None:
   471                 if old_window is not None:
   467                     old_window.GetSizer().Clear(True)
   472                     old_window.GetSizer().Clear(True)
   468                     old_window.Destroy()
   473                     old_window.Destroy()
   469 
       
   470                 window = wx.Panel(self.PluginTree, -1, size=wx.Size(-1, -1))
       
   471                 window.SetBackgroundColour(wx.WHITE)
       
   472                 tcsizer = wx.BoxSizer(wx.HORIZONTAL)
       
   473                 
   474                 
       
   475                 outside = wx.Panel(self.PluginTree, -1, size=wx.Size(-1, -1))
       
   476                 outside.SetBackgroundColour(wx.WHITE)
       
   477                 
       
   478                 insidesizer = wx.FlexGridSizer(cols=1,rows=1)
       
   479                 insidesizer.AddGrowableCol(0)
       
   480                 
       
   481                 outside.SetSizer(insidesizer)
       
   482                 
       
   483                 window = wx.Panel(outside, -1, size=wx.Size(-1, -1))
       
   484                 window.SetBackgroundColour(wx.Colour(250,250,255))
       
   485                 insidesizer.AddWindow(window, border=1, flag=wx.GROW|wx.ALL)
       
   486                 
       
   487                 tcsizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
       
   488 
   474                 if "channel" in infos:
   489                 if "channel" in infos:
   475                     sc = wx.SpinCtrl(window, -1, size=wx.Size(50, 25))
   490                     sc = wx.SpinCtrl(window, -1, size=wx.Size(50, 25))
   476                     sc.SetValue(infos["channel"])
   491                     sc.SetValue(infos["channel"])
   477                     sc.Bind(wx.EVT_SPINCTRL, self.GetItemChannelChangedFunction(root))
   492                     sc.Bind(wx.EVT_SPINCTRL, self.GetItemChannelChangedFunction(root))
   478                     tcsizer.AddWindow(sc, 0, border=5, flag=wx.LEFT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
   493                     tcsizer.AddWindow(sc, 0, border=5, flag=wx.LEFT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
       
   494 
       
   495                 bsizer = wx.BoxSizer(wx.HORIZONTAL)
   479                 
   496                 
   480                 if "parent" in infos or plugin == self.PluginRoot:
   497                 if "parent" in infos or plugin == self.PluginRoot:
   481                     addbutton_id = wx.NewId()
   498                     addbutton_id = wx.NewId()
   482                     addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Add24x24.png')),
   499                     addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Add24x24.png')),
   483                           name='AddBusButton', parent=window, pos=wx.Point(0, 0),
   500                           name='AddBusButton', parent=window, pos=wx.Point(0, 0),
   484                           size=wx.Size(24, 24), style=wx.NO_BORDER)
   501                           size=wx.Size(24, 24), style=wx.NO_BORDER)
   485                     addbutton.SetToolTipString("Add a plugin to this one")
   502                     addbutton.SetToolTipString("Add a plugin to this one")
   486                     addbutton.Bind(wx.EVT_BUTTON, self.GetAddButtonFunction(root, window), id=addbutton_id)
   503                     addbutton.Bind(wx.EVT_BUTTON, self.GetAddButtonFunction(root, window), id=addbutton_id)
   487                     tcsizer.AddWindow(addbutton, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
   504                     bsizer.AddWindow(addbutton, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
   488                 
   505                 
   489                 if plugin != self.PluginRoot:
   506                 if plugin != self.PluginRoot:
   490                     deletebutton_id = wx.NewId()
   507                     deletebutton_id = wx.NewId()
   491                     deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Delete24x24.png')),
   508                     deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Delete24x24.png')),
   492                           name='DeleteBusButton', parent=window, pos=wx.Point(0, 0),
   509                           name='DeleteBusButton', parent=window, pos=wx.Point(0, 0),
   493                           size=wx.Size(24, 24), style=wx.NO_BORDER)
   510                           size=wx.Size(24, 24), style=wx.NO_BORDER)
   494                     deletebutton.SetToolTipString("Delete this plugin")
   511                     deletebutton.SetToolTipString("Delete this plugin")
   495                     deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(root), id=deletebutton_id)
   512                     deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(root), id=deletebutton_id)
   496                     tcsizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
   513                     bsizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
   497                 
   514                 
       
   515                 plugin_infos = plugin.GetParamsAttributes()
       
   516 
   498                 psizer = wx.BoxSizer(wx.HORIZONTAL)
   517                 psizer = wx.BoxSizer(wx.HORIZONTAL)
   499                 plugin_infos = plugin.GetParamsAttributes()
   518                 self.RefreshSizerElement(window, psizer, plugin_infos, None, True, root)
   500 
   519 
   501                 sizer = wx.BoxSizer(wx.HORIZONTAL)
   520                 msizer = wx.BoxSizer(wx.VERTICAL)
   502                 self.RefreshSizerElement(window, sizer, plugin_infos, None, True, root)
   521                 msizer.AddSizer(bsizer, 0, border=0, flag=wx.GROW)
   503                 if plugin != self.PluginRoot and len(plugin.PluginMethods) > 0:
   522                 if plugin != self.PluginRoot and len(plugin.PluginMethods) > 0:
   504                     for plugin_method in plugin.PluginMethods:
   523                     for plugin_method in plugin.PluginMethods:
   505                         if "method" in plugin_method:
   524                         if "method" in plugin_method:
   506                             id = wx.NewId()
   525                             id = wx.NewId()
   507                             if "bitmap" in plugin_method:
   526                             button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=window, 
   508                                 button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=window, 
   527                                 bitmap=wx.Bitmap(os.path.join(CWD, "%s24x24.png"%plugin_method.get("bitmap", os.path.join("images", "RunMethod")))), label=plugin_method["name"], 
   509                                     bitmap=wx.Bitmap(os.path.join(CWD, "%s24x24.png"%plugin_method["bitmap"])), label=plugin_method["name"], 
   528                                 name=plugin_method["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER)
   510                                     name=plugin_method["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER)
       
   511                             else:
       
   512                                 button = wx.Button(id=id, label=plugin_method["name"], 
       
   513                                     name=plugin_method["name"], parent=window, 
       
   514                                     pos=wx.Point(0, 0), style=wx.BU_EXACTFIT)
       
   515                             button.SetToolTipString(plugin_method["tooltip"])
   529                             button.SetToolTipString(plugin_method["tooltip"])
   516                             button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id)
   530                             button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id)
   517                             sizer.AddWindow(button, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
   531                             msizer.AddWindow(button, 0, border=5, flag=wx.RIGHT)
   518                 tcsizer.AddSizer(sizer, 0, border=0, flag=wx.GROW)
   532                 tcsizer.AddSizer(msizer, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
   533                 tcsizer.AddSizer(psizer, 0, border=0, flag=wx.GROW)
       
   534                 if plugin == self.PluginRoot:
       
   535                     tcsizer.AddGrowableCol(0)
       
   536                 else:
       
   537                     tcsizer.AddGrowableCol(1)
       
   538                 
   519             window.SetSizer(tcsizer)
   539             window.SetSizer(tcsizer)
   520             tcsizer.Fit(window)
   540             insidesizer.Fit(outside)
   521             self.PluginTree.SetItemWindow(root, window)
   541             self.PluginTree.SetItemWindow(root, outside)
   522             if "enabled" in infos:
   542             if "enabled" in infos:
   523                 self.PluginTree.CheckItem(root, infos["enabled"])
   543                 self.PluginTree.CheckItem(root, infos["enabled"])
   524                 self.PluginTree.SetItemWindowEnabled(root, infos["enabled"])
   544                 self.PluginTree.SetItemWindowEnabled(root, infos["enabled"])
   525 
   545 
   526         item, root_cookie = self.PluginTree.GetFirstChild(root)
   546         item, root_cookie = self.PluginTree.GetFirstChild(root)
   527         for values in infos["values"]:
   547         for values in infos["values"]:
   528             if item is None or not item.IsOk():
   548             if item is None or not item.IsOk():
   529                 if wx.VERSION >= (2, 8, 0):
   549                 item = self.PluginTree.AppendItem(root, "")
   530                     item = self.PluginTree.AppendItem(root, "", ct_type=1)
   550                 # 2.6.x returns bad item on gtk
   531                 else:
       
   532                     item = self.PluginTree.AppendItem(root, "")
       
   533                 
       
   534                 if wx.Platform != '__WXMSW__' or wx.VERSION >= (2, 8, 0):
   551                 if wx.Platform != '__WXMSW__' or wx.VERSION >= (2, 8, 0):
   535                     item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   552                     item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   536             self.GenerateTreeBranch(item, values)
   553             self.GenerateTreeBranch(item, values)
   537             item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   554             item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   538         while item is not None and item.IsOk():
   555         while item is not None and item.IsOk():
   539             to_delete.append(item)
   556             to_delete.append(item)
   540             item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   557             item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   541         for item in to_delete:
   558         for item in to_delete:
   542             self.PluginTree.Delete(item)
   559             self.PluginTree.Delete(item)
       
   560 
       
   561     MustRecalTreeSizes = False
       
   562     def OnPluginTreeResize(self,event):
       
   563         self.ResizePluginTreeWindow()
       
   564         event.Skip()
       
   565 
       
   566     def OnPluginTreeIdle(self,event):
       
   567         if self.MustRecalTreeSizes:
       
   568             event.RequestMore()
       
   569             self.ResizePluginTreeWindow()
       
   570         event.Skip()
       
   571 
       
   572     def ResizePluginTreeWindow(self):
       
   573         if getattr(self, "PluginRoot", None):
       
   574             root = self.PluginTree.GetRootItem()
       
   575             if root is not None and root.IsOk():
       
   576                 self.ResizePluginTreeWindow_r(root)
       
   577             self.MustRecalTreeSizes = False
       
   578 
       
   579     def ResizePluginTreeWindow_r(self, root):
       
   580         window = self.PluginTree.GetItemWindow(root)
       
   581         pos = window.GetPosition()
       
   582         sz = self.PluginTree.GetClientSize()
       
   583         window.SetSize(wx.Size(sz.width - pos.x, -1))
       
   584         item, root_cookie = self.PluginTree.GetFirstChild(root)
       
   585         while item is not None and item.IsOk():
       
   586             self.ResizePluginTreeWindow_r(item)
       
   587             item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
       
   588         
       
   589 
   543 
   590 
   544     def GetSelectedPluginName(self, selected = None):
   591     def GetSelectedPluginName(self, selected = None):
   545         if selected is None:
   592         if selected is None:
   546             selected = self.PluginTree.GetSelection()
   593             selected = self.PluginTree.GetSelection()
   547         if selected is None or not selected.IsOk():
   594         if selected is None or not selected.IsOk():
   607                 self.ShowChildrenWindows(item, show)
   654                 self.ShowChildrenWindows(item, show)
   608             item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   655             item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
   609 
   656 
   610     def OnPluginTreeItemExpanded(self, event):
   657     def OnPluginTreeItemExpanded(self, event):
   611         self.ShowChildrenWindows(event.GetItem(), True)
   658         self.ShowChildrenWindows(event.GetItem(), True)
       
   659         self.MustRecalTreeSizes = True
   612         event.Skip()
   660         event.Skip()
   613 
   661 
   614     def OnPluginTreeItemCollapsed(self, event):
   662     def OnPluginTreeItemCollapsed(self, event):
   615         self.ShowChildrenWindows(event.GetItem(), False)
   663         self.ShowChildrenWindows(event.GetItem(), False)
   616         event.Skip()
   664         event.Skip()