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;
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" },
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 = ".";
{
if (flagCPP)
MakePackageCPP(files);
+ else if (flagPython)
+ MakePackagePython(files);
else
MakePackageZIP(files);
}
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\
}
+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()
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;
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" },
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 = ".";
{
if (flagCPP)
MakePackageCPP(files);
+ else if (flagPython)
+ MakePackagePython(files);
else
MakePackageZIP(files);
}
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\
}
+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()