Re: [PyQt] Calling slots in a QThread?

2009-08-12 Thread Lukas Hetzenecker
But If I call long-running funtions in a run() method everything works as 
expected.
I want to call such functions also from outside (using a signal-slot-
connection from another thread).

Am Mittwoch 12 August 2009 20:26:38 schrieb Arnold Krille:
> Hi,
>
> On Wednesday 12 August 2009 19:04:46 Lukas Hetzenecker wrote:
> > is it possible to connect signals from a Widget to a slot in a QThread
> > and ensure that the Widget responds to keypress and mouse events?
> > I attached my first try, but it doesn't work, the UI blocks until the
> > execution of the function is finished.
>
> Without looking at the code: This is not a problem with Qt but with python.
> The keyword is GIL, the global interpreter lock which ensures that only one
> thread is executing python in this runtime instance.
>
> There are two ways to have "true" threads:
> 1) Implement the thread in C++ and bridge it to python with SIP the same
> way Qt is bridged to python.

I want to use python modules in the thread so I don't think that this would 
work.

> 2) Use processes instead of threads. Then you can run several instances of
> the python interpreter at the same time.

This seems too complicated for this simple task.

> Arnold

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


Re: [PyQt] Collapse/expand frame

2009-08-12 Thread Hans-Peter Jansen
Am Mittwoch, 12. August 2009 schrieb Scott Ballard:
> Does anyone know of a way to collapse/expand a frame or a group box that
> contains widgets in it? I don't see anything in the docs or Google about
> it, but it would seem like something common.

Try .hide()/.show() resp. .setVisible(bool)

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


[PyQt] Collapse/expand frame

2009-08-12 Thread Scott Ballard
Does anyone know of a way to collapse/expand a frame or a group box that 
contains widgets in it? I don't see anything in the docs or Google about 
it, but it would seem like something common.


Cheers,
-Scott


__ Information from ESET NOD32 Antivirus, version of virus signature 
database 4330 (20090812) __

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


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


Re: [PyQt] Calling slots in a QThread?

2009-08-12 Thread Arnold Krille
Hi,

On Wednesday 12 August 2009 19:04:46 Lukas Hetzenecker wrote:
> is it possible to connect signals from a Widget to a slot in a QThread and
> ensure that the Widget responds to keypress and mouse events?
> I attached my first try, but it doesn't work, the UI blocks until the
> execution of the function is finished.

Without looking at the code: This is not a problem with Qt but with python. 
The keyword is GIL, the global interpreter lock which ensures that only one 
thread is executing python in this runtime instance.

There are two ways to have "true" threads:
1) Implement the thread in C++ and bridge it to python with SIP the same way 
Qt is bridged to python.
2) Use processes instead of threads. Then you can run several instances of the 
python interpreter at the same time.

Arnold


signature.asc
Description: This is a digitally signed message part.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Calling slots in a QThread?

2009-08-12 Thread Lukas Hetzenecker
Hello,

is it possible to connect signals from a Widget to a slot in a QThread and 
ensure that the Widget responds to keypress and mouse events?

I attached my first try, but it doesn't work, the UI blocks until the execution 
of the function is finished.

Thanks for your help,
Lukas
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Main(QWidget):
def __init__(self,  parent=None):
super(Main,  self).__init__(parent)

# Some widgets to check if the Widget responds to keypress events
layout = QVBoxLayout()
btn1 = QPushButton("Push me...",  self)
txt1 = QTextEdit(self)
lin1 = QLineEdit(self)
btn2 = QPushButton("Just testing...",  self)

layout.addWidget(btn1)
layout.addWidget(txt1)
layout.addWidget(lin1)
layout.addWidget(btn2)

self.setLayout(layout)

self.thread = Thread()
self.thread.start()

self.connect(btn1,  SIGNAL("clicked()"),  self.thread,  SLOT("long()"))

class Thread(QThread):
def __init__(self,  parent=None):
super(Thread,  self).__init__(parent)

def run(self):
# Short running method
time.sleep(1)
self.long()
self.exec_()

@pyqtSignature("")
def long(self):
print "Is Thread still running?",  self.isRunning()
print "starting long running function..."
time.sleep(4)
print "ending long running function..."

if __name__ == "__main__":
app = QApplication([])
main = Main()
main.show()
app.exec_()
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] problem with createEditor method of QItemDelegate

2009-08-12 Thread TP
Hi,

Try the example at the end of this message: it is a table with editable
items. This is a modified version of the example "spinboxdelegate.py" of
the PyQt examples ("itemviews" section). When the user double-clicks on an
item, a LabelAndSpinBox instance is created as delegate. The problem is
that the QHBoxLayout layout of this delegate does not expand to occupy all
the available space; therefore the item data value remains visible and the
delegates is too small. How to make it work correctly?

Thanks,

Julien

PS1: this is a simple example, but in a more elaborated version, the
delegate does not appear at all when the user double clicks. It is
displayed correctly if no parent is given (it appears in a separate
window), but when defining a parent (the "QWidget * parent" given to
createEditor) as parent of the delegate, it does not appear at all.
Perhaps solving the size problem on the simple example below will solve the
problem in this more elaborated version.

PS2:
>>> qVersion()
'4.4.0'
>>> PYQT_VERSION_STR
'4.4.4'


###
#!/usr/bin/env python

import sys
from PyQt4 import QtCore, QtGui


class LabelAndSpinBox( QtGui.QWidget ):

def __init__( self, parent ):

super( LabelAndSpinBox, self ).__init__( parent )

qh = QtGui.QHBoxLayout( self )
self.qlabel = QtGui.QLabel()
self.qlabel.setText( "foobar" )
qh.addWidget( self.qlabel )

self.qspinbox = QtGui.QSpinBox()
self.qspinbox.setValue( 0 )
qh.addWidget( self.qspinbox )

self.toolbutton = QtGui.QToolButton()
qh.addWidget( self.toolbutton )

self.setLayout( qh )


def setMinimum( self, value ):

self.qspinbox.setMinimum( value )


def setMaximum( self, value ):

self.qspinbox.setMaximum( value )


def setValue( self, value ):

self.qspinbox.setValue( value )


def value( self ):

return self.qspinbox.value()





class SpinBoxDelegate(QtGui.QItemDelegate):

def __init__(self, parent = None):

QtGui.QItemDelegate.__init__(self, parent)

def createEditor(self, parent, option, index):

editor = LabelAndSpinBox( parent )
editor.setMinimum( 0 )
editor.setMaximum( 100 )
# editor.installEventFilter(self)
return editor

def setEditorData( self, spinBox, index ):

value, ok = index.model().data(index, QtCore.Qt.DisplayRole).toInt()
spinBox.setValue(value)

def setModelData(self, editor, model, index):

value = editor.value()
model.setData( index
, QtCore.QVariant( value ) )

def updateEditorGeometry( self, editor, option, index ):

editor.setGeometry(option.rect)


if __name__ == "__main__":

app = QtGui.QApplication(sys.argv)

model = QtGui.QStandardItemModel(4, 2)
tableView = QtGui.QTableView()
tableView.setModel(model)

delegate = SpinBoxDelegate()
tableView.setItemDelegate(delegate)

for row in range(4):
for column in range(2):
index = model.index(row, column, QtCore.QModelIndex())
model.setData(index, QtCore.QVariant((row+1) * (column+1)))

tableView.setWindowTitle("Spin Box Delegate")
tableView.show()
sys.exit(app.exec_())
###

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)

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


Re: [PyQt] Accessing the underlying Qt object in a C-API extension.

2009-08-12 Thread Phil Thompson
On Wed, 12 Aug 2009 07:34:13 -0700, Christian Caron 
wrote:
> Hi All,
> 
> First things first: I think PyQt is awesome. Now onto the question.
> 
> I sometimes have small pieces of code that I would like to speed up  
> using a C-API extension.
> I'd like to be able to pass PyQt objects to an extension, and once  
> inside dig up the internal Qt pointer...
> 
> Is this a difficult (or possible at all) thing to do?
> 
> I looked through the archives before posting but failed to find  
> something relevant.
> 
> Sample code would be great.

Write your C++ extension as a library - just like one of the Qt libraries.

Write SIP bindings for your library - just like the PyQt modules.

Your C++ doesn't need to be aware of Python at all, the SIP generated code
will take care of all that.

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


[PyQt] Accessing the underlying Qt object in a C-API extension.

2009-08-12 Thread Christian Caron

Hi All,

First things first: I think PyQt is awesome. Now onto the question.

I sometimes have small pieces of code that I would like to speed up  
using a C-API extension.
I'd like to be able to pass PyQt objects to an extension, and once  
inside dig up the internal Qt pointer...


Is this a difficult (or possible at all) thing to do?

I looked through the archives before posting but failed to find  
something relevant.


Sample code would be great.

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


Re: [PyQt] Configure write incorrect qt path in Makefile

2009-08-12 Thread Alexandr N Zamaraev

Alexandr N Zamaraev wrote:

P.S. My Environment:

PyQt 4.5.4

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


Re: [PyQt] PyQt v4.6 and SIP v4.9 Snapshots

2009-08-12 Thread Phil Thompson
On Wed, 12 Aug 2009 10:16:30 +0200, Detlev Offenbach
 wrote:
> Hi,
> 
> what would be the best method to convert a bigger application like eric4
to
> 
> the new QString API? Is there a tool available doing a scan and 
> highlighting/converting incompatible API calls? Please give some hints.

Assuming you are doing it as part of a planned move to Python v3 (otherwise
I can't see the point)...

- Eliminate all calls to QString() and QStringList(). PyQt will always do
the right thing when given a string or a list instead.

- Deal with calling the very small number of Qt calls that make use of the
mutability of QStrings. These are described in the PyQt documentation in
the section covering the QString v2 API. Most are related to QValidator.

- That leaves Qt calls that return QStrings and QStringLists where, for
example, you might be calling toLower() on a result rather than lower().
There's not a lot that can be done to fix these apart from looking at the
source and fixing exceptions as they arise.

Mark Summerfield's advice to convert to Python types as early as possible
and to convert to Qt types as late as possible (or always let PyQt do it
for you) is very relevant.

Generally there is a lot that can be done in terms of preparation before
actually switching to the new API. In making sure the PyQt examples worked
under both Python v2 and v3, once I'd followed Mark's advice there were
relatively few cases where it actually mattered which QString API was
enabled.

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


[PyQt] Configure write incorrect qt path in Makefile

2009-08-12 Thread Alexandr N Zamaraev

I use several versions and builds of Qt.
Switch them via symlink.
Bat after configure PyQt some Qt path in Makefile has mixin slash:
	@if not exist C:/Lang/qt/qt4.5.2\qsci\api\python mkdir 
C:/Lang/qt/qt4.5.2\qsci\api\python

copy /y PyQt4.api C:/Lang/qt/qt4.5.2\qsci\api\python\PyQt4.api
You may need to call os.path.normpath for each path obtained in 
get_qt_configuration?


P.S. My Environment:
OS Windows Vista Home Basic Ru + sp2
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit 
(Intel)] on win32

Qt 4.5.2 (self build)
mingw32 g++ (GCC) 4.4.0
GNU ld (GNU Binutils) 2.19
mingwrt 3.15.2
w32api 3.13

P.P.S. Path for configure.py:
diff -r 73820d292c75 configure.py
--- a/configure.py  Mon Aug 10 12:18:36 2009 +0700
+++ b/configure.py  Wed Aug 12 15:44:39 2009 +0700
@@ -35,6 +35,7 @@

 import sys
 import os
+import os.path
 import glob
 import optparse
 import shutil
@@ -1768,12 +1769,12 @@
 global qt_dir, qt_incdir, qt_libdir, qt_bindir, qt_datadir, 
qt_pluginsdir

 global qt_version, qt_edition, qt_licensee, qt_shared, qt_xfeatures

-qt_dir = lines[0]
-qt_incdir = lines[1]
-qt_libdir = lines[2]
-qt_bindir = lines[3]
-qt_datadir = lines[4]
-qt_pluginsdir = lines[5]
+qt_dir = os.path.normpath(lines[0])
+qt_incdir = os.path.normpath(lines[1])
+qt_libdir = os.path.normpath(lines[2])
+qt_bindir = os.path.normpath(lines[3])
+qt_datadir = os.path.normpath(lines[4])
+qt_pluginsdir = os.path.normpath(lines[5])
 qt_version = lines[6]
 qt_edition = lines[7]
 qt_licensee = lines[8]
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] eric4 survey

2009-08-12 Thread Detlev Offenbach
Hi,

who is using eric4 with KDE style dialogs? If this feature is not used very 
often, I would like to remove it to clean up the code.

Regards,
Detlev
-- 
Detlev Offenbach
det...@die-offenbachs.de
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] inheriting from QObject and dbus.service.Object

2009-08-12 Thread Phil Thompson
On Wed, 12 Aug 2009 10:05:26 +0200, Marcos Dione 
wrote:
> On Tue, Aug 11, 2009 at 09:21:37AM +0100, Phil Thompson wrote:
>> On Tue, 11 Aug 2009 07:54:35 +0200, Marcos Dione 
>> wrote:
>> > In [8]: class A (dbus.service.Object, QObject): pass
>> > TypeError: Error when calling the metaclass bases
>> > metaclass conflict: the metaclass of a derived class must be a
>> > (non-strict)
>> > subclass of the metaclasses of all its bases
>> > 
>> > is it possible to inherit from both? or will I have to make
another
>> > class
>> > for this?
>> 
>> You can't inherit from both for the reason given. I don't know enough
>> about
>> DBus to know what the best solution is.
> 
> ok, let me put it this way. does PyQt build any metaclass for the
> QObject
> class or any other class which it might inherit from? I tried to figure
> this 
> out from the source but between sip and the generated code they managed
to 
> confuse me enough to ask for help :) if not, I'll try to play with it a
> little 
> more, and if i fail, just create another class as a wrapper.

PyQt defines its own metaclass (as "print type(QObject)" demonstrates).

It's a fundamental problem with Python's implementation that you get
meta-class conflicts that prevent you using multiple inheritance when you
might want to. It would be nice to be able to (somehow) specify multiple
meta-class calls in a similar way that a derived class's __init__
explicitly calls the __init__ of each of its super-classes.

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


[PyQt] Debugging SIP wrapped C++ code with Visual Studio 2008

2009-08-12 Thread magnus . benjes

Hi,
does somebody know how to debug SIP wrapped C++ code with Visual Studio  
2008?


I have build a custom QWidget in C++ and wrapped it with SIP. I use this  
widget from Python with PyQt. I have figured out, that I need python_d.lib  
to compile the widget in debug mode and how to create python_d.lib.


In the VS 2008 project Debugging configuration I use the following  
configuration:

application: C:\Python26\python.exe
arguments: the Python script, which loads the SIP generated module
working directory: The directory of the Python script

The Python script crashes when it tries to load the SIP generated module  
and prints the following error message:

"Fatal Python error: Interpreter not initialized (version mismatch?)"


With Visual Studio 2003, Python 2.4 and swig I used this approach  
successfully to debug non Qt C++ components.


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

Re: [PyQt] PyQt v4.6 and SIP v4.9 Snapshots

2009-08-12 Thread Detlev Offenbach
Hi,

what would be the best method to convert a bigger application like eric4 to 
the new QString API? Is there a tool available doing a scan and 
highlighting/converting incompatible API calls? Please give some hints.

Regards,
Detlev

On Sonntag, 9. August 2009, Phil Thompson wrote:
> The current PyQt and SIP snapshots are now driven from the v4.6 and v4.9
> branches respectively. These implement the (selectable) incompatible API
> changes described in the Roadmap.
>
> You can now decide whether, for example, QVariant and/or QString should be
> automatically converted to and from the corresponding Python types. The
> default for Python v3 is to use the newer APIs, so I have updated the
> installer for Python v3.1. All the demos should work with both Python v2
> and v3.
>
> I've decided not to look at individual methods to see if they should be
> made more Pythonic - raising an exception rather than returning an error
> flag for example. I don't think there are too many of these and they seem
> to be in areas that duplicate standard Python - so if you want a more
> Pythonic API then use the Python API. Happy to discuss further if somebody
> wants to make a strong argument the other way.
>
> Phil
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt



-- 
Detlev Offenbach
det...@die-offenbachs.de
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] inheriting from QObject and dbus.service.Object

2009-08-12 Thread Marcos Dione
On Tue, Aug 11, 2009 at 09:21:37AM +0100, Phil Thompson wrote:
> On Tue, 11 Aug 2009 07:54:35 +0200, Marcos Dione 
> wrote:
> > In [8]: class A (dbus.service.Object, QObject): pass
> > TypeError: Error when calling the metaclass bases
> > metaclass conflict: the metaclass of a derived class must be a
> > (non-strict)
> > subclass of the metaclasses of all its bases
> > 
> > is it possible to inherit from both? or will I have to make another
> > class
> > for this?
> 
> You can't inherit from both for the reason given. I don't know enough about
> DBus to know what the best solution is.

ok, let me put it this way. does PyQt build any metaclass for the QObject 
class or any other class which it might inherit from? I tried to figure this 
out from the source but between sip and the generated code they managed to 
confuse me enough to ask for help :) if not, I'll try to play with it a little 
more, and if i fail, just create another class as a wrapper.

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