[Scilab-users] Exporting figures containing uicontrols to any format
amonmayr at laas.fr
amonmayr at laas.fr
Tue Nov 8 12:40:33 CET 2016
Hi all,
Just in case it can help someone else, here is the code I hacked this
morning to get a proper export menu on my figures.
It really is a hack and should probably work only on my machine (linux
64 bits, X window, ImageMagick) and with my current figure layout:
//////////////////////////////////////////////////////////
// New menu
h = uimenu(demo_fp, ...
"label" , gettext("File"));
// Export entry
uimenu(h, ...
"label" , gettext("Export Figure (Hack)"), ...
"callback" , "exportHack();", ...
"tag" , "export_menu");
function exportHack()
// Export figure with uicontrols to png using X server & import
(imagemagick)
// Horrible hack the should only work on my machine (linux 64bits.
// get around bug http://bugzilla.scilab.org/show_bug.cgi?id=14836
https://bugzilla.scilab.org/show_bug.cgi?id=14502
h=gcbo;
//current figure name
figname=h.parent.parent.figure_name;
//getting X server id for current window
ret=unix_g("xwininfo -int -name " +""""+figname+"""");
//hackish, depends directly on the syntax of xwininfo outputs
tok=tokens(ret(2),':');
tok=tokens(tok(3)," ")
winid=tok(1);//X server windows id, as a string
// File save dialog parameters
file_mask=["*.png"];
boxTitle="Export";
//If previous filename is present, use it to start the dialog in the
corresponding directory
if h.userdata~="" then
dir=h.userdata;
else
dir=pwd();
end
dir
PathFileName=uiputfile(file_mask,dir,boxTitle);
// LD_LIBRARY_PATH required to get around bug:
http://bugzilla.scilab.org/show_bug.cgi?id=14143
unix_s("LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH ;
import -window "+winid +" "+PathFileName)
// keep savec filename for future reference.
h.userdata=PathFileName;
endfunction
//////////////////////////////////////////////////////////
Hope it helps,
Antoine
Le 04/11/2016 à 23:46, Philipp Mühlmann a écrit :
> pittywise driver() does also not brings the solution
>
> interstingly playing with usecanvas() made it possible to only show
> pushbuttons in a figure.
>
> e.g.:
> usecanvas(%T);
> f=figure();
> plot2d();
> h=uicontrol(f,'unit','normalized',"style","pushbutton","string","pushbutton", 'Position',[0.1, 0.7, 0.2, 0.1]);
> h=uicontrol(f,'unit','normalized',"style","frame","string","frame", 'Position',[0.1, 0.5, 0.2, 0.1]);
>
> but expoting this figure as a image file resulted in having the know
> style.
> no pushbuttons rendered, only the figure of plot2d().....(also not the
> frame)
>
>
>
>
> 2016-11-04 1:50 GMT+01:00 Philipp Mühlmann <p.muehlmann at gmail.com
> <mailto:p.muehlmann at gmail.com>>:
>
> it seems that:
>
> exportUI() only recognizes figure handles (and axes) for the export.
>
> since pushbuttons etc. are not figure handles they are not exported?
>
>
> e.g.: handles.mypushbotton.style = "pushbutton"
>
> ...should be maybe "figure", "frame" or "axes" to be recognized by
> exportUI().
>
> Seems to be the same with "printfigure()"
>
>
>
>
> sidequestion:
>
> Is it possible to export content of a xml-file to an figure/image?
>
> If so one could maybe use:
>
> saveGui(gcf(), 'screenshot.xml');
>
> and than convert the content of the xml file into an image?
>
>
>
>
>
>
>
>
>
> 2016-11-03 23:08 GMT+01:00 Philipp Mühlmann <p.muehlmann at gmail.com
> <mailto:p.muehlmann at gmail.com>>:
>
> Dear all,
>
> searching a little how GUI's can be "screenshotted" in Matlab
> gave me following:
>
> Request on a Matlab forum, see:
>
> https://de.mathworks.com/matlabcentral/newsreader/view_thread/146264
> <https://de.mathworks.com/matlabcentral/newsreader/view_thread/146264>
>
> [...] " In order to show users without atlab on their desktop
> the output, i want to create a export function."
>
> This could be the reason for having the oppertunity of
> screenshotting a GUI.
>
> Anyways:
>
> to me it seems that following is needed to do the trick:
>
> [name,path,index] = uiputfile
> saveas(guifigurehandle,[path name]);
>
> while "saveas" calls "print"
> see "ocatave" code:
> https://fossies.org/dox/octave-4.0.3/saveas_8m_source.html
> <https://fossies.org/dox/octave-4.0.3/saveas_8m_source.html>
>
> The print.m code is than way beyond my code understanding.
> see "ocatave" code:
> https://fossies.org/dox/octave-4.0.3/print_8m_source.html
> <https://fossies.org/dox/octave-4.0.3/print_8m_source.html>
>
>
> best regards,
> Phil
>
>
>
>
>
>
> 2016-11-02 23:07 GMT+01:00 Rafael Guerra
> <jrafaelbguerra at hotmail.com <mailto:jrafaelbguerra at hotmail.com>>:
>
> Hi Antoine,
>
> I do not have an answer but a question, if you will.
> Why is it important for you to export the whole shebang
> from Scilab?
>
> For the regular figures the export functions work fine and
> generate high-resolution post-script files.
> For the GUI figures, using external screen capture
> software does not seem to me to be a big handicap, but I
> might be wrong and I therefore raise the question.
>
> Thanks and regards,
> Rafael
>
>
> -----Original Message-----
> From: users [mailto:users-bounces at lists.scilab.org
> <mailto:users-bounces at lists.scilab.org>] On Behalf Of
> Antoine Monmayrant
> Sent: Tuesday, November 01, 2016 9:41 PM
> To: Users mailing list for Scilab <users at lists.scilab.org
> <mailto:users at lists.scilab.org>>
> Subject: [Scilab-users] Exporting figures containing
> uicontrols to any format
>
> Hi everyone,
>
> After a long fight to build fancy graphics with uicontrols
> to demo some physics, I am now stuck because of bug 14502
> ( https://bugzilla.scilab.org/show_bug.cgi?id=14502
> <https://bugzilla.scilab.org/show_bug.cgi?id=14502> ).
> Basically, I have no way to export my figure to any format
> (ie no exportUI(gcf()) and no xs2something).
> As any of you ever managed to export a figure with
> uicontrols where both the plots and the uicontrols are
> well rendered?
>
> Antoine
>
> PS: for a bit of context, try the following:
>
> 1) Demos->GUI->Uicontrols 2 //(or any with uicontrols)
> 2) h=gcf();xs2svg(h, 'h.svg'); // or any other format
> 3) open h.svg, it's empty
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org <mailto:users at lists.scilab.org>
> http://lists.scilab.org/mailman/listinfo/users
> <http://lists.scilab.org/mailman/listinfo/users>
> _______________________________________________
> users mailing list
> users at lists.scilab.org <mailto:users at lists.scilab.org>
> http://lists.scilab.org/mailman/listinfo/users
> <http://lists.scilab.org/mailman/listinfo/users>
>
>
>
>
> --
> In Kanada is' ka' na' da. Sonst wär' Kanada Jemanda.
>
> There we have the salad.
>
>
>
>
> --
> In Kanada is' ka' na' da. Sonst wär' Kanada Jemanda.
>
> There we have the salad.
>
>
>
>
> --
> In Kanada is' ka' na' da. Sonst wär' Kanada Jemanda.
>
> There we have the salad.
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
--
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Antoine Monmayrant LAAS - CNRS
7 avenue du Colonel Roche
BP 54200
31031 TOULOUSE Cedex 4
FRANCE
Tel:+33 5 61 33 64 59
email : antoine.monmayrant at laas.fr
permanent email : antoine.monmayrant at polytechnique.org
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161108/1f6cb98a/attachment.htm>
More information about the users
mailing list