[PyKDE] KConfigSkeleton Blues

Paul Waldo pwaldo at waldoware.com
Fri Dec 15 02:23:45 GMT 2006

Hi all,

I'm trying to make KConfigSkeleton easier for me to use.  The thought of
having to convert all those nice python strings to QStrings and back
makes me cringe.  So here is what I did: I created a wrapper class that
handles the conversion for me, as shown below:

from qt import *

class ConfigurationString(object):
    def __init__(self, initialValue = ''):
        self._qStringValue = QString(initialValue)

    # From http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/205183
    def value():
        doc = "document me"
        def fget(self):
            return str(self._qStringValue)
        def fset(self, value):
            self._qStringValue = QString(str(value))
        def fdel(self):
            del self._qStringValue
        return locals()  # credit: David Niergarth
    value = property(**value())
def main():
    cs = ConfigurationString('initial')
    print 'value is ' + cs.value
    cs.value = 'end'
    print 'value is ' + cs.value
    print 'qstring is ' + str(cs._qStringValue)
if __name__ == '__main__':

The idea here is that I use the "value" property whenever I want a
python string, but the underlying storage is a QString.  Now, when I
create my KConfigSkeleton, I do this:

from qt import *
from kdecore import *
import signals

from ConfigurationString import ConfigurationString

class ConfigurationSchema(KConfigSkeleton):
    # Configuration defaults
    defaultTemplate = QString('default')
    # Configuration item keys
    ITEM_KEY_TEMPLATE = QString('template')
    def __init__(self):
        self.cs = ConfigurationString()
    def _matchInternalConfigToKdeConfig(self):
    def readConfig(self):

    def writeConfig(self):
        # We need to match the two configs again because the underlying
        # of the internal configs might have been modified

This all seems to work fine and dandy when I manually call
ConfigurationSchema.writeConfig, but when I change the configuration
data, it seems to automatically call KConfigSkeleton.writeConfig, which
bypasses my matchInternalConfigToKdeConfig.  I see this on stdout when
just modifying a few of the configuration items:

kdecore (KConfigSkeleton): KConfigSkeleton::writeConfig()
kdecore (KConfigSkeleton): KConfigSkeleton::readConfig()
KCrash: crashing... crashRecursionCounter = 2

I assume that this is because the references to the QStrings in
KConfigSkeleton are not set up properly...

I am looking for help in either solving this issue or finding another
way to do KConfigSkeletons without having to do QString conversions all
over my code.  Any help would be greatly appreciated!


More information about the PyQt mailing list