[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] [PyKDE] KConfigSkeleton/KConfigDialog combo not working
From: Adeodato =?utf-8?B?U2ltw7M=?= <dato () net ! com ! org ! es>
Date: 2008-03-27 15:32:02
Message-ID: 20080327153202.GA16846 () chistera ! yi ! org
[Download RAW message or body]
Hello.
I'm having trouble porting my PyKDE3 KConfigSkeleton/KConfigDialog: it
behaves weird in KDE4.
I'm attaching a very small sample program. The weird behavior I'm
observing is:
(a) on the first run, when no testrc file exists under ~/.kde, the
value of MyOption is correctly set to False, but when I click on
the Preferences button, the checkbox is checked (instead of not
checked, at it'd correspond)
(b) so I change in the dialog the value to True, when closing the
dialog the LineEdit updates accordingly, and the option is written
as "true" to the testrc file, but when I restart the program, it
is set to False again
Can you reproduce? Is there something wrong with my code? (With KDE 3 it
worked just fine).
Thanks in advance,
--
Adeodato Simó dato at net.com.org.es
Debian Developer adeodato at debian.org
- Oh! Uh, congratulations.
- For what?
- You know, your thing tomorrow, renewing your vows.
- You congratulate the groom. You offer the bride best wishes.
-- Luke and Emily
["test.py" (text/x-python)]
#! /usr/bin/env python
import sys
import testui
from PyQt4 import QtGui, QtCore
from PyKDE4 import kdeui, kdecore
class Preferences(kdeui.KConfigSkeleton):
def __init__(self):
kdeui.KConfigSkeleton.__init__(self)
self.setCurrentGroup('General')
self._my_option_item = self.addItemBool('MyOption', False, False)
self.readConfig()
def MyOption(self):
return self._my_option_item.property().toBool()
##
class PreferencesPage(QtGui.QWidget, testui.Ui_Dialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setupUi(self)
##
class PreferencesDialog(kdeui.KConfigDialog):
def __init__(self, parent, name, preferences):
kdeui.KConfigDialog.__init__(self, parent, name, preferences)
self.page = PreferencesPage(self)
self.addPage(self.page, 'General')
##
class MainWindow(kdeui.KMainWindow):
def __init__ (self, *args):
kdeui.KMainWindow.__init__(self, *args)
self.widget = QtGui.QWidget(self)
self.line = QtGui.QLineEdit(self.widget)
self.button = QtGui.QPushButton('Preferences', self.widget)
self.preferences = Preferences()
layout = QtGui.QVBoxLayout()
layout.addWidget(self.line)
layout.addWidget(self.button)
self.widget.setLayout(layout)
self.setCentralWidget(self.widget)
self.slot_settings_changed() # initial value
self.connect(self.button, QtCore.SIGNAL('clicked (bool)'),
self.slot_preferences)
def slot_preferences(self):
if kdeui.KConfigDialog.showDialog('preferences dialog'):
return
else:
dialog = PreferencesDialog(self, 'preferences dialog', self.preferences)
self.connect(dialog, QtCore.SIGNAL('settingsChanged(const QString &)'),
self.slot_settings_changed)
dialog.show()
def slot_settings_changed(self):
print 'applying preferences, MyOption =', self.preferences.MyOption()
self.line.setText(str(self.preferences.MyOption()))
def main():
kdecore.KCmdLineArgs.init(sys.argv, 'test', '', kdecore.ki18n('test'), '1.0')
application = kdeui.KApplication()
main_window = MainWindow()
main_window.show()
application.exec_()
if __name__ == '__main__':
main()
["testui.py" (text/x-python)]
#!/usr/bin/env python
# Generated by pykdeuic4 from testui.ui on Thu Mar 27 15:55:57 2008
#
# WARNING! All changes to this file will be lost.
from PyKDE4 import kdecore
from PyKDE4 import kdeui
from PyQt4 import QtCore, QtGui
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,400,300).size()).expandedTo(Dialog.minimumSizeHint()))
self.vboxlayout = QtGui.QVBoxLayout(Dialog)
self.vboxlayout.setObjectName("vboxlayout")
self.kcfg_MyOption = QtGui.QCheckBox(Dialog)
self.kcfg_MyOption.setObjectName("kcfg_MyOption")
self.vboxlayout.addWidget(self.kcfg_MyOption)
spacerItem = QtGui.QSpacerItem(20,40,QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding)
self.vboxlayout.addItem(spacerItem)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(kdecore.i18n("Dialog"))
self.kcfg_MyOption.setText(kdecore.i18n("Option"))
["testui.ui" (text/plain)]
<ui version="4.0" >
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="kcfg_MyOption" >
<property name="text" >
<string>Option</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic