Re: [PythonCE] Unicode default encoding

2006-03-02 Thread Fuzzyman
Jeffrey Barish wrote:

Luke Dunstan wrote:


- Original Message - 
From: Jeffrey Barish [EMAIL PROTECTED]
To: pythonce@python.org
Sent: Friday, February 24, 2006 11:03 AM
Subject: [PythonCE] Unicode default encoding
  
  

What is the correct way to set PythonCE's default Unicode encoding?  My
reading (Python in a Nutshell) indicates that I am supposed to make a 
change to site.py, but there doesn't seem to be a site.py in
PythonCE.  (The  closest I came is a site.pyc in python23.zip.)  Nutshell
suggests that in desperation one could put the following at the start of
the main script:   

import sys
reload(sys)
sys.setdefaultencoding('iso-8859-15')
del sys.setdefaultencoding

This code solved the problem I was having reading and processing text that
contains Unicode characters, but I am uncomfortable leaving a desperation
solution in place.



I don't think modifying site.py would be a good solution, because if you 
upgrade or reinstall python then the script will be overwritten. If you
only  want to run your program on your own system then a better solution is
to  create a file sitecustomize.py in your Python\Lib directory containing
this: 

import sys
sys.setdefaultencoding('iso-8859-15')

If you want to distribute your program to other people though, you can't 
expect them to change their default encoding so it is better not to rely on 
the default encoding at all.

  
  

Yep, using unicode and explicitly encoding/decoding is a better approach.

Fuzzyman



Once again, I am forced to display my ignorance.  Sorry guys.  I really don't 
know much about Unicode.  The solution that Luke suggested (sitecustomize.py 
in my Python\Lib directory) works fine for me, but I am concerned about the 
suggestion from him and Fuzzyman that explicit encoding/decoding is a better 
approach.  What is explicit encoding/decoding?  Can someone point me to a 
good resource for learning how to deal with Unicode correctly?
  

Unicode, and text encodings in general, is a bit of a learning curve.
Once you get your head round it, Python makes it pretty straightforward.

Simple rules :

* In Python text *really* means a unicode string
* Because ordinary strings are really just strings of bytes
* If you know the encoding, decode it to turn it into encoding
* When writing or printing, encode it to turn it back into bytes
* If you don't know the encoding then you better pray that whatever it
is is encoded in the system default. ;-)

byte_string = open(filename).read() # read a file
text = byte_string.decode('utf_8')# we know it is UTF8, so we decode
to unicode
# code that uses the text
byte_string = text.encode('utf_8')   # we encode it back to UTF8
open(filename, 'w').write(byte_string) # so we can write it back out

Decoding turns a byte string into a unicode object.
Encoding turns a unicode object into a byte string.

If this still confuses you (which it probably does) then there are lots
of good resources. I happen to like :

http://www.pyzine.com/Issue008/Section_Articles/article_Encodings.html

Which seems to be down at the moment. :-(

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] Warning about comctl32.dll

2006-03-02 Thread Luke Dunstan

- Original Message - 
From: Jeffrey Barish [EMAIL PROTECTED]
To: pythonce@python.org
Sent: Thursday, March 02, 2006 11:27 AM
Subject: Re: [PythonCE] Warning about comctl32.dll


  Some of my applications are now triggering a warning when they first 
  start
  running that reads:
 
  Please install a newer version of comctl32.dll (at least version 4.70 
  is
  required but you have 0.00) or the program won't operate correctly.

 If I search for this message on Google it appears only in wxWidgets 
 source
 code, so I suggest you ask on their mailing list.

 Luke

 I did post a message, as you suggested.  In case anyone is interested, the
 response that I got was:

 It seems in 2_6_BRANCH of wxWidgets source repository this message occur 
 in
 wxW/src/msw/listctrl.cpp when wxLC_VIRTUAL flag is used.

 The version of wx that runs on WinCE is 2.5.2.8u, but the symptoms match. 
 All
 my test programs that contain a list control in virtual mode produce the
 error message and those with a list control in normal mode do not.  I am
 still searching for a solution to this problem.
 -- 
 Jeffrey Barish

Did they admit that it is a wxWidgets bug though? As you say, Windows CE has 
no comctl32.dll so wxWidgets should probably not check for the version 
number, but I don't know for sure. The only way to avoid it would be to 
modify and recompile wxWidgets for WinCE.

Luke
___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] Running Python program without getting Python CE window

2006-03-02 Thread Luke Dunstan

The normal .py association on Windows is done with a couple of registry 
values:

1. Create a key: HKEY_CLASSES_ROOT\.py
2. Set the default value of this key to: Python.File
3. Create a key: HKEY_CLASSES_ROOT\Python.File\shell\open\command
4. Set the default value to: C:\Python24\python.exe %1 %*

Windows CE is the same but the command might be: \Program 
Files\PythonCE\python.exe %1

You could make .pyw work on WinCE by creating a key HKCR\.pyw and another 
like HKCR\Python.File.NoShell, with the appropriate command line. In fact I 
may do this in the next version of the PythonCE installer.

There are several ways to edit the registry. I've used two:
1. Total Commander, a free file manager for WinCE that includes a registry 
editor
2. Remote Registry Editor from MS eMbedded Visual C++

I've also used this command line console: 
http://www.symbolictools.de/public/pocketconsole/


Luke

- Original Message - 
From: Jeffrey Barish [EMAIL PROTECTED]
To: pythonce@python.org
Sent: Thursday, March 02, 2006 10:35 AM
Subject: [PythonCE] Running Python program without getting Python CE window


- Original Message - 
From: Jeffrey Barish [EMAIL PROTECTED]
To: pythonce@python.org
Sent: Friday, February 24, 2006 11:08 AM
Subject: [PythonCE] Running Python program without getting Python CE window

  Whenever I run a Python application, I get a window titled Python CE
that
  seems to capture stdout. Is it called the console? I would like to run
my
  application without getting that window. I had the impression that this
  window would not appear if I ran the application using pythonw. To that
  end,  I changed the first line of my application to
 
  #! /usr/bin/env pythonw
 
  (instead of /usr/bin/env/python). Changing this line has no effect in
  either CE or XP. What is the correct procedure?

 As somebody else mentioned, that is a Unix-specific feature. In Windows XP
 you can rename the file to .pyw to run it automatically with pythonw.exe. 
 On
 Windows CE there is no standard way but this might help:

 python /nopcceshell program.py

 Luke

Forgive my continued ignorance.  Changing the extension works fine in XP to
suppress the console window, but I don't understand how to enter the command
you suggested in CE.  Did you find a console for CE that permits you to type
in commands?  Does CE come with one (that I have been unable to locate)?

I also posted a related question last week, but I never saw my message in 
the
digest (which happens frequently).  I am also wondering what the procedure 
is
for attaching an icon to my application so that I can run the application by
tapping the icon?  And, to be precise, what I would like is to run my Python
program in such a way that the console window does not appear.  Perhaps
tapping the icon would run the command that you suggested above.
-- 
Jeffrey Barish
___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce
___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] Running Python program without getting Python CE window

2006-03-02 Thread Ed Blake
--- Michael Foord [EMAIL PROTECTED] wrote:

 You ought to check out Wax. It's a friendly Pythonic layer that sits 
 atop of wx and IMHO is just as easy to use as Tkinter.

Lol! I've been using/tinkering with firedrop for a few weeks now so I am
vaguely familier with wax.  I don't really like the idea of using a largish
wrapper over the top of a huge library though, especially on a small embedded
device!  Also wax is incomplete, and as I've said I don't know enough Wx to
fix/add stuff.

BTW in Firedrop my page template was failing because the editor I was using
inserted tabs instead of spaces.  I didn't really feel like fixing my
template so I poked around in embedded_code.py.  If you add .replace('\t','
') to the return statement in replace_separators tabs vs. spaces becomes a
non-issue ^_^


--- Luke Dunstan [EMAIL PROTECTED] wrote:

 
 
 You could make .pyw work on WinCE by creating a key HKCR\.pyw and another 
 like HKCR\Python.File.NoShell, with the appropriate command line. In fact I
 
 may do this in the next version of the PythonCE installer.
 ...

Hope you don't mind, attached is my hacked version of setup-registry.py which
registers .pyw, and adds the PythonCE icon to all Python files!  It can
also be found here:
http://kitsu.petesdomain.com/files/WinCE/setup-registry.py

I haven't tested it yet!  My ipaq is out of commission for a while because I
needed its SD card -_-#
#	Setup the registry to allow us to double click on python scripts
#
from _winreg import *

print Setting up registry to allow\nrunning of Python files.

#
#	Create the registry entries for .py and .pyc extensions
#
for Name in (.py, .pyc):
Key = CreateKey(HKEY_CLASSES_ROOT, Name)
SetValue(Key, None, REG_SZ, Python.File)
CloseKey(Key)

#
#	Create the registry entry for .pyw extension
#
Key = CreateKey(HKEY_CLASSES_ROOT, .pyw)
SetValue(Key, None, REG_SZ, Python.File.Noconsole)
CloseKey(Key)

#
#	Create HKEY_CLASSES_ROOT\Python.File\Shell\Open\Command = \Program Files\Python\Lib\Python.exe %1
#
Key = CreateKey(HKEY_CLASSES_ROOT, Python.File)
for Name in (Shell,Open,Command):
  New_Key= CreateKey(Key, Name)
  CloseKey(Key)
  Key = New_Key
SetValue(Key, None, REG_SZ, \\\Storage Card\\python\\lib\\Python.exe\ \%1\)
CloseKey(Key)

print Setting up registry to allow\ndouble clicking of Python files to work

#
#	Create command key for nopcceshell (.pyw files)
#
Key = CreateKey(HKEY_CLASSES_ROOT, Python.File.Noconsole)
for Name in (Shell,Open,Command):
  New_Key= CreateKey(Key, Name)
  CloseKey(Key)
  Key = New_Key
SetValue(Key, None, REG_SZ, \\\Storage Card\\python\\lib\\Python.exe /nopcceshell\ \%1\)
CloseKey(Key)

#
#	Create keys for DefaultIcon
#
icon_path = \\Storage Card\\python\\lib\\python.exe,0
for name in (Python.File, Python.File.):
Key = CreateKey(HKEY_CLASSES_ROOT, name)
New_Key = CreateKey(Key, DefaultIcon)
SetValue(New_Key, None, REG_SZ, icon_path)
CloseKey(Key)
CloseKey(New_Key)
print 'Icon set to %s' %icon_path

import time
time.sleep(5)
___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] Running Python program without getting Python CE window

2006-03-02 Thread Thomas Heller
Ed Blake wrote:
 --- Michael Foord [EMAIL PROTECTED] wrote:
 
 You ought to check out Wax. It's a friendly Pythonic layer that sits 
 atop of wx and IMHO is just as easy to use as Tkinter.
 
 Lol! I've been using/tinkering with firedrop for a few weeks now so I am
 vaguely familier with wax.  I don't really like the idea of using a largish
 wrapper over the top of a huge library though, especially on a small embedded
 device!  Also wax is incomplete, and as I've said I don't know enough Wx to
 fix/add stuff.

I've lost the original email, butI hope this is still on topic:

Now that ctypes works on WindowsCE, someone should revive the venster project!

http://venster.sourceforge.net/htdocs/

Thomas

___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] Running Python program without getting Python CE window

2006-03-02 Thread Ed Blake

--- Thomas Heller [EMAIL PROTECTED] wrote:

 
 I've lost the original email, butI hope this is still on topic:
 
 Now that ctypes works on WindowsCE, someone should revive the venster
 project!
 
 http://venster.sourceforge.net/htdocs/
 

Very cool project, I've been thinking for a while that a Pythonic wrapper
around Windows ui stuff would be very handy... but the inability to
fix/extend goes double for microsoft stuff. 
It would be nice if there were good win32ui docs/tutorials/guides.  It
seems to wrap a lot of stuff, but I have next to zero knowledge concerning
windows ui programming and the wrapping looks pretty raw!
___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce