Using Eto OpenFileDialog

Hi Dale

I have tried using Eto.Forms.OpenFileDialog like your code above but in Python instead, Unfortunately, when the file dialog pops up by using Forms.FilePicker that doesn’t have any filter option. How can I solve it, Thanks!
This is my code :
self.fd = forms.OpenFileDialog
filter = forms.FileFilter(“CSV file”,“.csv”)
self.fd.Filters.Add(filter)
self.filepath = forms.FilePicker()

I’ve moved this to a new topic.

Hi @Dat_Nguyen,

How about this?

import rhinoscriptsyntax as rs
filename = rs.OpenFileName("Open", "CSV Files (*.csv)|*.csv||")
if filename: 
    rs.MessageBox(filename)

– Dale

1 Like

Hi @dale,

Thanks for your response. I want to put the “input file” box into the Eto layout like this image
and then hit the browse button and see the filter option at the right hand, is it possible? or I have to use rs.OpenFileName to open the file separately from the Eto layout?

Hey @Dat_Nguyen,

If you did something like this:

self.PathTextBox = Eto.Forms.TextBox()

Then you can do this:

 def BrowseButtonClick(self, sender, e):
    filename = rs.OpenFileName("Open", "CSV Files (*.csv)|*.csv||")
    if filename: 
        self.PathTextBox.Text = filename

– Dale

4 Likes

Thanks @dale , I’ll try it!

Hi @dale
If we have more file extensions and we choose between them, how we can use the choice to save xlsx or csv for example?

rs.SaveFileName(“Save”, “xlsx Files (.xlsx)|.xlsx|csv Files (.csv)|.csv||”)


Update, i find this solution but maybe there is a better one

filename = rs.SaveFileName("Save", "xlsx Files (*.xlsx)|*.xlsx|csv Files (*.csv)|*.csv||")
        file, extension = os.path.splitext(filename)
        if filename:
            if extension == '.xlsx':
                self.grid.Save(filename)
            elif extension == '.csv':
                self.grid.CurrentWorksheet.ExportAsCSV(filename)

How would the same code be used inside Eto forms: Label Layout? Please guide me

Check this guide

1 Like