Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62082 > unrolled thread
| Started by | wmcbrine@gmail.com |
|---|---|
| First post | 2013-12-16 09:32 -0800 |
| Last post | 2013-12-20 01:18 -0800 |
| Articles | 6 — 3 participants |
Back to article view | Back to comp.lang.python
Determining whether a glyph is available in Tkinter wmcbrine@gmail.com - 2013-12-16 09:32 -0800
Re: Determining whether a glyph is available in Tkinter Terry Reedy <tjreedy@udel.edu> - 2013-12-16 14:41 -0500
Re: Determining whether a glyph is available in Tkinter wmcbrine@gmail.com - 2013-12-16 15:59 -0800
Re: Determining whether a glyph is available in Tkinter Terry Reedy <tjreedy@udel.edu> - 2013-12-16 22:58 -0500
Re: Determining whether a glyph is available in Tkinter wmcbrine@gmail.com - 2013-12-19 15:10 -0800
Re: Determining whether a glyph is available in Tkinter wxjmfauth@gmail.com - 2013-12-20 01:18 -0800
| From | wmcbrine@gmail.com |
|---|---|
| Date | 2013-12-16 09:32 -0800 |
| Subject | Determining whether a glyph is available in Tkinter |
| Message-ID | <f84fbcb9-e784-4a2a-9c27-d55136e3c7b2@googlegroups.com> |
I have a Tkinter app that can optionally label some buttons with certain Unicode glyphs that aren't always available (depending on the OS, etc.). When they aren't available, Tkinter renders them as "\uNNNN". What I'd like to do is check whether the glyphs are available, and fall back to my own alternate text for the button if not. Can I do this? I'd also like to do the same in pygtk.
[toc] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-12-16 14:41 -0500 |
| Message-ID | <mailman.4233.1387222873.18130.python-list@python.org> |
| In reply to | #62082 |
On 12/16/2013 12:32 PM, wmcbrine@gmail.com wrote: > I have a Tkinter app that can optionally label some buttons with > certain Unicode glyphs that aren't always available (depending on the > OS, etc.). It depends on the font in use. The best scenario would be to always use the same unicode font. Idle, built on tkinter, has a configuration dialog that gets a list of available fonts and sets the one the user selects. I use Lucida Sans Unicode. It is not very pretty, but it seems to cover much the BMP. AFAIK, it should be available on all Windows from XP on. I do not know what comes with *nix and mac, but from reading https://en.wikipedia.org/wiki/Unicode_font#List_of_Unicode_fonts there seem to be TrueType fonts that you could install with your software: FreeSerif (etc), GNU Unifont, (both GPL), BitstreamCyber (free for non-commercial use). The font table linked above is followed by table indicating something about coverage. Unifont is the champ. > When they aren't available, Tkinter renders them as > "\uNNNN". What I'd like to do is check whether the glyphs are > available, and fall back to my own alternate text for the button if > not. Can I do this? Don't know. See the 'Utility software' section of the page above. > I'd also like to do the same in pygtk. No idea. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | wmcbrine@gmail.com |
|---|---|
| Date | 2013-12-16 15:59 -0800 |
| Message-ID | <c2a0c7e1-4983-4187-b35f-8f7c0ae834e5@googlegroups.com> |
| In reply to | #62095 |
I'm not going to control the font. This is for a program that's distributed to the general public, for use on a wide variety of systems. But what I do in the current version is to use the ASCII label strings by default, and have a command-line option to select the "graphical" (non-ASCII Unicode) labels. What I want is to make the graphical labels the default, and have the program detect, at runtime, whether any of the glyphs used in the fancy labels would render as "\uNNNN" in whatever the default font for the buttons is, and automatically revert to the ASCII labels in that case. I'm assuming this is possible, because Tkinter itself seems to know which glyphs are unavailable, or they'd probably be showing up as those boxed number characters or question marks instead of "\uNNNN".
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-12-16 22:58 -0500 |
| Message-ID | <mailman.4255.1387252699.18130.python-list@python.org> |
| In reply to | #62118 |
On 12/16/2013 6:59 PM, wmcbrine@gmail.com wrote:
> I'm not going to control the font.
Tk widgets that display text must use *some* font. If you do not select
one, then you get the system-dependent default.
for k, v in tk.Text().configure().items(): print(k, v)
...
font ('font', 'font', 'Font', <font object: 'TkFixedFont'>, 'TkFixedFont')
TkTextFont may be preferable for your purposes, although on Windows both
might be Courier New.
> This is for a program that's
> distributed to the general public, for use on a wide variety of
> systems. But what I do in the current version is to use the ASCII
> label strings by default, and have a command-line option to select
> the "graphical" (non-ASCII Unicode) labels. What I want is to make
> the graphical labels the default, and have the program detect, at
> runtime, whether any of the glyphs used in the fancy labels would
> render as "\uNNNN" in whatever the default font for the buttons is,
> and automatically revert to the ASCII labels in that case.
I would not assume that the default covers more than ascii.
But to answer your question, this might work: fonts have a measure()
method that returns what the pixel length of a string would be if it
were to be displayed.
>>> import tkinter.font as tkf
>>> ft=tkf.Font(font='TkFixedFont')
>>> ft.metrics()
{'ascent': 17, 'descent': 5, 'fixed': 1, 'linespace': 22}
>>> ft.measure('a')
12
>>> ft.measure('\u9fff')
12
*If* the measure is, say, 50 or more for a character that would display
as \uNNNN, then you would know. Go ahead and experiment.
> I'm assuming this is possible, because Tkinter itself seems to know
> which glyphs are unavailable, or they'd probably be showing up as
> those boxed number characters or question marks instead of "\uNNNN".
I do not know whether it is tk itself or a system graphics call that
translates a sequence of codes to pixels on the screen.
--
Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | wmcbrine@gmail.com |
|---|---|
| Date | 2013-12-19 15:10 -0800 |
| Message-ID | <31f4e87b-dad7-4bdc-a703-07964cc8c1d1@googlegroups.com> |
| In reply to | #62143 |
On Monday, December 16, 2013 10:58:06 PM UTC-5, Terry Reedy wrote: > I would not assume that the default covers more than ascii. In this case, I already know that the glyphs I chose work with the default fonts for OS X 10.4+ and Windows 7+, but not for (for example) Win XP. > But to answer your question, this might work: fonts have a measure() > method that returns what the pixel length of a string would be if it > were to be displayed. Thanks. Unfortunately, measure() doesn't seem to do the trick -- it's giving me answers that look like normal single-width characters, for glyphs that actually render as \uNNNN. Oh well. :/
[toc] | [prev] | [next] | [standalone]
| From | wxjmfauth@gmail.com |
|---|---|
| Date | 2013-12-20 01:18 -0800 |
| Message-ID | <cbf37d68-c8e0-45a1-ae8d-138a4b37fe9c@googlegroups.com> |
| In reply to | #62419 |
Le vendredi 20 décembre 2013 00:10:58 UTC+1, wmcb...@gmail.com a écrit : > On Monday, December 16, 2013 10:58:06 PM UTC-5, Terry Reedy wrote: > > > In this case, I already know that the glyphs I chose work with the default fonts for OS X 10.4+ and Windows 7+, but not for (for example) Win XP. > > As I pointed in an another thread, Windows 7 is the first Windows which became full unicode compliant (0th order approximation). If your application works fine with win7, good. If it does not on XP, it's like this. --- Font: I do not know what glyphs you "need". Do not expect to find always a single font that will cover your needs. It's a little bit a side effect of "unicode", but everything has been constructed to be a no problem. And it is a no problem. jmf
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web