User input

Hi,

I have created a simple gui with a dialogue box. I want to be able to enter the name of a histogram into the dialogue box, press Draw and get ROOT to display it. What is the simplest way of doing this? I have attached my code.

Lisa
MyDialog.C (3.1 KB)

Hi Lisa,

You need to create an embedded canvas (fEcanvas) for the drawing in the constructor MyDialog::MyDialog (see the example in the User’s Guide) and the following lines in the DoDraw() method:

   TCanvas *fCanvas = fEcanvas->GetCanvas();
   fCanvas->cd();
   fPlotter->Draw();
   fCanvas->Update();

Best regards, Ilka
p.s. you did not provide the header file of your example.

Hi Ilka,

I have followed your suggestion but when I click on the button that should display my dialog box I getth e following errors:

Generating stack trace…
/usr/bin/addr2line: useMainFrame: No such file or directory
/usr/bin/addr2line: useMainFrame: No such file or directory
/usr/bin/addr2line: useMainFrame: No such file or directory
0x42b785c8 in from /lib/libc.so.6
0x42744102 in TGFrame::TGFrame[not-in-charge](TGWindow const*, unsigned, unsign
ed, unsigned, unsigned long) + 0x76 from /opt/products/root/4.00.08/lib/libGui.s
o.4.00
0x42718e96 in TGCanvas::TGCanvas[not-in-charge](TGWindow const*, unsigned, unsi
gned, unsigned, unsigned long) + 0x48 from /opt/products/root/4.00.08/lib/libGui
.so.4.00
0x427c61a2 in TRootEmbeddedCanvas::TRootEmbeddedCanvas[in-charge](char const*,
TGWindow const*, unsigned, unsigned, unsigned, unsigned long) + 0x42 from /opt/p
roducts/root/4.00.08/lib/libGui.so.4.00
0x4001fd10 in MyDialog::MyDialog[in-charge](TGWindow const*, TGWindow const*, u
nsigned, unsigned, unsigned) at /opt/products/root/4.00.08/include/TObject.h:154
from …/lib/i586_linux24/libtest.so
0x0804cc23 in MainFrame::DoDialog() + 0x73 from useMainFrame
0x40022cac in from …/lib/i586_linux24/libtest.so
0x41a0e8f0 in G__CallFunc::Exec(void*) + 0x7c from /opt/products/root/4.00.08/l
ib/libCint.so.4.00
0x41359b15 in TQConnection::ExecuteMethod() + 0x6b from /opt/products/root/4.00
.08/lib/libCore.so.4.00
0x4135c99a in TQObject::Emit(char const*) + 0x2b8 from /opt/products/root/4.00.
08/lib/libCore.so.4.00
0x42710c46 in TGButton::Clicked() + 0x2c from /opt/products/root/4.00.08/lib/li
bGui.so.4.00
0x4270b01f in TGButton::EmitSignals(bool) + 0x6f from /opt/products/root/4.00.0
8/lib/libGui.so.4.00
0x4270afa3 in TGButton::HandleButton(Event_t*) + 0x189 from /opt/products/root/
4.00.08/lib/libGui.so.4.00
0x4274530d in TGFrame::HandleEvent(Event_t*) + 0x21b from /opt/products/root/4.
00.08/lib/libGui.so.4.00
0x4271caf7 in TGClient::HandleEvent(Event_t*) + 0xd7 from /opt/products/root/4.
00.08/lib/libGui.so.4.00
0x4271c7ec in TGClient::ProcessOneEvent() + 0x6e from /opt/products/root/4.00.0
8/lib/libGui.so.4.00
0x4271c876 in TGClient::HandleInput() + 0x28 from /opt/products/root/4.00.08/li
b/libGui.so.4.00
0x4271b26a in TGInputHandler::Notify() + 0x22 from /opt/products/root/4.00.08/l
ib/libGui.so.4.00
0x414378bc in TUnixSystem::DispatchOneEvent(bool) + 0x52 from /opt/products/roo
t/4.00.08/lib/libCore.so.4.00
0x413791e8 in TSystem::InnerLoop() + 0x22 from /opt/products/root/4.00.08/lib/l
ibCore.so.4.00
0x4137917e in TSystem::Run() + 0x80 from /opt/products/root/4.00.08/lib/libCore
.so.4.00
0x41317249 in TApplication::Run(bool) + 0x37 from /opt/products/root/4.00.08/li
b/libCore.so.4.00
0x4221360a in TRint::Run(bool) + 0x380 from /opt/products/root/4.00.08/lib/libR
int.so.4.00
0x0804cd69 in main + 0xc9 from useMainFrame
0x42b648ae in __libc_start_main + 0xce from /lib/libc.so.6
0x0804b8d1 in TApplicationImp::ShowMembers(TMemberInspector&, char*) + 0x3d fro
m useMainFrame
Root >

Lisa

p.s I have now included my header file.
MyDialog.h (1.2 KB)

Hi Lisa,

According to the provided header file you need to create the embedded canvas in your main application (should be MainFrame ), not in MyDialog constructor. It is not clear from the code you have sent how have you created this main application and how haveyou passed its pointer to the MyDialog. Please try to simpify your case and to send entire code of a running example that shows the problem.

Running .x MyDialog.C
I got the message:
Error: cannot open file “H1Analysis/H1Analysis.h” FILE:MyDialog.h LINE:18
*** Interpreter error recovered ***

and I see other missing header files too. It will be goot if you send as an attachement the error messages if they are many.

Thank you, Ilka

Hi Ilka,

Sorry about that. I have attached all of my code.

I do not get the error that you get, I run my gui by compiling the code and then running an executable, useMainFrame.

Thanks,

Lisa
useMainFrame.C (623 Bytes)
MainFrame.C (2.02 KB)
MainFrame.h (936 Bytes)

Hi Lisa,

No way to run it - missing file “H1Analysis/H1InteractivePlotter.h” FILE:MainFrame.h LINE:6

Cheers, Ilka

Hi Ilka,

My fault, that line should have been deleted. Sorry.

Lisa

Hi Lisa,

I do not think so, because in MainFrame.h you have:

class MainFrame : public H1InteractivePlotter

Please check your code once more.

Cheers, Ilka

Sorry, I have deleted the

public : H1InteractivePlotter

too. You probably still won’t be able to run it as the AddHistArray function has pointers to the H1 direrctories that I want to retrieve the histogram arrays from.

I have found this function:

void MyDialog:: SetNameHandler()
{
TGTextEntry entry = (TGTextEntry)gTQSender;

TString text = entry->GetText();

TCanvas *fCanvas = fEcanvas->GetCanvas();
fCanvas->cd();
fPlotter->Draw();
fCanvas->Update();
gSystem->ProcessEvents();

}

Can I use this in the MyDialog class to link my AddHistArray function to the Ok button, so that when I enter the name of the histogram array into the text entry in my dialogue box and click Ok, it retrieves the histogram and displays it for me?

Apologies,

Lisa

Hi Lisa,

Yes, this should work. You need to connect MyDialog:: SetNameHandler with ReturmPressed() signal of TGTextEntry.

Cheers, Ilka

Hi Ilka,

I have used the void SetNameHandler function in the MyDialog class, with:

header file:

void SetNameHandler();

MyDialog.C file:

fOk->Connect(“Released()”, “TGTextEntry”, fText, “ReturnPressed()”);

fText->Connect(“ReturnPressed()”, 0, 0, “SetNameHandler()”);

in the constructor, and the function:

void MyDialog:: SetNameHandler()
{
fText = (TGTextEntry*)gTQSender;

TString text = fText->GetText();

TCanvas *fCanvas = fEcanvas->GetCanvas();
fCanvas->cd();
fPlotter->Draw();
fCanvas->Update();
gSystem->ProcessEvents();

}

I get the error:

root [0] Error in TQObject::CheckConnectArgs: slot SetNameHandler() does not exist.

I have tried to fix this but do not seem to be getting anywhere. What have I missed out?

Thanks,

Lisa

I have managed to figure out what my problem was,

fText->Connect(“ReturnPressed()”, 0, 0,“SetNameHandler()”);

Should be:

fText->Connect(“ReturnPressed()”,“MyDialog”, this, “SetNameHandler()”);

Sorry about that, Ilka.

Lisa

Hi Lisa,

The signal ReturnPressed is emittetd any time the Enter key is pressed and you do not need to connect it; only to get the text when it hapens., i.e.
fText->Connect(“ReturnPressed()”, ,“MyDialog”, this, “SetNameHandler()”);

When writing this answer, I 've got your message, so I could only say please re-read the provided info about signals/slots mechanizm at:
root.cern.ch/root/HowtoSignalSlot.html
root.cern.ch/root/html/examples/exec3.C.html
ftp://root.cern.ch/root/doc/chapter23.pdf
and spend some time to examine the provided examples.

Cheers, Ilka

Hi Lisa,

A part of my message disappeared - the text:

should be read:

Cheers, Ilka

Hi Ilka,

I’m a little confused, do I not need the line

fText->Connect(“ReturnPressed()”, ,“MyDialog”, this, “SetNameHandler()”);

at all?

Lisa

Hi Lisa,

You need it and I am glad that you found the problem yourself. My previous comments were about the following connection:

Best regards, Ilka

Hi Ilka,

I’m sorry to bug you again. I got rid of the line:

fOk->Connect(“Released()”, “TGTextEntry”, fText, “ReturnPressed()”);

I get the attached errors when I type the name of the histogram array and hit the enter key. What is worrying me the most is that it doesn’t recognise my executable, useMainFrame.

Any ideas why?

Lisa
Errors.C (1.17 KB)

Hi Lisa,

There are two points:

  • how are you going to use the entered text in the SetNameHandler()
    TString text = fText->GetText(); ?
  • if you want to draw something when a button is clicked, the lines:
    TCanvas *fCanvas = fEcanvas->GetCanvas();
    fCanvas->cd();
    fPlotter->Draw();
    fCanvas->Update();
    gSystem->ProcessEvents();
    should take place in the slot Slot_for_drawing, connected to the button fOk->Connect(“Released()”, “Class_name_of_the_slot”, class_pointer, “Slot_for_drawing()”);

Best regards, Ilka