force textctrl to use ascii

I have an application where a textctrl is converting to unicode against my will and this is causing issues later in my code. If I type a quotation mark " in the textctrl, I can watch it be converted to the the curved unicode version. How do I stop this from happening? I tried adding

wx.SetDefaultPyEncoding(‘ascii’)

to the code, but it doesn’t seem to have changed anything. I would be glad to set a global setting somewhere or even just a parameter or style for the control. I just need this to go away.

Thanks,

Ryan

It was throwing errors in my code. I think I have fixed it for now.

When I read the text I call .encode() on the string that gets returned. Since sys.getdefaultencoding() returns ‘ascii’, python tries to encode the string from the textctrl as ascii by default. This throws an error.

To work around this, I had to call .encode(‘UTF-8’).

But the bigger issue in my mind is that if my application specifically required ascii text, the textctrl doesn’t seem capable of this. If I type " into the box, it gets converted to a curly UTF-8 equivalent and there doesn’t seem to be a way to get back to pure ascii. I write a lot of code to communicate over serial between python and Arduino where we need to use pure ascii. The ability to get pure ascii from a textctrl seems to be lost in wxPython 2.9.

Ryan

···

On Thu, Nov 19, 2015 at 8:21 AM, Boštjan Mejak bostjan.xperia@gmail.com wrote:

What’s wrong with UTF-8?

On Thu, Nov 19, 2015, 14:26 Ryan Krauss ryanlists@gmail.com wrote:

I have an application where a textctrl is converting to unicode against my will and this is causing issues later in my code. If I type a quotation mark " in the textctrl, I can watch it be converted to the the curved unicode version. How do I stop this from happening? I tried adding

wx.SetDefaultPyEncoding(‘ascii’)

to the code, but it doesn’t seem to have changed anything. I would be glad to set a global setting somewhere or even just a parameter or style for the control. I just need this to go away.

Thanks,

Ryan

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

I’m using Python 2.7 with wxPython 2.8 and Python 3.4 with Phoenix
under Windows and have never observed such strange behaviour.
What platform are you using?
As suggested, please try Phoenix. If you still have the problem, it
would probably be the best to provide a code example. For Windows, I
can test and try to find out the root cause.
Regards,
Dietmar

···

Am 19.11.2015 um 15:45 schrieb Boštjan
Mejak:

    Please use wxPython Phoenix instead, it handles

non-ASCII characters quite elegantly.

On Thu, Nov 19, 2015, 15:43 Ryan Krauss < >
wrote:

          The ability to get pure ascii from a textctrl seems to

be lost in wxPython 2.9.

ryanlists@gmail.com

When I read the text I call .encode() on the string that gets returned.

you really never want to call a bare encode() -- if you want something
encoded, you should darn well know what you want it encoded to!

Since sys.getdefaultencoding() returns 'ascii', python tries to encode the
string from the textctrl as ascii by default. This throws an error.

To work around this, I had to call .encode('UTF-8').

why are you encoding it anyway? If you are passing it off to something that
really, really requires ASCII, then UTF-8 is going to break it anyway --
even though the encode call won't fail. But if, for instance the unicode
string has a LEFT DOUBLE QUOTATION MARK character, then that will get
encoded as multibyte in utf-8, and that may make something downstream barf.
You really don't want to push this can down the road.

So you should probably encode to ascii, but with "replace" or something so
it won't barf: "ignore"
or "replace".

But the bigger issue in my mind is that if my application specifically

required ascii text, the textctrl doesn't seem capable of this.

it used to be possible to get an ascii build of wx -- but that may not be
an option anymore.

If I type " into the box, it gets converted to a curly UTF-8 equivalent

just to be a bit pedantic here -- it's not a UTF-8 anyting -- it's
apparently a unicode LEFT DOUBLE QUOTATION MARK character -- which is
actualy really really , weird -- I seriously doubt that wx has anything to
do with it -- the native control must be replacing it -- but THAT has got
to be something you can turn off -- you _might_want that in a fancy-dancy
word processor ,-- but you sure as heck wouldn't' want it in programmers
text editor.

what platform/version, etc are you seeing this on ?

and what widget?

-CHB

···

On Thu, Nov 19, 2015 at 6:43 AM, Ryan Krauss <ryanlists@gmail.com> wrote:

and there doesn't seem to be a way to get back to pure ascii. I write a
lot of code to communicate over serial between python and Arduino where we
need to use pure ascii. The ability to get pure ascii from a textctrl
seems to be lost in wxPython 2.9.

Ryan

On Thu, Nov 19, 2015 at 8:21 AM, Boštjan Mejak <bostjan.xperia@gmail.com> > wrote:

What's wrong with UTF-8?

On Thu, Nov 19, 2015, 14:26 Ryan Krauss <ryanlists@gmail.com> wrote:

I have an application where a textctrl is converting to unicode against
my will and this is causing issues later in my code. If I type a quotation
mark " in the textctrl, I can watch it be converted to the the curved
unicode version. How do I stop this from happening? I tried adding

wx.SetDefaultPyEncoding('ascii')

to the code, but it doesn't seem to have changed anything. I would be
glad to set a global setting somewhere or even just a parameter or style
for the control. I just need this to go away.

Thanks,

Ryan

--
You received this message because you are subscribed to the Google
Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

I am using wxPython 2.9 where ansi/pure ascii is no longer an option. I am running OSX 10.10.5 Yosemite. I have python 2.7.

I don’t remember upgrading wxPython since this problem started. It is possible the upgrade to Yosemite caused it.

I will try and put together a minimum working example that causes the issue.

···

On Thu, Nov 19, 2015 at 3:25 PM, Chris Barker chris.barker@noaa.gov wrote:

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

On Thu, Nov 19, 2015 at 6:43 AM, Ryan Krauss ryanlists@gmail.com wrote:

When I read the text I call .encode() on the string that gets returned.

you really never want to call a bare encode() – if you want something encoded, you should darn well know what you want it encoded to!

Since sys.getdefaultencoding() returns ‘ascii’, python tries to encode the string from the textctrl as ascii by default. This throws an error.

To work around this, I had to call .encode(‘UTF-8’).

why are you encoding it anyway? If you are passing it off to something that really, really requires ASCII, then UTF-8 is going to break it anyway – even though the encode call won’t fail. But if, for instance the unicode string has a LEFT DOUBLE QUOTATION MARK character, then that will get encoded as multibyte in utf-8, and that may make something downstream barf. You really don’t want to push this can down the road.

So you should probably encode to ascii, but with “replace” or something so it won’t barf: “ignore”
or “replace”.

But the bigger issue in my mind is that if my application specifically required ascii text, the textctrl doesn’t seem capable of this.

it used to be possible to get an ascii build of wx – but that may not be an option anymore.

If I type " into the box, it gets converted to a curly UTF-8 equivalent

just to be a bit pedantic here – it’s not a UTF-8 anyting – it’s apparently a unicode LEFT DOUBLE QUOTATION MARK character – which is actualy really really , weird – I seriously doubt that wx has anything to do with it – the native control must be replacing it – but THAT has got to be something you can turn off – you _might_want that in a fancy-dancy word processor ,-- but you sure as heck wouldn’t’ want it in programmers text editor.

what platform/version, etc are you seeing this on ?

and what widget?

-CHB

and there doesn’t seem to be a way to get back to pure ascii. I write a lot of code to communicate over serial between python and Arduino where we need to use pure ascii. The ability to get pure ascii from a textctrl seems to be lost in wxPython 2.9.

Ryan

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

On Thu, Nov 19, 2015 at 8:21 AM, Boštjan Mejak bostjan.xperia@gmail.com wrote:

What’s wrong with UTF-8?

On Thu, Nov 19, 2015, 14:26 Ryan Krauss ryanlists@gmail.com wrote:

I have an application where a textctrl is converting to unicode against my will and this is causing issues later in my code. If I type a quotation mark " in the textctrl, I can watch it be converted to the the curved unicode version. How do I stop this from happening? I tried adding

wx.SetDefaultPyEncoding(‘ascii’)

to the code, but it doesn’t seem to have changed anything. I would be glad to set a global setting somewhere or even just a parameter or style for the control. I just need this to go away.

Thanks,

Ryan

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

I am using wxPython 2.9 where ansi/pure ascii is no longer an option. I am running OSX 10.10.5 Yosemite. I have python 2.7.

I can’t recall – is 32 bit and Carbon still an option? I doubt the Carbon libs would do this.

I don’t remember upgrading wxPython since this problem started. It is possible the upgrade to Yosemite caused it

Could be – it sure seems that it’s the system widget that’s replacing the quote character.

CHB

···

On Thu, Nov 19, 2015 at 3:25 PM, Chris Barker chris.barker@noaa.gov wrote:

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

On Thu, Nov 19, 2015 at 6:43 AM, Ryan Krauss ryanlists@gmail.com wrote:

When I read the text I call .encode() on the string that gets returned.

you really never want to call a bare encode() – if you want something encoded, you should darn well know what you want it encoded to!

Since sys.getdefaultencoding() returns ‘ascii’, python tries to encode the string from the textctrl as ascii by default. This throws an error.

To work around this, I had to call .encode(‘UTF-8’).

why are you encoding it anyway? If you are passing it off to something that really, really requires ASCII, then UTF-8 is going to break it anyway – even though the encode call won’t fail. But if, for instance the unicode string has a LEFT DOUBLE QUOTATION MARK character, then that will get encoded as multibyte in utf-8, and that may make something downstream barf. You really don’t want to push this can down the road.

So you should probably encode to ascii, but with “replace” or something so it won’t barf: “ignore”
or “replace”.

But the bigger issue in my mind is that if my application specifically required ascii text, the textctrl doesn’t seem capable of this.

it used to be possible to get an ascii build of wx – but that may not be an option anymore.

If I type " into the box, it gets converted to a curly UTF-8 equivalent

just to be a bit pedantic here – it’s not a UTF-8 anyting – it’s apparently a unicode LEFT DOUBLE QUOTATION MARK character – which is actualy really really , weird – I seriously doubt that wx has anything to do with it – the native control must be replacing it – but THAT has got to be something you can turn off – you _might_want that in a fancy-dancy word processor ,-- but you sure as heck wouldn’t’ want it in programmers text editor.

what platform/version, etc are you seeing this on ?

and what widget?

-CHB

and there doesn’t seem to be a way to get back to pure ascii. I write a lot of code to communicate over serial between python and Arduino where we need to use pure ascii. The ability to get pure ascii from a textctrl seems to be lost in wxPython 2.9.

Ryan

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

On Thu, Nov 19, 2015 at 8:21 AM, Boštjan Mejak bostjan.xperia@gmail.com wrote:

What’s wrong with UTF-8?

On Thu, Nov 19, 2015, 14:26 Ryan Krauss ryanlists@gmail.com wrote:

I have an application where a textctrl is converting to unicode against my will and this is causing issues later in my code. If I type a quotation mark " in the textctrl, I can watch it be converted to the the curved unicode version. How do I stop this from happening? I tried adding

wx.SetDefaultPyEncoding(‘ascii’)

to the code, but it doesn’t seem to have changed anything. I would be glad to set a global setting somewhere or even just a parameter or style for the control. I just need this to go away.

Thanks,

Ryan

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Hi,

I am using wxPython 2.9 where ansi/pure ascii is no longer an option. I am
running OSX 10.10.5 Yosemite. I have python 2.7.

I can't recall -- is 32 bit and Carbon still an option? I doubt the Carbon
libs would do this.

It is, but but for wxPython 2.9+ it is advisable to get the Cocoa package.
IIRC, Carbon was stopped sometimes around 2.9.0.

Thank you.

···

On Fri, Nov 20, 2015 at 11:28 AM, Chris Barker - NOAA Federal <chris.barker@noaa.gov> wrote:

I don't remember upgrading wxPython since this problem started. It is
possible the upgrade to Yosemite caused it

Could be -- it sure seems that it's the system widget that's replacing the
quote character.

CHB

I will try and put together a minimum working example that causes the issue.

On Thu, Nov 19, 2015 at 3:25 PM, Chris Barker <chris.barker@noaa.gov> wrote:

On Thu, Nov 19, 2015 at 6:43 AM, Ryan Krauss <ryanlists@gmail.com> wrote:

When I read the text I call .encode() on the string that gets returned.

you really never want to call a bare encode() -- if you want something
encoded, you should darn well know what you want it encoded to!

Since sys.getdefaultencoding() returns 'ascii', python tries to encode
the string from the textctrl as ascii by default. This throws an error.

To work around this, I had to call .encode('UTF-8').

why are you encoding it anyway? If you are passing it off to something
that really, really requires ASCII, then UTF-8 is going to break it anyway
-- even though the encode call won't fail. But if, for instance the unicode
string has a LEFT DOUBLE QUOTATION MARK character, then that will get
encoded as multibyte in utf-8, and that may make something downstream barf.
You really don't want to push this can down the road.

So you should probably encode to ascii, but with "replace" or something so
it won't barf: "ignore"
or "replace".

But the bigger issue in my mind is that if my application specifically
required ascii text, the textctrl doesn't seem capable of this.

it used to be possible to get an ascii build of wx -- but that may not be
an option anymore.

If I type " into the box, it gets converted to a curly UTF-8 equivalent

just to be a bit pedantic here -- it's not a UTF-8 anyting -- it's
apparently a unicode LEFT DOUBLE QUOTATION MARK character -- which is
actualy really really , weird -- I seriously doubt that wx has anything to
do with it -- the native control must be replacing it -- but THAT has got to
be something you can turn off -- you _might_want that in a fancy-dancy word
processor ,-- but you sure as heck wouldn't' want it in programmers text
editor.

what platform/version, etc are you seeing this on ?

and what widget?

-CHB

and there doesn't seem to be a way to get back to pure ascii. I write a
lot of code to communicate over serial between python and Arduino where we
need to use pure ascii. The ability to get pure ascii from a textctrl seems
to be lost in wxPython 2.9.

Ryan

On Thu, Nov 19, 2015 at 8:21 AM, Boštjan Mejak <bostjan.xperia@gmail.com> >>> wrote:

What's wrong with UTF-8?

On Thu, Nov 19, 2015, 14:26 Ryan Krauss <ryanlists@gmail.com> wrote:

I have an application where a textctrl is converting to unicode against
my will and this is causing issues later in my code. If I type a quotation
mark " in the textctrl, I can watch it be converted to the the curved
unicode version. How do I stop this from happening? I tried adding

wx.SetDefaultPyEncoding('ascii')

to the code, but it doesn't seem to have changed anything. I would be
glad to set a global setting somewhere or even just a parameter or style for
the control. I just need this to go away.

Thanks,

Ryan

--
You received this message because you are subscribed to the Google
Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google
Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yes, it's probably not a bug, it's a feature of the OS: https://support.apple.com/kb/PH18439?locale=en_US

Regards,

Dietmar

···

Am 20.11.2015 um 13:49 schrieb Ryan Krauss:

I am using wxPython 2.9 where ansi/pure ascii is no longer an option. I am running OSX 10.10.5 Yosemite. I have python 2.7.

I don't remember upgrading wxPython since this problem started. It is possible the upgrade to Yosemite caused it.

Yes, it's probably not a bug, it's a feature of the OS:
https://support.apple.com/kb/PH18439?locale=en_US

sigh. nice feature, and it looks like it is configurable on an application
level. Indeed, checking out textedit it's there. But it really, really
shouldn't default to replacement behavior.

The trick now it to figure out how to programmatically turn it off.

sigh.

-CHB

···

On Fri, Nov 20, 2015 at 10:28 AM, Dietmar Schwertberger < maillist@schwertberger.de> wrote:

Am 20.11.2015 um 13:49 schrieb Ryan Krauss:

Regards,

Dietmar

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

This behaviour is still default in macOS Monterey. Apple link is not available anymore but I guess it explained:
To fix this behaviour go to System Preferences > open the “Text” tab > uncheck “Use smart quotes and dashes”