Mercurial > hg > octave-lyh
annotate scripts/plot/uigetfile.m @ 12183:b4d26c65e7e6
Allow ui file function to work if gnuplot is the selected toolkit and fltk is available
author | Kai Habel <kai.habel@gmx.de> |
---|---|
date | Thu, 27 Jan 2011 17:58:19 +0100 |
parents | b0084095098e |
children | 33bbae85769a |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2010-2011 Kai Habel |
11283 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uigetfile (@var{flt}) |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 ## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@var{flt}, @var{dialog_name}, @var{default_file}) |
11283 | 22 ## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@var{flt}, @var{dialog_name}) |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
23 ## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@dots{}, "Position", [@var{px}, @var{py}]) |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
24 ## @deftypefnx {Function File} {[@dots{}] =} uigetfile (@dots{}, "Multiselect", @var{mode}) |
11283 | 25 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
26 ## Open a GUI dialog to select a file. It returns the filename @var{fname}, |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
27 ## the path to this file @var{fpath}, and the filter index @var{fltidx}. |
11283 | 28 ## @var{flt} contains a (list of) file filter string(s) in one of the following |
29 ## formats: | |
30 ## | |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
31 ## @table @asis |
11283 | 32 ## @item "/path/to/filename.ext" |
33 ## If a filename is given the file extension is extracted and used as filter. | |
34 ## In addtion the path is selected as current path and the filname is selected | |
35 ## as default file. | |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
36 ## Example: @code{uigetfile ("myfun.m")} |
11283 | 37 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
38 ## @item A single file extension "*.ext" |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
39 ## Example: @code{uigetfile ("*.ext")} |
11283 | 40 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
41 ## @item A 2-column cell array |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
42 ## containing the file extension in the first column and a brief description |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
43 ## in the second column. |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
44 ## Example: @code{uigetfile (@{"*.ext", "My Description";"*.xyz", |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
45 ## "XYZ-Format"@})} |
11583
c4c2cd67c440
Fixes for ui file functions, bug#32190
Kai Habel <kai.habel@gmx.de>
parents:
11576
diff
changeset
|
46 ## |
11283 | 47 ## The filter string can also contain a semicolon separated list of filter |
48 ## extensions. | |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
49 ## Example: @code{uigetfile (@{"*.gif;*.png;*.jpg", "Supported Picture |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
50 ## Formats"@})} |
11283 | 51 ## @end table |
52 ## | |
53 ## @var{dialog_name} can be used to customize the dialog title. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11583
diff
changeset
|
54 ## If @var{default_file} is given it is selected in the GUI dialog. |
11283 | 55 ## If in addtion a path is given it is also used as current path. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11583
diff
changeset
|
56 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
57 ## The screen position of the GUI dialog can be set using the "Position" key |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
58 ## and a 2-element vector containing the pixel coordinates. |
11283 | 59 ## Two or more files can be selected when setting the "Multiselect" key to "on". |
11583
c4c2cd67c440
Fixes for ui file functions, bug#32190
Kai Habel <kai.habel@gmx.de>
parents:
11576
diff
changeset
|
60 ## In that case @var{fname} is a cell array containing the files. |
11283 | 61 ## @end deftypefn |
62 | |
63 ## Author: Kai Habel | |
64 | |
65 function [retfile, retpath, retindex] = uigetfile (varargin) | |
66 | |
67 if (nargin <= 7) | |
68 | |
69 defaultvals = {"All Files(*)", #FLTK File Filter | |
70 "Open File?", #Dialog Title | |
11284
b9bc32327c4d
ChangeLog fix, set default directory to pwd for ui file functions
Kai Habel <kai.habel@gmx.de>
parents:
11283
diff
changeset
|
71 pwd, #FLTK default file name |
11283 | 72 [240, 120], #Dialog Position (pixel x/y) |
73 "off"}; #Multiselect on/off | |
74 | |
75 outargs = cell (5, 1); | |
76 for i = 1 : 5 | |
77 outargs{i} = defaultvals{i}; | |
78 endfor | |
79 | |
80 idx1 = idx2 = []; | |
81 if (length (varargin) > 0) | |
82 for i = 1 : length (varargin) | |
83 val = varargin{i}; | |
84 if (ischar (val)) | |
85 if (strncmp (tolower (val), "multiselect", 11)) | |
86 idx1 = i; | |
87 elseif (strncmp(tolower (val), "position", 8)) | |
88 idx2 = i; | |
89 endif | |
90 endif | |
91 endfor | |
92 endif | |
93 | |
94 stridx = [idx1, idx2, 0]; | |
95 if (length (stridx) > 1) | |
96 stridx = min (stridx(1 : end - 1)); | |
97 endif | |
98 | |
99 args = varargin; | |
100 if (stridx) | |
101 args = varargin(1 : stridx - 1); | |
102 endif | |
103 | |
104 len = length (args); | |
105 if (len > 0) | |
106 file_filter = args{1}; | |
107 outargs{1} = __fltk_file_filter__ (file_filter); | |
108 if (ischar (file_filter)) | |
109 outargs{3} = file_filter; | |
110 endif | |
111 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11583
diff
changeset
|
112 |
11283 | 113 if (len > 1) |
114 outargs{2} = args{2}; | |
115 endif | |
116 | |
117 if (len > 2) | |
118 outargs{3} = args{3}; | |
119 endif | |
120 | |
121 if (stridx) | |
122 ## we have string arguments ("position" or "multiselect") | |
123 | |
124 ## check for even number of remaining arguments, prop/value pair(s) | |
125 if (rem (nargin - stridx + 1, 2)) | |
11295
75ff3db6a687
Simplify code for uimenu.m. Fix error messages for ui file functions.
Kai Habel <kai.habel@gmx.de>
parents:
11284
diff
changeset
|
126 error ("uigetfile: expecting property/value pairs"); |
11283 | 127 endif |
128 | |
129 for i = stridx : 2 : nargin | |
130 prop = varargin{i}; | |
131 val = varargin{i + 1}; | |
11583
c4c2cd67c440
Fixes for ui file functions, bug#32190
Kai Habel <kai.habel@gmx.de>
parents:
11576
diff
changeset
|
132 if (strncmp (tolower (prop), "position", 8)) |
11283 | 133 if (ismatrix (val) && length(val) == 2) |
134 outargs{4} = val; | |
135 else | |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11588
diff
changeset
|
136 error ("uigetfile: expecting 2-element vector for position argument"); |
11283 | 137 endif |
138 elseif (strncmp (tolower (prop), "multiselect", 11)) | |
139 if (ischar (val)) | |
140 outargs{5} = tolower (val); | |
141 else | |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11588
diff
changeset
|
142 error ("uigetfile: expecting string argument (on/off) for multiselect"); |
11283 | 143 endif |
144 else | |
11295
75ff3db6a687
Simplify code for uimenu.m. Fix error messages for ui file functions.
Kai Habel <kai.habel@gmx.de>
parents:
11284
diff
changeset
|
145 error ("uigetfile: unknown argument"); |
11283 | 146 endif |
147 endfor | |
148 endif | |
149 else | |
11295
75ff3db6a687
Simplify code for uimenu.m. Fix error messages for ui file functions.
Kai Habel <kai.habel@gmx.de>
parents:
11284
diff
changeset
|
150 error ("uigetfile: number of input arguments must be less than eight"); |
11283 | 151 endif |
152 | |
12183
b4d26c65e7e6
Allow ui file function to work if gnuplot is the selected toolkit and fltk is available
Kai Habel <kai.habel@gmx.de>
parents:
11589
diff
changeset
|
153 if (exist("__fltk_uigetfile__") == 3) |
11583
c4c2cd67c440
Fixes for ui file functions, bug#32190
Kai Habel <kai.habel@gmx.de>
parents:
11576
diff
changeset
|
154 [retfile, retpath, retindex] = __fltk_uigetfile__ (outargs{:}); |
11283 | 155 else |
11588
d5bd2766c640
style fixes for warning and error messages in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
156 error ("uigetfile: fltk graphics toolkit required"); |
11283 | 157 endif |
158 | |
159 endfunction | |
160 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11583
diff
changeset
|
161 %!demo |
11283 | 162 %! uigetfile({"*.gif;*.png;*.jpg", "Supported Picture Formats"}) |