[PyQt] Re: [Matplotlib-users] Using matplotlib in Qt4/Qt4 Designer

2008-08-06 Thread B Clowers
Ewald,

Here is a ui file, its conversion, matplotlib Qt widget and the associated main 
program to give you and example of how to use matplotlib (0.98.3) and Qt4 
Designer.  Have fun.

Brian

--- On Wed, 8/6/08, Ewald Zietsman <[EMAIL PROTECTED]> wrote:
From: Ewald Zietsman <[EMAIL PROTECTED]>
Subject: Re: [Matplotlib-users] Using matplotlib in Qt4/Qt4 Designer
To: [EMAIL PROTECTED]
Date: Wednesday, August 6, 2008, 4:46 PM

Actually, I have another question. The toolbar will be very nice to have. Is it 
easy to make it work again? I am using the newest matplotlib.

Ewald

On Thu, Aug 7, 2008 at 12:39 AM, Ewald Zietsman <[EMAIL PROTECTED]> wrote:

Yes! Thank you very much. I figured it out just before your email came in :-) 
I'm much happier now. 



Thank you again for teaching me this.

Cheers

Ewald




On Thu, Aug 7, 2008 at 12:31 AM, B Clowers <[EMAIL PROTECTED]> wrote:




Ewald,

If you look at the following link it may help you get started:

http://code.google.com/p/subplot/source/browse/branches/mzViewer/PyMZViewer/mpl_custom_widget.py



What you need to do is make a ui with designer and then place a widget where 
ever you'd like.  From there make sure you right click on the widget and select 
horizontal layout (This is to make sure the widget occupies the GUI fully).  
Then right click on the widget and click on "Promote to."  From there what you 
need to do is select QWidget as the base class name.  Using the example file I 
pointed to above you would put in "MPL_Widget" for the "Promoted class name" 
followed by "mpl_custom_widget" in the header file: field.  Click promote and 
you should be done.  Be sure to place the mpl_custom_widget.py in the directory 
of your converted ui file
 (i.e. the one that was created using pyuic4). Now from your main window file 
(the one that controls adding data to the plot) you simply need to use the name 
of widget you promoted followed by canvas.ax etc. to manipulate the plot.  For 
example if your promoted widget name is "plotWidget" you should be able to 
access the mpl API using "self.plotWidget.canvas.ax.plot(x,y,*kwargs)" where 
x,y, and *kwargs are the appropriate numpy arrays and keyword arguments.



I hope that helps, and let me know if you need anythinge else.

Cheers,

Brian

--ps if you need the toolbar using the latest version of matplotlib you may 
have to uncomment some of the code and remove some of the arguments that locate 
the toolbar in the ui.  



--- On Wed, 8/6/08, Ewald Zietsman <[EMAIL PROTECTED]> wrote:


From: Ewald
 Zietsman <[EMAIL PROTECTED]>
Subject: Re: [Matplotlib-users] Using matplotlib in Qt4/Qt4 Designer
To: [EMAIL PROTECTED]


Date: Wednesday, August 6, 2008, 2:47 PM


Hi,

Sorry for replying only now. Thanks for the link. I'm very new to GUI 
programming. Can you please explain to me how to promote a mpl widget from a 
regular widget? In qt3 it was possible to create a mpl widget in the form by 
telling the form to import your module containing the widget definition (a 
python class). I'm working with the qwt widgets at the moment and although 
they're supposed to be fast, they don't seem to be much faster than mpl, unless 
I'm doing something funny which is possible. I'm not really a programmer, but I 
like to tinker in order to learn as much as I can so that I can create programs 
to solve astrophysical  problems/analyse data more efficiently (less time/less 
code).




Cheers

Ewald
 

On Wed, Aug 6, 2008 at 12:46 AM, B Clowers <[EMAIL PROTECTED]> wrote:
>
> Ewald,
>
> It is very much a work in progress (and poorly named) but you can check out a 
> project of mine:



>
> http://code.google.com/p/subplot/
>
> I created a custom matplotlib widget that you can promote from a regular 
> widget in Designer.  I hope it helps, let me know if you have any questions.  
> The ui files are also included in the SVN.  One thing to note there was a 
> recent change to the Qt backend that altered the nature of the toolbar so you 
> may want to comment that part out if you are using the latest matplotlib.  If 
> it is a must have I think I'm sure I could update  the code when I find some 
> time (Currently, I'm using v 0.91 I believe).  Good luck.



>
> Cheers,
>
> Brian
>
> --- On Tue, 8/5/08, Ewald Zietsman <[EMAIL PROTECTED]> wrote:
>


> From: Ewald Zietsman <[EMAIL PROTECTED]>

> Subject: [Matplotlib-users] Using matplotlib in Qt4/Qt4 Designer
> To: [EMAIL PROTECTED]
> Date: Tuesday, August 5, 2008, 10:06 AM



>
> Hi All,
>
> I'd like to use a matplotlib widget in a GUI app I'm working on. I have tried 
> qwt but I know matplotlib a lot better and would like to use it instead. Is 
> there anybody who have done this before? More specifically, does anyone know 
> how to add a matplotlib widget as a custom widget in qt4 designer?



>
> Any help will be greatly appreciated,
>
> Ewald Zietsman
>
> -
> This SF.Net email is sponsored by the Moblin Your Move De

Re: [PyQt] re: PyQt4.4.3 segfault

2008-08-06 Thread Giovanni Bajo

On 8/6/2008 7:22 PM, juergen urner wrote:
sometimes posting reports helps to find the bug :-) did not pass to pass 
the

integer along. nevermind.


Well, it shouldn't segfault anyway, should it?
--
Giovanni Bajo
Develer S.r.l.
http://www.develer.com
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] re: PyQt4.4.3 segfault

2008-08-06 Thread juergen urner
sometimes posting reports helps to find the bug :-) did not pass to pass 
the

integer along. nevermind.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] PyQt4.4.3 segfault

2008-08-06 Thread juergen urner

Hi all,

i get a segfault when trying to connect to a signal with the following 
signature i emit:

SIGNAL('whatever(int)')

am i doing something wrong?




Platform: linux2 
Python Version: 2.5.2 
Qt Version: 4.4.0 
PyQt Version: 4.4.3-snapshot-20080705 
Sip Version: 4.7.6 



Starting program: /*.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb7e1e6b0 (LWP 6602)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7e1e6b0 (LWP 6602)]
0x08075483 in PyInt_AsLong (op=0x2) at ../Objects/intobject.c:152
152 ../Objects/intobject.c: No such file or directory.
   in ../Objects/intobject.c

(gdb) bt
#0  0x08075483 in PyInt_AsLong (op=0x2) at ../Objects/intobject.c:152
#1  0xb7be07d8 in ?? () from /usr/lib/python2.5/site-packages/PyQt4/QtCore.so
#2  0xb7be4790 in ?? () from /usr/lib/python2.5/site-packages/PyQt4/QtCore.so
#3  0xb7bec2c2 in ?? () from /usr/lib/python2.5/site-packages/PyQt4/QtCore.so
#4  0xb7fc54b2 in ?? () from /usr/lib/python2.5/site-packages/sip.so
#5  0xb7cd0a1b in ?? () from /usr/lib/python2.5/site-packages/PyQt4/QtCore.so
#6  0x080c9ab3 in PyEval_EvalFrameEx (f=0x82e6dfc, throwflag=0)
   at ../Python/ceval.c:3573
#7  0x080cb1f7 in PyEval_EvalCodeEx (co=0xb63e4de8, globals=0xb63e0cec,
   locals=0x0, args=0xb63ee618, argcount=2, kws=0x0, kwcount=0, defs=0x0,
   defcount=0, closure=0x0) at ../Python/ceval.c:2836
#8  0x0811372e in function_call (func=0xb63e69cc, arg=0xb63ee60c, kw=0x0)
   at ../Objects/funcobject.c:517
#9  0x0805cb97 in PyObject_Call (func=0x831b370, arg=0xb63ee60c, kw=0x0)
   at ../Objects/abstract.c:1861
#10 0x08062bfb in instancemethod_call (func=0xb63e69cc, arg=0xb63ee60c, kw=0x0)
   at ../Objects/classobject.c:2519
#11 0x0805cb97 in PyObject_Call (func=0x831b370, arg=0xb63e960c, kw=0x0)
   at ../Objects/abstract.c:1861
#12 0x080c2e9c in PyEval_CallObjectWithKeywords (func=0xb63ec75c,
   arg=0xb63e960c, kw=0x0) at ../Python/ceval.c:3442
#13 0xb7fc5627 in ?? () from /usr/lib/python2.5/site-packages/sip.so
#14 0xb7be8dc7 in ?? () from /usr/lib/python2.5/site-packages/PyQt4/QtCore.so



___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] SIP - %Exception for StopIteration

2008-08-06 Thread Giovanni Bajo

On 8/6/2008 7:23 AM, Jonny Morrill wrote:

Thank you both for your help!!

@Matt:

WOW! I never new that you could create an iterable object from only the
__len__ and operator[] functions!! I must have missed that when I was
searching through the python documentation for iterator objects. It is not
clear to me which is quicker, the only difference seems to be that when you
use __iter__, you can return a copy of the object so that any modifications
will not affect the original object. Thanks again!


Actually, __iter__ shouldn't modify anything. The simplest way to 
implement __iter__ in Python is to write a generator function which 
yields the elements.


__len__ and __getitem__ predate __iter__ (and iterators, and generators) 
by far: it is the oldest and easier way to iterate over an object in a 
for loop. If you think of it, it is obvious that it is possible to do a 
for-loop over an object that represents a collection and already exposes 
__len__ and __getitem__.


To be specific, you don't even need __len__: it's just an optimization 
exploited internally by Python. It's sufficient to have __getitem__ and 
raises IndexError whenever the sequence is finished.




@Giovanni:

That seems to be exactly what I was after. I have a few questions about the
implementation though.

Since I do use the next() function as part of my C++ API i might just keep
my iteration the way it is currently. I use it to iterate similar to the
following code:

Item* Object::next()
{
  if(this->currentIndex < this->length) {
return item[this->currentIndex];
  } else {
return NULL;
  }
}

// In Code
Object* object = new Object;
Item* item;
while(item = object->next()) {
  // do something with item
}


I wouldn't call this a good design: your iteration actually does modify 
the object. So you can iterate onto the object only once (or you need a 
resetIteration function); the object is not thread-safe; etc.


Anyway, surely it's not what Python expects from the iteration function.


Oh!! So the %MethodCode doesn't require a partner C++ function? You can
specify python specific functions inside it??


Yes. Given the code you showed me, probably it's sufficient something 
like this in the sip file (pseudo-code, untest):



class Object
{

Item* __getitem__(int);
%MethodCode
if (a0 >= sipCpp->length)
{
   PyErr_SetNone(PyExc_IndexError);
   sipIsErr = 1;
}
else
{
   Item *item = sipCpp->items[a0];
   sipResult = sipConvertToInstance([...]);
}
%End
}

I'll let you find out the details of how to write the code. Refer to the 
SIP documentation.

--
Giovanni Bajo
Develer S.r.l.
http://www.develer.com
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] PyQt and 3D visualization

2008-08-06 Thread Pierre Raybaut
2008/8/6 Phil Thompson <[EMAIL PROTECTED]>:
> On Wed, 6 Aug 2008 11:11:52 +0200, "Pierre Raybaut" <[EMAIL PROTECTED]>
> wrote:
>> Hi Phil,
>>
>> As I probably already mentioned, I'm very interested in PyQt for
>> scientific GUI programming, i.e. GUI embedding classic widgets as well
>> as 2D and 3D plots.
>> Matplotlib + PyQt can help programming rapidly this kind of GUI.
>>
>> However, when it comes to 3D visualization, it seems that Enthought is
>> a step ahead with TVTK which is using wxPython - adding the missing
>> pythonic interface to VTK *and* ready-to-use widgets for visualization
>> purpose with Trait.
>>
>> I saw on Enthought code website that a Qt backend is being developed
>> for Trait (and I think that you are involved in this project).
>> (Q1) There is not much information on this, so I'm not sure I
>> understand correctly: do you know if this means that, for example, one
>> could use TVTK with a Qt backend?
>
> TVTK works fine with PyQt, though you may need the SVN version of VTK to
> get the latest PyQt support.

(sorry I forgot to answer to the mailing list in my previous message)

Ok, that's great news, and this answers to my second question as well.
But, I'm curious: do you know why no publicity is made around this?
Because this means that one could use the Enthought Tool Suite without
having to install wxPython, which would be great from my point of view
(I'm tired of including multiple libraries which can do the same thing
in my Python distribution).
And BTW, do you know how to use (/install) the Trait Qt backend
instead of the default wx backend? (if not, do you know where could I
find some help on this?)

Thanks
Pierre

>
> PyQt support in ETS is a subset of the wx support - bits are ported as
> required on a commercial basis.
>
>> Another related question:
>> (Q2) Is there a way to embend VTK objects in PyQt GUI without
>> reinventing the wheel, i.e. with features similar to those of TVTK
>> (basic tools that one could put in a toolbar: rotation, zoom,
>> projections, ...)?
>
> I don't know, I've never used VTK/TVTK myself.
>
> Phil
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] PyQt and 3D visualization

2008-08-06 Thread Phil Thompson
On Wed, 6 Aug 2008 11:11:52 +0200, "Pierre Raybaut" <[EMAIL PROTECTED]>
wrote:
> Hi Phil,
> 
> As I probably already mentioned, I'm very interested in PyQt for
> scientific GUI programming, i.e. GUI embedding classic widgets as well
> as 2D and 3D plots.
> Matplotlib + PyQt can help programming rapidly this kind of GUI.
> 
> However, when it comes to 3D visualization, it seems that Enthought is
> a step ahead with TVTK which is using wxPython - adding the missing
> pythonic interface to VTK *and* ready-to-use widgets for visualization
> purpose with Trait.
> 
> I saw on Enthought code website that a Qt backend is being developed
> for Trait (and I think that you are involved in this project).
> (Q1) There is not much information on this, so I'm not sure I
> understand correctly: do you know if this means that, for example, one
> could use TVTK with a Qt backend?

TVTK works fine with PyQt, though you may need the SVN version of VTK to
get the latest PyQt support.

PyQt support in ETS is a subset of the wx support - bits are ported as
required on a commercial basis.

> Another related question:
> (Q2) Is there a way to embend VTK objects in PyQt GUI without
> reinventing the wheel, i.e. with features similar to those of TVTK
> (basic tools that one could put in a toolbar: rotation, zoom,
> projections, ...)?

I don't know, I've never used VTK/TVTK myself.

Phil

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Installation problem on OSX

2008-08-06 Thread Pim Schellart

Hello everyone,

I am new to the list so please correct me if I ask my question in the  
wrong way.


Recently I installed the latest version of Qt (4.4.1) and the latest  
version of PqQt4 (4.4.2).
My python installation is from the scisoft package (ESO software  
bundle) version 2.5.1.

Installation of PqQt4 was done using a simple:

sudo python configure.py
(seemed to be necessary because without the sudo it complained about:
IOError: [Errno 13] Permission denied: 'qtdirs.pro')

followed by:
sudo make
sudo make install

This seemed to work.
But if I run the following from within python:

>>> import sys
>>> from PyQt4.QtGui import *

I get the following error:

Traceback (most recent call last):
  File "", line 1, in 
ImportError: dlopen(/scisoft/i386/library/Frameworks/Python.framework/ 
Versions/2.5/lib/python2.5/site-packages/PyQt4/QtGui.so, 2): Library  
not loaded: QtGui.framework/Versions/4/QtGui
  Referenced from: /scisoft/i386/library/Frameworks/Python.framework/ 
Versions/2.5/lib/python2.5/site-packages/PyQt4/QtGui.so

  Reason: image not found

At first I thought it might be the `library' with lower case because  
according to find my installation is located at:


/scisoft/i386/Packages/Python-2.5.1/Python.framework/Versions/2.5/lib/ 
python2.5/site-packages/PyQt4


/scisoft/i386/Packages/Python-2.5.1/Python.framework/Versions/2.5/ 
share/sip/PyQt4


/scisoft/i386/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/site-packages/PyQt4/


So I tried changing `library' to `Library' in pyqtconfig.py and  
Makefile (after configure.py) but this did not solve the problem.


Does anyone have a clue what is going wrong?

Kind regards,

Pim Schellart

smime.p7s
Description: S/MIME cryptographic signature
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] dll problem

2008-08-06 Thread Nescio Nomen
I recently ran into a dll problem and couldn't run any of my scripts.  I
checked C:\Program Files\MiKTeX 2.7\miktex\bin and I can see QtCore4 and
QtGui4.dll.  I already have these two DLLs (though possibly different
versions) in C:\Program Files\Python25\PyQt4\bin.  I am sure it is MikTex's
fault because I went to the system variables and removed the aforementioned
path from the "Path" system variable and then my scripts worked.  Is there
any way for me to fix this problem without removing MikTeX from Path (which
presumably might break something)?  I realize this is not directly related
to PyQt but I am hoping someone can help.  Thanks.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Pyuic4 QScrollArea missing setWidget()

2008-08-06 Thread Phil Thompson
On Wed, 06 Aug 2008 10:41:44 +0200, Jan Kaluza <[EMAIL PROTECTED]> wrote:
> Hello all,
> I've just found bug in Pyuic4 4.4.2. When I create QScrollArea called 
> Form and put some widget into it, then Pyuic4 generates code without 
> self.Form.setWidget(self.scrollAreaWidgetContents). This causes that 
> widget in QScrollArea Form is not resized properly (It has only 
> QScrollArea as parent).
> 
> Thanks for answer
> Jan Kaluza

Have you tried the current snapshot?

Phil

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] PyQt and 3D visualization

2008-08-06 Thread Pierre Raybaut
Hi Phil,

As I probably already mentioned, I'm very interested in PyQt for
scientific GUI programming, i.e. GUI embedding classic widgets as well
as 2D and 3D plots.
Matplotlib + PyQt can help programming rapidly this kind of GUI.

However, when it comes to 3D visualization, it seems that Enthought is
a step ahead with TVTK which is using wxPython - adding the missing
pythonic interface to VTK *and* ready-to-use widgets for visualization
purpose with Trait.

I saw on Enthought code website that a Qt backend is being developed
for Trait (and I think that you are involved in this project).
(Q1) There is not much information on this, so I'm not sure I
understand correctly: do you know if this means that, for example, one
could use TVTK with a Qt backend?

Another related question:
(Q2) Is there a way to embend VTK objects in PyQt GUI without
reinventing the wheel, i.e. with features similar to those of TVTK
(basic tools that one could put in a toolbar: rotation, zoom,
projections, ...)?

Thanks for your help,
Regards,
Pierre Raybaut
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Pyuic4 QScrollArea missing setWidget()

2008-08-06 Thread Jan Kaluza

Hello all,
I've just found bug in Pyuic4 4.4.2. When I create QScrollArea called 
Form and put some widget into it, then Pyuic4 generates code without 
self.Form.setWidget(self.scrollAreaWidgetContents). This causes that 
widget in QScrollArea Form is not resized properly (It has only 
QScrollArea as parent).


Thanks for answer
Jan Kaluza

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] SIP - %Exception for StopIteration

2008-08-06 Thread Phil Thompson
On Tue, 5 Aug 2008 22:23:31 -0700, "Jonny Morrill" <[EMAIL PROTECTED]>
wrote:
> Thank you both for your help!!
> 
> @Matt:
> 
> WOW! I never new that you could create an iterable object from only the
> __len__ and operator[] functions!! I must have missed that when I was
> searching through the python documentation for iterator objects. It is
not
> clear to me which is quicker, the only difference seems to be that when
> you
> use __iter__, you can return a copy of the object so that any
> modifications
> will not affect the original object. Thanks again!
> 
> @Giovanni:
> 
> That seems to be exactly what I was after. I have a few questions about
> the
> implementation though.
> 
> Since I do use the next() function as part of my C++ API i might just
keep
> my iteration the way it is currently. I use it to iterate similar to the
> following code:
> 
> Item* Object::next()
> {
>   if(this->currentIndex < this->length) {
> return item[this->currentIndex];
>   } else {
> return NULL;
>   }
> }
> 
> // In Code
> Object* object = new Object;
> Item* item;
> while(item = object->next()) {
>   // do something with item
> }
> 
> Oh!! So the %MethodCode doesn't require a partner C++ function? You can
> specify python specific functions inside it??

[snip]

Most people probably don't realise it but you can use SIP to write new
C/C++ extension modules (as opposed to wrapping an external library). SIP
will handle all the boilerplate code, module initialisation, argument and
return value marshaling etc. You just provide the "meat" of what you want
the module to do as %MethodCode.

Phil

Phil

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt