ROOT Gui with pyRoot

From: Johan Bregeon <johan.bregeon_at_pi.infn.it>
Date: Mon, 15 Jan 2007 18:54:24 +0100


Hello all,
our purpose is to build a ROOT application with a ROOT Gui using pyRoot within ROOT v5.14.00.
here is a simple piece of code, that tries to reproduce the example of Chapter 2 of root documentation :
ftp://root.cern.ch/root/doc/chapter26.pdf

Our main problems are :
1) the application hangs up when closing the gui window clicking on the
'cross' : it looks like the overriding of the "CloseWindow" methode is
not taken into account.
2)Is "app = ROOT.gApplication" the right way of getting the current application instanced by pyRoot ?
3) it's not stable : the 'external X11 window' is displayed quite
'randomly'. You run the code once, it's there. You run it twice, it's
not there anymore.
4) the Connect methode on the button widget gives nice crash, complaining that on of the argument is not of a pointer type (very likely need to use sip here ?)

Thanks for any comments,
Best Regards,
Johan



#!/bin/env python
import sys
import os
import ROOT

class gMainFrame(ROOT.TGMainFrame):

    def __init__(self, parent, width, height):

        ROOT.TGMainFrame.__init__(self, parent, width, height)

    def CloseWindow(self):

        print "closing"
        ROOT.gApplication.Terminate(0)

class gMainWindow():

    def __init__(self, parent, width, height, app):

        self.Application = app
        self.MainFrame = gMainFrame(parent, width, height)
        self.Canvas    = ROOT.TRootEmbeddedCanvas("Canvas",\
                                                  self.MainFrame, 200, 200)
        self.MainFrame.AddFrame(self.Canvas, ROOT.TGLayoutHints())
        self.ButtonsFrame = ROOT.TGHorizontalFrame(self.MainFrame, 200, 40)
        self.DrawButton   = ROOT.TGTextButton(self.ButtonsFrame, '&Draw')

    # Following line give a seg. fault
        #self.DrawButton.Connect('clicked()', 'gMainWindow', self, 'draw()')
        self.ButtonsFrame.AddFrame(self.DrawButton, ROOT.TGLayoutHints())
        self.ExitButton   = ROOT.TGTextButton(self.ButtonsFrame, '&Exit')
        self.ButtonsFrame.AddFrame(self.ExitButton, ROOT.TGLayoutHints())
        self.MainFrame.AddFrame(self.ButtonsFrame, ROOT.TGLayoutHints())
        self.MainFrame.SetWindowName('My first GUI')
        self.MainFrame.MapSubwindows()
        self.MainFrame.Resize(self.MainFrame.GetDefaultSize())
        self.MainFrame.MapWindow()
   
    def __del__(self):
        self.MainFrame.Cleanup()
        self.Application.Terminate(0)

if __name__ == '__main__':

    ROOT.gROOT.Reset()
    app = ROOT.gApplication
    window = gMainWindow(ROOT.gClient.GetRoot(), 200, 200, app)     print "Is gApplication running ? %d" % app.IsRunning()     app.Run()


Received on Mon Jan 15 2007 - 18:54:51 CET

This archive was generated by hypermail 2.2.0 : Wed Jan 17 2007 - 05:50:00 CET