Added right aligment of parameteres blocks
authoretisserant
Mon, 28 Jan 2008 20:06:22 +0100
changeset 89 0ab2868c6aa6
parent 88 6d3bd16ab508
child 90 f3205d5acdf4
Added right aligment of parameteres blocks
Fixed crash on wxPopen of non existing exe.
.pydevproject
Beremiz.py
wxPopen.py
--- a/.pydevproject	Mon Jan 28 10:22:31 2008 +0100
+++ b/.pydevproject	Mon Jan 28 20:06:22 2008 +0100
@@ -2,5 +2,5 @@
 <?eclipse-pydev version="1.0"?>
 
 <pydev_project>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.4</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5</pydev_property>
 </pydev_project>
--- a/Beremiz.py	Mon Jan 28 10:22:31 2008 +0100
+++ b/Beremiz.py	Mon Jan 28 20:06:22 2008 +0100
@@ -103,7 +103,8 @@
 
         input = []
         p = wxPopen3(Command, input, output, errors, fin, self.output)
-        spin(p)
+        if p.pid:
+        	spin(p)
 
         return (self.exitcode, self.outdata, self.errdata)
 
@@ -353,6 +354,8 @@
               name='PluginTree', parent=self, pos=wx.Point(0, 0),
               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)
             self.PluginTree.Bind(wx.EVT_RIGHT_UP, self.OnPluginTreeRightUp)
+            self.PluginTree.Bind(wx.EVT_SIZE, self.OnPluginTreeResize)
+            self.PluginTree.Bind(wx.EVT_IDLE, self.OnPluginTreeIdle)
             self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnPluginTreeItemSelected,
                   id=ID_BEREMIZPLUGINTREE)
             self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.OnPluginTreeItemChecked,
@@ -386,6 +389,7 @@
         if projectOpen:
             self.PluginRoot.LoadProject(projectOpen, self.Log)
             self.RefreshPluginTree()
+            self.RefreshPluginToolBar()
             self.PluginTree.SelectItem(self.PluginTree.GetRootItem())
         
         if wx.VERSION < (2, 8, 0):
@@ -439,6 +443,7 @@
             self.RefreshPluginParams()
         
         self.DisableEvents = False
+        self.MustRecalTreeSizes = True
 
     def SelectedPluginByName(self, root, name):
         if name:
@@ -466,16 +471,28 @@
                 if old_window is not None:
                     old_window.GetSizer().Clear(True)
                     old_window.Destroy()
-
-                window = wx.Panel(self.PluginTree, -1, size=wx.Size(-1, -1))
-                window.SetBackgroundColour(wx.WHITE)
-                tcsizer = wx.BoxSizer(wx.HORIZONTAL)
                 
+                outside = wx.Panel(self.PluginTree, -1, size=wx.Size(-1, -1))
+                outside.SetBackgroundColour(wx.WHITE)
+                
+                insidesizer = wx.FlexGridSizer(cols=1,rows=1)
+                insidesizer.AddGrowableCol(0)
+                
+                outside.SetSizer(insidesizer)
+                
+                window = wx.Panel(outside, -1, size=wx.Size(-1, -1))
+                window.SetBackgroundColour(wx.Colour(250,250,255))
+                insidesizer.AddWindow(window, border=1, flag=wx.GROW|wx.ALL)
+                
+                tcsizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
+
                 if "channel" in infos:
                     sc = wx.SpinCtrl(window, -1, size=wx.Size(50, 25))
                     sc.SetValue(infos["channel"])
                     sc.Bind(wx.EVT_SPINCTRL, self.GetItemChannelChangedFunction(root))
                     tcsizer.AddWindow(sc, 0, border=5, flag=wx.LEFT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
+
+                bsizer = wx.BoxSizer(wx.HORIZONTAL)
                 
                 if "parent" in infos or plugin == self.PluginRoot:
                     addbutton_id = wx.NewId()
@@ -484,7 +501,7 @@
                           size=wx.Size(24, 24), style=wx.NO_BORDER)
                     addbutton.SetToolTipString("Add a plugin to this one")
                     addbutton.Bind(wx.EVT_BUTTON, self.GetAddButtonFunction(root, window), id=addbutton_id)
-                    tcsizer.AddWindow(addbutton, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
+                    bsizer.AddWindow(addbutton, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
                 
                 if plugin != self.PluginRoot:
                     deletebutton_id = wx.NewId()
@@ -493,32 +510,35 @@
                           size=wx.Size(24, 24), style=wx.NO_BORDER)
                     deletebutton.SetToolTipString("Delete this plugin")
                     deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(root), id=deletebutton_id)
-                    tcsizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
+                    bsizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER)
                 
+                plugin_infos = plugin.GetParamsAttributes()
+
                 psizer = wx.BoxSizer(wx.HORIZONTAL)
-                plugin_infos = plugin.GetParamsAttributes()
-
-                sizer = wx.BoxSizer(wx.HORIZONTAL)
-                self.RefreshSizerElement(window, sizer, plugin_infos, None, True, root)
+                self.RefreshSizerElement(window, psizer, plugin_infos, None, True, root)
+
+                msizer = wx.BoxSizer(wx.VERTICAL)
+                msizer.AddSizer(bsizer, 0, border=0, flag=wx.GROW)
                 if plugin != self.PluginRoot and len(plugin.PluginMethods) > 0:
                     for plugin_method in plugin.PluginMethods:
                         if "method" in plugin_method:
                             id = wx.NewId()
-                            if "bitmap" in plugin_method:
-                                button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=window, 
-                                    bitmap=wx.Bitmap(os.path.join(CWD, "%s24x24.png"%plugin_method["bitmap"])), label=plugin_method["name"], 
-                                    name=plugin_method["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER)
-                            else:
-                                button = wx.Button(id=id, label=plugin_method["name"], 
-                                    name=plugin_method["name"], parent=window, 
-                                    pos=wx.Point(0, 0), style=wx.BU_EXACTFIT)
+                            button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=window, 
+                                bitmap=wx.Bitmap(os.path.join(CWD, "%s24x24.png"%plugin_method.get("bitmap", os.path.join("images", "RunMethod")))), label=plugin_method["name"], 
+                                name=plugin_method["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER)
                             button.SetToolTipString(plugin_method["tooltip"])
                             button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id)
-                            sizer.AddWindow(button, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
-                tcsizer.AddSizer(sizer, 0, border=0, flag=wx.GROW)
+                            msizer.AddWindow(button, 0, border=5, flag=wx.RIGHT)
+                tcsizer.AddSizer(msizer, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
+                tcsizer.AddSizer(psizer, 0, border=0, flag=wx.GROW)
+                if plugin == self.PluginRoot:
+                    tcsizer.AddGrowableCol(0)
+                else:
+                    tcsizer.AddGrowableCol(1)
+                
             window.SetSizer(tcsizer)
-            tcsizer.Fit(window)
-            self.PluginTree.SetItemWindow(root, window)
+            insidesizer.Fit(outside)
+            self.PluginTree.SetItemWindow(root, outside)
             if "enabled" in infos:
                 self.PluginTree.CheckItem(root, infos["enabled"])
                 self.PluginTree.SetItemWindowEnabled(root, infos["enabled"])
@@ -526,11 +546,8 @@
         item, root_cookie = self.PluginTree.GetFirstChild(root)
         for values in infos["values"]:
             if item is None or not item.IsOk():
-                if wx.VERSION >= (2, 8, 0):
-                    item = self.PluginTree.AppendItem(root, "", ct_type=1)
-                else:
-                    item = self.PluginTree.AppendItem(root, "")
-                
+                item = self.PluginTree.AppendItem(root, "")
+                # 2.6.x returns bad item on gtk
                 if wx.Platform != '__WXMSW__' or wx.VERSION >= (2, 8, 0):
                     item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
             self.GenerateTreeBranch(item, values)
@@ -541,6 +558,36 @@
         for item in to_delete:
             self.PluginTree.Delete(item)
 
+    MustRecalTreeSizes = False
+    def OnPluginTreeResize(self,event):
+        self.ResizePluginTreeWindow()
+        event.Skip()
+
+    def OnPluginTreeIdle(self,event):
+        if self.MustRecalTreeSizes:
+            event.RequestMore()
+            self.ResizePluginTreeWindow()
+        event.Skip()
+
+    def ResizePluginTreeWindow(self):
+        if getattr(self, "PluginRoot", None):
+            root = self.PluginTree.GetRootItem()
+            if root is not None and root.IsOk():
+                self.ResizePluginTreeWindow_r(root)
+            self.MustRecalTreeSizes = False
+
+    def ResizePluginTreeWindow_r(self, root):
+        window = self.PluginTree.GetItemWindow(root)
+        pos = window.GetPosition()
+        sz = self.PluginTree.GetClientSize()
+        window.SetSize(wx.Size(sz.width - pos.x, -1))
+        item, root_cookie = self.PluginTree.GetFirstChild(root)
+        while item is not None and item.IsOk():
+            self.ResizePluginTreeWindow_r(item)
+            item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
+        
+
+
     def GetSelectedPluginName(self, selected = None):
         if selected is None:
             selected = self.PluginTree.GetSelection()
@@ -609,6 +656,7 @@
 
     def OnPluginTreeItemExpanded(self, event):
         self.ShowChildrenWindows(event.GetItem(), True)
+        self.MustRecalTreeSizes = True
         event.Skip()
 
     def OnPluginTreeItemCollapsed(self, event):
--- a/wxPopen.py	Mon Jan 28 10:22:31 2008 +0100
+++ b/wxPopen.py	Mon Jan 28 20:06:22 2008 +0100
@@ -43,10 +43,10 @@
     def __init__(self, input, handler=None):
         if handler is None:
             handler = self
-        self.handler = handler    
-        handler.Bind(wx.EVT_MENU, self.OnIdle)
-        handler.Bind(wx.EVT_END_PROCESS, self.OnProcessEnded, id=-1)
-        
+        self.handler = handler
+        handler.Bind(wx.EVT_IDLE, self.OnIdle)
+        handler.Bind(wx.EVT_END_PROCESS, self.OnProcessEnded)
+
         input.reverse() # so we can pop
         self.input = input
         
@@ -93,8 +93,8 @@
     def kill(self):
         if self.process is not None:
             self.process.CloseOutput()
-            if wx.Process_Kill(self.pid, wx.SIGTERM) != wx.KILL_OK:
-                wx.Process_Kill(self.pid, wx.SIGKILL)
+            if wx.Process.Kill(self.pid, wx.SIGTERM) != wx.KILL_OK:
+                wx.Process.Kill(self.pid, wx.SIGKILL)
             self.process = None
 
     def updateStream(self, stream, data):
@@ -156,5 +156,34 @@
     p.setCallbacks(output, errors, finish)
     p.execute(cmd)
     return p
-    
-    
\ No newline at end of file
+
+def _test():
+    app = wx.PySimpleApp()
+    f = wx.Frame(None, -1, 'asd')#, style=0)
+    f.Show()
+
+    def output(v):
+        print 'OUTPUT:', v
+    def errors(v):
+        print 'ERRORS:', v
+    def fin():
+        p.Close()
+        f.Close()
+        print 'FINISHED'
+
+
+    def spin(p):
+        while not p.finished:
+            wx.Yield()
+            time.sleep(0.01)
+
+    def evt(self, event):
+        input = []
+        p = wxPopen3('''c:\\python23\\python.exe -c "print '*'*5000"''',
+                 input, output, errors, fin, f)
+        print p.pid
+
+    app.MainLoop()
+
+if __name__ == '__main__':
+    _test()