m2sci_gui now uses Scilab uicontrols instead of a TK user interface
[scilab.git] / scilab / modules / m2sci / macros / m2sci_gui.sci
index 60383c0..2c09290 100644 (file)
+//
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2002-2004 - INRIA - Vincent COUVERT 
+// Copyright (C) 2002-2008 - INRIA - Vincent COUVERT 
 // 
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
 // you should have received as part of this distribution.  The terms
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//
+
+function m2sci_gui()
+
+// Sizes
+widgeth = 20;
+btnh = 22;
+btnw = 80;
+defaultfont = "arial";
+margin = 13;
+figw = 500;
+figh = 17*margin + btnh + 7*widgeth + 70; // 70 = size of the status bar and the menu bar
+
+// Figure creation
+m2scifig = figure("position", [0 0 figw figh], "figure_name", gettext("Matlab to Scilab conversion tool"));
+
+// Remove Scilab graphics menus & toolbar
+delmenu(m2scifig.figure_id, gettext("File"));
+delmenu(m2scifig.figure_id, gettext("Tools"));
+delmenu(m2scifig.figure_id, gettext("Edit"));
+delmenu(m2scifig.figure_id, gettext("?"));
+toolbar(m2scifig.figure_id, "off");
+
+//-------------------
+// --- Validation ---
+//-------------------
+
+// Convert button
+convertbtn = uicontrol("parent", m2scifig,...
+    "backgroundcolor", [0.8 0.8 0.8],...
+    "style", "pushbutton",...
+    "string", gettext("Convert"),...
+    "position", [figw-margin-btnw margin btnw btnh],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "tag","convertbtn",...
+    "callback","cb_m2sci_gui");
+
+// Cancel button
+cancelbtn = uicontrol("parent", m2scifig,...
+    "backgroundcolor", [0.8 0.8 0.8],...
+    "style", "pushbutton",...
+    "string", gettext("Cancel"),...
+    "position",[figw-2*margin-2*btnw margin btnw btnh],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "tag", "cancelbtn",...
+    "callback","cb_m2sci_gui");
+
+//----------------
+// --- Options ---
+//----------------
+// Frame
+optframe = uicontrol("parent", m2scifig,...
+    "relief", "groove",...
+    "style", "frame",...
+    "units", "pixels",...
+    "position", [margin 2*margin+btnh figw-2*margin 5*margin+4*widgeth],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "fontweight", "bold", ...
+    "horizontalalignment", "center");
+// Frame title
+opttitle = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Options"),...
+    "units", "pixels",...
+    "position", [2*margin 2*margin+btnh+4*margin+4*widgeth-3 50 14],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 9,...
+    "horizontalalignment", "center");
+
+// --- Pretty print option ---
+pplabel = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Generate pretty printed code: "),...
+    "position",[2*margin 2*margin+btnh+margin 180 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10);
+ppradioyes = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("Yes"),...
+    "position",[2*margin+180 2*margin+btnh+margin 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 0,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "ppradioyes"); 
+ppradiono = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("No"),...
+    "position",[2*margin+240 2*margin+btnh+margin 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 1,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "ppradiono"); 
+
+// --- Verbose option ---
+verby = 2*margin+btnh+margin+widgeth+margin;
+verblabel = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Verbose mode: "),...
+    "position",[2*margin verby 180 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10); 
+verbradio0 = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("0"),...
+    "position",[2*margin+180 verby 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 0,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "verbradio0"); 
+verbradio1 = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("1"),...
+    "position",[2*margin+180+60 verby 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 0,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "verbradio1"); 
+verbradio2 = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("2"),...
+    "position",[2*margin+180+60+60 verby 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 0,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "verbradio2"); 
+verbradio3 = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("3"),...
+    "position",[2*margin+180+60+60+60 verby 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 1,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "verbradio3"); 
+
+// --- Only doubles option ---
+douby = verby + margin + widgeth;
+doublabel = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Only double values used: "),...
+    "position",[2*margin douby 180 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10); 
+doubradioyes = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("Yes"),...
+    "position",[2*margin+180 douby 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 0,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "doubradioyes"); 
+doubradiono = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("No"),...
+    "position",[2*margin+240 douby 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 1,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "doubradiono"); 
+
+// --- Recursive mode option ---
+recy = douby + margin + widgeth;
+reclabel = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Recursive conversion: "),...
+    "position",[2*margin recy 180 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10); 
+recradioyes = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("Yes"),...
+    "position",[2*margin+180 recy 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 0,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "recradioyes"); 
+recradiono = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("No"),...
+    "position",[2*margin+240 recy 60 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 1,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "recradiono"); 
+
+// ------------------------
+// --- Output directory ---
+// ------------------------
+// Frame
+optframemaxy = 2*margin+btnh + 5*margin+4*widgeth;
+outframe = uicontrol("parent", m2scifig,...
+    "relief", "groove",...
+    "style", "frame",...
+    "units", "pixels",...
+    "position", [margin optframemaxy+margin figw-2*margin widgeth+2*margin],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 13,...
+    "fontweight", "bold", ...
+    "horizontalalignment", "center");
+// Frame title
+outtitle = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Output directory"),...
+    "units", "pixels",...
+    "position", [2*margin optframemaxy+margin+widgeth+margin-3 90 14],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 9,...
+    "horizontalalignment", "center");
+outlabel = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Directory name: "),...
+    "position",[2*margin optframemaxy+2*margin-1 100 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10);
+outedit = uicontrol("parent", m2scifig,...
+    "style", "edit",...
+    "string", getcwd(),...
+    "units", "points",...
+    "position",[3*margin+100 optframemaxy+2*margin-1 figw-6*margin-100-btnw widgeth],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10, ...
+    "tag", "outedit");
+outbtn = uicontrol("parent", m2scifig,...
+    "backgroundcolor", [0.8 0.8 0.8],...
+    "style", "pushbutton",...
+    "string", gettext("Browse"),...
+    "position",[figw-2*margin-btnw optframemaxy+2*margin btnw btnh],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "outbtn");
+
+// --------------------------------
+// --- File/Directory selection ---
+// --------------------------------
+// Frame
+outframemaxy = optframemaxy + 2*margin + widgeth + margin;
+selframe = uicontrol("parent", m2scifig,...
+    "relief", "groove",...
+    "style", "frame",...
+    "units", "pixels",...
+    "position", [margin outframemaxy+margin figw-2*margin 2*margin+widgeth],...
+    "fontname", "arial",...
+    "fontunits", "points",...
+    "fontsize", 13,...
+    "fontweight", "bold", ...
+    "horizontalalignment", "center");
+// Frame title
+dirtitle = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Input directory"),...
+    "units", "pixels",...
+    "position", [2*margin outframemaxy+margin+margin+widgeth-3 85 14],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 9,...
+    "horizontalalignment", "center", ...
+    "tag", "dirtitle",...
+    "visible", "off");
+filetitle = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Input file"),...
+    "units", "pixels",...
+    "position", [2*margin outframemaxy+margin+margin+widgeth-3 50 14],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 9,...
+    "horizontalalignment", "center", ...
+    "tag", "filetitle");
+
+// --- Directory selection ---
+dirlabel = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Directory name: "),...
+    "position",[2*margin outframemaxy+2*margin-1 100 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "visible", "off",...
+    "tag", "dirlabel");
+diredit = uicontrol("parent", m2scifig,...
+    "style", "edit",...
+    "string", getcwd(),...
+    "position",[3*margin+100 outframemaxy+2*margin-1 figw-6*margin-100-btnw widgeth],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "tag", "diredit",...
+    "visible", "off",...
+    "tag", "diredit");
+dirbtn = uicontrol("parent", m2scifig,...
+    "backgroundcolor", [0.8 0.8 0.8],...
+    "style", "pushbutton",...
+    "string", gettext("Browse"),...
+    "position",[figw-2*margin-btnw outframemaxy+2*margin btnw btnh],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "visible", "off",...
+    "callback", "cb_m2sci_gui",...
+    "tag", "dirbtn");
+
+// --- File\0 selection ---
+filelabel = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("File name: "),...
+    "position",[2*margin outframemaxy+2*margin-1 100 widgeth],...
+    "horizontalalignment", "left",...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "tag", "filelabel");
+
+fileedit = uicontrol("parent", m2scifig,...
+    "style", "edit",...
+    "string", gettext("<enter a file name>"),...
+    "position",[3*margin+100 outframemaxy+2*margin-1 figw-6*margin-100-btnw widgeth],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "tag", "fileedit");
+
+filebtn = uicontrol("parent", m2scifig,...
+    "backgroundcolor", [0.8 0.8 0.8],...
+    "style", "pushbutton",...
+    "string", gettext("Browse"),...
+    "position",[figw-2*margin-btnw outframemaxy+2*margin btnw btnh],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10,...
+    "callback", "cb_m2sci_gui",...
+    "tag", "filebtn");
+
+// ------------
+// --- Mode ---
+// ------------
+// Frame
+selframemaxy = outframemaxy + 2*margin + widgeth + margin;
+modeframe = uicontrol("parent", m2scifig,...
+    "relief", "groove",...
+    "style", "frame",...
+    "units", "pixels",...
+    "position", [margin selframemaxy+margin figw-2*margin 2*margin+widgeth],...
+    "fontname", "arial",...
+    "fontunits", "points",...
+    "fontsize", 13,...
+    "fontweight", "bold", ...
+    "horizontalalignment", "center");
+// Frame title
+modetitle = uicontrol("parent", m2scifig,...
+    "style", "text",...
+    "string", gettext("Conversion mode"),...
+    "units", "pixels",...
+    "position", [2*margin selframemaxy+margin+margin+widgeth-3 100 14],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 9,...
+    "horizontalalignment", "center", ...
+    "tag", "seltitle");
+
+fileradio = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("Convert a single file"),...
+    "position",[2*margin selframemaxy+2*margin (figw-5*margin)/2 widgeth],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10, ...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 1,...
+    "tag", "fileradio", ...
+    "callback", "cb_m2sci_gui");
+
+dirradio = uicontrol("parent", m2scifig,...
+    "style", "radiobutton",...
+    "string", gettext("Convert a whole directory"),...
+    "position",[3*margin+(figw-5*margin)/2 selframemaxy+2*margin (figw-5*margin)/2 widgeth],...
+    "fontname", defaultfont,...
+    "fontunits", "points",...
+    "fontsize", 10, ...
+    "min", 0, ...
+    "max", 1, ...
+    "value", 0,...
+    "tag", "dirradio", ...
+    "callback", "cb_m2sci_gui");
 
-function res=m2sci_gui()
-// Call m2sci.tcl to get file or path to convert using M2SCI and user defined options
-
-if ~with_tk() then
-  error(gettext("Tcl/Tk interface not defined."));
-end
-
-// Default Options and Values
-TCL_SetVar("ePathToConvert",getcwd());
-TCL_SetVar("eFileToConvert",gettext("<enter a file name>"));
-TCL_SetVar("eResDirName",getcwd());
-TCL_SetVar("rRecMode",gettext("NO"));
-TCL_SetVar("rOnlyDouble",gettext("NO"));
-TCL_SetVar("rVerbMode","3");
-TCL_SetVar("rPrettyPrint",gettext("NO"));
-TCL_SetVar("rFlagWhatToConvert","0");
-TCL_SetVar("rToDo","0");
-TCL_SetVar("rWindowKilled","0");
-
-TCL_EvalFile(SCI+"/modules/m2sci/tcl/m2sci.tcl");
-
-rWindowKilled=TCL_GetVar("rWindowKilled");
-rToDo=TCL_GetVar("rToDo");
-while rToDo=="0" & rWindowKilled=="0"
-  rWindowKilled=TCL_GetVar("rWindowKilled");
-  rToDo=TCL_GetVar("rToDo");
-  sleep(1);
-end
-
-if rToDo=="1" then
-  DirName=TCL_GetVar("ePathToConvert");
-  FileName=TCL_GetVar("eFileToConvert");
-  ResDirName=TCL_GetVar("eResDirName");
-  RecMode=TCL_GetVar("rRecMode");
-  OnlyDouble=TCL_GetVar("rOnlyDouble");
-  VerbMode=TCL_GetVar("rVerbMode");
-  PrettyPrint=TCL_GetVar("rPrettyPrint");
-  FlagWhatToConvert=TCL_GetVar("rFlagWhatToConvert");
-  
-  // Modify Tcl/Tk values
-  if RecMode==gettext("YES") then
-    RecMode=%T
-  else  
-    RecMode=%F
-  end    
-  if OnlyDouble==gettext("YES") then
-    OnlyDouble=%T
-  else
-    OnlyDouble=%F
-  end    
-  if PrettyPrint==gettext("YES") then
-    PrettyPrint=%T
-  else
-    PrettyPrint=%F
-  end    
-  VerbMode=evstr(VerbMode);
-  
-  if FlagWhatToConvert=="0" then // Convert a whole directory
-    translatepaths(DirName,ResDirName);
-    res=0
-  else
-    res=mfile2sci(FileName,ResDirName,RecMode,OnlyDouble,VerbMode,PrettyPrint);
-  end
-elseif rToDo=="-1" then
-  // Cancel button
-  res=0
-else
-  // Window killed
-  res=0
-end
 endfunction