forked from commontk/QtTesting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add ability to record/playback a python script.
Also add ability to query QObject properties from python.
- Loading branch information
Clinton Stimpson
committed
Oct 18, 2006
1 parent
236b416
commit fe6b1ed
Showing
11 changed files
with
814 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*========================================================================= | ||
|
||
Program: ParaView | ||
Module: QtTestingConfigure.h.in | ||
|
||
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc. | ||
All rights reserved. | ||
|
||
ParaView is a free software; you can redistribute it and/or modify it | ||
under the terms of the ParaView license version 1.1. | ||
|
||
See License_v1.1.txt for the full ParaView license. | ||
A copy of this license can be obtained by contacting | ||
Kitware Inc. | ||
28 Corporate Drive | ||
Clifton Park, NY 12065 | ||
USA | ||
|
||
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 AUTHORS 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. | ||
|
||
=========================================================================*/ | ||
|
||
#ifndef _QtTestingConfigure_h | ||
#define _QtTestingConfigure_h | ||
|
||
#cmakedefine QT_TESTING_WITH_XML | ||
|
||
#cmakedefine QT_TESTING_WITH_PYTHON | ||
|
||
#endif // _QtTestingConfigure_h | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*========================================================================= | ||
Program: ParaView | ||
Module: pqPythonEventObserver.cxx | ||
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc. | ||
All rights reserved. | ||
ParaView is a free software; you can redistribute it and/or modify it | ||
under the terms of the ParaView license version 1.1. | ||
See License_v1.1.txt for the full ParaView license. | ||
A copy of this license can be obtained by contacting | ||
Kitware Inc. | ||
28 Corporate Drive | ||
Clifton Park, NY 12065 | ||
USA | ||
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 AUTHORS 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 "pqPythonEventObserver.h" | ||
|
||
#include <QTextStream> | ||
|
||
//////////////////////////////////////////////////////////////////////////////////// | ||
// pqPythonEventObserver | ||
|
||
pqPythonEventObserver::pqPythonEventObserver(QTextStream& stream) : | ||
Stream(stream) | ||
{ | ||
this->Stream << "#/usr/bin/env python\n\n"; | ||
this->Stream << "import QtTesting\n\n"; | ||
} | ||
|
||
pqPythonEventObserver::~pqPythonEventObserver() | ||
{ | ||
this->Stream.flush(); | ||
} | ||
|
||
void pqPythonEventObserver::onRecordEvent( | ||
const QString& Widget, | ||
const QString& Command, | ||
const QString& Arguments) | ||
{ | ||
|
||
QString varname = this->Names[Widget]; | ||
if(varname == QString::null) | ||
{ | ||
varname = QString("object%1").arg(this->Names.count()); | ||
this->Names.insert(Widget, varname); | ||
QString objname("%1 = '%2'"); | ||
objname = objname.arg(varname); | ||
objname = objname.arg(Widget); | ||
this->Stream << objname << "\n"; | ||
} | ||
|
||
QString pycommand("QtTesting.playCommand(%1, '%2', '%3')"); | ||
pycommand = pycommand.arg(varname); | ||
pycommand = pycommand.arg(Command); | ||
pycommand = pycommand.arg(Arguments); | ||
this->Stream << pycommand << "\n"; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*========================================================================= | ||
Program: ParaView | ||
Module: pqPythonEventObserver.h | ||
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc. | ||
All rights reserved. | ||
ParaView is a free software; you can redistribute it and/or modify it | ||
under the terms of the ParaView license version 1.1. | ||
See License_v1.1.txt for the full ParaView license. | ||
A copy of this license can be obtained by contacting | ||
Kitware Inc. | ||
28 Corporate Drive | ||
Clifton Park, NY 12065 | ||
USA | ||
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 AUTHORS 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. | ||
=========================================================================*/ | ||
|
||
#ifndef _pqPythonEventObserver_h | ||
#define _pqPythonEventObserver_h | ||
|
||
#include <QObject> | ||
#include <QHash> | ||
#include <QString> | ||
class QTextStream; | ||
|
||
/** | ||
Observes high-level ParaView events, and serializes them to a stream as Python | ||
for possible playback (as a test-case, demo, tutorial, etc). To use, | ||
connect the onRecordEvent() slot to the pqEventTranslator::recordEvent() | ||
signal. | ||
\note Output is sent to the stream from this object's destructor, so you | ||
must ensure that it goes out of scope before trying to playback the stream. | ||
\sa pqEventTranslator, pqStdoutEventObserver, pqPythonEventSource. | ||
*/ | ||
|
||
class pqPythonEventObserver : | ||
public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
pqPythonEventObserver(QTextStream& Stream); | ||
~pqPythonEventObserver(); | ||
|
||
public slots: | ||
void onRecordEvent( | ||
const QString& Widget, | ||
const QString& Command, | ||
const QString& Arguments); | ||
|
||
private: | ||
/// Stores a stream that will be used to store the Python output | ||
QTextStream& Stream; | ||
QHash<QString, QString> Names; | ||
}; | ||
|
||
#endif // !_pqPythonEventObserver_h | ||
|
Oops, something went wrong.