PDA

View Full Version : browsing application



nitriles
25th October 2007, 16:39
Hello,

I want to create a browse app. Just a browse button, where when clicked, opens a window for browsing and displays the file name (or the whole link) in a lineedit. I know that there is QFileDialog, but since im quite new, i dont understand that. And all the info that i found was written in C++, which i really dont get, im using Python.
Hope someone can help me!
Thanks

high_flyer
25th October 2007, 20:53
Hope someone can help me!
With what?
We can't tell you things that are not in the docs.
There is no way around starting, and trying.
Then, when you get stuck, you will have a specific question about where you got stuck.
Post it here, and we will try to help you.

Good luck.

P.S
If I remember right, there is an example that comes with Qt which does exactly what you want.

nitriles
26th October 2007, 13:03
ok i agree my question was kinda vague!
I have a program which subplots 10 data using matplotlib.
It is ran by typing in the console:
python plotdata.py DataFile.csv
If i do not type DataFile.csv then it doesn't run the program but says, please enter file name.
What i want is to create a small form with Qt with a line edit (where the file name should be), a browse button (which opens a browse window to select the file which is later displayed in the line edit) a cancel button to close and a Plot button which launches my plotdata.py file and plots graphs using the datafile that was chosen.
I hope this is clear. My problem is that i dont know how to create a browse button.
I didn't look into the programming of launchin my python program, but i think that it should be something with exec_file(plotdata.py).

high_flyer
26th October 2007, 13:13
I hope this is clear. My problem is that i dont know how to create a browse button.
You were clear the last time too.
But what do expect as an answer?
If you can read our answer on how to do this, you can just as well read it in the docs, where it is for sure better explained.
Unless of course you have a specific question.

If I understand you correctly, you want a small GUI program, that will feed your console program with the fine name you chose through the GUI.
You can create the GUI it self with Designer.
You can then make a small programm that feeds the selcted file name by using QProcess.

You should look at PyQt for using Qt with Python, sadly, I am C++ coder and can't help you with that (may be others on the forum?).

nitriles
26th October 2007, 13:21
Well i have searched, but failed. What i did find is C++ examples, which i dont understand. But yeah, u did understand me correctly :)
-btw: im also in Munich, garching

high_flyer
26th October 2007, 13:34
google is your friend ;)
http://www.cs.usfca.edu/~afedosov/qttut/
(there are many others)

(I am in the South - Sendling :) )

nitriles
26th October 2007, 13:40
Thanks, thats the site where I learned PyQt.
But the problem is that i dont know how to write the code that when the button Browse is clicked, that it opens a window where a file can be selected.
I created a form with Qt, know i just need to create some signals and slots. I wished there was a browse widget.

high_flyer
26th October 2007, 13:49
I wished there was a browse widget.
But there is: QFileDialog (http://doc.trolltech.com/3.3/qfiledialog.html) ;)

nitriles
26th October 2007, 13:58
aha! :o
yes, well ill look into that, thanks a lot.

nitriles
30th October 2007, 11:13
Yippi, i managed to get a popup by just saying:


def OpenFile(self):
QFileDialog.getOpenFileName()


But now im having trouble with selecting the file. When the user has selected a file and clicks open, i want the file path including its name to be printed in a lineEdit_box.
I tried using:


datafile = fileSelected() OR datafile=selectedFile()
self.lE_file.setText(datafile)

But this didnt work. Does anybody have any ideas?

NameError: global name 'selectedFile' is not defined

Thanks!

high_flyer
30th October 2007, 11:38
QFileDialog::dirPath() (http://doc.trolltech.com/3.3/qfiledialog.html#dirPath)?
although selectedFile() should work.
What do you mean "doesn't work"?
What do you get in the returned string?

nitriles
30th October 2007, 11:43
i dont get anythin returned.

Well I geuss thats indeed what i need, but how to use it?
I get
"TypeError: first argument of unbound method QFileDialog.dirPath() must be a QFileDialog instance"
when i just use it like:
print QFileDialog.dirPath()
just to see if it works.



def OpenFile(self):
QFileDialog.getOpenFileName("/home/Documents/29-10-07 MiraTest/Browsing app", "UI Files (*.ui)")
print QFileDialog.dirPath()
#print QFileDialog.selectedFile()
#datafile = QFileDialog.selectedFile()
#QFileDialog.ExistingFile()
#datafile = fileSelected()
#datafile=selectedFile()
#datafile = self.lE_file.text().ascii()
#self.lE_file.setText(datafile)
#self.lE_file.insertItem

As you can see i tried multiple things. I want to name the file that has been chosen as "datafile" and then set this as the text for my lineEdit.

high_flyer
30th October 2007, 11:47
I get
TypeError: first argument of unbound method QFileDialog.dirPath() must be a QFileDialog instance
getFileDialog() is a static member - so you don't need an instance of QFileDialog to use it.
But to use selecteFile() you need an instance of QFileDialog.
So create a variable of Type QFileDialog, and use it to access all the methods you need.

nitriles
30th October 2007, 11:49
Im not quite sure i completly understand how to do that. Its rather new for me.

high_flyer
30th October 2007, 11:56
Do what? define a variable?

nitriles
30th October 2007, 15:14
a variable of Type QFileDialog, and use it to access all the methods you need.

I dont know what to do here

high_flyer
30th October 2007, 15:19
Amm...
I don't know what to answer to that.

1. define a variable of type QFileDialog. (if you don't know how to do this, you should start by reading the fundamentals of programming in general, and the language you are using - nothing we can help you here with)
2. use the variable you declared in 1 to access the method - again, if you don't understand this, you lack basic understanding of the programming language you are trying to use, and again, nothing we can help with.

pnikolov
2nd July 2008, 21:25
Just use:

filename = QtGui.QFileDialog.getOpenFileName(self)

When a User selected file is available in filename which is in QString type, you can transform it with str()