comparison scripts/plot/util/graphics_toolkit.m @ 19705:bf27e21f0bfb

maint: Merge default to temporary audio-gsoc branch.
author John W. Eaton <jwe@octave.org>
date Wed, 31 Dec 2014 14:59:42 -0500
parents abc78c10acb6
children 446c46af4b42
comparison
equal deleted inserted replaced
19704:dac3191a5301 19705:bf27e21f0bfb
1 ## Copyright (C) 2008-2013 Michael Goffioul
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 -*-
20 ## @deftypefn {Function File} {@var{name} =} graphics_toolkit ()
21 ## @deftypefnx {Function File} {@var{name} =} graphics_toolkit (@var{hlist})
22 ## @deftypefnx {Function File} {} graphics_toolkit (@var{name})
23 ## @deftypefnx {Function File} {} graphics_toolkit (@var{hlist}, @var{name})
24 ## Query or set the default graphics toolkit which is assigned to new figures.
25 ##
26 ## With no inputs, return the current default graphics toolkit. If the input
27 ## is a list of figure graphic handles, @var{hlist}, then return the name
28 ## of the graphics toolkit in use for each figure.
29 ##
30 ## When called with a single input @var{name} set the default graphics toolkit
31 ## to @var{name}. If the toolkit is not already loaded, it is initialized by
32 ## calling the function @code{__init_@var{name}__}. If the first input
33 ## is a list of figure handles, @var{hlist}, then the graphics toolkit is set
34 ## to @var{name} for these figures only.
35 ##
36 ## @seealso{available_graphics_toolkits}
37 ## @end deftypefn
38
39 function retval = graphics_toolkit (name, hlist = [])
40
41 if (nargin > 2)
42 print_usage ();
43 endif
44
45 if (nargout > 0 || nargin == 0)
46 retval = get (0, "defaultfigure__graphics_toolkit__");
47 endif
48
49 if (nargin == 0)
50 return;
51 elseif (nargin == 1)
52 if (all (isfigure (name)))
53 hlist = name;
54 retval = get (hlist, "__graphics_toolkit__");
55 return;
56 elseif (! ischar (name))
57 error ("graphics_toolkit: invalid graphics toolkit NAME");
58 endif
59 elseif (nargin == 2)
60 ## Swap input arguments
61 [hlist, name] = deal (name, hlist);
62 if (! all (isfigure (hlist)))
63 error ("graphics_toolkit: invalid figure handle list HLIST");
64 elseif (! ischar (name))
65 error ("graphics_toolkit: invalid graphics toolkit NAME");
66 endif
67 endif
68
69 if (! any (strcmp (available_graphics_toolkits (), name)))
70 error ("graphics_toolkit: %s toolkit is not available", name);
71 endif
72
73 if (! any (strcmp (loaded_graphics_toolkits (), name)))
74 feval (["__init_", name, "__"]);
75 if (! any (strcmp (loaded_graphics_toolkits (), name)))
76 error ("graphics_toolkit: %s toolkit was not correctly loaded", name);
77 endif
78 endif
79
80 if (isempty (hlist))
81 set (0, "defaultfigure__graphics_toolkit__", name);
82 else
83 set (hlist, "__graphics_toolkit__", name);
84 endif
85
86 endfunction
87
88
89 %!testif HAVE_FLTK
90 %! unwind_protect
91 %! hf = figure ("visible", "off");
92 %! toolkit = graphics_toolkit ();
93 %! assert (get (0, "defaultfigure__graphics_toolkit__"), toolkit);
94 %! graphics_toolkit (hf, "fltk");
95 %! assert (graphics_toolkit (hf), "fltk");
96 %! unwind_protect_cleanup
97 %! close (hf);
98 %! end_unwind_protect
99
100 %!testif HAVE_FLTK
101 %! old_toolkit = graphics_toolkit ();
102 %! switch (old_toolkit)
103 %! case {"gnuplot"}
104 %! new_toolkit = "fltk";
105 %! otherwise
106 %! new_toolkit = "gnuplot";
107 %! endswitch
108 %! assert (graphics_toolkit (new_toolkit), old_toolkit);
109 %! assert (graphics_toolkit (old_toolkit), new_toolkit);
110