]> Creatis software - CreaPhase.git/blob - octave_packages/zenity-0.5.7/zenity_progress.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / zenity-0.5.7 / zenity_progress.m
1 ## Copyright (C) 2006  Søren Hauberg
2 ## 
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ## 
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ## 
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn  {Function File} @var{h} = zenity_progress(@var{title}, @var{option1}, @var{option2})
18 ## @deftypefnx {Function File} zenity_progress(@var{h}, @var{progress})
19 ## @deftypefnx {Function File} zenity_progress(@var{h}, @var{progress}, @var{text})
20 ## Displays a graphical progress bar.
21 ## If the first argument is either non-present or a string, a new progress bar is
22 ## created and a handle is returned. If the first argument is a string it will be
23 ## used as the title of the progress bar. The two optional arguments @var{option1}
24 ## and @var{option2} can be
25 ## @table @samp
26 ## @item auto-close
27 ## The progress bar will be closed when it reaches 100.
28 ## @item pulsate
29 ## The progress bar will pulsate.
30 ## @end table
31 ##
32 ## If the first argument is a handle to a progress bar and the second
33 ## argument is an integer, the progress bar will set its current value
34 ## to the given integer. If the second argument is a string, the text
35 ## of the progress bar will be set to the given string.
36 ## It is possible to pass both an integer and a string to the function
37 ## in one function call.
38 ##
39 ## @seealso{zenity_calendar, zenity_list, zenity_entry, zenity_message,
40 ## zenity_text_info, zenity_file_selection, zenity_notification}
41 ## @end deftypefn
42
43 function pid = zenity_progress(h, progress, text)
44   ## Create a progress bar?
45   if (nargin == 0 || (nargin >= 1 && ischar(h)))
46     ## Title
47     title = options = "";
48     if (nargin == 1)
49         title = sprintf('--title="%s" --text="%s"', h, h);
50     endif
51     ## Options
52     if (nargin > 1 && ischar(progress))
53       if (strcmpi(progress, "auto-close"))
54         options = sprintf("%s --auto-close", options);
55       elseif (strcmpi(progress, "pulsate"))
56         options = sprintf("%s --pulsate", options);
57       endif
58     endif
59     if (nargin > 2 && ischar(text))
60       if (strcmpi(text, "auto-close"))
61         options = sprintf("%s --auto-close", options);
62       elseif (strcmpi(text, "pulsate"))
63         options = sprintf("%s --pulsate", options);
64       endif
65     endif
66     ## Start the process
67     pid = popen(["zenity --progress ", title, " ", options], "w");
68   ## Handle an existing process
69   elseif (nargin > 0 && isnumeric(h))
70     out = "";
71     if (nargin > 1 && isnumeric(progress))
72       out = sprintf("%s\n%d\n", out, progress);
73     endif
74     if (nargin > 1 && ischar(progress))
75       out = sprintf("%s\n#%s\n", out, progress);
76     endif
77     if (nargin > 2 && isnumeric(text))
78       out = sprintf("%s\n%d\n", out, text);
79     endif
80     if (nargin > 2 && ischar(text))
81       out = sprintf("%s\n#%s\n", out, text);
82     endif
83     fputs(h, out);
84   else
85     print_usage();
86   endif
87 endfunction