File Name in Input Box

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
gsandy
Posts: 292
Joined: Sun Jan 27, 2019 7:07 pm
Location: Auckland New Zealand

File Name in Input Box

Post by gsandy »

How can I modify the code below so that the image name (MyImage) is entered by an input box and "imageLocation" would return the same value as it does now?
The object is to be able to enter different image names without going into the code.

Code: Select all

imageLocation = "E:/Freecad/Images/MyImage.jpg"
edi
Posts: 482
Joined: Fri Jan 17, 2020 1:32 pm

Re: File Name in Input Box

Post by edi »

Code: Select all

from PySide import QtGui
MyImage=QtGui.QInputDialog.getText(None,"Input File Name","Please input the file name")[0]
imageLocation = "E:/Freecad/Images/"+MyImage+".jpg"
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: File Name in Input Box

Post by heda »

https://pyside.github.io/docs/pyside/Py ... ialog.html

Code: Select all

fileName, *_ = QtGui.QFileDialog.getOpenFileName(None, "Open Image", "E:/Freecad/Images", "Image Files (*.png *.jpg *.bmp)")
edited code,
was not unpacking correct,
and fileName is imageLocation (i.e. just put imageLocation instead of fileName in the above if I get your question right)
Last edited by heda on Mon Jun 21, 2021 8:18 pm, edited 3 times in total.
gsandy
Posts: 292
Joined: Sun Jan 27, 2019 7:07 pm
Location: Auckland New Zealand

Re: File Name in Input Box

Post by gsandy »

Thanks edi your code just how I wanted it to, great.

Thanks heda for the web link. And I would like to pursue your code further. I got it working but I don't know how to get your "fileName" incorporated into my "imageLocation", which is used else where in my code.
Post Reply