ANN: GUI2Exe for wxPython :-D

Hi All,

    I am happy to announce the birth of GUI2Exe, that is (my) first
attemp to unify all the available "executable builders" for Python in
a single and simple to use graphical user interface. At the moment
only py2exe is supported (is the only one I ever used), but it
shouldn't be hard to extend it.

What is it?

···

----------------

The aim of GUI2Exe was (for me) to create a wxPython GUI tool that
unifies and simplifies various standalone executable builders for
Python, such as py2exe, py2app, cx_Freeze, etc. It may look like the
Holy Grail, but this is at least a small step toward the Great Theory
of Unification.

How it works?
--------------------

GUI2Exe is implemented as follows:

- It uses the bsddb module to store all the projects you have compiled
with GUI2Exe in a database, so you can always retrieve what you did in
the past. The project names are displayed in a wxPython tree control;

- The central window shows the options available to the user for a
particular executable builder (only py2exe at the moment). This
windows contains a set of widgets, the usage of most of them is very
simple. However, for the following py2exe options:

a) Includes;
b) Packages;
c) Excludes;
d) Dll Excludes;
e) Ignores;
f) Data Files;
g) Icon Resources, Bitmap Resources and Other Resources;

you will see a list control: if you want to add an item to these lists
(i.e., add an Includes module, or a Dll Excludes Windows dll), simply
click on the list and hit Ctrl+A. All the lists (except the Data Files
one) will add an item and allow you to edit it to insert the module
you wish. The Data File list will open a file dialog that allows you
to choose a bunch of data files you want to include in one shot;

- GUI2Exe starts the py2exe compilation as an external process
(calling Python -u and using wx.Process/wx.Execute) and it monitors
the output and error streams of this process;

- The bottom window is a log window, that shows messages, warnings,
errors and it contains 3 buttons: Dry-Run, Compile and Kill. The
Dry-Run button will call py2exe but no real compilation will take
place. The Compile button will actually build your executable, and the
Kill button will attempt to kill a running py2exe building process.
There are few caveats about the Dry-Run and Kill buttons, see below.

Features
-------------

GUI2Exe has a number of features, namely:

- Saves and store your work in a database, displaying all your
projects in a tree control. To load an existing projects, simply
double click on it;

- Possibility to export the Setup.py file (menu File => Export setup
file...), even though you shouldn't ever need anymore to have a
Setup.py file. Everything is done automagically inside GUI2Exe;

- Allows the user to insert custom Python code in the "in-memory"
Setup.py file, which will be properly included at runtime during the
building process (menu Options => Add custom code...);

- Ability to test the executable: if the executable crashes (for
whatever reason), GUI2Exe will notice it and report to you the
traceback for inspection (menu Options => Test executable);

- After a building process, choosing the menu View => Missing modules
or View => Binary dependencies, you will be presented respectively
with a list of modules py2exe thinks are missing or a list of binary
dependencies (dll) py2exe has found;

- I built also a page that tries to explain all the py2exe
switches/options available, and how they mix with GUI2Exe. You can see
it by choosing the menu View => Compiler switches;

- As all of my GUIs, GUI2Exe is based on wxAUI for the interface
design. You can save and load "perspectives" (i.e., interface
appearances);

- The GUI2Exe "user guide" is still a work in progress: the
documentation at the moment includes the epydoc-generated API for
GUI2Exe. The code is quite well commented, but there is no user guide
for GUI2Exe. See below for a couple of examples.

Caveats
------------

There are few caveats about py2exe and wxPython that I wasn't able to
solve till now.

py2exe

Assuming that the following events happen simultaneously:

-You never built the executable for your main script, so the file
YourScript.exe doesn't exist;
-You choose the Dry-Run option.

py2exe will crash with a system error saying that the file py2exe is
looking for (YourScript.exe) can not be found. Yes, I knew that, it's
a *Dry-Run*, so py2exe shouldn't look for any executable file.
However, if you apply the attached patch to
/site-packages/py2exe/build_exe.py, the problem should be fixed.

wxPython

It looks like it is impossible to kill the py2exe process once it
started. I tried with wx.Process.Kill(process_Id, wx.SIGTERM), but no
way. Trying with wx.Process.Kill(process_Id, wx.SIGKILL) cause Python
to crash with the classical Windows error dialog. Moreover, if the
process ends normally, calling wx.Process.Destroy() will crash Python
as above.

bsddb

Every time you restart the application, bsddb gives you back the
projects stored in the database sorted *by project name*. I was
convinced that it should have ordered them based on *when* they were
added, but this is easy to fix.

Interface

On the 2 Windows machines I tried GUI2Exe, the interface looked
reasonably good. I can not test it on my Ubuntu Virtual Machine
because, after the upgrade to Edgy 6.10, everything stopped working. I
can't obviously test it on Mac. I don't know if the GUI will even
start on GTK or Mac, but if someone manages to run it, please send me
a screenshot of it

Examples
---------------

Hereafter I show a couple of examples on how to use GUI2Exe.

Simple one

We will build the sample file that comes with py2exe, on:

/site-packages/py2exe/sample/singlefile/gui/test_wx.py

1) With the GUI opened, hit Ctrl+N or choose File => New project...
2) Enter a name for the new project, i.e. "pyexe sample file"
3) In the central window that appears, under Python Main Script,
browse to search for the aforementioned file;
4) On the Optimize, Compressed and Bundle Files drop down choices,
choose 2, 2, 1 respectively;
5) Scroll down the central window to the bottom and check the XP
Manifest File option;
6) Click on the Compile button.

And you're done. You can follow the compilation steps in the bottom
log window as py2exe builds your executable.

Less simpler one

We will build the wxPython demo as executable.

1) With the GUI opened, hit Ctrl+N or choose File => New project...
2) Enter a name for the new project, i.e. "wxPython demo"
3) In the central window that appears, under Python Main Script,
browse to search for the file /YourPathToTheDemo/demo/Main.py;
4) On the Optimize, Compressed and Bundle Files drop down choices,
choose 2, 2, 1 respectively;
5) On the Packages list, hit Ctrl+A twice and edit the items to be wx
and wx.lib respectively;
6) On the Data Files list, hit Ctrl+A, browse with the file dialog to
/YourPathToTheDemo/demo/bitmaps and select all the files. Do the same
thing for the folders bmp_source and data.
7) Scroll down the central window to the bottom and check the XP
Manifest File option;
8) Click on the Compile button.

And you're done. You can follow the compilation steps in the bottom
log window as py2exe builds your executable.

Source code (for those who use wxPython and py2exe, 400 KB) and a
Windows installer (for those who wants to try iit without having
wxPython, 7.1 MB) are available in the usual place:

http://xoomer.alice.it/infinity77/eng/freeware.html#gui2exe

Comments, suggestions, criticisms about the implementation, the
interface, the easiness (or uneasiness) of use and on the usefulness
(or uselessness) of this package are as always extremely welcome.

wxPython rules :smiley:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

As a beginner with currently nothing worthy of being made executable (someday…) I guess I don’t have the knowledge to state this with any authority, but…this looks awesome! Thank you!
-Che

Many thanks Andrea :slight_smile:

I can’t make it run… :stuck_out_tongue:

The windows binary gives:

Traceback (most recent call last):
File “wx_misc.pyo”, line 1341, in Notify
File “wx_core.pyo”, line 14189, in Notify
File “GUI2Exe.py”, line 1183, in ShowMain
File "
GUI2Exe.py", line 106, in init
File “DataBase.pyo”, line 31, in init
File “bsddb_init_.pyo”, line 323, in btopen
bsddb.db.DBNoSuchFileError: (2, ‘No such file or directory’)

Running from source gave me an error saying setuptools is missing (I saw the comment on the source code. Why would anyone have py2app installed on windows?),

so I installed setuptools anyway and I got this error:

Traceback (most recent call last):
File “C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx_misc.py”, line 1341
, in Notify
self.notify()
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx_core.py
", line 1418
9, in Notify
self.result = self.callable(*self.args, **self.kwargs)
File “C:\Download\GUI2Exe_source\GUI2Exe.py”, line 1183, in ShowMain
frame = GUI2Exe(None, -1, “”, size=(xvideo, yvideo))

File “C:\Download\GUI2Exe_source\GUI2Exe.py”, line 106, in init
self.dataBase = DataBase(self, dbName)
File “C:\Download\GUI2Exe_source\DataBase.py”, line 31, in init
self.db
= bsddb.btopen(dbName, “c”)
File “C:\Python25\lib\bsddb_init_.py”, line 323, in btopen
d.open(file, db.DB_BTREE, flags, mode)
UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 26-29: ord

inal not in range(128)

My default system encoding is hebrew, must be something in bsddb’s unicode support.

···

On 4/1/07, C M cmpython@gmail.com wrote:

As a beginner with currently nothing worthy of being made executable (someday…) I guess I don’t have the knowledge to state this with any authority, but…this looks awesome! Thank you!
-Che

Hi Roee,

The windows binary gives:
Traceback (most recent call last):
  File "wx\_misc.pyo", line 1341, in Notify
  File "wx\_core.pyo", line 14189, in Notify
  File "GUI2Exe.py", line 1183, in ShowMain
  File " GUI2Exe.py", line 106, in __init__
  File "DataBase.pyo", line 31, in __init__
  File "bsddb\__init__.pyo", line 323, in btopen
bsddb.db.DBNoSuchFileError: (2, 'No such file or directory')

It looks like on PCs other than the 2 I tried Python doesn'like these
lines of code:

    def CheckForDatabase(self):
        """ Checks if a database exists. If it doesn't, creates one anew. """

        # We build the database inside the user config folder, where we
        # also create a sub-directory called /.GUI2Exe
        standardPath = wx.StandardPaths.Get()
        configDir = opj(standardPath.GetUserConfigDir() + "/.GUI2Exe")
        configDb = opj(configDir + "/GUI2Exe_Database.db")

        if not os.path.isfile(configDb):
            # No database
            if not os.path.isdir(configDir):
                # And no directory. Create a new one.
                os.mkdir(configDir)

        return configDb

So, it doesn't create the directory and bsddb is right in
complaining... I don't really know why, I was just trying to create a
directory called /.GUI2Exe under the user configuration directory
which for me is:

C:\Documents and Settings\Andrea\Dati applicazioni

Curiously enough, it works well here :frowning: :frowning:

BTW, I noticed I forgot to include the manifest file for Windows
(!!!!!), so the executable didn't look that much XP-style :frowning: . I
re-uploaded another version right now. However, I still don't know the
reason why the program can't create that particular directory. Maybe
someone more knowledgeable than me can explain it.

Running from source gave me an error saying setuptools is missing (I saw the
comment on the source code. Why would anyone have py2app installed on
windows?),

I tried to install il to see if could be acutally __import__ed,
because, for example, on Windows cx_freeze and PyInstaller can not be
imported, do not live under site-packages and so on... cx_Freeze is an
executable on Windows!!!

so I installed setuptools anyway and I got this error:
Traceback (most recent call last):
  File
"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py",
line 1341
, in Notify
    self.notify()
  File
"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py
", line 1418
9, in Notify
    self.result = self.callable(*self.args, **self.kwargs)
  File "C:\Download\GUI2Exe_source\GUI2Exe.py", line 1183,
in ShowMain
    frame = GUI2Exe(None, -1, "", size=(xvideo, yvideo))
  File "C:\Download\GUI2Exe_source\GUI2Exe.py", line 106,
in __init__
    self.dataBase = DataBase(self, dbName)
  File "C:\Download\GUI2Exe_source\DataBase.py", line 31,
in __init__
    self.db = bsddb.btopen(dbName, "c")
  File "C:\Python25\lib\bsddb\__init__.py", line 323, in
btopen
    d.open(file, db.DB_BTREE, flags, mode)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 26-29:
ord
inal not in range(128)

My default system encoding is hebrew, must be something in bsddb's unicode
support.

I have no idea about that... surely Robin knows the answer, he has
developed bsddb for quite long time... but maybe is just my fault, I
never worked with bsddb before :smiley:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 4/1/07, roee shlomo wrote:

Hi Roee,

It did create the .GUI2Exe directory in my %appdata% folder.
my guess is that it looks after an encoded path and that is why it can't
find it.
I have tried to replace opj with os.path.join and even to replace
standardPath.GetUserConfigDir() with a more simple path like C: , no luck so
far.

Thank you for the beta testing :smiley: :smiley: . Actually, if you write something like:

print configDir, configDb

in CheckForDatabase, do you receive meaningful path or something that
doesn't even exist? This one really puzzles me. I work on an PC with
italian configuration and another one with english (UK) one, and both
started without a flaw, both the executable and the source code.
Either I did something really stupid in the code or I don't know how
to deal correctly with bsddb...

Thank you again for your bug report, altough I don't know what to do
about it at the moment as on my machines all went well :frowning: . Is
anybody else seeing this problem (a part from Roee and Jesus
Martinez)?

:frowning: :frowning: :frowning:

···

On 4/2/07, roee shlomo wrote:

On 4/2/07, Andrea Gavana <andrea.gavana@gmail.com > wrote:
>
> Hi Roee,
>
> On 4/1/07, roee shlomo wrote:
> > The windows binary gives:
> > Traceback (most recent call last):
> > File "wx\_misc.pyo", line 1341, in Notify
> > File "wx\_core.pyo", line 14189, in Notify
> > File "GUI2Exe.py", line 1183, in ShowMain
> > File " GUI2Exe.py", line 106, in __init__
> > File "DataBase.pyo", line 31, in __init__
> > File "bsddb\__init__.pyo", line 323, in btopen
> > bsddb.db.DBNoSuchFileError: (2, 'No such file or directory')
>
> It looks like on PCs other than the 2 I tried Python doesn'like these
> lines of code:
>
> def CheckForDatabase(self):
> """ Checks if a database exists. If it doesn't, creates one anew.
"""
>
> # We build the database inside the user config folder, where we
> # also create a sub-directory called /.GUI2Exe
> standardPath = wx.StandardPaths.Get()
> configDir = opj(standardPath.GetUserConfigDir() + "/.GUI2Exe")
> configDb = opj(configDir + "/GUI2Exe_Database.db")
>
> if not os.path.isfile(configDb):
> # No database
> if not os.path.isdir(configDir):
> # And no directory. Create a new one.
> os.mkdir(configDir)
>
> return configDb
>
> So, it doesn't create the directory and bsddb is right in
> complaining... I don't really know why, I was just trying to create a
> directory called /.GUI2Exe under the user configuration directory
> which for me is:
>
> C:\Documents and Settings\Andrea\Dati applicazioni
>
> Curiously enough, it works well here :frowning: :frowning:
>
> BTW, I noticed I forgot to include the manifest file for Windows
> (!!!!!), so the executable didn't look that much XP-style :frowning: . I
> re-uploaded another version right now. However, I still don't know the
> reason why the program can't create that particular directory. Maybe
> someone more knowledgeable than me can explain it.
>
> > Running from source gave me an error saying setuptools is missing (I saw
the
> > comment on the source code. Why would anyone have py2app installed on
> > windows?),
>
> I tried to install il to see if could be acutally __import__ed,
> because, for example, on Windows cx_freeze and PyInstaller can not be
> imported, do not live under site-packages and so on... cx_Freeze is an
> executable on Windows!!!
>
> > so I installed setuptools anyway and I got this error:
> > Traceback (most recent call last):
> > File
> >
"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py",
> > line 1341
> > , in Notify
> > self.notify()
> > File
> >
"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py
> > ", line 1418
> > 9, in Notify
> > self.result = self.callable(*self.args, **self.kwargs)
> > File "C:\Download\GUI2Exe_source\GUI2Exe.py", line
1183,
> > in ShowMain
> > frame = GUI2Exe(None, -1, "", size=(xvideo, yvideo))
> > File "C:\Download\GUI2Exe_source\GUI2Exe.py", line
106,
> > in __init__
> > self.dataBase = DataBase(self, dbName)
> > File "C:\Download\GUI2Exe_source\DataBase.py", line
31,
> > in __init__
> > self.db = bsddb.btopen(dbName, "c")
> > File "C:\Python25\lib\bsddb\__init__.py", line 323,
in
> > btopen
> > d.open(file, db.DB_BTREE, flags, mode)
> > UnicodeEncodeError: 'ascii' codec can't encode characters in position
26-29:
> > ord
> > inal not in range(128)
> >
> > My default system encoding is hebrew, must be something in bsddb's
unicode
> > support.
>
> I have no idea about that... surely Robin knows the answer, he has
> developed bsddb for quite long time... but maybe is just my fault, I
> never worked with bsddb before :smiley:
>
> Andrea.
>
> "Imagination Is The Only Weapon In The War Against Reality."
> http://xoomer.virgilio.it/infinity77/
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
>

--
Google Code Archive - Long-term storage for Google Code Project Hosting.

--
Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

Hi Andrea,

It prints the right paths

C:\Documents and Settings\שלמה\Application Data.GUI2Exe
C:\Documents and Settings\שלמה\Application Data.GUI2Exe\GUI2Exe_Database.db

Both are correct unicode paths (I also printed type(…) and it returns ‘unicode’)

I also tried to encode configDir:

configDir = configDir.encode(sys.getfilesystemencoding())

The result was bsddb.db.DBNoSuchFileError: (2, ‘No such file or directory’)

I did successfully run the program by not sending dbName to the DataBase object (which causes the db file to be stored in the application path). It works quite well, except for saving projects:

Traceback (most recent call last):
File “C:\Download\GUI2Exe_source\GUI2Exe.py”, line 389, in OnSaveProject
self.SaveProject(project)
File “C:\Download\GUI2Exe_source\GUI2Exe.py”, line 770, in SaveProject

self.dataBase.SaveProject(project)

File “C:\Download\GUI2Exe_source\DataBase.py”, line 62, in SaveProject
self.db[key] = serialize(project)
File “C:\Python25\lib\bsddb_init_.py”, line 230, in setitem

_DeadlockWrap(wrapF)  # self.db[key] = value

File “C:\Python25\lib\bsddb\dbutils.py”, line 62, in DeadlockWrap
return function(*_args, **kwargs)
File "C:\Python25\lib\bsddb_init
.py", line 229, in wrapF

self.db[key] = value

TypeError: String or Integer object expected for key, unicode found

Again unicode issues.

btw, I’m using the unicode version of wxPython 2.8.3.0.

Thanks,

Roee.

···

On 4/2/07, Andrea Gavana andrea.gavana@gmail.com wrote:

Hi Roee,

On 4/2/07, roee shlomo wrote:

It did create the .GUI2Exe directory in my %appdata% folder.

my guess is that it looks after an encoded path and that is why it can’t
find it.
I have tried to replace opj with os.path.join and even to replace
standardPath.GetUserConfigDir() with a more simple path like C: , no luck so

far.

Thank you for the beta testing :smiley: :smiley: . Actually, if you write something like:

print configDir, configDb

in CheckForDatabase, do you receive meaningful path or something that
doesn’t even exist? This one really puzzles me. I work on an PC with

italian configuration and another one with english (UK) one, and both
started without a flaw, both the executable and the source code.
Either I did something really stupid in the code or I don’t know how

to deal correctly with bsddb…

Thank you again for your bug report, altough I don’t know what to do
about it at the moment as on my machines all went well :frowning: . Is
anybody else seeing this problem (a part from Roee and Jesus

Martinez)?

:frowning: :frowning: :frowning:

On 4/2/07, Andrea Gavana <andrea.gavana@gmail.com > wrote:

Hi Roee,

On 4/1/07, roee shlomo wrote:

The windows binary gives:
Traceback (most recent call last):
File “wx_misc.pyo”, line 1341, in Notify
File “wx_core.pyo”, line 14189, in Notify

File “GUI2Exe.py”, line 1183, in ShowMain
File " GUI2Exe.py", line 106, in init
File “DataBase.pyo”, line 31, in init
File “bsddb_init_.pyo”, line 323, in btopen

bsddb.db.DBNoSuchFileError: (2, ‘No such file or directory’)

It looks like on PCs other than the 2 I tried Python doesn’like these
lines of code:

def CheckForDatabase(self):
“”" Checks if a database exists. If it doesn’t, creates one anew.
“”"

   # We build the database inside the user config folder, where we
   # also create a sub-directory called /.GUI2Exe
   standardPath = wx.StandardPaths.Get()
   configDir = opj(standardPath.GetUserConfigDir() + "/.GUI2Exe")
   configDb = opj(configDir + "/GUI2Exe_Database.db")

   if not os.path.isfile(configDb):
       # No database
       if not os.path.isdir

(configDir):

           # And no directory. Create a new one.
           os.mkdir(configDir)

   return configDb

So, it doesn’t create the directory and bsddb is right in

complaining… I don’t really know why, I was just trying to create a
directory called /.GUI2Exe under the user configuration directory
which for me is:

C:\Documents and Settings\Andrea\Dati applicazioni

Curiously enough, it works well here :frowning: :frowning:

BTW, I noticed I forgot to include the manifest file for Windows
(!!!), so the executable didn’t look that much XP-style :frowning: . I

re-uploaded another version right now. However, I still don’t know the
reason why the program can’t create that particular directory. Maybe
someone more knowledgeable than me can explain it.

Running from source gave me an error saying setuptools is missing (I saw
the
comment on the source code. Why would anyone have py2app installed on
windows?),

I tried to install il to see if could be acutally __import__ed,
because, for example, on Windows cx_freeze and PyInstaller can not be
imported, do not live under site-packages and so on… cx_Freeze is an

executable on Windows!!!

so I installed setuptools anyway and I got this error:
Traceback (most recent call last):
File

“C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx_misc.py”,

line 1341
, in Notify
self.notify()
File

"C:\Python25\Lib\site-packages\wx-
2.8-msw-unicode\wx_core.py

", line 1418
9, in Notify
self.result = self.callable(*self.args, **self.kwargs)
File “C:\Download\GUI2Exe_source\GUI2Exe.py”, line

1183,

in ShowMain
frame = GUI2Exe(None, -1, “”, size=(xvideo, yvideo))
File “C:\Download\GUI2Exe_source\GUI2Exe.py”, line
106,

in init
self.dataBase = DataBase(self, dbName)
File “C:\Download\GUI2Exe_source\DataBase.py”, line
31,
in init
self.db = bsddb.btopen(dbName, “c”)
File “C:\Python25\lib\bsddb_init_.py”, line 323,
in
btopen
d.open(file, db.DB_BTREE, flags, mode)

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position
26-29:
ord
inal not in range(128)

My default system encoding is hebrew, must be something in bsddb’s

unicode

support.

I have no idea about that… surely Robin knows the answer, he has
developed bsddb for quite long time… but maybe is just my fault, I

never worked with bsddb before :smiley:

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.virgilio.it/infinity77/


To unsubscribe, e-mail:

wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org


http://code.google.com/p/lh-abc


Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.virgilio.it/infinity77/


To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org


http://code.google.com/p/lh-abc

Hi Andrea,

[snip]

Yeah, that's my fault, on my machines I still have ansi build... I
know I know, my bad :smiley: . By the way, I got rid of the ansi builds and
installed the unicode one. Well, I don't know if this is the right
solution or not, but I inserted at the beginning of GUI2Exe.py these
lines:

# This is *really* ugly
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
del sys.setdefaultencoding

And then used wx.SetDefaultPyEncoding("utf-8"), I am not sure "utf-8"
will be enough for all the cases (probably not), but the world of
encodings is still a bit obscure to me.

This will probably stop the UnicodeEncodeErrors, but in this case the big question is - does bsddb expect that the string it's given is in UTF-8 encoding? (My guess is that it doesn't.) This becomes a problem because it might do something like pass that UTF-8 string straight to Windows, which probably won't expect a string in UTF-8, so it will treat the string like it was encoded in whatever locale Windows is set to. (e.g. ASCII, Latin-1, Shift-JIS, etc., etc.) The end result is that it may give "file not found" errors, or write the file to disk using garbled folder names. A better fix for the problem in Windows would probably be to grab the Windows locale (there's functions for this in the locale module, IIRC) then in DataBase.py, change the line:

self.db = bsddb.btopen(dbName, "c")

to

self.db = bsddb.btopen(dbName.encode(myWinLocale), "c")

This way you don't have to make global script changes. You should also do this anytime you store user-supplied data in bsddb, although since you're probably almost always grabbing data from the GUI in those cases, calling wx.SetDefaultPyEncoding(myWinLocale) might take care of those issues. (I always get nervous about setting it globally like that though...)

In any case, this is just my two cents, but an API that cannot handle Unicode in this day and age is likely to cause lots of problems now and in the future, particularly since it doesn't sound like there's a plan to Unicode enable it. (not to mention it leaves all the conversion issues in your lap to deal with.) Also, IIUC, the current database approach sort of assumes these projects are only managed by one user - but what if you want to store your GUI2Exe projects in your project's CVS/SVN so others can build exe's and installers? As an alternative, you might want to look into either a simple XML project format, or perhaps just pickling the Python objects instead.

Regards,

Kevin

···

On Apr 1, 2007, at 5:36 PM, Andrea Gavana wrote:

In any case, noting that bsddb
doesn't like unicode objects as keys, I just encode()d them before
passing to it. I don't think it's an elegant solution, but at the
moment I am short of ideas...
I re-uploaded the new source and installer in the usual place. I don't
think it will make any difference, but if someone could try it I would
ben very happy :smiley:

Thank you.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hi Andrea and Kevin,

The workaround suggested by Andrea actually worked.

I have tried different kinds of encodings including locale.getpreferredencoding() and sys.getfilesystemencoding() but only utf-8 worked.

The latest release from Andrea’s site works perfectly as far as I can tell.

Cheers,

Roee.

···

On 4/2/07, Kevin Ollivier kevino@theolliviers.com wrote:

Hi Andrea,

On Apr 1, 2007, at 5:36 PM, Andrea Gavana wrote:

[snip]

Yeah, that’s my fault, on my machines I still have ansi build… I

know I know, my bad :smiley: . By the way, I got rid of the ansi builds and
installed the unicode one. Well, I don’t know if this is the right
solution or not, but I inserted at the beginning of GUI2Exe.py
these
lines:

This is really ugly

import sys
reload(sys)
sys.setdefaultencoding(‘utf-8’)
del sys.setdefaultencoding

And then used wx.SetDefaultPyEncoding
(“utf-8”), I am not sure “utf-8”
will be enough for all the cases (probably not), but the world of
encodings is still a bit obscure to me.

This will probably stop the UnicodeEncodeErrors, but in this case the

big question is - does bsddb expect that the string it’s given is in
UTF-8 encoding? (My guess is that it doesn’t.) This becomes a problem
because it might do something like pass that UTF-8 string straight to

Windows, which probably won’t expect a string in UTF-8, so it will
treat the string like it was encoded in whatever locale Windows is
set to. (e.g. ASCII, Latin-1, Shift-JIS, etc., etc.) The end result
is that it may give “file not found” errors, or write the file to

disk using garbled folder names. A better fix for the problem in
Windows would probably be to grab the Windows locale (there’s
functions for this in the locale module, IIRC) then in DataBase.py,
change the line:

self.db = bsddb.btopen(dbName, “c”)

to

self.db = bsddb.btopen(dbName.encode(myWinLocale), “c”)

This way you don’t have to make global script changes. You should
also do this anytime you store user-supplied data in bsddb, although

since you’re probably almost always grabbing data from the GUI in
those cases, calling wx.SetDefaultPyEncoding(myWinLocale) might take
care of those issues. (I always get nervous about setting it globally

like that though…)

In any case, this is just my two cents, but an API that cannot handle
Unicode in this day and age is likely to cause lots of problems now
and in the future, particularly since it doesn’t sound like there’s a

plan to Unicode enable it. (not to mention it leaves all the
conversion issues in your lap to deal with.) Also, IIUC, the current
database approach sort of assumes these projects are only managed by
one user - but what if you want to store your GUI2Exe projects in

your project’s CVS/SVN so others can build exe’s and installers? As
an alternative, you might want to look into either a simple XML
project format, or perhaps just pickling the Python objects instead.

Regards,

Kevin

In any case, noting that bsddb
doesn’t like unicode objects as keys, I just encode()d them before
passing to it. I don’t think it’s an elegant solution, but at the

moment I am short of ideas…
I re-uploaded the new source and installer in the usual place. I don’t
think it will make any difference, but if someone could try it I would
ben very happy :smiley:

Thank you.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.virgilio.it/infinity77/


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-
help@lists.wxwidgets.org


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org


http://code.google.com/p/lh-abc

Robin:

As I mentioned before, sys.getfilesystemencoding() brings a file not found error.

Andrea:

in CheckForDatabase please encode configDb only when you return it.

os.path.isdir(configDir) won’t work well otherwise.

def CheckForDatabase(self):
“”" Checks if a database exists. If it doesn’t, creates one anew. “”"

We build the database inside the user config folder, where we

    # also create a sub-directory called /.GUI2Exe
    standardPath = wx.StandardPaths.Get()
    configDir = opj(standardPath.GetUserConfigDir

() + “/.GUI2Exe”)
configDb = opj(configDir + “/GUI2Exe_Database.db”)

    if not os.path.isfile(configDb):
        # No database
        if not os.path.isdir(configDir):

            # And no directory. Create a new one.
            os.mkdir(configDir)

return configDb.encode()

btw,

Adding data files via GUI is not implemented yet, right?

···

On 4/2/07, Robin Dunn robin@alldunn.com wrote:

Andrea Gavana wrote:

d.open(file, db.DB_BTREE, flags, mode)

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position

26-29:
ord
inal not in range(128)

My default system encoding is hebrew, must be something in bsddb’s
unicode
support.

I have no idea about that… surely Robin knows the answer, he has

developed bsddb for quite long time… but maybe is just my fault, I
never worked with bsddb before :smiley:

It’s expecting a string. When you pass a unicode object to it then
Python tries to coerce it to a string, using the default codec. You

should do the conversion yourself (probably to the
sys.getfilesystemencoding() encoding) before calling open.


Robin Dunn
Software Craftsman
http://wxPython.org
Java give you jitters? Relax with wxPython!


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org



http://code.google.com/p/lh-abc

Andrea Gavana wrote:

And removed
wx.SetDefaultPyEncoding("utf-8")

No, don't do that. If you encode everything using UTF-8, I can enter a
project name like this:

MyProject (some kind of french/german/russian/whatever non-ascii
non-cp1252 letter)

And, while the database will recognize them (because you are encoding
them as UTF-8), the tree control on the left will not display the
project names correctly, as wxPython will use
wx.GetDefaultPyEncoding(), which returns the string encoding
for the system at the moment. That means, if you send me your
database, my tree control will probably display a bunch of squares
instead of the names you have used (if you used hebrew letters, for
example). I may be wrong here, so please everyone enlight me if I am
saying stupid things.

Just for clarification, the wx.SetDefaultPyEncoding value only sets the codec to be used when wxPython needs to convert to/from unicode/ansi for wx methods and functions only. This value usually defaults to locale.getpreferredencoding() so it matches what Python thinks is the default for your system as it is currently configured. It doesn't have any effect on any other automatic conversions or coercions that Python will try to.

For example, if you have a Unicode build of wxPython, and pass a string object to textctrl.SetValue, then it will use the wx.GetDefaultPyEncoding() encoding to convert it to a Unicode object to pass to the C++ SetValue. The opposite is also true, if you have an ansi build of wxPython and pass a Unicode object then that encoding will be used to convert it to a string first.

For other automatic ansi/unicode conversions that Python does then it uses the return value of sys.getdefaultencoding() for the encoding. Python also provides the sys.getfilesystemencoding() value which specifies what should be used for encoding unicode values into ansi strings to be used for path and file names on the current system.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Robin,

Andrea Gavana wrote:

>> And removed
>> wx.SetDefaultPyEncoding("utf-8")
>
> No, don't do that. If you encode everything using UTF-8, I can enter a
> project name like this:
>
> MyProject (some kind of french/german/russian/whatever non-ascii
> non-cp1252 letter)
>
> And, while the database will recognize them (because you are encoding
> them as UTF-8), the tree control on the left will not display the
> project names correctly, as wxPython will use
> wx.GetDefaultPyEncoding(), which returns the string encoding
> for the system at the moment. That means, if you send me your
> database, my tree control will probably display a bunch of squares
> instead of the names you have used (if you used hebrew letters, for
> example). I may be wrong here, so please everyone enlight me if I am
> saying stupid things.

Just for clarification, the wx.SetDefaultPyEncoding value only sets the
codec to be used when wxPython needs to convert to/from unicode/ansi for
wx methods and functions only. This value usually defaults to
locale.getpreferredencoding() so it matches what Python thinks is the
default for your system as it is currently configured. It doesn't have
any effect on any other automatic conversions or coercions that Python
will try to.

Ok, thank you for the explanation.

For example, if you have a Unicode build of wxPython, and pass a string
object to textctrl.SetValue, then it will use the
wx.GetDefaultPyEncoding() encoding to convert it to a Unicode object to
pass to the C++ SetValue. The opposite is also true, if you have an
ansi build of wxPython and pass a Unicode object then that encoding will
be used to convert it to a string first.

Well, let's assume I have an unicode build of wxPython. Then Roee
sends me his database of GUI2Exe projects, and he has put in there
project names with hebrew letters (or cyrillic or whatever). My
database pre-processing will not blink, but on my machines
wx.GetDefaultPyEncoding() returns either 'cp1251' (here at work) or
'ascii' at home. Will it harm if I receive Roee's database?

For other automatic ansi/unicode conversions that Python does then it
uses the return value of sys.getdefaultencoding() for the encoding.
Python also provides the sys.getfilesystemencoding() value which
specifies what should be used for encoding unicode values into ansi
strings to be used for path and file names on the current system.

sys.getdefaultencoding() seems not enough to work with bsddb, also
Roee reported the same problem. And I found exactly the same when
assigning project names with accented letters (french, german and
similar). I saved a project in the database with this strange name,
closed GUI2Exe, reopened it and the project name was completely
screwed up :frowning:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 4/4/07, Robin Dunn wrote:

Hi Andrea,

Thanks for the Ctrl+A hint :slight_smile:

Indeed wx.SetDefaultPyEncoding(“utf-8”) is necessary.

I’m getting UnicodeDecodeError with non-english non-hebrew letters otherwise (like üßÄ).

Your latest release + the change in CheckForDatabase (encoding only on return) works well and it displays correctly project names even after restart (I have tried dutch letters for testing).

As far as I can tell all unicode issues are fixed.

If you want to make a test, I attached a simple database.

It has three projects in it, all have hebrew words as project names.
A screenshot would be the best way to be sure it displays it correctly.

Greetings,

Roee.

GUI2Exe_Database.db (16 KB)

···

On 4/5/07, Andrea Gavana andrea.gavana@gmail.com wrote:

Hi Robin,

On 4/4/07, Robin Dunn wrote:

Andrea Gavana wrote:

And removed

wx.SetDefaultPyEncoding(“utf-8”)

No, don’t do that. If you encode everything using UTF-8, I can enter a
project name like this:

MyProject (some kind of french/german/russian/whatever non-ascii

non-cp1252 letter)

And, while the database will recognize them (because you are encoding
them as UTF-8), the tree control on the left will not display the
project names correctly, as wxPython will use

wx.GetDefaultPyEncoding(), which returns the string encoding
for the system at the moment. That means, if you send me your
database, my tree control will probably display a bunch of squares

instead of the names you have used (if you used hebrew letters, for
example). I may be wrong here, so please everyone enlight me if I am
saying stupid things.

Just for clarification, the wx.SetDefaultPyEncoding value only sets the
codec to be used when wxPython needs to convert to/from unicode/ansi for
wx methods and functions only. This value usually defaults to
locale.getpreferredencoding
() so it matches what Python thinks is the
default for your system as it is currently configured. It doesn’t have
any effect on any other automatic conversions or coercions that Python
will try to.

Ok, thank you for the explanation.

For example, if you have a Unicode build of wxPython, and pass a string
object to textctrl.SetValue, then it will use the
wx.GetDefaultPyEncoding() encoding to convert it to a Unicode object to

pass to the C++ SetValue. The opposite is also true, if you have an
ansi build of wxPython and pass a Unicode object then that encoding will
be used to convert it to a string first.

Well, let’s assume I have an unicode build of wxPython. Then Roee

sends me his database of GUI2Exe projects, and he has put in there
project names with hebrew letters (or cyrillic or whatever). My
database pre-processing will not blink, but on my machines
wx.GetDefaultPyEncoding
() returns either ‘cp1251’ (here at work) or
‘ascii’ at home. Will it harm if I receive Roee’s database?

For other automatic ansi/unicode conversions that Python does then it
uses the return value of sys.getdefaultencoding() for the encoding.
Python also provides the sys.getfilesystemencoding() value which
specifies what should be used for encoding unicode values into ansi
strings to be used for path and file names on the current system.

sys.getdefaultencoding() seems not enough to work with bsddb, also
Roee reported the same problem. And I found exactly the same when
assigning project names with accented letters (french, german and
similar). I saved a project in the database with this strange name,

closed GUI2Exe, reopened it and the project name was completely
screwed up :frowning:

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.virgilio.it/infinity77/


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org



http://code.google.com/p/lh-abc

BTW, which Windows version are you and Roee using? I wonder what
sys.getfilesystemencoding() is returning that it doesn’t work when

converting to it from a Unicode object?

I’m using XP.

It returns ‘mbcs’

···

On 4/5/07, Kevin Ollivier kevino@theolliviers.com wrote:

Hi Andrea,

On Apr 5, 2007, at 1:58 AM, Andrea Gavana wrote:

Hi Robin,

On 4/4/07, Robin Dunn wrote:

Andrea Gavana wrote:

And removed
wx.SetDefaultPyEncoding(“utf-8”)

No, don’t do that. If you encode everything using UTF-8, I can

enter a

project name like this:

MyProject (some kind of french/german/russian/whatever non-ascii
non-cp1252 letter)

And, while the database will recognize them (because you are

encoding

them as UTF-8), the tree control on the left will not display the
project names correctly, as wxPython will use
wx.GetDefaultPyEncoding(), which returns the string encoding

for the system at the moment. That means, if you send me your
database, my tree control will probably display a bunch of squares
instead of the names you have used (if you used hebrew letters, for

example). I may be wrong here, so please everyone enlight me if
I am
saying stupid things.

Just for clarification, the wx.SetDefaultPyEncoding value only

sets the
codec to be used when wxPython needs to convert to/from unicode/
ansi for
wx methods and functions only. This value usually defaults to
locale.getpreferredencoding
() so it matches what Python thinks is the
default for your system as it is currently configured. It doesn’t
have
any effect on any other automatic conversions or coercions that

Python
will try to.

Ok, thank you for the explanation.

For example, if you have a Unicode build of wxPython, and pass a
string
object to textctrl.SetValue
, then it will use the
wx.GetDefaultPyEncoding() encoding to convert it to a Unicode
object to
pass to the C++ SetValue. The opposite is also true, if you have an
ansi build of wxPython and pass a Unicode object then that

encoding will
be used to convert it to a string first.

Well, let’s assume I have an unicode build of wxPython. Then Roee
sends me his database of GUI2Exe projects, and he has put in there

project names with hebrew letters (or cyrillic or whatever). My
database pre-processing will not blink, but on my machines
wx.GetDefaultPyEncoding() returns either ‘cp1251’ (here at work) or

‘ascii’ at home. Will it harm if I receive Roee’s database?

Yes, but only because you’re letting byte strings run around your app
without converting them to Unicode objects first. :wink: The best way to

handle encoding issues like this, IMHO, is to convert to/from Unicode
objects when, and only when, setting or receiving data via non-
Unicode compliant APIs, such as bsddb. Rather than relying on
libraries to silently convert for you, you should do the conversion

right when you send and/or receive the data. If a library gives you a
string, convert it to Unicode ASAP. :wink: It might seem convenient to
have Python silently convert string<->Unicode whenever needed, but in

reality that gets a lot trickier to debug when your global encoding
doesn’t work with a certain set of input data. As you noticed, when
you’re not dealing with ASCII but don’t use the right encoding, you

often won’t get encoding errors - just garbled text. Well, actually,
more likely your user will get garbled text. ;-/

SetDefaultPyEncoding() really should only be used for ANSI builds
where you always need to convert, and for some reason the value of

GetDefaultPyEncoding() doesn’t match the encoding that wxWidgets
expects the data to be in. (i.e. you’re not telling wxWidgets which
encoding to use, you’re telling wxPython which encoding wxWidgets is

expecting)

For other automatic ansi/unicode conversions that Python does then it
uses the return value of sys.getdefaultencoding() for the encoding.
Python also provides the sys.getfilesystemencoding() value which
specifies what should be used for encoding unicode values into ansi
strings to be used for path and file names on the current system.

sys.getdefaultencoding
() seems not enough to work with bsddb, also
Roee reported the same problem. And I found exactly the same when
assigning project names with accented letters (french, german and
similar). I saved a project in the database with this strange name,

closed GUI2Exe, reopened it and the project name was completely
screwed up :frowning:

BTW, which Windows version are you and Roee using? I wonder what
sys.getfilesystemencoding() is returning that it doesn’t work when

converting to it from a Unicode object?

Regards,

Kevin

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.virgilio.it/infinity77/


To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-
help@lists.wxwidgets.org


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org


http://code.google.com/p/lh-abc

Hi Roee,

BTW, which Windows version are you and Roee using? I wonder what
sys.getfilesystemencoding() is returning that it doesn’t work when
converting to it from a Unicode object?

I’m using XP.

It returns ‘mbcs’

Okay, two more questions:

  1. Do or did you ever switch your Windows locale? (i.e. is it possible that the ‘mbcs’ encoding doesn’t have some of the characters because you wrote those characters while Win was set to a different locale?)

  2. if you run ‘configDb.encode(sys.getfilesystemencoding(), ‘replace’)’ and print the new value, do each of the (Hebrew?) characters show up as ‘?’ in the output?

Thanks,

Kevin

···

On Apr 5, 2007, at 11:47 AM, roee shlomo wrote:

On 4/5/07, Kevin Ollivier kevino@theolliviers.com wrote:

Hi Andrea,

On Apr 5, 2007, at 1:58 AM, Andrea Gavana wrote:

Hi Robin,

On 4/4/07, Robin Dunn wrote:

Andrea Gavana wrote:

And removed
wx.SetDefaultPyEncoding(“utf-8”)

No, don’t do that. If you encode everything using UTF-8, I can
enter a
project name like this:

MyProject (some kind of french/german/russian/whatever non-ascii
non-cp1252 letter)

And, while the database will recognize them (because you are
encoding
them as UTF-8), the tree control on the left will not display the
project names correctly, as wxPython will use
wx.GetDefaultPyEncoding(), which returns the string encoding
for the system at the moment. That means, if you send me your
database, my tree control will probably display a bunch of squares
instead of the names you have used (if you used hebrew letters, for
example). I may be wrong here, so please everyone enlight me if
I am
saying stupid things.

Just for clarification, the wx.SetDefaultPyEncoding value only
sets the
codec to be used when wxPython needs to convert to/from unicode/
ansi for
wx methods and functions only. This value usually defaults to
locale.getpreferredencoding () so it matches what Python thinks is the
default for your system as it is currently configured. It doesn’t
have
any effect on any other automatic conversions or coercions that
Python
will try to.

Ok, thank you for the explanation.

For example, if you have a Unicode build of wxPython, and pass a
string
object to textctrl.SetValue , then it will use the
wx.GetDefaultPyEncoding() encoding to convert it to a Unicode
object to
pass to the C++ SetValue. The opposite is also true, if you have an
ansi build of wxPython and pass a Unicode object then that
encoding will
be used to convert it to a string first.

Well, let’s assume I have an unicode build of wxPython. Then Roee
sends me his database of GUI2Exe projects, and he has put in there
project names with hebrew letters (or cyrillic or whatever). My
database pre-processing will not blink, but on my machines
wx.GetDefaultPyEncoding() returns either ‘cp1251’ (here at work) or
‘ascii’ at home. Will it harm if I receive Roee’s database?

Yes, but only because you’re letting byte strings run around your app
without converting them to Unicode objects first. :wink: The best way to
handle encoding issues like this, IMHO, is to convert to/from Unicode
objects when, and only when, setting or receiving data via non-
Unicode compliant APIs, such as bsddb. Rather than relying on
libraries to silently convert for you, you should do the conversion
right when you send and/or receive the data. If a library gives you a
string, convert it to Unicode ASAP. :wink: It might seem convenient to
have Python silently convert string<->Unicode whenever needed, but in
reality that gets a lot trickier to debug when your global encoding
doesn’t work with a certain set of input data. As you noticed, when
you’re not dealing with ASCII but don’t use the right encoding, you
often won’t get encoding errors - just garbled text. Well, actually,
more likely your user will get garbled text. ;-/

SetDefaultPyEncoding() really should only be used for ANSI builds
where you always need to convert, and for some reason the value of
GetDefaultPyEncoding() doesn’t match the encoding that wxWidgets
expects the data to be in. (i.e. you’re not telling wxWidgets which
encoding to use, you’re telling wxPython which encoding wxWidgets is
expecting)

For other automatic ansi/unicode conversions that Python does then it
uses the return value of sys.getdefaultencoding() for the encoding.
Python also provides the sys.getfilesystemencoding() value which
specifies what should be used for encoding unicode values into ansi
strings to be used for path and file names on the current system.

sys.getdefaultencoding () seems not enough to work with bsddb, also
Roee reported the same problem. And I found exactly the same when
assigning project names with accented letters (french, german and
similar). I saved a project in the database with this strange name,
closed GUI2Exe, reopened it and the project name was completely
screwed up :frowning:

BTW, which Windows version are you and Roee using? I wonder what
sys.getfilesystemencoding() is returning that it doesn’t work when
converting to it from a Unicode object?

Regards,

Kevin

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.virgilio.it/infinity77/


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-
help@lists.wxwidgets.org


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org


http://code.google.com/p/lh-abc

  1. Do or did you ever switch your Windows locale?

No

  1. if you run ‘configDb.encode(sys.getfilesystemencoding(), ‘replace’)’ and print the new value, do each of the (Hebrew?) characters show up as ‘?’ in the output?

No. There aren’t any question marks. only wierd symbols like ∙∞εΣ .

Just as a note, in the application I develop I use sys.getfilesystemencoding() to encode the root path of the app and it works fine.

···

On 4/9/07, Kevin Ollivier kevino@theolliviers.com wrote:

Hi Roee,

On Apr 5, 2007, at 11:47 AM, roee shlomo wrote:

BTW, which Windows version are you and Roee using? I wonder what
sys.getfilesystemencoding() is returning that it doesn’t work when
converting to it from a Unicode object?

I’m using XP.

It returns ‘mbcs’

Okay, two more questions:

  1. Do or did you ever switch your Windows locale? (i.e. is it possible that the ‘mbcs’ encoding doesn’t have some of the characters because you wrote those characters while Win was set to a different locale?)
  1. if you run ‘configDb.encode(sys.getfilesystemencoding(), ‘replace’)’ and print the new value, do each of the (Hebrew?) characters show up as ‘?’ in the output?

Thanks,

Kevin

On 4/5/07, Kevin Ollivier <kevino@theolliviers.com > > > wrote:

Hi Andrea,

On Apr 5, 2007, at 1:58 AM, Andrea Gavana wrote:

Hi Robin,

On 4/4/07, Robin Dunn wrote:

Andrea Gavana wrote:

And removed
wx.SetDefaultPyEncoding(“utf-8”)

No, don’t do that. If you encode everything using UTF-8, I can
enter a
project name like this:

MyProject (some kind of french/german/russian/whatever non-ascii
non-cp1252 letter)

And, while the database will recognize them (because you are
encoding
them as UTF-8), the tree control on the left will not display the
project names correctly, as wxPython will use
wx.GetDefaultPyEncoding(), which returns the string encoding
for the system at the moment. That means, if you send me your
database, my tree control will probably display a bunch of squares
instead of the names you have used (if you used hebrew letters, for
example). I may be wrong here, so please everyone enlight me if
I am
saying stupid things.

Just for clarification, the wx.SetDefaultPyEncoding value only
sets the
codec to be used when wxPython needs to convert to/from unicode/
ansi for
wx methods and functions only. This value usually defaults to
locale.getpreferredencoding
() so it matches what Python thinks is the
default for your system as it is currently configured. It doesn’t
have
any effect on any other automatic conversions or coercions that

Python
will try to.

Ok, thank you for the explanation.

For example, if you have a Unicode build of wxPython, and pass a
string
object to textctrl.SetValue
, then it will use the
wx.GetDefaultPyEncoding() encoding to convert it to a Unicode
object to
pass to the C++ SetValue. The opposite is also true, if you have an
ansi build of wxPython and pass a Unicode object then that
encoding will
be used to convert it to a string first.

Well, let’s assume I have an unicode build of wxPython. Then Roee
sends me his database of GUI2Exe projects, and he has put in there
project names with hebrew letters (or cyrillic or whatever). My
database pre-processing will not blink, but on my machines
wx.GetDefaultPyEncoding() returns either ‘cp1251’ (here at work) or
‘ascii’ at home. Will it harm if I receive Roee’s database?

Yes, but only because you’re letting byte strings run around your app
without converting them to Unicode objects first. :wink: The best way to
handle encoding issues like this, IMHO, is to convert to/from Unicode
objects when, and only when, setting or receiving data via non-
Unicode compliant APIs, such as bsddb. Rather than relying on
libraries to silently convert for you, you should do the conversion
right when you send and/or receive the data. If a library gives you a
string, convert it to Unicode ASAP. :wink: It might seem convenient to
have Python silently convert string<->Unicode whenever needed, but in
reality that gets a lot trickier to debug when your global encoding
doesn’t work with a certain set of input data. As you noticed, when
you’re not dealing with ASCII but don’t use the right encoding, you
often won’t get encoding errors - just garbled text. Well, actually,
more likely your user will get garbled text. ;-/

SetDefaultPyEncoding() really should only be used for ANSI builds
where you always need to convert, and for some reason the value of
GetDefaultPyEncoding() doesn’t match the encoding that wxWidgets
expects the data to be in. (i.e. you’re not telling wxWidgets which
encoding to use, you’re telling wxPython which encoding wxWidgets is
expecting)

For other automatic ansi/unicode conversions that Python does then it
uses the return value of sys.getdefaultencoding() for the encoding.
Python also provides the sys.getfilesystemencoding() value which
specifies what should be used for encoding unicode values into ansi
strings to be used for path and file names on the current system.

sys.getdefaultencoding
() seems not enough to work with bsddb, also
Roee reported the same problem. And I found exactly the same when
assigning project names with accented letters (french, german and
similar). I saved a project in the database with this strange name,
closed GUI2Exe, reopened it and the project name was completely
screwed up :frowning:

BTW, which Windows version are you and Roee using? I wonder what
sys.getfilesystemencoding() is returning that it doesn’t work when
converting to it from a Unicode object?

Regards,

Kevin

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.virgilio.it/infinity77/


To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-

help@lists.wxwidgets.org


To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org


http://code.google.com/p/lh-abc


http://code.google.com/p/lh-abc