Re: Unicode range

Vasilis Vlachoudis <[email protected]> Mon, 4 Jan 2021 19:08:56 +0000
Newsgroups gmane.comp.python.tkinter
Message-ID <[email protected]>
--===============8401276977868533037==
Content-Language: en-US
Content-Type: multipart/alternative;
	boundary="_000_0BC70B5D93E054469872FFD0FE07220E0312E09E75CERNXCHG51cer_"

--_000_0BC70B5D93E054469872FFD0FE07220E0312E09E75CERNXCHG51cer_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Many thanks Nam,

I followed your suggestion and modified a bit as
_UNICODE_RANGE =3D re.compile(u'[^\u0000-\uFFFF]', re.UNICODE)
...
except tk.TclError:
    # when it fails try to remove unicode outside the accepted range
    self.text.insert("0.0", _UNICODE_RANGE.sub("?",log.messages))

which is faster

Vasilis

________________________________
From: Nam Nguyen [[email protected]]
Sent: Monday, January 04, 2021 18:39
To: Vasilis Vlachoudis
Cc: [email protected]
Subject: Re: [Tkinter-discuss] Unicode range

Hi Vasilis,

Perhaps by removing characters that are outside of that range?

The error message gives you a range, from 0 to 65535. So this line might do=
.

s =3D ''.join(c for c in s if 0 < ord(c) < 65535)

Cheers,
Nam

On Mon, Jan 4, 2021 at 1:25 AM Vasilis Vlachoudis <Vasilis.Vlachoudis@cern.=
ch<mailto:[email protected]>> wrote:
Hi all,

how can I "replace/strip" unicode characters that are out of the accepted t=
k range before inserting them to Text()?

  File "/usr/lib/python3.6/tkinter/__init__.py", line 3272, in insert
    self.tk.call((self._w, 'insert', index, chars) + args)
_tkinter.TclError: character U+1c784 is above the range (U+0000-U+FFFF) all=
owed by Tcl

Vasilis
_______________________________________________
Tkinter-discuss mailing list
[email protected]<mailto:[email protected]>
https://mail.python.org/mailman/listinfo/tkinter-discuss

--_000_0BC70B5D93E054469872FFD0FE07220E0312E09E75CERNXCHG51cer_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html dir=3D"ltr">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" id=3D"owaParaStyle"></style>
</head>
<body fpstyle=3D"1" ocsi=3D"0">
<div style=3D"direction: ltr;font-family: Tahoma;color: #000000;font-size: =
10pt;">Many thanks Nam,
<div><br>
</div>
<div>I followed your suggestion and modified a bit as</div>
<div><font face=3D"Segoe UI, Helvetica, Arial, sans-serif"><span style=3D"f=
ont-size: 13.3333px;">_UNICODE_RANGE =3D re.compile(u'[^\u0000-\uFFFF]', re=
.UNICODE)</span></font></div>
<div><font face=3D"Segoe UI, Helvetica, Arial, sans-serif"><span style=3D"f=
ont-size: 13.3333px;">...</span></font></div>
<div><font face=3D"Segoe UI, Helvetica, Arial, sans-serif"><span style=3D"f=
ont-size: 13.3333px;">except tk.TclError:</span></font></div>
<div><font face=3D"Segoe UI, Helvetica, Arial, sans-serif">&nbsp; &nbsp; # =
when it fails try to remove unicode outside the accepted range</font></div>
<div><font face=3D"Segoe UI, Helvetica, Arial, sans-serif"><span style=3D"f=
ont-size: 13.3333px;">&nbsp; &nbsp; self.text.insert(&quot;0.0&quot;, _UNIC=
ODE_RANGE.sub(&quot;?&quot;,log.messages))</span><br>
</font>
<div>
<div style=3D"font-family:Tahoma; font-size:13px">
<div style=3D"font-size:13px; font-family:Tahoma">
<div style=3D"font-size:13px; font-family:Tahoma"><font size=3D"1"><span st=
yle=3D"font-family:Helvetica"><br>
</span></font></div>
<div style=3D"font-size:13px; font-family:Tahoma"><font size=3D"1"><span st=
yle=3D"font-family:Helvetica">which is faster</span></font></div>
<div style=3D"font-size:13px; font-family:Tahoma"><br>
</div>
<div style=3D"font-size:13px; font-family:Tahoma">Vasilis</div>
<div style=3D"font-size:13px; font-family:Tahoma"><font size=3D"1"><span st=
yle=3D"font-family:Helvetica"><br>
</span></font></div>
</div>
</div>
</div>
<div style=3D"font-family: Times New Roman; color: #000000; font-size: 16px=
">
<hr tabindex=3D"-1">
<div id=3D"divRpF30385" style=3D"direction: ltr;"><font face=3D"Tahoma" siz=
e=3D"2" color=3D"#000000"><b>From:</b> Nam Nguyen [[email protected]]<br=
>
<b>Sent:</b> Monday, January 04, 2021 18:39<br>
<b>To:</b> Vasilis Vlachoudis<br>
<b>Cc:</b> [email protected]<br>
<b>Subject:</b> Re: [Tkinter-discuss] Unicode range<br>
</font><br>
</div>
<div></div>
<div>
<div dir=3D"ltr">
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace">Hi V=
asilis,</div>
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace"><br>
</div>
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace">Perh=
aps by removing characters that are outside of that range?</div>
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace"><br>
</div>
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace">The =
error message gives you a range, from 0 to 65535. So this line might&nbsp;d=
o.</div>
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace"><br>
</div>
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace">s =
=3D ''.join(c for c in s if 0 &lt; ord(c) &lt; 65535)</div>
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace"><br>
</div>
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace">Chee=
rs,</div>
<div class=3D"gmail_default" style=3D"font-family:monospace,monospace">Nam<=
/div>
</div>
<br>
<div class=3D"gmail_quote">
<div dir=3D"ltr" class=3D"gmail_attr">On Mon, Jan 4, 2021 at 1:25 AM Vasili=
s Vlachoudis &lt;<a href=3D"mailto:[email protected]" target=3D"_b=
lank" rel=3D"noopener noreferrer">[email protected]</a>&gt; wrote:=
<br>
</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex; border=
-left:1px solid rgb(204,204,204); padding-left:1ex">
<div>
<div style=3D"direction:ltr; font-family:Tahoma; color:rgb(0,0,0); font-siz=
e:10pt">
<div>
<div>
<div><font face=3D"Segoe UI, Helvetica, Arial, sans-serif"><span style=3D"f=
ont-size:13.3333px">Hi all,</span></font></div>
<div><font face=3D"Segoe UI, Helvetica, Arial, sans-serif"><span style=3D"f=
ont-size:13.3333px"><br>
</span></font></div>
<div><font face=3D"Segoe UI, Helvetica, Arial, sans-serif"><span style=3D"f=
ont-size:13.3333px">how can I &quot;replace/strip&quot; unicode characters =
that are out of the accepted tk range before inserting them to Text()?</spa=
n></font></div>
<div style=3D"font-family:Tahoma; font-size:13px"><span style=3D"font-famil=
y:&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif; font-size:13.3333px"><br=
>
</span></div>
<div style=3D"font-family:Tahoma; font-size:13px"><span style=3D"font-famil=
y:&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif; font-size:13.3333px">&nb=
sp; File &quot;/usr/lib/python3.6/tkinter/__init__.py&quot;, line 3272, in =
insert</span><br style=3D"font-family:&quot;Segoe UI&quot;,Helvetica,Arial,=
sans-serif; font-size:13.3333px">
<span style=3D"font-family:&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif;=
 font-size:13.3333px">&nbsp;&nbsp;&nbsp; self.tk.call((self._w, 'insert', i=
ndex, chars) &#43; args)</span><br style=3D"font-family:&quot;Segoe UI&quot=
;,Helvetica,Arial,sans-serif; font-size:13.3333px">
<span style=3D"font-family:&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif;=
 font-size:13.3333px">_tkinter.TclError: character U&#43;1c784 is above the=
 range (U&#43;0000-U&#43;FFFF) allowed by Tcl</span></div>
<div style=3D"font-family:Tahoma; font-size:13px"><span style=3D"font-famil=
y:&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif; font-size:13.3333px"><br=
>
</span></div>
<div style=3D"font-family:Tahoma; font-size:13px"><span style=3D"font-famil=
y:&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif; font-size:13.3333px">Vas=
ilis</span></div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
Tkinter-discuss mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank" rel=3D"noop=
ener noreferrer">[email protected]</a><br>
<a href=3D"https://mail.python.org/mailman/listinfo/tkinter-discuss" rel=3D=
"noreferrer" target=3D"_blank">https://mail.python.org/mailman/listinfo/tki=
nter-discuss</a><br>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

--_000_0BC70B5D93E054469872FFD0FE07220E0312E09E75CERNXCHG51cer_--

--===============8401276977868533037==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tkinter-discuss mailing list
[email protected]
https://mail.python.org/mailman/listinfo/tkinter-discuss

--===============8401276977868533037==--