opening several files with File trait...

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

opening several files with File trait...

fred-2
Hi all,

How could I open multiple files at once?

Something like pressing Ctrl-a which selects all files in the current
directory, or selecting several files with Shift pressed, and so on...


File trait seems to not understand this... :-(


TIA.


Cheers,

--
Fred
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: opening several files with File trait...

Robert Kern
On Mon, Apr 12, 2010 at 11:19 AM, Fred <[hidden email]> wrote:
> Hi all,
>
> How could I open multiple files at once?
>
> Something like pressing Ctrl-a which selects all files in the current
> directory, or selecting several files with Shift pressed, and so on...
>
>
> File trait seems to not understand this... :-(

Sorry, a File trait is for a single file, not a list of files. You
will have to resort to more statndard GUI programming for this. I
recommend using a button or a menu item to open a file using a
FileDialog (from enthought.pyface.api import FileDialog) with the
appropriate settings to allow multiselection. Check out
TraitsGUI/examples/python_editor.py for an example of how to use the
FileDialog class. Check its source for the options you need to set to
get multiselection.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: opening several files with File trait...

Brennan Williams
Robert Kern wrote:

> On Mon, Apr 12, 2010 at 11:19 AM, Fred <[hidden email]> wrote:
>  
>> Hi all,
>>
>> How could I open multiple files at once?
>>
>> Something like pressing Ctrl-a which selects all files in the current
>> directory, or selecting several files with Shift pressed, and so on...
>>
>>
>> File trait seems to not understand this... :-(
>>    
>
> Sorry, a File trait is for a single file, not a list of files. You
> will have to resort to more statndard GUI programming for this. I
> recommend using a button or a menu item to open a file using a
> FileDialog (from enthought.pyface.api import FileDialog) with the
> appropriate settings to allow multiselection. Check out
> TraitsGUI/examples/python_editor.py for an example of how to use the
> FileDialog class. Check its source for the options you need to set to
> get multiselection.
>
>  
I use something like...

        fd=FileDialog(action='open
files',wildcard=wildcard,title='Choose input and output files to import')
      if fd.open()==OK:
        for eachfile in fd.paths:
           ....

Brennan



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: opening several files with File trait...

fred-2
Le 12/04/2010 23:53, Brennan Williams a écrit :

> I use something like...
>
>          fd=FileDialog(action='open
> files',wildcard=wildcard,title='Choose input and output files to import')
>        if fd.open()==OK:
>          for eachfile in fd.paths:
I already FileDialog trait but to save file.

I did not know that I could open several files with it.


Thanks Robert & Brennan!

--
Fred
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: opening several files with File trait...

fred-2
In reply to this post by Brennan Williams
Le 12/04/2010 23:53, Brennan Williams a écrit :
>
> I use something like...
>
>          fd=FileDialog(action='open
> files',wildcard=wildcard,title='Choose input and output files to import')
>        if fd.open()==OK:
>          for eachfile in fd.paths:

Brennan,

Using this:

     def _img_file_button_fired(self):
         fd = FileDialog(action='open files',
                         default_filename=self.img_file,
                         title='Open images files...',
                         wildcard='PNG files (*.png)|*.png|JPEG files
(*.jpg)|*.jpg|')


I get a blank field above Cancel & Ok buttons if default_filename is not
empty.

Do you get the same result, or is my wildcard bad?

TIA.


Cheers,

--
Fred
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: opening several files with File trait...

Warren Weckesser
Fred wrote:

> Le 12/04/2010 23:53, Brennan Williams a écrit :
>  
>> I use something like...
>>
>>          fd=FileDialog(action='open
>> files',wildcard=wildcard,title='Choose input and output files to import')
>>        if fd.open()==OK:
>>          for eachfile in fd.paths:
>>    
>
> Brennan,
>
> Using this:
>
>      def _img_file_button_fired(self):
>          fd = FileDialog(action='open files',
>                          default_filename=self.img_file,
>                          title='Open images files...',
>                          wildcard='PNG files (*.png)|*.png|JPEG files
> (*.jpg)|*.jpg|')
>
>
> I get a blank field above Cancel & Ok buttons if default_filename is not
> empty.
>  

I'm not sure if this is the problem, but you shouldn't have that
trailing vertical bar at the end.  Try removing it.

Warren

> Do you get the same result, or is my wildcard bad?
>
> TIA.
>
>
> Cheers,
>
>  

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: opening several files with File trait...

Brennan Williams
Warren Weckesser wrote:

> Fred wrote:
>  
>> Le 12/04/2010 23:53, Brennan Williams a écrit :
>>  
>>    
>>> I use something like...
>>>
>>>          fd=FileDialog(action='open
>>> files',wildcard=wildcard,title='Choose input and output files to import')
>>>        if fd.open()==OK:
>>>          for eachfile in fd.paths:
>>>    
>>>      
>> Brennan,
>>
>> Using this:
>>
>>      def _img_file_button_fired(self):
>>          fd = FileDialog(action='open files',
>>                          default_filename=self.img_file,
>>                          title='Open images files...',
>>                          wildcard='PNG files (*.png)|*.png|JPEG files
>> (*.jpg)|*.jpg|')
>>
>>
>> I get a blank field above Cancel & Ok buttons if default_filename is not
>> empty.
>>  
>>    
>
> I'm not sure if this is the problem, but you shouldn't have that
> trailing vertical bar at the end.  Try removing it.
>
> Warren
>
>  

Just looking at my code, I'm only using a single filter in my wildcard, e.g.

wildcard='rezen projects (*.rzp)|*.rzp'

However I think you need a comma in there ...

wildcard='PNG files (*.png)|*.png,JPEG files (*.jpg)|*.jpg'


and I think Warren is correct about that last |

Brennan

>> Do you get the same result, or is my wildcard bad?
>>
>> TIA.
>>
>>
>> Cheers,
>>
>>  
>>    
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>  


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: opening several files with File trait...

Robert Kern
On Tue, Apr 13, 2010 at 5:16 PM, Brennan Williams
<[hidden email]> wrote:

> Warren Weckesser wrote:
>> Fred wrote:
>>
>>> Le 12/04/2010 23:53, Brennan Williams a écrit :
>>>
>>>
>>>> I use something like...
>>>>
>>>>          fd=FileDialog(action='open
>>>> files',wildcard=wildcard,title='Choose input and output files to import')
>>>>        if fd.open()==OK:
>>>>          for eachfile in fd.paths:
>>>>
>>>>
>>> Brennan,
>>>
>>> Using this:
>>>
>>>      def _img_file_button_fired(self):
>>>          fd = FileDialog(action='open files',
>>>                          default_filename=self.img_file,
>>>                          title='Open images files...',
>>>                          wildcard='PNG files (*.png)|*.png|JPEG files
>>> (*.jpg)|*.jpg|')
>>>
>>>
>>> I get a blank field above Cancel & Ok buttons if default_filename is not
>>> empty.
>>>
>>>
>>
>> I'm not sure if this is the problem, but you shouldn't have that
>> trailing vertical bar at the end.  Try removing it.
>>
>> Warren
>>
>>
>
> Just looking at my code, I'm only using a single filter in my wildcard, e.g.
>
> wildcard='rezen projects (*.rzp)|*.rzp'
>
> However I think you need a comma in there ...
>
> wildcard='PNG files (*.png)|*.png,JPEG files (*.jpg)|*.jpg'

| is correct:

http://www.wxpython.org/docs/api/wx.FileDialog-class.html

> and I think Warren is correct about that last |

The implementation strips it out:

        # Create the actual dialog.
        dialog = wx.FileDialog(parent, self.title, defaultDir=default_directory,
                    defaultFile=default_filename, style=style,
                    wildcard=self.wildcard.rstrip('|'))

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev