Commit 909be985 authored by Jan Möbius's avatar Jan Möbius

Integrate basic python widget

parent 82ada2c8
......@@ -59,6 +59,9 @@
/// The Menu will be added inside the Algorithms Menu
#define ALGORITHMMENU tr("Algorithms")
/// The Menu will be added inside the Python Menu
#define PYTHONMENU tr("Python")
/** \file MenuInterface.hh
*
* Interface for adding per plugin toolboxes to OpenFlippers UI.\ref menuInterfacePage
......
......@@ -152,6 +152,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
modeChangeWidget(0),
fileMenu_(0),
viewMenu_(0),
pythonMenu_(0),
toolsMenu_(0),
fileMenuEnd_(0),
stereoButton_(0),
......@@ -182,6 +183,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
stereoSettingsWidget_(0),
aboutWidget_(0),
optionsWidget_(0),
pythonWidget_(0),
stereoActive_(false),
actionMode_(Viewer::PickingMode),
lastActionMode_(Viewer::ExamineMode),
......
......@@ -90,6 +90,7 @@
#include <OpenFlipper/common/OFGLWidget.hh>
#include <OpenFlipper/widgets/pythonWidget/pythonWidget.hh>
#include <OpenFlipper/widgets/aboutWidget/aboutWidget.hh>
#include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh>
#include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh>
......@@ -798,6 +799,9 @@ public:
/// View Menu
QMenu *viewMenu_;
/// Python Menu
QMenu* pythonMenu_;
/// Tools Menu
QMenu *toolsMenu_;
......@@ -1220,6 +1224,22 @@ public:
/// Pointer to the OptionsWidget
OptionsWidget* optionsWidget_;
/** @} */
//===========================================================================
/** @name Options System
* @{ */
//===========================================================================
public slots:
void showPythonScriptInterpreter();
private:
/// Pointer to the about widget
PythonWidget* pythonWidget_;
/** @} */
//===========================================================================
......
......@@ -579,6 +579,22 @@ void CoreWidget::setupMenuBar()
algorithmMenu_ = new QMenu( ALGORITHMMENU );
menus_[tr("Algorithms")] = algorithmMenu_;
// ======================================================================
// Python Menu
// ======================================================================
#ifdef PYTHON_ENABLED
pythonMenu_ = new QMenu( PYTHONMENU );
menuBar()->addMenu(pythonMenu_ );
menus_[tr("Python")] = pythonMenu_;
//Open Python Widget
QAction* AC_PythonWidget = new QAction(tr("Python Script"), this);
AC_PythonWidget->setStatusTip(tr("Open Python Script Interpreter"));
AC_PythonWidget->setWhatsThis(tr("Open the <b>Python Script Interpreter</b>"));
connect(AC_PythonWidget, SIGNAL(triggered()), this, SLOT(showPythonScriptInterpreter()));
pythonMenu_->addAction(AC_PythonWidget);
#endif
// ======================================================================
// help Menu
// ======================================================================
......@@ -629,6 +645,10 @@ void CoreWidget::setupMenuBar()
windowMenu_->installEventFilter(this);
algorithmMenu_->installEventFilter(this);
helpMenu_->installEventFilter(this);
}
......
#include "CoreWidget.hh"
void CoreWidget::showPythonScriptInterpreter() {
if ( OpenFlipper::Options::nogui() )
return;
if ( pythonWidget_ == 0 ) {
pythonWidget_ = new PythonWidget( this );
}
pythonWidget_->show();
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#include <pybind11/include/pybind11/pybind11.h>
#include <pybind11/include/pybind11/embed.h>
#include "pythonWidget.hh"
#include <iostream>
#include <QObject>
#include <OpenFlipper/PythonInterpreter/PythonInterpreter.hh>
//#include <dlfcn.h>
PythonWidget::PythonWidget(QWidget *parent )
: QMainWindow(parent)
{
setupUi(this);
connect (RunButton, SIGNAL( clicked() ), this, SLOT( runScript()) );
// QIcon icon;
// icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"window-close.png");
// actionClose->setIcon(icon);
//
// setWindowTitle(tr("About %1").arg(TOSTRING(PRODUCT_NAME)));
// const int idx = About->indexOf(tab_2);
// About->setTabText(idx, tr(TOSTRING(PRODUCT_NAME), "about box tab title"));
//
// if (QFile::exists(":/branding/license_text.html")) {
// OpenFlipperLicense->setText("");
// QFile licenseTextFile(":/branding/license_text.html");
// licenseTextFile.open(QFile::ReadOnly);
// QByteArray licenseTextBA = licenseTextFile.readAll();
// QString licenseText = QString::fromUtf8(licenseTextBA.data(), licenseTextBA.size());
// OpenFlipperLicense->setHtml(licenseText.arg(TOSTRING(PRODUCT_NAME)));
// } else {
// OpenFlipperLicense->setHtml(OpenFlipperLicense->toHtml().arg(TOSTRING(PRODUCT_NAME)));
// }
//
// connect( actionClose , SIGNAL(triggered() ) , this, SLOT(hide()) );
// connect( closeButton , SIGNAL(clicked() ) , this, SLOT(hide()) );
// closeButton->setFocus();
}
void PythonWidget::runScript() {
PythonInterpreter* interpreter = PythonInterpreter::getInstance();
interpreter->runScript(scriptWidget->toPlainText());
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#pragma once
#include "ui_pythonWidget.h"
class PythonWidget : public QMainWindow, public Ui::PythonWidget
{
Q_OBJECT
public:
explicit PythonWidget(QWidget *parent = 0);
public slots:
void runScript();
};
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PythonWidget</class>
<widget class="QMainWindow" name="PythonWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>994</width>
<height>699</height>
</rect>
</property>
<property name="windowTitle">
<string>About OpenFlipper</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="scriptTab">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Python Script</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTextEdit" name="scriptWidget">
<property name="readOnly">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Python Information</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QTextEdit" name="OpenFlipperLicense">
<property name="enabled">
<bool>true</bool>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="RunButton">
<property name="text">
<string>Run</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeButton">
<property name="text">
<string>Close</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<action name="actionClose">
<property name="text">
<string>Close</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment