Re: [PyQt] QTableView header connection
On Wed, Mar 18, 2009 at 3:40 PM, Gert-Jan wrote: > Class GUI: > def __init__(self): > tableWidget = QtGui.QTableWidget() > # Code to insert 5 columns and make a horizontal header) > self.connect(tableWidget.horizontalHeader, > QtCore.SIGNAL("clicked()"), > self.random_function) > > def random_function(self): > print 'ok' > > However, double-clicking the header does not make the console print 'ok'. If you double click, the signal should be doubleClicked(). Till ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Qt trying to load .uic instead of .ui
On Mon, Mar 16, 2009 at 7:05 PM, Arthur Pemberton wrote: > when I try to do a uic.loadUi, th euic module tries to load a .ui file > instead a .uic file. According to the documentation, uic.loadUi() is supposed to load the .ui file. Is that incorrect? http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#the-uic-module Till ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] linking subprocess function and items in listwidget?
On Mon, Mar 16, 2009 at 11:32 AM, klia wrote: > I have function myexif.py that extracts exif data from photos into .csv > file, i have subprocess this function into this form under a bush button > (add photo) > > p= Popen(["python","myexif.py","-q","photopath"], > stdout=file("test.csv","w")) > p.wait() > > I am suppose to select one or more photos in the listwidget and execute my > (add photo) button which will extracts exif data from the photos selected, > but i am facing problem on how to get the function above to know the path of > my selected photos in the listwidget? Using a QListWidget, you will either have to add the items with their full path to the list or use a common directory root. If that is not possible, use a QListView and your own data model. A custom data model allows you to keep the list entry and path to the file name as separate entities. http://doc.trolltech.com/4.4/model-view-programming.html Till ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Re: PyQT lost reference (was: Re: PyKDE: KConfigSkeleton not writing configuration)
On 3/13/09, Phil Thompson wrote: > On Fri, 13 Mar 2009 11:44:57 +0100, Wolfgang Rohdewald > wrote: >> On Freitag, 13. März 2009, Till Gerken wrote: >> >>> The QString() that I am passing as reference to the C++ class >>> KCoreConfigSkeleton exists as local variable in my Python class >>> derived from KCoreConfigSkeleton. Now any code that interacts with >>> KCoreConfigSkeleton (C++ or Python) may change this QString instance. >> >> this is because QString() is mutable while python strings are immutable. >> When dealing with KCoreConfig, do not use QString as local variables, >> always convert explicitly from/to python strings. > > No, do exactly the opposite. If you pass a Python string then it will be > converted to a QString under the covers. Any changes to that QString will > then be discarded. The weird thing in this case is that the changes made by KCoreConfigSkeleton are discarded. Even if I call KCoreConfigSkeleton::ItemString::setValue(), the referenced QString is not updated (although it will then be written to disk correctly). This suggests that two instances of the same QString exist. I can live with the workaround calling KCoreConfigSkeleton::ItemString::setValue() and getValue(), but I wonder where the bug is. Any pointers would be appreciated. Till ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Executing function with argument under a button in pyqt
On Fri, Mar 13, 2009 at 2:59 PM, klia wrote: > Till Gerken-2 wrote: >> On Fri, Mar 13, 2009 at 2:23 PM, klia wrote: >>> I have this function that is suppose to extract Exif(exchangeable image >>> formate) from photos and direct the output to an .CSV file (comma >>> seperated >>> values) >>> >>> well the function syntax is like the following: >>> >>> was...@home:~/Desktop/Project2/GUI$ python myexif.py -q waseem1.JPG > >>> test.csv >>> >>> in the program now my photos are listed in ListWidget... >>> How can i select photo or multiple photos from the listwidget and execute >>> the above syntax after clicking a button which is already there in order >>> to >>> create a CSV file?? >> >> Just create a new method that you connect to your button's clicked() >> signal and include the Exif extraction code there. Since your Exif >> extraction already seems to be in Python, you do not have to execute >> any external programs. >> >> connect(yourButton, SIGNAL("clicked(bool)"), yourExifMethod) >> >> The signal is documented here: >> http://doc.trolltech.com/4.4/qpushbutton.html#details >> http://doc.trolltech.com/4.4/qabstractbutton.html#clicked > > creating a connect method ain't a problem for me but how to select photo in > the ListWidget and then executing myexif functiion with -q argument? For selecting an item in the list widget and retrieving an item see QListWidget::setCurrentItem() and QListWidget::currentItem(): http://doc.trolltech.com/4.4/qlistwidget.html#currentItem http://doc.trolltech.com/4.4/qlistwidget.html#setCurrentItem If the list item is changed, currentItemChanged() is emitted: http://doc.trolltech.com/4.4/qlistwidget.html#currentItemChanged And for executing, why do you want to run a Python script as external application rather than just embedding it into your own script? But if you really want to run it as external application, see os.exec*(): http://docs.python.org/library/os.html#process-management Till ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Executing function with argument under a button in pyqt
On Fri, Mar 13, 2009 at 2:23 PM, klia wrote: > I have this function that is suppose to extract Exif(exchangeable image > formate) from photos and direct the output to an .CSV file (comma seperated > values) > > well the function syntax is like the following: > > was...@home:~/Desktop/Project2/GUI$ python myexif.py -q waseem1.JPG > > test.csv > > in the program now my photos are listed in ListWidget... > How can i select photo or multiple photos from the listwidget and execute > the above syntax after clicking a button which is already there in order to > create a CSV file?? Just create a new method that you connect to your button's clicked() signal and include the Exif extraction code there. Since your Exif extraction already seems to be in Python, you do not have to execute any external programs. connect(yourButton, SIGNAL("clicked(bool)"), yourExifMethod) The signal is documented here: http://doc.trolltech.com/4.4/qpushbutton.html#details http://doc.trolltech.com/4.4/qabstractbutton.html#clicked Till ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Re: PyQT lost reference (was: Re: PyKDE: KConfigSkeleton not writing configuration)
Hi, sorry for keeping replying to myself, but nobody else seems to show interest and I am trying to find the root cause of the error: The QString() that I am passing as reference to the C++ class KCoreConfigSkeleton exists as local variable in my Python class derived from KCoreConfigSkeleton. Now any code that interacts with KCoreConfigSkeleton (C++ or Python) may change this QString instance. Looking at the SIP file I see the following: KCoreConfigSkeleton::ItemString* addItemString (const QString& name, QString& reference, const QString& defaultValue = QLatin1String(""), const QString& key = QString()); Could it be that this method declaration misses /In/ and /Out/ for QString &reference? The documentation on /In/ and /Out/ was not too clear for me, could someone elaborate what happens exactly when these statements are given? Thanks, Till ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] PyQT lost reference (was: Re: PyKDE: KConfigSkeleton not writing configuration)
Hello, I have debugged the issue that I sent an email about yesterday some more. I noticed the following: - modifying a KCoreConfigSkeleton::ItemString value does not write this value to disk on KCoreConfigSkeleton::writeConfig() - however, calling KCoreConfigSkeleton::ItemString::setValue() causes the value to be updated correctly. I have attached an updated version of the script that illustrates this, with the method setSimpleThing() on line 36 being the crucial part: def setSimpleThing(self, simpleThing): # BUG: This does not update the KConfigItem value self._simpleThing = simpleThing # BUG: The explicit setting however, does. self._simpleThingKC.setValue(simpleThing) I found this when looking at KCoreConfigSkeleton::ItemString: void KCoreConfigSkeleton::ItemString::writeConfig( KConfig *config ) { if ( mReference != mLoadedValue ) // WABA: Is this test needed? { KConfigGroup cg(config, mGroup ); if ((mDefault == mReference) && !cg.hasDefault( mKey)) cg.revertToDefault( mKey ); else if ( mType == Path ) cg.writePathEntry( mKey, mReference ); else if ( mType == Password ) cg.writeEntry( mKey, KStringHandler::obscure( mReference ) ); else cg.writeEntry( mKey, mReference ); } } The first line (mReference!=mLoadedValue) is where PyQt "fails". mReference is of type QString& and is supposed to point to the value that gets passed to KCoreConfigSkeleton::addItemString: [Python Code] myString = QString("foo") KCoreConfigSkeleton::addItemString("bar", myString, "barDefaultValue") At this point, mReference points to myString and mReference==mLoadedValue. Now, in Python: myString = QString("bar") At this point, mReference still seems to contain or point to a string "foo", which causes the check in KCoreConfigSkeleton::ItemString::writeConfig() to fail. My assumption is (I do not have any knowledge about PyQt's inner workings) that the Python string and the QString copy live at different positions in memory, even though they are supposed to be passed by reference. This behavior also does not change when using QString() instances directly in the Python code. (I adjusted my example from yesterday accordingly) However, at least when using QStrings directly from Python, I would assume the reference to be passed correctly to KCoreConfigSkeleton so that it catches any updates inside its code. Is this assumption wrong or is it a bug in PyQt/PyKDE? I am using the bindings packaged in Kubuntu, version 4:4.2.1-0ubuntu1~intrepid2. Thanks, Till On 3/10/09, Till Gerken wrote: > Hello, > > I have a problem with KConfigSkeleton not writing its configuration to > disk when calling KCoreConfigSkeleton::writeConfig(). The odd thing > about this is that it works when being used together with > KConfigDialog and KConfigDialogManager, in which case the > configuration file is written correctly. > > I have attached a small sample illustrating this behavior. When run, > the value that is entered in the configuration widget will be written > to disk. However, the value that is specified in > MyConfigMain.queryClose() is not written. > > Is this a bug in PyKDE or am I missing something? > > Thanks, > > Till > import sys from PyKDE4.kdecore import * from PyKDE4.kdeui import * from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4 import uic # # Configuration storage # class MyConfig(KConfigSkeleton): _simpleThing = QString() _simpleThingKC = None _simpleThingDlg = QString() __instance = None def __init__(self): if self.__instance: raise self.__instance self.__instance = self KConfigSkeleton.__init__(self, "configtestrc") self.createConfig() self.readConfig() def createConfig(self): # Create entries for the main window self._simpleThingKC = self.addItemString ("simpleThing", self._simpleThing, QString("foo")) self.addItemString ("simpleThingDlg", self._simpleThingDlg, QString("bar")) def simpleThing(self): return self._simpleThing def setSimpleThing(self, simpleThing): # BUG: This does not update the KConfigItem value self._simpleThing = simpleThing # BUG: The explicit setting however, does. self._simpleThingKC.setValue(simpleThing) def simpleThingDlg(self): return self._simpleThingDlg def setSimpleThingDlg(self, simpleThingDlg): self._simpleThingDlg = simpleThingDlg # # Configuration dialog # class MyConfigDialog(KConfigDialog): def __init__(self, parentWidget, configuration): KConfigDialog.__init__(self, parentWidget, "MainSettings", configuration ) self.setFaceType ( KPageDialog.Plain ) self.configWidget = QWidget() uic.loadUi ( "mycfg.ui", self.configWidget ) self.addPage ( self.configWidget, "Configuration
[PyQt] PyKDE: KConfigSkeleton not writing configuration
Hello, I have a problem with KConfigSkeleton not writing its configuration to disk when calling KCoreConfigSkeleton::writeConfig(). The odd thing about this is that it works when being used together with KConfigDialog and KConfigDialogManager, in which case the configuration file is written correctly. I have attached a small sample illustrating this behavior. When run, the value that is entered in the configuration widget will be written to disk. However, the value that is specified in MyConfigMain.queryClose() is not written. Is this a bug in PyKDE or am I missing something? Thanks, Till import sys from PyKDE4.kdecore import * from PyKDE4.kdeui import * from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4 import uic # # Configuration storage # class MyConfig(KConfigSkeleton): _simpleThing = QString() _simpleThingDlg = QString() __instance = None def __init__(self): if self.__instance: raise self.__instance self.__instance = self KConfigSkeleton.__init__(self, "configtestrc") self.createConfig() self.readConfig() def createConfig(self): # Create entries for the main window self.addItemString ("simpleThing", self._simpleThing, QString("foo")) self.addItemString ("simpleThingDlg", self._simpleThingDlg, QString("bar")) def simpleThing(self): return self._simpleThing def setSimpleThing(self, simpleThing): self._simpleThing = simpleThing def simpleThingDlg(self): return self._simpleThingDlg def setSimpleThingDlg(self, simpleThingDlg): self._simpleThingDlg = simpleThingDlg # # Configuration dialog # class MyConfigDialog(KConfigDialog): def __init__(self, parentWidget, configuration): KConfigDialog.__init__(self, parentWidget, "MainSettings", configuration ) self.setFaceType ( KPageDialog.Plain ) self.configWidget = QWidget() uic.loadUi ( "mycfg.ui", self.configWidget ) self.addPage ( self.configWidget, "Configuration" ) # # Main application class # class MyConfigMain(KMainWindow): def __init__(self): KMainWindow.__init__(self) # Create configuration self.config = MyConfig() # # BUG?: A value that is accessed from the dialog below is written to the file when changed (desired behavior) # self.cfgDialog = MyConfigDialog(self, self.config) self.cfgDialogManager = KConfigDialogManager(self.cfgDialog, self.config) self.cfgDialog.show() # not necessary, nothing here - but do something self.show() def queryClose(self): # # BUG?: This should cause the text to be written to the configuration file, but it does not appear (not desired) # self.config.setSimpleThingDlg("foobar!") self.config.writeConfig() return True # # Startup Code # # Create main window and application info, # then instantiate main class and jump there # appName = "configtest" catalog = "" programName = ki18n("Configuration Test") version = "0.1" description = ki18n("Configuration Test") license = KAboutData.License_GPL copyright = ki18n("(c) 2009 Till Gerken, ") text = ki18n("none") homePage = "" bugEmail = "till.ger...@gmail.com" aboutData = KAboutData ( appName, catalog, programName, version, description, license, copyright, text, homePage, bugEmail ) KCmdLineArgs.init ( sys.argv, aboutData ) app = KApplication() docmgr = MyConfigMain() sys.exit(app.exec_()) mycfg.ui Description: application/designer ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt