Re: [PyQt] object using deleteLater(), signal destroyed() not emitted

2009-11-15 Thread Phil Thompson
On Sun, 15 Nov 2009 20:53:44 +0100, Wilbert Berendsen 
wrote:
> Hi,
> 
> in recent sip releases (on my Karmic system, 4.9.1-snapshot), the signal 
> destroyed() is not emitted (as least not by PyQt) when a remote object 
> destroys itself using deleteLater().
> 
> in sip 4.7.9 it works perfectly.  The qobject in question is a KDE
readonly
> 
> part (KonsolePart) that destroys itself using deleteLater() when the user
> logs 
> out of the terminal. I want to notice the logout and hide the widget, 
> recreating the part when the terminal view is requested again.
> 
> But as said, in sip 4.9.1.x the slot connected to the part's destroyed() 
> signal is not called. Attached is a small (KDE) test app to demonstrate
the
> 
> problem.
> 
> Is this a bug or should I use another way of doing this?
> 
> Attached the small test app. When the user logs out the terminal, a
message
> 
> should be printed on stdout.

Fixed in current snapshots.

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


[PyQt] Need help with Model/View DnD

2009-11-15 Thread Ruslan Popov
Hi all,
I am new in PyQt but I have worked with Python and Qt earlier some time
before.
I never work with Qt4 before. It seems I did everything right with this
model/view code.
But I still can't to run with Drag'n'Drop. I have looked at puzzle example a
lot of time.
Nothing helps.

Can you help me? What did I do wrong in my code?

P.S. Sorry for comment, they are in russian.
-- 
Ruslan Popov
phone: +7 916 926 1205
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# (c) 2009 Ruslan Popov 

import sys, re
from datetime import datetime, timedelta
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class Event(object):

""" Класс события. """

def __init__(self, dt, duration, course, *args, **kwargs):
self.dt = dt
self.duration = duration
self.course = course

def __unicode__(self):
return self.course

class EventStorage(QAbstractItemModel):


def __init__(self, work_hours, week_days,
 quant=timedelta(minutes=30),
 room_list=tuple(), parent=None):
self.work_hours = work_hours
self.week_days = week_days
self.quant = quant
self.rooms = room_list
self.multiplier = timedelta(hours=1).seconds / self.quant.seconds

begin_hour, end_hour = work_hours
self.rows_count = (end_hour - begin_hour) * timedelta(hours=1).seconds / quant.seconds
self.cols_count = len(week_days)

QAbstractItemModel.__init__(self, parent)

self.event_mime = 'application/x-calendar-event'

self.rc2e = {} # (row, col, room): event
self.e2rc = {} # (event, room): [(row, col), (row, col), ...]

def rowCount(self, parent):
if parent.isValid():
return 0
else:
return self.rows_count

def columnCount(self, parent):
if parent.isValid():
return 0
else:
return self.cols_count

def headerData(self, section, orientation, role):
""" Метод для определения вертикальных и горизонтальных меток для
рядов и колонок таблицы. """
#print 'EventStorage::headerData'
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return QVariant(self.week_days[section])
if orientation == Qt.Vertical and role == Qt.DisplayRole:
begin_hour, end_hour = self.work_hours
start = timedelta(hours=begin_hour)
step = timedelta(seconds=(self.quant.seconds * section))
return QVariant(str(start + step)[:-3])
return QVariant()

def index(self, row, col, parent):
""" Реализация виртуального метода для генерации индекса. """
if row < 0 or col < 0 or row >= self.rowCount(parent) \
or col >= self.columnCount(parent):
return QModelIndex()
return self.createIndex(row, col)

def data(self, index, role):
""" Перегруженный метод базового класса. Под ролью понимаем зал. """
print 'EventStorage::data'
if not index.isValid():
return QVariant()
event = self.get_event_by_cell(index.row(), index.column(), role)
if event:
cells = self.get_cells_by_event(event, role)
if cells:
if cells[0] == (index.row(), index.column()):
event.type = 'head'
elif cells[-1] == (index.row(), index.column()):
event.type = 'tail'
else:
event.type = 'body'
return QVariant(event)

def get_event_by_cell(self, row, col, room):
""" Получение события по указанным координатам. """
event = self.rc2e.get( (row, col, room), None )
return event

def get_cells_by_event(self, event, room):
""" Получение всех ячеек события. """
return self.e2rc.get( (event, room), None )

def datetime2rowcol(self, dt):
row = (dt.hour - self.work_hours[0]) * self.multiplier
col = dt.weekday()
return (row, col)

def may_insert(self, event, row, col):
""" Метод для проверки возможности размещения события по указанным
координатам. Возвращает список залов, которые предоставляют такую
возможность. """
result = []
for room, color, id in self.rooms:
free = []
for i in xrange(event.duration.seconds / self.quant.seconds):
free.append( self.rc2e.get( (row + i, col, room), None ) is None )
if reduce( lambda x,y: x and y, free ):
result.append( room )
return result

def insert(self, room, event):
""" Метод регистрации нового события. """
row, col = self.datetime2rowcol(event.dt)
self.beginInsertRows(QModelIndex(), row, row)
cells = []
for i in xrange(event.duration.seconds / self.quant.seconds):
cells.append( (row + i, col) )
self.rc2e.update( { (row + i, col, room): event } )
self.e2rc.up

[PyQt] object using deleteLater(), signal destroyed() not emitted

2009-11-15 Thread Wilbert Berendsen
Hi,

in recent sip releases (on my Karmic system, 4.9.1-snapshot), the signal 
destroyed() is not emitted (as least not by PyQt) when a remote object 
destroys itself using deleteLater().

in sip 4.7.9 it works perfectly.  The qobject in question is a KDE readonly 
part (KonsolePart) that destroys itself using deleteLater() when the user logs 
out of the terminal. I want to notice the logout and hide the widget, 
recreating the part when the terminal view is requested again.

But as said, in sip 4.9.1.x the slot connected to the part's destroyed() 
signal is not called. Attached is a small (KDE) test app to demonstrate the 
problem.

Is this a bug or should I use another way of doing this?

Attached the small test app. When the user logs out the terminal, a message 
should be printed on stdout.

w best regards,
Wilbert Berendsen

-- 
http://www.wilbertberendsen.nl/
"You must be the change you wish to see in the world."
-- Mahatma Gandhi
#!/usr/bin/env python

import os, sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.kdecore import *
from PyKDE4.kdeui import *
from PyKDE4.kparts import *

aboutData = KAboutData(
'libkonsoleparttester', '',
ki18n('libkonsoleparttester'), '1.0',
)

KCmdLineArgs.init(sys.argv, aboutData)

app = KApplication()

mainwin = KParts.MainWindow()
app.setTopWidget(mainwin)

factory = KPluginLoader("libkonsolepart").factory()

part = factory.create(mainwin)
mainwin.setCentralWidget(part.widget())
part.openUrl(KUrl(os.environ["HOME"]))

def slotDestroyed():
print "Konsole part destroyed"

QObject.connect(part, SIGNAL("destroyed()"), slotDestroyed, Qt.DirectConnection)

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

Re: [PyQt] Freezes and crashes with signal autoconnection

2009-11-15 Thread Phil Thompson
On Sat, 14 Nov 2009 05:22:41 -0800 (PST), Christian Roche
 wrote:
> Hi again;
> 
> 
> Phil Thompson-5 wrote:
>> 
>> I can't remember if you are using snapshots or not, but there are some
>> issues fixed related to looking up Python reimplementations of virtual
>> methods.
>> 
> 
> forget about Windows. The whole thing crashes so quick on Windows XP that
I
> can't even get a glimpse of the main window. I'm using the latest build
> (PyQt-Py2.6-gpl-4.6.1-1.exe) but not snapshots as I can't compile there.
> I'd
> be willing to compile a build there and also get debugger feedback but I
> would need a pointer on some resource on how to do that on Windows.
> 
> Back on Linux I also get crashes although much less frequently. The
> difference is that I'm able to get some feedback from the system in that
> case so it might prove a bit more useful! Here is the backtrace of a
random
> crash that appears to occur when a thread calls the QUrl.resolved()
method.
> This is with PyQt4-4.5.4-1 and sip-4.8.2.
> -
> Program terminated with signal 11, Segmentation fault.   
 
>   
> #0  0x082c0f23 in qpycore_PyObject_FromQString (qs...@0xb5bd21b8) at
> qpycore_qstring.cpp:55   
> 55  *pyu++ = (qstr.at(i)).unicode(); 
 

It's difficult to see how this would crash if everything else (ie. Python
and Qt) is working as it should.

However it does imply you are using a very old version of Qt (v4.1).

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


Re: [PyQt] Re: Updates to sipdistutils.py

2009-11-15 Thread Giovanni Bajo
Il giorno dom, 15/11/2009 alle 13.13 +, Phil Thompson ha scritto:
> On Sun, 15 Nov 2009 13:36:52 +0100, Giovanni Bajo 
> wrote:
> > Il giorno dom, 15/11/2009 alle 11.39 +, Phil Thompson ha scritto:
> >> On Fri, 13 Nov 2009 20:53:34 +0100, Giovanni Bajo 
> >> wrote:
> >> > Hi Phil,
> >> > 
> >> > please find attached an improved sipdistutils.py, and the diff against
> >> > current version for reference.
> >> > 
> >> > Modifications:
> >> > 
> >> >  * Added command line option to pass arguments to sip. Now you can for
> >> > instance do: "python setup.py build --sip-opts='-e'" to activate
> >> > exceptions. Or you can put the "sip-opts='-e'" in a local
> distutils.cfg
> >> > file in your source directory.
> >> > 
> >> >  * Fixed invocation of sip.exe under Windows. I still maintain that
> >> > siputils.py should put the full pathname of sip, including extension,
> >> > under the "sip_bin" in the configuration, but a quick workaround is
> >> > needed anyway to make sipdistutils work with all versions of sip.
> >> 
> >> I consider the extension an implementation detail that shouldn't be
> >> exposed. 
> > 
> > I need the full pathname to compute the checksum. How do I suggest I
> > find it out then? Should I iterate over supported extensions until I
> > find the correct one?
> 
> I don't think it is a sensible approach in the first place.

Thus, I'm not sure what I am supposed to do.

What are you giving in by putting the full pathname in the build-time
generated sipconfig.py? That entry in the dictionary is used only by
build scripts that want to invoke sip directly; how are you making any
difference for them by exposing the sip binary extension? If it changes
in SIP v5, let it change; when installing sip v5, you will generate a
new siputils.py with the new full pathname on it, whichever it is.

I don't see it as exposing an implementation detail on which users might
accidentally rely; on the contrary, by *not* exposing it, you're making
some users (like sipdistutils.py) rely on the current value (.exe).

-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com


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


Re: [PyQt] pylupdate4 bug?

2009-11-15 Thread Phil Thompson
On Sat, 14 Nov 2009 16:28:36 +0100, Michele Petrazzo - Unipex
 wrote:
> Hi,
> just discovered that pylupdate4 has a problem with empty docstring. If I
> forgot to write at least one character inside the docstring space,
> pylupdate4 stops to look for new string translation.
> 
> class Main(Qtclass):
>  def __init__(self):
>  ""
> 
>  def test(self):
>  """simple docstring"""
>  return self.trUtf8("test")
> 
> generate:
> 
> pylupdate4: main.py:9: Unterminated string
> pylupdate4: Updating 'i18n/i18nit.ts'...
> pylupdate4: Found 0 source texts (0 new and 0 already existing)
> 
> adding a simgle char ("a") to the first docstring:
> 
> pylupdate4: Updating 'i18n/i18nit.ts'...
> pylupdate4: Found 1 source text (1 new and 0 already existing)

Fixing this properly is very risky as the parsing code isn't the greatest
in the world. Instead I've clarified the error message.

One day I'll get round to a Python version of pylupdate which uses the
interpreter to do the parsing.

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


Re: [PyQt] Re: Updates to sipdistutils.py

2009-11-15 Thread Phil Thompson
On Sun, 15 Nov 2009 13:36:52 +0100, Giovanni Bajo 
wrote:
> Il giorno dom, 15/11/2009 alle 11.39 +, Phil Thompson ha scritto:
>> On Fri, 13 Nov 2009 20:53:34 +0100, Giovanni Bajo 
>> wrote:
>> > Hi Phil,
>> > 
>> > please find attached an improved sipdistutils.py, and the diff against
>> > current version for reference.
>> > 
>> > Modifications:
>> > 
>> >  * Added command line option to pass arguments to sip. Now you can for
>> > instance do: "python setup.py build --sip-opts='-e'" to activate
>> > exceptions. Or you can put the "sip-opts='-e'" in a local
distutils.cfg
>> > file in your source directory.
>> > 
>> >  * Fixed invocation of sip.exe under Windows. I still maintain that
>> > siputils.py should put the full pathname of sip, including extension,
>> > under the "sip_bin" in the configuration, but a quick workaround is
>> > needed anyway to make sipdistutils work with all versions of sip.
>> 
>> I consider the extension an implementation detail that shouldn't be
>> exposed. 
> 
> I need the full pathname to compute the checksum. How do I suggest I
> find it out then? Should I iterate over supported extensions until I
> find the correct one?

I don't think it is a sensible approach in the first place.

>> It won't be .exe for SIP v5.
> 
> Out of curiosity, what will it be?

Probably .bat as SIP v5 will probably be written in Python.

>> >  * Consider the sip binary checksum as an implicit dependency for
>> >  build.
>> > This is very useful when switching between different sip versions,
>> > because everything is automatically recompiled.
>> > 
>> > Coming up:
>> > 
>> >  * As discussed some months ago, I plan to add an option to sip itself
>> > to printf() any .sip file it opens. I will then use a dry-run with
this
>> > option to automatically discover dependencies so to rebuild whenever
>> > necessary. This would be a strong improvement over the current state
>> > where one must manually list all sip files (theoretically, of all
>> > imported modules as well) in the setup.py.
>> 
>> Applied to the trunk.
>> 
>> Feel free to send a patch for the documentation :)
> 
> Attached. I assumed most distutils users are not familiar with passing
> options to distutils' subcommands, so I elaborated on it a little.

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


[PyQt] Re: Updates to sipdistutils.py

2009-11-15 Thread Giovanni Bajo
Il giorno dom, 15/11/2009 alle 11.39 +, Phil Thompson ha scritto:
> On Fri, 13 Nov 2009 20:53:34 +0100, Giovanni Bajo 
> wrote:
> > Hi Phil,
> > 
> > please find attached an improved sipdistutils.py, and the diff against
> > current version for reference.
> > 
> > Modifications:
> > 
> >  * Added command line option to pass arguments to sip. Now you can for
> > instance do: "python setup.py build --sip-opts='-e'" to activate
> > exceptions. Or you can put the "sip-opts='-e'" in a local distutils.cfg
> > file in your source directory.
> > 
> >  * Fixed invocation of sip.exe under Windows. I still maintain that
> > siputils.py should put the full pathname of sip, including extension,
> > under the "sip_bin" in the configuration, but a quick workaround is
> > needed anyway to make sipdistutils work with all versions of sip.
> 
> I consider the extension an implementation detail that shouldn't be
> exposed. 

I need the full pathname to compute the checksum. How do I suggest I
find it out then? Should I iterate over supported extensions until I
find the correct one?

> It won't be .exe for SIP v5.

Out of curiosity, what will it be?

> >  * Consider the sip binary checksum as an implicit dependency for build.
> > This is very useful when switching between different sip versions,
> > because everything is automatically recompiled.
> > 
> > Coming up:
> > 
> >  * As discussed some months ago, I plan to add an option to sip itself
> > to printf() any .sip file it opens. I will then use a dry-run with this
> > option to automatically discover dependencies so to rebuild whenever
> > necessary. This would be a strong improvement over the current state
> > where one must manually list all sip files (theoretically, of all
> > imported modules as well) in the setup.py.
> 
> Applied to the trunk.
> 
> Feel free to send a patch for the documentation :)

Attached. I assumed most distutils users are not familiar with passing
options to distutils' subcommands, so I elaborated on it a little. 

-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com

Index: distutils.rst
===
--- distutils.rst	(revisione 26185)
+++ distutils.rst	(copia locale)
@@ -23,3 +23,19 @@
 As we can see, the above is a normal distutils setup script, with just a
 special line which is needed so that SIP can see and process ``word.sip``.
 Then, running ``setup.py build`` will build our extension module.
+
+If you want to use any of sip's command-line options described in
+:ref:`ref-command-line`, there is a new option available for the
+``build_ext`` command in distutils: ``--sip-opts``. So you can either invoke
+distutils as follows::
+
+ $ python setup.py build_ext --sip-opts="-e -g" build
+
+or you can leverage distutils' config file support by creating a ``setup.cfg``
+file in the supported system or local paths (eg: in the same directory of
+``setup.py``) with these contents::
+
+ [build_ext]
+ sip-opts = -e -g
+
+and then run ``setup.py build`` as usual.
Index: command_line.rst
===
--- command_line.rst	(revisione 26185)
+++ command_line.rst	(copia locale)
@@ -1,3 +1,5 @@
+.. _ref-command-line:
+
 The SIP Command Line
 
 
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Re: Updates to sipdistutils.py

2009-11-15 Thread Phil Thompson
On Fri, 13 Nov 2009 20:53:34 +0100, Giovanni Bajo 
wrote:
> Hi Phil,
> 
> please find attached an improved sipdistutils.py, and the diff against
> current version for reference.
> 
> Modifications:
> 
>  * Added command line option to pass arguments to sip. Now you can for
> instance do: "python setup.py build --sip-opts='-e'" to activate
> exceptions. Or you can put the "sip-opts='-e'" in a local distutils.cfg
> file in your source directory.
> 
>  * Fixed invocation of sip.exe under Windows. I still maintain that
> siputils.py should put the full pathname of sip, including extension,
> under the "sip_bin" in the configuration, but a quick workaround is
> needed anyway to make sipdistutils work with all versions of sip.

I consider the extension an implementation detail that shouldn't be
exposed. It won't be .exe for SIP v5.

>  * Consider the sip binary checksum as an implicit dependency for build.
> This is very useful when switching between different sip versions,
> because everything is automatically recompiled.
> 
> Coming up:
> 
>  * As discussed some months ago, I plan to add an option to sip itself
> to printf() any .sip file it opens. I will then use a dry-run with this
> option to automatically discover dependencies so to rebuild whenever
> necessary. This would be a strong improvement over the current state
> where one must manually list all sip files (theoretically, of all
> imported modules as well) in the setup.py.

Applied to the trunk.

Feel free to send a patch for the documentation :)

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