From 4e0a7935d7deaad7f4ead8114d5467d5bab8d791 Mon Sep 17 00:00:00 2001 From: caremoli Date: Fri, 24 Sep 2010 16:05:45 +0000 Subject: [PATCH] CCAR: Second part of development to be able to generate a module with GUI (from c++ sources) Add one example (Examples/cppgui1) --- Examples/cppgui1/components.py | 53 +++++++++++ Examples/cppgui1/cppcompos.png | Bin 0 -> 831 bytes Examples/cppgui1/cppcomposGUI.cxx | 102 +++++++++++++++++++++ Examples/cppgui1/cppcomposGUI.h | 38 ++++++++ Examples/cppgui1/demo.ui | 146 ++++++++++++++++++++++++++++++ Examples/cppgui1/exec.png | Bin 0 -> 831 bytes Examples/cppgui1/index.rst | 23 +++++ Examples/cppgui1/using.rst | 17 ++++ MANIFEST.in | 4 + module_generator/gener.py | 49 +++++++--- module_generator/gui_tmpl.py | 22 ++++- 11 files changed, 441 insertions(+), 13 deletions(-) create mode 100644 Examples/cppgui1/components.py create mode 100644 Examples/cppgui1/cppcompos.png create mode 100644 Examples/cppgui1/cppcomposGUI.cxx create mode 100644 Examples/cppgui1/cppcomposGUI.h create mode 100644 Examples/cppgui1/demo.ui create mode 100644 Examples/cppgui1/exec.png create mode 100644 Examples/cppgui1/index.rst create mode 100644 Examples/cppgui1/using.rst diff --git a/Examples/cppgui1/components.py b/Examples/cppgui1/components.py new file mode 100644 index 0000000..43cd326 --- /dev/null +++ b/Examples/cppgui1/components.py @@ -0,0 +1,53 @@ +# Copyright (C) 2009-2010 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +#import context from .. +execfile("../context.py") + +import os +from module_generator import Generator,Module,Service,CPPComponent + +body=""" +std::cerr << "a: " << a << std::endl; +std::cerr << "b: " << b << std::endl; +c=a+b; +std::cerr << "c: " << c << std::endl; +""" +c1=CPPComponent("compo1",services=[ + Service("s1",inport=[("a","double"),("b","double")], + outport=[("c","double")], + defs="//def1",body=body, + ), + ], + includes="-I/usr/include", + ) + +modul=Module("cppcompos",components=[c1],prefix="./install", + doc=["*.rst",], + gui=["cppcomposGUI.cxx","cppcomposGUI.h","Makefile.am","demo.ui","*.png"], + ) + +g=Generator(modul,context) +g.generate() +g.bootstrap() +g.configure() +g.make() +g.install() +g.make_appli("appli", restrict=["KERNEL"], altmodules={"GUI":GUI_ROOT_DIR, "YACS":YACS_ROOT_DIR}) + diff --git a/Examples/cppgui1/cppcompos.png b/Examples/cppgui1/cppcompos.png new file mode 100644 index 0000000000000000000000000000000000000000..16a20c116e8243a6b49ed862613d2cc49bdf4caa GIT binary patch literal 831 zcmV-F1Hk-=P)A+3!%gdoE?w?yY*XMamxaAW~()k6;QGVVf3ZPpQcy+38CrH3{Qk zoaxN-vWJ+OcH(Y#5qvHK|CitMf1CdUU;7AQ8zF4-#i736F~#EMso~pq*Ek7JMLa$}POH_T(b)M|f)>8t;^3f3 zKA)#ntMKyW+7Z-s>l6xWsZ53jrMAEC5{41RXe`Snj$`6DMr+Vop|xgsc$hE@Sz20V zb@eG)%b|Y+_m{*NND_%L1}POFH@MUObOdhQq^%&CMdWZvC2q+x@_Pg_JQ$DGG%bJbwIyVzG#2o#E=$@5yGf z#Bm5%IplY1BB@I((}Bdlpj1;;nAaqNZEDBWHP2)F0;K|LMcrchIBe@ z&Ye4p5H>e&{)pCc=qTd1Z_6|q4IIZIpUy{Fg7-dG2KQ=nb2l+s9 +#include +#include +#include + +// QT Includes +#include +#include + +// Export the module +extern "C" { + CAM_Module* createModule() + { + return new cppcomposGUI(); + } +} + +// Constructor +cppcomposGUI::cppcomposGUI() : + SalomeApp_Module( "cppcompos" ), // default name + LightApp_Module( "cppcompos" ) +{ +} + +// Module's initialization +void cppcomposGUI::initialize( CAM_Application* app ) +{ + + SalomeApp_Module::initialize( app ); + + QWidget* aParent = application()->desktop(); + SUIT_ResourceMgr* aResourceMgr = app->resourceMgr(); + + // create actions + QPixmap aPixmap = aResourceMgr->loadPixmap( "cppcompos","exec.png" ); + createAction( 901, "Banner", QIcon( aPixmap ), "Banner", "Banner", 0, aParent, false, this, SLOT( OnGetBanner() ) ); + createAction( 902, "Designer", QIcon( aPixmap ), "Designer", "Designer", 0, aParent, false, this, SLOT( OnDesigner() ) ); + + // create menus + int aMenuId; + aMenuId = createMenu( "cppcompos", -1, -1, 30 ); + createMenu( 901, aMenuId, 10 ); + + // create toolbars + int aToolId = createTool ( "cppcompos" ); + createTool( 901, aToolId ); + createTool( 902, aToolId ); +} + +// Module's engine IOR +QString cppcomposGUI::engineIOR() const +{ + return "bidon"; +} + +// Module's activation +bool cppcomposGUI::activateModule( SUIT_Study* theStudy ) +{ + bool bOk = SalomeApp_Module::activateModule( theStudy ); + + setMenuShown( true ); + setToolShown( true ); + + return bOk; +} + +// Module's deactivation +bool cppcomposGUI::deactivateModule( SUIT_Study* theStudy ) +{ + setMenuShown( false ); + setToolShown( false ); + + return SalomeApp_Module::deactivateModule( theStudy ); +} + +// Action slot +void cppcomposGUI::OnGetBanner() +{ + // Dialog to get the Name + bool ok = FALSE; + QString myName = QInputDialog::getText( getApp()->desktop(), "label", "name", QLineEdit::Normal, QString::null, &ok ); + + if ( ok && !myName.isEmpty()) + { + QString banner = "Hello " + myName; + SUIT_MessageBox::information( getApp()->desktop(), "info", banner, "OK" ); + } +} + +// Action slot +void cppcomposGUI::OnDesigner() +{ + QWidget* wid= new MyDemo(getApp()->desktop()); + wid->show(); +} + +MyDemo::MyDemo(QWidget *parent) + :QDialog(parent) +{ + ui.setupUi(this); +} diff --git a/Examples/cppgui1/cppcomposGUI.h b/Examples/cppgui1/cppcomposGUI.h new file mode 100644 index 0000000..a9f5abc --- /dev/null +++ b/Examples/cppgui1/cppcomposGUI.h @@ -0,0 +1,38 @@ +#ifndef _cppcomposGUI_H_ +#define _cppcomposGUI_H_ + +#include +#include "ui_demo.h" + +class cppcomposGUI: public SalomeApp_Module +{ + Q_OBJECT + +public: + cppcomposGUI(); + void initialize( CAM_Application* ); + QString engineIOR() const; + +public slots: + bool deactivateModule( SUIT_Study* ); + bool activateModule( SUIT_Study* ); + +protected slots: + void OnGetBanner(); + void OnDesigner(); + +}; + +class MyDemo: public QDialog +{ + Q_OBJECT + +public: + MyDemo(QWidget *parent = 0); + +private: + Ui::DemoDialog ui; + +}; + +#endif diff --git a/Examples/cppgui1/demo.ui b/Examples/cppgui1/demo.ui new file mode 100644 index 0000000..69e4ac0 --- /dev/null +++ b/Examples/cppgui1/demo.ui @@ -0,0 +1,146 @@ + + + + + DemoDialog + + + + 0 + 0 + 400 + 300 + + + + PyUIC4 Demo Dialog + + + + 9 + + + 6 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + + + 6 + + + + + Add items + + + + + + + Clear list + + + + + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 131 + 31 + + + + + + + + OK + + + + + + + + + + + + okButton + clicked() + DemoDialog + accept() + + + 369 + 256 + + + 96 + 254 + + + + + button2 + clicked() + list + clear() + + + 92 + 112 + + + 279 + 123 + + + + + diff --git a/Examples/cppgui1/exec.png b/Examples/cppgui1/exec.png new file mode 100644 index 0000000000000000000000000000000000000000..16a20c116e8243a6b49ed862613d2cc49bdf4caa GIT binary patch literal 831 zcmV-F1Hk-=P)A+3!%gdoE?w?yY*XMamxaAW~()k6;QGVVf3ZPpQcy+38CrH3{Qk zoaxN-vWJ+OcH(Y#5qvHK|CitMf1CdUU;7AQ8zF4-#i736F~#EMso~pq*Ek7JMLa$}POH_T(b)M|f)>8t;^3f3 zKA)#ntMKyW+7Z-s>l6xWsZ53jrMAEC5{41RXe`Snj$`6DMr+Vop|xgsc$hE@Sz20V zb@eG)%b|Y+_m{*NND_%L1}POFH@MUObOdhQq^%&CMdWZvC2q+x@_Pg_JQ$DGG%bJbwIyVzG#2o#E=$@5yGf z#Bm5%IplY1BB@I((}Bdlpj1;;nAaqNZEDBWHP2)F0;K|LMcrchIBe@ z&Ye4p5H>e&{)pCc=qTd1Z_6|q4IIZIpUy{Fg7-dG2KQ=nb2l+s9
+ +
+
+
""" -- 2.39.2