Skip to content

Instantly share code, notes, and snippets.

@Foadsf
Last active March 25, 2019 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Foadsf/7449f709b7eab53f66dfdb1cf9dc75c7 to your computer and use it in GitHub Desktop.
Save Foadsf/7449f709b7eab53f66dfdb1cf9dc75c7 to your computer and use it in GitHub Desktop.
updating the positon of an image in a scilab figure when resizing the figure -->http://bugzilla.scilab.org/show_bug.cgi?id=16016

OK, I'm going to write here because Scilab bugzilla is awfull. I wrote comments twice and it just shows the first couple of lines of my text!!!!

http://bugzilla.scilab.org/show_bug.cgi?id=16016

I wish Scilab decision makers would just move the entire codebase to modern platforms Github or GitLab. This is not good at all. so much headach for users and contributors.

about the bug, I don't think moving the resizefcnfunction solves the problem. The ex002.sce proves that. There are 3 issues

  1. The resizefcn shouldn't be triggered upon creating the figure. this is a bad behaviour in my opinion.
  2. the findobj function should at least drop a warning when not finding an object.
  3. there is a problem specifically with the vertical positioning of the image object. the horizontal is fine. plus the pushbutton's position is updated.

the ex003.sce pinpoints the bug more specifically.

function closemainfigure()
MainFigure = findobj('tag','MainFigure');
close(MainFigure);
endfunction
function resizemainfigure()
MainFigure = findobj('tag', 'MainFigure');
MainFigureAxesSize = MainFigure.axes_size;
StartPushButton = findobj('tag', 'StartPushButton');
StartPushButton.Position = [0 (MainFigureAxesSize(2) - PushButtonHeigth) PushButtonWidth PushButtonHeigth];
StopPushButton = findobj('tag', 'StopPushButton');
StopPushButton.Position = [0 (MainFigureAxesSize(2) - PushButtonHeigth * 2) PushButtonWidth PushButtonHeigth];
LogoImage = findobj('tag', 'LogoImage');
// LogoImage.Position = [0 0 50 50];
// disp(LogoImage.Tag)
LogoImage.Position = [0 0 50 50];
// LogoImage.Position = [(MainFigureAxesSize(1) - 50) (MainFigureAxesSize(2) - 50) 50 50];
endfunction
FigureNumber = 1002;
MainFigure = figure(FigureNumber, 'menubar_visible', 'off',...
'menubar_visible', 'off',...
'toolbar', 'none',...// 'toolbar_visible', 'off',...
'infobar_visible', 'off',...
'dockable', 'off',...
'auto_resize', 'on',...
'figure_name', 'GUI',...
'tag', 'MainFigure',...
'backgroundcolor', [0.94 0.94 0.94]... // 'resizefcn', 'resizemainfigure'...
);
MainFigureAxesSize = MainFigure.axes_size;
LogoImage = uicontrol(MainFigure, 'style', 'image', 'string', get_absolute_file_path('ex002.sce') + 'logo02.png',...
'position', [0 0 50 50],...// 'position', [0 0 50 50],... (MainFigureAxesSize(1) - 50)
'tag', 'LogoImage' );
//myObj = findobj('tag','LogoImage');
//disp(myObj.Position)
PushButtonWidth = 60;
PushButtonHeigth = 25;
StartPushButton = uicontrol(MainFigure, 'Style','pushbutton',...
'callback_type', 10,...
'String', 'Start',...
'tag', 'StartPushButton',...
'Position', [0 MainFigureAxesSize(2)-PushButtonHeigth PushButtonWidth PushButtonHeigth]...
);
StopPushButton = uicontrol(MainFigure, 'Style','pushbutton',...
'callback_type', 10,...
'String', 'Stop',...
'tag', 'StopPushButton',...
'Position', [0 MainFigureAxesSize(2) - PushButtonHeigth * 2 PushButtonWidth PushButtonHeigth],...
'callback', 'closemainfigure'...
);
TopPlot = newaxes(MainFigure);
//TopPlot.margins = [0, 0, 0, 0]
TopPlot.axes_bounds = [0, 0, 1.0, 0.5];
t = 0:0.1:20;
plot(t,acosh(t),'r')
a2 = newaxes(MainFigure);
a2.axes_bounds = [0, 0.5, 1.0, 0.5];
x = 0:0.1:4;
plot(x,sinh(x))
legend('sinh')
MainFigure.resizefcn = 'resizemainfigure';
function closemainfigure()
MainFigure = findobj('tag','MainFigure');
close(MainFigure);
endfunction
function resizemainfigure()
MainFigure = findobj('tag', 'MainFigure');
MainFigureAxesSize = MainFigure.axes_size;
StartPushButton = findobj('tag', 'StartPushButton');
StartPushButton.Position = [0 (MainFigureAxesSize(2) - PushButtonHeigth) PushButtonWidth PushButtonHeigth];
StopPushButton = findobj('tag', 'StopPushButton');
StopPushButton.Position = [0 (MainFigureAxesSize(2) - PushButtonHeigth * 2) PushButtonWidth PushButtonHeigth];
// LogoImage = findobj('style', 'image');
LogoImage = findobj('tag', 'LogoImage');
// LogoImage.Position = [0 0 50 50];
// disp(LogoImage.Tag)
LogoImage.Position = [0 (0.01 * MainFigureAxesSize(2)) 50 50];
// LogoImage.Position = [(MainFigureAxesSize(1) - 50) (MainFigureAxesSize(2) - 50) 50 50];
endfunction
PushButtonWidth = 60;
PushButtonHeigth = 25;
FigureNumber = 1002;
MainFigure = figure(FigureNumber, 'menubar_visible', 'off',...
'menubar_visible', 'off',...
'toolbar', 'none',...// 'toolbar_visible', 'off',...
'infobar_visible', 'off',...
'dockable', 'off',...
'auto_resize', 'on',...
'figure_name', 'GUI',...
'tag', 'MainFigure',...
'backgroundcolor', [0.94 0.94 0.94],...
'resizefcn', 'resizemainfigure'...
);
MainFigureAxesSize = MainFigure.axes_size;
LogoImage = uicontrol(MainFigure, 'style', 'image', 'string', get_absolute_file_path('ex003.sce') + 'logo02.png',...
'position', [0 (0.01 * MainFigureAxesSize(2)) 50 50],...// 'position', [0 0 50 50],... (MainFigureAxesSize(1) - 50)
'tag', 'LogoImage' );
//myObj = findobj('tag','LogoImage');
//disp(myObj.Position)
StartPushButton = uicontrol(MainFigure, 'Style','pushbutton',...
'callback_type', 10,...
'String', 'Start',...
'tag', 'StartPushButton',...
'Position', [0 MainFigureAxesSize(2)-PushButtonHeigth PushButtonWidth PushButtonHeigth]...
);
StopPushButton = uicontrol(MainFigure, 'Style','pushbutton',...
'callback_type', 10,...
'String', 'Stop',...
'tag', 'StopPushButton',...
'Position', [0 MainFigureAxesSize(2) - PushButtonHeigth * 2 PushButtonWidth PushButtonHeigth],...
'callback', 'closemainfigure'...
);
TopPlot = newaxes(MainFigure);
//TopPlot.margins = [0, 0, 0, 0]
TopPlot.axes_bounds = [0, 0, 1.0, 0.5];
t = 0:0.1:20;
plot(t,acosh(t),'r')
a2 = newaxes(MainFigure);
a2.axes_bounds = [0, 0.5, 1.0, 0.5];
x = 0:0.1:4;
plot(x,sinh(x))
legend('sinh')
//MainFigure.resizefcn = 'resizemainfigure';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment