From 634bdc45ef560055a0e4608d0e820a6698edbff6 Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Wed, 21 Jul 2021 17:01:35 +0200 Subject: [PATCH] Light GUI module example. --- Examples/cppgui2/Makefile | 21 ++++ Examples/cppgui2/build.sh | 1 + Examples/cppgui2/components.py | 38 +++++++ Examples/cppgui2/cppcompos.png | Bin 0 -> 831 bytes Examples/cppgui2/cppcomposGUI.cxx | 159 ++++++++++++++++++++++++++++++ Examples/cppgui2/cppcomposGUI.h | 65 ++++++++++++ Examples/cppgui2/demo.ui | 146 +++++++++++++++++++++++++++ Examples/cppgui2/exec.png | Bin 0 -> 831 bytes Examples/cppgui2/index.rst | 23 +++++ Examples/cppgui2/using.rst | 17 ++++ 10 files changed, 470 insertions(+) create mode 100644 Examples/cppgui2/Makefile create mode 100755 Examples/cppgui2/build.sh create mode 100644 Examples/cppgui2/components.py create mode 100644 Examples/cppgui2/cppcompos.png create mode 100644 Examples/cppgui2/cppcomposGUI.cxx create mode 100644 Examples/cppgui2/cppcomposGUI.h create mode 100644 Examples/cppgui2/demo.ui create mode 100644 Examples/cppgui2/exec.png create mode 100644 Examples/cppgui2/index.rst create mode 100644 Examples/cppgui2/using.rst diff --git a/Examples/cppgui2/Makefile b/Examples/cppgui2/Makefile new file mode 100644 index 0000000..8ca1e93 --- /dev/null +++ b/Examples/cppgui2/Makefile @@ -0,0 +1,21 @@ +# Copyright (C) 2009-2021 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, or (at your option) any later version. +# +# 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 +# + +clean: + rm -rf *.o *.so cppcompos_* appli install *.bak traceExec_proc *.err *.log diff --git a/Examples/cppgui2/build.sh b/Examples/cppgui2/build.sh new file mode 100755 index 0000000..8430376 --- /dev/null +++ b/Examples/cppgui2/build.sh @@ -0,0 +1 @@ +../exec.sh python components.py diff --git a/Examples/cppgui2/components.py b/Examples/cppgui2/components.py new file mode 100644 index 0000000..eb18cad --- /dev/null +++ b/Examples/cppgui2/components.py @@ -0,0 +1,38 @@ +# Copyright (C) 2009-2021 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, or (at your option) any later version. +# +# 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 .. +exec(compile(open("../context.py").read(), "../context.py", 'exec')) + +import os +from module_generator import * + + +modul=Module("cppcompos",components=[],prefix="./install", + doc=["*.rst",], + gui=["cppcomposGUI.cxx","cppcomposGUI.h","demo.ui","*.png"], + ) + +g=Generator(modul,context) +g.generate() +g.configure() +g.make() +g.install() +g.make_appli("appli", restrict=["KERNEL","GUI","YACS"], sys_modules=SYS_MODULES) + diff --git a/Examples/cppgui2/cppcompos.png b/Examples/cppgui2/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 +#include +#include +#include + +#include + +// QT Includes +#include +#include +#include + +// Export the module +extern "C" { + CAM_Module* createModule() + { + return new cppcomposGUI(); + } +} + +// Constructor +cppcomposGUI::cppcomposGUI() : + SalomeApp_Module( "cppcompos" ) // default name +{ +} + +//static cppcompos_ORB::cppcompos_var engine; + +// 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 ); + + _myWidget = new QLabel("My module!", aParent); + _myViewManager = getApp()->createViewManager("cppcompos", _myWidget); + _myViewManager->getActiveView()->setClosable( false ); + if(app->desktop() ) + connect( app->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT(onWindowActivated( SUIT_ViewWindow* )) ); + +} + +// Get compatible dockable windows. +void cppcomposGUI::windows( QMap& theMap ) const +{ + theMap.clear(); +// theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea ); +// theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea ); +} + +// Module's engine IOR +QString cppcomposGUI::engineIOR() const +{ + return "Fake"; +} + +// Module's activation +bool cppcomposGUI::activateModule( SUIT_Study* theStudy ) +{ + bool bOk = SalomeApp_Module::activateModule( theStudy ); + + if(bOk) + { + setMenuShown( true ); + setToolShown( true ); + _myViewManager->setShown(true); + _myWidget->setVisible(true); + _myViewManager->getActiveView()->setFocus(); + } + return bOk; +} + +// Module's deactivation +bool cppcomposGUI::deactivateModule( SUIT_Study* theStudy ) +{ + setMenuShown( false ); + setToolShown( false ); + _myWidget->setVisible(false); + _myViewManager->setShown(false); + + return SalomeApp_Module::deactivateModule( theStudy ); +} + +void cppcomposGUI::onWindowActivated( SUIT_ViewWindow* svw) +{ + if(_myViewManager->getActiveView()->getId() == svw->getId()) + if (!getApp()->activeModule() || + getApp()->activeModule()->moduleName() != "cppcompos") + getApp()->activateModule("cppcompos"); +} + +// 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/cppgui2/cppcomposGUI.h b/Examples/cppgui2/cppcomposGUI.h new file mode 100644 index 0000000..b4f26c0 --- /dev/null +++ b/Examples/cppgui2/cppcomposGUI.h @@ -0,0 +1,65 @@ +// Copyright (C) 2009-2021 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, or (at your option) any later version. +// +// 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 +// + +#ifndef _cppcomposGUI_H_ +#define _cppcomposGUI_H_ + +#include +#include "ui_demo.h" + +class SUIT_ViewManager; +class SUIT_ViewWindow; + +class cppcomposGUI: public SalomeApp_Module +{ + Q_OBJECT + +public: + cppcomposGUI(); + void initialize( CAM_Application* ); + QString engineIOR() const; + virtual void windows( QMap& theMap ) const; + +public slots: + bool deactivateModule( SUIT_Study* ); + bool activateModule( SUIT_Study* ); + +protected slots: + void OnGetBanner(); + void OnDesigner(); + void onWindowActivated( SUIT_ViewWindow* svw); + +private: + QWidget* _myWidget; + SUIT_ViewManager* _myViewManager; +}; + +class MyDemo: public QDialog +{ + Q_OBJECT + +public: + MyDemo(QWidget *parent = 0); + +private: + Ui::DemoDialog ui; + +}; + +#endif diff --git a/Examples/cppgui2/demo.ui b/Examples/cppgui2/demo.ui new file mode 100644 index 0000000..69e4ac0 --- /dev/null +++ b/Examples/cppgui2/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/cppgui2/exec.png b/Examples/cppgui2/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