Re: [PyQt] Model/View, QTreeView, drag/drop and arbitrary objects

2009-03-24 Thread Phil Thompson
On Tue, 24 Mar 2009 11:44:41 +1000, Scott Ballard sc...@scottballard.net
wrote:
 Hi,
 
 I'm trying to put together a QTreeView using the Model/View programming 
 but using either the Python Object class or QObject class as the data. 
 It seems that neither can be passed around as MIME/QDataStream data for 
 the drag and drop functionality. This looks the be a limitation of the 
 PyQt implementation and not of Qt itself. Would be great if the 
 documentation explicitly mentioned that they didn't implement 
 Q_DECLARE_METATYPE() functionality under QMetaType instead having dead 
 links to the method.
 
 The current implementation seems to only support a small subset of PyQt 
 classes (QStringList and a couple others) These are no good for handling 
 objects with a lot of custom attributes.
 
 I'm wondering if anyone has successfully done this before and what the 
 trick is? Do you have any example code? There was mention of supporting 
 arbitrary Python objects and QDataStream in the PyQt roadmap but no 
 mention of when it might be completed. I understand that it won't be 
 included in PyQT 4.5.
 
 I really hope that I am overlooking something as my application hinges 
 around this. The model/view programming seems great for simple stuff but 
 falls apart quickly for more high level uses. Someone must have figured 
 this out before!?

The following may help...

https://svn.enthought.com/enthought/browser/TraitsBackendQt/trunk/enthought/traits/ui/qt4/clipboard.py

...which shows how to define a MIME type for a Python object and put it on
the clipboard.

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


Re: [PyQt] QSplashScreen with transparent background

2009-03-24 Thread Saúl Ibarra
On Tue, Mar 24, 2009 at 8:52 AM, David Douard david.dou...@logilab.fr wrote:
 pic = QtGui.QPixmap(:splash/images/splash.png)
 splash = QSplashScreen(pic, Qt.WindowStaysOnTopHint)
 splash.setMask(pic.mask())
 splash.show()

Yeah! That worked for me!! Thank you both!!

:)


-- 
Saúl -- Nunca subestimes el ancho de banda de un camión lleno de disketes.

http://www.saghul.net/

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


[PyQt] possible regression in PyQt/sip snapshots

2009-03-24 Thread Darren Dale
I have been keeping up to date with the snapshots, and after installing them
I try to launch Eric4 and I get a segfault. I think this simple example,
adapted from eric4's Debugger/BreakPointModel.py, might illustrate the
problem:

from PyQt4 import QtCore
alignment = QtCore.QVariant(QtCore.Qt.Alignment(QtCore.Qt.AlignLeft))

When I run that script, I get:

Traceback (most recent call last):
  File test_alignment.py, line 3, in module
alignment = QtCore.QVariant(QtCore.Qt.Alignment(QtCore.Qt.AlignLeft))
TypeError: unable to convert a Python 'Alignment' object to a C++
'Qt::Alignment' instance

Can anyone please confirm?

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

Re: [PyQt] possible regression in PyQt/sip snapshots

2009-03-24 Thread Phil Thompson
On Tue, 24 Mar 2009 10:13:16 -0400, Darren Dale dsdal...@gmail.com wrote:
 I have been keeping up to date with the snapshots, and after installing
 them
 I try to launch Eric4 and I get a segfault. I think this simple example,
 adapted from eric4's Debugger/BreakPointModel.py, might illustrate the
 problem:
 
 from PyQt4 import QtCore
 alignment = QtCore.QVariant(QtCore.Qt.Alignment(QtCore.Qt.AlignLeft))
 
 When I run that script, I get:
 
 Traceback (most recent call last):
   File test_alignment.py, line 3, in module
 alignment = QtCore.QVariant(QtCore.Qt.Alignment(QtCore.Qt.AlignLeft))
 TypeError: unable to convert a Python 'Alignment' object to a C++
 'Qt::Alignment' instance
 
 Can anyone please confirm?

Should be fixed in tonight's PyQt snapshot. However I don't see how it
might cause a crash.

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


Re: [PyQt] PyQt and Python v3

2009-03-24 Thread Simon Edwards

Phil Thompson wrote:

The current SIP and PyQt4 snapshots now support Python v3. The build
process is exactly the same - just use the right interpreter to run
configure.py.



I'm still working through the examples - so far they have all run under
Python v3 without any changes.


oh excellent news! I didn't expect to see anything working so soon 
actually. How much work can we expect for getting Python 2 .sip files 
working on Python 3? Did you encounter many problems with hand written code?


cheers,

--
Simon Edwards | KDE-NL, Guidance tools, Guarddog Firewall
si...@simonzone.com   | http://www.simonzone.com/software/
Nijmegen, The Netherlands | ZooTV? You made the right choice.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] QThread problem in linux

2009-03-24 Thread Stefan Stammberger
Hi,

I have a small QThread problem here. I'm trying to do a small progress bar in 
my app while my app is working. I have already tried 
QApplication.processEvents() which works very well in Windows
but screws everything up in Linux. When I use it my app receives key events 
only once in 10 tries, its completely unreliable. Now I have read in a kde 
mailing list that QApplication.processEvents()
is a bad thing anyway I have tried putting the progress bar in its own thread. 
This is my ProgreassBar class code:

class ProgressBarThread(QThread):
def __init__(self, min, max, moduleName):
QThread.__init__(self)
self.progress = QProgressDialog(Loading  + moduleName, Abort 
Loading, min, max, None);
self.progress.setWindowModality(Qt.WindowModal)

def setProgress(self, progress, labelText):
self.progress.setLabelText(labelText)
self.progress.setValue(progress)

def run(self):
self.progress.show()
self.exec_()


And how I use it:

   def loadModule(self, moduleName):
t = og.Timer()

self.progress = ProgressBarThread(0, 8, moduleName)
self.progress.start()

for m in self.moduleList:
if m.name == moduleName:
if m.hasDependencies: # load modules on wich the main module 
depends before the main module is loaded
for moduleDependencie in m.moduleDependencies:
for m2 in self.moduleList:
if m2.name == moduleDependencie:
self.progress.setProgress(2, Loading 
Dependencie:  + moduleDependencie)
m2.load()

self.modelSelectionDialog.scanDirForModels(m2.moduleRoot)

self.materialSelectionDialog.scanDirForMaterials(m2.moduleRoot)
self.mainModuledependencieList.append(m2)

self.progress.setProgress(4, Loading  + moduleName)
m.load()
self.progress.setProgress(6, Scan for models...)
self.modelSelectionDialog.scanDirForModels(m.moduleRoot)
self.progress.setProgress(8, Scan for materials)
self.materialSelectionDialog.scanDirForMaterials(m.moduleRoot)
self.mainModule = m
self.moduleExplorer.setCurrentModule(m)

self.progress.quit()
print Time to load module:  + str(t.getMilliseconds() / 1000.0) +  
seconds
del t

When using this I get a few warnings:

QPixmap: It is not safe to use pixmaps outside the GUI thread
QCoreApplication::sendPostedEvents: Cannot send posted events for objects in 
another thread

And the worst:

X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 181

Extension: 155 (RENDER)

Minor opcode: 25 (RenderCompositeGlyphs32)

Resource id: 0x0



When I get this error no text in my application is drawn at all. The strange 
thing is,
when I have a cleanly booted system, it works very well the first time I start 
the application.
On the second time I don't get any text. Two screen shots:
How it looks without text: 
http://picasaweb.google.de/some.fusion/Lockenwickler?feat=directlink#5316822651416543426
And how it should look: 
http://picasaweb.google.de/some.fusion/Lockenwickler?feat=directlink#5316822694766353394

I don't know what I'm doing wrong here, I'm very new to the Threading stuff.

In case anybody wonders what my app is all about, its a game editor for an open 
source game.
http://www.youtube.com/watch?v=J-1ekVyv19o and 
http://www.youtube.com/watch?v=R0ZKMbLtXYY

Sorry for this long email!

Thank you very much!
Stefan Stammberger




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


Re: [PyQt] QThread problem in linux

2009-03-24 Thread mir amicitas
(ack sorry I pressed the wrong button and sent it before it was done.
Here is the exciting conculsion . . .)

I think what you probably want to do here is to put your loadModule()
function in a thread instead of the the progress dialog.  That is to
say the program that you want to run in the background is in the
thread.

Then to communicate with the progress dialog, you can have
loadModule() emit events.
To have the dialog communicate with the thread (to cancel for example)
the simplest way is to give them both access to a variable that
defines the cancel state.  Then have your thread check this variable
occasionally.

The harder part is making sure that your thread can properly access
everything else that it needs in your application.  To do this you
will probably want to make use of a QMutexLocker in your thread.


I home some of this is helpful, I am not an expert on multithreaded
programming (though I have build a couple of applications).  Keeping
everything straight is kinda hard.

Novi


Here is a small example:

class LoadModuleThread(QThread):
   def __init__(self, moduleName):
       QThread.__init__(self)

   self.mutex = QtCore.QMutex()

   def run(self):
   with QtCore.QMutexLocker(self.mutex) as locker:
       t = og.Timer()

       for m in self.moduleList:
           if m.name == moduleName:
               if m.hasDependencies: # load modules on wich the
main module depends before the main module is loaded
                   for moduleDependencie in m.moduleDependencies:
                       for m2 in self.moduleList:
                           if m2.name == moduleDependencie:

self.emit(QtCore.SIGNAL('setProgress'), 2, Loading Dependencie:  +
moduleDependencie)
                               m2.load()

   self.emit(QtCore.SIGNAL('setProgress'), 4, Loading  +
moduleName)
               m.load()

   self.emit(QtCore.SIGNAL('loadingDone'))
       print Time to load module:  + str(t.getMilliseconds() /
1000.0) +  seconds


def startLoadingModules(self):
    self.thread = LoadModuleThread(moduleName)

    self.connect(self.thread
    ,QtCore.SIGNAL('setProgress')
    ,self.setProgress)
    self.connect(self.thread
        ,QtCore.SIGNAL('loadingDone')
    ,self.setProgressDone)

   self.progress = QProgressDialog(Loading  + moduleName, Abort
Loading, min, max, None);
   self.progress.setWindowModality(Qt.WindowModal)
   self.progress.show()

   self.thread.start()

def setProgress(self, progress, labelText):
   self.progress.setLabelText(labelText)
   self.progress.setValue(progress)

def setProgressDone(self):
  self.progress.quit()


---
On Tue, Mar 24, 2009 at 11:38 AM, Stefan Stammberger
sstammber...@web.de wrote:

 Hi,

 I have a small QThread problem here. I'm trying to do a small progress bar in 
 my app while my app is working. I have already tried 
 QApplication.processEvents() which works very well in Windows
 but screws everything up in Linux. When I use it my app receives key events 
 only once in 10 tries, its completely unreliable. Now I have read in a kde 
 mailing list that QApplication.processEvents()
 is a bad thing anyway I have tried putting the progress bar in its own 
 thread. This is my ProgreassBar class code:

 class ProgressBarThread(QThread):
    def __init__(self, min, max, moduleName):
        QThread.__init__(self)
        self.progress = QProgressDialog(Loading  + moduleName, Abort 
 Loading, min, max, None);
        self.progress.setWindowModality(Qt.WindowModal)

    def setProgress(self, progress, labelText):
        self.progress.setLabelText(labelText)
        self.progress.setValue(progress)

    def run(self):
        self.progress.show()
        self.exec_()


 And how I use it:

   def loadModule(self, moduleName):
        t = og.Timer()

        self.progress = ProgressBarThread(0, 8, moduleName)
        self.progress.start()

        for m in self.moduleList:
            if m.name == moduleName:
                if m.hasDependencies: # load modules on wich the main module 
 depends before the main module is loaded
                    for moduleDependencie in m.moduleDependencies:
                        for m2 in self.moduleList:
                            if m2.name == moduleDependencie:
                                self.progress.setProgress(2, Loading 
 Dependencie:  + moduleDependencie)
                                m2.load()
                                
 self.modelSelectionDialog.scanDirForModels(m2.moduleRoot)
                                
 self.materialSelectionDialog.scanDirForMaterials(m2.moduleRoot)
                                self.mainModuledependencieList.append(m2)

                self.progress.setProgress(4, Loading  + moduleName)
                m.load()
                self.progress.setProgress(6, Scan for models...)
                

Re: [PyQt] PyQt and Python v3

2009-03-24 Thread Phil Thompson
On Tue, 24 Mar 2009 19:54:05 +0100, Simon Edwards si...@simonzone.com
wrote:
 Phil Thompson wrote:
 The current SIP and PyQt4 snapshots now support Python v3. The build
 process is exactly the same - just use the right interpreter to run
 configure.py.
 
 I'm still working through the examples - so far they have all run under
 Python v3 without any changes.
 
 oh excellent news! I didn't expect to see anything working so soon 
 actually. How much work can we expect for getting Python 2 .sip files 
 working on Python 3? Did you encounter many problems with hand written
 code?

Grep the .sip files for PY_MAJOR_VERSION to see how much version dependent
stuff - not a lot and (I think) mostly to do with __repr__ implementations.

The main thing you will need to do is to identify any function arguments
that should be interpreted as an unencoded byte stream rather than UTF-8
encoded text.

I've tried to be flexible in what string conversions are allowed - it's not
as simple as mapping QString to a v3 string object and char * to a v3 bytes
object. I've come to the conclusion that it is a fairly easy task to write
code that will run under v2.6 and v3.x without change.

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


Re: [PyQt] PyQt and Python v3

2009-03-24 Thread Phil Thompson
On Tue, 24 Mar 2009 20:31:21 +0100, Detlev Offenbach
det...@die-offenbachs.de wrote:
 On Dienstag, 24. März 2009, Phil Thompson wrote:
 The current SIP and PyQt4 snapshots now support Python v3. The build
 process is exactly the same - just use the right interpreter to run
 configure.py.

 pyuic4 has yet to be ported - but the code it generates should run under
 Python v3.

 pyrcc4 generates code for Python v2.6 and v3. If you need to generate
 code
 for earlier versions of Python use the new -py2 flag. Note that Python
 v2.6
 can handle both formats.

 I'm still working through the examples - so far they have all run under
 Python v3 without any changes.

 
 That is excellent news. eric4's debugger will support Python3 in the
first 
 development snapshot as well.
 
 When will QScintilla's Python bindings be made Python3 compatible?

It wouldn't surprise me if it just worked - though configure.py will need
some changes.

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


[PyQt] Larger size of QIcon?

2009-03-24 Thread Mads
Hi all,

I have just started using pyqt4 and decided to make a small
thumbnail-viewer to learn how things work.

I would like the thumbnails to be displayed in a grid that
automatically change the grid when resized so I use the QListWidget.
So far so good - it works fine ...almost... the thumbnails (QIcons)
are very small - how do I make them larger?

Code is attached.

Thanks!
Mads
#! /usr/bin/env python

from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys

TITLE = 'ThumbGridWidget'
THUMBWIDTH = 64
PICS = ['Elvis1.jpg',
		'Elvis2.jpg',
		'Elvis3.jpg',
		'Elvis4.jpg']*4

black   = QColor(0, 0, 0)
white   = QColor(255, 255, 255)
red = QColor(255, 0, 0)
green   = QColor(0, 255, 0)
blue= QColor(0, 0, 255)
yellow  = QColor(255, 255, 0)
cyan= QColor(0, 255, 255)
magenta = QColor(255, 0, 255)





class Thumb(QListWidgetItem):

	def __init__(self, parent=None, imgPath='', title=''):
		super(Thumb, self).__init__(parent)

		pic = QPixmap(imgPath)
		icon = QIcon(pic)
		self.setIcon(icon)
		self.setText(title)



class ThumbListWidget(QListWidget):

	p = QPalette()

	def __init__(self, parent=None, palette=None):
		super(ThumbListWidget, self).__init__(parent)

		# Setup
		self.setViewMode(QListView.IconMode)
		self.setResizeMode(QListView.Adjust)
		self.setLayoutMode(QListView.SinglePass)
		self.setUniformItemSizes(1)
		self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

		# Colors
		if palette: self.p = palette
		self.setPalette(self.p)

		list = PICS
		for pic in list:
			thumb = Thumb(None, pic, pic)
			self.addItem(thumb)

	def setBackgroundColor(self, color):
		self.p.setColor(QPalette.Base, color)
		self.setPalette(self.p)

	def setTextColor(self, color):
		self.p.setColor(QPalette.Text, color)
		self.setPalette(self.p)




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

		self.setWindowTitle(TITLE)

		self.listView = ThumbListWidget(self)

		self.listView.setBackgroundColor(black)
		self.listView.setTextColor(white)

		self.setCentralWidget(self.listView)




if __name__ == __main__:
	print Starting..
	app = QApplication(sys.argv)
	win = Main()
	win.show()
	app.exec_()
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Range slider?

2009-03-24 Thread David Boddie
On Mon Mar 23 02:02:51 GMT 2009, Hazen Babcock wrote:

 Does anyone know if a widget like this:
 http://www.codeproject.com/KB/miscctrl/CRangeSlider/CRangeSlider.gif
 exists for Qt?

There's a range slider of sorts included in the package mentioned here:

http://labs.trolltech.com/blogs/2009/03/23/embedded-widgets-source-code-released/

It's written in C++. I imagine it could be wrapped fairly easily with SIP
or ported to Python.

 This being the slider in the upper left corner of the 
 image which lets the user define a range or interval.

 If not, any suggestions on how to go about creating one?

You might start by subclassing QAbstractSlider to inherit the API:

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qabstractslider.html

Drawing the slider might be a challenge - you could keep things simple to
start with and use simple drawing primitives, and later move on to use the
QStyle drawing API:

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qstyle.html

Handling mouse clicks and key events should be simple if you know enough
about the event model. Some of the examples provided with PyQt (Scribble,
Character Map) contain useful code that shows how to handle events, but the
examples themselves don't really address the same use case.

 I'm currently using to two sliders that are coupled to each other,
 one to set the high value and the other to set the low value, but I
 think this would be a lot cooler...

Yes, I agree. :-)

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


[PyQt] QCoreApplication doesn't exit

2009-03-24 Thread Thomas Coopman
I have a problem with QCoreApplication,  my program doesn't return.

this is the the code

import sys

from PyQt4.QtCore import QCoreApplication

if __name__==__main__:
app=QCoreApplication(sys.argv)
sys.exit(app.exec_())

but this program doesn't exit and blocks all input in konsole, it just
doesn't do anything and doesn't respond to keypresses.

Am I doing something wrong?


-- 
Thomas Coopman
thomas.coop...@gmail.com
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] QCoreApplication doesn't exit

2009-03-24 Thread Phil Thompson
On Wed, 25 Mar 2009 00:10:31 +0100, Thomas Coopman
thomas.coop...@gmail.com wrote:
 I have a problem with QCoreApplication,  my program doesn't return.
 
 this is the the code
 
 import sys
 
 from PyQt4.QtCore import QCoreApplication
 
 if __name__==__main__:
 app=QCoreApplication(sys.argv)
 sys.exit(app.exec_())
 
 but this program doesn't exit and blocks all input in konsole, it just
 doesn't do anything and doesn't respond to keypresses.
 
 Am I doing something wrong?

It's doing exactly what you have told it to do - sitting in the event loop
waiting for events to process.

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