Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot,...

16
Rapid Application Rapid Application Design with the ROOT Design with the ROOT GUI Classes GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN, Geneva, Switzerland * IHEP, Protvino, Russia

Transcript of Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot,...

Page 1: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

Rapid Application Design Rapid Application Design with the ROOT GUI Classeswith the ROOT GUI Classes

24 April 2007

Ilka Antcheva, Bertrand Bellenot, René Brun,

Fons Rademakers, Valeriy Onuchin*

CERN, Geneva, Switzerland* IHEP, Protvino, Russia

Page 2: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 2

OverviewOverview

• Main Features• Benefits from Using CINT• Application Design

• Signals & Slots• Scripting• C++ Code Generation• Dialogs• GUI Builder

• Automatic Context Menus• External Applications• Conclusions

Page 3: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 3

• ROOT GUI classes form a rich and complete set of widgets

• Fully cross platform with the same look and feel on either Unix, Linux, Windows and Mac OS X

• Fully scriptable allowing fast prototyping via the embedded CINT C++ interpreter

• The GUI builder (under development) makes the task of designing complex GUI’s easier and faster

• High level GUI’s in ROOT : the browser, tree viewer, graphics editor, fit panel, session viewer of PROOF, etc.

Main Features Main Features

Page 4: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 4

fText = new TGTextEntry(fMain, new TGTextBuffer(100)); fText->SetToolTipText("Enter the label and hit Enter key"); fText->Connect("ReturnPressed()", "MyDialog", this, "DoSetlabel()"); fMain->AddFrame(fText, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5)); fGframe = new TGGroupFrame(fMain, "Last File"); fLabel = new TGLabel(fGframe, "No Intut "); fGframe->AddFrame(fLabel, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5)); fMain->AddFrame(fGframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 1, 1));

// fText = new TGTextEntry(fMain, new TGTextBuffer(100));// fText->SetToolTipText("Enter the label and hit Enter key");// fText->Connect("ReturnPressed()", "MyDialog", this, "DoSetlabel()");// fMain->AddFrame(fText, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5)); fGframe = new TGGroupFrame(fMain, "Last File"); fLabel = new TGLabel(fGframe, "No Intut "); fGframe->AddFrame(fLabel, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5)); fText = new TGTextEntry(fGframe, new TGTextBuffer(100)); fText->SetToolTipText("Enter the label and hit Enter key"); fText->Connect("ReturnPressed()", "MyDialog", this, "DoSetlabel()"); fText->Resize(150, fText->GetDefaultHeight()); fGframe->AddFrame(fText, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5)); fMain->AddFrame(fGframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 1, 1));

root [0] .x myDialog.Croot [1]root [0] .x myDialog.Croot [1] .x myDialog.C

Prototyping via the CINT C++ interpreter• Supports from simple sequence of

statements to complex C++ class and method definitions

• Remove edit compile cycle• Macros can be edited and re-executed• Transparent interface to native C++

compiler to run macro with native machine performance

Benefits from Using CINTBenefits from Using CINT

Page 5: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 5

Application DesignApplication Design

• Map user requirements and logically organize the GUI• Application window is handled by TGMainFrame• Select widgets from ROOT GUI classes• Layout the GUI components

• Parent-children relationship• Different layout managers

• Program them to perform actions• Signal/slot mechanism• Conventional model of event processing

• Run and validate … or iterate to improve

Page 6: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 6

• Signal/Slot communication mechanism is integrated into ROOT core by TQObject, TQConnection, TQClass

• Uses dictionary information and the CINT interpreter to connect signal methods to slot methods

• Total independence of the interacting classes (easy programming)

Signals & SlotsSignals & Slots

Page 7: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 7

ScriptingScripting

• Macros via the ROOT Object Browser

Page 8: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 8

• TGTextEditor - basic editor for compiling and executing macros

More ScriptingMore Scripting

Drag & Dropmacros from the browser

Page 9: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 9

C++ Code GenerationC++ Code Generation

• Using ctrl+S any GUI can be saved as a C++ macro file thanks to the SavePrimitive methods implemented in all GUI classes.

• The generated macro can be modified and executed

• It restores the complete original GUI and all existing signal/slot connections

// transient frame TGTransientFrame *frame2 = new TGTransientFrame(gClient->GetRoot(),760,590); // group frame TGButtonGroupe *frame3 = new TGGroupFrame(frame2,“Operation");

TGRadioButton *frame4 = new TGRadioButton(frame3,“Nop",10); frame3->AddFrame(frame4);

root [0] .x example.C

Page 10: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 10

DialogsDialogs

Standard set of common dialogs• Files selection (multiple files)TGFileInfo fi;new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen,&fi);if (fi.fMultipleSelection && fi.fFileNamesList) { TObjString *el; TIter next(fi.fFileNamesList); while ((el = (TObjString *) next())) { new TFile(el->GetString(), "update"); }} else if (fi.fFilename) { new TFile(fi.fFilename, "update");}

• Input dialog• Message window• Search dialog• Print dialog

Page 11: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 11

More DialogsMore Dialogs

// Change background color via color selector.

TGFrame *fr; TGColorDialog *cd = GetGlobalColorDialog(); cd->SetCurrentColor(fr->GetBackground()); cd->Connect("ColorSelected(Pixel_t)", "TGFrame", fr, ChangeBackground(Pixel_t)"); fClient->WaitForUnmap(cd); TQObject::Disconnect(cd);

// Change text font via font selection dialog.

TGGroupFrame *gfr; TGFontDialog *fd = GetGlobalFontDialog(); TGResourcePool *rc = gc=fClient->GetResourcePool(); TGGC *gc = rc->GetGCPool()->FindGC(fr->GetNormGC()); TGFont *font = 0; Font = rc->GetFontPool()->FindFont(fr->GetFontStruct()); fd->SetColor(gc->GetForeground()); fd->SetFont(font); fd->Connect("FontSelected(char*)", "TGGroupFrame", gfr, "SetTextFont(char*)"); fd->Connect("ColorSelected(Pixel_t)", "TGGroupFrame", gfr, "SetTextColor(Pixel_t)"); fClient->WaitForUnmap(fd); TQObject::Disconnect(fd);

Page 12: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 12

Complex DialogsComplex Dialogs

Page 13: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 13

GUI BuilderGUI Builder

• Visual design without coding

• Design process• Mainly based on Drag &

Drop• Flexible layout settings• Ends up as C++ source code

reflecting parents-children relationship

• Establish signal/slot connections and their concrete implementation (to be done)

Page 14: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 14

• Context sensitive popup menu

• Automatically generated by ROOT

• Gives direct access to class member functions

• Any context menu can be retrieved

• Can be extended with user- defined entries

Automatic Context MenusAutomatic Context Menus

TClass *cl = Graph->IsA(); TList *mnl = cl->GetMenuList();

Page 15: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 15

TCanvas can be embedded into any 3rd party GUI environment when it is possible to:• Obtain a Window ID (XID on X11, HWND on Windows)• Create a timer to handle ROOT events• Forward events to the ROOT canvas

External ApplicationsExternal Applications

Page 16: Rapid Application Design with the ROOT GUI Classes 24 April 2007 Ilka Antcheva, Bertrand Bellenot, René Brun, Fons Rademakers, Valeriy Onuchin * CERN,

I. Antcheva ACAT07 NIKEF, Amsterdam 16

ConclusionsConclusions• The ROOT GUI classes form a rich

and powerful scriptable cross-platform GUI library

• Solid basis for the development of additional GUIs: help browser, object editors, fit panel, event displays

• The GUI builder makes designing GUIs easier

• Easy application distribution by storing the GUIs with data in the same ROOT file

• The future - to provide users with access through multiple interfaces from any location, with any device at any time.