[PyQt] Executing function with argument under a button in pyqt

Till Gerken till.gerken at gmail.com
Fri Mar 13 14:48:53 GMT 2009


On Fri, Mar 13, 2009 at 2:59 PM, klia <alwaseem307ster at yahoo.com> wrote:
> Till Gerken-2 wrote:
>> On Fri, Mar 13, 2009 at 2:23 PM, klia <alwaseem307ster at yahoo.com> 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:
>>>
>>> waseem at 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


More information about the PyQt mailing list