[PyQt] QAxBase.dynamicCall overloaded with list as arguments

2012-11-15 Thread Knacktus

Hello everyone,

calling QAxBase.dynamicCall like this works:

my_comp.dynamicCall("MyMethod(const QString&, int, bool)", "test", 2, False)

however, using the overloaded call 
(http://qt-project.org/doc/qt-4.8/qaxbase.html#dynamicCall-2) doesn't:


my_comp.dynamicCall("MyMethod(const QString&, int, bool)", ["test", 2, 
False])


It gives an Error: ... Non-optional parameter missing

As I've got 18 args I need to use the overloaded call.

Cheers,

Jan

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


Re: [PyQt] including Unicode in QListWidget

2012-06-17 Thread Knacktus

Am 17.06.2012 22:55, schrieb David Beck:

Message: 2
Date: Sun, 17 Jun 2012 18:42:54 +0200
From: Knacktus mailto:knack...@googlemail.com>>
To: pyqt@riverbankcomputing.com <mailto:pyqt@riverbankcomputing.com>
Subject: Re: [PyQt] including Unicode in QListWidget
Message-ID: <4fde090e.1070...@googlemail.com
<mailto:4fde090e.1070...@googlemail.com>>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Am 17.06.2012 18:29, schrieb David Beck:

I am trying to build a GUI for navigating through a large XML
database on a Mac running OS 10.7, Python 3.3, PyQt 4. I want to get
a list of the text in all of the nodes called and put them into
a QListWidget called "hLexNav". To do this, I wrote the following bit
of code (this isn't the whole thing, just the parts that are supposed
to add items to the listbox):


import sys
from PyQt4 import QtCore, QtGui
from xml.dom import minidom
import xml.etree.ElementTree as etree
from fieldbookGui import Ui_Fieldbook
import images
import btnCmds

class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Fieldbook()
self.ui.setupUi(self)


xmltree = etree.parse('BabyDb.xml')
root = xmltree.getroot()
for child in root:
self.ui.hLexNav.addItem(child.findtext('Orth'))

The first 25 items that are returned by child.findtext('Orth') are:

['a:', 'a:ch?j', 'a:chul?:', "a:h?:xtu'", 'a:ho:t?n', 'a:k?s',
"a:li:ma'ht?n", 'a:li:st?:n', 'a:m?', "a:ma'ha:'pi'tz?'n",
'a:mixtzay?n', 'a:nan?:', 'a:t?:n', 'a:tz?:', "a:tzem?'j", 'a:x?:lh',
'a:xt?m', 'a:x?:x', "a:'h?la'", "a:'j", "a:'jm?", "a:'jnan?:",
"a:'jtz?:", "a:'jtzanan?:", "a:'kn?:"]

In the QListWidget created by this code, I see only items
corresponding to those elements that do not contain accented vowels
(here, those that don't contain "?", "?", etc.); items that
correpsond to strings with accented vowels are left empty. Further
experimentation with addItem( ), addItems(), and insertItem( ) show
that any string that contains an non-ASCII character results in an
empty Item being inserted into the QListWidget.

Any ideas about what is going on would be appreciated.


Are you 100 % sure that unicode is handled properly while reading the
xml? I never had problems with unicode and PyQt but I strictly using
unicode strings only in my apps.

This for example works for me (Python 2.7):

# -*- coding: utf-8 -*-

if __name__ == "__main__":

import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
list_widget = QListWidget()
list_widget.addItem(u"??^? l? l?")
list_widget.show()
app.exec_()



Yes, it seems to be independent of the XML. For instance, I get the same
thing when I run the little app below (the GUI is generated by pyuic4):

import sys
from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class Ui_UTFWidget(object):
def setupUi(self, UTFWidget):
UTFWidget.setObjectName(_fromUtf8("UTFWidget"))
UTFWidget.resize(400, 300)
self.centralWidget = QtGui.QWidget(UTFWidget)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.listWidget = QtGui.QListWidget(self.centralWidget)
self.listWidget.setGeometry(QtCore.QRect(17, 9, 362, 241))
self.listWidget.setObjectName(_fromUtf8("listWidget"))
UTFWidget.setCentralWidget(self.centralWidget)
self.menuBar = QtGui.QMenuBar(UTFWidget)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 400, 22))
self.menuBar.setObjectName(_fromUtf8("menuBar"))
self.menuUTF_test = QtGui.QMenu(self.menuBar)
self.menuUTF_test.setObjectName(_fromUtf8("menuUTF_test"))
UTFWidget.setMenuBar(self.menuBar)
self.mainToolBar = QtGui.QToolBar(UTFWidget)
self.mainToolBar.setObjectName(_fromUtf8("mainToolBar"))
UTFWidget.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtGui.QStatusBar(UTFWidget)
self.statusBar.setObjectName(_fromUtf8("statusBar"))
UTFWidget.setStatusBar(self.statusBar)
self.menuBar.addAction(self.menuUTF_test.menuAction())

self.retranslateUi(UTFWidget)
QtCore.QMetaObject.connectSlotsByName(UTFWidget)

def retranslateUi(self, UTFWidget):
UTFWidget.setWindowTitle(QtGui.QApplication.translate("UTFWidget",
"UTFWidget", None, QtGui.QApplication.UnicodeUTF8))
self.menuUTF_test.setTitle(QtGui.QApplication.translate("UTFWidget",
"UTF test", None, QtGui.QApplication.UnicodeUTF8))


Re: [PyQt] including Unicode in QListWidget

2012-06-17 Thread Knacktus

Am 17.06.2012 18:29, schrieb David Beck:

I am trying to build a GUI for navigating through a large XML database on a Mac running OS 
10.7, Python 3.3, PyQt 4. I want to get a list of the text in all of the nodes 
called  and put them into a QListWidget called "hLexNav". To do this, I 
wrote the following bit of code (this isn't the whole thing, just the parts that are supposed 
to add items to the listbox):


import sys
from PyQt4 import QtCore, QtGui
from xml.dom import minidom
import xml.etree.ElementTree as etree
from fieldbookGui import Ui_Fieldbook
import images
import btnCmds

class MyForm(QtGui.QMainWindow):
   def __init__(self, parent=None):
 QtGui.QWidget.__init__(self, parent)
 self.ui = Ui_Fieldbook()
 self.ui.setupUi(self)


 xmltree = etree.parse('BabyDb.xml')
 root = xmltree.getroot()
 for child in root:
   self.ui.hLexNav.addItem(child.findtext('Orth'))

The first 25 items that are returned by child.findtext('Orth') are:

['a:', 'a:cháj', 'a:chulá:', "a:hé:xtu'", 'a:ho:tán', 'a:kús', "a:li:ma'htín", 'a:li:stá:n', 'a:má', "a:ma'ha:'pi'tzí'n", 'a:mixtzayán', 'a:nanú:', 'a:tú:n', 
'a:tzá:', "a:tzemá'j", 'a:xí:lh', 'a:xtúm', 'a:xú:x', "a:'hála'", "a:'j", "a:'jmá", "a:'jnanú:", "a:'jtzá:", 
"a:'jtzananú:", "a:'kní:"]

In the QListWidget created by this code, I see only items corresponding to those elements that do 
not contain accented vowels (here, those that don't contain "á", "ú", etc.); 
items that correpsond to strings with accented vowels are left empty. Further experimentation with 
addItem( ), addItems(), and insertItem( ) show that any string that contains an non-ASCII character 
results in an empty Item being inserted into the QListWidget.

Any ideas about what is going on would be appreciated.


Are you 100 % sure that unicode is handled properly while reading the 
xml? I never had problems with unicode and PyQt but I strictly using 
unicode strings only in my apps.


This for example works for me (Python 2.7):

# -*- coding: utf-8 -*-

if __name__ == "__main__":

import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
list_widget = QListWidget()
list_widget.addItem(u"ÄÜ^°  là lÁ")
list_widget.show()
app.exec_()




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


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


[PyQt] Using Windows DwmApi

2011-11-03 Thread Knacktus

Hi guys,

I want use the DwmApi on Windows 7. Mainly the 
DwmExtendFrameIntoClientArea method.


The API doc is here:

http://msdn.microsoft.com/library/ms748975.aspx

and a Qt Example here:

http://nicug.blogspot.com/2011/03/qt-windows-7-extend-frame-into-client.html

I'm trying to use the Python ctypes module to call the native method.

The Code is here:

###
import sys
from ctypes import *

from PyQt4 import QtGui
from PyQt4 import QtCore

# struct needed as input for DwmExtendFrameIntoClientArea
class Margins(Structure):
_fields_ = [("cxLeftWidth", c_int),
("cxRightWidth", c_int),
("cyTopHeight", c_int),
("cyBottomHeight", c_int)]

margins = Margins(-1, -1, -1, -1)

app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()

w_handle = w.winId()

# The question is how to create proper args
proper_w_handle_arg = byref(c_int(w_handle))
proper_margins_arg = byref(margins)

# From an Internet research I assume windll for stdcall convention
# but not sure, really
windll.DwmApi.DwmExtendFrameIntoClientArea(proper_w_handle_arg, 
proper_margins_arg)


w.show()
app.exec_()


1) I'm not 100 % sure about the calling convention (windll vs. cdll)
2) It seems I don't get the arguments right.

How do I do it properly?

Cheers,

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


Re: [PyQt] Professional IDE

2011-09-07 Thread Knacktus

Am 07.09.2011 23:06, schrieb Muhammad Bashir Al-Noimi:

On 07/09/2011 10:07 م, Knacktus wrote:


Am 07.09.2011 15:20, schrieb ad...@mbnoimi.net:

On 07/09/2011 03:18 م, 机械唯物主义 : linjunhalida wrote:

I use emacs... you can try wing ide:http://wingware.com/

Actually I found eclipse better than wing but both of them don't have
PyQt integration just like eric.


They both have PyQt integration. See e.g.

http://wingware.com/doc/howtos/pyqt



See what wing says:


Wing IDE doesn't currently include a GUI builder for PyQt but it can
be used with an external GUI builder. Wing will automatically reload
files that are written by the GUI builder, making for a fairly
seamless integration.


it hasn't eric's PyQt integration at all.


What does eric do to integrate more with PyQt?
(I tested eric 2 years ago. So I might not be up to date of what you 
mean with "PyQt integration". Does is provide it's own GUI builder?)








-
Best Regards
Muhammad Bashir Al-Noimi
My Blog: http://mbnoimi.net



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

Re: [PyQt] Professional IDE

2011-09-07 Thread Knacktus

Am 07.09.2011 15:20, schrieb ad...@mbnoimi.net:

On 07/09/2011 03:18 م, 机械唯物主义 : linjunhalida wrote:

I use emacs... you can try wing ide:http://wingware.com/

Actually I found eclipse better than wing but both of them don't have
PyQt integration just like eric.


They both have PyQt integration. See e.g.

http://wingware.com/doc/howtos/pyqt




The only missing thing in eric is good auto completion just like wing or
eclipse.

PS
Project management & auto completion are perfect in eclipse.

--
Best Regards
Muhammad Bashir Al-Noimi
My Blog:http://mbnoimi.net



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


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

[PyQt] Excess closing bracket in ActiveX Example

2011-07-29 Thread Knacktus
Hi Phil,

there's one excess closing bracket in the example of the activex webbrowser
(webbrowser.pyw, line 139).

I'm still fiddeling around to get my control to work (it's a licensed one),
but so far I'm really very happy with the option to use activex.

Chees,

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

[PyQt] Basic 3D Viewer

2011-05-30 Thread Knacktus

Hi guys,

I need to evaluate the options for building a basic 3D viewer with PyQt. 
The scenes are static, but quite large (some hundreds medium complex 
(~500 triangles) objects). Show/Hide objects, rotate, drag, zoom, change 
colors and some other basic operations need to be available.


Currently, I've got some very coarse understanding of OpenGL and 
scenegraphs, but cannot really grasp the complexitiy of the topic.


Can anyone comment on the complexity of building it from scratch? I'm 
looking for some directions, best practices. E.g., do PyOpenGL and PyQt 
play together?


Also, are there some higher level scenegraph libs (or bindings) or 3D 
engines (CAD engine) compatible with PyQt that could be usefull?


Cheers,

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


[PyQt] StyleSheet for Menu Button

2011-04-21 Thread Knacktus

Hi guys,

I've got a problem applying a stylesheet to a Menu Button. I expect the 
following code to apply a blue background to all widgets, including the 
Button for the menu. But it doesn't. Is it a bug or am I doing something 
wrong?


Cheers,

Jan


import PyQt4.QtGui as QtGui

class MyMainWindow(QtGui.QMainWindow):

def __init__(self, parent=None):
super(MyMainWindow, self).__init__(parent)
self.menu_bar = self.menuBar()
self.session_menu = self.menu_bar.addMenu("&Session")

self.setStyleSheet("""
*
{
background-color: blue;
}
""")

if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
main_window = MyMainWindow()
main_window.show()
app.exec_()
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Question on QTreeView, interactive expanding/collapsing

2011-04-19 Thread Knacktus

Am 19.04.2011 23:29, schrieb Zoltan Szalai:

The "*" key expands all children but you can easily implement your own
expand / collapse subtree functionality.



Wow, I didn't know about that! But Qt needs a method to expand all 
subchildren recursively. Why is this method not available? Or is it?


Background story:

I've needed an expand_all_below action. I've implemented this similiar 
to what Paul suggested (a bit more rookie-like with recursion), but 
wasn't so happy with the performance on very large trees. So my hope is 
that the method used by Qt internaly must be a faster.


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


[PyQt] Overloading new-style signal

2011-02-19 Thread Knacktus

Hi guys,

I don't get overloading of new-style signals to work. I can't spot the 
mistake ... my eyes don't see anything anymore ;-).


Any help is highly appreciated.

Cheers,

Jan

Here's an example:


import PyQt4.Qt as Qt
import PyQt4.QtCore as QtCore


class ItemsChangedNotifier(Qt.QObject):

items_changed = QtCore.pyqtSignal([list], [dict])


class ItemChanger(object):

def __init__(self):
self.notifier = ItemsChangedNotifier()

def change_with_list(self, items):
self.notifier.items_changed.emit(items)

def change_with_dict(self, old_items_to_new_items):
self.notifier.items_changed[dict].emit(old_items_to_new_items)

class Presenter(object):

def __init__(self, item_changer):
self.item_changer = item_changer
self.item_changer.notifier.items_changed.connect(self.show_list)

self.item_changer.notifier.items_changed[dict].connect(self.show_dict)

def show_list(self, items):
print "list %s" % items

def show_dict(self, old_items_to_new_items):
print "dict %s" % old_items_to_new_items

if __name__ == "__main__":

changer = ItemChanger()
presenter = Presenter(changer)

changer.change_with_list(["Check", 1, 2, 3])
changer.change_with_dict({"old": "new"})
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Loading from DB: Threading vs. Multiprocessing

2011-01-04 Thread Knacktus

OK, I'll give QThreads a try.

Thanks, Erik and Matt.

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


[PyQt] Loading from DB: Threading vs. Multiprocessing

2010-12-30 Thread Knacktus

Hello everyone,

here the background story ;-):
--

I'm writing an application which handles a lot of nested data. Imagine a 
QTreeView with 10-20 levels and up to 5 lines.
The standard use case would be to expand one level after the other in 
the GUI. For each level I would load the data from the database. This 
can be very slow, as I have a lot of network traffic and DB requests 
with little amounts of data.
On the other hand, I am able to identify all the data of the tree in the 
database. Therefore I can load all items to the client with one request. 
But this is not always necessary.
My idea is to load all the data to the client (as bulk) on certain user 
requests only, e.g. if the user clicks "expand all". In the meantime, 
the user should be able to keep on working with the app.


Here the question:
--

I've read about multithreading and multiprocessing, but have no 
experience with it yet. I've done a lot of MPI programming with Fortran, 
so multiprocessing is more familiar to me. Right now I have these 
options in my mind:


1) Multiprocessing: Loading the bulk data from the DB with a seperate 
process and merge this data with the exisiting data in my main process. 
The data is in a huge dict with the item ids as keys. So merging should 
not be a problem. That sounds clean to me, but I'm concerned about the 
fact, that multiprocessing is copying the whole app (with all the data 
already loaded from the DB) in memory.


2) Multithreading: I guess trying to write to the same dict with my 
items with two threads could be messy. Therefore I would create a 
temporary dict in the secondary thread that loads the bulk from the DB 
and merge with the main dict later. The question here would be the 
responsiveness of the GUI as Python can't perform "real" multithreading.


3) Creating a Subprocess: I would create a helper app that loads the 
data from the DB and saves it temporarly on the local drive as pickle. 
The main app would read the data from the file and merge with the main dict.



What are your recommendations and experiences? Are there best practices?

Any comments are welcome!

Cheers,

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


Re: [PyQt] ANN: PyQt v4.8.2 Released

2010-12-26 Thread Knacktus

Am 24.12.2010 13:49, schrieb Phil Thompson:

PyQt v4.8.2 has been released.

This is primarily a bug fix release but also includes a number of new
examples from Hans-Peter Jansen.

For the first time 64-bit Windows installers are provided.

Awesome! Thank you Santa ;-)


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


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


Re: [PyQt] Send data from GUI to an external file

2010-12-05 Thread Knacktus

Am 05.12.2010 19:24, schrieb Alasdair Mac Arthur:

Hi need to have the slider values from a GUI sent to an external file
external to the GUI just as text or csv file. Currently, I can only see
the values in a LCD widget. Ultimately, these will go to a python
wrapper for a script. Any help would be much appreciated
Why not create a custom slot (function/method) that writes the value to 
the external file? Connect this function to the desired signal (e.g. 
valueChanged()) and done.


HTH,

Jan


Cheers
Alasdair






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


Re: [PyQt] ANN: PyQt v4.8.1 Released

2010-11-08 Thread Knacktus

Am 08.11.2010 20:48, schrieb Arnold Krille:

On Monday 08 November 2010 17:40:02 Phil Thompson wrote:

On Mon, 08 Nov 2010 08:11:07 -0500, John Posner

wrote:

On 10/30/2010 7:47 AM, Phil Thompson wrote:

PyQt v4.8.1 has been released and is available from the usual place.


Over the past year, downloads from
http://www.riverbankcomputing.co.uk/software/pyqt/download have been
impossible for me. More precisely, the download speed starts at about
0.6KB/sec, and degrades from there. After a minute or so, I put the
download out of its misery. Does anyone else experience this behavior?


Out of curiosity, what are you using (ie. which browser) to download?


We used Firefox on windows and chromium on Linux both with the same (slow)
result. We are in Germany, other sites work as well as they should with our
universities connection (that is a lot faster then downloads from
riverbankcomputing...).
Just downloaded PyQt 4.8.1 also from Germany with Firefox 3.6.12. It 
took about 2 minutes. I have a T-Online DSL 16000 contract. (16000 
kbits/s). Maybe this info is of any help...


Jan


Have fun,

Arnold



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


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


Re: [PyQt] Observations with nesting-level: Performance of QTreeView

2010-10-13 Thread Knacktus

Am 10.10.2010 23:28, schrieb Baz Walter:

On 10/10/10 18:39, Knacktus wrote:

Those results are very interesting! Thanks.
Just to confirm: You had 5000 items and to expand the whole tree took
only 0.67 seconds? Also, only 1 call to parent().
Now, that makes my wonder and hope. The main differences are that I'm on
Windows 7 and I'm using pyqt 4.7.4 (build on Qt 4.6 afaik). I've read
about some performance optimisation in Qt 4.7. That would be great news.


yes, 5000 in 0.67 for qt 4.7 is correct. the only change to your
previous example code was to replace the expand_all method with this:

I just installed Qt4.7 and can confirm your observation. Now, I'm at 
0.266 seconds compared to more than 90 seconds.


Sweeet. Thanks for your help!!

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


Re: [PyQt] Observations with nesting-level: Performance of QTreeView

2010-10-10 Thread Knacktus

Am 10.10.2010 18:39, schrieb Baz Walter:

On 10/10/10 15:43, Knacktus wrote:

Hi everyone,

a little update of my observations so far for the interested:

The flatter the tree, the better the performance. I've done some tests
with 10 children per parent. Now, that looks much better. For 10
items expanding all takes about 30 seconds.


is that a more realistic test of your actual use case?
I'm expecting on average 5 children per parent. Fortunately the 
performance is highly depending on the nesting.


i'm not sure what to make of the example code you posted. given how
expensive python method calls are, it doesn't seem all that surprising
that you get relatively poor performance with *five thousand* levels of
nesting :)
Well, if you know how Qt works, it might be natural. But if you don't 
(like me ;-)), you're surprised. I still wonder why the nesting levels 
make such a big difference.


anyway, i profiled the expandAll() method in your example code (with
max_items=5000). most methods get called 1-3 times per child item, which
doesn't look abnormal. however it does look very different from the
profiling results you posted earlier. are we testing the same thing?

I think so. To be sure I've attached a module with the code and the 
profiling commands. Note: I've added some code to allow variation of the 
number of children per parent.

here are my results:

Those results are very interesting! Thanks.
Just to confirm: You had 5000 items and to expand the whole tree took 
only 0.67 seconds? Also, only 1 call to parent().
Now, that makes my wonder and hope. The main differences are that I'm on 
Windows 7 and I'm using pyqt 4.7.4 (build on Qt 4.6 afaik). I've read 
about some performance optimisation in Qt 4.7. That would be great news.


[arch-linux 2.6.35, python 2.7, qt 4.7.0, sip 4.11.1, pyqt 4.7.7]

110103 function calls in 0.670 CPU seconds

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.670 0.670 :1()
10003 0.095 0.000 0.317 0.000 tree_model.py:178(rowCount)
5001 0.022 0.000 0.031 0.000 tree_model.py:190(columnCount)
24 0.000 0.000 0.000 0.000 tree_model.py:193(data)
12 0.000 0.000 0.000 0.000 tree_model.py:206(headerData)
5005 0.046 0.000 0.128 0.000 tree_model.py:213(index)
1 0.000 0.000 0.000 0.000 tree_model.py:218(parent)
15012 0.093 0.000 0.154 0.000 tree_model.py:233(
view_item_from_index)
4999 0.021 0.000 0.021 0.000 tree_model.py:43(__init__)
15008 0.060 0.000 0.110 0.000 tree_model.py:50(children)
5000 0.029 0.000 0.050 0.000 tree_model.py:77(
get_view_item_children)
3 0.000 0.000 0.000 0.000 {built-in method column}
5005 0.021 0.000 0.021 0.000 {built-in method createIndex}
1 0.194 0.194 0.670 0.670 {built-in method expandAll}
15005 0.029 0.000 0.029 0.000 {built-in method
internalPointer}
15012 0.033 0.000 0.033 0.000 {built-in method isValid}
3 0.000 0.000 0.000 0.000 {getattr}
15007 0.028 0.000 0.028 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'disable' of
'_lsprof.Profiler' objects}
___
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


import sys
import cProfile
import pstats

import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore


#
# Underlying data
# 
# - RuntimeItems hold the data. They come from a database.
# - ViewItems are the objects, that are given to the model indexes of Qt. 
#   They are constructed according to some rules like filters and 
#   configuration.
# - DummieViewItemFactory processes the rules and configurations. 
#   The example here is simplfied. An instance of the factory is given 
#   to each ViewItem. 
#   The view item calls the 
#   DummieViewItemFactory.get_view_item_children method
#   to request calculation of its children on demand.
# - For this demo-version, the number of items is controlled by 
#   DummieViewItemFactory.max_items. It's passed in by the constructor. 
# - Nesting as high as possible: One child per parent.
#


class RuntimeItem(object):
"""Represent the real world business items. These objects 
have a lot of relations.
"""

def __init__(self, name, ident, item_type):
self.name = name
self.ident = ident
self.item_type = item_type


class ViewItem(object):
"""Represent items that are to be shown to the user in a QTreeView.
Those items do only occur one time in a view. They have a 
corresponding runtime_item.
The children are calculated by the view_item_factory on demand.
"""

def __init__(self, view_item_factory, runtime_item=None, parent=None, 
 hidden_runtime_items=None):
self.view_item_factory =

[PyQt] Observations with nesting-level: Performance of QTreeView

2010-10-10 Thread Knacktus

Hi everyone,

a little update of my observations so far for the interested:

The flatter the tree, the better the performance. I've done some tests 
with 10 children per parent. Now, that looks much better. For 10 
items expanding all takes about 30 seconds.


Cheers,

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


Re: [PyQt] Performance of QTreeView

2010-10-10 Thread Knacktus

Am 10.10.2010 13:01, schrieb Virgil Dupras:

It probably has something to do with the bazillions of parent() call
that are made to your model. I asked a similar question on stack
overflow a while ago. I profiled the example, so the bottleneck is
evident.

http://stackoverflow.com/questions/841096/slow-selection-in-qtreeview-why

So the answer is: In some respects, Qt sucks balls.

Regards,
--
Virgil Dupras
Hardcoded Software
http://www.hardcoded.net


Thanks for your reply. I've used your profiling instructions (never done 
that before, so another thing learned;-)) and now I'm puzzled...


In my example with just 500 Items(!!) Qt calls some of the model methods 
125000 times for one "expandAll()" call


What!?!?

Does anyone know something about that?

Here's the profiling data:



Sun Oct 10 13:23:55 2010profdata

 896930 function calls in 8.202 CPU seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
15.8855.8858.2028.202 {built-in method exec_}
   1258531.2380.0001.9430.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:220(parent)

10.3360.3362.3012.301 {built-in method expandAll}
   1282940.2390.0000.3000.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:235(view_item_from_index)
   1273720.2120.0000.2170.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:53(children)

   1257340.1790.0000.1790.000 {built-in method createIndex}
   1282940.0400.0000.0400.000 {built-in method isValid}
   1250450.0280.0000.0280.000 {method 'index' of 'list' 
objects}
   1281680.0200.0000.0200.000 {built-in method 
internalPointer}
 16380.0080.0000.0230.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:180(rowCount)
  6890.0040.0000.0080.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:215(index)
  8010.0030.0000.0040.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:195(data)
  5000.0020.0000.0050.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:80(get_view_item_children)
  4990.0020.0000.0020.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:46(__init__)
 10180.0020.0000.0020.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:192(columnCount)
  1140.0010.0000.0010.000 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:208(headerData)

 26780.0000.0000.0000.000 {len}
10.0000.0002.3012.301 
C:\Users\Jan\Desktop\Integrations-System\Source\ipdm\QTreeView_Performance.py:141(expand_all)

  1140.0000.0000.0000.000 {built-in method column}
  1140.0000.0000.0000.000 {getattr}
10.0000.0008.2028.202 :1()
10.0000.0000.0000.000 {method 'disable' of 
'_lsprof.Profiler' objects}

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


[PyQt] Last update: Code Example -- Performance of QTreeView

2010-10-10 Thread Knacktus

OK, here the last update, I promise ;-) ...
(The expand_below action was broken - not sensitive for the problem, but 
for correctnes of the code):




import sys
import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore


#
# Underlying data
# 
# - RuntimeItems hold the data. They come from a database.
# - ViewItems are the objects, that are given to the model indexes of Qt.
#   They are constructed according to some rules like filters and
#   configuration.
# - DummieViewItemFactory processes the rules and configurations.
#   The example here is simplfied. An instance of the factory is given
#   to each ViewItem.
#   The view item calls the
#   DummieViewItemFactory.get_view_item_children method
#   to request calculation of its children on demand.
# - For this demo-version, the number of items is controlled by
#   DummieViewItemFactory.max_items. It's passed in by the constructor.
# - Nesting as high as possible: One child per parent.
#


class RuntimeItem(object):
"""Represent the real world business items. These objects
have a lot of relations.
"""

def __init__(self, name, ident, item_type):
self.name = name
self.ident = ident
self.item_type = item_type


class ViewItem(object):
"""Represent items that are to be shown to the user in a QTreeView.
Those items do only occur one time in a view. They have a
corresponding runtime_item.
The children are calculated by the view_item_factory on demand.
"""

def __init__(self, view_item_factory, runtime_item=None, parent=None,
 hidden_runtime_items=None):
self.view_item_factory = view_item_factory
self.runtime_item = runtime_item
self.parent = parent
self.hidden_runtime_items = hidden_runtime_items

@property
def children(self):
try:
return self._children
except AttributeError:
self._children = \
self.view_item_factory.get_view_item_children(self)
return self._children

@children.setter
def children(self, children):
self._children = children


class DummieViewItemFactory(object):
"""Creates the view_items. This is a dumb dummie as a simple
example. Normally a lot of things happen here like filtering
and configuration. But once the view_item hierachy is build,
this shouldn't be called at all.
"""

def __init__(self, runtime_item, max_items):
self.runtime_item = runtime_item
self.max_items = max_items
self.item_counter = 0
self.aux_root_view_item = ViewItem(self)

def get_view_item_children(self, view_item_parent):
if self.item_counter > self.max_items:
return []
self.item_counter += 1
view_item = ViewItem(self, self.runtime_item, view_item_parent)
return [view_item]


#
# Qt classes
# 
# - This should be standard stuff. I've got most of it from the Rapid
#   GUI Programming book.
# - The ActiveColums class tells the model which colums to use.
# - The TreeView has a context menu with navigation actions.
# - The expand_all calls the Qt slot. Here the surprise for the
#   performance.
#


class ActiveColumns(object):

def __init__(self, columns):
self.columns = columns


class TreeView(QtGui.QTreeView):

def __init__(self, aux_root_view_item, active_columns, parent=None,
 header_hidden=False):
super(TreeView, self).__init__(parent)
self.setIndentation(10)
self.active_columns = active_columns
self.setAlternatingRowColors(True)
self.setHeaderHidden(header_hidden)
self.setAllColumnsShowFocus(True)
self.setUniformRowHeights(True)
self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)

self.model = TreeModel(aux_root_view_item, self)
self.setModel(self.model)

e_a_action = QtGui.QAction("Expand all", self)
e_a_action.setToolTip("Expands all items of the tree.")
e_a_action.triggered.connect(self.expand_all)

e_a_b_action = QtGui.QAction("Expand all below", self)
e_a_b_action.setToolTip("Expands all items under the selection.")
e_a_b_action.triggered.connect(self.expand_all_below)

c_a_action = QtGui.QAction("Collapse all", self)
c_a_action.setToolTip("Collapses all items of the tree.")
c_a_action.triggered.connect(self.collapse_all)

c_a_b_action = QtGui.QAction("Collapse all below", self)
c_a_b_action.setToolTip("Collapses all items under the selection.")
c_a_b_action.triggered.connect(self.collapse_all_below)

for action in (e_a_action, c_a

Re: [PyQt] Performance of QTreeView

2010-10-10 Thread Knacktus

import sys
import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore


#
# Underlying data
# 
# - RuntimeItems hold the data. They come from a database.
# - ViewItems are the objects, that are given to the model indexes of Qt.
#   They are constructed according to some rules like filters and
#   configuration.
# - DummieViewItemFactory processes the rules and configurations.
#   The example here is simplfied. An instance of the factory is given
#   to each ViewItem.
#   The view item calls the
#   DummieViewItemFactory.get_view_item_children method
#   to request calculation of its children on demand.
# - For this demo-version, the number of items is controlled by
#   DummieViewItemFactory.max_items. It's passed in by the constructor.
# - Nesting as high as possible: One child per parent.
#


class RuntimeItem(object):
"""Represent the real world business items. These objects
have a lot of relations.
"""

def __init__(self, name, ident, item_type):
self.name = name
self.ident = ident
self.item_type = item_type


class ViewItem(object):
"""Represent items that are to be shown to the user in a QTreeView.
Those items do only occur one time in a view. They have a
corresponding runtime_item.
The children are calculated by the view_item_factory on demand.
"""

def __init__(self, view_item_factory, runtime_item=None, parent=None,
 hidden_runtime_items=None):
self.view_item_factory = view_item_factory
self.runtime_item = runtime_item
self.parent = parent
self.hidden_runtime_items = hidden_runtime_items

@property
def children(self):
try:
return self._children
except AttributeError:
self._children = \
self.view_item_factory.get_view_item_children(self)
return self._children

@children.setter
def children(self, children):
self._children = children


class DummieViewItemFactory(object):
"""Creates the view_items. This is a dumb dummie as a simple
example. Normally a lot of things happen here like filtering
and configuration. But once the view_item hierachy is build,
this shouldn't be called at all.
"""

def __init__(self, runtime_item, max_items):
self.runtime_item = runtime_item
self.max_items = max_items
self.item_counter = 0
self.aux_root_view_item = ViewItem(self)

def get_view_item_children(self, view_item_parent):
if self.item_counter > self.max_items:
return []
self.item_counter += 1
view_item = ViewItem(self, self.runtime_item, view_item_parent)
return [view_item]


#
# Qt classes
# 
# - This should be standard stuff. I've got most of it from the Rapid
#   GUI Programming book.
# - The ActiveColums class tells the model which colums to use.
# - The TreeView has a context menu with navigation actions.
# - The expand_all calls the Qt slot. Here the surprise for the
#   performance.
#


class ActiveColumns(object):

def __init__(self, columns):
self.columns = columns


class TreeView(QtGui.QTreeView):

def __init__(self, aux_root_view_item, active_columns, parent=None,
 header_hidden=False):
super(TreeView, self).__init__(parent)
self.setIndentation(10)
self.active_columns = active_columns
self.setAlternatingRowColors(True)
self.setHeaderHidden(header_hidden)
self.setAllColumnsShowFocus(True)
self.setUniformRowHeights(True)
self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)

model = TreeModel(aux_root_view_item, self)
self.setModel(model)

e_a_action = QtGui.QAction("Expand all", self)
e_a_action.setToolTip("Expands all items of the tree.")
e_a_action.triggered.connect(self.expand_all)

e_a_b_action = QtGui.QAction("Expand all below", self)
e_a_b_action.setToolTip("Expands all items under the selection.")
e_a_b_action.triggered.connect(self.expand_all_below)

c_a_action = QtGui.QAction("Collapse all", self)
c_a_action.setToolTip("Collapses all items of the tree.")
c_a_action.triggered.connect(self.collapse_all)

c_a_b_action = QtGui.QAction("Collapse all below", self)
c_a_b_action.setToolTip("Collapses all items under the selection.")
c_a_b_action.triggered.connect(self.collapse_all_below)

for action in (e_a_action, c_a_action, e_a_b_action, c_a_b_action):
self.addAction(action)

def expand_all(self):
self.expandAll()

def collapse_all(self):
   

[PyQt] Exmple better formatted Performance of QTreeView

2010-10-10 Thread Knacktus

Some lines have been to long. Here's the example again:


import sys
import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore


###
# Underlying data
# 
# - RuntimeItems hold the data. They come from a database.
# - ViewItems are the objects, that are given to the model indexes of 
Qt. They

#   are constructed according to some rules like filters and configuration.
# - DummieViewItemFactory processes the rules and configurations. The 
example

#   here is simplfied. An instance of the factory is given to each ViewItem.
#   The view item calls the DummieViewItemFactory.get_view_item_children 
method

#   to request calculation of its children on demand.
# - For this demo-version, the number of items is controlled by
#   DummieViewItemFactory.max_items. It's passed in by the constructor.
# - Nesting as high as possible: One child per parent.
###


class RuntimeItem(object):
"""Represent the real world business items. These objects have a 
lot of

relations.
"""

def __init__(self, name, ident, item_type):
self.name = name
self.ident = ident
self.item_type = item_type


class ViewItem(object):
"""Represent items that are to be shown to the user in a QTreeView.
Those items do only occur one time in a view. They have a corresponding
runtime_item.
The children are calculated by the view_item_factory on demand.
"""

def __init__(self, view_item_factory, runtime_item=None, parent=None,
 hidden_runtime_items=None):
self.view_item_factory = view_item_factory
self.runtime_item = runtime_item
self.parent = parent
self.hidden_runtime_items = hidden_runtime_items

@property
def children(self):
try:
return self._children
except AttributeError:
self._children = \
self.view_item_factory.get_view_item_children(self)
return self._children

@children.setter
def children(self, children):
self._children = children


class DummieViewItemFactory(object):
"""Creates the view_items. This is a dumb dummie as a simple example.
Normally a lot of things happen here like filtering and configuration.
But once the view_item hierachy is build, this shouldn't be called 
at all.

"""

def __init__(self, runtime_item, max_items):
self.runtime_item = runtime_item
self.max_items = max_items
self.item_counter = 0
self.aux_root_view_item = ViewItem(self)

def get_view_item_children(self, view_item_parent):
if self.item_counter > self.max_items:
return []
self.item_counter += 1
view_item = ViewItem(self, self.runtime_item, view_item_parent)
return [view_item]


##
# Qt classes
# 
# - This should be standard stuff. I've got most of it from the Rapid GUI
#   Programming book.
# - The ActiveColums class tells the model which colums to use.
# - The TreeView has a context menu with navigation actions.
# - The expand_all calls the Qt slot. Here the surprise for the performance.
##


class ActiveColumns(object):

def __init__(self, columns):
self.columns = columns


class TreeView(QtGui.QTreeView):

def __init__(self, aux_root_view_item, active_columns, parent=None,
 header_hidden=False):
super(TreeView, self).__init__(parent)
self.setIndentation(10)
self.active_columns = active_columns
self.setAlternatingRowColors(True)
self.setHeaderHidden(header_hidden)
self.setAllColumnsShowFocus(True)
self.setUniformRowHeights(True)
self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)

model = TreeModel(aux_root_view_item, self)
self.setModel(model)

e_a_action = QtGui.QAction("Expand all", self)
e_a_action.setToolTip("Expands all items of the tree.")
e_a_action.triggered.connect(self.expand_all)

e_a_b_action = QtGui.QAction("Expand all below", self)
e_a_b_action.setToolTip("Expands all items under the selection.")
e_a_b_action.triggered.connect(self.expand_all_below)

c_a_action = QtGui.QAction("Collapse all", self)
c_a_action.setToolTip("Collapses all items of the tree.")
c_a_action.triggered.connect(self.collapse_all)

c_a_b_action = QtGui.QAction("Collapse all below", self)
c_a_b_action.setToolTip("Collapses all items under the selection.")
c_a_b_action.triggered.connect(self.collapse_all_below)

for action in (e_a_action, c_a_action, e_a_b_action, c_a_b_action):
self.addAction(action)

def expand_al

[PyQt] Code-Example: Performance of QTreeView

2010-10-10 Thread Knacktus

Hi all,

here's an example of my code. It've tried to make minimal ... In my 
E-Mail client some lines are wrapped. But I think if you copy and paste 
it to your editor you should be able to run it in one module (using 
Python 2.7 and PyQt 4.7.4). (It worked for me)
Performance is even worse then in my real world example, but here I have 
a one-child-per-parent structure. Therefore it's as deep as it can get.

So that seems to matter a lot.

Cheers,

Jan

Here's the code with comments:




import sys
import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore



# Underlying data
# 
# - RuntimeItems hold the data. They come from a database.
# - ViewItems are the objects, that are given to the model indexes of 
Qt. They

#   are constructed according to some rules like filters and configuration.
# - DummieViewItemFactory processes the rules and configurations. The 
example

#   here is simplfied. An instance of the factory is given to each ViewItem.
#   The view item calls the DummieViewItemFactory.get_view_item_children 
method

#   to request calculation of its children on demand.
# - For this demo-version, the number of items is controlled by
#   DummieViewItemFactory.max_items. It's passed in by the constructor.
# - Nesting as high as possible: One child per parent.



class RuntimeItem(object):
"""Represent the real world business items. These objects have a 
lot of

relations.
"""

def __init__(self, name, ident, item_type):
self.name = name
self.ident = ident
self.item_type = item_type


class ViewItem(object):
"""Represent items that are to be shown to the user in a QTreeView.
Those items do only occur one time in a view. They have a corresponding
runtime_item.
The children are calculated by the view_item_factory on demand.
"""

def __init__(self, view_item_factory, runtime_item=None, parent=None,
 hidden_runtime_items=None):
self.view_item_factory = view_item_factory
self.runtime_item = runtime_item
self.parent = parent
self.hidden_runtime_items = hidden_runtime_items

@property
def children(self):
try:
return self._children
except AttributeError:
self._children = 
self.view_item_factory.get_view_item_children(self)

return self._children

@children.setter
def children(self, children):
self._children = children


class DummieViewItemFactory(object):
"""Creates the view_items. This is a dumb dummie as a simple example.
Normally a lot of things happen here like filtering and configuration.
But once the view_item hierachy is build, this shouldn't be called 
at all.

"""

def __init__(self, runtime_item, max_items):
self.runtime_item = runtime_item
self.max_items = max_items
self.item_counter = 0
self.aux_root_view_item = ViewItem(self)

def get_view_item_children(self, view_item_parent):
if self.item_counter > self.max_items:
return []
self.item_counter += 1
view_item = ViewItem(self, self.runtime_item, view_item_parent)
return [view_item]



# Qt classes
# 
# - This should be standard stuff. I've got most of it from the Rapid GUI
#   Programming book.
# - The ActiveColums class tells the model which colums to use.
# - The TreeView has a context menu with navigation actions.
# - The expand_all calls the Qt slot. Here is the surprise for the 
performance.




class ActiveColumns(object):

def __init__(self, columns):
self.columns = columns


class TreeView(QtGui.QTreeView):

def __init__(self, aux_root_view_item, active_columns, parent=None,
 header_hidden=False):
super(TreeView, self).__init__(parent)
self.setIndentation(10)
self.active_columns = active_columns
self.setAlternatingRowColors(True)
self.setHeaderHidden(header_hidden)
self.setAllColumnsShowFocus(True)
self.setUniformRowHeights(True)
self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)

model = TreeModel(aux_root_view_item, self)
self.setModel(model)

e_a_action = QtGui.QAction("Expand all", self)
e_a_action.setToolTip("Expands all items of the tree.")
e_a_action.triggered.connect(self.expand_all)

e_a_b_action = QtGui.QAction("Expand all below", self)
e_a_b_action.setToolTip("Expands all items under the selection.")
e_a_b_action.triggered.connect(self.expand_all_below)

c_a_action = QtGui.QAction("Collapse all", self)
c_a_action.setTool

[PyQt] Performance of QTreeView

2010-10-09 Thread Knacktus

Hi everyone,

I've got a QTreeView with a custom model. I've set the 
setUniformRowHeights property to True:


self.setUniformRowHeights(True)

Now, to expand the tree with a model with 1 rows and 6 cols calling 
the expandAll slot takes about 1 minute! (on a 2.8 GHz Intel 860)
I'm doing some calculations in my underlaying data. But when I iterate 
recursivly over the model and print the lines to the shell, it takes a 
couple of seconds.


Is that the kind of performance one can expect from pyqt or Qt?
Also, when collapsing all and expanding again, it takes the same amount 
of time.

Further, I saw no benefit setting the setUniformRowHeights property to True.

Another hint: My data is deeply nested. Does that come into account?

Thanks,

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


[PyQt] Newbee: Approach to expand QTreeView completely below selected index

2010-10-08 Thread Knacktus

Hi everyone,

I'm writing my first app, so I'm sometimes a bit unsure if my approaches 
are recommended practice.


To expand everything below a selected index in a TreeView with custom 
QAbstractItemModel, I've done the following (I didn't find a predefined 
slot for this case, only for expanding one level or the whole tree):


1) expand the index using the slot expand(index)
2) get the number of rows  from TreeModel.rowCount()
3) loop over the rows and get the child indexes from TreeModel.index()
4) go recursively to step 1)

Is that the way to go or do I miss some other, better approach?

Thanks in advance,

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


[PyQt] Newbie: get one of several QDockWidgets to perform action on

2010-10-05 Thread Knacktus

Hi everyone,

I'm kind of stuck to find the best approach for handling multiple 
dockwidgets.


Imagine this case: I have a QMainWindow with two QDockWidgets. Each 
QDockWidget contains one QTreeView. Now I'd like to implement a button 
"Expand all" that calls a method "expand_all()" which in turn triggers 
the ExpandAll slot of the QTreeView which is active.


I think I need to identify the QDockWidget, which had focus when I 
pressed the button. I've tried the following approaches:


1) qApp.hasFocus() in my "expand_all()" method --> didn't work, gives 
the focus of the button I pressed


2) qApp.activeWindow() --> didn't work, gives the QMainWindow

Overall, I have a bit of a lack of understanding what's "active" and 
"focus" means in the context of QDockWidgets. Hints to documentation is 
appreciated.


Thanks in advance and cheers,

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


[PyQt] createIndex() in treemodels and pyqt-book

2010-08-26 Thread Knacktus

Hello everyone,

I'm a bit confused about the third argument of the createIndex() method. 
The Qt class documentation simply says it's an internal pointer. Then, 
the PyQt-Book "Rapid GUI Programming ..." says index have a row, column 
and a parent. So I thought the pointer must be a pointer to the parent 
index. That's also what additional Qt documentation on the model-view 
framework is saying:


http://doc.qt.nokia.com/4.6/model-view-model.html
(paragraph "Parents of Items")

But on the other hand, the Qt doc says about 
ModelIndex::internalPointer, that it's an association with the internal 
data structure, so it wouldn't be a pointer to another model index.
Also, when I look at examples in the pyqt-Book it looks like parent is 
the parent in the underlaying data structure.


code from the example of chapter 16, treeoftable.py:

def index(self, row, column, parent):
assert self.root
branch = self.nodeFromIndex(parent)
assert branch is not None
return self.createIndex(row, column,
branch.childAtRow(row))

def nodeFromIndex(self, index):
return (index.internalPointer()
if index.isValid() else self.root)

So, what's the pointer pointing to?

- a QModelIndex of the the parent in the underlying data structure
- a reference to the corresponding item itself in the underlying data 
structure
- a reference to the corresponding parent of the item in the underlying 
data structure


Thanks in advance and cheers,

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