Quantcast

uigetfile

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

uigetfile

Sascha Raddatz
hi,

i've got a matlab-file which i want to use with octave. octave seems not
to know the function 'uigetfile'. how can i else open a textfile to read
its content into octave?

yours,

sascha

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uigetfile

Søren Hauberg
tor, 15 04 2010 kl. 16:36 +0200, skrev Sascha Raddatz:
> i've got a matlab-file which i want to use with octave. octave seems not
> to know the function 'uigetfile'. how can i else open a textfile to read
> its content into octave?

The functions 'textread' and 'load' might be of use to you.

Søren

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uigetfile

Petr Mikulik
In reply to this post by Sascha Raddatz
> i've got a matlab-file which i want to use with octave. octave seems not
> to know the function 'uigetfile'.

I wrote this uigetfile.m:
        physics.muni.cz/~mikulik/tmp/uigetfile.m
and also
        physics.muni.cz/~mikulik/tmp/listdlg.m

They work fine on Linux; other systems untested.

---
Petr Mikulik
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uigetfile

farhi
Thanks for the nice uigetfile contribution.

I took the liberty to slightly enhance it with a call to zenity (gnome dialogs) to complement kdialog. Also, the fall back solution now uses 'dir' which is platform independent, and thus will work on all systems.

Shuold it be contributed to the octave sourceforge ?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uigetfile

farhi
And here is the uigetfile using dir, or zenity or kdialogs, which should work on all systems.

uigetfile.m

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uigetfile

Petr Mikulik
In reply to this post by Petr Mikulik
> I took the liberty to slightly enhance it with a call to zenity (gnome
> dialogs) to complement kdialog.
> And here is the uigetfile using dir, or zenity or kdialogs, which should
> work on all systems.

Unfortunately zenity does not work properly:

A1. uigetfile('*.dat', 'Open data file')
   => it ignores the '*.dat' filter. Even if I try it from command line
        zenity --file-selection --filename='*.dat'
   then the filter is ignored.
   Is that a bug in zenity? If it is, then zenity has to be the last
   dialog tried.

A2. On my system, it always prints:

   (zenity:19867): Gtk-CRITICAL **:
gtk_file_chooser_default_set_current_name:
   assertion `impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || impl->action
==
   GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed

   which is very annoying.

B. Further, you have removed the case of "xdialog". I think it is available
on (older) systems without KDE and Gnome ... cygwin/X11, for example.
Please revert it.

C. Further, you have removed lines such as
        [a,b]=system('which XXXXdialog 2>/dev/null');
and thus yet another annoying messages appear such as:
        sh: zenity: command not found
I think it should be reverted.
BTW -- is this "which" available in cygwin-Octave?

D1. Your plain text "dir" is cool, but produces wrong output for files:
        ... a.dat/
        ... b.dat/
        ... c.dat/

D2. uigetfile('*.dat', 'Open data file')
produces error message:
error: ui: A(I): index out of bounds; value 3 out of bound 2

Could you please update the patch?


> Should it be contributed to the octave sourceforge?

I would very welcome this patch available there.


Greetings,
   Petr Mikulik
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uigetfile

farhi
Hi Petr and Sacha,

Thanks a lot for your comments.

A: zenity is now third choice, and indeed the filter is not functional (unfortunately). On the other hand, launching Kdialog from a non KDE systems takes quite some time. The warning is not shown as a  '2>/dev/null' redirection is there.

B: Xdialog is indeed very good, thus I put it back.

C: I fixed the warning (from stderr) displayed when some of xdialog/kdialog/zenity is not installed. I thus re-introduced the '2>/dev/null' redirection in command lines.

D: the 'dir' now works OK, aa a check for existence of files to select is done prior to anything else. Trailing filesep have been removed.

I hope we now converge to something both portable and fancy .

Octave 'uigetfile' code:
uigetfile.m
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uigetfile

schnumbl
Here is another approch using the octave java package:

uigetfile.m
--------------------------------------------------------------------------------------
function [filename filepath] =uigetfile(titlestr, defaultpathstr)

 %FileChooser doc: http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JFileChooser.html
 %File doc: http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html
 %JFileFilter doc: http://www.lamatek.com/lamasoft/javadocs/swingextras/com/lamatek/util/JFileFilter.html

 %load octave java package
 pkg load java;
 
 %create java File Chooser
 FileChooser = java_new('javax.swing.JFileChooser',defaultpathstr);
 FileChooser.setDialogTitle(titlestr);

 %%include additional java classes
 %javajarpath="C:\\Programme\\Java\\jre6\\lib\\rt.jar";
 %javaaddpath("C:\\Programme\\Java\\jre6\\lib\\rt.jar");
 %javaaddpath("C:\\SwingExtras.jar"); %http://www.lamatek.com/lamasoft/
 
 %%define a JFileFilter
  %JFileFilter = java_new('com.lamatek.util.JFileFilter',"Octave Files ","m");
        %FileChooser.setFileFilter(JFileFilter);
 
 %show Dialog
 FileChooser.showOpenDialog([]);
 
 %get file information
 File = FileChooser.getSelectedFile();
 filename = File.getName();
 filepath = File.getPath();
end

uiputfile.m
--------------------------------------------------------------------------------------
function [filename filepath] =uiputfile(titlestr, defaultpathstr)
 %FileChooser doc: http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JFileChooser.html
 %File doc: http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html
 %JFileFilter doc: http://www.lamatek.com/lamasoft/javadocs/swingextras/com/lamatek/util/JFileFilter.html
 
 filename ="error";
 filepath ="error";
 
 %create java File Chooser
 JFileChooser = java_new('javax.swing.JFileChooser',defaultpathstr);
 JFileChooser.setDialogTitle(titlestr);
 JFileChooser.setSelectedFile(java_new('java.io.File', defaultpathstr))  

 %show Dialog
 JFileChooser.showSaveDialog([]);

 %get file information
 File = JFileChooser.getSelectedFile();
 filename = File.getName();
 filepath = File.getPath();
end
Loading...