Hello Luca,
This looks good, Thank you very much. Nice progress.
> otherwise the window get closed immediately.
That has nothing to do with PyROOT/PyQt/QtROOT. I think this the correct (!!!) behavior of your script. I do not know Python. However, from the first glance your "main" does create the object of the class "window" and this object is to be DESTROYED as soon as your code leaves the "main" scope. You should ask someone who knows Python to find the correct way to preserve the Python object beyond the method scope.
> I still don't get that, it looks like the application main loop is not running...
I had made an assumption that event loop is started for us by PyROOT. May be this is not correct. We need the Wim's clarification again. I did not find anything on "Event loop" on his Web page http://wlav.web.cern.ch/wlav/pyroot <http://wlav.web.cern.ch/wlav/pyroot> yet. I need digging his code now. I need to know how and where PyROOT manages the ROOT event loop to avoid the guess job.
May be Wim can look up the C++ code sent last time to tell us where, how, and when the PyROOT implements the
TRint *theApp = new TRint("Rint", &argc, argv);
and
theApp->Run();
May be the only thing you should do is to call
gApplication.Run()
instead of your "raw_input()". However, to avoid the guess job one needs to know precisely where gApplication is coming from and how. I'll investigate this today and let you know hot to proceed further.
My best regards, Valeri
From: Luca Baldini [mailto:luca.baldini_at_pi.infn.it]
Sent: Tue 1/16/2007 3:30 AM
To: Fine, Valeri
Cc: Johan Bregeon; WLavrijsen_at_lbl.gov; Luca Baldini; ROOT Talk
Subject: Re: [ROOT] RE: PyQt and PyROOT
Hi Valeri,
this is the best we could do, so far, following your suggestions.
The script works, except for the fact that it needs the last raw_input()
stuff, otherwise the window get closed
immediately. I still don't get that, it looks like the application main
loop is not running...
Also, we would like to be able to close the application by clicking on
the window, rather than pressing a
key on the prompt.
#!/bin/env python
import sip
from qt import QMainWindow, QWidget, QGridLayout
from ROOT import TH1F, TQtWidget, gSystem, AddressOf
gSystem.Load('qtcint')
class window(QMainWindow):
def __init__(self):
QMainWindow.__init__(self) self.CentralWidget = QWidget(self) self.setCentralWidget(self.CentralWidget) self.Layout = QGridLayout(self.CentralWidget) self.Histogram = TH1F("histogram", "histogram", 100, 0, 100) self.Address = sip.unwrapinstance(self.CentralWidget) self.Canvas = TQtWidget(sip.voidptr(self.Address).ascobject())
self.Layout.addWidget(sip.wrapinstance(AddressOf(self.Canvas)[0], QWidget), 0, 0)
self.Histogram.Draw()
if __name__ == '__main__':
w = window()
w.resize(350, 350)
w.show()
raw_input('Press return to exit...')
Received on Tue Jan 16 2007 - 15:26:55 CET
This archive was generated by hypermail 2.2.0 : Wed Jan 17 2007 - 05:50:00 CET