Changes

Jump to navigation Jump to search
1,557 bytes added ,  15:54, 4 August 2017
Create a GUI example page
= uicontrols: Build a GUI in GNU Octave =

You have to use the "qt" graphics toolkit (default since 4.0). For the best results GNU Octave version >= 4.2.x should be used.

== Resources ==

* https://www.gnu.org/software/octave/doc/interpreter/GUI-Development.html

== Examples ==

=== imageViewer ===

GUI which opens a file selection dialog when a button is pressed and views the selected image.

[[File:imageViewer1.png]] [[File:imageViewer2.png]]

{{Code|imageViewer example|<pre>
%% In file 'imageViewer.m'
function imageViewer ()
MainFrm = figure ( ...
'position', [100, 100, 250, 350]);

TitleFrm = axes ( ...
'position', [0, 0.8, 1, 0.2], ...
'color', [0.9, 0.95, 1], ...
'xtick', [], ...
'ytick', [], ...
'xlim', [0, 1], ...
'ylim', [0, 1] );

Title = text (0.05, 0.5, 'Preview Image', 'fontsize', 30);

ImgFrm = axes ( ...
'position', [0, 0.2, 1, 0.6], ...
'xtick', [], ...
'ytick', [], ...
'xlim', [0, 1], ...
'ylim', [0, 1]);

ButtonFrm = uicontrol (MainFrm, ...
'style', 'pushbutton', ...
'string', 'OPEN THE IMAGE', ...
'units', 'normalized', ...
'position', [0, 0, 1, 0.2], ...
'callback', { @previewImage, ImgFrm });
end

%% callback subfunction (in same file)
function previewImage (hObject, eventdata, ImageFrame)
[fname, fpath] = uigetfile();
Img = imread (fullfile(fpath, fname));
axes(ImageFrame);
imshow(Img, []);
axis image off
end
</pre>}}

Then run <code>imageViewer()</code> from your terminal:
219

edits

Navigation menu