Uicontrols

From Octave
Revision as of 19:54, 4 August 2017 by Andy1978 (talk | contribs) (Create a GUI example page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

Examples

imageViewer

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

ImageViewer1.png ImageViewer2.png

Code: imageViewer example
%% 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

Then run imageViewer() from your terminal: