Exception in sample.pyw

135 views
Skip to first unread message

fpp

unread,
Sep 2, 2013, 2:38:44 PM9/2/13
to gui...@googlegroups.com
Hi,

I did use pyCard very, very long ago, and want to try out gui2py which looks like a nice upgrade.

Following instructions I installed wxPython2.9-win32-2.9.4.0-py27 and gui2py-0.9.3-py2x.win32. I have Python 2.7.3 (win32) on a (French) Windows 7.

Trying out the examples in gui2py-0.9.3.zip, I can run the small ones but sample.pyw gives me the following exception :

>C:\Python\pythonw -u "sample.pyw"
Traceback (most recent call last):
File "C:\Python\lib\site-packages\wx-2.9.4-msw\wx\lib\masked\numctrl.py", line 1244, in OnTextChange
value = self.GetValue()
File "C:\Python\lib\site-packages\wx-2.9.4-msw\wx\lib\masked\numctrl.py", line 1269, in GetValue
return self._fromGUI( BaseMaskedTextCtrl.GetValue(self) )
File "C:\Python\lib\site-packages\wx-2.9.4-msw\wx\lib\masked\numctrl.py", line 1660, in _fromGUI
value = self._GetNumValue(value)
File "C:\Python\lib\site-packages\wx-2.9.4-msw\wx\lib\masked\numctrl.py", line 916, in _GetNumValue
return value.replace(self._groupChar, '').replace(self._decimalChar, '.').replace('(', '-').replace(')','').strip()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
File "sample.pyw", line 172, in <module>
top='46', width='101', parent='mywin.notebook.tab0', value=98.76, )
File "D:\python\3rd-party\gui2py-0.9.3\gui\controls\textbox.py", line 43, in __init__
Control.__init__(self, *args, **kwargs)
File "D:\python\3rd-party\gui2py-0.9.3\gui\component.py", line 642, in __init__
Component.__init__(self, parent, **kwargs)
File "D:\python\3rd-party\gui2py-0.9.3\gui\component.py", line 168, in __init__
self.wx_obj = self._wx_class(wx_parent, **self._wx_kwargs)
File "D:\python\3rd-party\gui2py-0.9.3\gui\controls\textbox.py", line 293, in __init__
masked.NumCtrl.__init__(self, *args, **kwargs)
File "C:\Python\lib\site-packages\wx-2.9.4-msw\wx\lib\masked\numctrl.py", line 618, in __init__
self.SetParameters(**init_args)
File "C:\Python\lib\site-packages\wx-2.9.4-msw\wx\lib\masked\numctrl.py", line 875, in SetParameters
newtext = self._toGUI(text)
File "C:\Python\lib\site-packages\wx-2.9.4-msw\wx\lib\masked\numctrl.py", line 1570, in _toGUI
value = self._GetNumValue(value)
File "C:\Python\lib\site-packages\wx-2.9.4-msw\wx\lib\masked\numctrl.py", line 916, in _GetNumValue
return value.replace(self._groupChar, '').replace(self._decimalChar, '.').replace('(', '-').replace(')','').strip()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128)
Exception KeyError: ('mywin.notebook.tab0.numeric',) in <bound method TextBox.__del__ of gui.TextBox(id='', name='numeric', pos='', size='', alignment='right',
sizer_align='', sizer_border='', bgcolor='', client_size='',
editable='', enabled='', fgcolor='', helptext='',
parent='mywin.notebook.tab0', userdata='', visible='', onblur='',
onchange='', onfocus='', onkeydown='', onkeypress='', onkeyup='',
onmousedown='', onmousemove='', onmouseout='', onmouseover='',
onmouseup='', onmousewheel='', )> ignored

Thanks for any hint...
fp

Mariano Reingart

unread,
Sep 2, 2013, 4:20:45 PM9/2/13
to fpp, gui2py
Did you hit any special keystroke when testing?
or copied a value with the clipboard?
does it show the main screen or aborts before user interaction?

It's seems that the wxPython masked numeric control (numctrl) cannot
accept the character 0xa0 "non-breaking space":

http://en.wikipedia.org/wiki/Non-breaking_space

Maybe your locale / regional settings have that character inside the
numeric format.

On windows, you can see the default locale with:

Z:\gui2py>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'Spanish_Argentina.1252'
>>>

On linux:

reingart@s5ultra:~/pyafipws$ python
Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> print locale.getlocale()
(None, None)
>>> locale.setlocale(locale.LC_ALL, "")
'es_ES.UTF-8'
>>>

To try to solve the problem, could you add the following lines to
samples.pyw (before import gui):

# set default locale to handle correctly numeric format (maskedit):
import locale
locale.setlocale(locale.LC_ALL, "")

(attached is an example already modified)

Let me know if this solves the issue

Best regards,

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com
sample.pyw

fpp

unread,
Sep 2, 2013, 5:00:17 PM9/2/13
to gui...@googlegroups.com
Hola Mariano,

Thanks for the quick response !

No, I did not type or copy anything, as the exception happens at the very start, before anything is displayed.

My locale as shown by your code above is 'French_France.1252', and adding the lines at the start of the script does not change anything.

My guess is that the problem is with self._groupChar in line 916, because in French the thousands separator is a space, and it is perfectly possible that in this locale they made it a non-breaking, non-ascii one (it keeps large numbers together when lines wrap :-).

If I want to see the samples I think I will have to find a way to change the locale, or at least the thousands separator...

Gracias pour tu ayuda,
fp

Mariano Reingart

unread,
Sep 2, 2013, 5:57:48 PM9/2/13
to fpp, gui2py
Could you try the attached tentative patch to textbox.py (lines 279-280)?
Just download and replace your textbox.py file in the controls folder
inside gui directory.

The thousands separator is taken from locale.localeconv() conversion
settings, its seems to be returning str instead of unicode, so the
patch tries to decode it correctly:

lc = locale.localeconv()
kwargs['useFixedWidthFont'] = False
kwargs['groupChar'] = lc['mon_thousands_sep'] or ','
# ...
# fix non-breaking space 0xa0 thousands sep in French_France.1252 (win)
if isinstance(kwargs['groupChar'], str):
kwargs['groupChar'] = kwargs['groupChar'].decode("latin1", "replace")

Best regards and thank you for testing!
textbox.py

fpp

unread,
Sep 3, 2013, 3:35:27 PM9/3/13
to gui...@googlegroups.com, fpp
Yes, with the patched textbox.py the samples script runs just fine, thanks a lot ! (and it's a better fix than mine too :-)

Now I have to try the designer tool, it looks really good...

Two side questions :

1) I changed the textbox.py in the gui/controls subfolder of the gui2py-0.9.3.zip archive, where the samples are.
There is a similar folder under the Python site-packages tree where gui2py was installed.
It seems the widgets there are all older than those in the samples zip. Should I also update textbox.py in there too ?

2) Is there a sort of "canvas" widget, where I could for example put icons or thumbnails and move them around with the mouse (drag 'n drop), or is there another way of doing this in gui2py ?

TIA,
fp
Reply all
Reply to author
Forward
0 new messages