Re: [PyQt] Python wrappers for QML/ Qt Quick?

2010-03-09 Thread Ville M. Vainio
On Mon, Mar 8, 2010 at 4:50 PM, Attila Csipa p...@csipa.in.rs wrote:

 Note that QML itself will be part of mainline Qt4.7, so I guess it's just a
 question of time (read: Phil's schedule :) until a bit more 'official'
 support for QML + PyQt appears.

There is a bit more to think about than just wrapping Qml* classes;
there are multiple interesting paths for creating QML + Python apps.

For one, it should be possible to avoid loading the PyQt libs
altogether (in the interest of smaller footprint  faster launch) -
just create a C++ application like qmlviewer, and embed python
interpreter to that. All the Qt facing code would be on the javascript
side, and the javascript code would be able to access the embedded
python interpreter through some exposed stubs. In the first phase,
even being able to exec/eval strings would get you started.

-- 
Ville M. Vainio
http://tinyurl.com/vainio
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Using new-style connections with QSignalMapper

2010-03-09 Thread Phil Thompson
On Mon, 08 Mar 2010 17:29:48 -0500, Mark Visser ma...@lumierevfx.com
wrote:
 Is there some reason new-style connection from any signal to 
 QSignalMapper.map do not appear to work?
 
 Using old-style self.connect works, i.e.:
 |
 #self.connect(self.b1, SIGNAL(clicked()),
 # self.mapper, SLOT(map()))
 #self.connect(self.b2, SIGNAL(clicked()),
 # self.mapper, SLOT(map()))
 |
 But using new-style self.signal.connect does not:
 
 |||self.b1.clicked.connect(self.mapper.map)
 self.b2.clicked.connect(self.mapper.map)
 |
 Here's a complete example:|
 =
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
 app = QApplication([])
 
 class Test(QWidget):
 def __init__(self, parent=None):
 super(Test, self).__init__(parent)
 layout = QVBoxLayout()

 self.b1 = QPushButton(B1)
 self.b2 = QPushButton(B2)
 
 layout.addWidget(self.b1)
 layout.addWidget(self.b2)
 
 self.setLayout(layout)
 
 self.mapper = QSignalMapper(self)
 
 self.mapper.setMapping(self.b1, B1)
 self.mapper.setMapping(self.b2, B2)
 
 self.b1.clicked.connect(self.mapper.map)
 self.b2.clicked.connect(self.mapper.map)
 
 #self.connect(self.b1, SIGNAL(clicked()),
 # self.mapper, SLOT(map()))
 #self.connect(self.b2, SIGNAL(clicked()),
 # self.mapper, SLOT(map()))
 
 self.mapper.mapped[QString].connect(self.sayIt)
 
 @pyqtSlot(QString)
 def sayIt(self, name):
 print name

 
 t = Test()
 
 t.show()
 
 app.exec_()
 ||=|

It's actually a problem with QSignalMapper.map() being called from a proxy
rather than new-style connections.

The workaround is to explicitly specify a signal that is compatible with
map()...

self.b1.clicked[()].connect(self.mapper.map)

Tonight's PyQt snapshot will be smarter about finding a usable Qt slot
before deciding that it needs to use a proxy so that the workaround won't
be necessary.

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


Re: [PyQt] Python wrappers for QML/ Qt Quick?

2010-03-09 Thread Ville M. Vainio
On Tue, Mar 9, 2010 at 2:07 PM, Giovanni Bajo ra...@develer.com wrote:

 It might make more sense to have a way to export PyQt classes to QML, that
 is implement QMLElement in Python rather than in C++, and make them
 available to QML itself.

This is pretty much what I'm thinking of. Python would take the part
of C++ here, not Javascript.

-- 
Ville M. Vainio
http://tinyurl.com/vainio
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Best way to implement an Image Viewer?

2010-03-09 Thread TP
I'm using Windows XP, Python 2.6.4, and PyQt 4.7.1.

While trying out the example
C:\Python26\Lib\site-packages\PyQt4\examples\widgets\imageviewer.pyw,
I notice that the more I zoom into an 1553x2653 BW PNG image, the
longer it takes to display. This becomes unacceptably long (on the
order of a few seconds) at the not so high 3x zoom factor.

Intuitively, I would have thought it would be *faster* since the more
I zoom in the fewer image pixels need to be displayed. I think what's
happening is the entire QLabel widget is getting enlarged then
cropped, rather than just displaying a sub-portion of the image:

def scaleImage(self, factor):
self.scaleFactor *= factor
self.imageLabel.resize(self.scaleFactor *
self.imageLabel.pixmap().size())

I want to create an app to help people explore various image
processing operations. Fast  flexible image display is essential.

Some features I like to have:

* Zoom In/Out quickly. I can see zooming *out* being slower since more
  image pixels would be involved. Once past the 1x zoom-in factor, I'd
  rather have the pixels as raw as possible to avoid blurring edges
  like the Image Viewer example currently does.

* Compare transformations by having multiple views of images that are
  synchronized as to pan position and zoom factor. Dragging the mouse
  in any of the views should pan all the views.

* Multi-screen support.

I started off by modifying the PyQt4 Image Viewer example, but now I'm
having second thoughts. Should I really be basing my Image Viewer on a
QLabel?

Should I instead be using a QGraphicsView (even though I'll probably
only have a single image, not lots of 2D objects)?

Maybe I should use a QGLWidget (I'd rather not).

Or perhaps I have to write my own custom widget and draw using a
QPainter object?

Any tips or pointers to other PyQt-based Image Viewers would be
appreciated.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Python wrappers for QML/ Qt Quick?

2010-03-09 Thread Giovanni Bajo

On 3/9/2010 11:37 AM, Ville M. Vainio wrote:

On Mon, Mar 8, 2010 at 4:50 PM, Attila Csipap...@csipa.in.rs  wrote:


Note that QML itself will be part of mainline Qt4.7, so I guess it's just a
question of time (read: Phil's schedule :) until a bit more 'official'
support for QML + PyQt appears.


There is a bit more to think about than just wrapping Qml* classes;
there are multiple interesting paths for creating QML + Python apps.

For one, it should be possible to avoid loading the PyQt libs
altogether (in the interest of smaller footprint  faster launch) -
just create a C++ application like qmlviewer, and embed python
interpreter to that. All the Qt facing code would be on the javascript
side, and the javascript code would be able to access the embedded
python interpreter through some exposed stubs. In the first phase,
even being able to exec/eval strings would get you started.


I personally don't see a good use case for putting Python somehow within 
QML. QML already comes with its scripting language and bindings 
(Javascript), so unless you are on a religion war, I don't see much 
sense in putting Python in there.


It might make more sense to have a way to export PyQt classes to QML, 
that is implement QMLElement in Python rather than in C++, and make them 
available to QML itself.

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


Re: [PyQt] Best way to implement an Image Viewer?

2010-03-09 Thread Vincent Vande Vyvre
TP a écrit :
 I'm using Windows XP, Python 2.6.4, and PyQt 4.7.1.

 While trying out the example
 C:\Python26\Lib\site-packages\PyQt4\examples\widgets\imageviewer.pyw,
 I notice that the more I zoom into an 1553x2653 BW PNG image, the
 longer it takes to display. This becomes unacceptably long (on the
 order of a few seconds) at the not so high 3x zoom factor.

 Intuitively, I would have thought it would be *faster* since the more
 I zoom in the fewer image pixels need to be displayed. I think what's
 happening is the entire QLabel widget is getting enlarged then
 cropped, rather than just displaying a sub-portion of the image:

 def scaleImage(self, factor):
 self.scaleFactor *= factor
 self.imageLabel.resize(self.scaleFactor *
 self.imageLabel.pixmap().size())

 I want to create an app to help people explore various image
 processing operations. Fast  flexible image display is essential.

 Some features I like to have:

 * Zoom In/Out quickly. I can see zooming *out* being slower since more
   image pixels would be involved. Once past the 1x zoom-in factor, I'd
   rather have the pixels as raw as possible to avoid blurring edges
   like the Image Viewer example currently does.

 * Compare transformations by having multiple views of images that are
   synchronized as to pan position and zoom factor. Dragging the mouse
   in any of the views should pan all the views.

 * Multi-screen support.

 I started off by modifying the PyQt4 Image Viewer example, but now I'm
 having second thoughts. Should I really be basing my Image Viewer on a
 QLabel?

 Should I instead be using a QGraphicsView (even though I'll probably
 only have a single image, not lots of 2D objects)?

 Maybe I should use a QGLWidget (I'd rather not).

 Or perhaps I have to write my own custom widget and draw using a
 QPainter object?

 Any tips or pointers to other PyQt-based Image Viewers would be
 appreciated.
 ___
 PyQt mailing listPyQt@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt

   
See attachement, it's an images viewer + zoom with QGraphicScene.

Before use, change the line 63

Vincent
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Example of an image viewer with zoom
#
# Created: Thu Feb 25 19:54:49 2010
#  by: PyQt4 UI code generator 4.4.4
#
# Author: Vincent Vande Vyvre v...@swing.be
#
# Note: before use, change the line 63

import os
import time
import glob

from PyQt4 import QtCore, QtGui

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.resize(900, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.gridLayout = QtGui.QGridLayout(self.centralwidget)
self.verticalLayout = QtGui.QVBoxLayout()
self.scene = QtGui.QGraphicsScene()
self.view = QtGui.QGraphicsView(self.scene)
self.verticalLayout.addWidget(self.view)
self.horizontalLayout = QtGui.QHBoxLayout()
spacerItem = QtGui.QSpacerItem(150, 20, QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.toolButton_3 = QtGui.QToolButton(self.centralwidget)
self.toolButton_3.setIconSize(QtCore.QSize(48, 24))
self.toolButton_3.setText(Previous)
self.horizontalLayout.addWidget(self.toolButton_3)
self.toolButton_4 = QtGui.QToolButton(self.centralwidget)
self.toolButton_4.setIconSize(QtCore.QSize(48, 24))
self.toolButton_4.setText(Next)
self.horizontalLayout.addWidget(self.toolButton_4)
spacerItem1 = QtGui.QSpacerItem(100, 20, QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.toolButton_6 = QtGui.QToolButton(self.centralwidget)
self.toolButton_6.setText(Quit)
self.horizontalLayout.addWidget(self.toolButton_6)
self.verticalLayout.addLayout(self.horizontalLayout)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
MainWindow.setWindowTitle(speedyView)
MainWindow.show()
QtCore.QCoreApplication.processEvents()

QtCore.QObject.connect(ui.toolButton_3, QtCore.SIGNAL(clicked()), self.prec)
QtCore.QObject.connect(ui.toolButton_4, QtCore.SIGNAL(clicked()), self.next)
QtCore.QObject.connect(ui.toolButton_6, QtCore.SIGNAL(clicked()), exit)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

self.centralwidget.wheelEvent = self.wheel_event

self.set_view()

def set_view(self):
in_folder = /folder/with/images/
chain = in_folder + /*
self.images = glob.glob(chain)
self.images.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
self.zoom_step = 0.04
self.w_vsize = self.view.size().width()
self.h_vsize = 

Re: [PyQt] Python wrappers for QML/ Qt Quick?

2010-03-09 Thread Attila Csipa
On Tuesday 09 March 2010 15:54:54 Ville M. Vainio wrote:
 On Tue, Mar 9, 2010 at 2:07 PM, Giovanni Bajo ra...@develer.com wrote:
  It might make more sense to have a way to export PyQt classes to QML,
  that is implement QMLElement in Python rather than in C++, and make them
  available to QML itself.

 This is pretty much what I'm thinking of. Python would take the part
 of C++ here, not Javascript.

If I understand correctly what you want to do, it has little to do with PyQt, 
it would be more of a PyQML custom binding... Which is interesting, but sounds 
like quite a niche to me - it will be hard to avoid Qt parts, and at that 
point it's much easier to go via the 'main' PyQt path. But, I'm no QML expert 
(yet :), so take this with a grain of salt, I don't intend to discourage 
anyone. What might be related, but I also don't know enough about, is what the 
current state of QtScript is. Is currently it possible to operate on Python 
objects from QtScript ? 'Cause if it is, QML should not be far off.

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


Re: [PyQt] Python wrappers for QML/ Qt Quick?

2010-03-09 Thread Giovanni Bajo
On Tue, 2010-03-09 at 19:57 +0100, Attila Csipa wrote:
 On Tuesday 09 March 2010 15:54:54 Ville M. Vainio wrote:
  On Tue, Mar 9, 2010 at 2:07 PM, Giovanni Bajo ra...@develer.com wrote:
   It might make more sense to have a way to export PyQt classes to QML,
   that is implement QMLElement in Python rather than in C++, and make them
   available to QML itself.
 
  This is pretty much what I'm thinking of. Python would take the part
  of C++ here, not Javascript.
 
 If I understand correctly what you want to do, it has little to do with PyQt, 
 it would be more of a PyQML custom binding... Which is interesting, but 
 sounds 
 like quite a niche to me - it will be hard to avoid Qt parts, and at that 
 point it's much easier to go via the 'main' PyQt path. But, I'm no QML expert 
 (yet :), so take this with a grain of salt, I don't intend to discourage 
 anyone. What might be related, but I also don't know enough about, is what 
 the 
 current state of QtScript is. Is currently it possible to operate on Python 
 objects from QtScript ? 'Cause if it is, QML should not be far off.

Your two examples are unrelated.

QtScript creates an automatic binding between Javascript and C++ using
QObject introspection features. Thus, if you create a Python QObject,
explicitly define signals/slots/properties at the QMetaObject level
through PyQt decorators, the resulting object will be accessible from
QtScript, with QtScript totally ignoring it is a Python object under the
hood.

For a C++ object to be exported to QML, on the other hand, you need an
additional set of meta-definitions which are currently unavailable from
Python. I'm not even sure if those meta-definitions resolves to
*runtime* data that can be dynamically build, as it would be required by
PyQt. Surely, there is more work to be done on the PyQt side.

-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com


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


[PyQt] Style sheet properties..

2010-03-09 Thread Jebagnana Das
Hello all,

If i apply a property to a parent widget it is automatically applied for
child widgets too.. Is there any way of preventing this??

For example if i set background color as white in a dialog then any
button,combo boxes and scroll bars(within the dialog) looks white and it
lacks it's native look(have to say it's unpleasant to the eyes(esp. in unix)
 ugly).. Is there any way that i can apply the stylesheets only to a parent
widget not to it's children? can i exclude specifically some child widgets
from not inheriting parent SS properties??
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] VTK in PyQt

2010-03-09 Thread Bastian Weber
Gib Bogle wrote:
 Gib Bogle wrote:
 OK, I located QVTKRenderWindowInteractor.py.  I'll see if I can figure
 out how to use it.
 
 Not much success here. 

Maybe you want to check the source code of

http://sourceforge.net/projects/pymbs/

Its a python Multibody modelling tool width some visualization
facilities based on qt4 and VTK. (in the 'Graphics' package)

Regards,
Bastian.




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


Re: [PyQt] QTreeWidget setItemWidget dissapears after drag drop

2010-03-09 Thread Taylor Carrasco
Any idea how to keep the setItemWidget() after it's reparented ?
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] VTK in PyQt

2010-03-09 Thread Matt Smith
I looked through the code and two things I see different than what I
have:

a. I set the size of my RenderWindow
b. I keep a reference to it, which probably isn't your problem because
your not getting a seg fault.

I've got an example but I can't verify that it works since I don't have
vtk installed atm.

mbs

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


Re: [PyQt] Best way to implement an Image Viewer?

2010-03-09 Thread Vincent Vande Vyvre




TP a crit:

  On Tue, Mar 9, 2010 at 3:54 PM, TP wing...@gmail.com wrote:
  
  
On Tue, Mar 9, 2010 at 9:27 AM, Vincent Vande Vyvre
vincent.vandevy...@swing.be wrote:


  TP a crit :
  
  
I'm using Windows XP, Python 2.6.4, and PyQt 4.7.1.

While trying out the example
C:\Python26\Lib\site-packages\PyQt4\examples\widgets\imageviewer.pyw,
I notice that the more I zoom into an 1553x2653 BW PNG image, the
longer it takes to display. This becomes unacceptably long (on the
order of a few seconds) at the not so high 3x zoom factor.

Intuitively, I would have thought it would be *faster* since the more
I zoom in the fewer image pixels need to be displayed. I think what's
happening is the entire QLabel widget is getting enlarged then
cropped, rather than just displaying a sub-portion of the image:

  def scaleImage(self, factor):
self.scaleFactor *= factor
self.imageLabel.resize(self.scaleFactor *
self.imageLabel.pixmap().size())

I want to create an app to help people explore various image
processing operations. Fast  flexible image display is essential.

Some features I like to have:

* Zoom In/Out quickly. I can see zooming *out* being slower since more
 image pixels would be involved. Once past the 1x zoom-in factor, I'd
 rather have the pixels as raw as possible to avoid blurring edges
 like the Image Viewer example currently does.

* Compare transformations by having multiple views of images that are
 synchronized as to pan position and zoom factor. Dragging the mouse
 in any of the views should pan all the views.

* Multi-screen support.

I started off by modifying the PyQt4 Image Viewer example, but now I'm
having second thoughts. Should I really be basing my Image Viewer on a
QLabel?

Should I instead be using a QGraphicsView (even though I'll probably
only have a single image, not lots of 2D objects)?

Maybe I should use a QGLWidget (I'd rather not).

Or perhaps I have to write my own custom widget and draw using a
QPainter object?

Any tips or pointers to other PyQt-based Image Viewers would be
appreciated.
___
PyQt mailing list  PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt



  
  See attachement, it's an images viewer + zoom with QGraphicScene.

Before use, change the line 63

Vincent

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

  

Thank you. Your example does indeed zoom in/out quickly.

However, delving into it I see it basically doing something like this:

scaledPixmap = pixmap.scaled(newWidth, newHeight,
  QtCore.Qt.KeepAspectRatio,
  QtCore.Qt.FastTransformation)
self.scene.clear()
self.scene.setSceneRect(0, 0, newWidth, newHeight)
self.scene.addPixmap(scaledPixmap)

And if I change QtCore.Qt.FastTransformation to
QtCore.Qt.SmoothTransformation things become as slow as using a
QLabel.

It seems to me that doing things this way completely ignores the
advantage of using a QGraphicsScene? Instead of scaling (and therefore
recreating the Pixmap), one should presumably use the QGraphicsScene scale() and
translate() methods.

Anyway, my original question remains. Is the best approach to use a
QGraphicsView or one of the other options previously mentioned?

  

Yes, it is ...for me

  


  
  
Ooops. I meant to say:

 Instead of scaling (and therefore recreating the Pixmap), one should
 presumably use the QGraphicsView scale() and translate() methods.

  

If you resize the current view the degradation is exponantial.
If you like mosaics ...

It's necessary to re-create the view from the original for each step of
zoom.

For your second idea, you can change the function like this:

 def zoom(self, step):
 w = (1 + self.zoom_step*step)
 self.view.scale(w, w)

and see the result.
All the areas with hight contrast are in staircase.

I don't say my method is the best way, but is a good compromise between
speed and quality.

Vincent



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