Discussion:
Changing color to a segment
Mauro Alberti
2012-09-17 08:44:56 UTC
Permalink
I have a very simple question: how is possible to programmatically change
the color of a segment shape from the default yellow to, for instance, red?

Many thanks,
mauro
Vincent Le Saux
2012-09-26 13:44:56 UTC
Permalink
Hi Mauro,

I faced the same problem and I may have found a solution to your problem.

The idea I found is to catch the signal emitted by your plot when you
create a shape (i.e. when your itemlist change), to analyze the contents of
your itemlist and then to change the properties of your object. Here is
some piece of code. In the following example, I just change the width of
the line of my object (when this object is not selected in the itemlist)
only if it is a 'guiqwt.shapes.RectangleShape' object.

from guiqwt.signals import SIG_ITEMS_CHANGED,
self.connect(self.plot,SIG_ITEMS_CHANGED,self.toto)

def toto(self):

listitems = self.imagewidget.panels['itemlist']

for n in range(len(listitems.listwidget)):

objet = listitems.listwidget.items[n]

type_objet = str(type(objet))

if 'RectangleShape' in type_objet:

pen = objet.pen

pen.setWidth(5)

self.plot.replot()

It is not very clean (I'm clearly not very good in programming as I have
learnt by myself) but it works! If anyone has a better way to do this, feel
free to share your knowledge, I would be very interested to know the way to
do this properly.

Cheers,

Vincent
Post by Mauro Alberti
I have a very simple question: how is possible to programmatically change
the color of a segment shape from the default yellow to, for instance, red?
Many thanks,
mauro
Mauro Alberti
2012-09-26 16:47:37 UTC
Permalink
Hi Vincent, thanks for your suggestion, that looks promising.

In the meantime, I found a shortcut for my particular sitution, given that
I could produce an installer file from my python scripts for distributing
to the client. I changed the default color for Segment color in the config
file of the quiqwt module, and, thanks to the creation of an exe and pyd
files (with py2exe) and subsequent installer creation (with innosetup), I
got this change frozen in my application, without requiring any change to
the client python installation.

cheers,
mauro

On Wed, Sep 26, 2012 at 3:44 PM, Vincent Le Saux
Post by Vincent Le Saux
Hi Mauro,
I faced the same problem and I may have found a solution to your problem.
The idea I found is to catch the signal emitted by your plot when you
create a shape (i.e. when your itemlist change), to analyze the contents of
your itemlist and then to change the properties of your object. Here is
some piece of code. In the following example, I just change the width of
the line of my object (when this object is not selected in the itemlist)
only if it is a 'guiqwt.shapes.RectangleShape' object.
from guiqwt.signals import SIG_ITEMS_CHANGED,
self.connect(self.plot,SIG_ITEMS_CHANGED,self.toto)
listitems = self.imagewidget.panels['itemlist']
objet = listitems.listwidget.items[n]
type_objet = str(type(objet))
pen = objet.pen
pen.setWidth(5)
self.plot.replot()
It is not very clean (I'm clearly not very good in programming as I have
learnt by myself) but it works! If anyone has a better way to do this, feel
free to share your knowledge, I would be very interested to know the way to
do this properly.
Cheers,
Vincent
Post by Mauro Alberti
I have a very simple question: how is possible to programmatically change
the color of a segment shape from the default yellow to, for instance, red?
Many thanks,
mauro
Loading...