RE: ruby with root + qt

From: Fine, Valeri <fine_at_bnl.gov>
Date: Thu, 23 Jul 2009 13:44:55 -0400


Hello Robert,

I have neither Python nor PyQt installed to debug PyROOT related issue.

> I tried to translate the python+qt example from the userguide to ruby.
>> I had to add one modification (line 17, actually in comments) to get
it
> working, but the program doesn't behave as well as the python-version.

>From the first glance the example:

ftp://root.cern.ch/root/doc/19PythonRuby.pdf is for Qt3.

That was fixed by Zoltan Mathe (See his E-mail below)

>> -----Original Message-----
>> From: Zoltan MATHE [mailto:Zoltan.Mathe_at_ucdconnect.ie]
>> Sent: Wednesday, June 10, 2009 7:50 AM
>> To: Fine, Valeri
>> Cc: WLavrijsen_at_lbl.gov; Rene Brun
>> Subject: Re: [Fwd: root and qt problem]

>> Hello, :)
>> I changed the qtexample.py, because it is implemented qt3. I attached

>> the file. But it still dosn't work.

 ....

I've submitted his patch to CERN.

Index: qtexample.py


+from PyQt4.QtGui import *
+from PyQt4.QtCore import *
+
+

 import ROOT
 import sip

-class window(qt.QMainWindow):
+class window(QMainWindow):

    def __init__(self):

        # Init the main window.
-        qt.QMainWindow.__init__(self)
+        QMainWindow.__init__(self)
         self.resize(350, 350)

      # Create the central widget.
-        self.CentralWidget = qt.QWidget(self)
+        self.CentralWidget = QWidget(self)
         self.setCentralWidget(self.CentralWidget)
-        self.Layout = qt.QGridLayout(self.CentralWidget)
+        self.Layout = QGridLayout(self.CentralWidget)

     # Create a button.
-        self.QuitButton    = qt.QPushButton(self.centralWidget())
+        self.QuitButton    = QPushButton(self.centralWidget())
         self.QuitButton.setText('Quit')
         self.Layout.addWidget(self.QuitButton, 1, 0)
     # Connect the button.
-        qt.QObject.connect(self.QuitButton, qt.SIGNAL('clicked()'),
self.quit)
+        QObject.connect(self.QuitButton, SIGNAL('clicked()'),
self.quit)
     # Create a root histogram.
         self.hist = ROOT.TH1F("pipo","pipo", 100, 0, 100)
@@ -31,7 +34,7 @@

     # Place the TQtWidget in the main grid layout and draw the histogram.

-
self.Layout.addWidget(sip.wrapinstance(ROOT.AddressOf(self.Canvas)[0],qt .QWidget), 0, 0)
+
self.Layout.addWidget(sip.wrapinstance(ROOT.AddressOf(self.Canvas)[0],QW idget), 0, 0)

         self.hist.Draw()

    def quit(self):
@@ -40,11 +43,12 @@

 if __name__ == '__main__':
- application = qt.qApp
+ application = qApp

    terminator = ROOT.TQtRootSlot.CintSlot() - termAddress =
sip.wrapinstance(ROOT.AddressOf(terminator)[0],qt.QObject) - qt.QObject.connect(application,
qt.SIGNAL("lastWindowClosed()"),termAddress ,qt.SLOT("Terminate()")) + termAddress =
sip.wrapinstance(ROOT.AddressOf(terminator)[0],QObject) + QObject.connect(application,
SIGNAL("lastWindowClosed()"),termAddress ,SLOT("Terminate()"))

    w = window()
    w.show()
    ROOT.gApplication.Run(1)
    print 'Bye forever!'
+

> Closing the TBrowser and restarting with another
> click on the button doesn't work.
> In some cases windows freeze. Without the
> fork-command the qt-window freezes.

 From the first glance, your application lacks of the "event loop" by some reason.

> Maybe it's a bug. Does anyone have a better idea how to make it with
ruby?

I am not aware about any attempt to use QtRoot with ruby.

Anyway, before going further with the guess job please clarify:

  1. What your ROOT version is
  2. What your Qt version is
  3. Does you activate QtROOT layer via ROOT resource file
      see: "Qt-layer Configuration"
           ftp://root.cern.ch/root/doc/26ROOTandQt.pdf 
           p.424
       ?

    4. Does the patched version of "qtexample.py" works for you?

Thank you, Valeri        

  -

>
> Greets Robert
>
> Versions:
> Root v5.20/00
> Ruby ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
> opensuse 11.1 with kde 4.2.4 and ruby-kde4 4.2.4
>
> Code with highlighting on pastie.org: http://pastie.org/548613
> Code without highlighting here:
>
> #!/usr/bin/env ruby
> $KCODE = 'u' # use utf8 encoding of this file
>
> require 'Qt4'
> require 'libRuby'
>
> class CustomWidget < Qt::PushButton
>
> slots :browse
>
> def initialize( label )
> super( label )
> end
>
> def browse
> tb = TBrowser.new
> # fork do gApplication.Run end
> end
>
> end
>
> a = Qt::Application.new(ARGV) # create an application object
> w = CustomWidget.new( 'Start TBrowser' ) # create an instance of our
self-
> made
> CustomWidget
> Qt::Object.connect( w, SIGNAL( :clicked ), w, SLOT( :browse ) )
> w.show # show our widget
> a.exec # run the application
>

Received on Thu Jul 23 2009 - 19:45:01 CEST

This archive was generated by hypermail 2.2.0 : Thu Jul 30 2009 - 05:50:23 CEST