1 # Copyright (C) 2009-2015 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, or (at your option) any later version.
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>
36 #include <utilities.h>
38 #define COMPONENT_NAME "${component_name}"
43 ${component_name}GUI::${component_name}GUI() :
44 SalomeApp_Module( COMPONENT_NAME ) // Module name
51 default_selection = QString("");
53 // List for the selector
54 selector_strings.clear();
55 selector_strings.append( tr( "PREF_LIST_TEXT_0" ) );
56 selector_strings.append( tr( "PREF_LIST_TEXT_1" ) );
57 selector_strings.append( tr( "PREF_LIST_TEXT_2" ) );
60 // Gets a reference to the module's engine
61 ${component_name}_ORB::${component_name}_Gen_ptr ${component_name}GUI::Init${component_name}Gen( SalomeApp_Application* app )
63 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer",COMPONENT_NAME );
64 ${component_name}_ORB::${component_name}_Gen_ptr clr = ${component_name}_ORB::${component_name}_Gen::_narrow(comp);
65 ASSERT(!CORBA::is_nil(clr));
69 // Module's initialization
70 void ${component_name}GUI::initialize( CAM_Application* app )
72 // Get handle to Application, Desktop and Resource Manager
73 SalomeApp_Module::initialize( app );
75 Init${component_name}Gen( dynamic_cast<SalomeApp_Application*>( app ) );
77 QWidget* aParent = app->desktop();
79 SUIT_ResourceMgr* aResourceMgr = application()->resourceMgr();
82 // --> Create actions: 190 is linked to item in "File" menu
83 // and 901 is linked to both specific menu and toolbar
84 createAction( 190, tr( "TLT_MY_NEW_ITEM" ), QIcon(), tr( "MEN_MY_NEW_ITEM" ), tr( "STS_MY_NEW_ITEM" ), 0, aParent, false,
85 this, SLOT( OnMyNewItem() ) );
87 QPixmap aPixmap = aResourceMgr->loadPixmap( COMPONENT_NAME,tr( "ICON_${component_name}" ) );
88 createAction( 901, tr( "TLT_${component_name}_ACTION" ), QIcon( aPixmap ), tr( "MEN_${component_name}_ACTION" ), tr( "STS_${component_name}_ACTION" ), 0, aParent, false,
89 this, SLOT( OnCallAction() ) );
91 // --> Create item in "File" menu
93 aMenuId = createMenu( tr( "MEN_FILE" ), -1, -1 );
94 createMenu( separator(), aMenuId, -1, 10 );
95 aMenuId = createMenu( tr( "MEN_FILE_${component_name}" ), aMenuId, -1, 10 );
96 createMenu( 190, aMenuId );
98 // --> Create specific menu
99 aMenuId = createMenu( tr( "MEN_${component_name}" ), -1, -1, 30 );
100 createMenu( 901, aMenuId, 10 );
102 // --> Create toolbar item
103 int aToolId = createTool ( tr( "TOOL_${component_name}" ) );
104 createTool( 901, aToolId );
107 // Module's engine IOR
108 QString ${component_name}GUI::engineIOR() const
110 CORBA::String_var anIOR = getApp()->orb()->object_to_string( Init${component_name}Gen( getApp() ) );
111 return QString( anIOR.in() );
114 // Module's activation
115 bool ${component_name}GUI::activateModule( SUIT_Study* theStudy )
117 bool bOk = SalomeApp_Module::activateModule( theStudy );
119 setMenuShown( true );
120 setToolShown( true );
125 // Module's deactivation
126 bool ${component_name}GUI::deactivateModule( SUIT_Study* theStudy )
128 setMenuShown( false );
129 setToolShown( false );
131 return SalomeApp_Module::deactivateModule( theStudy );
135 void ${component_name}GUI::windows( QMap<int, int>& theMap ) const
138 theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
139 theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
142 // Action slot: Launched with action 190
143 void ${component_name}GUI::OnMyNewItem()
145 SUIT_MessageBox::warning( getApp()->desktop(),tr( "INF_${component_name}_TITLE" ), tr( "INF_${component_name}_TEXT" ), tr( "BUT_OK" ) );
148 // Action slot: Launched with action 901
149 void ${component_name}GUI::OnCallAction()
151 // Create a ${component_name} component
152 ${component_name}_ORB::${component_name}_Gen_ptr ${component_name}gen = ${component_name}GUI::Init${component_name}Gen( getApp() );
156 // ${component_name}gen->method( arg1, arg2, ... );
158 // Open a dialog showing Preferences values (just to display something)
160 // ****** Direct access to preferences: implementation at 12/12/05 ******
161 // Comment out this section when "preferencesChanged" called back
162 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
164 default_bool = mgr->booleanValue(COMPONENT_NAME, "default_bool", false);
166 default_int = mgr->integerValue(COMPONENT_NAME, "default_integer", 3);
168 default_spinInt = mgr->integerValue(COMPONENT_NAME, "default_spinint", 4);
170 default_spinDbl = mgr->doubleValue(COMPONENT_NAME, "default_spindbl", 4.5);
172 int selectorIndex = mgr->integerValue(COMPONENT_NAME, "default_selector");
173 default_selection = (0<=selectorIndex && selectorIndex<=selector_strings.count() ? selector_strings[selectorIndex]: QString("None"));
174 // ****** End of section to be commented out ******
176 QString SUC = ( default_bool ? QString( tr ("INF_${component_name}_CHECK") ) : QString( tr("INF_${component_name}_UNCHECK") ) ) ;
178 QString textResult = QString( tr( "RES_${component_name}_TEXT" ) ).arg(SUC).arg(default_int).arg(default_spinInt).arg(default_spinDbl).arg(default_selection);
179 SUIT_MessageBox::information( getApp()->desktop(), tr( "RES_${component_name}_TITLE" ), textResult, tr( "BUT_OK" ) );
182 void ${component_name}GUI::createPreferences()
184 // A sample preference dialog
187 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
190 int defaultsGroup = addPreference( tr( "PREF_GROUP_DEFAULTS" ), genTab );
193 addPreference( tr( "PREF_DEFAULT_BOOL" ), defaultsGroup, LightApp_Preferences::Bool, COMPONENT_NAME, "default_bool" );
195 // An entry for integer
196 addPreference( tr( "PREF_DEFAULT_INTEGER" ), defaultsGroup, LightApp_Preferences::Integer, COMPONENT_NAME, "default_integer" );
198 // An integer changed by spinbox
199 int spinInt = addPreference( tr( "PREF_DEFAULT_SPININT" ), defaultsGroup, LightApp_Preferences::IntSpin, COMPONENT_NAME, "default_spinint" );
200 setPreferenceProperty( spinInt, "min", 0 );
201 setPreferenceProperty( spinInt, "max", 20 );
202 setPreferenceProperty( spinInt, "step", 2 );
204 // A Double changed by spinbox
205 int spinDbl = addPreference( tr( "PREF_DEFAULT_SPINDBL" ), defaultsGroup, LightApp_Preferences::DblSpin, COMPONENT_NAME, "default_spindbl" );
206 setPreferenceProperty( spinDbl, "min", 1 );
207 setPreferenceProperty( spinDbl, "max", 10 );
208 setPreferenceProperty( spinDbl, "step", 0.1 );
210 // A choice in a list
211 int options = addPreference( tr( "PREF_DEFAULT_SELECTOR" ), defaultsGroup, LightApp_Preferences::Selector, COMPONENT_NAME, "default_selector" );
212 QList<QVariant> indices;
216 setPreferenceProperty( options, "strings", selector_strings );
217 setPreferenceProperty( options, "indexes", indices );
220 void ${component_name}GUI::preferencesChanged( const QString& sect, const QString& name )
222 // ****** This is normal way: Not yet called back at 12/12/05 ******
223 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
224 if( sect==COMPONENT_NAME )
226 if( name=="default_bool" )
227 default_bool = mgr->booleanValue(COMPONENT_NAME, "default_bool", false);
228 if( name=="default_integer" )
229 default_int = mgr->integerValue(COMPONENT_NAME, "default_integer", 3);
230 if( name=="default_spinint" )
231 default_spinInt = mgr->integerValue(COMPONENT_NAME, "default_spinint", 4);
232 if( name=="default_spindbl" )
233 default_spinDbl = mgr->doubleValue(COMPONENT_NAME, "default_spindbl", 4.5);
234 if( name=="default_selector" )
236 int selectorIndex = mgr->integerValue(COMPONENT_NAME, "default_selector");
237 default_selection = (0<=selectorIndex && selectorIndex<=selector_strings.count() ? selector_strings[selectorIndex]: QString("None"));
244 CAM_Module* createModule()
246 return new ${component_name}GUI();
250 hxxgui_cxx=Template(hxxgui_cxx)
253 #ifndef _${component_name}GUI_H_
254 #define _${component_name}GUI_H_
256 #include <SalomeApp_Module.h>
258 #include <SALOMEconfig.h>
259 #include CORBA_CLIENT_HEADER(${component_name})
261 class SalomeApp_Application;
262 class ${component_name}GUI: public SalomeApp_Module
267 ${component_name}GUI();
269 void initialize( CAM_Application* );
270 QString engineIOR() const;
271 void windows( QMap<int, int>& ) const;
273 static ${component_name}_ORB::${component_name}_Gen_ptr Init${component_name}Gen( SalomeApp_Application* );
275 virtual void createPreferences();
276 virtual void preferencesChanged( const QString&, const QString& );
279 bool deactivateModule( SUIT_Study* );
280 bool activateModule( SUIT_Study* );
290 double default_spinDbl;
291 QString default_selection;
293 QStringList selector_strings;
299 hxxgui_h=Template(hxxgui_h)
304 <name>@default</name>
306 <source>ICON_${component_name}</source>
307 <translation>Exec${component_name}.png</translation>
312 hxxgui_icon_ts=Template(hxxgui_icon_ts)
313 hxxgui_message_en="""
317 <name>@default</name>
319 <source>TLT_MY_NEW_ITEM</source>
320 <translation>A ${component_name} owned menu item</translation>
323 <source>MEN_MY_NEW_ITEM</source>
324 <translation>My menu</translation>
327 <source>STS_MY_NEW_ITEM</source>
328 <translation>Display a simple dialog</translation>
331 <source>TLT_${component_name}_ACTION</source>
332 <translation>Open ${component_name} dialog</translation>
335 <source>MEN_FILE</source>
336 <translation>File</translation>
339 <source>MEN_FILE_${component_name}</source>
340 <translation>${component_name} menu</translation>
343 <source>MEN_${component_name}</source>
344 <translation>${component_name}</translation>
347 <source>TOOL_${component_name}</source>
348 <translation>${component_name}</translation>
352 <name>${component_name}GUI</name>
354 <source>BUT_OK</source>
355 <translation>OK</translation>
358 <source>BUT_CANCEL</source>
359 <translation>Cancel</translation>
362 <source>INF_${component_name}_TITLE</source>
363 <translation>${component_name} Information</translation>
366 <source>INF_${component_name}_TEXT</source>
367 <translation>This is just a test</translation>
370 <source>INF_${component_name}_CHECK</source>
371 <translation>checked</translation>
374 <source>INF_${component_name}_UNCHECK</source>
375 <translation>Unchecked</translation>
378 <source>RES_${component_name}_TITLE</source>
379 <translation>Sample ${component_name} dialog</translation>
382 <source>RES_${component_name}_TEXT</source>
383 <translation>Preferences are: \n\tCheckbox: %1\n\tInteger: %2\n\tInteger2: %3\n\tDouble: %4\n\tText: %5</translation>
386 <source>PREF_TAB_GENERAL</source>
387 <translation>General</translation>
390 <source>PREF_GROUP_DEFAULTS</source>
391 <translation>Default Values</translation>
394 <source>PREF_DEFAULT_BOOL</source>
395 <translation>Check me</translation>
398 <source>PREF_DEFAULT_INTEGER</source>
399 <translation>Enter an integer :</translation>
402 <source>PREF_DEFAULT_SPININT</source>
403 <translation>Click arrows (integer) :</translation>
406 <source>PREF_DEFAULT_SPINDBL</source>
407 <translation>Click arrows (double)</translation>
410 <source>PREF_DEFAULT_SELECTOR</source>
411 <translation>Select an option</translation>
414 <source>PREF_LIST_TEXT_0</source>
415 <translation>first option</translation>
418 <source>PREF_LIST_TEXT_1</source>
419 <translation>second option</translation>
422 <source>PREF_LIST_TEXT_2</source>
423 <translation>third option</translation>
428 hxxgui_message_en=Template(hxxgui_message_en)
429 hxxgui_message_fr="""
433 <name>@default</name>
435 <source>TLT_MY_NEW_ITEM</source>
436 <translation>Un article de menu propre a ${component_name}</translation>
439 <source>MEN_MY_NEW_ITEM</source>
440 <translation>Mon menu</translation>
443 <source>STS_MY_NEW_ITEM</source>
444 <translation>Affiche une boite de dialogue simple</translation>
447 <source>TLT_${component_name}_ACTION</source>
448 <translation>Ouvre la boite de dialogue de ${component_name}</translation>
451 <source>MEN_FILE</source>
452 <translation>File</translation>
455 <source>MEN_FILE_${component_name}</source>
456 <translation>Menu de ${component_name}</translation>
459 <source>MEN_${component_name}</source>
460 <translation>${component_name}</translation>
463 <source>TOOL_${component_name}</source>
464 <translation>${component_name}</translation>
468 <name>${component_name}GUI</name>
470 <source>BUT_OK</source>
471 <translation>OK</translation>
474 <source>BUT_CANCEL</source>
475 <translation>Annuler</translation>
478 <source>INF_${component_name}_TITLE</source>
479 <translation>Information ${component_name}</translation>
482 <source>INF_${component_name}_TEXT</source>
483 <translation>Ceci est un simple test</translation>
486 <source>INF_${component_name}_CHECK</source>
487 <translation>coche</translation>
490 <source>INF_${component_name}_UNCHECK</source>
491 <translation>decoche</translation>
494 <source>RES_${component_name}_TITLE</source>
495 <translation>Dialogue example de ${component_name}</translation>
498 <source>RES_${component_name}_TEXT</source>
499 <translation>Les preferences sont : \n\tCase a cocher : %1\n\tEntier : %2\n\tEntier2 : %3\n\tDouble : %4\n\tTexte : %5</translation>
502 <source>PREF_TAB_GENERAL</source>
503 <translation>General</translation>
506 <source>PREF_GROUP_DEFAULTS</source>
507 <translation>valeur par defaut</translation>
510 <source>PREF_DEFAULT_BOOL</source>
511 <translation>Cochez-moi</translation>
514 <source>PREF_DEFAULT_INTEGER</source>
515 <translation>Entrez un entier :</translation>
518 <source>PREF_DEFAULT_SPININT</source>
519 <translation>cliquez sur les fleches (entier)</translation>
522 <source>PREF_DEFAULT_SPINDBL</source>
523 <translation>cliquez sur les fleches (double)</translation>
526 <source>PREF_DEFAULT_SELECTOR</source>
527 <translation>Choisissez une option</translation>
530 <source>PREF_LIST_TEXT_0</source>
531 <translation>premiere option</translation>
534 <source>PREF_LIST_TEXT_1</source>
535 <translation>deuxieme option</translation>
538 <source>PREF_LIST_TEXT_2</source>
539 <translation>troisieme option</translation>
544 hxxgui_message_fr=Template(hxxgui_message_fr)
548 hxxgui_config=Template(hxxgui_config)
550 <?xml version='1.0' encoding='us-ascii'?>
551 <!DOCTYPE application PUBLIC "" "desktop.dtd">
552 <application title="${component_name} component" date="9/12/2001" author="C Caremoli" appId="${component_name}" >
554 <!-- ### MENUBAR ### -->
557 <menu-item label-id="File" item-id="1" pos-id="">
558 <submenu label-id="Hello" item-id="19" pos-id="9">
559 <popup-item item-id="190" pos-id="" label-id="MyNewItem" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
564 <menu-item label-id="${component_name}" item-id="90" pos-id="3">
565 <popup-item item-id="901" label-id="Get banner" icon-id="" tooltip-id="Get ${component_name} banner" accel-id="" toggle-id="" execute-action=""/>
569 <!-- ### TOOLBAR ### -->
570 <toolbar label-id="${component_name}">
571 <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=""/>
576 hxxgui_xml_en=Template(hxxgui_xml_en)
578 <?xml version='1.0' encoding='us-ascii'?>
579 <!DOCTYPE application PUBLIC "" "desktop.dtd">
580 <application title="${component_name} component" date="9/12/2001" author="C Caremoli" appId="${component_name}" >
582 <!-- ### MENUBAR ### -->
584 <menu-item label-id="File" item-id="1" pos-id="">
585 <submenu label-id="Hello" item-id="19" pos-id="9">
586 <popup-item item-id="190" pos-id="" label-id="MyNewItem" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
590 <menu-item label-id="${component_name}" item-id="90" pos-id="3">
591 <popup-item item-id="941" label-id="Lancer IHM" icon-id="" tooltip-id="Lancer IHM ${component_name}" accel-id="" toggle-id="" execute-action=""/>
594 <!-- ### TOOLBAR ### -->
595 <toolbar label-id="${component_name}">
596 <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=""/>
601 hxxgui_xml_fr=Template(hxxgui_xml_fr)