Skip to content
Snippets Groups Projects
Commit 9587a318 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Gui: added GtSlideShow class (to view multiple images), and classes for...

Gui: added GtSlideShow class (to view multiple images), and classes for joinable interfaces/display of lists

Squashed commit of the following:

commit b24355ee2ef49c41fce0b5de696da72640aa83e4
Author: Nicola Vigano <nicola.vigano@esrf.fr>
Date:   Tue Aug 7 01:18:53 2012 +0200

    Gui: GtSlideShow: added better selection of images (by index and list)

Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

commit 7a04a43256ad45d4c385ed9c70aa1ff0f8773517
Author: Nicola Vigano <nicola.vigano@esrf.fr>
Date:   Tue Jul 31 20:14:10 2012 +0200

    GtSlideShow: added initial simple class to browse a folder content

Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

commit 260ac1d304a2253afb4e5d4d3d8fdb7a86402066
Author: Nicola Vigano <nicola.vigano@esrf.fr>
Date:   Mon Aug 6 19:42:20 2012 +0200

    Gui: added list selector, based on joinable GUIs.

Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

commit 0c400c19021df639de402e1c5b95519f9c15c8da
Author: Nicola Vigano <nicola.vigano@esrf.fr>
Date:   Mon Aug 6 19:41:36 2012 +0200

    Gui: added join-able GUI object (to act as a function that returns a value)

Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@683 4c865b51-4357-4376-afb4-474e03ccb993
parent 80bafa93
No related branches found
No related tags found
No related merge requests found
classdef GtGuiJoinableElem < GtBaseGuiElem
% Class GtGuiJoinableElem: base class for joinable graphical user interfaces. It
% is useful in case you want to build a GUI object that should return a value.
%
% It makes the object oriented GUI implementations equivalent to function
% implementations.
%
% Working with it is simple: you first instanciate your object, and then you
% expect a result from the call to the join() method.
%
% >> objHandle = DerivedClass(blabla);
% >> expectedResult = objHandle.join();
%
properties
jointRetval = [];
jointIsSet = false;
isJoint = false;
end
methods (Access = public)
function obj = GtGuiJoinableElem()
obj = obj@GtBaseGuiElem();
end
function retval = join(obj)
savedInitialVal = obj.jointRetval;
obj.isJoint = true;
try
while(~obj.jointIsSet)
pause(0.0156);
end
retval = obj.jointRetval;
delete(obj);
catch mexc
retval = savedInitialVal;
% If the exception is of that type, we don't care, because it
% simply means that the object was deleted.
if (~gtCheckExceptionType(mexc, 'MATLAB:class:InvalidHandle'))
gtPrintException(mexc);
delete(obj);
end
end
end
end
methods (Access = protected)
function setJointReturnVal(obj, val)
obj.jointRetval = val;
obj.jointIsSet = true;
end
end
end
classdef GtGuiSelectInList < GtGuiJoinableElem
% Class GtGuiSelectInList: Selector class for lists of entries.
%
% It expects a cell string array as input, and displays the values in the rows.
% Using the join() method is suggested.
%
% >> objHandle = GtGuiSelectInList({'Item1', 'Item2', 'Item3'});
% >> index = objHandle.join();
%
% index will contain the index of the selected element, in case Ok button was
% pressed, otherwise it will be an empty vector.
%
properties
listOfNames;
end
methods (Access = public)
function obj = GtGuiSelectInList(listOfNames, varargin)
obj = obj@GtGuiJoinableElem();
if (iscell(listOfNames))
listOfNames = reshape(listOfNames, [1 numel(listOfNames)]);
end
obj.listOfNames = listOfNames;
obj.conf.f_title = 'List Selection';
obj.initGtBaseGuiElem(varargin);
end
end
methods (Access = protected)
function initGui(obj)
initGui@GtBaseGuiElem(obj)
dlgBlock = [];
dlgBlock.hor_boxes = uiextras.HBox('Parent', obj.conf.currentParent);
dlgBlock.list = uicontrol('Parent', dlgBlock.hor_boxes, ...
'Style', 'listbox', 'String', obj.listOfNames);
dlgBlock.vert_boxes = uiextras.VButtonBox('Parent', dlgBlock.hor_boxes);
dlgBlock.butts(1) = uicontrol('Parent', dlgBlock.vert_boxes, ...
'Style', 'pushbutton', 'String', 'Ok', ...
'Callback', @(src, evt)onOkButton(obj));
dlgBlock.butts(2) = uicontrol('Parent', dlgBlock.vert_boxes, ...
'Style', 'pushbutton', 'String', 'Cancel', ...
'Callback', @(src, evt)onCancelButton(obj));
set(dlgBlock.hor_boxes, 'Sizes', [-1 120]);
obj.conf.dlgBlock = dlgBlock;
end
function resetUiComponents(obj)
end
function doUpdateDisplay(obj)
end
function addUICallbacks(obj)
end
end
methods (Access = public)
function onOkButton(obj)
selected = get(obj.conf.dlgBlock.list, 'Value');
if (obj.isJoint)
obj.setJointReturnVal(selected);
else
fprintf('Selected value: %d\n', selected);
delete(obj);
end
end
function onCancelButton(obj)
if (obj.isJoint)
obj.setJointReturnVal([]);
else
delete(obj);
end
end
end
end
classdef GtSlideShow < GtVolView
properties
end
methods (Access = public)
function obj = GtSlideShow(filePattern, varargin)
% GTVOLVIEW/GTVOLVIEW Constructor
files = dir(filePattern);
if (isempty(files))
error('GtSlideShow:wrong_argument', ...
'the given file pattern: "%s", didn''t produce any result', ...
filePattern)
end
params = {'CMap', gray(2^16), 'CLims', [0 2^16], ...
'filesRecord', files, 'filesDir', fileparts(filePattern)};
params = [params varargin{:}];
params(end+1:end+2) = {'f_title', 'GtSlideShow'};
vol = ones(2, 2, length(files));
vol(1:2, 1, 1) = 0;
obj = obj@GtVolView(vol, params{:});
% We need to get the parameters seen - It's a dirty trick but it
% works
obj.initParams(params);
obj.setConfigInvariants();
obj.resetUiComponents();
obj.updateDisplay();
end
end
methods (Access = protected)
function initParams(obj, arguments)
obj.conf.filesRecord = [];
obj.conf.filesDir = '';
initParams@GtVolView(obj, arguments)
end
function initGui(obj)
% GTGRAINSMANAGER/INITGUI Inherited method that builds the interface
initGui@GtVolView(obj)
% Let's disable zoom, while configuring
zoomOp = zoom(obj.conf.h_figure);
zoomState = get(zoomOp, 'Enable');
zoom(obj.conf.h_figure, 'off');
obj.conf.main_s_boxes = uiextras.VBox('Parent', obj.conf.currentParent);
obj.conf.upper_s_boxes = uiextras.HBox('Parent', obj.conf.main_s_boxes);
obj.conf.h_viewer_panel = uipanel('BorderWidth', 4, ...
'BorderType', 'line', ...
'Parent', obj.conf.main_s_boxes);
set(obj.conf.main_boxes, 'Parent', obj.conf.h_viewer_panel);
set(obj.conf.main_s_boxes, 'Sizes', [25 -1]);
% Setting up image selection bar
obj.conf.upper_s_bar(1) = uicontrol('Parent', obj.conf.upper_s_boxes, ...
'Style', 'text', 'HorizontalAlignment', 'left');
obj.conf.upper_s_bar(2) = uicontrol('Parent', obj.conf.upper_s_boxes, ...
'Style', 'text', 'String', 'Index:', 'HorizontalAlignment', 'left');
obj.conf.upper_s_bar(3) = uicontrol('Parent', obj.conf.upper_s_boxes, ...
'Style', 'edit', 'HorizontalAlignment', 'right', ...
'Callback', @(src, evt)onChangeEdit(obj));
obj.conf.upper_s_bar(4) = uicontrol('Parent', obj.conf.upper_s_boxes, ...
'Style', 'text', 'HorizontalAlignment', 'left', ...
'String', sprintf('/%d', length(obj.conf.filesRecord)));
obj.conf.upper_s_bar(5) = uicontrol('Parent', obj.conf.upper_s_boxes, ...
'Style', 'pushbutton', 'String', 'List', ...
'Callback', @(src, evt)onSelectButton(obj));
set(obj.conf.upper_s_boxes, 'Sizes', [-1 45 40 50 60]);
% Reset back the zoom to the previous state (before the inclusion)
set(zoomOp, 'Enable', zoomState);
end
function slice = loadSlice(obj, vol)
if (~isempty(obj.conf.filesRecord))
filename = obj.conf.filesRecord(obj.conf.slicendx).name;
filename = fullfile(obj.conf.filesDir, filename);
set(obj.conf.upper_s_bar(1), 'String', sprintf('Image: %s', filename));
set(obj.conf.upper_s_bar(3), 'String', sprintf('%d', obj.conf.slicendx));
drawnow;
[slice, obj.conf.volInfo] = GtVolView.loadVolume(filename);
% slice = permute(slice, [2, 1]);
[dim(1), dim(2)] = size(slice);
obj.conf.dim = [dim, length(obj.conf.filesRecord)];
obj.conf.hordisplay = [1 obj.conf.dim(1)];
obj.conf.verdisplay = [1 obj.conf.dim(2)];
obj.conf.clims = gtSetColourLimits(slice, 0, true);
minVal = get(obj.conf.h_min, 'Value');
maxVal = get(obj.conf.h_max, 'Value');
if (minVal < obj.conf.clims(1))
minVal = obj.conf.clims(1);
elseif (minVal > obj.conf.clims(2))
minVal = obj.conf.clims(2);
end
if (maxVal < obj.conf.clims(1))
maxVal = obj.conf.clims(1);
elseif (maxVal > obj.conf.clims(2))
maxVal = obj.conf.clims(2);
end
set(obj.conf.h_min, 'Min', obj.conf.clims(1), 'Max', obj.conf.clims(2), 'Value', minVal);
set(obj.conf.h_max, 'Min', obj.conf.clims(1), 'Max', obj.conf.clims(2), 'Value', maxVal);
else
slice = loadSlice@GtVolView(obj, vol);
end
end
end
methods (Access = public)
function onSelectButton(obj)
names = {obj.conf.filesRecord.name};
names = cellfun(@(x){fullfile(obj.conf.filesDir, x)}, names);
selector = GtGuiSelectInList(names);
index = selector.join();
if (~isempty(index))
obj.changeSlice(index);
end
end
function onChangeEdit(obj)
value = get(obj.conf.upper_s_bar(3), 'String');
try
value = str2double(value);
if (value > 0 && value <= length(obj.conf.filesRecord))
obj.changeSlice(value);
else
error('GUI:GtSlideShow:wrong_argument', ...
'Index %d out of bounds', value);
end
catch mexc
gtPrintException(mexc)
d = errordlg(['Error: ' mexc.message], mexc.identifier, 'modal');
uiwait(d);
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment