LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-25-2012, 08:02 AM   #1
devilboy09
Member
 
Registered: Nov 2011
Location: Iran
Distribution: Debian, CentOS, LFS
Posts: 346

Rep: Reputation: 7
File selection in Python


i want to create a file selector in python.here's my code, so far:
Code:
def file_open(self, widget):
                self.file_sel = gtk.FileSelection("File")
                self.file_sel.connect("destroy", lambda w:self.file_sel.destroy())
                self.file_sel.ok_button.connect("clicked", self.open_file)
                self.file_sel.cancel_button.connect("clicked", lambda w:self.file_sel.destroy())
                self.file_sel.show()
what's the body of "self.open_file" function. i can't figure it out.there's no function in FileSelection for opening a file
 
Old 01-25-2012, 08:22 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,853

Rep: Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121
a file selection dialog shouldn't open a file, it should return the name of the chosen file for the rest of the code to act upon. you have the get_filename() method there to use. It's none of a gui widgets business actually DOING anything with the file.

note that FileSelection is obsolete, and I think you should be using FileChooserDialog instead these days if possible.
 
Old 01-25-2012, 08:50 AM   #3
devilboy09
Member
 
Registered: Nov 2011
Location: Iran
Distribution: Debian, CentOS, LFS
Posts: 346

Original Poster
Rep: Reputation: 7
i used this code as the body of self.open_file:
Code:
def open_file(self, w):
                filename = self.file_sel.get_filename()
                self.browser.open(filename)
                self.file_sel.destroy()
and it worked.you said i should use FileChooserDialog.is there any advantages for using this widget?
 
Old 01-25-2012, 12:25 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,853

Rep: Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121
more modern I guess. I just read the API (the one you could have read ) and it said it was deprecated, so I repeated that.
 
Old 01-25-2012, 01:21 PM   #5
devilboy09
Member
 
Registered: Nov 2011
Location: Iran
Distribution: Debian, CentOS, LFS
Posts: 346

Original Poster
Rep: Reputation: 7
thamk you for your answers.i used File Chooser Dialog and it worked
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python - How to get text file data into an array on python. golmschenk Programming 3 06-16-2011 11:59 AM
Python: how to import a python file that doesn't end in .py? BrianK Programming 5 04-15-2008 12:35 PM
wxPython: file browser with multiple file selection: possible? BrianK Programming 0 01-13-2008 02:44 AM
file selection munna_dude Programming 0 03-23-2007 04:08 AM
cp and file selection Calgarian Linux - Newbie 7 07-16-2006 09:23 AM


All times are GMT -5. The time now is 04:29 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration