Re: [PyQt] Camelot 13.04.13 released

2013-04-16 Thread Sibylle Koczian

Am 12.04.2013 12:03, schrieb Erik Janssens:

Hello,

Camelot 13.04.13 has been released.

Camelot provides components to build business applications
on top SQLAlchemy and PyQt.  For screenshots, see :

http://www.python-camelot.com/

An overview of the changes can be found here :

http://www.python-camelot.com/3/post/2013/04/release-130413.html



Still not for Python 3? I can't even tell from the web site, do I look 
in the wrong place or what? The package list for the Conceptive Python 
SDK mentions Python 2.7.2, but that's not the only option, even on 
Windows, is it?


Thank you,
Sibylle

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


Re: [PyQt] Win 7, 64 bit, latest PyQt installer: importing QtGui fails

2013-04-03 Thread Sibylle Koczian

Am 02.04.2013 10:31, schrieb Phil Thompson:


As I have said, I (and presumably most other people) cannot reproduce the
problem. One possibility is a missing DLL - try installing a DLL dependency
checker to see if that identifies it.



Thank you, yes, it did. Installing the DirectX9 end user runtime helped. 
So this time it wasn't that ctypes bug.


Sibylle



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


[PyQt] Win 7, 64 bit, latest PyQt installer: importing QtGui fails

2013-04-01 Thread Sibylle Koczian

Hello,

I've just installed the latest PyQt4 with this installer:

http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10/PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe

Installation seemed to work normally, but now I can't import QtGui:

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 
bit (AM

D64)] on win32
Type help, copyright, credits or license for more information.
 from PyQt4 import QtCore
 from PyQt4 import QtGui
Traceback (most recent call last):
  File stdin, line 1, in module
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.


What can I do? Is this the same error Detlev Offenbach reported two 
weeks ago?


Thank you for help,
Sibylle
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Win 7, 64 bit, latest PyQt installer: importing QtGui fails

2013-04-01 Thread Sibylle Koczian

Am 01.04.2013 13:43, schrieb Sibylle Koczian:

Hello,

I've just installed the latest PyQt4 with this installer:

http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10/PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe


Installation seemed to work normally, but now I can't import QtGui:

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64
bit (AM
D64)] on win32
Type help, copyright, credits or license for more information.
  from PyQt4 import QtCore
  from PyQt4 import QtGui
Traceback (most recent call last):
File stdin, line 1, in module
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
 



Just remembered a similar issue with fdb and Python 3.3. In that case it 
seems to have been this ctypes bug:


http://bugs.python.org/issue16283

Could it be the same problem here? Nothing about fixing the bug in the 
report, as far as I can see.


Sibylle


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


[PyQt] Model/view: values of type Decimal not shown

2012-07-26 Thread Sibylle Koczian

Hello,

I don't know how to get numeric data from my model to my GUI, if they 
aren't floats but decimal.Decimal. In the following example the last 
column of the view and the last QLineEdit of the form both stay empty. 
The model data are printed to the console and it can be seen that the 
model contains the correct data for the last column and that they have 
the right type. But the GUI doesn't show them. What should I change?


Thanks for hints,
Sibylle


# modeltest.py

import sys
import decimal
import datetime
from PyQt4 import QtCore
from PyQt4 import QtGui

RAWDATA = [(1, First, datetime.date(2012, 7, 15), 1.25, 
decimal.Decimal(2.5)),

   (2, Second, datetime.date(2011, 6, 10), 3.77,
decimal.Decimal(7.54)),
   (3, Third, datetime.date(2010, 5, 27), 5.03,
decimal.Decimal(10.06))]

class MyDialog(QtGui.QDialog):

def __init__(self, data, parent=None):
super(MyDialog, self).__init__(parent)
self.myModel = self.setupModel(data)
self.showModelData()
view = self.setupView()
form = self.setupForm()
view.selectionModel().currentRowChanged.connect(
self.mapper.setCurrentModelIndex)
layout = QtGui.QVBoxLayout()
layout.addWidget(view)
layout.addWidget(form)
self.setLayout(layout)
#self.mapper.toFirst()
view.selectRow(0)

def setupModel(self, data):
md = QtGui.QStandardItemModel(len(data), 5)
md.setHorizontalHeaderLabels([Int, String, Date, Float,
  Decimal])
for (i, row) in enumerate(data):
# Integer
item = QtGui.QStandardItem()
item.setData(row[0], QtCore.Qt.EditRole)
md.setItem(i, 0, item)
# String
md.setItem(i, 1, QtGui.QStandardItem(row[1]))
item = QtGui.QStandardItem()
# First try: use datetime.date as is. Result:
# Date column in view empty, QDateEdit shows 1.1.2000
# item.setData(row[2], QtCore.Qt.EditRole)
# Second try: convert to QDate via string
dt = QtCore.QDate.fromString(row[2].isoformat(),
 QtCore.Qt.ISODate)
item.setData(dt, QtCore.Qt.EditRole)
md.setItem(i, 2, item)
# Float
item = QtGui.QStandardItem()
item.setData(row[3], QtCore.Qt.EditRole)
md.setItem(i, 3, item)
# Decimal
item = QtGui.QStandardItem()
item.setData(row[4], QtCore.Qt.EditRole)
md.setItem(i, 4, item)
return md

def setupView(self):
view = QtGui.QTableView()
view.setModel(self.myModel)
view.setAlternatingRowColors(True)
view.setSelectionMode(QtGui.QTableView.SingleSelection)
view.setSelectionBehavior(QtGui.QTableView.SelectRows)
view.resizeColumnsToContents()
return view

def setupForm(self):
# set up the widgets
intBox = QtGui.QSpinBox()
strEdit = QtGui.QLineEdit()
dateEdit = QtGui.QDateEdit()
floatEdit = QtGui.QLineEdit()
decEdit = QtGui.QLineEdit()
# set up the mapper
self.mapper = QtGui.QDataWidgetMapper(self)
self.mapper.setModel(self.myModel)
self.mapper.addMapping(intBox, 0)
self.mapper.addMapping(strEdit, 1)
self.mapper.addMapping(dateEdit, 2)
self.mapper.addMapping(floatEdit, 3)
self.mapper.addMapping(decEdit, 4)
# set up the layout
form = QtGui.QWidget()
layout = QtGui.QFormLayout()
layout.addRow(Int:, intBox)
layout.addRow(String:, strEdit)
layout.addRow(Date:, dateEdit)
layout.addRow(Float:, floatEdit)
layout.addRow(Decimal:, decEdit)
form.setLayout(layout)
return form

def showModelData(self):
print(--- Model data: ---)
for i in range(self.myModel.rowCount()):
inr = self.myModel.data(self.myModel.index(i, 0))
desc = self.myModel.data(self.myModel.index(i, 1))
day = self.myModel.data(self.myModel.index(i, 2))
fl = self.myModel.data(self.myModel.index(i, 3))
dec = self.myModel.data(self.myModel.index(i, 4))
print({0}: {1} / {2}, {3}, {4} ({5}).format(inr, desc, 
day, fl,

  dec, type(dec)))
print(--- End of model data ---)

app = QtGui.QApplication(sys.argv)
dia = MyDialog(RAWDATA)
dia.show()
app.exec_()
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] QStandardItemModel: problems with non-string data

2012-07-04 Thread Sibylle Koczian

Hello,

I want to show records containing a numeric field and a date field in a 
 QTableView connected to a QStandardItemModel.


The numeric field: if that gets its value from a floating point literal, 
this value is displayed in the view. If the value comes from a database 
table the view column is empty. The database column is Numeric(9,2), the 
RDBMS is PostgreSQL.


If I create the QStandardItem for the date column using a Python 
datetime the view column is empty. If I use a QDate it's displayed 
correctly. This is independent of the data source. I don't understand 
it, because the documentation for QDate says: A Python date object may 
be used whenever a QDate is expected. Same thing for datetime objects. 
And there is no direct conversion from a Python date or datetime to a 
QDate or QDateTime.


I can send an example if necessary - but changing the database to SQLite 
might alter the behavior, and everything else would need adapting.


Python 3.2.3, PyQt4 4.9.4, Windows 7 (64 bit, german - might this be a 
localization issue?).


Thank you for hints,
Sibylle
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] PyQt4.QtCore not a valid Win32 application - with windowsinstaller

2010-01-10 Thread Sibylle Koczian

Hello,

I posted this a week ago, but didn't get any answer at all. So I'm 
trying again, because I really would like to use PyQt again, and I'd 
definitely prefer the Windows installer, if at all possible.


Sibylle Koczian schrieb:

Hello,

trying to import PyQt4.QtCore I get this:

Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit
(AMD64)] on win32
Type copyright, credits or license() for more information.

import PyQt4.QtCore

Traceback (most recent call last):
  File pyshell#4, line 1, in module
import PyQt4.QtCore
ImportError: DLL load failed: %1 ist keine zulässige Win32-Anwendung.

(Translation: %1 is no valid Win32 application.)

Using Windows 7 Home Premium 64 bit, Python version see above, PyQt from
the Windows installer: PyQt-Py3.1-gpl-4.6.2-2.exe.

I know there are earlier posts about this, but not, I think, with the
installer package from the Riverbank download page.

The Visual C++ redistributable package is installed in the 32 bit and in 
the 64 bit version.


One thing looked suspicious when I started the installation: I got a 
message window saying Python 3.1. doesn't seem to be installed - but 
it's there, in C:\Python31, and afterwards it was found without manual 
intervention.


What's the matter here?



Is the windows installer supposed to work with 64 bit Windows and 64 bit 
Python? On the Riverbank web site I don't find anything to the contrary, 
so I'd think it should work. Right or wrong?


Thank you for help,
Sibylle

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


[PyQt] PyQt4.QtCore not a valid Win32 application - with windows installer

2010-01-03 Thread Sibylle Koczian

Hello,

trying to import PyQt4.QtCore I get this:

Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit
(AMD64)] on win32
Type copyright, credits or license() for more information.

import PyQt4.QtCore

Traceback (most recent call last):
  File pyshell#4, line 1, in module
import PyQt4.QtCore
ImportError: DLL load failed: %1 ist keine zulässige Win32-Anwendung.

(Translation: %1 is no valid Win32 application.)

Using Windows 7 Home Premium 64 bit, Python version see above, PyQt from
the Windows installer: PyQt-Py3.1-gpl-4.6.2-2.exe.

I know there are earlier posts about this, but not, I think, with the
installer package from the Riverbank download page.

The Visual C++ redistributable package is installed in the 32 bit and in 
the 64 bit version.


One thing looked suspicious when I started the installation: I got a 
message window saying Python 3.1. doesn't seem to be installed - but 
it's there, in C:\Python31, and afterwards it was found without manual 
intervention.


What's the matter here?

Thank you,
Sibylle

--
Dr. Sibylle Koczian


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


[PyQt] Subclassing QSqlQueryModel, making one column checkable

2009-08-16 Thread Sibylle Koczian
Hello,

I want to do the following: get two normal columns and one boolean
expression computed by a subquery from my database table, put them into
a QSqlQueryModel and show one of the columns in a QListView. Works so far.

But I'd like to make this column checkable. At the start of the
application the state should depend on the value of my boolean
expression in another column. I get so far with the code shown below.

But then the user should be able to check and uncheck items in the view,
without changing either the text in the column or the value of the
boolean column of the model. I suppose I should overwrite setData, just
for the CheckStateRole, but how?

Or would it be better to use a QStandardItemModel, because
QStandardItems have all the methods I need?

Here is the code for the model:

class EigReiseModel(QtSql.QSqlQueryModel):

def flags(self, index):
flags = QtSql.QSqlQueryModel.flags(self, index)
if index.column() == 1:
flags |= QtCore.Qt.ItemIsUserCheckable
return flags

def data(self, index, role=QtCore.Qt.DisplayRole):
zl = index.row()
if index.column() == 1 and role == QtCore.Qt.CheckStateRole:
idx2 = self.createIndex(zl, 2)
if self.data(idx2).toBool():
return QtCore.Qt.Checked
else:
return QtCore.Qt.Unchecked
else:
return QtSql.QSqlQueryModel.data(self, index, role)

##def setData(self, index, value, role=QtCore.Qt.EditRole):
##if index.column() == 1 and role == QtCore.Qt.CheckStateRole:
##chk = value.toBool()
##if chk:
##??? (check item, but how?)

Thank you for all hints,
Sibylle

-- 
Sibylle Koczian


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


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

2009-06-24 Thread Sibylle Koczian
 Message: 1
 Date: Tue, 23 Jun 2009 14:41:20 +0200
 From: V. Armando Sol? s...@esrf.fr
 Subject: Re: [PyQt] Pressing enter in QLineEdit clicks QPushButton?
 To: Mads Ipsen m...@comxnet.dk
 Cc: Sibylle Koczian sibylle.kocz...@t-online.de,PyQt-Liste
   pyqt@riverbankcomputing.com
 
 Mads Ipsen wrote:
 rom 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:

 
 It is certainly not the correct solution if you really need a dialog :-)
 

Right, but in this case I don't need a return value from my window and
so I don't think I need a dialog. This is a small application with only
one form.

 You can also call setAutoDefault(False) for all the buttons.
 

Yes, just tried it, that works too. So, this being solved, on to the
next problem I won't be able to solve for myself.

Thank you,
Sibylle
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


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

2009-06-23 Thread Sibylle Koczian
Mads Ipsen schrieb:
 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:
 

Yes, I think so too. Tried it, works, thanks to you both!

Sibylle


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


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

2009-06-22 Thread Sibylle Koczian
Mads Ipsen m...@comxnet.dk 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(uWrite something and press Enter)
self.pushtest = QPushButton(uTest button)
self.log = QTextBrowser()
btFertig = QPushButton(uExit)
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(uLine 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_()



-- 
Dr. Sibylle Koczian 

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


[PyQt] Pressing enter in QLineEdit clicks QPushButton?

2009-06-20 Thread Sibylle Koczian
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

-- 
Sibylle Koczian

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


Re: [PyQt] QSqlTableModel: how to check the UPDATE statement inside the model?

2008-03-17 Thread Sibylle Koczian
Am Dienstag, 11. März 2008 23:11:31 schrieb Hans-Peter Jansen:
 Am Dienstag, 11. März 2008 schrieb Sibylle Koczian:
  Hello,
 
  somewhere in the QSqlTableModel code there must be SQL statements for
  UPDATE, INSERT and DELETE, to make the model editable. Right? I can't
  find methods to view these statements - is it necessary to dig into the
  C++ code to find them?
 
  Background: I'm still trying to edit data in a view (SQL view, not Qt
  view) joining two tables. I wrote a trigger to make this possible at all,
  and in the command line client the update statements I construct myself
  are executed correctly. Same thing in PyQt, if I use QSqlQuery instances
  directly.
 
  The database is Firebird 2.0.3, Qt version 4.3.4, PyQt 4.3.3, Python
  2.5.1, OS Gentoo Linux.
 
  If I use a QSqlTableModel, things get complicated: with the view in
  the Employee example database (phone_list) all is still well, the
  database tables are updated using the view. With my own database I don't
  get any error messages, but no updates either. INSERT works as expected.
 
  If I could execute the UPDATE statement used by the model in the command
  line client, I might find out what happens  - a bug in my trigger is
  quite probable. But for this I have to know this statement.
 
  Can anybody help me?

 Well, QSqlQuery/QSqlResult of Qt3 fame had a method lastQuery(). Otherwise,
 if you won't look into Qt itself (which was very enlightening, each time I
 did that), you're always open to redirect the db communication over the
 network, and trace that. tcpdump and wireshark are nice tools in this
 respect.


I did dig around a little in the Qt sources, changed my triggers, and found a 
way to update the SQL view. But perhaps there is a better way, so I'll put it 
here. The problem seems to be that a SQL view doesn't have a primary key. But 
my view is such that the primary key of one of the participating tables can 
very well be used as surrogate primary key of the view. So I've subclassed 
QSqlTableModel like this, because setPrimaryKey is protected: 

class SqlViewModel(QtSql.QSqlTableModel):

def setTable(self, viewname, primname):
QtSql.QSqlTableModel.setTable(self, viewname)
db = self.database()
prim = db.primaryIndex(primname)
self.setPrimaryKey(prim)

Of course I can post the whole (still small) application - but the database is 
Firebird and adapting the triggers to SQLite would probably produce lots of 
other bugs. But if anyone is interested I'll try.

Regards,
Sibylle

-- 
Dr. Sibylle Koczian

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


[PyQt] QSqlTableModel: how to check the UPDATE statement inside the model?

2008-03-11 Thread Sibylle Koczian
Hello,

somewhere in the QSqlTableModel code there must be SQL statements for UPDATE, 
INSERT and DELETE, to make the model editable. Right? I can't find methods to 
view these statements - is it necessary to dig into the C++ code to find 
them? 

Background: I'm still trying to edit data in a view (SQL view, not Qt view) 
joining two tables. I wrote a trigger to make this possible at all, and in 
the command line client the update statements I construct myself are executed 
correctly. Same thing in PyQt, if I use QSqlQuery instances directly.

The database is Firebird 2.0.3, Qt version 4.3.4, PyQt 4.3.3, Python 2.5.1, OS 
Gentoo Linux.

If I use a QSqlTableModel, things get complicated: with the view in 
the Employee example database (phone_list) all is still well, the 
database tables are updated using the view. With my own database I don't get 
any error messages, but no updates either. INSERT works as expected.

If I could execute the UPDATE statement used by the model in the command line 
client, I might find out what happens  - a bug in my trigger is quite 
probable. But for this I have to know this statement.

Can anybody help me?

Thank you,
Sibylle

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


Re: [PyQt] Standard font in PyQt applications (Eric included)

2008-02-14 Thread Sibylle Koczian
Am Mittwoch, 13. Februar 2008 23:38:49 schrieb Danny Pansters:

 I think you'd want to run qtconfig, not the qt3 version, but the qt4
 version. On FreeBSD it's called qtconfig-qt4. For gentoo, look at your
 qt4's ebuilds to see under what name it gets installed. Then you can set
 fonts for all qt4 apps.


Many thanks, that did it.
Sibylle

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


[PyQt] Standard font in PyQt applications (Eric included)

2008-02-13 Thread Sibylle Koczian
Hello,

I'm using PyQt 4.3.3, Qt 4.3.3, Eric 4.0.4(r1711), sip 4.7.3, QScintilla 2.1, 
Python 2.5.1 on Gentoo Linux, with KDE 3.5.8 as my Desktop manager. After one 
of the last Gentoo updates the font in Eric and in all my PyQt applications 
suddenly changed to something very small and quite ugly. Regarding Eric: it's 
not the font used for the source code - that didn't change and would be 
easily reset. It's the font for menus, buttons and the like.

I don't much want to set a font explicitly in every application, and until 
this upgrade it was quite nice. What can have happened? Which information 
would be useful?

No change of fonts in other applications, including KDE itself.

Regards,
Sibylle

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


Re: [PyQt] problem in variable usage in sql statement

2008-02-09 Thread Sibylle Koczian
Am Donnerstag, 7. Februar 2008 10:03:55 schrieb Phil Thompson:

 Dynamically create the string you want...

 db.query(
   SELECT OS, IP_Adress
   FROM ServerDB
   WHERE IP_Adress = '%s'
% chosen)


Why not use prepare and bindValue?

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


[PyQt] View made updatable by trigger - no update in QTableView

2008-01-28 Thread Sibylle Koczian
Hello,

the firebird example database contains a view which is read-only by nature. 
But by adding a trigger I made some of its fields editable. That works in the 
command line client, but I can't get it to work in a PyQt example program.

I took the cachedtable.py example, changed the createConnection() function 
and put the name of the view into the setTable() call of the 
QSqlTableModel. If I change a value in one of the columns that should now be 
editable, I get this error message: 
The database reported an error: Unsuccessful execution caused by system error
that does not preclude successful execution of subsequent statements Unable to
execute query

Here is the complete example (without the Trolltech Copyright notice):

#!/bin/env python

import sys
from PyQt4 import QtCore, QtGui, QtSql

def createConnection():
db = QtSql.QSqlDatabase.addDatabase(QIBASE)
db.setDatabaseName(localhost:employee)
db.setUserName('sysdba')
db.setPassword('masterkey')
if not db.open():
print Datenbank lässt sich nicht öffnen.
return False
print Datenbank offen.
return True

class TableEditor(QtGui.QDialog):
def __init__(self, tableName, parent = None):
QtGui.QDialog.__init__(self, parent)

self.model = QtSql.QSqlTableModel(self)
self.model.setTable(tableName)
self.model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)
self.model.select()

self.model.setHeaderData(0, QtCore.Qt.Horizontal,
 QtCore.QVariant(self.tr(ID)))
self.model.setHeaderData(1, QtCore.Qt.Horizontal,
 QtCore.QVariant(self.tr(First name)))
self.model.setHeaderData(2, QtCore.Qt.Horizontal,
 QtCore.QVariant(self.tr(Last name)))
self.model.setHeaderData(3, QtCore.Qt.Horizontal,
 QtCore.QVariant(self.tr(Phone Ext)))
self.model.setHeaderData(4, QtCore.Qt.Horizontal,
 QtCore.QVariant(self.tr(Dept. Location)))
self.model.setHeaderData(5, QtCore.Qt.Horizontal,
 QtCore.QVariant(self.tr(Dept. Phone No)))

view = QtGui.QTableView()
view.setModel(self.model)

self.submitButton = QtGui.QPushButton(self.tr(Submit))
self.submitButton.setDefault(True)
self.revertButton = QtGui.QPushButton(self.tr(Revert))
self.quitButton = QtGui.QPushButton(self.tr(Quit))

self.connect(self.submitButton, QtCore.SIGNAL(clicked()), 
self.submit)
self.connect(self.revertButton, QtCore.SIGNAL(clicked()), 
 self.model.revertAll)
self.connect(self.quitButton, QtCore.SIGNAL(clicked()), self.close)

buttonLayout = QtGui.QVBoxLayout()
buttonLayout.addWidget(self.submitButton)
buttonLayout.addWidget(self.revertButton)
buttonLayout.addWidget(self.quitButton)
buttonLayout.addStretch(1)

mainLayout = QtGui.QHBoxLayout()
mainLayout.addWidget(view)
mainLayout.addLayout(buttonLayout)
self.setLayout(mainLayout)

self.setWindowTitle(self.tr(Cached Table))

def closeEvent(self,  event):
print Jetzt ist Schluss.
QtSql.QSqlDatabase.database().close()
event.accept()

def submit(self):
self.model.database().transaction()
if self.model.submitAll():
self.model.database().commit()
else:
self.model.database().rollback()
QtGui.QMessageBox.warning(self, self.tr(Cached Table),
self.tr(The database reported an error: %1)
.arg(self.model.lastError().text()))

if __name__ == __main__:
app = QtGui.QApplication(sys.argv)
if not connection_fb.createConnection():
sys.exit(1)
editor = TableEditor(phone_list)
editor.show()
sys.exit(app.exec_())


What is wrong? I will try to reproduce the problem on SQLITE, but that may 
take a little time.

Thank you,
Sibylle

-- 
Dr. Sibylle Koczian

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


Re: [PyQt] How to communicate with mysql?

2008-01-27 Thread Sibylle Koczian
Am Samstag, 26. Januar 2008 19:05:38 schrieb Ryen Lee:
 Hi everybody! I am a newbie for PyQT.Now I am write a simple programm which
 use mysql as its database,but I find it is very diffucult to use the PyQT
 APIs.I write sth like that:

 db = QtSql.QSqlDatabase.addDatabase(QMYSQL)
 db.setHostName(127.0.0.1)
 db.setDatabaseName(test)
 db.setUserName(root)
 db.setPassword(123456)
 db.open()

 but it just doesn't work. snip

Meaning? What does db.open() return, True or False? Does the database test 
exist? And is Qt configured with MySQL support? 

Or did you perhaps call these methods before you had created a QApplication or 
a QCoreApplication object? That won't work and the error messages aren't very 
helpful for this case.

I can't test your code, because I don't have MySQL installed.

HTH
Sibylle

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


Re: [PyQt] Creating an action with a verbose signal

2008-01-25 Thread Sibylle Koczian
Am Freitag, 25. Januar 2008 11:02:02 schrieb Phil Thompson:
 On Friday 25 January 2008, Martin Höfling wrote:
  Hi all,
 
  I am a bit confused how to realize the following, any hint's are welcome:
 
  What I have is a menu, this menu should be filled with all executable
  scripts in a directory. On menu selection, the selected script should be
  executed. So far so good.
 
  Here come's the problem: For each file i create a QAction object, add
  this to the menu and connect it's triggered() signal with a python
  function blubb. The problem is to distinguish from which QAction/File
  blubb has been called.
 
  Any hint's how to solve this?

 QObject.sender()

 or

 QSignalMapper

 or

 Connect to a lambda function that calls blubb with the action as an
 argument.


or

import functools
...
connect to functools.partial(blubb, filename)


-- 
Dr. Sibylle Koczian

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


[PyQt] QSqlQuery / Firebird: alternating two prepared queries

2008-01-23 Thread Sibylle Koczian
Hello,

the script below should take the strings in the list newData and put the
contents into two different tables of the Firebird example database
employee.fdb. Strings starting with C belong to the customer table and
the insert statement returns the newly created cust_no (new in firebird 2.0).
Strings starting with O belong to table sales and their content is 
combined with the last new cust_no to form a new record.

In the present form, with all transaction() and commit() calls commented
out, I get the DatabaseError insOrder deadlock Unable to execute query. Same
error if I uncomment the calls labeled Transaction use 1. This probably
shouldn't work because the documentation says When using transactions you 
must start the transaction before you create your query. - but it would be 
the sensible way to do the inserts.

If I uncomment instead the calls labeled Transaction use 2, then I get 
another error message from the second call to insCustomer: insCustomer/exec 
The cursor identified in a FETCH or CLOSE statement is not open. Unable to 
close statement

In all the cases no new record gets into the database. What is wrong? Of
course, in this very small example I could first put all the C records in,
collect the new cust_no values in a list and process them together with 
the O records. But what if this is no tiny example list, but a huge file?

Thanks for any shove in the right direction,
Sibylle


import sys
from PyQt4.QtCore import *
from PyQt4.QtSql import *

newData = ['C;Moritz;Germany', 'O;V08A0001;141;520.10', 
   'C;Capitalism Kill  Destroy Ltd.;England', 'O;V08A0002;6;7200', 
   'C;Camorra Corp.;Italy', 'O;V08A0003;121;240', 
   'C;Adam  Eve;Austria', 'O;V08A0004;141;3500', 
   'C;Toblerone Inc.;Switzerland', 'O;V08A0005;141;689.50']

class DatabaseError(Exception):
pass

def employeeConn(user='sysdba', passwd='masterkey'):
db = QSqlDatabase.addDatabase('QIBASE')
db.setHostName('localhost')
db.setConnectOptions('ISC_DPB_LC_CTYPE=ISO8859_1')
db.setDatabaseName('Employee')
db.setUserName(user)
db.setPassword(passwd)
ok = db.open()
msg = (db.lastError().text() if not ok else '')
return (ok, msg)

def insCustomer(custdata, query):
(idchar, custname,  custcountry) = custdata.split(';')
custno_var = QVariant()
query.bindValue(':customer', QVariant(custname))
query.bindValue(':country', QVariant(custcountry))
if not query.exec_():
raise DatabaseError, 'insCustomer/exec %s' % query.lastError().text()
if query.first():
custno_var = query.value(0)
else:
raise DatabaseError, 'insCustomer/first %s' % query.lastError().text()
return custno_var

def insOrder(custno_var, orderdata, query):
(idchar, orderno, salesrep, total) = orderdata.split(';')
query.bindValue(':po_number', QVariant(orderno))
query.bindValue(':cust_no', custno_var)
query.bindValue(':sales_rep', QVariant(salesrep))
query.bindValue(':total_value', QVariant(total))
if not query.exec_():
raise DatabaseError, 'insOrder %s' % query.lastError().text()
   
def main(args):
app = QCoreApplication(args)
(ok, msg) = employeeConn()
if not ok:
print msg
sys.exit(1)
try:
# Transaction use 2
#QSqlDatabase.database().transaction()
custQuery = QSqlQuery()
custQuery.prepare('INSERT INTO CUSTOMER (customer, country) '
  'VALUES (:customer, :country) RETURNING cust_no')
orderQuery = QSqlQuery()
orderQuery.prepare('INSERT INTO SALES (po_number, cust_no, 
sales_rep, '
   'total_value) VALUES (:po_number, :cust_no, '
   ':sales_rep, ':total_value)')
new_custno = QVariant()
for data in newData:
# Transaction use 1
#QSqlDatabase.database().transaction()
if data.startswith('C'):
new_custno = insCustomer(data, custQuery)
elif data.startswith('O'):
insOrder(new_custno, data, orderQuery)
# Transaction use 1
#QSqlDatabase.database().commit()
print data
# Transaction use 2
#QSqlDatabase.database().commit()
except DatabaseError, e:
print e
finally:
QSqlDatabase.database().close()
print 'Ready.'

if __name__ == '__main__':
main(sys.argv)

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


[PyQt] PyQt book: problem with database example

2008-01-09 Thread Sibylle Koczian
Hello,

the assetmanager.pyw example doesn't seem to work correctly, or I'm using it 
wrongly:

- The logs view always shows one empty line after the records belonging to the 
selected asset. Why? When I try to write such a master-detail dialog myself, 
using the asset manager as a model, I get even more empty lines, and their 
number changes. Should I try to shrink it to a minimal example still showing 
the problem, or is this a known issue?

- After leaving the application I get the error 
message QSqlDatabasePrivate::removeDatabase: 
connection 'qt_sql_default_connection' is still in use, all queries will 
cease to work.  I have had this message in my own programs - it went away, 
when I didn't define a main funktion, but put its content directly 
under if __name__ == '__main__':. But I never understood why this should be 
so.

Thank you for hints,
Koczian

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


Re: [PyQt] QSqlQuery: one parameter in two different places?

2008-01-02 Thread Sibylle Koczian
Am Dienstag, 1. Januar 2008 23:22:38 schrieb Hans-Peter Jansen:

 On debugging such problems, I found QSqlQuery.lastQuery() pretty useful
 (before digging in the Qt source..). Hopefully it still exists in Qt4.
 Applied to your problem, let us know about the outcome.


QSqlQuery.lastQuery() still exists, there is also QSqlQuery.executedQuery(). 
Applied to my problem they give:

1. One parameter name in both places:

def abrechnung(datum):
sqltext = UPDATE ausgaben SET abrech_datum = :a_datum
WHERE abrech_datum IS NULL AND ausg_datum  :a_datum
query = QSqlQuery()
query.prepare(sqltext)
query.bindValue('a_datum', QVariant(datum))
query.exec_()
print 'numRowsAffected:', query.numRowsAffected()
print 'lastQuery:', query.lastQuery()
print 'executedQuery:', query.executedQuery()

result:
numRowsAffected: -1 (in fact nothing was updated)
lastQuery: UPDATE ausgaben SET abrech_datum = :a_datum
WHERE abrech_datum IS NULL AND ausg_datum  :a_datum
executedQuery: UPDATE ausgaben SET abrech_datum = ?
WHERE abrech_datum IS NULL AND ausg_datum  ?

Why the '?'? 

2. Two names for the same parameter:

def abrechnung(datum):
sqltext = UPDATE ausgaben SET abrech_datum = :a_datum
WHERE abrech_datum IS NULL AND ausg_datum  :b_datum
query = QSqlQuery()
query.prepare(sqltext)
query.bindValue('a_datum', QVariant(datum))
query.bindValue('b_datum', QVariant(datum))
query.exec_()
print 'lastQuery:',
print query.lastQuery()
print 'executedQuery:',
print query.executedQuery()

result:
numRowsAffected: 2 (which is correct)
lastQuery: UPDATE ausgaben SET abrech_datum = :a_datum
WHERE abrech_datum IS NULL AND ausg_datum  :b_datum
executedQuery: UPDATE ausgaben SET abrech_datum = ?
WHERE abrech_datum IS NULL AND ausg_datum  ?

Again '?' in place of values for the parameters, but this time it works.

Should I send a little more code to make a complete example? Or does this tell 
enough about the problem?

Thank you,
Sibylle

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


[PyQt] QDateEdit keeps me strictly in current month

2008-01-02 Thread Sibylle Koczian
Hello,

to my inexperienced eyes this looks like a bug: a QDateEdit should let me 
choose any day in the last month, but I can't get to dates this past 
December. Direct editing doesn't work, using the arrow for earlier dates 
doesn't work. 

If I change the date range to November 2, 2007 until December 2, 2007, I can 
reach every day if I change first the month and then the day. This isn't very 
intuitive using my normal date format (day.month.year), but at least it 
works. For December 2, 2007 to January 2, 2008 I didn't find any workaround.

My suspicion: this happens, because the date has to stay valid all through the 
editing process, and this isn't always possible.

Here is my test application. Changing between 
lastdate = today 
and 
lastdate = today.addMonths(-1) (commented out)
should demonstrate the problem.

# test_dateedit_dlg.py
# QDateEdit testen

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

class TestDateDlg(QDialog):

def __init__(self, parent=None):
super(TestDateDlg, self).__init__(parent)
today = QDate.currentDate()
lastdate = today
#lastdate = today.addMonths(-1)
firstdate = today.addMonths(-2)
self.edDate = QDateEdit()
self.edDate.setDateRange(firstdate, lastdate)
self.edDate.setDate(lastdate)
self.edDate.setDisplayFormat('dd.MM.')
self.datelist = QListWidget()
self.datelist.addItem(QString('Starting date: %1')\
  .arg(lastdate.toString(Qt.ISODate)))
self.datelist.addItem(QString('Current date: %1')\
  .arg(firstdate.toString(Qt.ISODate)))
layout = QVBoxLayout()
layout.addWidget(self.edDate)
layout.addWidget(self.datelist)
self.setLayout(layout)
self.connect(self.edDate, SIGNAL('editingFinished()'), self.logDate)

def logDate(self):
newdate = self.edDate.date().toString(Qt.ISODate)
self.datelist.addItem(QString('New date: %1').arg(newdate))

if __name__ == '__main__':
app = QApplication(sys.argv)
form = TestDateDlg()
form.show()
app.exec_()



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


[PyQt] QSqlQuery: one parameter in two different places?

2008-01-01 Thread Sibylle Koczian
Hello, 

my SQL query has this form:

sqltext = 'UPDATE mytable SET field_1 = :newvalue WHERE field_2  :newvalue'

The database is SQLITE. If I use this query as is:

query = QSqlQuery()
query.prepare(sqltext)
query.bindValue(':newvalue', QVariant(mynewvalue))
query.exec()

then nothing is updated. If I change to

sqltext = 'UPDATE mytable SET field_1 = :value_1 WHERE field_2  :value_2'
query = QSqlQuery()
query.prepare(sqltext)
query.bindValue(':value_1', QVariant(mynewvalue))
query.bindValue(':value_2', QVariant(mynewvalue))
query.exec()

the update works as expected. Can't I use the same parameter name in two 
different places of the query, if I want to use the same value twice?

Thank you,
Sibylle

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


Re: [PyQt] qtable data source

2007-12-23 Thread Sibylle Koczian
Am Sonntag, 23. Dezember 2007 06:50:44 schrieb nishith datta:
 hi all,
   I wish to show the output of my sql query in  a table.
   I am unable to do that.
   Can someone point out some resource / example or documentation to help me
 out. thanks in advance

http://doc.trolltech.com/4.0/sql.html

Is this no good? If no, why not? Or, of course, the book: Mark Summerfield, 
Rapid GUI programming with Python and Qt, Prentice Hall 2007, ISBN 
0-13-235418-7.

Sibylle

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


Re: [PyQt] QDataWidgetMapper

2007-12-03 Thread Sibylle Koczian
Am Montag, 3. Dezember 2007 08:45:43 schrieben Sie:
 On Sun, 2007-12-02 at 12:00 +0100, Sibylle Koczian wrote:
  Did you solve your problem? I've tried several variations, but the only
  one that did help was putting your data into a QStandardItemModel.

 Yes, sorry for not getting back here. The main error was in data(). It
 did not correctly return data when role was EditRole (which is what
 QDataWidgetMapper asks for).


Where did you find that? Is it in the documentation, or in one of the 
examples? If so, I've overlooked it. 

  Things I tried:
  - subclassing QAbstractTableModel instead of QAbstractItemModel, because
  your model isn't hierarchical

 Yeah, I guess this makes more sense. Some of the functions in my model
 can be eliminated then.


And the rowCount() can be simplified again. As it is, it isn't quite correct:

def rowCount(self, parent):
if not parent.isValid():
return len(words)
else:
return 0

If parent is None (normal in your model) then it has no attribute isValid(). I 
changed it to if parent is None or not parent.isValid(), but that's ugly 
and I'm not sure if it's really the logic you meant.

  - making column 1 of the model editable

 Did you do that by returning ItemIsEditable from flags()?


Not quite. For this there is an example in the Model / View programming part 
of the documentation:

def flags(self, index):
flags = QtCore.QAbstractItemModel.flags(self, index)
if index.column()  0:
flags |= QtCore.Qt.ItemIsEditable
return flags

def setData(self, index, value, role=QtCore.Qt.EditRole):
if not (index.isValid() and role == QtCore.Qt.EditRole):
return False
if index.column() == 1:
words[index.row()]['opposite'] = value.toString()
else:
return False
self.emit(QtCore.SIGNAL('dataChanged(const QModelIndex , const 
QModelIndex )'), index, index)
return True

  What does the QDataWidgetMapper expect from a model?

 Nothing more than it being correct :)


Well, I don't think a model not returning anything for the EditRole is 
necessary wrong in itself and in all circumstances. 

 I used the modeltest.py from contrib to fix some things in my model (but
 it had no way of detecting my error in data()).


What and where is that?

Thank you,
Sibylle
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] QDataWidgetMapper

2007-12-02 Thread Sibylle Koczian
Hello, Daniel,

Am Montag, 26. November 2007 13:59:52 schrieb Daniel Lundqvist:
 Hey,

 I've been struggling to get the above to work correctly. I've looked
 around but haven't found a solution to my problem yet.

 The issue I'm having is I can't get the mapper to update the widgets at
 all. Not even when I call setCurrentIndex(n).

 I'm attaching my sample project that shows the problem. The sample
 contains a simple model with two columns. One combo box show column 0
 from the model and a QLineEdit should show second column from the index
 selected in the combo box. (I've also tried connecting
 QComboBox::activated(int) - QDataWidgetMapper::setCurrentIndex(int) to
 no avail).


Did you solve your problem? I've tried several variations, but the only one 
that did help was putting your data into a QStandardItemModel.

Things I tried:
- subclassing QAbstractTableModel instead of QAbstractItemModel, because your 
model isn't hierarchical
- storing the data directly in the model
- making column 1 of the model editable
- setting the model row in the __init__ method either with .toFirst() or 
with .setCurrentIndex(self.ui.comboBox.currentIndex())

In another variation I put an additional QTableView into the main window. This 
shows all the data correctly and can easily be synchronized with the 
combobox. But still the QLineEdit is empty.

In the meantime I got my copy of the PyQt book, but it uses the 
QDataWidgetMapper only with data from a database, not with a custom model.

What does the QDataWidgetMapper expect from a model?

Sibylle

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


Re: [PyQt] QDataWidgetMapper

2007-11-27 Thread Sibylle Koczian
Am Montag, 26. November 2007 13:59:52 schrieb Daniel Lundqvist:
 Hey,

 I've been struggling to get the above to work correctly. I've looked
 around but haven't found a solution to my problem yet.

 The issue I'm having is I can't get the mapper to update the widgets at
 all. Not even when I call setCurrentIndex(n).

 I'm attaching my sample project that shows the problem. The sample
 contains a simple model with two columns. One combo box show column 0
 from the model and a QLineEdit should show second column from the index
 selected in the combo box. (I've also tried connecting
 QComboBox::activated(int) - QDataWidgetMapper::setCurrentIndex(int) to
 no avail).


I'm just playing with the QDataWidgetMapper myself, so I looked at your 
project and tried some changes. Changing the model to a QStandardItemModel, 
QSqlQueryModel, QSqlTableModel (with a SQLite memory database) didn't help. 
But if I take the combobox out, then the QLineEdit shows content.

In my own project I've got a main window containing a QTableView and a QDialog 
containing only QLineEdit controls using a QDataWidgetMapper. That works.

Could it be that you can't mix controls using a model directly and controls 
using a QDataWidgetMapper in the same window? Looks very strange.

Just replacing one riddle by a new one, I'm afraid.

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


Re: [PyQt] How to use QButtonGroup?

2007-11-27 Thread Sibylle Koczian
Am Sonntag, 25. November 2007 23:58:52 schrieb David Boddie:
 On Sun Nov 25 14:05:39 GMT 2007, Sibylle Koczian wrote:
  I'm reading the documentation about QButtonGroup and QGroupBox and I
  don't quite understand the relationship between them.

 I think the relationship between them in Qt 3 is a different to that in Qt
 4, so that might also be a cause of confusion for some people.


I don't know much Qt 3, Qt 4 alone is just difficult enough.

  I can create QRadioButtons and put them into a QGroupBox. That makes them
  visible and mutually exclusive. And, of course, I should put a layout
  between the box and the buttons. Right?

 Correct.

  If I put those same buttons into a QButtonGroup, then I can map them to
  integers, and I can connect the buttonClicked(int) signal of the group to
  a method or function that can use the id of the button. Still right?

 Correct again.

  But there seems to be no connection between the QGroupBox and the
  QButtonGroup. I have to put each of my radio buttons into the box _and_
  into the buttongroup. Right, or did I overlook something?

 Yes, the QButtonGroup object just acts as a messenger for the buttons. You
 still need to put them inside a widget, and a QGroupBox widget is usually
 the sort of widget you would use.


Thank you, so that's cleared up. The next problem is still too vague for 
sensible questions, but they will come.

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


Re: [PyQt] QDataWidgetMapper

2007-11-27 Thread Sibylle Koczian
Am Dienstag, 27. November 2007 20:02:51 schrieb Sibylle Koczian:

 I'm just playing with the QDataWidgetMapper myself, so I looked at your
 project and tried some changes. Changing the model to a QStandardItemModel,
 QSqlQueryModel, QSqlTableModel (with a SQLite memory database) didn't
 help. But if I take the combobox out, then the QLineEdit shows content.

Wrong. I had added errors of my own. The problem _does_ lie in your model, 
only I can't find it there. 

 In my own project I've got a main window containing a QTableView and a
 QDialog containing only QLineEdit controls using a QDataWidgetMapper. That
 works.

 Could it be that you can't mix controls using a model directly and controls
 using a QDataWidgetMapper in the same window? Looks very strange.

No, it's not that. If you replace your dwm.py with the following, only 
slightly longer class definition, the QLineEdit shows the right content and 
this content follows changes in the QComboBox.

-
from PyQt4 import QtGui, QtCore

from ui_dwm import Ui_Dwm

# from mymodel import MyModel
import mymodel

class Dwm(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)

self.ui = Ui_Dwm()
self.ui.setupUi(self)

#   self.model = mymodel.MyModel()
# new, koc
self.model = self.makeModel()
self.ui.comboBox.setModel(self.model)

self.dwm = QtGui.QDataWidgetMapper()
self.dwm.setModel(self.model)
self.dwm.addMapping(self.ui.lineEdit, 1)
self.dwm.toFirst()
# new, koc
self.connect(self.ui.comboBox, 
QtCore.SIGNAL(currentIndexChanged(int)), 
 self.dwm, QtCore.SLOT(setCurrentIndex(int)))


# new, koc
def makeModel(self):
model = QtGui.QStandardItemModel()
for word in mymodel.words:
ll = []
ll.append(QtGui.QStandardItem(word['name']))
ll.append(QtGui.QStandardItem(word['opposite']))
model.appendRow(ll)
return model
-

This just replaces your model with a QStandardItemModell filled with the same 
data. Which most probably isn't what you really need. But I really can't see 
what's wrong with your model (some quite trivial corrections excepted, which 
didn't help).

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


[PyQt] How to use QButtonGroup?

2007-11-25 Thread Sibylle Koczian
Hello,

I'm reading the documentation about QButtonGroup and QGroupBox and I don't 
quite understand the relationship between them. 

I can create QRadioButtons and put them into a QGroupBox. That makes them 
visible and mutually exclusive. And, of course, I should put a layout between 
the box and the buttons. Right? 

If I put those same buttons into a QButtonGroup, then I can map them to 
integers, and I can connect the buttonClicked(int) signal of the group to a 
method or function that can use the id of the button. Still right?

But there seems to be no connection between the QGroupBox and the 
QButtonGroup. I have to put each of my radio buttons into the box _and_ into 
the buttongroup. Right, or did I overlook something?

Thank you,
Koczian

-- 
Dr. Sibylle Koczian
Fasanenstraße 12
82293 Mittelstetten

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


Re: [PyQt] How to close QSqlDatabase connection?

2007-11-18 Thread Sibylle Koczian
Am Mittwoch, 14. November 2007 16:13:43 schrieb Sibylle Koczian:

 I will try to find out more: can I put part of the code into main(), but
 not all of it? Can I use such a function, if I don't call it main()? And
 I will certainly use another database backend (firebird), but at the moment
 I doubt very much if that will make any difference. It's more interesting
 to try PyQt applications not using a database with and without a separate
 main().


After much trial and still more error: 

- another database backend, firebird in my case, doesn't change anything.
- renaming the main() function doesn't change anything.
- PyQt applications without database connections: putting the main code 
(creating the QApplication instance, creating and showing the main window, 
calling sys.exit(app.exec_())) into a function called main() works without 
problems.
- PyQt applications with database connection: if and only if the QApplication 
instance is created in the main() function then I get this error message when 
I close the application: 
QSqlDatabasePrivate::removeDatabase: 
connection 'qt_sql_default_connection' is still in use, all queries will 
cease to work.

Why?

Sibylle

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


Re: [PyQt] How to close QSqlDatabase connection?

2007-11-14 Thread Sibylle Koczian
Am Montag, 12. November 2007 20:55:20 schrieb Hans-Peter Jansen:
 Am Montag, 12. November 2007 schrieb Sibylle Koczian:
  So I looked around and saw that I had this:
 
  def main(args):
  app = QtGui.QApplication(args)
  if not visa_conn():
  sys.exit(1)
  visa_mf = VisaMF()
  visa_mf.show()
  sys.exit(app.exec_())
 
  if __name__ == '__main__':
  main(sys.argv[1:])
 
  while cachedtable.py has no separate main function and calls the app
  constructor with the full list sys.argv. Doing the same in my own example
  seems to do the trick. But why?

 I will (hopefully) leave a more satisfying answer to the experts, but
 omitting sys.argv[0] doesn't make any sense to me anyway. Maybe the process
 name is used internally for creating the default connection name, and
 creates a None, NULL, whatever mismatch on close later in this case.

 You may want to experiment a bit with faked sys.argv args, e.g.: [], [''],
 ['xxx'], and let us know about the outcome. Using a different database
 backend would also be interesting.


I did, and the content of the argument list seems to be quite unimportant: 
app = QtGui.QApplication(args) with an arbitrary list args works without 
error message - as long as I don't use a separate main function. That seems 
to be the important difference, not the arguments to the QApplication 
constructor. Which leads again to the question: why? What's wrong with such a 
function?

I will try to find out more: can I put part of the code into main(), but not 
all of it? Can I use such a function, if I don't call it main()? And I will 
certainly use another database backend (firebird), but at the moment I doubt 
very much if that will make any difference. It's more interesting to try PyQt 
applications not using a database with and without a separate main().

Very mystified,
Sibylle

-- 
Dr. Sibylle Koczian
Fasanenstraße 12
82293 Mittelstetten

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


Re: [PyQt] How to close QSqlDatabase connection?

2007-11-12 Thread Sibylle Koczian
Am Sonntag, 11. November 2007 16:09:04 schrieb Hans-Peter Jansen:
 Dear Sibylle,

 I can only talk for PyQt3, through (yes, I'm retro..), but..


As far as I can see the version differences are particularly big in this area, 
because of the model/view design pattern. No QDataTable to start with. And  
I've not used PyQt3 beyond a little playing around with the tutorial.

 Am Sonntag, 11. November 2007 schrieb Sibylle Koczian:
  Hello,
 
  I'm trying to write a very small database application, but I can't get
  rid of this error message when I close the main
  window: QSqlDatabasePrivate::removeDatabase:
  connection 'qt_sql_default_connection' is still in use, all queries will
  cease to work.
 
 My close connection code typically contains code like (for a QDataTable
 derived case in this example):

 if self.sqlCursor():
 self.setSqlCursor()

 You may want to try to give the db instance an explicit name, and use that
 on tear down...


At the moment I'm inclined to search the error in my main function. I've 
taken the cachedtable.py example and changed it to use my SQLite database. 
This example had no close code at all, and when I put a closeEvent method 
in, I got the error message if and only if this method contained a call 
to removeDatabase. But removing this line from my own program didn't change 
anything. 

So I looked around and saw that I had this:

def main(args):
app = QtGui.QApplication(args)
if not visa_conn():
sys.exit(1)
visa_mf = VisaMF()
visa_mf.show()
sys.exit(app.exec_())

if __name__ == '__main__':
main(sys.argv[1:])

while cachedtable.py has no separate main function and calls the app 
constructor with the full list sys.argv. Doing the same in my own example 
seems to do the trick. But why?

Thank you,
Sibylle

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


[PyQt] How to close QSqlDatabase connection?

2007-11-11 Thread Sibylle Koczian
Hello,

I'm trying to write a very small database application, but I can't get rid of 
this error message when I close the main 
window: QSqlDatabasePrivate::removeDatabase: 
connection 'qt_sql_default_connection' is still in use, all queries will 
cease to work.

At the moment I'm using this code to open and to close the database:

Global function of the module:
def visa_conn():
db = QtSql.QSqlDatabase.addDatabase(QSQLITE)
db.setDatabaseName(/home/sib/pfotweg/visa_s.db)
return db.open()

Method of the main window, connected with a button:
def close(self):
db = QtSql.QSqlDatabase.database()
db.close()
db.removeDatabase(db.connectionNames()[0])
QtGui.QMainWindow.close(self)

And the main() function:
def main(args):
app = QtGui.QApplication(args)
if not visa_conn():
QtGui.QMessageBox.critical(None,  ...)
sys.exit(1)
visa_mf = VisaMF()
visa_mf.show()
sys.exit(app.exec_())

I found some posts to this list in the archive with the same error, but no 
solution. I've tried to use 'qt_sql_default_connection' as argument to 
db.removeDatabase, but that doesn't change anything. What's wrong? Or what 
additional info should I give?

Using qt-4.3.1, PyQt4-4.3.1, Python 2.5.1, Gentoo Linux.

Thanks for every hint,
Sibylle

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


Re: [PyKDE] PyQt4 windowIcon

2007-03-04 Thread Sibylle Koczian

Tina I schrieb:


pyuic4 produces this line in my 'gui file':

  MainWindow.setWindowIcon(QtGui.QIcon(../log.png))

The icon is stored in the same directory as the application it self. I 
guess I'm missing something, I just don't have any idea what. So if 
somebody could provide me with a clue I would really appreciate it.


I can see what's wrong (at least I think I see it). But I'm not using 
the designer, so I don't really know what to do about it. The 
setWindowIcon method expects the icon in the parent directory, not in 
the same directory as the application itself (that would be 
./log.png). You might simply move the icon and try again - or is that 
not an option?


HTH
Sibylle

___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] QLayout parent

2007-01-28 Thread Sibylle Koczian
  Tony Cappellini [EMAIL PROTECTED] schrieb: 
Is this what you mean?
If not- would you add an example?

[snipped]
self.h_layout.addChildLayout(self.v1_layout)
self.h_layout.addChildLayout(self.v2_layout)

Probably wrong, should be:
self.h_layout.addLayout(self.v1_layout)
self.h_layout.addLayout(self.v2_layout)

I've added 2 QVBoxLayouts as children of the QHBoxLayout.
A tiny window appears without any widgets.
What have I not done correctly? 

class Dialog(QtGui.QDialog):

 I think you've got to replace the calls to addChildLayout by calls to 
addLayout. The documentation says addChildLayout is called from addLayout - 
and I suppose addLayout does more than just this call. Trying your example with 
this change worked for me, at all events.
HTH,
Sibylle

-- 
Dr. Sibylle Koczian 
Fasanenstrasse 12 
D-82293 Mittelstetten 
___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Model-View application: view not updated

2006-12-19 Thread Sibylle Koczian
Am Sonntag, den 17.12.2006, 19:33 +0100 schrieb Andreas Pakulat:

 You should update that. PyQt4 4.0.1 doesn't have support for Qt4.2
 Actually I'm surprised they got it to build with Qt4.2, IIRC the changes
 needed are only included in PyQt4 4.1. Thats one of the reasons I roll
 my own Python/Qt4/PyQt4 into $HOME here...
 

I'll probably have to do that too (or possibly find a distribution with
the newest Python/Qt4/PyQt4).

   If you can't change your Qt version, try emitting the dataChanged
   Signal with the top-left and bottom-right QModelIndex.
  
  That has helped: I replaced the self.reset() at the end of
  setResultset() with the dataChanged Signal, now I get the original data
  back without changing focus or doing other tricks. It's not very
  beautiful, but it works for the moment.
 
 This would imply that it could be a problem in Qt4.2.0 itself. Maybe you
 know enough C++ to re-write your example in it, just for testing of
 course. It seems its fixed in later Qt4.2 versions...
 

It might be a good idea to relearn C++, but that will take time. I've
learnt the basics years ago, but then I got a Delphi 1 Demo CD and that
was that (Python came much later).

Sibylle

-- 
Dr. Sibylle Koczian
Fasanenstraße 12
D-82293 Mittelstetten


___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Model-View application: view not updated

2006-12-17 Thread Sibylle Koczian
Am Samstag, den 16.12.2006, 19:45 +0100 schrieb Andreas Pakulat:

 Ok, thanks now I do understand your problem. Unfortunately I can't
 reproduce it here with your example application. After editing two cells
 and clicking Cancel the view is updated to reflect the original data and
 I get 
 
 TestModel.setResultset called
 fillTable called
 TestModel.setResultset called
 Signal modelReset empfangen
 
 In the console, so its clearly working. What version of Qt4 are you
 using? (I'm on 4.2.x here, where x is IIRC something around 2)
 

Qt4: 4.2.0-1ubuntu6 (installed packages: libqt4-core, -def, -gui,
-qt3support, -sql, qt4-designer, qt4-doc - possibly something lacking?)
PyQt4: 4.0.1-1ubuntu1 (installed packages: pyqt4-dev-tools, python-qt4,
-qt4-dev, -doc, -sql)

 If you can't change your Qt version, try emitting the dataChanged
 Signal with the top-left and bottom-right QModelIndex.
 

That has helped: I replaced the self.reset() at the end of
setResultset() with the dataChanged Signal, now I get the original data
back without changing focus or doing other tricks. It's not very
beautiful, but it works for the moment.

BTW, making this change I saw that the rowCount() and columnCount()
methods should get parent=None as default argument.

Regarding a newer Qt and/or PyQt version, I'm thinking about changing my
linux distribution anyway, but I don't yet know what I really need.

  BTW: Did you look at the
   ready-made models for accessing SQL databases in Qt4?
  
  I didn't understand how to get the SQL support for Firebird.
 
 Load the driver? I haven't compiled firebird support here, but it should
 be as easy as that.
 
  Especially using Ubuntu which doesn't put Firebird in the standard place 
  Qt4 expects it in.
 
 Well, if firebird libs and includes are in different directories use the
 -I and -L flags to Qt4's configure (or use the system-provided Qt4 if it
 includes firebird support - which it should). For example I run
 configure -I/usr/include/mysql -I/usr/include/postgresql
 to get the mysql and postgresql driver built (am using plain Debian
 here)
 
The system provided Qt4 doesn't include Firebird support, as far as I
can see (Synaptic says PostgreSQL, MySQL, SQLite). Qt4's configure:
that would be the configure step as in configure / make / make
install, right?

At the moment I'm playing with a SQLite database containing part of my
data. So I could try out the SQL models with this. The cachedtable
example should be a good start.

Thank you for your help,
Sibylle


-- 
Dr. Sibylle Koczian
Fasanenstraße 12
D-82293 Mittelstetten


___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Model-View application: view not updated

2006-12-16 Thread Sibylle Koczian
Andreas Pakulat [EMAIL PROTECTED] schrieb:
 On 15.12.06 16:17:21, Sibylle Koczian wrote:
  The problem is with the cancel button: the changed records are only
  changed back after the window lost focus - the view isn't updated
  directly after clicking the button. It _is_ updated after changing the
  spin box value - but only if it's a real change, not after changing and
  changing back again to the old value. I can't understand this, because
  in both cases the same method is called.
 
 Hmm, I don't think I follow your description. 

I'll try again. The application is started and shows some records in a 
QTableView. I edit one or more of these records and decide to cancel my 
alterations. So I click on cancel. No change in the view. Now I can do 
several things to get back the unedited records:

- I click into another window - _now_ the view changes to show the edited 
records in their original form.

- I choose another value in my spinbox and click on ok - the view shows a new 
set of records, as it should. Back to the first value: it shows the unedited 
records of the first set, again as it should.

- I try to trick my application by changing the spinbox value twice and 
clicking ok only after returning to the original value: no change, I see the 
edited records and not the original form.

All of this hasn't really anything to do with database use, the example script 
doesn't use any database at all.

BTW: Did you look at the
 ready-made models for accessing SQL databases in Qt4?
 

I did, but: 

I didn't understand how to get the SQL support for Firebird. Especially using 
Ubuntu which doesn't put Firebird in the standard place Qt4 expects it in.

And I've already got a lot of functions using kinterbasdb with my database (all 
the work which can be done without a GUI). So I'm not so very happy with the 
thought of changing the database driver.


  I've reduced the problem to a smaller application with a small global
  list in place of the database - the offending behaviour stays the same.
  But it's still 153 lines of code. Should I post it or is the description
  sufficient?
 
 153 loc is not really large, please post it.
 

Ok, here it is. Thanks to everybody taking a look!
Sibylle

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


view_update.py

Test update of view with editable model subclassed from QAbstractTableModel.


import sys

from PyQt4 import QtCore, QtGui

gData = [[(101, 'Beckenbauer', 'Franz'), (102, 'Braun', 'Egidius'),
  (103, 'Hackmann', 'Werner'), (104, 'Zwanziger', 'Theo')],
 [(201, 'Doll', 'Thomas'), (202, 'Funkel', 'Friedhelm'),
  (203, 'Hitzfeld', 'Otmar'), (204, 'Magath', 'Felix'),
  (205, 'Veh', 'Armin')],
 [(301, 'Huggel', 'Benjamin'), (302, 'Jones', 'Jermaine'),
  (303, 'Spycher', 'Christoph')]]

cFelder = ['IDNr', 'LastName', 'FirstName']
  
class TestModel(QtCore.QAbstractTableModel):

def __init__(self, columnTitles, parent=None):
QtCore.QAbstractTableModel.__init__(self, parent)
self._resultRows = []
self._columnTitles = columnTitles

def columnCount(self, parent):
return len(self._columnTitles)

def rowCount(self, parent):
return len(self._resultRows)

def data(self, index, role):
if not (index.isValid() and role in (QtCore.Qt.DisplayRole,
 QtCore.Qt.EditRole)):
return QtCore.QVariant()
value = self._resultRows[index.row()][index.column()]
if value is None:
value = 
if isinstance(value, str):
try:
value = unicode(value, UTF-8)
except UnicodeError:
value = unicode(value, ISO-8859-1)
else:
value = unicode(value)
return QtCore.QVariant(value)

def headerData(self, section, orientation, role):
if role != QtCore.Qt.DisplayRole:
return QtCore.QVariant()
if orientation == QtCore.Qt.Horizontal:
return QtCore.QVariant(self._columnTitles[section])
elif orientation == QtCore.Qt.Vertical:
return QtCore.QVariant(section + 1)
return QtCore.QVariant()

def flags(self, index):
# First column (IDNr) may not be editable
flags = QtCore.QAbstractItemModel.flags(self, index)
if index.column()  0:
flags |= QtCore.Qt.ItemIsEditable
return flags

def setData(self, index, value, role):
if index.column()  0:
s = value.toString()
self._resultRows[index.row()][index.column()] = str(s)
else:
return False
self.emit(QtCore.SIGNAL('dataChanged(const QModelIndex , '
'const QModelIndex )'),
  index, index)
return True

def setResultset(self, recno):
print TestModel.setResultset called
# The items in _resultRows can't be tuples if the model shall

Re: [PyKDE] Small database application - best way?

2006-11-28 Thread Sibylle Koczian
Matt Newell [EMAIL PROTECTED] schrieb:
 On Monday 27 November 2006 00:50, Sibylle Koczian wrote:
 snipped...
  Double clicking, pressing F2 or Enter in a cell in one of the editable
  columns doesn't select the text of this cell, as it does in the example
  programs with editable models. Instead it erases the text completely. Not
  helpful, if a small typo should be corrected, a date altered by one day or
  similar small changes are necessary.
 
 Sounds like you aren't handling Qt::EditRole in you model's data function, it 
 should be returning the same thing as Qt::DisplayRole.
 

Yes, that solved this problem, thank you. Two other things still don't work:

Moving with the tab key through the table cells only works after the first 
change.

And, more important: in the setData method the dataChanged signal is emitted:

def setData(self, index, value, role):
...
self.emit(QtCore.SIGNAL('dataChanged'), index, index)
return True

and in the __init__ method of the main window this is connected to a method of 
this window:

self.connect(self.model, QtCore.SIGNAL('dataChanged(const QModelIndex , const 
QModelIndex )'),
 self.ausgeben)

But this doesn't work, self.ausgeben (which prints a message to stdin) isn't 
called.

What's wrong here?

I didn't find an example for an editable model subclassed from 
QAbstractTableModel. Did I overlook it?

Thank you,
Sibylle

-- 
Dr. Sibylle Koczian 
Fasanenstrasse 12 
D-82293 Mittelstetten 

___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Small database application - best way?

2006-11-27 Thread Sibylle Koczian
Very sorry: that should have gone to the list!

Koczian

David Boddie [EMAIL PROTECTED] schrieb:
 On 21 Nov 2006 10:29 GMT, Sibylle Koczian wrote:
 David Boddie [EMAIL PROTECTED] schrieb:
 
  Have you put the QTableView in a layout, or did you use QMainWindow for
  the window and set the QTableView as the central widget?
  
 
 Put in a layout.
 
 If the QTableView is in a layout with other controls, you may need to make
 sure that it has a larger stretch factor than they do, to make it as large
 as possible. It may be the case that resizing the main window is the only
 way to give the table more space if the other controls also demand space
 from the layout system.
 

Begins to look like it; adding a stretch factor didn't help. But this isn't 
really important, I'll get back to it after solving all the other problems. I 
just thought I'd made some quite simple error, easily visible to anybody with 
more experience.

 An alternative is to try to change the widths of the rows and columns as
 displayed in the table.
 

That doesn't seem to alter the geometry of the viewport. 

Now back to problems that can't simply be worked around by a little dragging:

I connected the model in sqlcursorview.py with my database. That worked well, 
as long as I didn't try to make the model editable. To this end I implemented 
flags and setData:

def flags(self, index):
flags = QtCore.QAbstractItemModel.flags(self, index)
if index.column() in (0, 3, 4):
flags |= QtCore.Qt.ItemIsEditable
return flags

def setData(self, index, value, role):
if role != QtCore.Qt.EditRole:
return False
if index.column() == 0:
self._resultRows[index.row()][0] = value.toString()
elif index.column() in (3, 4):
self._resultRows[index.row()][index.column()] = int(value.toString())
else:
return False
self.emit(QtCore.SIGNAL('dataChanged'), index, index)
return True

Then I put the view and some buttons into a subclass of QWidget and added a 
small function to handle the 'dataChanged' signal:

In the __init__ method of the QWidget subclass:

self.connect(self.model,
 QtCore.SIGNAL('dataChanged(const QModelIndex , '
   'const QModelIndex )'),
 self.ausgeben)
... 

def ausgeben(self, startindex, endindex):
print 'Daten geändert: Zeile %d, Spalte %d' % (startindex.row(),
   startindex.column())
print 'Bis Zeile %d, Spalte %d' % (endindex.row(), endindex.column())

The data in column 0 are date values, in column 3 and 4 integer values.

This doesn't work as expected:

The method ausgeben is never called.

Double clicking, pressing F2 or Enter in a cell in one of the editable columns 
doesn't select the text of this cell, as it does in the example programs with 
editable models. Instead it erases the text completely. Not helpful, if a small 
typo should be corrected, a date altered by one day or similar small changes 
are necessary.

This last looks like a problem with the used delegate class. But the view is a 
standard QTableView, that should use a QItemDelegate, and the data method of 
the model changes everything to a unicode object and then to QVariant. It's the 
original method from the EuroPython example program. So that should work out 
of the box, shouldn't it?

And a question: how can I convert the QVariant in column 0 to a Python 
datetime.date object, when I put it back into self._resultRows?

Thank you,
Koczian

-- 
Dr. Sibylle Koczian 
Fasanenstrasse 12 
D-82293 Mittelstetten 

___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


[PyKDE] Small database application - best way?

2006-11-19 Thread Sibylle Koczian
Hello,

I'm trying to migrate a small database application originally written in
Delphi 6.0 to Python. It's for my own use, so it needs a GUI only for
some parts. For these parts I'd like to use PyQt, but at the moment I
don't really see my way.

The first problem I'm trying to solve: The main window contains a
QTableView and some controls. At the start it should be big enough to
show all the data in the view (6-9 rows, 6 columns). I can call
mainwindow.resize(x, y), but I'd prefer to resize the viewport, if
possible depending on the current row count. Calling tableview.resize(x,
y) doesn't help, that still gives a window that only shows part of the
table. What's the right method to use?

Second problem: The QTableView shouldn't be editable. Double clicking on
a record should call a dialog window showing this record, and in this
window some of the fields should be editable. But as far as I can see in
the docs, edit-ability is a property of the model, not of the view.
Anyway, I don't know how to connect a model with controls not inheriting
one of the view classes. On the other hand, I don't think I really plan
something so very unusual.

And, finally: If possible I would prefer not to use the Qt database
plugins, but to keep using the Python database module. Or is that a very
bad idea?

The database is Firebird 1.5.3, OS and distribution Ubuntu 6.10 (with
Gnome as the desktop, but the necessary libraries for PyQt are
installed), database module kinterbasdb 3.2. Everything local on the
same machine.

I've tried and failed to find helpful examples in the documentation, but
of course I may simply have missed them.

Thank you for all hints,
Sibylle


___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


[PyKDE] Re: sender info in Python slot

2006-11-12 Thread Sibylle Koczian
Andreas Pakulat wrote:

  Why unclean (I didn't look yet at the sender() function)?
 
 Then look at the docs. There's a big fat Warning that using sender
 violates OO-principles and the signal/slot mechanim. There are quite
 some restrictions on sender() which you always have to have in the back
 of you head.
 

Yes, I saw that in your other post. 

  Still trying to get a simple QSignalMapper example to run. In the PyQt4 
  examples it is used only in mdi.py which isn't exactly simple, right?
 
 Actually I think it is a simple example, you do look at the python
 version do you? I guess best idea would be to strip it down to only
 include the open and the open-recent-files stuff and remove everything
 else. That should make it as simple as it can get.
 

Yes, I did look at the python version. Stripping it down should help, thanks 
for the tip. In the meantime I got a python translation of the ButtonWidget 
example in the C++ docs to run, there I'd made quite a simple error. 

Sibylle

-- 
Dr. Sibylle Koczian 
Fasanenstrasse 12 
D-82293 Mittelstetten 

___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


[PyKDE] Re: sender info in Python slot

2006-11-11 Thread Sibylle Koczian
Hello,

I'm choosing this post to answer, because it contains the other possibilities.

Jeremy Sanders wrote:
 
 On Thu, 9 Nov 2006, Andreas Pakulat wrote:
 
  On 09.11.06 16:43:00, Sibylle Koczian wrote:
  hopefully the subject line isn't too misleading. This is my problem: I 
  would like to connect the clicked signal of several buttons to one 
  and the same function - but this function should know which button sent 
  the signal. Example: one button to increase a value, another to 
  decrease it, and one single function which adds '+1' or '-1' depending 
  on the sending button. Or a row of buttons with a letter, and clicking 
  one searches for all words beginning with this letter in a list.
 
  How can I do this? Subclassing QPushButton seems to be a possibility, 
  but is there a simpler way?
 
  The unclean solution would be to use the sender() function, the proper 
  one is to have a look at QSignalMapper.
 

Why unclean (I didn't look yet at the sender() function)? Still trying to get a 
simple QSignalMapper example to run. In the PyQt4 examples it is used only in 
mdi.py which isn't exactly simple, right?

 An alternative pythonic way to do this is to do something like:
 
 class BoundCaller(object):
  A callable class to wrap a function and its arguments.
  def __init__(self, fn, *params):
  self.fn = fn
  self.params = params
  def __call__(self, *params):
  self.fn( *(self.params+params) )
 
 in your class:
 
   def __init__(self):
   self.myslot1 = BoundCaller(myslot, 1)
   self.myslot2 = BoundCaller(myslot, 2)
 
   self.connect(self.mybutton, SIGNAL('clicked()'), self.myslot1)
   ...
 
   def myslot(self, boundarg):
   print boundarg
 
 You have to keep a separate reference to the BoundCaller object (hence the
 assignment to self), otherwise it gets garbage collected.
 

I tried this, it works, and I think I've understood it.

Thanks for all the answers!

-- 
Dr. Sibylle Koczian 
Fasanenstrasse 12 
D-82293 Mittelstetten 

___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


[PyKDE] sender info in Python slot

2006-11-09 Thread Sibylle Koczian
Hello,

hopefully the subject line isn't too misleading. This is my problem: I would 
like to connect the clicked signal of several buttons to one and the same 
function - but this function should know which button sent the signal. Example: 
one button to increase a value, another to decrease it, and one single function 
which adds '+1' or '-1' depending on the sending button. Or a row of buttons 
with a letter, and clicking one searches for all words beginning with this 
letter in a list.

How can I do this? Subclassing QPushButton seems to be a possibility, but is 
there a simpler way?

Using PyQt 4 with Python 2.4.

Thank you,
Koczian

-- 
Dr. Sibylle Koczian 
Fasanenstrasse 12 
D-82293 Mittelstetten 

___
PyKDE mailing listPyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


[PyKDE] Python und GUI-Toolkits

2004-06-02 Thread Sibylle Koczian
Dear Mr. Lauer,
shameless self-promotion
Did you try reading Python und GUI-Toolkits? This one aims at giving
you some background to how event driven programs work, what makes a
GUI-Toolkit at all etc. It contains a presentation of a full-fledged
application which is layed out GUI-Toolkit independent in the core and
than later on finished with
 * wxWidget
 * PyGTK
 * PyQt
 * Tkinter
/shameless self-promotion
Very glad to see you're in this list. I've got the book, did part of the 
Tkinter version of the application a while ago, but run into difficulties 
with the Qt version. After closing the application as it is in step 1a, I 
get the message: Fatal Python error: PyEval_RestoreThread: NULL tstate. 
It seems the circular reference (from the application instance to its main 
window and from the main window back to the application) is responsible, 
but I don't see a really good way around it.

Moreover in my own application I'd like to use a new style application 
class, and with the current version of PyQt/SIP it's not possible to derive 
a class from QApplication and from a new style class.

At the moment I've got Python 2.3.3, PyQt 3.11.17, SIP 3.10.1.16, Qt 
3.3.1-36.5, running under SuSE Linux 9.1. I hear SIPv4 should solve both 
problems, but I don't see how that update can get round the fact of the 
circular reference.

Koczian
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : [EMAIL PROTECTED]
___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde