[PyQt] dip error

Phil Thompson phil at riverbankcomputing.com
Mon Feb 7 18:05:39 GMT 2011


On Mon, 07 Feb 2011 18:28:50 +0100, Achim Kisseler
<ak7 at jupiter.uni-freiburg.de> wrote:
> by the way:
> 
> I try to set up a basic test case for using an .ui file created with 
> designer as base.
> 
> The .ui is a MainWindow, containing among other stuff a label named
"label"
> 
> --%<--
> import sys
> 
> from PyQt4.QtCore import Qt
> from PyQt4.QtGui import QApplication
> 
> from dip.model import *
> from dip.ui import *
> from dip.ui.toolkits.qt import QtToolkit
> 
> class test(Model):
>      label = "testtext"
> 
> app = QApplication(sys.argv)
> 
> toolkit = QtToolkit()
> 
> ui_file_name = "dip-test.ui"
> 
> model = test()
> 
> ui = Designer()
> 
> ui.exec_()
> --%<--
> 
> ..which is probaly wrong.

Very wrong. Designer is a factory class for an item in a view. So you need
to create the factory for the view itself, then call the view factory to
create the actual GUI.

Something like...

import sys

from PyQt4.QtGui import QApplication

from dip.model import Model, Str
from dip.ui import Designer, VBox
from dip.ui.toolkits.qt import QtToolkit

app = QApplication(sys.argv)

# Define the model.
class test(Model):
    label = Str("testtext")

# Create the model.
model = test()

# Define the view.
view = VBox(Designer('dip-test.ui'))

# Create and display the GUI.
ui = view(model, QtToolkit(), widget=True)
ui.show()

app.exec_()

However .ui files aren't much use given your original requirement for
automatically connecting up widgets to attributes.

(BTW I've just updated the snapshots to fix a bug so that the above
example will actually work.)

Phil


More information about the PyQt mailing list