[pygtk] How to use gtk.FileChooserButton?
Alexandre Abadie
Alexandre.Abadie at irisa.fr
Mon Aug 13 21:34:02 WST 2007
Taras Ivashcenko a écrit :
> On Mon, 13 Aug 2007 14:29:48 +0200
> Alexandre Abadie <Alexandre.Abadie at irisa.fr> wrote:
>
> Hello, Alexandre!
> I think, you don't understand me correctly... :)
> I talk about gtk.FileChooserButton.
> __init__() method of what class do you mean?
>
Ok, I understand now :-)
For me it's easier to use the gtk.FileChooserDialog and I don't know
anything about to use gtk.FileChooserButton.
I meant I connect my button in the __init__ method of my graphical
application class. In this method, I also define the other widgets.
>
>> Taras a écrit :
>>
>>> Hello, everybody!
>>> Now I currently use such code with usual button for run and process
>>> response file chooser dialog.
>>> Some times ago I found in PyGTK reference new gtk.FileChooserButton (
>>> http://pygtk.org/docs/pygtk/class-gtkfilechooserbutton.html)
>>> but from manual I didn't understand how to use it.
>>> Can you give me some example of it?
>>>
>>> # ...
>>>
>>> fileselButton = gtk.Button("Browse")
>>> fileselButton.connect("clicked", self.open_file_dialog)
>>>
>>> # ...
>>>
>>> def open_file_dialog(self, widget):
>>> self.chooser = gtk.FileChooserDialog(title=None,action=
>>> gtk.FILE_CHOOSER_ACTION_OPEN,
>>> buttons=(gtk.STOCK_CANCEL,
>>> gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
>>> self.chooser.set_current_folder(os.environ['HOME'])
>>> self.chooser.set_default_response(gtk.RESPONSE_OK)
>>> response = self.chooser.run()
>>>
>>> if response == gtk.RESPONSE_OK:
>>> # some actions
>>> self.chooser.destroy()
>>>
>>>
>>>
>> Hi,
>>
>> I use it like this :
>>
>> # in the __init__ method
>>
>> self.button = gtk.Button("Browse...")
>> self.button.connect("clicked", self.browse_for_file, None)
>> # ...
>>
>> # my class method for browsing the file
>> def browse_for_file(self):
>> file_open = gtk.FileChooserDialog(title="Select dicomdir"
>> , action=gtk.FILE_CHOOSER_ACTION_OPEN
>> , buttons=(gtk.STOCK_CANCEL
>> , gtk.RESPONSE_CANCEL
>> , gtk.STOCK_OPEN
>> , gtk.RESPONSE_OK))
>> result = ""
>> if file_open.run() == gtk.RESPONSE_OK:
>> result = file_open.get_filename()
>> file_open.destroy()
>> return result
>>
>>
>> It works fine.
>>
>> Alex
>>
>>
>
>
>
--
Alexandre ABADIE
-------------------------------------------------------------------
- Unité/Projet VisAGeS - U746 - Ph. : 02.99.84.22.17 -
- IRISA, UMR CNRS 6074 - Email : Alexandre.Abadie at irisa.fr -
- Campus de Beaulieu - http://www.irisa.fr/visages -
- 35042 Rennes Cedex - -
-------------------------------------------------------------------
More information about the pygtk
mailing list