Python support in wxrc
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16502 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -62,12 +62,13 @@ private:
|
||||
void DeleteTempFiles(const wxArrayString& flist);
|
||||
void MakePackageZIP(const wxArrayString& flist);
|
||||
void MakePackageCPP(const wxArrayString& flist);
|
||||
void MakePackagePython(const wxArrayString& flist);
|
||||
|
||||
void OutputGettext();
|
||||
wxArrayString FindStrings();
|
||||
wxArrayString FindStrings(wxXmlNode *node);
|
||||
|
||||
bool flagVerbose, flagCPP, flagGettext;
|
||||
bool flagVerbose, flagCPP, flagPython, flagGettext;
|
||||
wxString parOutput, parFuncname, parOutputPath;
|
||||
wxArrayString parFiles;
|
||||
int retCode;
|
||||
@@ -87,8 +88,9 @@ int XmlResApp::OnRun()
|
||||
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
|
||||
{ wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" },
|
||||
{ wxCMD_LINE_SWITCH, "c", "cpp-code", "output C++ source rather than .rsc file" },
|
||||
{ wxCMD_LINE_SWITCH, "p", "python-code", "output wxPython source rather than .rsc file" },
|
||||
{ wxCMD_LINE_SWITCH, "g", "gettext", "output list of translatable strings (to stdout or file if -o used)" },
|
||||
{ wxCMD_LINE_OPTION, "n", "function", "C++ function name (with -c) [InitXmlResource]" },
|
||||
{ wxCMD_LINE_OPTION, "n", "function", "C++/Python function name (with -c or -p) [InitXmlResource]" },
|
||||
{ wxCMD_LINE_OPTION, "o", "output", "output file [resource.xrs/cpp]" },
|
||||
#if 0 // not yet implemented
|
||||
{ wxCMD_LINE_OPTION, "l", "list-of-handlers", "output list of neccessary handlers to this file" },
|
||||
@@ -140,13 +142,21 @@ void XmlResApp::ParseParams(const wxCmdLineParser& cmdline)
|
||||
flagGettext = cmdline.Found("g");
|
||||
flagVerbose = cmdline.Found("v");
|
||||
flagCPP = cmdline.Found("c");
|
||||
flagPython = cmdline.Found("p");
|
||||
|
||||
if (!cmdline.Found("o", &parOutput))
|
||||
{
|
||||
if (flagGettext)
|
||||
parOutput = wxEmptyString;
|
||||
else
|
||||
parOutput = flagCPP ? "resource.cpp" : "resource.xrs";
|
||||
{
|
||||
if (flagCPP)
|
||||
parOutput = "resource.cpp";
|
||||
else if (flagPython)
|
||||
parOutput = "resource.py";
|
||||
else
|
||||
parOutput = "resource.xrs";
|
||||
}
|
||||
}
|
||||
parOutputPath = wxPathOnly(parOutput);
|
||||
if (!parOutputPath) parOutputPath = ".";
|
||||
@@ -171,6 +181,8 @@ void XmlResApp::CompileRes()
|
||||
{
|
||||
if (flagCPP)
|
||||
MakePackageCPP(files);
|
||||
else if (flagPython)
|
||||
MakePackagePython(files);
|
||||
else
|
||||
MakePackageZIP(files);
|
||||
}
|
||||
@@ -360,6 +372,9 @@ void XmlResApp::MakePackageCPP(const wxArrayString& flist)
|
||||
wxPrintf("creating C++ source file " + parOutput + "...\n");
|
||||
|
||||
file.Write("\
|
||||
//\n\
|
||||
// This file was automatically generated by wxrc, do not edit by hand.\n\
|
||||
//\n\n\
|
||||
#include <wx/wxprec.h>\n\
|
||||
\n\
|
||||
#ifdef __BORLANDC__\n\
|
||||
@@ -413,6 +428,81 @@ void " + parFuncname + "()\n\
|
||||
|
||||
}
|
||||
|
||||
static wxString FileToPythonArray(wxString filename, int num)
|
||||
{
|
||||
wxString output;
|
||||
wxString tmp;
|
||||
wxString snum;
|
||||
wxFFile file(filename, "rb");
|
||||
size_t lng = file.Length();
|
||||
|
||||
snum.Printf("%i", num);
|
||||
output = " xml_res_file_" + snum + " = \"\"\"\\\n";
|
||||
|
||||
unsigned char *buffer = new unsigned char[lng];
|
||||
file.Read(buffer, lng);
|
||||
|
||||
for (size_t i = 0, linelng = 0; i < lng; i++)
|
||||
{
|
||||
unsigned char c = buffer[i];
|
||||
if (c == '\n')
|
||||
{
|
||||
tmp = (wxChar)c;
|
||||
linelng = 0;
|
||||
}
|
||||
else if (c < 32 || c > 127)
|
||||
tmp.Printf("\\x%02x", c);
|
||||
else if (c == '\\')
|
||||
tmp = "\\\\";
|
||||
else
|
||||
tmp = (wxChar)c;
|
||||
if (linelng > 70)
|
||||
{
|
||||
linelng = 0;
|
||||
output << "\\\n";
|
||||
}
|
||||
output << tmp;
|
||||
linelng += tmp.Length();
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
output += "\"\"\"\n\n";
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
void XmlResApp::MakePackagePython(const wxArrayString& flist)
|
||||
{
|
||||
wxFFile file(parOutput, "wt");
|
||||
size_t i;
|
||||
|
||||
if (flagVerbose)
|
||||
wxPrintf("creating Python source file " + parOutput + "...\n");
|
||||
|
||||
file.Write(
|
||||
"#\n"
|
||||
"# This file was automatically generated by wxrc, do not edit by hand.\n"
|
||||
"#\n\n"
|
||||
"from wxPython.wx import *\n"
|
||||
"from wxPython.xrc import *\n\n"
|
||||
);
|
||||
|
||||
|
||||
file.Write("def " + parFuncname + "():\n");
|
||||
|
||||
for (i = 0; i < flist.Count(); i++)
|
||||
file.Write(FileToPythonArray(flist[i], i));
|
||||
|
||||
for (i = 0; i < flist.Count(); i++)
|
||||
{
|
||||
wxString s;
|
||||
s.Printf(" wxXmlResource_Get().LoadFromString(xml_res_file_%i)\n", i);
|
||||
file.Write(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void XmlResApp::OutputGettext()
|
||||
|
@@ -62,12 +62,13 @@ private:
|
||||
void DeleteTempFiles(const wxArrayString& flist);
|
||||
void MakePackageZIP(const wxArrayString& flist);
|
||||
void MakePackageCPP(const wxArrayString& flist);
|
||||
void MakePackagePython(const wxArrayString& flist);
|
||||
|
||||
void OutputGettext();
|
||||
wxArrayString FindStrings();
|
||||
wxArrayString FindStrings(wxXmlNode *node);
|
||||
|
||||
bool flagVerbose, flagCPP, flagGettext;
|
||||
bool flagVerbose, flagCPP, flagPython, flagGettext;
|
||||
wxString parOutput, parFuncname, parOutputPath;
|
||||
wxArrayString parFiles;
|
||||
int retCode;
|
||||
@@ -87,8 +88,9 @@ int XmlResApp::OnRun()
|
||||
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
|
||||
{ wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" },
|
||||
{ wxCMD_LINE_SWITCH, "c", "cpp-code", "output C++ source rather than .rsc file" },
|
||||
{ wxCMD_LINE_SWITCH, "p", "python-code", "output wxPython source rather than .rsc file" },
|
||||
{ wxCMD_LINE_SWITCH, "g", "gettext", "output list of translatable strings (to stdout or file if -o used)" },
|
||||
{ wxCMD_LINE_OPTION, "n", "function", "C++ function name (with -c) [InitXmlResource]" },
|
||||
{ wxCMD_LINE_OPTION, "n", "function", "C++/Python function name (with -c or -p) [InitXmlResource]" },
|
||||
{ wxCMD_LINE_OPTION, "o", "output", "output file [resource.xrs/cpp]" },
|
||||
#if 0 // not yet implemented
|
||||
{ wxCMD_LINE_OPTION, "l", "list-of-handlers", "output list of neccessary handlers to this file" },
|
||||
@@ -140,13 +142,21 @@ void XmlResApp::ParseParams(const wxCmdLineParser& cmdline)
|
||||
flagGettext = cmdline.Found("g");
|
||||
flagVerbose = cmdline.Found("v");
|
||||
flagCPP = cmdline.Found("c");
|
||||
flagPython = cmdline.Found("p");
|
||||
|
||||
if (!cmdline.Found("o", &parOutput))
|
||||
{
|
||||
if (flagGettext)
|
||||
parOutput = wxEmptyString;
|
||||
else
|
||||
parOutput = flagCPP ? "resource.cpp" : "resource.xrs";
|
||||
{
|
||||
if (flagCPP)
|
||||
parOutput = "resource.cpp";
|
||||
else if (flagPython)
|
||||
parOutput = "resource.py";
|
||||
else
|
||||
parOutput = "resource.xrs";
|
||||
}
|
||||
}
|
||||
parOutputPath = wxPathOnly(parOutput);
|
||||
if (!parOutputPath) parOutputPath = ".";
|
||||
@@ -171,6 +181,8 @@ void XmlResApp::CompileRes()
|
||||
{
|
||||
if (flagCPP)
|
||||
MakePackageCPP(files);
|
||||
else if (flagPython)
|
||||
MakePackagePython(files);
|
||||
else
|
||||
MakePackageZIP(files);
|
||||
}
|
||||
@@ -360,6 +372,9 @@ void XmlResApp::MakePackageCPP(const wxArrayString& flist)
|
||||
wxPrintf("creating C++ source file " + parOutput + "...\n");
|
||||
|
||||
file.Write("\
|
||||
//\n\
|
||||
// This file was automatically generated by wxrc, do not edit by hand.\n\
|
||||
//\n\n\
|
||||
#include <wx/wxprec.h>\n\
|
||||
\n\
|
||||
#ifdef __BORLANDC__\n\
|
||||
@@ -413,6 +428,81 @@ void " + parFuncname + "()\n\
|
||||
|
||||
}
|
||||
|
||||
static wxString FileToPythonArray(wxString filename, int num)
|
||||
{
|
||||
wxString output;
|
||||
wxString tmp;
|
||||
wxString snum;
|
||||
wxFFile file(filename, "rb");
|
||||
size_t lng = file.Length();
|
||||
|
||||
snum.Printf("%i", num);
|
||||
output = " xml_res_file_" + snum + " = \"\"\"\\\n";
|
||||
|
||||
unsigned char *buffer = new unsigned char[lng];
|
||||
file.Read(buffer, lng);
|
||||
|
||||
for (size_t i = 0, linelng = 0; i < lng; i++)
|
||||
{
|
||||
unsigned char c = buffer[i];
|
||||
if (c == '\n')
|
||||
{
|
||||
tmp = (wxChar)c;
|
||||
linelng = 0;
|
||||
}
|
||||
else if (c < 32 || c > 127)
|
||||
tmp.Printf("\\x%02x", c);
|
||||
else if (c == '\\')
|
||||
tmp = "\\\\";
|
||||
else
|
||||
tmp = (wxChar)c;
|
||||
if (linelng > 70)
|
||||
{
|
||||
linelng = 0;
|
||||
output << "\\\n";
|
||||
}
|
||||
output << tmp;
|
||||
linelng += tmp.Length();
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
output += "\"\"\"\n\n";
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
void XmlResApp::MakePackagePython(const wxArrayString& flist)
|
||||
{
|
||||
wxFFile file(parOutput, "wt");
|
||||
size_t i;
|
||||
|
||||
if (flagVerbose)
|
||||
wxPrintf("creating Python source file " + parOutput + "...\n");
|
||||
|
||||
file.Write(
|
||||
"#\n"
|
||||
"# This file was automatically generated by wxrc, do not edit by hand.\n"
|
||||
"#\n\n"
|
||||
"from wxPython.wx import *\n"
|
||||
"from wxPython.xrc import *\n\n"
|
||||
);
|
||||
|
||||
|
||||
file.Write("def " + parFuncname + "():\n");
|
||||
|
||||
for (i = 0; i < flist.Count(); i++)
|
||||
file.Write(FileToPythonArray(flist[i], i));
|
||||
|
||||
for (i = 0; i < flist.Count(); i++)
|
||||
{
|
||||
wxString s;
|
||||
s.Printf(" wxXmlResource_Get().LoadFromString(xml_res_file_%i)\n", i);
|
||||
file.Write(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void XmlResApp::OutputGettext()
|
||||
|
Reference in New Issue
Block a user