1 # Copyright (C) 2009-2013 EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from string import Template
23 from compat import Template,set
26 #include "${component_name}GUI.h"
28 #include <SUIT_MessageBox.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_Session.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_Preferences.h>
35 #include <SALOME_LifeCycleCORBA.hxx>
37 #define COMPONENT_NAME "${component_name}"
42 ${component_name}GUI::${component_name}GUI() :
43 SalomeApp_Module( COMPONENT_NAME ) // Module name
50 default_selection = QString("");
52 // List for the selector
53 selector_strings.clear();
54 selector_strings.append( tr( "PREF_LIST_TEXT_0" ) );
55 selector_strings.append( tr( "PREF_LIST_TEXT_1" ) );
56 selector_strings.append( tr( "PREF_LIST_TEXT_2" ) );
59 // Gets a reference to the module's engine
60 ${component_name}_ORB::${component_name}_Gen_ptr ${component_name}GUI::Init${component_name}Gen( SalomeApp_Application* app )
62 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer",COMPONENT_NAME );
63 ${component_name}_ORB::${component_name}_Gen_ptr clr = ${component_name}_ORB::${component_name}_Gen::_narrow(comp);
64 ASSERT(!CORBA::is_nil(clr));
68 // Module's initialization
69 void ${component_name}GUI::initialize( CAM_Application* app )
71 // Get handle to Application, Desktop and Resource Manager
72 SalomeApp_Module::initialize( app );
74 Init${component_name}Gen( dynamic_cast<SalomeApp_Application*>( app ) );
76 QWidget* aParent = app->desktop();
78 SUIT_ResourceMgr* aResourceMgr = application()->resourceMgr();
81 // --> Create actions: 190 is linked to item in "File" menu
82 // and 901 is linked to both specific menu and toolbar
83 createAction( 190, tr( "TLT_MY_NEW_ITEM" ), QIcon(), tr( "MEN_MY_NEW_ITEM" ), tr( "STS_MY_NEW_ITEM" ), 0, aParent, false,
84 this, SLOT( OnMyNewItem() ) );
86 QPixmap aPixmap = aResourceMgr->loadPixmap( COMPONENT_NAME,tr( "ICON_${component_name}" ) );
87 createAction( 901, tr( "TLT_${component_name}_ACTION" ), QIcon( aPixmap ), tr( "MEN_${component_name}_ACTION" ), tr( "STS_${component_name}_ACTION" ), 0, aParent, false,
88 this, SLOT( OnCallAction() ) );
90 // --> Create item in "File" menu
92 aMenuId = createMenu( tr( "MEN_FILE" ), -1, -1 );
93 createMenu( separator(), aMenuId, -1, 10 );
94 aMenuId = createMenu( tr( "MEN_FILE_${component_name}" ), aMenuId, -1, 10 );
95 createMenu( 190, aMenuId );
97 // --> Create specific menu
98 aMenuId = createMenu( tr( "MEN_${component_name}" ), -1, -1, 30 );
99 createMenu( 901, aMenuId, 10 );
101 // --> Create toolbar item
102 int aToolId = createTool ( tr( "TOOL_${component_name}" ) );
103 createTool( 901, aToolId );
106 // Module's engine IOR
107 QString ${component_name}GUI::engineIOR() const
109 CORBA::String_var anIOR = getApp()->orb()->object_to_string( Init${component_name}Gen( getApp() ) );
110 return QString( anIOR.in() );
113 // Module's activation
114 bool ${component_name}GUI::activateModule( SUIT_Study* theStudy )
116 bool bOk = SalomeApp_Module::activateModule( theStudy );
118 setMenuShown( true );
119 setToolShown( true );
124 // Module's deactivation
125 bool ${component_name}GUI::deactivateModule( SUIT_Study* theStudy )
127 setMenuShown( false );
128 setToolShown( false );
130 return SalomeApp_Module::deactivateModule( theStudy );
134 void ${component_name}GUI::windows( QMap<int, int>& theMap ) const
137 theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
138 theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
141 // Action slot: Launched with action 190
142 void ${component_name}GUI::OnMyNewItem()
144 SUIT_MessageBox::warning( getApp()->desktop(),tr( "INF_${component_name}_TITLE" ), tr( "INF_${component_name}_TEXT" ), tr( "BUT_OK" ) );
147 // Action slot: Launched with action 901
148 void ${component_name}GUI::OnCallAction()
150 // Create a ${component_name} component
151 ${component_name}_ORB::${component_name}_Gen_ptr ${component_name}gen = ${component_name}GUI::Init${component_name}Gen( getApp() );
155 // ${component_name}gen->method( arg1, arg2, ... );
157 // Open a dialog showing Preferences values (just to display something)
159 // ****** Direct access to preferences: implementation at 12/12/05 ******
160 // Comment out this section when "preferencesChanged" called back
161 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
163 default_bool = mgr->booleanValue(COMPONENT_NAME, "default_bool", false);
165 default_int = mgr->integerValue(COMPONENT_NAME, "default_integer", 3);
167 default_spinInt = mgr->integerValue(COMPONENT_NAME, "default_spinint", 4);
169 default_spinDbl = mgr->doubleValue(COMPONENT_NAME, "default_spindbl", 4.5);
171 int selectorIndex = mgr->integerValue(COMPONENT_NAME, "default_selector");
172 default_selection = (0<=selectorIndex && selectorIndex<=selector_strings.count() ? selector_strings[selectorIndex]: QString("None"));
173 // ****** End of section to be commented out ******
175 QString SUC = ( default_bool ? QString( tr ("INF_${component_name}_CHECK") ) : QString( tr("INF_${component_name}_UNCHECK") ) ) ;
177 QString textResult = QString( tr( "RES_${component_name}_TEXT" ) ).arg(SUC).arg(default_int).arg(default_spinInt).arg(default_spinDbl).arg(default_selection);
178 SUIT_MessageBox::information( getApp()->desktop(), tr( "RES_${component_name}_TITLE" ), textResult, tr( "BUT_OK" ) );
181 void ${component_name}GUI::createPreferences()
183 // A sample preference dialog
186 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
189 int defaultsGroup = addPreference( tr( "PREF_GROUP_DEFAULTS" ), genTab );
192 addPreference( tr( "PREF_DEFAULT_BOOL" ), defaultsGroup, LightApp_Preferences::Bool, COMPONENT_NAME, "default_bool" );
194 // An entry for integer
195 addPreference( tr( "PREF_DEFAULT_INTEGER" ), defaultsGroup, LightApp_Preferences::Integer, COMPONENT_NAME, "default_integer" );
197 // An integer changed by spinbox
198 int spinInt = addPreference( tr( "PREF_DEFAULT_SPININT" ), defaultsGroup, LightApp_Preferences::IntSpin, COMPONENT_NAME, "default_spinint" );
199 setPreferenceProperty( spinInt, "min", 0 );
200 setPreferenceProperty( spinInt, "max", 20 );
201 setPreferenceProperty( spinInt, "step", 2 );
203 // A Double changed by spinbox
204 int spinDbl = addPreference( tr( "PREF_DEFAULT_SPINDBL" ), defaultsGroup, LightApp_Preferences::DblSpin, COMPONENT_NAME, "default_spindbl" );
205 setPreferenceProperty( spinDbl, "min", 1 );
206 setPreferenceProperty( spinDbl, "max", 10 );
207 setPreferenceProperty( spinDbl, "step", 0.1 );
209 // A choice in a list
210 int options = addPreference( tr( "PREF_DEFAULT_SELECTOR" ), defaultsGroup, LightApp_Preferences::Selector, COMPONENT_NAME, "default_selector" );
211 QList<QVariant> indices;
215 setPreferenceProperty( options, "strings", selector_strings );
216 setPreferenceProperty( options, "indexes", indices );
219 void ${component_name}GUI::preferencesChanged( const QString& sect, const QString& name )
221 // ****** This is normal way: Not yet called back at 12/12/05 ******
222 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
223 if( sect==COMPONENT_NAME )
225 if( name=="default_bool" )
226 default_bool = mgr->booleanValue(COMPONENT_NAME, "default_bool", false);
227 if( name=="default_integer" )
228 default_int = mgr->integerValue(COMPONENT_NAME, "default_integer", 3);
229 if( name=="default_spinint" )
230 default_spinInt = mgr->integerValue(COMPONENT_NAME, "default_spinint", 4);
231 if( name=="default_spindbl" )
232 default_spinDbl = mgr->doubleValue(COMPONENT_NAME, "default_spindbl", 4.5);
233 if( name=="default_selector" )
235 int selectorIndex = mgr->integerValue(COMPONENT_NAME, "default_selector");
236 default_selection = (0<=selectorIndex && selectorIndex<=selector_strings.count() ? selector_strings[selectorIndex]: QString("None"));
243 CAM_Module* createModule()
245 return new ${component_name}GUI();
249 hxxgui_cxx=Template(hxxgui_cxx)
252 #ifndef _${component_name}GUI_H_
253 #define _${component_name}GUI_H_
255 #include <SalomeApp_Module.h>
257 #include <SALOMEconfig.h>
258 #include CORBA_CLIENT_HEADER(${component_name})
260 class SalomeApp_Application;
261 class ${component_name}GUI: public SalomeApp_Module
266 ${component_name}GUI();
268 void initialize( CAM_Application* );
269 QString engineIOR() const;
270 void windows( QMap<int, int>& ) const;
272 static ${component_name}_ORB::${component_name}_Gen_ptr Init${component_name}Gen( SalomeApp_Application* );
274 virtual void createPreferences();
275 virtual void preferencesChanged( const QString&, const QString& );
278 bool deactivateModule( SUIT_Study* );
279 bool activateModule( SUIT_Study* );
289 double default_spinDbl;
290 QString default_selection;
292 QStringList selector_strings;
298 hxxgui_h=Template(hxxgui_h)
303 <name>@default</name>
305 <source>ICON_${component_name}</source>
306 <translation>Exec${component_name}.png</translation>
311 hxxgui_icon_ts=Template(hxxgui_icon_ts)
312 hxxgui_message_en="""
316 <name>@default</name>
318 <source>TLT_MY_NEW_ITEM</source>
319 <translation>A ${component_name} owned menu item</translation>
322 <source>MEN_MY_NEW_ITEM</source>
323 <translation>My menu</translation>
326 <source>STS_MY_NEW_ITEM</source>
327 <translation>Display a simple dialog</translation>
330 <source>TLT_${component_name}_ACTION</source>
331 <translation>Open ${component_name} dialog</translation>
334 <source>MEN_FILE</source>
335 <translation>File</translation>
338 <source>MEN_FILE_${component_name}</source>
339 <translation>${component_name} menu</translation>
342 <source>MEN_${component_name}</source>
343 <translation>${component_name}</translation>
346 <source>TOOL_${component_name}</source>
347 <translation>${component_name}</translation>
351 <name>${component_name}GUI</name>
353 <source>BUT_OK</source>
354 <translation>OK</translation>
357 <source>BUT_CANCEL</source>
358 <translation>Cancel</translation>
361 <source>INF_${component_name}_TITLE</source>
362 <translation>${component_name} Information</translation>
365 <source>INF_${component_name}_TEXT</source>
366 <translation>This is just a test</translation>
369 <source>INF_${component_name}_CHECK</source>
370 <translation>checked</translation>
373 <source>INF_${component_name}_UNCHECK</source>
374 <translation>Unchecked</translation>
377 <source>RES_${component_name}_TITLE</source>
378 <translation>Sample ${component_name} dialog</translation>
381 <source>RES_${component_name}_TEXT</source>
382 <translation>Preferences are: \n\tCheckbox: %1\n\tInteger: %2\n\tInteger2: %3\n\tDouble: %4\n\tText: %5</translation>
385 <source>PREF_TAB_GENERAL</source>
386 <translation>General</translation>
389 <source>PREF_GROUP_DEFAULTS</source>
390 <translation>Default Values</translation>
393 <source>PREF_DEFAULT_BOOL</source>
394 <translation>Check me</translation>
397 <source>PREF_DEFAULT_INTEGER</source>
398 <translation>Enter an integer :</translation>
401 <source>PREF_DEFAULT_SPININT</source>
402 <translation>Click arrows (integer) :</translation>
405 <source>PREF_DEFAULT_SPINDBL</source>
406 <translation>Click arrows (double)</translation>
409 <source>PREF_DEFAULT_SELECTOR</source>
410 <translation>Select an option</translation>
413 <source>PREF_LIST_TEXT_0</source>
414 <translation>first option</translation>
417 <source>PREF_LIST_TEXT_1</source>
418 <translation>second option</translation>
421 <source>PREF_LIST_TEXT_2</source>
422 <translation>third option</translation>
427 hxxgui_message_en=Template(hxxgui_message_en)
428 hxxgui_message_fr="""
432 <name>@default</name>
434 <source>TLT_MY_NEW_ITEM</source>
435 <translation>Un article de menu propre a ${component_name}</translation>
438 <source>MEN_MY_NEW_ITEM</source>
439 <translation>Mon menu</translation>
442 <source>STS_MY_NEW_ITEM</source>
443 <translation>Affiche une boite de dialogue simple</translation>
446 <source>TLT_${component_name}_ACTION</source>
447 <translation>Ouvre la boite de dialogue de ${component_name}</translation>
450 <source>MEN_FILE</source>
451 <translation>File</translation>
454 <source>MEN_FILE_${component_name}</source>
455 <translation>Menu de ${component_name}</translation>
458 <source>MEN_${component_name}</source>
459 <translation>${component_name}</translation>
462 <source>TOOL_${component_name}</source>
463 <translation>${component_name}</translation>
467 <name>${component_name}GUI</name>
469 <source>BUT_OK</source>
470 <translation>OK</translation>
473 <source>BUT_CANCEL</source>
474 <translation>Annuler</translation>
477 <source>INF_${component_name}_TITLE</source>
478 <translation>Information ${component_name}</translation>
481 <source>INF_${component_name}_TEXT</source>
482 <translation>Ceci est un simple test</translation>
485 <source>INF_${component_name}_CHECK</source>
486 <translation>coche</translation>
489 <source>INF_${component_name}_UNCHECK</source>
490 <translation>decoche</translation>
493 <source>RES_${component_name}_TITLE</source>
494 <translation>Dialogue example de ${component_name}</translation>
497 <source>RES_${component_name}_TEXT</source>
498 <translation>Les preferences sont : \n\tCase a cocher : %1\n\tEntier : %2\n\tEntier2 : %3\n\tDouble : %4\n\tTexte : %5</translation>
501 <source>PREF_TAB_GENERAL</source>
502 <translation>General</translation>
505 <source>PREF_GROUP_DEFAULTS</source>
506 <translation>valeur par defaut</translation>
509 <source>PREF_DEFAULT_BOOL</source>
510 <translation>Cochez-moi</translation>
513 <source>PREF_DEFAULT_INTEGER</source>
514 <translation>Entrez un entier :</translation>
517 <source>PREF_DEFAULT_SPININT</source>
518 <translation>cliquez sur les fleches (entier)</translation>
521 <source>PREF_DEFAULT_SPINDBL</source>
522 <translation>cliquez sur les fleches (double)</translation>
525 <source>PREF_DEFAULT_SELECTOR</source>
526 <translation>Choisissez une option</translation>
529 <source>PREF_LIST_TEXT_0</source>
530 <translation>premiere option</translation>
533 <source>PREF_LIST_TEXT_1</source>
534 <translation>deuxieme option</translation>
537 <source>PREF_LIST_TEXT_2</source>
538 <translation>troisieme option</translation>
543 hxxgui_message_fr=Template(hxxgui_message_fr)
547 hxxgui_config=Template(hxxgui_config)
549 <?xml version='1.0' encoding='us-ascii'?>
550 <!DOCTYPE application PUBLIC "" "desktop.dtd">
551 <application title="${component_name} component" date="9/12/2001" author="C Caremoli" appId="${component_name}" >
553 <!-- ### MENUBAR ### -->
556 <menu-item label-id="File" item-id="1" pos-id="">
557 <submenu label-id="Hello" item-id="19" pos-id="9">
558 <popup-item item-id="190" pos-id="" label-id="MyNewItem" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
563 <menu-item label-id="${component_name}" item-id="90" pos-id="3">
564 <popup-item item-id="901" label-id="Get banner" icon-id="" tooltip-id="Get ${component_name} banner" accel-id="" toggle-id="" execute-action=""/>
568 <!-- ### TOOLBAR ### -->
569 <toolbar label-id="${component_name}">
570 <toolbutton-item item-id="901" label-id="Get banner" icon-id="Exec${component_name}.png" tooltip-id="Get ${component_name} banner" accel-id="" toggle-id="" execute-action=""/>
575 hxxgui_xml_en=Template(hxxgui_xml_en)
577 <?xml version='1.0' encoding='us-ascii'?>
578 <!DOCTYPE application PUBLIC "" "desktop.dtd">
579 <application title="${component_name} component" date="9/12/2001" author="C Caremoli" appId="${component_name}" >
581 <!-- ### MENUBAR ### -->
583 <menu-item label-id="File" item-id="1" pos-id="">
584 <submenu label-id="Hello" item-id="19" pos-id="9">
585 <popup-item item-id="190" pos-id="" label-id="MyNewItem" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
589 <menu-item label-id="${component_name}" item-id="90" pos-id="3">
590 <popup-item item-id="941" label-id="Lancer IHM" icon-id="" tooltip-id="Lancer IHM ${component_name}" accel-id="" toggle-id="" execute-action=""/>
593 <!-- ### TOOLBAR ### -->
594 <toolbar label-id="${component_name}">
595 <toolbutton-item item-id="941" label-id="Lancer IHM" icon-id="Exec${component_name}.png" tooltip-id="Lancer IHM ${component_name}" accel-id="" toggle-id="" execute-action=""/>
600 hxxgui_xml_fr=Template(hxxgui_xml_fr)