Render text in plugin of extension type

Hi all,

I work in Python, and I try to render text with a plugin of extension
type. I have begun
to write a static text with :
def performAction(self, action, glwidget):
self.emit(SIGNAL(“message(const QString&)”), “Hello World Signal …”)
glwidget.painter.drawText( 50, 50, “Hello world !” )
glwidget.updateGeometry()
return None

The signal works, but I have no “Hello World !”.
With a engine plugin, it works no problem (thanks to documentation) :
def renderOpaque(self, pd):
pd.painter.drawText( 50, 50, “Hello world” )

So, must I load/reload engine in my extension to render a text ?
Another possibilities to render a text in extension plugin ?
Is there a limitation in a plugin of extension type ?

Regards,
Mickaël Gadroy

Hi,

On Mon, Feb 22, 2010 at 4:01 PM, Mickaël Gadroy
mickael.gadroy@univ-reims.fr wrote:

Hi all,

I work in Python, and I try to render text with a plugin of extension
type. I have begun
to write a static text with :
def performAction(self, action, glwidget):
self.emit(SIGNAL(“message(const QString&)”), “Hello World Signal …”)
glwidget.painter.drawText( 50, 50, “Hello world !” )
glwidget.updateGeometry()
return None

The signal works, but I have no “Hello World !”.
With a engine plugin, it works no problem (thanks to documentation) :
def renderOpaque(self, pd):
pd.painter.drawText( 50, 50, “Hello world” )

So, must I load/reload engine in my extension to render a text ?
Another possibilities to render a text in extension plugin ?
Is there a limitation in a plugin of extension type ?

It’s not possible to draw anything from an extension since there is no
paint function or something similar which gets called when the screen
is refreshed. In other words, you can’t use a painter outside an
Engine (or Tool::paint). For future versions we may want extensions to
be able to draw things. There are a number of cases where this would
be useful.

It might be possible to add this functionality to python extensions
now without breaking anything. I would have to add a new function to
GLWidget to make it aware of extensions so it can call
PythonExtension::paint() when an Extension is a PythonExtension
(qobject_cast)… (For future versions we can add the virtual
Extension::paint() function but this willbreak ABI.)

Does anyone have objections to me adding this?

Cheers,
Tim

Regards,
Mickaël Gadroy


Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

On Mon, Feb 22, 2010 at 6:00 PM, Tim Vandermeersch
tim.vandermeersch@gmail.com wrote:

Hi,

On Mon, Feb 22, 2010 at 4:01 PM, Mickaël Gadroy
mickael.gadroy@univ-reims.fr wrote:

Hi all,

I work in Python, and I try to render text with a plugin of extension
type. I have begun
to write a static text with :
def performAction(self, action, glwidget):
self.emit(SIGNAL(“message(const QString&)”), “Hello World Signal …”)
glwidget.painter.drawText( 50, 50, “Hello world !” )
glwidget.updateGeometry()
return None

The signal works, but I have no “Hello World !”.
With a engine plugin, it works no problem (thanks to documentation) :
def renderOpaque(self, pd):
pd.painter.drawText( 50, 50, “Hello world” )

So, must I load/reload engine in my extension to render a text ?
Another possibilities to render a text in extension plugin ?
Is there a limitation in a plugin of extension type ?

It’s not possible to draw anything from an extension since there is no
paint function or something similar which gets called when the screen
is refreshed. In other words, you can’t use a painter outside an
Engine (or Tool::paint). For future versions we may want extensions to
be able to draw things. There are a number of cases where this would
be useful.

It might be possible to add this functionality to python extensions
now without breaking anything. I would have to add a new function to
GLWidget to make it aware of extensions so it can call
PythonExtension::paint() when an Extension is a PythonExtension
(qobject_cast)… (For future versions we can add the virtual
Extension::paint() function but this willbreak ABI.)

Does anyone have objections to me adding this?

Since this wasn’t a lot of work, I already implemented it. (See github)

The following script now works as expected:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from numpy import *
import Avogadro

always use ‘Extension’ for class name

class Extension(QObject):
def init(self):
QObject.init(self)

def name(self):
return “Painting from a PythonExtension example”

def description(self):
return “Example python extension showing new paint ability.”

def actions(self):
actions =
return actions

def performAction(self, action, glwidget):
return

def paint(self, glwidget):
glwidget.painter.drawText( 50, 50, “Hello world !” )

Tim

Cheers,
Tim

Regards,
Mickaël Gadroy


Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

Thank you very much.
But, I do not understand some mechanism (Python, Avogadro). How do we
perform the paint method in extension script ? (Signals to connect ?)

Mickaël Gadroy

Thank you very much.
But, I do not understand some mechanism (Python, Avogadro). How do we perform the paint method in extension script ? (Signals to connect ?)

You can’t paint in extension. Create engine insted


Regards,
Konstantin

On Tue, Feb 23, 2010 at 5:00 PM, Mickaël Gadroy
mickael.gadroy@univ-reims.fr wrote:

Thank you very much.
But, I do not understand some mechanism (Python, Avogadro). How do we
perform the paint method in extension script ? (Signals to connect ?)

When using the very latest version of Avogadro, the paint method in a
python extension will be called for you (from the GLWidget). The
important thing to notice is that GLWidget calls the paint method at
the correct stage in render pipeline…

What version are you using 1.0? Did you compile from source?

Tim

Mickaël Gadroy

I am using the avogadro version 1.1.0 (SIP 4.10, Qt 4.6.2, PyQt 4.7) and I
have compiled from source (github, the git URL from
http://github.com/cryos/avogadro/). I don’t see message error. The script is
present in plugin management (extension section) and check. I appear it in
script menu.
If I understand, paint method is called automatically. I have tested to
send a signal (self.emit(SIGNAL(“message(const QString&)”), “Paint Signal
…”)) in paint method. No display. And no idea …

Mickaël Gadroy

On Tue, Feb 23, 2010 at 6:26 PM, Mickaël Gadroy
mickael.gadroy@univ-reims.fr wrote:

I am using the avogadro version 1.1.0 (SIP 4.10, Qt 4.6.2, PyQt 4.7) and I
have compiled from source (github, the git URL from
GitHub - cryos/avogadro: Avogadro 1 is not under active development, the repository was archived in September 2021. Development of Avogadro 2 is being done at https://github.com/openchemistry/avogadrolibs. Avogadro is an advanced molecular editor designed for cross-platform use in computational chemistry, molecular modeling, bioinformatics, materials science, and related areas.).

Did you recently update your copy and recompile? (git pull origin master)

I don’t see message error. The script is
present in plugin management (extension section) and check. I appear it in
script menu.
If I understand, paint method is called automatically. I have tested to
send a signal (self.emit(SIGNAL(“message(const QString&)”), “Paint Signal
…”)) in paint method. No display. And no idea …

Mickaël Gadroy

Perfect !
I do not think that, because I have had to reinstall my development
environment yesterday and I have realized a “git clone” after your last
response. I “git pull” this morning. Now it works.
Thanks. I will do more careful next time (with “git log”).

Regards.
Mickaël Gadroy