Re: [PyQt] Resizing index widgets

2013-01-30 Thread Mads Ipsen

Hi Detlev,

We have of the order 60-70 interface plugins available in our 'tool box' 
- to be able to order them, group them, filter/search them - and still 
maintain a compact layout - I felt that the QToolBox offered too 'flat' 
a solution. Let me know your opinion or suggestions for a better approach.


Best regards,

Mads



On 01/30/2013 07:11 PM, Detlev Offenbach wrote:


Hi Mads,

why are you using QTreeView? I would use QToolbox for such a layout.

Regards,

Detlev

On Tuesday 29 January 2013, 22:31:14 Mads Ipsen wrote:

Hi,

We develop a tool for manipulating atomic structures and have embedded 
all the manipulation widgets in a panel bar (widget on the right in 
attached screen0.png). The Panel bar has expandable buttons, which 
upon expansion display different interfaces for manipulating the 
atomic structures.


The whole thing is implemented using a MVC approach using a QTreeView 
and an overloaded QItemDelegate class used for handling painting of 
the buttons, sizeHints, etc. The widget interfaces however, are 
displayed by setting setIndexWidget() on the tree view.


This works fine if the widgets have a fixed size. However if the 
atomic structure changes (molecule to crystal), previously hidden GUI 
elements may be shown in the widget, which gives rise to a compressed 
(bad) layout since the index widget has a fixed size (screen1.png).


The only way I could fix this was to use an idle time, that keeps 
triggering the emission of the signal


sizeHintChanged(const QModelIndex & index)

from the delegate. This immediately triggers a smooth update of the 
index widget resulting in screen2.png. From a user perspective it 
works fine, but to me it appears somewhat hacky. Is there eg. a way to 
monitor layout changes in visible index widgets?


Best regards,

Mads

--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:mads.ip...@gmail.com  
<mailto:mads.ip...@gmail.com>  |
+--+--+
  




--

Detlev Offenbach

det...@die-offenbachs.de




--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+

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

Re: [PyQt] button delegate in a tableview

2013-01-30 Thread Mads Ipsen

Hi,

You could consider using setIndexWidget() on the TableView. But some 
care should be taken if you also use a QSortFilterProxyModel for 
filtering your data.


Best,

Mads

On 01/30/2013 11:32 AM, Cristobal Infante wrote:

Hi,

Sorry to bump this thread again.

I am almost done with my PYQT application but I  still have this 
glitch on my button delegate..


Are there any alternatives to using buttons delegate in tableviews?

But I need a button per row...

Best,
Cris

On 8 November 2012 21:53, Cristobal Infante <mailto:cgc...@gmail.com>> wrote:


Hi Erik,

Thanks again for your reply, It's good to know that at least I am
making some progress
with PyQt and have arrived to a dead end ;)

To be honest I am fine with it, will just have to explain my users
they will have to
activate the cell before clicking.

The important thing was to have my button clicking and that has
been achieved.

Thanks!
Cris


On 8 November 2012 17:09, Erik Janssens
mailto:erik.janss...@conceptive.be>>
wrote:

Hi Chris,

I'm not sure if this can be fixed, maybe you can ask this

on the Qt info mailing list. If it can be fixed, I'm interested

in the solution ;)

What happens is, when the TableWidget receives a click, it

creates an editor, but the editor has not yet received the

click. That is perfect in most cases, but in case you draw

a button it isn't.

Cheers,

Erik

On Wednesday, November 07, 2012 02:50:17 PM Cristobal Infante
wrote:

Hi Eric,

Thanks for the tip, I've managed to get my button inside my
tableview.

There is only one thing that bothers me, not sure if it is a
limitation or something I can fix.

To be able to press a button, I need to "activate" the
containing cell with a click.
Once the cell is active I can press the button. This could
become confusing for your average user.

Is this fixable?

Best,
Cris




On 6 November 2012 22:05, mailto:erik.janss...@conceptive.be>> wrote:

The delegate itself can only paint, it cannot react to

clicks, you should implement the createEditor method,

the editor then reacts to clicks

On Tuesday, November 06, 2012 09:59:03 PM Cristobal Infante wrote:

Hi,


I am trying to embed a button per row inside a tableview. My
botton are drawing correctly as delegates but are not reacting
to any clicks.


Should I be setting flags for this column? so far I have
something like:


  if index.column() == 14:  

 flags |=  QtCore.Qt.ItemIsSelectable  | QtCore.Qt.ItemIsUserCheckable | Qt.ItemIsEnabled  

 return flags  




This is my delegate, but how do I make the button react to clicks?


Thanks,

cris




class AButton(QtGui.QStyledItemDelegate):  

mouse_isPressed = False  






def __init__(self, parent = None):  

 QtGui.QStyledItemDelegate.__init__(self, parent)  






def boundingRect(self):  

 return QtCore.QRectF(0, 0, 40, 40)  






def paint(self, painter, option, widget = 0):  

 opt = QtGui.QStyleOptionButton()  






 opt.state = ((QtGui.QStyle.State_Sunken if self.mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled)  

 opt.text = self.text()  

 opt.icon = self.icon()  

 opt.rect = option.rect  

 opt.palette = option.palette  

 QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter)  






def text(self):  

 return QtCore.QString("hi")  






def icon(self):  

 return QtGui.QIcon()  






def mousePressEvent(self, event):  

 self.mouse_isPressed = True  

 print "HELLO"  

 self.update()  






def mouseReleaseEvent(self, event):  

 self.mouse_isPressed = False  

 self.update()  





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





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





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

Re: [PyQt] HeightForWidth label

2013-01-10 Thread Mads Ipsen

Dear Pete,

Thanks a lot for your input. To some extend its too bad that this 
feature cannot be implemented in a proper fashion - especially when the 
documentation of Qt tells you that it can.


Best regards,

Mads

On 09/01/2013 22:00, Hans-Peter Jansen wrote:

Dear Mads,

Am Mittwoch, 9. Januar 2013, 15:56:29 schrieb Mads Ipsen:

Hi,

4-5 years I needed a widget with the following properties:

   * Display text incl. HTML
   * Text should be wrapped on several lines
   * When the widget is put into a layout, the height of the widget
 should be adjusted in such a way that the text exactly fits the
 widget geometry

This subwidget should be used in a layout to provide some detail on how
the other GUI elements in the layout work but only consume a minimum
space to display its content.

I thought this was an easy one - but each time I return to the challenge
I always end by giving up.

The main problem is that the layout breaks down when heightForWidth() is
implemented and a QSizePolicy with setHeightForWidth(True) is used. It
can shrink to infinitely small. Apparently this is Qt bug.

Yes, been there, done that, and failed in similar ways.

The best thing I could come up on this was:

use a QTextBrowser for the text:

 
self.aboutText.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
 self.aboutText.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
 self.aboutText.setLineWrapMode(QtGui.QTextEdit.NoWrap)
 self.aboutText.setSizePolicy(QtGui.QSizePolicy.Fixed, 
QtGui.QSizePolicy.Fixed)
 self.aboutText.setHtml("...")

 w = self.aboutText.document().idealWidth()
 self.aboutText.document().setTextWidth(w)
 ds = self.aboutText.document().size()
 self.aboutText.setMinimumSize(int(ds.width() + 3), int(ds.height() + 
3))
 self.aboutText.updateGeometry()
 self.layout().setSizeConstraint(QtGui.QLayout.SetFixedSize)

with this, you can even provide clickable links (but disable openLinks prop):

 @QtCore.pyqtSignature("const QUrl &")
 def on_aboutText_anchorClicked(self, url):
 QtGui.QDesktopServices.openUrl(url)

Maybe it gets you going..

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



--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+

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


[PyQt] HeightForWidth label

2013-01-09 Thread Mads Ipsen

Hi,

4-5 years I needed a widget with the following properties:

 * Display text incl. HTML
 * Text should be wrapped on several lines
 * When the widget is put into a layout, the height of the widget
   should be adjusted in such a way that the text exactly fits the
   widget geometry

This subwidget should be used in a layout to provide some detail on how 
the other GUI elements in the layout work but only consume a minimum 
space to display its content.


I thought this was an easy one - but each time I return to the challenge 
I always end by giving up.


The main problem is that the layout breaks down when heightForWidth() is 
implemented and a QSizePolicy with setHeightForWidth(True) is used. It 
can shrink to infinitely small. Apparently this is Qt bug.


Another approach is to call updateGeometry() when a resizeEvent() occurs 
and call setFixedHeight(h) using a width dependent height. But this also 
gives rise to some weird layout behavior.


If anybody has any good suggestions on how to approach this, please let 
me know.


I attach a small snippet that reproduces the layout resizing behavior.

Best regards,

Mads

--
+-+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:mads.ip...@gmail.com  |
+--+--+

import sys
from PyQt4 import QtCore, QtGui

class Square(QtGui.QLabel):
def __init__(self, parent=None):
QtGui.QLabel.__init__(self, parent)
self.setAutoFillBackground(True)

palette = QtGui.QPalette()
palette.setColor(QtGui.QPalette.Window, QtGui.QColor('red'))
self.setPalette(palette)

policy = self.sizePolicy()
policy.setHeightForWidth(True)
self.setSizePolicy(policy)

def sizeHint(self):
return QtCore.QSize(128, 128)

def heightForWidth(self, width):
return width

class Widget(QtGui.QWidget):
def __init__(self, parent=None):
# Call base class constructor
QtGui.QWidget.__init__(self, parent)

# Add a layout
layout = QtGui.QVBoxLayout()
self.setLayout(layout)

# Add Square
label = Square()
layout.addWidget(label)

spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
layout.addItem(spacerItem)

# Some dummy button
self._push_button = QtGui.QPushButton('Press me')
layout.addWidget(self._push_button)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

widget = Widget()
widget.show()

sys.exit(app.exec_())

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

[PyQt] Size for hint label

2013-01-09 Thread Mads Ipsen

Hi,

4-5 years I needed a widget with the following properties:

 * Display text incl. HTML
 * Text should be wrapped on several lines
 * When the widget is put into a layout, the height of the widget
   should be adjusted in such a way that the text exactly fits the
   widget geometry

This subwidget should be used in a layout to provide some detail on how 
the other GUI elements in the layout work but only consume a minimum 
space to display its content.


I thought this was an easy one - but each time I return to the challenge 
I always end by giving up.


The main problem is that the layout breaks down when heightForWidth() is 
implemented and a QSizePolicy with setHeightForWidth(True) is used. It 
can shrink to infinitely small. Apparently this is Qt bug.


Another approach is to call updateGeometry() when a resizeEvent() occurs 
and call setFixedHeight(h) using a width dependent height. But this also 
gives rise to some weird layout behavior.


If anybody has any good suggestions on how to approach this, please let 
me know.


I attach a small snippet that reproduces the layout resizing behavior.

Best regards,

Mads

--
+-+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+

import sys
from PyQt4 import QtCore, QtGui

class Square(QtGui.QLabel):
def __init__(self, parent=None):
QtGui.QLabel.__init__(self, parent)
self.setAutoFillBackground(True)

palette = QtGui.QPalette()
palette.setColor(QtGui.QPalette.Window, QtGui.QColor('red'))
self.setPalette(palette)

policy = self.sizePolicy()
policy.setHeightForWidth(True)
self.setSizePolicy(policy)

def sizeHint(self):
return QtCore.QSize(128, 128)

def heightForWidth(self, width):
return width

class Widget(QtGui.QWidget):
def __init__(self, parent=None):
# Call base class constructor
QtGui.QWidget.__init__(self, parent)

# Add a layout
layout = QtGui.QVBoxLayout()
self.setLayout(layout)

# Add Square
label = Square()
layout.addWidget(label)

spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
layout.addItem(spacerItem)

# Some dummy button
self._push_button = QtGui.QPushButton('Press me')
layout.addWidget(self._push_button)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

widget = Widget()
widget.show()

sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Python generated file changes not detected by QFileSystemModel

2012-05-22 Thread Mads Ipsen

Hi,

Here's the problem:

1. Set up a QFileSystemModel, call setRootPath() and hook up to the
   dataChanged signal.
2. Open a new file from Python and write some text into it. Then close it.
3. Reopen the file in append mode and write some more text into it.
   Then close it.
4. Open a file in an external editor. Write some stuff. Save. Write
   more stuff. Save.

If you do (3), the dataChanged signal is NOT emitted. However, if you do 
(4), the dataChanged signal IS emitted.


Any clues? An attached file that reproduces the issue is attached.

Best regards,

Mads


--
+-+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


import sys
import os

from PyQt4 import QtGui, QtCore

class Widget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)

layout = QtGui.QVBoxLayout()
self.setLayout(layout)
self._view = QtGui.QListView()
layout.addWidget(self._view)

# Add the model
self._model = QtGui.QFileSystemModel()
self._model.setRootPath(QtCore.QDir().rootPath())
self._model.setReadOnly(False)
self._model.setFilter(QtCore.QDir.AllDirs | QtCore.QDir.AllEntries)
self._view.setModel(self._model)

# Root path
path = os.path.dirname(os.path.abspath(__file__))
self._model.setRootPath(path)

# Set a root index
index = self._model.index(path)
self._view.setRootIndex(index)

# Generate a file with some text
print 'Making file'
f = open('foo.dat', 'w')
f.write('Some stuff\n')
f.close()

self.connect(self._model, QtCore.SIGNAL('dataChanged(const QModelIndex &, const QModelIndex &)'), self.dataChanged)

# Append more text - this should trigger a signal call
print 'Modifying file'
f = open('foo.dat', 'w+')
f.write('Some more stuff\n')
f.close()

def dataChanged(self, index_0, index_1):
print 'dataChanged', self._model.filePath(index_0), self._model.filePath(index_1)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

widget = Widget()
widget.show()

sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Widget over modal dialog

2012-05-15 Thread Mads Ipsen

Hi,

Here's my problem:

* Launch a modal dialog where some parameters can be set.
* Modal dialog contains a 'plot' button that launches a widget 
displaying a 2D plot visualizing some consequences of the parameter 
settings.
* When the plot window is shown, the window is always underneath the 
modal dialog.


Is it possible to make the plot appear on top of the main modal dialog, 
provided its the active window?


To me it makes sense to do something like this, but correct me if I'm 
wrong.


The main dialog from where the 2D plot is launched, takes care of 
closing the 2D plot if its open.


Best regards,

Mads

--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


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

[PyQt] Setting icon size on a header view

2012-03-14 Thread Mads Ipsen

Hi,

Trying to set the size of the icon displayed by a vertical header using 
its setIconSize() method in QTableView and QStandardItemModel framework. 
All attempts are unsuccessful so far.


Have attached small snippet and an PNG illustrating the issue.

Any ideas about what is going wrong?

Best regards,

Mads

--
+-+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


import sys

from PyQt4 import QtGui, QtCore

class Table(QtGui.QTableView):
def __init__(self):
QtGui.QTableView.__init__(self)

# Hook up model
self._model = QtGui.QStandardItemModel(3,3)
self.setModel(self._model)

# Add dummy data
for i in range(3):
for j in range(3):
item = QtGui.QStandardItem('(%d,%d)' % (i,j))
self._model.setItem(i,j,item)

# Set vertical header icon sizes
self.verticalHeader().setIconSize(QtCore.QSize(128,128))

# Vertical header icons
for i in range(3):
pixmap = QtGui.QPixmap('X.png')
self._model.setHeaderData(i, QtCore.Qt.Vertical, QtCore.QVariant(pixmap), QtCore.Qt.DecorationRole)

# Alt. vertical header icons - also does NOT work
# for i in range(3):
# item = QtGui.QStandardItem()
# item.setSizeHint(QtCore.QSize(128,128))
# item.setIcon(QtGui.QIcon('X.png'))
# self._model.setVerticalHeaderItem(i, item)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

table = Table()
table.show()

sys.exit(app.exec_())
<>___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Unit testing PyQt applications

2012-03-14 Thread Mads Ipsen
Sorry for a late reply - but thanks for a very useful answer. Got one 
more question though.


How would you technically moc QFileDialog.exec_ to avoid that the unit 
test is halted by the Dialog popping up in its own event loop. Anyway, 
this is how I do it:


class Proxy:
def __init__(self):
self._called = False

def caller(self, *args):
self._called = args

def called(self):
return self._called

proxy = Proxy()
new_exec = proxy.exec_
old_exec = QtGui.QFileDialog.exec_
QtGui.QFileDialog.exec_ = new_exec

  ... Then do testing and query proxy.called() to test that the 
QFileDialog was called


Finally clean up and reinsert the old exec_ method.

QtGui.QFileDialog.exec_ = new.instancemethod(old_exec, None, 
QtGui.QFileDialog)


Makes sense?

On 07/03/2012 18:13, Andreas Pakulat wrote:

On 07.03.12 15:42:34, Mads Ipsen wrote:

OK, I agree, the snippets I provided were not nice, and I apologize
for that.

But suppose that the constructor in your class starts a thread that
generates say an icon for a QStandardItem. Then you want to make
sure that the thread has finished before you test that the icon has
been created.

* What would be the proper way of unit testing this?

I'd try to put in some moc-objects and split the testing. So one
unit-test would just test the loading of the icon from whatever source
it comes, without a thread in a blocking way.

Another unit-test would put in a moc-object that immediately returns the
icon so you can be sure that the amount of time the thread needs to run
is relatively small. Then in the unit-test, create the widget and then
let the main thread sleep for a bit so the background thread finishes.
Afterwards verify the moc-icon is properly retrieved. You don't need an
event loop here yet, unless you want the widget to be actually drawn.


* How should starting/stopping the event loop be handled?

Hmm, the Qt unit-test framework works by starting the event-loop and
triggering the unit-test functions via a timer. I guess this could also
be done in python with the unittest framework somehow.

Personally I'd probably avoid testing the actual event-loop-requiring
bits of the application via unit-tests completely. Instead I'd go for a
gui-test-tool to test those parts and use unit-tests for all the
business-logic and non-gui stuff.

Andreas

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



--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


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


Re: [PyQt] Unit testing PyQt applications

2012-03-07 Thread Mads Ipsen
OK, I agree, the snippets I provided were not nice, and I apologize for 
that.


But suppose that the constructor in your class starts a thread that 
generates say an icon for a QStandardItem. Then you want to make sure 
that the thread has finished before you test that the icon has been created.


* What would be the proper way of unit testing this?
* How should starting/stopping the event loop be handled?

Best regards,

Mads

On 07/03/2012 10:51, Andreas Pakulat wrote:

On 07.03.12 09:37:38, Mads Ipsen wrote:

Hi,

I have a general question about how to unit test PyQt applications
using the Python unittest moudle. I have attached a few examples. If
you have time to take a look and comment, it would be great.

The first module, Foo.py, defines a simple widget called 'Widget'
which is tested in FooTest.py. FooTest.py defines an instance of a
QApplication, which is needed in order to run the test. In this case
the test runs fine.

The second module, Bar.py, defines a more complex widget, also
called Widget, which starts a thread in its constructor. In real
life, this could be a used for generating an icon in the background.
This is tested in BarTest.py. In this case, the test fails, because
the unittest exits while the thread is still running.

There are ways to circumvent this, e.g:

* Hook up a slot which gets called when the thread finishes
* Start the event loop by calling QtGui.qApp.exec_()
* Kill the event loop when the slot is called

Your example code is simply buggy IMHO. If an object starts a thread it
should stop and clean that thread up once the object is destroyed.
This can be done through the destroyed signal. Once your widget cleans
up the thread you shouldn't have the problem anymore and you don't need
the finished-state either.

Andreas

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



--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


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


Re: [PyQt] Unit testing PyQt applications

2012-03-07 Thread Mads Ipsen

On 07/03/2012 09:43, Luca Beltrame wrote:

In data mercoledì 7 marzo 2012 09:37:38, Mads Ipsen ha scritto:


the Python unittest moudle. I have attached a few examples. If you have
time to take a look and comment, it would be great.

I have a question on FooTest: is having a QApplication instance enough in
unittest to ensure emission of signals? Otherwise your problem does not only
apply to using threads, but to any use of unittest with signals and slots.


* Hook up a slot which gets called when the thread finishes

As I said above, are signals emitted in the FooTest case? I ask because I've
been meaning to add unittest to my applications but I was not sure how to
handle the case of slots and signals.


* Start the event loop by calling QtGui.qApp.exec_()
Have attached a new version of the Bar example, that starts an event 
loop when the thread is started. In this case, the unit test succeeds. 
Bu then again, it this the way to do it?



I think I've tried this in the past and it didn't quite work for me.


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



--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


import time

from PyQt4 import QtCore, QtGui

class Thread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)

def run(self):
for i in range(10):
print i
time.sleep(0.1)

class Widget(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self._finished = False

self._thread = Thread()
self.connect(self._thread, QtCore.SIGNAL('finished()'), self.finished)

self._thread.start()

def finished(self):
self._finished = True





import unittest
import sys
import gc

from PyQt4 import QtCore, QtGui

# Must have an event handler running
QT_APP = QtGui.QApplication(sys.argv)

# Import the module that should be tested
from Bar import Widget

class Runner:
def __init__(self, thread):
self._thread = thread
self._thread.connect(self._thread, QtCore.SIGNAL('finished()'), self.finished)

if self._thread.isRunning():
QtGui.qApp.exec_()

def finished(self):
QtGui.qApp.processEvents()
QtGui.qApp.exit(0)

class BarTest(unittest.TestCase):

def setUp(self):
self._widget = Widget()

def tearDown(self):
del self._widget
gc.collect()

def testWidget(self):
""" Test that the object is OK """
runner = Runner(self._widget._thread)
self.assertTrue(isinstance(self._widget, Widget))
self.assertTrue(isinstance(self._widget, QtGui.QWidget))

def testThread(self):
""" Test that the thread finished """
runner = Runner(self._widget._thread)
self.assertTrue(self._widget._finished)

if __name__ == '__main__':
unittest.main()

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

Re: [PyQt] Unit testing PyQt applications

2012-03-07 Thread Mads Ipsen
Have modified the Bar example, since the thread was never started. Sorry 
for posting an incomplete example.


Anyway, now in this case, running the unittest gives:

FQThread: Destroyed while thread is still running
Segmentation fault


On 07/03/2012 09:43, Luca Beltrame wrote:

In data mercoledì 7 marzo 2012 09:37:38, Mads Ipsen ha scritto:


the Python unittest moudle. I have attached a few examples. If you have
time to take a look and comment, it would be great.

I have a question on FooTest: is having a QApplication instance enough in
unittest to ensure emission of signals? Otherwise your problem does not only
apply to using threads, but to any use of unittest with signals and slots.


* Hook up a slot which gets called when the thread finishes

As I said above, are signals emitted in the FooTest case? I ask because I've
been meaning to add unittest to my applications but I was not sure how to
handle the case of slots and signals.


* Start the event loop by calling QtGui.qApp.exec_()

I think I've tried this in the past and it didn't quite work for me.


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



--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


import time

from PyQt4 import QtCore, QtGui

class Thread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)

def run(self):
for i in range(10):
print i
time.sleep(0.1)

class Widget(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self._finished = False

self._thread = Thread()
self.connect(self._thread, QtCore.SIGNAL('finished'), self.finished)

self._thread.start()

def finished(self):
self._finished = True





import unittest
import sys
import gc

from PyQt4 import QtCore, QtGui

# Must have an event handler running
QT_APP = QtGui.QApplication(sys.argv)

# Import the module that should be tested
from Bar import Widget

class BarTest(unittest.TestCase):

def setUp(self):
self._widget = Widget()

def tearDown(self):
del self._widget
gc.collect()

def testWidget(self):
""" Test that the object is OK """
self.assertTrue(isinstance(self._widget, Widget))
self.assertTrue(isinstance(self._widget, QtGui.QWidget))

def testThread(self):
""" Test that the thread finished """
self.assertTrue(self._widget._finished)

if __name__ == '__main__':
unittest.main()

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

Re: [PyQt] Unit testing PyQt applications

2012-03-07 Thread Mads Ipsen

On 07/03/2012 09:43, Luca Beltrame wrote:

In data mercoledì 7 marzo 2012 09:37:38, Mads Ipsen ha scritto:


the Python unittest moudle. I have attached a few examples. If you have
time to take a look and comment, it would be great.

I have a question on FooTest: is having a QApplication instance enough in
unittest to ensure emission of signals? Otherwise your problem does not only
apply to using threads, but to any use of unittest with signals and slots.
Signals are emitted. You can emulate pressing a button using the static 
utility methods from the QTest module; the slots that the button signal 
is connected to will be called. In some cases, if the called slots 
perform a lot of processing, I usually call QtGui.qApp.processEvents() 
after triggering the event. However, I am not an expert, so I don't know 
if this is the right approach/thing to do.



* Hook up a slot which gets called when the thread finishes

As I said above, are signals emitted in the FooTest case? I ask because I've
been meaning to add unittest to my applications but I was not sure how to
handle the case of slots and signals.


* Start the event loop by calling QtGui.qApp.exec_()

I think I've tried this in the past and it didn't quite work for me.


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



--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


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

[PyQt] Unit testing PyQt applications

2012-03-07 Thread Mads Ipsen

Hi,

I have a general question about how to unit test PyQt applications using 
the Python unittest moudle. I have attached a few examples. If you have 
time to take a look and comment, it would be great.


The first module, Foo.py, defines a simple widget called 'Widget' which 
is tested in FooTest.py. FooTest.py defines an instance of a 
QApplication, which is needed in order to run the test. In this case the 
test runs fine.


The second module, Bar.py, defines a more complex widget, also called 
Widget, which starts a thread in its constructor. In real life, this 
could be a used for generating an icon in the background. This is tested 
in BarTest.py. In this case, the test fails, because the unittest exits 
while the thread is still running.


There are ways to circumvent this, e.g:

* Hook up a slot which gets called when the thread finishes
* Start the event loop by calling QtGui.qApp.exec_()
* Kill the event loop when the slot is called

But this easily becomes messy, when you have a large and complex code 
base, and I was wondering if there's some more generic approach.


I should add, that in my case I have a large nested unittest suite, 
which collects all the individual unittest files. In that case, the 
instance of a QApplication is only started once, by an __init__.py file, 
which gets loaded once, when the entire suite it run.


All that said, if you have any comments, pointers to good approaches, or 
like to share your ideas, I'd be happy to hear them.


Best regards,

Mads



--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


from PyQt4 import QtGui

class Widget(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)




import unittest
import sys
import gc

from PyQt4 import QtGui

# Must have an event handler running
QT_APP = QtGui.QApplication(sys.argv)

# Import the module that should be tested
from Foo import Widget

class ModelTest(unittest.TestCase):

def setUp(self):
self._widget = Widget()

def tearDown(self):
del self._widget
gc.collect()

def testWidget(self):
""" Test that the object is OK """
self.assertTrue(isinstance(self._widget, Widget))
self.assertTrue(isinstance(self._widget, QtGui.QWidget))

if __name__ == '__main__':
unittest.main()

import time

from PyQt4 import QtCore, QtGui

class Thread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)

def run(self):
for i in range(10):
print i
time.sleep(0.1)

class Widget(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self._thread = Thread()
self._thread.start()
self._finished = False

self.connect(self._thread, QtCore.SIGNAL('finished'), self.finished)

def finished(self):
self._finished = True





import unittest
import sys
import gc

from PyQt4 import QtGui

# Must have an event handler running
QT_APP = QtGui.QApplication(sys.argv)

# Import the module that should be tested
from Bar import Widget

class ModelTest(unittest.TestCase):

def setUp(self):
self._widget = Widget()

def tearDown(self):
del self._widget
gc.collect()

def testWidget(self):
""" Test that the object is OK """
self.assertTrue(isinstance(self._widget, Widget))
self.assertTrue(isinstance(self._widget, QtGui.QWidget))

def testThread(self):
""" Test that the thread finished """
self.assertTrue(self._widget._finished)

if __name__ == '__main__':
unittest.main()

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

Re: [PyQt] TableView - activated signal

2012-02-21 Thread Mads Ipsen

On 21/02/2012 16:47, Mateusz Korniak wrote:

On Tuesday 21 of February 2012, Mads Ipsen wrote:

On 21/02/2012 15:32, Mateusz Korniak wrote:

On Tuesday 21 of February 2012, Mads Ipsen wrote:

(...) I attach a snippet that reproduces the issue. So run
the example and try to tell me why the activated signal is NOT triggered
when a cell is clicked, double-clicked, entered etc.

I get handlers called for click, dbl-click, and hitting enter.
python-PyQt4-4.8.5
QtGui-4.7.4


 * But if you navigate around in the cell using arrow keys and then
   press space, the cell is opened, but no signal is triggered.
 * If you then write something in the cell and press TAB to leave the
   cell - no signal is triggered.

Perhaps above are cell contents edits, without activation.


 * Also, I would expect a double-click to also trigger the activated
   signal, since the cell is activated by the double-click.

That works for me:
activate on cell[1,1]
doubleClick on cell[1,1]

Any idea why this fails for me? Because I use Gnome? Bug?

In short: What does it mean that a cell is activated? What actions will
trigger this signal?

"This signal is emitted when the item specified by index is activated by the
user. How to activate items depends on the platform; e.g., by single- or
double-clicking the item, or by pressing the Return or Enter key when the item
is current" ?

Regards,




--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


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

Re: [PyQt] TableView - activated signal

2012-02-21 Thread Mads Ipsen

On 21/02/2012 15:32, Mateusz Korniak wrote:

On Tuesday 21 of February 2012, Mads Ipsen wrote:

(...) I attach a snippet that reproduces the issue. So run
the example and try to tell me why the activated signal is NOT triggered
when a cell is clicked, double-clicked, entered etc.


I get handlers called for click, dbl-click, and hitting enter.
python-PyQt4-4.8.5
QtGui-4.7.4

Regards,


This works for me also - except for single-click which triggers nothing.

   * But if you navigate around in the cell using arrow keys and then
 press space, the cell is opened, but no signal is triggered.
   * If you then write something in the cell and press TAB to leave the
 cell - no signal is triggered.
   * Also, I would expect a double-click to also trigger the activated
 signal, since the cell is activated by the double-click.


In short: What does it mean that a cell is activated? What actions will 
trigger this signal?


Best regards,

Mads

--
+-+
| Mads Ipsen  |
+--+--+
| Ga*seb?ksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


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

[PyQt] TableView - activated signal

2012-02-21 Thread Mads Ipsen

Hi,

Sorry for bugging you with the same issue again.

Last week I posted a problem regarding QTableView and the triggering of 
its activated signal. I didn't get any response - maybe I was too vague 
in the statement of the problem?


Anyway, this time I attach a snippet that reproduces the issue. So run 
the example and try to tell me why the activated signal is NOT triggered 
when a cell is clicked, double-clicked, entered etc.


Best regards,

Mads

--
+-+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


import sys
from PyQt4 import QtGui, QtCore

class Table(QtGui.QTableView):
def __init__(self):
QtGui.QTableView.__init__(self)

# Hook up model
self._model = QtGui.QStandardItemModel(3,3)
self.setModel(self._model)

# Add dummy data
for i in range(3):
for j in range(3):
item = QtGui.QStandardItem('(%d,%d)' % (i,j))
self._model.setItem(i,j,item)

# Connect
self.connect(self, QtCore.SIGNAL('doubleClicked(const QModelIndex &)'), self.doubleClicked)
self.connect(self, QtCore.SIGNAL('activated(const QModelIndex &)'), self.activated)

def doubleClicked(self, index):
print 'doubleClick on cell[%d,%d]' % (index.row(), index.column())

def activated(self, index):
print 'activate on cell[%d,%d]' % (index.row(), index.column())

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

table = Table()
table.show()

sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] activated signal

2012-02-17 Thread Mads Ipsen

Hi,

I have a QTableView. If I connect with

  self.connect(self.table, QtCore.SIGNAL('activated(const QModelIndex 
&)'), self.tableActivated)


the method tableActivated() is *not* called when I double-click a cell 
or enter via space press etc.


However, if I do

  self.connect(self.table, QtCore.SIGNAL('doubleClicked(const 
QModelIndex &)'), self.tableActivated)


the method is called when a cell is double-clicked.

What am I doing wrong?

Mads



--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


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

[PyQt] Hardcoded fonts in Qt designer

2011-11-30 Thread Mads Ipsen

On Ubuntu 11.04:

* Start Designer and use the basic widget template
* Add a QLabel.
* Right-click the label and enter rich-text editing
* Add some text with a superscript.

Now click the source tab. This is what I find:

"http://www.w3.org/TR/REC-html40/strict.dtd";>




p, li { white-space: pre-wrap; }

</pre><tt>


A2



Now, do perform the same exercise on Windows 7. Then the rich-text 
source will look like this:



"http://www.w3.org/TR/REC-html40/strict.dtd";>




p, li { white-space: pre-wrap; }



A1


Now, if you work in a cross-platform development where developers (on 
different OS's ie.) share UI files via a GIT repository, this quickly 
becomes a mess. Any suggestions?



Preprocess all .ui files and chop out






Best regards,


Mads


--
+-----+
| Mads Ipsen  |
+--+--+
| Gåsebæksvej 7, 4. tv |  |
| DK-2500 Valby| phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


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

[PyQt] Drag icons in QFileDialog

2011-09-23 Thread Mads Ipsen

Hi,

I have reverse engineered the QFileDialog class so it can be used as a 
file browser. Now I'd like to be able to access the underlying machinery 
in such a way that I can control the displayed drag icons when e.g. a 
file with the .py extension is being dragged.


Any clues to where I should start digging in order to control the 
displayed drag icons?


Best regards,

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


Re: [PyQt] Word wrap in QLabel - strange resizing - rephrased

2011-08-22 Thread Mads Ipsen

Thanks.

It seems strange to me though, that something like this even can be an 
issue, in the sense that it haven't been fixed ages ago. But maybe it 
isn't as trivial as it looks?


Mads

On 08/22/2011 12:39 PM, Jeremy Sanders wrote:

Mads Ipsen wrote:


I've attached a small example, displaying two widgets which both include
a QLabel: one with wordwrap on, and one without. Try to resize the two
widgets and see if you can reproduce the behavior.

This must be a bug, right?

This is a fairly well known Qt bug but I can't find the proper reference.
Here is some discussion for instance

http://www.qtcentre.org/threads/8766-Qt-layouting-QLabel-s-word-wrap-bug

If you go to the Qt bug tracker and search for QLabel wordwrap and layout
you find a whole pile of issues like this.

Jeremy




--
+-----+
| Mads Ipsen  |
+--+--+
| Florsgade 7, 4. th   |  |
| DK-2200 København N  | phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


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


[PyQt] Word wrap in QLabel - strange resizing - rephrased

2011-08-22 Thread Mads Ipsen

Sorry for my extremely sloppy writing. I'll try again:

Hi,

If you set wordWrap to True for a QLabel which has been added to a 
widget with a layout, the resizing of the parent widget is kinda 
strange: The widget can be resized to nothing etc.


I've attached a small example, displaying two widgets which both include 
a QLabel: one with wordwrap on, and one without. Try to resize the two 
widgets and see if you can reproduce the behavior.


This must be a bug, right?

Best regards,

Mads

import sys
from PyQt4 import QtCore, QtGui

class Label(QtGui.QLabel):
"""
   Class for defining a word wrapped label.
"""
def __init__(self, parent=None):
"""
   Constructor.
"""
# Call base class constructor
QtGui.QLabel.__init__(self, parent)

# Add some text
text = """Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."""
self.setText(text)

class Widget(QtGui.QWidget):
def __init__(self, word_wrap=False, parent=None):
"""
   Constructor.
"""
# Call base class constructor
QtGui.QWidget.__init__(self, parent)

# Add some text
layout = QtGui.QVBoxLayout()
self.setLayout(layout)

# Add some widgets
label = Label()
label.setWordWrap(word_wrap)
layout.addWidget(label)

push_button = QtGui.QPushButton('Press me')
layout.addWidget(push_button)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

widget1 = Widget(word_wrap=False)
widget1.show()

widget2 = Widget(word_wrap=True)
widget2.show()

sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Word wrap in QLabel - strange resizing

2011-08-22 Thread Mads Ipsen

Hi,

If you set wordWrap to True for a QLabel in widget the layout, the 
resizing of the widget is kinda strange: The widget can be resized to 
nothing etc. I've attached a small example, displaying two widgets: One 
with and one without wordwrap. This must be a bug, right?


Best regards,

Mads
import sys
from PyQt4 import QtCore, QtGui

class Label(QtGui.QLabel):
"""
   Class for defining a word wrapped label.
"""
def __init__(self, parent=None):
"""
   Constructor.
"""
# Call base class constructor
QtGui.QLabel.__init__(self, parent)

# Add some text
text = """Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."""
self.setText(text)

class Widget(QtGui.QWidget):
def __init__(self, word_wrap=False, parent=None):
"""
   Constructor.
"""
# Call base class constructor
QtGui.QWidget.__init__(self, parent)

# Add some text
layout = QtGui.QVBoxLayout()
self.setLayout(layout)

# Add some widgets
label = Label()
label.setWordWrap(word_wrap)
layout.addWidget(label)

push_button = QtGui.QPushButton('Press me')
layout.addWidget(push_button)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

widget1 = Widget(word_wrap=False)
widget1.show()

widget2 = Widget(word_wrap=True)
widget2.show()

sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Screenshot with no show

2011-06-21 Thread Mads Ipsen

Hi,

I have a GLWidget (OpenGL) based window which is used for displaying 
chemical structures. I would like to use this window to generate 
thumbnails used as icons for the files containing the chemical structures.


I would like to hide this process of icon generation from the user, so 
is there any way that you can


   * Show/display a GLWidget/QWidget in some sort of virtual frame
 buffer, in such a way that is does NOT appear visual to the user.
   * Dump the contents of the invisible window into a pixmap.

Best regards,

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

Re: [PyQt] Position widgets over widgets

2011-04-07 Thread Mads Ipsen

Hi,

I tried that, but is does not seem to work. The 'XXX' is still hidden by 
the widget in the layout.


What I eventually would like to achieve is to add a QPushButton in, say, 
the upper left corner of the parent widget.


I have attached a similar example, this time with a QPushButton. This 
QPushButton is rendered useless (i.e.) you cannot press it.


I thought solving this problem would be a walk in the park. Any clues?

Best regards,

Mads


On 2011-04-07 15:19, Hans-Peter Jansen wrote:

On Thursday 07 April 2011, 14:58:30 Mads Ipsen wrote:

Hi,

I have attached a simple example where a widget sets up two labels.
One which is added to the layout of the widget, and one which is not.

In the paintEvent() of the parent widget I instead position the
non-layout label using setGeometry to make it appear in the center of
the parent widget.

However, the label positioned by this approach is always obscured by
the widget which was added to the layout. I want it to appear as
visible, i.e. visible on top of the parent widget.

Create _label2 after _label1, but this is a questionable approach.

Why can't you use something like QStackedLayout?

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


--
+-----+
| Mads Ipsen  |
+--+--+
| Florsgade 7, 4. th   |  |
| DK-2200 København N  | phone:  +45-29716388 |
| Denmark  | email:  mads.ip...@gmail.com |
+--+--+


import sys

from PyQt4 import QtGui

class Widget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self)

self._label  = QtGui.QLabel('A Label')
self._button = QtGui.QPushButton('&Push Me', self)

layout = QtGui.QVBoxLayout()
self.setLayout(layout)
layout.addWidget(self._label)

def paintEvent(self, event):
w = self._button.width()
h = self._button.height()

x = (self.rect().width()  - w)/2.0
y = (self.rect().height() - h)/2.0
self._button.setGeometry(x,y,w,h)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

widget = Widget()
widget.show()

sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Position widgets over widgets

2011-04-07 Thread Mads Ipsen

Hi,

I have attached a simple example where a widget sets up two labels. One 
which is added to the layout of the widget, and one which is not.


In the paintEvent() of the parent widget I instead position the 
non-layout label using setGeometry to make it appear in the center of 
the parent widget.


However, the label positioned by this approach is always obscured by the 
widget which was added to the layout. I want it to appear as visible, 
i.e. visible on top of the parent widget.


Any clues?

Best regards,

Mads
import sys

from PyQt4 import QtGui

class Widget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self)

self._label2 = QtGui.QLabel('XXX', self)
self._label2.show()
self._label1 = QtGui.QLabel()

self._label1.setAutoFillBackground(True)
palette = QtGui.QPalette()
palette.setColor(self._label1.backgroundRole(), QtGui.QColor('blue'))
self._label1.setPalette(palette)

layout = QtGui.QVBoxLayout()
self.setLayout(layout)
layout.addWidget(self._label1)

def paintEvent(self, event):
w = self._label2.width()
h = self._label2.height()

x = (self.rect().width()  - w)/2.0
y = (self.rect().height() - h)/2.0
self._label2.setGeometry(x,y,w,h)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

widget = Widget()
widget.show()

sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] QTextEdit 80 chars wide

2011-01-27 Thread Mads Ipsen

Hi,

Suppose I have a QTextEdit set up with a monospace font. How do I make 
the text edit field exactly 80 chars wide? E.g. similar to a command 
prompt window.


Best regards,

Mads

--
+--+
| Mads Ipsen, Scientific developer |
+---+--+
| QuantumWise A/S   | phone:  +45-29716388 |
| Lersø Parkallé 107| www: www.quantumwise.com |
| DK-2100 Copenhagen Ø, Denmark | email:  mads.ip...@gmail.com |
+---+--+


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


[PyQt] GMail

2010-12-08 Thread Mads Ipsen

Hi,

If I post a message in the mailing list from my gmail account, my own 
post does not appear in my inbox. Has anybody here experienced a similar 
problem?


Best regards,

Mads

--
+--+
| Mads Ipsen, Scientific developer |
+---+--+
| QuantumWise A/S   | phone:  +45-29716388 |
| Nørre Søgade 27A  | www: www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  mads.ip...@gmail.com |
+---+--+


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


[PyQt] Select text in QMessageBox

2010-07-01 Thread Mads Ipsen
How do I make the text selectable (for mouse copy and paste) in a 
QMessageBox?


On Linux, it works by default, but on windows, the text cannot be selected.

Any clues?

Best regards,

Mads

--
+--+
| Mads Ipsen, Scientific developer |
+---+--+
| QuantumWise A/S   | phone:  +45-29716388 |
| Nørre Søgade 27A  | www: www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  mads.ip...@gmail.com |
+---+--+


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


Re: [PyQt] Overpainting example does not work

2010-04-20 Thread Mads Ipsen

1. The output from glxinfo yields:

name of display: :0.0
display: :0  screen: 0
direct rendering: Yes
server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
server glx extensions:
   GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_SGIX_fbconfig,
   GLX_SGIX_pbuffer, GLX_SGI_video_sync, GLX_SGI_swap_control,
   GLX_EXT_swap_control, GLX_EXT_texture_from_pixmap, 
GLX_ARB_create_context,
   GLX_ARB_create_context_profile, GLX_ARB_multisample, 
GLX_NV_float_buffer,

   GLX_ARB_fbconfig_float, GLX_EXT_framebuffer_sRGB

2. In fact I can make the example work by adding the lines

 glShadeModel(GL_FLAT)
 glDisable(GL_CULL_FACE)
 glDisable(GL_DEPTH_TEST)
 glDisable(GL_LIGHTING)

just after the line


 glCallList(self.object)

in the method paintEvent().

3. BTW - Isn't the second call to painter.fillRect() in 
drawInstructions() method redundant?


   painter.setRenderHint(QtGui.QPainter.TextAntialiasing)
   painter.fillRect(QtCore.QRect(0, 0, self.width(), rect.height() 
+ 2*border), QtGui.QColor(0, 0, 0, 127))

   painter.setPen(QtCore.Qt.white)
   painter.fillRect(QtCore.QRect(0, 0, self.width(), rect.height() 
+ 2*border), QtGui.QColor(0, 0, 0, 127))


Best regards,

Mads


David Boddie wrote:

On Mon Apr 19 20:55:32 BST 2010, Mads Ipsen wrote:

  

The overpainting example does not work on my computer - no bubbles nor
text is painted on top of the OpenGL scene. Anybody that can confirm this?



Can you give some details about your system? In particular, it would be
interesting to know what kind of graphics card you have and what sort of
driver support it has for OpenGL. It may be that one of the OpenGL extensions
is required for this example to work - it's a long time since I've looked at
OpenGL.

Doing a simple test on my old laptop with Qt 4.3.2, PyQt 4.3 and OpenGL 1.3
shows that it still works for me. According to glxinfo, my system has a
number of extensions as well:

  ...
  OpenGL renderer string: Mesa DRI Intel(R) 845G 20061017 x86/MMX/SSE2
  OpenGL version string: 1.3 Mesa 7.0.1
  OpenGL extensions:
  GL_ARB_imaging, GL_ARB_multisample, GL_ARB_multitexture,
  ...

Maybe multisampling is required for this example. Can you check to see if
you have problems with any of the other PyQt OpenGL examples, and take a look
at the PyOpenGL examples to see if any of those fail to work as expected?

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



--
+------+
| Mads Ipsen, Scientific developer |
+---+--+
| QuantumWise A/S   | phone:  +45-29716388 |
| Nørre Søgade 27A  | www: www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  mads.ip...@gmail.com |
+---+--+


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


[PyQt] Overpainting example does not work

2010-04-19 Thread Mads Ipsen

Hey,

The overpainting example does not work on my computer - no bubbles nor 
text is painted on top of the OpenGL scene. Anybody that can confirm this?


Best regards,

Mads

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  madsip...@gmail.com |
+---+-+


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


[PyQt] Show selected rows

2010-03-16 Thread Mads Ipsen

Dear Gurus,

Suppose I have a table model that I view in a QTableView (A). In another 
QTableView (B) I want to display the rows that are selected in the first 
QTableView (A).


How do I achieve this? Ie, each selected row in view (A) should be 
displayed in view (B).


Best regards,

Mads

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] Disposing of a QApplication

2010-03-12 Thread Mads Ipsen

Sybren A. Stüvel wrote:

Hi all,

I'm working on a PyQt GUI application using PyQt 4.6 and Python 2.6. According 
to the documentation:


For any GUI application using Qt, there is precisely one QApplication 
object

This is true for our application, but not for our unit tests. They start and 
stop a QApplication in quick succession, so when the test stops it has to shut 
down and dispose of the application properly. The application instance is 
stored in 'self.app' of the unittest class, but just doing 'del self.app' 
doesn't destroy the application (probably because there are other references 
to it in the Qt modules).


Right now I start a separate thread that waits for a bit and then sends the 
application the quit() signal. Then I start the application's main loop, so 
that it is running when it receives the quit() signal from the other thread. 
Of course, this is not an ideal way.


I tried a single-threaded approach by first sending it the quit() signal and 
then run app.exec_() but that doesn't stop the application. Another approach I 
used was to try and replace the event loop with the following code, but that 
also doesn't stop the application.


def aboutToQuit():
self.fail("Quitting!")

self.app.aboutToQuit.connect(aboutToQuit)


# Send the quit event and let the application process it.
start_time = time.time()
while not self.app.closingDown():
self.app.quit()
self.app.processEvents()
self.app.sendPostedEvents(self.app, 0)
self.app.flush()

time.sleep(0.01)

# Wait three seconds for the app to stop.

if time.time() - start_time > 3.0:
self.fail("Failed to quit the application")

del self.app

self.fail("Done")

It's done in a unittest.TestCase class, and the self.fail() calls are there so 
that I can quickly see what's going on.


What would you recommend?

  



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

We have a module that contains one instance of the QApplication object

QT_APP = QtGui.QApplication(sys.argv)

All unit tests include this module - I believe this makes QT_APP a 
single object.


Best regards,

Mads


--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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

[PyQt] Uppercase QLineEdit

2010-01-25 Thread Mads Ipsen

Hi,

I need to construct a QLineEdit that displays everything in upper-case. 
In native Qt this can be done via a QValidator using something along the 
lines


 pqUpcaseValidator::pqUpcaseValidator( QWidget* Parent, const char* 
Name )

 : QValidator( Parent, Name )
 {}

 QValidator::State pqUpcaseValidator::validate( QString& Text , 
int& Pos ) const

 {
 Text = Text.upper();
 return Acceptable;
 }

but how do I do something similar in PyQt, where it's not obvious how 
you handle strings by reference and also have limited support for 
modifying strings in-place?Uppercase


Any help/directions are welcome.

Best, Mads



--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] fixup in QValidator

2010-01-25 Thread Mads Ipsen

Hi,

I can't figure out how to use/implement the fixup() method of a 
QValidator. Any suggestions?


Best regards,

Mads

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] QString looks strang in online docs

2010-01-25 Thread Mads Ipsen

Doesn't QString look a little strange here:

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qvalidator.html#fixup-2

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] Getting a couple errors when I try and start a QMainWindow from a QMainWindow

2010-01-08 Thread Mads Ipsen

dizou wrote:

Solved this.
  

How?

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] Treeview with exclusive checkboxes - used to work

2010-01-08 Thread Mads Ipsen

Hi,

Some time ago I wrote a simple extension to the QStandardItemModel class 
that permits exclusive checkboxes in a treeview, ie. radio button 
behavior.  This no longer works. 

If you check the first item, and then check one of the other, the first 
item it not unchecked. If you then navigate with the keyboard to the 
first item, it then becomes unchecked once you enter it (update/repaint 
not called?).


Strangely enough, for all the other N-1 items, the behavior is 
completely as expected.


Is this a Qt bug?

Minimal example included below:

import sys
from PyQt4 import QtCore, QtGui

class ExclusiveModel(QtGui.QStandardItemModel):
   def __init__(self, parent=None):
   QtGui.QStandardItemModel.__init__(self, parent)

   def setData(self, index, value, role=QtCore.Qt.EditRole):
   # Call base class method
   return_value = QtGui.QStandardItemModel.setData(self, index, 
value, role)


   # Check if all other items must be unchecked
   if role == QtCore.Qt.CheckStateRole:
   changed_item = self.itemFromIndex(index)

   if changed_item.checkState() == QtCore.Qt.Checked:
   for row in range(self.rowCount()):
   item = self.item(row, 0)
   if item.text() != changed_item.text():
   new_value = QtCore.QVariant(QtCore.Qt.Unchecked)
   new_index = self.indexFromItem(item)
   QtGui.QStandardItemModel.setData(self, 
new_index, new_value, role)


   return return_value
  
class View(QtGui.QTreeView):

   """
  Class for defining a widget for holding the analysis and 
calculator views.

   """
   def __init__(self, parent=None):
   """
  Constructor.
   """
   # Call base class constructor
   QtGui.QTreeView.__init__(self, parent)

   # model
   self._model = ExclusiveModel()
   for value in ['Why', 'does', 'this', 'not', 'work']:
   item = QtGui.QStandardItem(value)
   item.setCheckable(True)
   self._model.appendRow([item])

   # Add the elements
   self.setModel(self._model)

if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)

   widget = View()
   widget.show()

   sys.exit(app.exec_())

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] Always on top on windows

2010-01-05 Thread Mads Ipsen

When I launch a QWidget from another widget as

 window_flags = QtCore.Qt.WindowFlags() | QtCore.Qt.Window
 self._widget = QtGui.QWidget(self, QtCore.Qt.Window)
 self._widget.show()

where self is a class inheriting from QWidget, the new widget has self 
as parent but appears in a separate window with its own frame etc.


* On Linux, the parent and child can be active completely independent of 
other.

* On XP, the child is always on top of the parent window.

The XP behavior is dead annoying. Any suggestions on how to get rid of tis'?

Best regards,

Mads

Minimal example app included below:

import sys
from PyQt4 import QtCore, QtGui

class Widget(QtGui.QWidget):
   def __init__(self, parent=None, window_flags=QtCore.Qt.WindowFlags()):
   QtGui.QWidget.__init__(self, parent, window_flags)

   # Add layuot
   layout = QtGui.QVBoxLayout(self)
   self.setLayout(layout)

   # Add a push button
   self._push_button = QtGui.QPushButton('Push me')
   layout.addWidget(self._push_button)

   # Connect it
   self.connect(self._push_button, QtCore.SIGNAL('clicked()'), 
self.clicked)


   def clicked(self):
   window_flags = QtCore.Qt.WindowFlags() | QtCore.Qt.Window
   self._widget = QtGui.QWidget(self, QtCore.Qt.Window)
   self._widget.show()
  


if __name__ == '__main__':
   app = QtGui.QApplication(sys.argv)

   widget = Widget()
   widget.show()
   sys.exit(app.exec_())

--
+-----+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] Object::disconnect: Unexpected null parameter

2009-11-27 Thread Mads Ipsen

After having upgraded from

sip-4.9.1 and PyQt-4.6.1

to

sip-4.9.3 and PyQt-4.6.2

on both Win32 and Linux, we literally get 100's of warnings of the form

 Object::disconnect: Unexpected null parameter

when running our unit test suite. Since I have never seen this before 
I'm puzzled as what to look for. Any clues?


Best regards,

Mads


--
+-----+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] Error when double clicking

2009-11-17 Thread Mads Ipsen

dizou wrote:

I have a class that inherits QTreeWidget, in the __init__ I am trying to
connect a double click with a function:


class TreeArea(QTreeWidget):
def __init__(self, parent):
.
.
.
self.connect(self, SIGNAL("itemDoubleClicked(QTreeWidgetItem *)"),
self.edit)

def edit(self, item):
   .
   .
   .

However, when I run the program and click on an item I get this error:
TypeError: edit() takes exactly 2 arguments (4 given)

Also, what is the PyQt equivalent of:
setEditTriggers(QAbstractItemView::NoEditTriggers)
  

I also get the same error with the example included below. Any clues?


import sys
from PyQt4 import QtCore, QtGui


class TreeWidget(QtGui.QTreeWidget):
   def __init__(self, parent=None):
   QtGui.QTreeWidget.__init__(self, parent)

   # Add an item
   item = QtGui.QTreeWidgetItem(['1'], 0)
   self.addTopLevelItem(item)

   # Connect
   self.connect(self, QtCore.SIGNAL('itemDoubleClicked ( 
QTreeWidgetItem *, int)'), self.edit)


   def edit(self, item, column):
   print 'Clicked'

if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)

   widget = TreeWidget()
   widget.show()

   sys.exit(app.exec_())

--
+-----+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] insert a radio button in menu of menubar

2009-11-12 Thread Mads Ipsen

vidyadhar wrote:

I want to have a radio button on menu entries in the menubar.

eg: like a gedit in linux

please help me out
thanks

  

* Set up the desired QAction's.
* Add them to a QActionGroup.
* Set the group to be exclusive (setExclusive(True)).
* Add the actions to your menubar.

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] How to read this mailing list?

2009-11-04 Thread Mads Ipsen

Piotr Byzia wrote:

Hi,

I wonder how do you read this list?
Separate emails is not the most convenient way as there are app. 350 
messages per month.

Daily Digest is messy when replying.

Is there any online front-end where I can read messages, search the 
list, and answer to a given message?


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



http://news.gmane.org/gmane.comp.python.pyqt-pykde

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] WaitCursor is ignored

2009-11-03 Thread Mads Ipsen

Baz Walter wrote:

Mads Ipsen wrote:

Hey,

I want to display a widget as disabled (setEnabled(False)) with its 
cursor set to Qt.WaitCursor.


Disabling the widget, however, always display the widget with a 
normal Qt.ArrowCursor if if the cursor is changed. How do I obtain a 
disabled widget with a Qt.WaitCursor?


i suppose this is because disabled widgets don't handle mouse events.

put the widget inside a container widget (which always stays enabled), 
and then set the cursor on the container.



Things is:

It fails on Ubuntu 8.04, KUbuntu 9.04 and Ubuntu 9.04 with Qt 4.5.2.

But it works on Mac OS X with Qt 4.6.0-beta and XPSP3 with Qt 4.3.3.

I believe it's a Qt bug.

Mads


--
+-----+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] pyuic : backslash escaping with untranslatable strings

2009-11-03 Thread Mads Ipsen

Mads Ipsen wrote:

Felix Schmidt wrote:

Hi,
I got the following bug (or Feature?) in pyuic :

With Qt Designer I created a QLineEdit with inputMask set to 
"\0\x>;_" (to input a hex-value like "0x12AB").

So far it's fine.
But when I uncheck the "translatable" flag of this inputMask (don't 
want it to be translated in any language),

pyuic doesn't escape the backslashes anymore.
I get a "ValueError: invalid \x escape" on line
> self.linHexcode.setInputMask("\0\x>;_")

With the translatable Flag set again, pyuic correctly generates a
> 
self.linHexcode.setInputMask(QtGui.QApplication.translate("AddSlaveDialog", 
"\\0\\x>;_", None, QtGui.QApplication.UnicodeUTF8))


With other string properties (instead of "inputMask") it's the same 
thing.


Is there any way to get this fixed? (Of course, i can just ignore 
this string in Linguist, but its not the neat solution. Manually 
escape the string in Qt Designer isn't either.)


Thanks,
Felix Schmidt

Versions:
Python 2.6
Qt 4.5.3
PyQt 4.6
sip 4.9


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


Things is:

It fails on Ubuntu 8.04, KUbuntu 9.04 and Ubuntu 9.04 with Qt 4.5.2.

But it works on Mac OS X with Qt 4.6.0-beta and XPSP3 with Qt 4.3.3. I 
believe its a Qt bug.


Mads







Really sorry - forget the above reply - was meant for a different post.

Mads

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] pyuic : backslash escaping with untranslatable strings

2009-11-03 Thread Mads Ipsen

Felix Schmidt wrote:

Hi,
I got the following bug (or Feature?) in pyuic :

With Qt Designer I created a QLineEdit with inputMask set to 
"\0\x>;_" (to input a hex-value like "0x12AB").

So far it's fine.
But when I uncheck the "translatable" flag of this inputMask (don't 
want it to be translated in any language),

pyuic doesn't escape the backslashes anymore.
I get a "ValueError: invalid \x escape" on line
> self.linHexcode.setInputMask("\0\x>;_")

With the translatable Flag set again, pyuic correctly generates a
> 
self.linHexcode.setInputMask(QtGui.QApplication.translate("AddSlaveDialog", 
"\\0\\x>;_", None, QtGui.QApplication.UnicodeUTF8))


With other string properties (instead of "inputMask") it's the same 
thing.


Is there any way to get this fixed? (Of course, i can just ignore this 
string in Linguist, but its not the neat solution. Manually escape the 
string in Qt Designer isn't either.)


Thanks,
Felix Schmidt

Versions:
Python 2.6
Qt 4.5.3
PyQt 4.6
sip 4.9


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


Things is:

It fails on Ubuntu 8.04, KUbuntu 9.04 and Ubuntu 9.04 with Qt 4.5.2.

But it works on Mac OS X with Qt 4.6.0-beta and XPSP3 with Qt 4.3.3. I 
believe its a Qt bug.


Mads






--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] WaitCursor is ignored

2009-11-03 Thread Mads Ipsen

Hey,

I want to display a widget as disabled (setEnabled(False)) with its 
cursor set to Qt.WaitCursor.


Disabling the widget, however, always display the widget with a normal 
Qt.ArrowCursor if if the cursor is changed. How do I obtain a disabled 
widget with a Qt.WaitCursor? Code that reproduces the problem is shown 
below.


Best regards,

Mads

import sys

from PyQt4 import QtCore, QtGui

if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)

   widget = QtGui.QWidget()
   widget.show()
   widget.setEnabled(False)

   cursor = QtGui.QCursor(QtCore.Qt.WaitCursor)
   widget.setCursor(cursor)

   sys.exit(app.exec_())


--
+-----+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] Block for interactions

2009-10-30 Thread Mads Ipsen
I have a widget with a start button. When the start button is pressed 
the cursor changes to a WaitCursor (hour-glass shaped cursor). In the 
same instant, I want all user-interaction with the widget to be blocked. 
That is, the widget should change to the same state it has when being 
blocked by a modal dialog.


Is this just calling setEnabled(False) or is there some more specific 
method? A blocked widget look different from a disabled widget.


Best regards,

Mads

--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] Wrong cursor

2009-10-29 Thread Mads Ipsen
The script below should display a QWidget with a Qt::SizeAllCursor. 
Instead it displays a Qt::ClosedHandCursor. Bug?


System information
Linux
Python 2.6.1
Qt 4.5.2
PyQt 4.5.4

Mads

import sys
from PyQt4 import QtCore, QtGui

if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)

   widget = QtGui.QWidget()
   widget.show()

   cursor = QtGui.QCursor(QtCore.Qt.SizeAllCursor)
   widget.setCursor(cursor)

   sys.exit(app.exec_())

--
+-----+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] QValidator raises TypeError

2009-10-20 Thread Mads Ipsen

Phil Thompson wrote:

On Tue, 20 Oct 2009 13:01:01 +0200, Mads Ipsen  wrote:
  
I am trying to implement a simple validator for a QLineEdit. To do this 
you should inherit from QtGui.QValidator and overload the method 
validate(). The validate method should then return either of the flags:


QtGui.QValidator.Invalid
QtGui.QValidator.Intermediate
QtGui.QValidator.Acceptable

Below is included a simple example that always returns 
QtGui.QValidator.Acceptable. Nevertheless, the programs raises the error


  TypeError: invalid result type from Validator.validate()

no matter what you type in the line edit.

Any suggestions?

Best, Mads


import sys
from PyQt4 import QtGui

class Validator(QtGui.QValidator):
def __init__(self, parent=None):
QtGui.QValidator.__init__(self, parent)

def validate(self, string, pos):
return QtGui.QValidator.Acceptable



The Python API is different to the C++ API because the latter updates the
reference to "pos". The Python API needs you to return the (possibly
different) position. Try...

return (QtGui.QValidator.Acceptable, pos)

Phil

  

Yep, that does it.

Thanks!!!

--
+-----+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] QValidator raises TypeError

2009-10-20 Thread Mads Ipsen
I am trying to implement a simple validator for a QLineEdit. To do this 
you should inherit from QtGui.QValidator and overload the method 
validate(). The validate method should then return either of the flags:


QtGui.QValidator.Invalid
QtGui.QValidator.Intermediate
QtGui.QValidator.Acceptable

Below is included a simple example that always returns 
QtGui.QValidator.Acceptable. Nevertheless, the programs raises the error


 TypeError: invalid result type from Validator.validate()

no matter what you type in the line edit.

Any suggestions?

Best, Mads


import sys
from PyQt4 import QtGui

class Validator(QtGui.QValidator):
   def __init__(self, parent=None):
   QtGui.QValidator.__init__(self, parent)

   def validate(self, string, pos):
   return QtGui.QValidator.Acceptable
  


if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)

   line_edit = QtGui.QLineEdit()
   line_edit.setValidator(Validator())
   line_edit.show()

   sys.exit(app.exec_())

--
+-----+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


[PyQt] PyQt 4.6 build wanings

2009-10-17 Thread Mads Ipsen

Dear Phil,

Here's a little something for the purist

System:

gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
Ubuntu 8.04
Qt 4.6-beta

Warnings:
==
g++ -c -pipe -fPIC -O2 -Wall -W -D_REENTRANT -DNDEBUG -DQT_NO_DEBUG 
-DQT_CORE_LIB -I. 
-I/home/mpi/tmp/Python/PyQt-x11-gpl-4.6.1-snapshot-20091014/qpy/QtCore 
-I/home/mpi/usr/include/python2.6 
-I/home/mpi/usr/Trolltech/Qt-4.6.0/mkspecs/default 
-I/home/mpi/usr/Trolltech/Qt-4.6.0/include/QtCore 
-I/home/mpi/usr/Trolltech/Qt-4.6.0/include -I/usr/X11R6/include -o 
sipQtCoreQDateTime.o sipQtCoreQDateTime.cpp
sip/QtCore/qdatetime.sip: In function ‘PyObject* 
meth_QDateTime_toPyDateTime(PyObject*, PyObject*)’:
sip/QtCore/qdatetime.sip:488: warning: deprecated conversion from string 
constant to ‘char*’
sip/QtCore/qdatetime.sip:488: warning: deprecated conversion from string 
constant to ‘char*’
sip/QtCore/qdatetime.sip: In function ‘int 
convertTo_QDateTime(PyObject*, void**, int*, PyObject*)’:
sip/QtCore/qdatetime.sip:360: warning: deprecated conversion from string 
constant to ‘char*’
sip/QtCore/qdatetime.sip:360: warning: deprecated conversion from string 
constant to ‘char*’
g++ -c -pipe -fPIC -O2 -Wall -W -D_REENTRANT -DNDEBUG -DQT_NO_DEBUG 
-DQT_CORE_LIB -I. 
-I/home/mpi/tmp/Python/PyQt-x11-gpl-4.6.1-snapshot-20091014/qpy/QtCore 
-I/home/mpi/usr/include/python2.6 
-I/home/mpi/usr/Trolltech/Qt-4.6.0/mkspecs/default 
-I/home/mpi/usr/Trolltech/Qt-4.6.0/include/QtCore 
-I/home/mpi/usr/Trolltech/Qt-4.6.0/include -I/usr/X11R6/include -o 
sipQtCoreQTime.o sipQtCoreQTime.cpp
sip/QtCore/qdatetime.sip: In function ‘PyObject* 
meth_QTime_toPyTime(PyObject*, PyObject*)’:
sip/QtCore/qdatetime.sip:302: warning: deprecated conversion from string 
constant to ‘char*’
sip/QtCore/qdatetime.sip:302: warning: deprecated conversion from string 
constant to ‘char*’
sip/QtCore/qdatetime.sip: In function ‘int convertTo_QTime(PyObject*, 
void**, int*, PyObject*)’:
sip/QtCore/qdatetime.sip:214: warning: deprecated conversion from string 
constant to ‘char*’
sip/QtCore/qdatetime.sip:214: warning: deprecated conversion from string 
constant to ‘char*’
g++ -c -pipe -fPIC -O2 -Wall -W -D_REENTRANT -DNDEBUG -DQT_NO_DEBUG 
-DQT_CORE_LIB -I. 
-I/home/mpi/tmp/Python/PyQt-x11-gpl-4.6.1-snapshot-20091014/qpy/QtCore 
-I/home/mpi/usr/include/python2.6 
-I/home/mpi/usr/Trolltech/Qt-4.6.0/mkspecs/default 
-I/home/mpi/usr/Trolltech/Qt-4.6.0/include/QtCore 
-I/home/mpi/usr/Trolltech/Qt-4.6.0/include -I/usr/X11R6/include -o 
sipQtCoreQDate.o sipQtCoreQDate.cpp
sip/QtCore/qdatetime.sip: In function ‘PyObject* 
meth_QDate_toPyDate(PyObject*, PyObject*)’:
sip/QtCore/qdatetime.sip:119: warning: deprecated conversion from string 
constant to ‘char*’
sip/QtCore/qdatetime.sip:119: warning: deprecated conversion from string 
constant to ‘char*’
sip/QtCore/qdatetime.sip: In function ‘int convertTo_QDate(PyObject*, 
void**, int*, PyObject*)’:
sip/QtCore/qdatetime.sip:55: warning: deprecated conversion from string 
constant to ‘char*’
sip/QtCore/qdatetime.sip:55: warning: deprecated conversion from string 
constant to ‘char*’


--
+-+
| Mads Ipsen, Scientific developer|
+---+-+
| QuantumWise A/S   | phone: +45-29716388 |
| Nørre Søgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen K, Denmark | email:  m...@quantumwise.com |
+---+-+


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


Re: [PyQt] QMessageBox does not get focus

2009-09-27 Thread Mads Ipsen

Mads Ipsen wrote:
When I launch a QMessageBox like below, from a QMainWindow the box 
does not have keyboard focus (its not the active window), implying 
that the key-shortcuts cannot be used. Any fixes or suggestions?


Mads

QtGui.QMessageBox.warning(self, 'Some title',
   self.tr("The document has been 
modified.\n"
   "Do you want to save your 
changes?"),
   QtGui.QMessageBox.Yes | 
QtGui.QMessageBox.Default,

   QtGui.QMessageBox.No,
   QtGui.QMessageBox.Cancel | 
QtGui.QMessageBox.Escape)



Let me rephrase this:

* Run application.py in examples/mainwindows/application
* Type something in the editor window.
* Close the application by pressing the 'cross' in the upper-right 
corner of the application window.

* A QMessageBox appears. It does not have keyboard focus.

If you exit by pressing Ctrl+Q, however, the QMessageBox will have 
keyboard focus.


Mads


--
+----+
| Mads Ipsen, Scientific developer   |
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


[PyQt] QMessageBox does not get focus

2009-09-27 Thread Mads Ipsen
When I launch a QMessageBox like below, from a QMainWindow the box does 
not have keyboard focus (its not the active window), implying that the 
key-shortcuts cannot be used. Any fixes or suggestions?


Mads

QtGui.QMessageBox.warning(self, 'Some title',
   self.tr("The document has been modified.\n"
   "Do you want to save your 
changes?"),
   QtGui.QMessageBox.Yes | 
QtGui.QMessageBox.Default,

   QtGui.QMessageBox.No,
   QtGui.QMessageBox.Cancel | 
QtGui.QMessageBox.Escape)


--
+----+
| Mads Ipsen, Scientific developer   |
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


[PyQt] Menu bar entry name - suggestions?

2009-09-25 Thread Mads Ipsen
I have a QMainWindow that contains three dock widgets. If the user 
closes one of the dock windows, these can be repositioned back into the 
main window by selecting the closed windows from a menu entry in the 
menu bar of the main window. Any good suggestions for the name of this 
menu entry.


An equivalent is the 'Windows' menu entry that display a list of all 
currently open windows.


Any good suggestions are most welcome.

Mads

--
+----+
| Mads Ipsen, Scientific developer   |
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


[PyQt] Segmentation fault in keyPressEvent

2009-09-17 Thread Mads Ipsen

The following script triggers a segmentation fault:

import sys
from PyQt4 import QtGui

if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)

   widget = QtGui.QWidget()
   widget.show()
   widget.keyPressEvent(None)

   sys.exit(app.exec_())

I believe it should generate an error.

Sys info:

Ubuntu 8.04
Qt 4.5.2
PyQt 4.5.4




--
+----+
| Mads Ipsen, Scientific developer   |
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


[PyQt] Error in example script

2009-09-08 Thread Mads Ipsen
The OpenGL example script 'samplebuffers.py' will fail when reaching the 
blocks:


'if not QtOpenGL.QGLFormat.hasOpenGL():
   QMessageBox.information(None, "OpenGL samplebuffers",
   "This system does not support OpenGL.")
   sys.exit(0)

and

   if not widget.format().sampleBuffers():
   QMessageBox.information(None, "OpenGL samplebuffers",
   "This system does not have sample buffer support.")
   sys.exit(0)

The calls to the static method 'QMessageBox.information' should be 
replaced by


 QtGui.QMessageBox.information

Best regards,

Mads



--
+--------+
| Mads Ipsen, Scientific developer   |
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


Re: [PyQt] Selecting several table items

2009-08-20 Thread Mads Ipsen

Mads Ipsen wrote:

Hi,

Ho do I programmatically select several items in a QTableView? I can 
select one element by calling the method setCurrentIndex(), but that 
only selects a single item. I need to do this in order to write a 
proper unit test.


Best regards,

Mads


Hi,

Solved this one by doing somthing along the lines:

selection_model = table.selectionModel()
selection_model.clearSelection()

index = model.index(0,0)
selection_model.select(index, QtGui.QItemSelectionModel.Select)

index = model.index(1,0)
selection_model.select(index, QtGui.QItemSelectionModel.Select)

Sorry for bothering you with this,

Mads

--
++
| Mads Ipsen, Scientific developer   |
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


[PyQt] Selecting several table items

2009-08-20 Thread Mads Ipsen

Hi,

Ho do I programmatically select several items in a QTableView? I can 
select one element by calling the method setCurrentIndex(), but that 
only selects a single item. I need to do this in order to write a proper 
unit test.


Best regards,

Mads

--
++
| Mads Ipsen, Ph.D, Scientific software developer|
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


Re: [PyQt] headerDataChanged

2009-08-20 Thread Mads Ipsen

Phil Thompson wrote:

On Thu, 20 Aug 2009 09:53:48 +0200, Mads Ipsen  wrote:
  

Hi,

How do I emit the signal headerDataChanged in PyQt when implementing  
the method

setHeaderData() for a QAbstractTableModel?

The C++ syntax is

  emit headerDataChanged(orientation, section, section);

and the C++ definition of the signal reads

  void QAbstractItemModel::headerDataChanged ( Qt::Orientation 
orientation, int first, int last )


but I don't know how to convert that to Python syntax.



Old API...

model.emit(SIGNAL('headerDataChanged(Qt::Orientation, int, int)'),
orientation, section, section)

New API...

model.headerDataChanged.emit(orientation, section, section)

Phil

  

Thanks for pronto response.

Mads

--
+----+
| Mads Ipsen, Ph.D, Scientific software developer|
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


[PyQt] headerDataChanged

2009-08-20 Thread Mads Ipsen

Hi,

How do I emit the signal headerDataChanged in PyQt when implementing  
the method

setHeaderData() for a QAbstractTableModel?

The C++ syntax is

 emit headerDataChanged(orientation, section, section);

and the C++ definition of the signal reads

 void QAbstractItemModel::headerDataChanged ( Qt::Orientation 
orientation, int first, int last )


but I don't know how to convert that to Python syntax.

Best regards,

Mads

--
+----+
| Mads Ipsen, Ph.D, Scientific software developer|
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


Re: [PyQt] Which QStyle

2009-07-22 Thread Mads Ipsen

Matt Newell wrote:

On Tuesday 21 July 2009 13:46:09 Mads Ipsen wrote:
  

How do I programatically determine which style I am using, i.e. whether
it's QWindowsStyle, QMacStyle, QMotifStyle etc.



style = QApplication.instance().style()
print style.metaObject().className()


Matt

  
Thanks. I believe one could argue that a Qt provided convenience method 
along the lines 


style = QApplication.instance().style()
print style.name()

would be in place.

Best regards, Mads


--
+----+
| Mads Ipsen, Ph.D, Scientific software developer|
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


[PyQt] Which QStyle

2009-07-21 Thread Mads Ipsen
How do I programatically determine which style I am using, i.e. whether 
it's QWindowsStyle, QMacStyle, QMotifStyle etc.


--
+----+
| Mads Ipsen, Ph.D, Scientific software developer|
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?

2009-06-23 Thread Mads Ipsen

projetmbc wrote:

Mads Ipsen a écrit :
If you change 'QDialog' to 'QWidget' the problem disappears. But I 
have no idea why. Anybody?


Best regards,

Mads
In the first example proposed that did not work, you can see that the 
button has the focus even if the cursor is in the lineedit. I think 
that the problem comes from here.



Christophe.


From the manual pages:

"A dialog's default button is the button that's pressed when the user 
presses Enter (Return). This button is used to signify that the user 
accepts the dialog's settings and wants to close the dialog."


In other words, the first button that gets added probably gets connected 
up with this behaviour, which explains the behaviour. So using a QWidget 
is probably the correct solution:


Mads

--
+--------+
| Mads Ipsen, Ph.D, Scientific software developer|
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com |
+--+-+


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


Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?

2009-06-22 Thread Mads Ipsen

Sibylle Koczian wrote:

"Mads Ipsen"  schrieb:
  

Sibylle Koczian wrote:


Hello,

I've got a dialog with a QLineEdit and a QPushButton. The QLineEdit is
connected to a method which takes its text and appends it to a
QTextBrowser (that's taken from the first GUI example in the PyQt book
by M. Summerfield). The "clicked()" signal of the QPushButton is
connected to a method that just prints a message. The problem: this
method, which should only be called by clicking the button, is called
every time Enter is pressed in the QLineEdit. This happens even if the
edit control isn't connected to any method.

The button is next to the line edit in the form and in the tab order.

With "setAutoDefault(false)" for this button and for the exit button
which follows in tab order I can prevent this behavior, but that isn't
really very comfortable. And it shouldn't be necessary, should it?

All this on openSUSE with Python 2.6, PyQt 4.4.4.

Thank you for help,
Sibylle

  
  

Can you supply a simple example that reproduces the behavior?




Here it is. Tried with PyQt 4.4.4 (openSUSE) and PyQt 4.5.1 (Windows XP
Prof.), same behavior.

If the returnPressed() signal of the line edit is connected to the
logText() method, then pressing Enter calls logText() (as it should) and
then logPush() (as it shouldn't), pressing Tab doesn't call either of
them.

If editingFinished() is connected to logText() instead (commented out
here), then pressing Enter calls both methods, as before, pressing Tab
only calls logText(), but clicking on one of the buttons (self.pushtest
or btFertig) calls first logText() and then the method the button is
connected to and should call.

So in both cases the application doesn't do what I want it to do: put
the line edit text into the text browser if and only if enter (or tab)
is pressed after entering something in that control, and calling the
method connected to the button if and only if the button is pressed. 


What can I do, or what did I misunderstand?

Regards
Sibylle


#!/usr/bin/env python
# -*- coding: utf-8 -*-
# test_lineeditenter.py

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

class Form(QDialog):

def __init__(self, parent=None):

super(Form, self).__init__(parent)
self.lineedit = QLineEdit(u"Write something and press Enter")
self.pushtest = QPushButton(u"Test button")
self.log = QTextBrowser()
btFertig = QPushButton(u"E&xit")
layout = QVBoxLayout()
layout.addWidget(self.lineedit)
layout.addWidget(self.pushtest)
layout.addWidget(self.log)
layout.addWidget(btFertig)
self.setLayout(layout)
self.lineedit.selectAll()
self.lineedit.setFocus()
self.connect(self.lineedit, SIGNAL("returnPressed()"), 
 self.logText)
#self.connect(self.lineedit, SIGNAL("editingFinished()"), 
# self.logText)

self.connect(self.pushtest, SIGNAL("clicked()"), self.logPush)
self.connect(btFertig, SIGNAL("clicked()"), self,
SLOT("close()"))
self.setWindowTitle(u"Line edit problem")

def logText(self):

tx = self.lineedit.text()
self.log.append(tx)
self.lineedit.selectAll()
self.lineedit.setFocus()

def logPush(self):

self.log.append("Button pressed")

if __name__ == "__main__":
app = QApplication(sys.argv)
mf = Form()
mf.show()
app.exec_()



  
If you change 'QDialog' to 'QWidget' the problem disappears. But I have 
no idea why. Anybody?


Best regards,

Mads

--
++
| Mads Ipsen, Ph.D, Scientific software developer|
+--+-+
| QuantumWise A/S  | phone: +45-29716388 |
| Nørresøgade 27A  | www:www.quantumwise.com |
| DK-1370 Copenhagen, Denmark  | email:  m...@quantumwise.com | 
+--+-+


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


Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?

2009-06-21 Thread Mads Ipsen

Sibylle Koczian wrote:

Hello,

I've got a dialog with a QLineEdit and a QPushButton. The QLineEdit is
connected to a method which takes its text and appends it to a
QTextBrowser (that's taken from the first GUI example in the PyQt book
by M. Summerfield). The "clicked()" signal of the QPushButton is
connected to a method that just prints a message. The problem: this
method, which should only be called by clicking the button, is called
every time Enter is pressed in the QLineEdit. This happens even if the
edit control isn't connected to any method.

The button is next to the line edit in the form and in the tab order.

With "setAutoDefault(false)" for this button and for the exit button
which follows in tab order I can prevent this behavior, but that isn't
really very comfortable. And it shouldn't be necessary, should it?

All this on openSUSE with Python 2.6, PyQt 4.4.4.

Thank you for help,
Sibylle

  

Can you supply a simple example that reproduces the behavior?

Best regards,

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


Re: [PyQt] problem with mouseDoubleClickEvent on QTreeView 1

2009-06-21 Thread Mads Ipsen

laurlaur wrote:

Just for a better view
Hi,
I'm new in PyQt programing so please have mercy :)
I want to display the directories content and to catch the event
mouseDoubleClickEvent , but it seems that I have some problems chatching
this event. Eventualy if someone have a better ideea how to do this I'm open
to suggestions.
Below is my code. 


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




class miniframe():
def __init__(self, parent =None):

self.tree = QtGui.QTreeView()
self.model = QtGui.QDirModel()
self.tree.setModel(self.model)
self.tree.setGeometry(10,750,400,200)
self.tree.show()

def mouseDoubleClickEvent(self, event):
print "event"

if __name__ =="__main__":
app = QtGui.QApplication(sys.argv)
x =miniframe()
x.show()

sys.exit(app.exec_())
  


Make sure you inherit from the classes correctly. In your case, you 
should inherit from the QTreeView class and then overload the method 
mouseDoubleClickEvent().


This snippet below works.

Best regards,

Mads

import sys
from PyQt4 import QtGui

class DirView(QtGui.QTreeView):
   def __init__(self, parent =None):
   QtGui.QTreeView.__init__(self, parent)
   self.model = QtGui.QDirModel()
   self.setModel(self.model)
   self.setGeometry(10,750,400,200)

   def mouseDoubleClickEvent(self, event):
   print "event"

if __name__ =="__main__":
   app = QtGui.QApplication(sys.argv)

   view = DirView()
   view.show()

   sys.exit(app.exec_())

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


Re: [PyQt] Empty style sheet changes QLineEdit

2009-06-18 Thread Mads Ipsen

David Wolfe wrote:

On 6/12/2009 2:32 AM, Mads Ipsen wrote:

* Try to enter a 'g' in the example included below. The lower part of
the 'g' will be invisible...


FWIW, I can't reproduce this behavior using Riverbank's binary installer
for PyQt4.5 (bundles Qt4.5.1) on Windows Vista Home Premium.  I type a
'g' in the QLineEdit and it shows up regardless of whether or not I call
setStyleSheet().  Perhaps it's a Linux-specific issue (seems likeliest),
or a bug in PyQt that has been fixed since PyQt 4.4.4...
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Thanks for giving it a try,

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


[PyQt] Empty style sheet changes QLineEdit

2009-06-11 Thread Mads Ipsen

Hi,

I can't seem to understand this. If I pass an empty stylesheet to a 
QLineEdit, the edit field changes property.


* Try to enter a 'g' in the example included below. The lower part of 
the 'g' will be invisible.
* Remove the call to setStyleSheet(). The lower part of the 'g' becomes 
visible.


Qt 4.5.1, PyQt 4.4.4, Ubuntu 8.04

Best regards,

Mads

import sys
from PyQt4 import QtCore, QtGui

if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)

   style_sheet = 'QLineEdit {}'

   line_edit = QtGui.QLineEdit()
   line_edit.setStyleSheet(QtCore.QString(style_sheet))
   line_edit.show()

   sys.exit(app.exec_())

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


[PyQt] QApllication changes the locale

2009-06-08 Thread Mads Ipsen

On a machine with

LANG=en_DK.UTF-8

The script

 import numpy

 # Now numpy is OK
 print "%s" % (numpy.float64(3.023423))
 print "%s %r" % (numpy.float32(3.023423), numpy.float32(3.023423))

prints

 3.023423
 3.02342 3.023423

Now change the script to

 import sys, os
 from PyQt4 import QtCore, QtGui, QtOpenGL

 # Set the LANG variable
 QT_APP = QtGui.QApplication(sys.argv)

 import numpy

 # Now numpy is OK
 print "%s" % (numpy.float64(3.023423))
 print "%s %r" % (numpy.float32(3.023423), numpy.float32(3.023423))

This prints

 3,023423
 3,02342 3,023423

which is very inconvenient in the application we are developing. Adding 
the line


 os.putenv('LANG', 'en_US.UTF-8')

before the QApplication is loaded solves the problem - but should this 
really happen?


Mads





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


[PyQt] QSortFilterProxyModel - AttributeError

2009-06-05 Thread Mads Ipsen

Hi,

The script below fails with

PyQt-4.4.4
qt-4.5.1

giving the error:

Traceback (most recent call last):
 File "simple.py", line 14, in 
   print proxy_model.sortColumn()
AttributeError: sortColumn

Am I missing something here?

Best regards,

Mads

import sys
from PyQt4 import QtCore, QtGui

if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)

   # Set up a model and proxy model
   model = QtGui.QFileSystemModel()
   proxy_model = QtGui.QSortFilterProxyModel()
   proxy_model.setSourceModel(model)
   proxy_model.sort(0, QtCore.Qt.AscendingOrder)

   # print properties - will fail
   print proxy_model.sortColumn()
   print proxy_model.sortOrder()
  
   sys.exit(app.exec_())



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


Re: [PyQt] QSpinBox: behavior on Linux

2009-06-04 Thread Mads Ipsen

TP wrote:

Hi everybody,

I have detected a strange behavior on Linux with QSpinBox (try the code
example below): when the "valueChanged( int )" signal is connected to a 
function that takes some time to execute, sometimes the "up" and "down"

clickable buttons of the QSpinBox increment and decrement its value by 2 or
more, instead of 1. Whereas on Windows it works correctly. Could you try
under Linux and confirm the strange behavior?

I have another question: why does the value of the spinbox change only after
the function has been executed? How to force the spinbox value to change
immediately, and call the function to be executed AFTER?

My version of PyQt: PyQt-x11-gpl-4.4.4
My version of Qt: 4.4.0.

Thanks

##
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys, time

app = QApplication( sys.argv )
dialog = QDialog( )
# dialog.setBackgroundRole( 9 )
dialog.resize( 750, 550 )

def wait_a_moment():
# pass

time.sleep( 0.5 )


spinbox = QSpinBox( dialog )

QObject.connect( spinbox
, SIGNAL( "valueChanged ( int )" )
, wait_a_moment )

vboxlayout = QVBoxLayout( dialog )
dialog.setLayout( vboxlayout )
dialog.show()

app.exec_()
##

  


Yes, this is correct, and I posted a similar question regarding this 
behavior observed under Linux. The most peculiar thing, is that it works 
correctly if you select the QLineEdit of the QSpinBox and press the up 
and down arrows on the keyboard.


The problem is, however, fixed in Qt 4.5.1!

Best regards,

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


Re: [PyQt] Simple connect does not work

2009-04-24 Thread Mads Ipsen
> On Friday 24 April 2009, Mads Ipsen wrote:
>
>> OK, I need to use a signature (see below). Sorry for bothering you!
>>
>> class SpinBox(QtGui.QSpinBox):
>> def __init__(self, parent=None):
>> QtGui.QSpinBox.__init__(self, parent)
>>
>> @QtCore.pyqtSignature("int")
>> def foo(self, i):
>> print i
>
> Or perhaps:
>
> QtCore.QObject.connect(spin, QtCore.SIGNAL('valueChanged(int)'), spin.foo)
>
> --
> Jan Ekholm
> jan.ekh...@smultron.net
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

That's the way that I normally would approach it, sure. But I wanted to
know how the SIGNAL, SLOT approach works - and there a signature is
needed.

Best regards,

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


Re: [PyQt] Simple connect does not work

2009-04-24 Thread Mads Ipsen
> Hi,
>
> I am puzzled why the connection used in the example below does not work. I
> get the error:
>
> Object::connect: No such slot SpinBox::foo(int)
>
> Example snippet:
>
> import sys
> from PyQt4 import QtCore, QtGui
>
> class SpinBox(QtGui.QSpinBox):
> def __init__(self, parent=None):
> QtGui.QSpinBox.__init__(self, parent)
>
> def foo(self, i):
> print i
>
> if __name__ == "__main__":
> app = QtGui.QApplication(sys.argv)
>
> spin = SpinBox()
> QtCore.QObject.connect(spin, QtCore.SIGNAL('valueChanged(int)'),
>spin, QtCore.SLOT('foo(int)'))
> spin.show()
>
> sys.exit(app.exec_())
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


OK, I need to use a signature (see below). Sorry for bothering you!

class SpinBox(QtGui.QSpinBox):
def __init__(self, parent=None):
QtGui.QSpinBox.__init__(self, parent)

@QtCore.pyqtSignature("int")
def foo(self, i):
print i
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Simple connect does not work

2009-04-24 Thread Mads Ipsen
Hi,

I am puzzled why the connection used in the example below does not work. I
get the error:

Object::connect: No such slot SpinBox::foo(int)

Example snippet:

import sys
from PyQt4 import QtCore, QtGui

class SpinBox(QtGui.QSpinBox):
def __init__(self, parent=None):
QtGui.QSpinBox.__init__(self, parent)

def foo(self, i):
print i

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

spin = SpinBox()
QtCore.QObject.connect(spin, QtCore.SIGNAL('valueChanged(int)'),
   spin, QtCore.SLOT('foo(int)'))
spin.show()

sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] RuntimeError: underlying C/C++ object has been deleted

2009-04-23 Thread Mads Ipsen
> Os Windows Vista Home Ru + sp1
> g++ (GCC) 3.4.5 (mingw-vista special r3)
> Qt 4.5 (self build)
> sip-4.7.9 (self build)
> PyQt-win-gpl-4.4.4.zip (self build)
>
> I was unable to allocate a minimum example. Here is pseudocode situations:
> [code]
>
> class BaseData(QObject):
>def save(self, obj):
>  self.emit(QtCore.SIGNAL('datat_change'), obj)
>
> class Model(QAbstractItemModel):
>def __init__(self, data):
>  #  data Mast be derived from BaseData
>  self.connect(
>data, QtCore.SIGNAL('data_change'), self.__data_changes)
>
>def __data_changes(self, arg):
>  row = self.__getRowForArg(arg)
>  ind = self.createIndex(row, 0, self.objects[row]) #!!! RuntimeError
>
> class Mixin(object):
>data = None #Mast be derived from BaseData
>result = None #Setup brfore accept()
>def __init__(self, ...):
>  ...
>def initUi(self):
>  ui = self.__ui = Ui_DlgFrame()
>  ui.setupUi(self)
>  model = self.__model = self.Model(self.dataCls.singleton())
>  ui.tableView.setModel(model)
>
> class DlgFrame(QDialog, Mixin):
>def __init__(self, data, parent=None, ...):
>  QDialog.__init__(self, parent)
>  Mixin.__init__(self, ...)
>  self.initUi()
>
>@classmethod
>def getRes(cls, parent ...):
>  frm = cls(parent, ...)
>  if frm.exec_() == QtGui.QDialog.Accepted:
>return frm._result
>  return None
>
> class FinalDlg(DlgFrame, ...):
># This class generated by function 'type'
>dataCls = FinalData #Derived from BaseData
>
> class Main(QMainWindow):
>def __init__(self):
>  data = FinalData.singleton()
>
>@QtCore.pyqtSignature('')
>def on_btGetRes_clicked(self):
>  self.res = FinalDlg.getRes(self, ...)
>
>@QtCore.pyqtSignature('')
>def on_btSaveRes_clicked(self):
>  self.data.save(self.res)
> [/code]
> Scenario for reproduction:
> start Application
> press btGetRes
> press btSaveRes
>
> In PyQt-win-gpl-4.5-snapshot-20090419.zip error also.
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


When you inherit from a Qt base class, you must always call the
constructor of the base class in the derived class. For example:

class BaseData(QObject):
  def __init__(self):
QObject.__init__(self)
...

class Model(QAbstractItemModel):
  def __init__(self, data):
QAbstractItemModel.__init__(self)
...

Best regards,

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


[PyQt] QItemDelegate + Hover

2009-04-19 Thread Mads Ipsen
Hi,

I would like the editor of my ItemDelegate to be triggered when the mouse
is hovered over the item. I've modified the 'spinboxdelegate.py' (example
included below):

* Reimplement the paint method of QItemDelegate
* Call setAttribute(QtCore.Qt.WA_Hover) on the TableViews viewport() method

and managed to make the background change whenever a mouse hovers a table
item.

That's part of the way, but still not what I want: The QSpinBox should
appear when the mouse hovers the item. Any clues on how so to solve this
(my guess is that it must be simple).

Best regards,

Mads

import sys
from PyQt4 import QtCore, QtGui

class SpinBoxDelegate(QtGui.QItemDelegate):
def __init__(self, parent = None):
QtGui.QItemDelegate.__init__(self, parent)

def createEditor(self, parent, option, index):
editor = QtGui.QSpinBox(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, spinBox, model, index):
spinBox.interpretText()
value = spinBox.value()

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

def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect)

# Modified by me
def paint(self, painter, option, index):
if (option.state & QtGui.QStyle.State_MouseOver):
painter.fillRect(option.rect, QtCore.Qt.red);
QtGui.QItemDelegate.paint(self, painter, option, index)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

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

# Modified by me
tableView.viewport().setAttribute(QtCore.Qt.WA_Hover);

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_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Larger size of QIcon?

2009-03-25 Thread Mads Ipsen
> 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
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt

like this:

list_view = QListView()
list_view.setIconSize(QSize(1024,1024))
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] QTableView header connection

2009-03-18 Thread Mads Ipsen
>
> Hey all,
>
> Since I still haven't been able to
> http://www.nabble.com/Sorting-column-with-QComboBox-cellwidgets-td22499840.html
> automatically sort a column with combo boxes , and now have another column
> with special sorting conditions, I'd like to manually do the sorting.
>
> The problem is that I can't seem to make a connection from the header.
> This
> is (very simplified) what I'm doing now:
>
> Class GUI:
>   def __init__(self):
>   tableWidget = QtGui.QTableWidget()
>   # Code to insert 5 columns and make a horizontal header)
>   self.connect(tableWidget.horizontalHeader, 
> QtCore.SIGNAL("clicked()"),
> self.random_function)
>
>   def random_function(self):
>   print 'ok'
>
> However, double-clicking the header does not make the console print 'ok'.
>
> Sooo, anyone got an idea why this is not working?
>
> Thanks in advance for any help!
>
> Cheers,
>
> Gert-Jan
> --
> View this message in context:
> http://www.nabble.com/QTableView-header-connection-tp22579905p22579905.html
> Sent from the PyQt mailing list archive at Nabble.com.
>
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

You should use the method horizontalHeader() not horizontalHeader when you
connect. The signal you should connect to is 'sectionClicked (int)', I
have included a small example below that hopefully should get you going.

Best, Mads

import sys
from PyQt4 import QtGui, QtCore

class Table(QtGui.QTableWidget):
def __init__(self, parent=None):
QtGui.QTableWidget.__init__(self, parent)

# Add 3 rows
for i in xrange(3):
self.insertRow(i)

# Add 3 cols
for i in xrange(3):
self.insertColumn(i)

# Add some cell data
for i in xrange(3):
for j in xrange(3):
item = QtGui.QTableWidgetItem()
item.setText(str(i+j))
self.setItem(i,j,item)

# Connect
self.connect(self.horizontalHeader(),
 QtCore.SIGNAL('sectionClicked (int)'),
 self.random_function)

def random_function(self, i):
print 'Header was clicked on column %d' % (i)


if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

widget = Table()
widget.show()

sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] subprocess in PyQt

2009-03-14 Thread Mads Ipsen
>
>
>
> Mads Ipsen-3 wrote:
>>
>>>
>>> Hello guys;
>>>
>>> i have a function that suppose to do something and from terminal it has
>>> this
>>> syntax to be executed;
>>>
>>> was...@home:~/Desktop/Project2/GUI$ python myexif.py -q "pathfile" >
>>> test.csv
>>>
>>> so far on using subprocess i came up with this;
>>>
>>> from subprocess import *
>>> x=Popen(['python','myexif','-q','sys.argv[1]'], stdout=PIPE)
>>> y=Popen(['>','Exif.csv'], stdin=x.stdout)
>>>
>>> but i keep getting this error
>>>
>>> was...@home:~/Desktop/Project2/GUI$ python wrapphotodb.py
>>> Traceback (most recent call last):
>>> File "wrapphotodb.py", line 37, in _addphotoClicked
>>> y=Popen(['>','Exif.csv'], stdin=x.stdout)
>>> File "/usr/lib/python2.5/subprocess.py", line 594, in __init__
>>> errread, errwrite)
>>> File "/usr/lib/python2.5/subprocess.py", line 1153, in _execute_child
>>> raise child_exception
>>> OSError: [Errno 2] No such file or directory
>>>
>>> Any idea? is my syntax correct?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/subprocess-in-PyQt-tp22510022p22510022.html
>>> Sent from the PyQt mailing list archive at Nabble.com.
>>>
>>> ___
>>> PyQt mailing listPyQt@riverbankcomputing.com
>>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>>
>>
>>
>> Why don't you try to use a QProcess from spawning external processes? I
>> have a good success ratio with that approach.
>>
>> Mads
>> ___
>> PyQt mailing listPyQt@riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>>
>
> Okay how am i going to use it? i read for sometimes i couldn't understand
>
> --
> View this message in context:
> http://www.nabble.com/subprocess-in-PyQt-tp22510022p22510772.html
> Sent from the PyQt mailing list archive at Nabble.com.
>
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

Look here:

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

Here's a C++ snippet that needs very little modification in order to run
as a PyQt program:

The following example runs gzip to compress the string "Qt rocks!",
without an event loop:

 QProcess gzip;
 gzip.start("gzip", QStringList() << "-c");
 if (!gzip.waitForStarted())
 return false;

 gzip.write("Qt rocks!");
 gzip.closeWriteChannel();

 if (!gzip.waitForFinished())
 return false;

 QByteArray result = gzip.readAll();
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] subprocess in PyQt

2009-03-14 Thread Mads Ipsen
>
> Hello guys;
>
> i have a function that suppose to do something and from terminal it has
> this
> syntax to be executed;
>
> was...@home:~/Desktop/Project2/GUI$ python myexif.py -q "pathfile" >
> test.csv
>
> so far on using subprocess i came up with this;
>
> from subprocess import *
> x=Popen(['python','myexif','-q','sys.argv[1]'], stdout=PIPE)
> y=Popen(['>','Exif.csv'], stdin=x.stdout)
>
> but i keep getting this error
>
> was...@home:~/Desktop/Project2/GUI$ python wrapphotodb.py
> Traceback (most recent call last):
> File "wrapphotodb.py", line 37, in _addphotoClicked
> y=Popen(['>','Exif.csv'], stdin=x.stdout)
> File "/usr/lib/python2.5/subprocess.py", line 594, in __init__
> errread, errwrite)
> File "/usr/lib/python2.5/subprocess.py", line 1153, in _execute_child
> raise child_exception
> OSError: [Errno 2] No such file or directory
>
> Any idea? is my syntax correct?
> --
> View this message in context:
> http://www.nabble.com/subprocess-in-PyQt-tp22510022p22510022.html
> Sent from the PyQt mailing list archive at Nabble.com.
>
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


Why don't you try to use a QProcess from spawning external processes? I
have a good success ratio with that approach.

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


Re: [PyQt] Connecting to a QItemModel

2009-03-07 Thread Mads Ipsen
> On Fri, Mar 6, 2009 at 6:22 PM, Mads Ipsen  wrote:
>>> How does one connect to the signals of a QItemModel?
>>>
>>> I tried the following, but it didn't work:
>>>
>>> self.connect(
>>>   self.model,
>>>   QtCore.SIGNAL('itemChanged(QStandardItem 8)'),
>>>   self.on_model_itemChanged
>>>   )
>>>
>>> and
>>>
>>> self.connect(
>>>   self.model,
>>>   QtCore.SIGNAL('itemChanged(QStandardItem &)'),
>>>   self.on_model_itemChanged
>>>   )
>>>
>>> Neither worked.
>>>
>
>>
>>
>> I believe you should do:
>>
>> self.connect(self.model,
>> QtCore.SIGNAL('itemChanged( QStandardItem *)'),
>> self.foo)
>>
>> At least that works for me.
>>
>> Best, Mads
>>
>
> I tried that. That '8' was supposed to have been an '*'
>
>
> --
> Fedora 9 : sulphur is good for the skin
> ( www.pembo13.com )
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


This small example uses the connection setup from my previous post. It
emits the signal 10 times. The signal it connected to foo(), which prints
out the changed item. Just save it and run to see for your self.

import sys
from PyQt4 import QtCore, QtGui

def foo(item):
print item

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

# Setup a model
model = QtGui.QStandardItemModel()

# Connect it
model.connect(model, QtCore.SIGNAL('itemChanged( QStandardItem *)'), foo)

# Add 10 dummy elements
for i in range(10):
item = QtGui.QStandardItem(str(i))
model.appendRow([item])

# Set them to be checked - this will trigger the 'itemChanged' signal
for row in range(model.rowCount()):
item = model.item(row, 0)
item.setCheckState(QtCore.Qt.Checked)
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Connecting to a QItemModel

2009-03-06 Thread Mads Ipsen
> How does one connect to the signals of a QItemModel?
>
> I tried the following, but it didn't work:
>
> self.connect(
>   self.model,
>   QtCore.SIGNAL('itemChanged(QStandardItem 8)'),
>   self.on_model_itemChanged
>   )
>
> and
>
> self.connect(
>   self.model,
>   QtCore.SIGNAL('itemChanged(QStandardItem &)'),
>   self.on_model_itemChanged
>   )
>
> Neither worked.
>
> --
> Fedora 9 : sulphur is good for the skin
> ( www.pembo13.com )
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


I believe you should do:

self.connect(self.model,
 QtCore.SIGNAL('itemChanged( QStandardItem *)'),
 self.foo)

At least that works for me.

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


[PyQt] (no subject)

2009-02-10 Thread Mads Ipsen
- Original Besked 
Fra: Markus Feldmann 
Til: pyqt@riverbankcomputing.com 
Emne: [PyQt] Re: how to show interactive Picture
Dato: 09/02/09 23:58

> Mads Ipsen schrieb:
> > Could is be that you try to paint before the window is shown? You
need to
> > call show() before you can start painting. The following snippet
generates
> > an error similar to yours:
> Hi,
>
> This is not all of my Code. So there is a <show()> in my main source

> code. This Source Code only shows a sub-widget of a MDI Application.
>
> However this window is shown, but without the picture.
> How do the program know in which widget shall the Pixmap
> be shown ?
>
> ___
> PyQt mailing list PyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

Thats something you tell the program. You reimplement the method
'paintEvent' for a widget class like in the example I posted. Then for a
particular instance of the widget, the window is painted everytime a
paintEvent occurs and the widget get painted. A paintEvent event occurs eg.
when a window is hidden underneath another window and then shown.

To a draw a pixmap onto a widget do something like this in the paintEvent
method:

def paintEvent(self, event):
painter = QtGui.QPainter(64,64)
pixmap = QtGui.QPixmap()

painter.begin(self)
painter.drawPixmap(0,0,pixmap)
painter.end()

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


Re: [PyQt] Re: how to show interactive Picture

2009-02-10 Thread Mads Ipsen
- Original Besked 
Fra: Markus Feldmann 
Til: pyqt@riverbankcomputing.com 
Emne: [PyQt] Re: how to show interactive Picture
Dato: 09/02/09 23:58

> Mads Ipsen schrieb:
> > Could is be that you try to paint before the window is shown? You
need to
> > call show() before you can start painting. The following snippet
generates
> > an error similar to yours:
> Hi,
> 
> This is not all of my Code. So there is a <show()> in my main source

> code. This Source Code only shows a sub-widget of a MDI Application.
> 
> However this window is shown, but without the picture.
> How do the program know in which widget shall the Pixmap
> be shown ?
> 
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 

Thats something you tell the program. You reimplement the method
'paintEvent' for a widget class like in the example I posted. Then for a
particular instance of the widget, the window is painted everytime a
paintEvent occurs and the widget get painted. A paintEvent event occurs eg.
when a window is hidden underneath another window and then shown.

To a draw a pixmap onto a widget do something like this in the paintEvent
method:

 def paintEvent(self, event):
painter = QtGui.QPainter(64,64)
pixmap = QtGui.QPixmap()

painter.begin(self)
painter.drawPixmap(0,0,pixmap)
painter.end()

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


Re: [PyQt] how to show interactive Picture

2009-02-09 Thread Mads Ipsen
- Original Besked 
Fra: Markus Feldmann 
Til: pyqt@riverbankcomputing.com 
Emne: [PyQt] how to show interactive Picture
Dato: 09/02/09 23:18

> Hi All,
> 
> i am programming a MDI Application where a Window in the
> workspace shall work as a Map Program. Therefore i want
> to show a Picture which is parted in many small hexagons.
> This hexagons can be selected with the mouse.
> 
> Ok, i started first to set up the picture, but got
> trouble. Here are some Messages:
> StdErr: QPainter::begin: Widget painting can only begin as a result of a 
> paintEvent
> QPainter::begin: Painter already active
> QPainter::setRenderHint: Painter must be active to set rendering hints
> QPainter::save: Painter not active
> QPainter::restore: Unbalanced save/restore
> QPainter::end: Painter not active, aborted
> 
> 
> So i think i do something wrong to show my picture.
> How can i show the picture correctly ?
> 
> Regards Markus
> 
> Here it comes a part of my Programm:
> #!/usr/bin/env python
> #
> # reisehelfer.py
> #
> 
> import sys
> from PyQt4.QtGui import QMainWindow,  QDockWidget,  QPainter,  QAction, 
>   QScrollArea
> from PyQt4.QtGui import QPaintEvent,  QPixmap,  QPen,  QBrush
> from PyQt4 import QtCore
> 
> 
> class ReiseHelfer(QMainWindow):
>  def __init__(self, parent=None):
>  QMainWindow.__init__(self, parent)
> 
>  self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
> 
>  self.createActions()
>  self.createMenus()
>  self.createStatusBar()
> 
>  self.setWindowTitle(self.tr("Reisehelfer"))
>  self.scrollarea = QScrollArea()
>  self.setCentralWidget(self.scrollarea)
> 
>  self.pen = QPen()
>  self.brush = QBrush()
>  self.pixmap = QPixmap()
>  self.pixmap.load(":/media/images/aventurien.jpg")
> 
>  self.readSettings()
> 
>  self.update()
> 
> 
>  def createActions(self):
>  self.openMapAct = QAction(self.tr("&Open Map"),
self)
>  self.openMapAct.setShortcut(self.tr("Ctrl+O"))
>  self.connect(self.openMapAct,
QtCore.SIGNAL("triggered()"), 
> self.loadMap)
> 
>  self.exitAct = QAction(self.tr("E&xit"), self)
>  self.exitAct.setShortcut(self.tr("Ctrl+Q"))
>  self.connect(self.exitAct,
QtCore.SIGNAL("triggered()"), self, 
> QtCore.SLOT("close()"))
> 
> 
>  def createMenus(self):
> 
> 
> 
>  def createStatusBar(self):
> 
> 
> 
>  def loadMap(self):
>  pass
> 
>  def paintEvent(self,  event):
>  painter =  QPainter(self.scrollarea)
>  painter.begin(self)
>  painter.setPen(self.pen)
>  painter.setBrush(self.brush)
>  painter.setRenderHint(QPainter.Antialiasing,  True)
> 
>  painter.save()
>  painter.drawPixmap(10,  10,  self.pixmap)
>  painter.restore()
>  painter.end()
> 
> 
> 
>  def readSettings(self):
> 
> 
>  def writeSettings(self):
> 
> 
> 
>  def closeEvent(self, event):
>  self.writeSettings()
>  event.accept()
> 
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 

Could is be that you try to paint before the window is shown? You need to
call show() before you can start painting. The following snippet generates
an error similar to yours:

import sys

from PyQt4 import QtCore, QtGui

class MyWidget(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)

def paintEvent(self, event):
painter = QtGui.QPainter()
painter.begin(self)
painter.end()

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
widget = MyWidget()

# Try to call an immature paintEvent
region = QtGui.QRegion(0,0,64,64)
event = QtGui.QPaintEvent(region)
widget.paintEvent(event)

widget.show()
sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] compare EditTriggers

2009-02-06 Thread Mads Ipsen
Suppose I say

tree_view = QTreeView()
tree_view.setEditTriggers(QAbstractItemView.DoubleClicked |
QAbstractItemView.SelectedClicked)

Then I can query the flags I just set by calling

triggers = tree_view.editTriggers()

But how do I test that the flags that I just have set actually are the ones
returned in the triggers variable above?

Doing 

triggers == (QAbstractItemView.DoubleClicked |
QAbstractItemView.SelectedClicked)

returns False. I must be doing something wrong here.

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


Re: [PyQt] Getting it ready to ship.

2009-02-06 Thread Mads Ipsen
- Original Besked 
Fra: Knapp 
Til: pyqt@riverbankcomputing.com 
Emne: [PyQt] Getting it ready to ship.
Dato: 06/02/09 09:51

> OK, I now have a little finished project that I want to send out to
> buyers so they can take a look. How do I get the python into a format
> that the code can not be stolen (without work anyway) and it is only a
> one click install? I need all three but Linux and Windows are the most
> important. I have looked around on the net and it seems there are a
> lot of ways. What is easy and best; execution speed is not very
> important for this program?
> Thanks
> -- 
> Douglas E Knapp
> 
> Amazon Gift Cards; let them choose!!
>
http://www.amazon.com/gp/product/B001078FFE?ie=UTF8&tag=seattlebujinkand&linkCode=as2&camp=1789&creative=9325&creativeASIN=B001078FFE
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 

1. Distribute only pyc files.
2. Use the VendorID approach

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


Re: [PyQt] rcc module?

2009-02-05 Thread Mads Ipsen
- Original Besked 
Fra: Phil Thompson 
Til: Brent Villalobos 
Cc: pyqt@riverbankcomputing.com
Emne: Re: [PyQt] rcc module?
Dato: 05/02/09 21:43

> On Thu, 05 Feb 2009 11:59:20 -0800, Brent Villalobos
>  wrote:
> > Is there an rcc python module similar to the uic module?  I would
like 
> > to be able to create a resource module dynamically at run time in a 
> > similar manner I create the UI classes using the uic module.  Right
now 
> > I think I have to shell out and run pyrcc4 so I'm wondering if there
is 
> > a better way of doing this.  Thanks.
> 
> No - it's on the todo list, but a very long way down.
> 
> Phil
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 

I do the whole thing from a Makefile. Thats almost automatical.

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


Re: [PyQt] set qlineedit red, easy?? SOLVED

2009-02-05 Thread Mads Ipsen
- Original Besked 
Fra: Knapp 
Til: Frédéric 
Cc: pyqt@riverbankcomputing.com
Emne: Re: [PyQt] set qlineedit red, easy?? SOLVED
Dato: 05/02/09 13:11

> On Thu, Feb 5, 2009 at 12:50 PM, Frédéric
>  wrote:
> >
> > Le 5/2/2009, "Knapp"  a écrit:
> >
> >>I have a qlineedit that I want to turn the background red when the
> >>input is bad but I can't seem to find how to do this. I would
think it
> >>would be easy but it does not seem to be. unless I missed
something.
> >
> > Using a stylesheet?
> >
> > css = """QLineEdit {
> > background-color: red;
> > }"""
> > myWidget. setStyleSheet(css)
> >
> > I didn't test...
> >
> > http://doc.trolltech.com/4.4/stylesheet.html#overview
> > http://doc.trolltech.com/4.4/qwidget.html#styleSheet-prop
> >
http://doc.trolltech.com/4.4/stylesheet-examples.html#customizing-qlineedit
> >
> > --
> >   Frédéric
> >
> 
> Worked perfectly. I knew it had to be easy and I overlooked the answer!
> Thanks all.
> -- 
> Douglas E Knapp
> 
> Amazon Gift Cards; let them choose!!
>
http://www.amazon.com/gp/product/B001078FFE?ie=UTF8&tag=seattlebujinkand&linkCode=as2&camp=1789&creative=9325&creativeASIN=B001078FFE
> 
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 

You can also do:

line_edit = QLineEdit()
palette = QPalette()
palette.setColor(widget.backgroundRole(), QColor('red'))
line_edit.setPalette(palette)

for a more subtle effect, you might consider exchanging backgroundRole()
with foregroundRole().

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


Re: [PyQt] item delegates

2009-02-05 Thread Mads Ipsen
- Original Besked 
Fra: Baba-k 
Til: pyqt@riverbankcomputing.com 
Emne: Re: [PyQt] item delegates
Dato: 05/02/09 11:09

> 
> Hi Mads,
> 
> I dunno if this is the best way of doing it but could you test to see
which
> row/column the item is inside the delegate and if its not in the correct
one
> then call the parent class method for creating the editor widget otherwise
> use yours, for example..
> 
> class myDelegate(QtGui.QItemDelegate):
>   
>   def createWidget(self, index ...):
>  if index.column() != someColumn and index.row() != someRow:
>  return QtGui.QItemDelegate(self, index, ... )
>
> return myWidget
> 
> if that makes sense, could be over kill though. Alternatively if you are
> using a custom model you might be able to set some flags on the cell you
> want and not the others.
> 
> hope that helps
> babak
> 
> 
> Mads Ipsen-3 wrote:
> > 
> > Hi,
> > 
> > Suppose I have a TableView. Then I can set itemdelegates for a
column, a
> > row
> > or the entire view using the respective methods
> > 
> > void setItemDelegateForColumn ( int column, QAbstractItemDelegate *
> > delegate
> > )
> > void setItemDelegateForRow ( int row, QAbstractItemDelegate *
delegate )
> > void setItemDelegate ( QAbstractItemDelegate * delegate )
> > 
> > All this is fine. But how do I specify a delegate for a single cell
in the
> > table?
> > 
> > Mads
> > ___
> > PyQt mailing listPyQt@riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> > 
> > 
> 
> -- 
> View this message in context:
http://www.nabble.com/item-delegates-tp21846648p21848453.html
> Sent from the PyQt mailing list archive at Nabble.com.
> 
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 

That actually how I do it. But, as you point out, its somewhat overkill. 

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


[PyQt] item delegates

2009-02-04 Thread Mads Ipsen
Hi,

Suppose I have a TableView. Then I can set itemdelegates for a column, a row
or the entire view using the respective methods

void setItemDelegateForColumn ( int column, QAbstractItemDelegate * delegate
)
void setItemDelegateForRow ( int row, QAbstractItemDelegate * delegate )
void setItemDelegate ( QAbstractItemDelegate * delegate )

All this is fine. But how do I specify a delegate for a single cell in the
table?

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


Re: [PyQt] QSpinBox and setLineEdit

2009-01-30 Thread Mads Ipsen
- Original Besked 
Fra: Matt Smith 
Til: pyqt@riverbankcomputing.com 
Cc: Mads Ipsen 
Emne: Re: [PyQt] QSpinBox and setLineEdit
Dato: 30/01/09 19:10

> > Yes, this will do the trick provided that the function you connect to
does
> > not take to long to update. In that case the spin box jams or locks
and does
> > several increments of its value. This is exactly why I want to
connect to
> > the lineedit since this is first updated once the function you
connect to
> > returns. I post a small cone snippet in a separate post that
illustrates
> > this.
> > 
> > Mads
> 
> I am going to suggest that if your function is taking too long to update
> it is not because of who/what you connected it too, but because your
> function is taking too long.  I made the spin box update quickly by
> starting a QThread and having the long process execute in that.  
> 
> This involved subclassing the spin box so that I would only make a new
> thread if the old thread had finished.  
> 
> Probably there are more elegant/better solutions.
> 
> mbs
> 

Funny thing is: The problem is not present on Mac and in Qt3 you could do
trick of using the lineEdit() method (called editor() in Qt3) to handle when
the spin box was done.

Could you provide me with a few snippets/starters for doing this in a
threaded way?

Best regards,

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


[PyQt] SpinBox jam/lock

2009-01-30 Thread Mads Ipsen
The following observation occurs on Linux (Ubuntu 8.04) with PyQt-4.4.4 and
qt-4.4.3.

If you connect to the valueChanged signal from a spin box, and the function
you call, take a long time before it returns, the spin box jams and does
several increments of it value. I have included a small snippet below that
reproduces this. Note, if you press ArrowUp or ArrowDown in the spin box's
line edit field, no jamming takes place. 

import sys

from PyQt4 import QtCore, QtGui

def foo(value):
for i in range(value*10):
print value

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

widget = QtGui.QSpinBox()
widget.connect(widget, QtCore.SIGNAL('valueChanged(int)'), foo)

widget.show()
sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] QSpinBox and setLineEdit

2009-01-30 Thread Mads Ipsen
Yes, this will do the trick provided that the function you connect to does
not take to long to update. In that case the spin box jams or locks and does
several increments of its value. This is exactly why I want to connect to
the lineedit since this is first updated once the function you connect to
returns. I post a small cone snippet in a separate post that illustrates
this.

Mads

- Original Besked 
Fra: Matt Smith 
Til: Mads Ipsen 
Cc: pyqt@riverbankcomputing.com
Emne: Re: [PyQt] QSpinBox and setLineEdit
Dato: 30/01/09 15:15

> On Fri, 2009-01-30 at 14:55 +0100, Mads Ipsen wrote:
> > import sys
> > 
> > from PyQt4 import QtCore, QtGui
> > 
> > def foo(text):
> > print 'valueChanged():', text
> > 
> > if __name__ == "__main__":
> > app = QtGui.QApplication(sys.argv)
> > spin_box = QtGui.QSpinBox()
> > line_edit = spin_box.lineEdit()
> > line_edit.connect(line_edit, QtCore.SIGNAL('textChanged(const
> > QString
> > &)'), foo)
> > spin_box.show()
> > sys.exit(app.exec_())
> 
> How about connecting to the spin box value changed?
> 
>  line_edit.connect(spin_box,QtCore.SIGNAL('valueChanged( int )'), foo)
> 
> I added that and it seems to do what you want.
> 
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] QSpinBox and setLineEdit

2009-01-30 Thread Mads Ipsen
- Original Besked 
Fra: Matt Smith 
Til: pyqt@riverbankcomputing.com 
Emne: Re: [PyQt] QSpinBox and setLineEdit
Dato: 30/01/09 14:11

> 
> > 
> > Well, OK. My problem is that I would like to connect up to the
> > textChanged(const QString &) signal emitted by the spinbox's
lineedit.
> > This
> > signal, however, is only emitted when the edit is modified directly,
not
> > when it changes indirectly eg. by pressing the up/down arrows on the
> > spinbox. Any suggestions for a solution?
> > 
> > Mads
> > 
> 
> QLine claims that the textChanged is emitted even when the text is
> changed programmatically.  Have you tried connecting to it?.
> 
>
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qlineedit.html#textChanged
> 
> Your previous example did not involve connecting to the line edit.
> 
> mbs
> 
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 

Thanks for asking, this is exactly my point. If you connect to the line
edit, the connection is olny triggered if you edit the line edit directly.
If you press the arrows on the spin box. Nothing happens. The examples below
illustrates this:

import sys

from PyQt4 import QtCore, QtGui

def foo(text):
print 'valueChanged():', text

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
spin_box = QtGui.QSpinBox()
line_edit = spin_box.lineEdit()
line_edit.connect(line_edit, QtCore.SIGNAL('textChanged(const QString
&)'), foo)
spin_box.show()
sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt