Is it possible to call system.file.openFile() allowing the user to select more than one type of file extension?
In my case i want the user to be able to select file types .JPG, .JPEG and .PNG
Currently, no. But here is the link to the entry on the feedback forum.
It’s not possible through the system function directly, unfortunately. Untested workaround solution:
from com.inductiveautomation.ignition.client.script import ClientFileUtilities
def openFiles(desc, *extensions):
filechooser = ClientFileUtilities.getChooser(0, desc, *extensions)
filechooser.setMultiSelectionEnabled(True)
if filechooser.showOpenDialog(None) is not None:
return [file.getPath() for file in filechooser.getSelectedFiles()]
def openFile(desc, *extensions):
filechooser = ClientFileUtilities.getChooser(0, desc, *extensions)
if filechooser.showOpenDialog(None) is not None:
return filechooser.getSelectedFile().getPath()
# imageFiles = openFiles("Image (JPG, JPEG, PNG)", "jpg", "jpeg", "png")
# imageFile = openFile("Image (JPG, JPEG, PNG)", "jpg", "jpeg", "png")
2 Likes
@PGriffith, your code works as expected. One thing I noticed is when users click cancel it still returns the selected file paths. Any idea how I could get it to return None when a user selects files and then decides to cancel?
if filechooser.showOpenDialog(None) is not None:
can probably be changed to
if filechooser.showOpenDialog(None) == 0:
where 0 is the ‘magic number’ representing javax.swing.JFileChooser#APPROVE_OPTION
; see the constant field values reference: https://docs.oracle.com/javase/7/docs/api/constant-values.html#javax.swing.JFileChooser.APPROVE_OPTION
2 Likes