Title: Rapid Application Design with the ROOT GUI Classes
1Rapid Application Design with the ROOT GUI Classes
Ilka Antcheva, Bertrand Bellenot, René Brun, Fons
Rademakers, Valeriy Onuchin
CERN, Geneva, Switzerland IHEP, Protvino, Russia
24 April 2007
2Overview
- Main Features
- Benefits from Using CINT
- Application Design
- Signals Slots
- Scripting
- C Code Generation
- Dialogs
- GUI Builder
- Automatic Context Menus
- External Applications
- Conclusions
3Main Features
- 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 GUIs easier and faster - High level GUIs in ROOT the browser, tree
viewer, graphics editor, fit panel, session
viewer of PROOF, etc.
4Benefits from Using CINT
- 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 -
root 0 .x myDialog.C root 1
root 0 .x myDialog.C root 1 .x myDialog.C
fText new TGTextEntry(fMain, new
TGTextBuffer(100)) fText-gtSetToolTipText("En
ter the label and hit Enter key")
fText-gtConnect("ReturnPressed()", "MyDialog",
this, "DoSetlabel()") fMain-gtAddFrame(fText,
new TGLayoutHints(kLHintsTop kLHintsLeft, 5,
5, 5, 5)) fGframe new TGGroupFrame(fMain,
"Last File") fLabel new TGLabel(fGframe,
"No Intut ") fGframe-gtAddFrame(fLabel, new
TGLayoutHints(kLHintsTop kLHintsLeft, 5, 5, 5,
5)) fMain-gtAddFrame(fGframe, new
TGLayoutHints(kLHintsExpandX, 2, 2, 1, 1))
// fText new TGTextEntry(fMain, new
TGTextBuffer(100)) // fText-gtSetToolTipText("En
ter the label and hit Enter key") //
fText-gtConnect("ReturnPressed()", "MyDialog",
this, "DoSetlabel()") // fMain-gtAddFrame(fText,
new TGLayoutHints(kLHintsTop kLHintsLeft, 5,
5, 5, 5)) fGframe new TGGroupFrame(fMain,
"Last File") fLabel new TGLabel(fGframe,
"No Intut ") fGframe-gtAddFrame(fLabel, new
TGLayoutHints(kLHintsTop kLHintsLeft, 5, 5, 5,
5)) fText new TGTextEntry(fGframe, new
TGTextBuffer(100)) fText-gtSetToolTipText("En
ter the label and hit Enter key")
fText-gtConnect("ReturnPressed()", "MyDialog",
this, "DoSetlabel()") fText-gtResize(150,
fText-gtGetDefaultHeight())
fGframe-gtAddFrame(fText, new TGLayoutHints(kLHints
Top kLHintsLeft, 5, 5, 5, 5))
fMain-gtAddFrame(fGframe, new TGLayoutHints(kLHints
ExpandX, 2, 2, 1, 1))
5Application 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
6Signals Slots
- 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)
7Scripting
- Macros via the ROOT Object Browser
8More Scripting
- TGTextEditor - basic editor for compiling and
executing macros
Drag Drop macros from the browser
9C Code Generation
- Using ctrlS 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
root 0 .x example.C
10Dialogs
- Standard set of common dialogs
- Files selection (multiple files)
- Input dialog
- Message window
- Search dialog
- Print dialog
TGFileInfo fi new TGFileDialog(fClient-gtGetDefaul
tRoot(), this, kFDOpen,fi) if
(fi.fMultipleSelection fi.fFileNamesList)
TObjString el TIter next(fi.fFileNamesList)
while ((el (TObjString ) next()))
new TFile(el-gtGetString(), "update") else
if (fi.fFilename) new TFile(fi.fFilename,
"update")
11More Dialogs
// Change background color via color
selector. TGFrame fr TGColorDialog cd
GetGlobalColorDialog() cd-gtSetCurrentColor(fr-gt
GetBackground()) cd-gtConnect("ColorSelected(Pix
el_t)", "TGFrame", fr,
ChangeBackground(Pixel_t)") fClient-gtWaitForUnm
ap(cd) TQObjectDisconnect(cd)
// Change text font via font selection
dialog. TGGroupFrame gfr TGFontDialog fd
GetGlobalFontDialog() TGResourcePool rc
gcfClient-gtGetResourcePool() TGGC gc
rc-gtGetGCPool()-gtFindGC(fr-gtGetNormGC())
TGFont font 0 Font rc-gtGetFontPool()-gtFind
Font(fr-gtGetFontStruct()) fd-gtSetColor(gc-gtGetF
oreground()) fd-gtSetFont(font)
fd-gtConnect("FontSelected(char)",
"TGGroupFrame", gfr, "SetTextFont(char)")
fd-gtConnect("ColorSelected(Pixel_t)",
"TGGroupFrame", gfr, "SetTextColor(Pixel_t)")
fClient-gtWaitForUnmap(fd) TQObjectDisconnec
t(fd)
12Complex Dialogs
13GUI 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)
14Automatic Context Menus
- 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
TClass cl Graph-gtIsA() TList mnl
cl-gtGetMenuList()
15External Applications
- 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
ROOT
16Conclusions
- 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.