HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
hal::PythonContext Class Reference

Interface for pybind11. More...

#include </home/runner/work/hal/hal/plugins/gui/include/gui/python/python_context.h>

Inheritance diagram for hal::PythonContext:
Inheritance graph
Collaboration diagram for hal::PythonContext:
Collaboration graph

Public Member Functions

 PythonContext (QObject *parent=nullptr)
 
 ~PythonContext ()
 
void interpretForeground (const QString &input)
 
void interpretBackground (QObject *caller, const QString &input, bool multiple_expressions=false)
 
void interpretScript (QObject *caller, const QString &input)
 
void forwardStdout (const QString &output)
 
void forwardError (const QString &output)
 
void scheduleClear ()
 
void scheduleReset ()
 
void setConsole (PythonConsole *console)
 
std::vector< std::tuple< std::string, std::string > > complete (const QString &text, bool use_console_context)
 
int checkCompleteStatement (const QString &text)
 
void initPython ()
 
void closePython ()
 
void updateNetlist ()
 
PythonThreadpythonThread () const
 
void abortThread ()
 
void abortThreadAndWait ()
 
bool isThreadRunning () const
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 
 QObject (QObject *parent)
 
virtual ~QObject ()
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
bool signalsBlocked () const const
 
bool blockSignals (bool block)
 
QThreadthread () const const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectListchildren () const const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
void dumpObjectTree () const const
 
void dumpObjectInfo () const const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const const
 
QList< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
 Q_CLASSINFO (Name, Value)
 
 Q_INTERFACES (...)
 
 Q_PROPERTY (...)
 
 Q_ENUMS (...)
 
 Q_FLAGS (...)
 
 Q_ENUM (...)
 
 Q_FLAG (...)
 
 Q_ENUM_NS (...)
 
 Q_FLAG_NS (...)
 
 Q_OBJECT Q_OBJECT
 
 Q_GADGET Q_GADGET
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SLOTS Q_SLOTS
 
 Q_SLOT Q_SLOT
 
 Q_EMIT Q_EMIT
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 

Static Public Member Functions

static void initializeContext (py::dict *context)
 
static void initializeScript (py::dict *context)
 
- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 

Additional Inherited Members

- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QObject
QObjectsender () const const
 
int senderSignalIndex () const const
 
int receivers (const char *signal) const const
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

Interface for pybind11.

This class provides an interface for using pybind11. It can call a python interpreter to run python expressions and scripts. Moreover it provides a function to get auto-completion candidates that are available in the context.

Definition at line 89 of file python_context.h.

Constructor & Destructor Documentation

◆ PythonContext()

hal::PythonContext::PythonContext ( QObject parent = nullptr)

Constructor.

Definition at line 40 of file python_context.cpp.

References initPython().

◆ ~PythonContext()

hal::PythonContext::~PythonContext ( )

Destructor.

Definition at line 63 of file python_context.cpp.

References closePython().

Member Function Documentation

◆ abortThread()

void hal::PythonContext::abortThread ( )

Definition at line 85 of file python_context.cpp.

References hal::PythonThread::interrupt().

Referenced by abortThreadAndWait().

◆ abortThreadAndWait()

void hal::PythonContext::abortThreadAndWait ( )

Definition at line 92 of file python_context.cpp.

References abortThread(), and QThread::wait().

◆ checkCompleteStatement()

int hal::PythonContext::checkCompleteStatement ( const QString text)

Check if given statement is a complete or incomplete statement for compound statement processing.

Parameters
[text]text - The text to check.
Returns
-1 on error, 0 for an incomplete statement and 1 for an complete statement.

Definition at line 539 of file python_context.cpp.

References _PyParser_Grammar, hal::state, and QString::toStdString().

Referenced by hal::PythonConsole::interpretCommand().

◆ closePython()

void hal::PythonContext::closePython ( )

Close the current context.

Definition at line 189 of file python_context.cpp.

Referenced by ~PythonContext().

◆ complete()

std::vector< std::tuple< std::string, std::string > > hal::PythonContext::complete ( const QString text,
bool  use_console_context 
)

Compute a list of auto completion options for a given input.
Each entry is a tuple (name_with_symbols, complete).
E.g. for text="pri" one entry would be ("print", "nt")

Parameters
text- The text to complete
use_console_context- Set true if identifiers in the context of the python console should be considered in the auto completion.
Returns
a vector of all possible auto completion candidates.

Definition at line 490 of file python_context.cpp.

References forwardError(), QString::fromStdString(), initializeContext(), log_warning, hal::state, and QString::toStdString().

Referenced by hal::PythonConsole::handleTabKeyPressed().

◆ forwardError()

void hal::PythonContext::forwardError ( const QString output)

Forwards error output to the python console.

Parameters
output- The output

Definition at line 481 of file python_context.cpp.

References hal::PythonConsole::handleError(), log_error, and hal::output.

Referenced by complete(), interpretBackground(), interpretForeground(), and hal::PYBIND11_PLUGIN().

◆ forwardStdout()

void hal::PythonContext::forwardStdout ( const QString output)

Forwards standard output to the python console.

Parameters
output- The output

Definition at line 469 of file python_context.cpp.

References hal::PythonConsole::handleStdout(), log_info, hal::output, and hal::utils::rtrim().

Referenced by interpretForeground(), interpretScript(), and hal::PYBIND11_PLUGIN().

◆ initializeContext()

void hal::PythonContext::initializeContext ( py::dict *  context)
static

◆ initializeScript()

void hal::PythonContext::initializeScript ( py::dict *  context)
static

Definition at line 154 of file python_context.cpp.

References hal::gGuiApi, and hal::gNetlistOwner.

Referenced by hal::PythonThread::run().

◆ initPython()

void hal::PythonContext::initPython ( )

Initializes the context to work with hal.

Definition at line 175 of file python_context.cpp.

References initializeContext().

Referenced by PythonContext().

◆ interpretBackground()

void hal::PythonContext::interpretBackground ( QObject caller,
const QString input,
bool  multiple_expressions = false 
)

Interprets an input string in python format in new thread.

Parameters
caller- The caller of interpreter, will be notified when finished
input- The input string in python format.
multiple_expressions- Must be set to true if the input contains multiple expressions (i.e. is a compound statement).

Definition at line 196 of file python_context.cpp.

References forwardError(), hal::input, and log_info.

Referenced by hal::PythonConsole::interpretCommand().

◆ interpretForeground()

void hal::PythonContext::interpretForeground ( const QString input)

Interprets an input string in python format in GUI thread.

Parameters
input- The input string in python format.

Definition at line 244 of file python_context.cpp.

References forwardError(), forwardStdout(), QString::fromStdString(), hal::input, log_info, and hal::state.

Referenced by hal::PythonConsole::PythonConsole().

◆ interpretScript()

void hal::PythonContext::interpretScript ( QObject caller,
const QString input 
)

Interprets a python script.

Parameters
caller- The caller of interpreter, will be notified when finished
input- The python script as a string.

Definition at line 291 of file python_context.cpp.

References forwardStdout(), hal::input, log_info, and log_warning.

Referenced by hal::PythonEditor::handleActionRun().

◆ isThreadRunning()

bool hal::PythonContext::isThreadRunning ( ) const
inline

Definition at line 205 of file python_context.h.

◆ pythonThread()

◆ scheduleClear()

void hal::PythonContext::scheduleClear ( )

Clears the python console.

Definition at line 609 of file python_context.cpp.

Referenced by hal::PYBIND11_PLUGIN().

◆ scheduleReset()

void hal::PythonContext::scheduleReset ( )

Resets the python console.

Definition at line 604 of file python_context.cpp.

Referenced by hal::PYBIND11_PLUGIN().

◆ setConsole()

void hal::PythonContext::setConsole ( PythonConsole console)

Assign this object the python console to work with.

Parameters
console- The python console to work with.

Definition at line 71 of file python_context.cpp.

References QObject::connect(), and hal::PythonConsole::inputReceived().

Referenced by hal::PythonConsole::PythonConsole(), and hal::PythonConsole::~PythonConsole().

◆ updateNetlist()

void hal::PythonContext::updateNetlist ( )

Update the current netlist the python context works with.

Definition at line 614 of file python_context.cpp.

References hal::gNetlistOwner, and hal::state.

Referenced by hal::MainWindow::handleFileOpened().


The documentation for this class was generated from the following files: