GUI with pyroot

Hi,
I would like to make a GUI using pyroot.
I started converting in python the example given in the ROOT manual - chapter 25 - but an error occurred at line:
self.DrawButton.Connect(‘clicked()’, ‘gMainWindow’, self, ‘draw()’)

This is my program:

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')

    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()

and the error message is:

Python 2.4.2 (#1, Aug 23 2006, 16:20:28)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

working on region in file /tmp/bstoraci/python-4754ymZ…

Traceback (most recent call last):
File “”, line 1, in ?
File “/tmp/bstoraci/python-4754ymZ”, line 43, in ?
window = gMainWindow(ROOT.gClient.GetRoot(), 200, 200, app)
File “/tmp/bstoraci/python-4754ymZ”, line 26, in init
self.DrawButton.Connect(‘clicked()’, ‘gMainWindow’, self, ‘draw()’)
TypeError: none of the 3 overloaded methods succeeded. Full details:
Bool_t TQObject(const char* signal, const char* receiver_class, void* receiver, const char* slot) =>
could not convert argument 3
static Bool_t TQObject(TQObject* sender, const char* signal, const char* receiver_class, void* receiver, const char* slot) =>
takes at least 5 arguments (4 given)
static Bool_t TQObject(const char* sender_class, const char* signal, const char* receiver_class, void* receiver, const char* slot) =>
takes at least 5 arguments (4 given)

How can I fix this error?

Thanks a lot,
Barbara

Hi Barbara,

Please see the example gui_ex.py in $ROOTSYS/tutorials/pyroot. The way of using signals/slots communication mechanism looks different there.

Cheers, Ilka