changing fonts?

Discussion in 'Python' started by Guest, Dec 8, 2007.

  1. Guest

    Guest Guest

    This is probably a silly question, but alas, I'll ask it anyway...

    Is it possible with Python, to change the font of the text returned in the Terminal Window in OS X? For example, lets say I'm running a Python program in Terminal, and it asks me "Please enter an English word to be changed to Greek:". So I then enter "bread". Is it possible for the next answer that Python returns in the Terminal Window to be displayed in the 'Symbols' font so that the Greek text is displayed correctly? I have my doubts, but thought I'd ask.

    Thanks!

    Jay
    Guest, Dec 8, 2007
    #1
    1. Advertising

  2. Guest

    greg Guest

    wrote:

    > Is it possible for the next answer that Python returns in the
    > Terminal Window to be displayed in the 'Symbols' font so that the
    > Greek text is displayed correctly?


    I don't think you can control the font, but you can print
    out the Greek text as utf8-encoded unicode. I just tried
    an experiment and managed to get Greek letters displayed
    this way.

    I had to turn off the "Wide Glyphs for Japanese/Chinese etc."
    option under File/Get Info to get the spacing to come out
    right.

    --
    Greg
    greg, Dec 8, 2007
    #2
    1. Advertising

  3. Guest

    Doug Morse Guest

    Hi Jay,

    I'm not *that* familiar with the Terminal program on OS/X, but regardless
    perhaps I can point out a possibly useful path to explore...

    With terminal programs generally -- especially more in the past, as then they
    were much more about emulating "real" terminals -- a lot of the terminal
    progam's behavior and configuration could be controlled with what are called
    "escape sequences".

    Escape sequences were named as such because, most often, these control
    sequences were output from the computer to the terminal (often over a serial
    port) and, crucially, started with the escape character (ASCII 27, also known
    as Ctrl-]). This escape character signaled to the terminal that the output
    arriving from the computer was not to be displayed, but rather flagged the
    output as control information for the terminal itself, such as "switch to
    boldface", "change the text color to blue", "move the cursor to position 11,
    43", or "change your character set to Latin-1", etc.

    (My apologies if you already know this stuff. It's necessary background,
    though, so I figured better to include it just in case...)

    So, hopefully you can see where I'm going with this. It's quite possible that
    OS/X's Terminal window understands a certain escape sequence to instruct it
    change the active font as well (since it's an Xterm emulator, I'm confident
    that escape sequences are used to control typeface, cursor location, text
    color, and many other things). If so, then having Python change the font is
    simply a matter of having your Python program emit the correct escape sequence
    at the time you desire the font to change. Note, however, that the font will
    most likely change for the ENTIRE Terminal screen, all at once. Historically,
    while many "real" terminals might have supported multiple fonts, very few
    supported multiple fonts SIMULTANEOUSLY. Terminal emulators such as OS/X's
    Terminal, being based on the "real" terminals of days past, generally behave
    in the same way.

    So, the good news is that this could be pretty easy to implement. The trick,
    however, will be figuring out if such an escape sequence exists for Terminal,
    and, if so, what it is. Google is your friend. Also, check out the termcap
    and/or terminfo entries -- /etc/termcap and (probably)
    /usr/share/terminfo/*/*, respectively -- for Terminal's TERM type. If such an
    escape sequence exists, it might well already be documented in one or both of
    these terminal databases.

    The only other alternative that readily comes to mind is that perhaps there's
    some programmatic interface to Terminal to tell it to change it's font. I
    tend to doubt this, but if it does exist then it will likely involve IPC
    (inter-process communication) and not be trival to implement (although not
    outrageously hard, either) -- you'd have to establish a connection between
    Python and the correct Terminal instance, and then send the right IPC message.

    Also, I guess that perhaps Terminal might even accepts signals to change its
    font (again, doubtful though). Check out Terminal's manual page (i.e., run
    "man Terminal") and see what signals it accepts and what they do. If you find
    one that changes the font, then just running something like "kill -SIGXXX
    999999" might work (where SIGXXX is a real and valid signal name and 999999 is
    a real and valid process number for the correct Terminal instance).

    I hope this is helpful, at least in terms of the alternative you have before
    you (as I see them): escape sequences, some sort of IPC, or system signals.
    Again, I think you might get luckly with the first option, whereas I have
    serious doubts that Terminal supports the latter two options (but ya never
    know...)

    Good luck,
    Doug

    P.S. -- I just realized that you probably need to switch Terminal's CHARACTER
    SET, not it's FONT. That said, though, everything I wrote is still applicable
    -- just replace "character set" wherever I talk about "font". Plus, I think
    there's a MUCH higher probability that there exists escape sequences to switch
    Terminal's active character set (as compared to switching its font). However,
    you may run into the problem that -- as I described as a possibility
    concerning fonts -- Terminal might not be able to display but one character
    set at a time (i.e., it can only change the character set for the entire
    window at once), which could be add odds with your requirements. If Terminal
    can only have one active character set at a time, then IF there's a character
    set it supports that has BOTH Greek and English characters, you'd still be
    able to pull it off. A lot of the European character sets ARE like this
    (i.e., English chars mixed with specific European chars) -- but not the Symbol
    character set, I believe -- so I suspect that you're in good luck! Once you
    can successfully switch character sets, it's probably then just a matter of
    tooling around with different character sets to see which one works for your
    needs. For this stuff, provided OS/X has it, the program tput will definitely
    Be Your Friend. Run "man tput" (and/or Google "terminfo tput") to learn more.


    On Fri, 7 Dec 2007 19:55:50 -0600, <>
    <> wrote:
    > This is probably a silly question, but alas, I'll ask it anyway...
    >
    > Is it possible with Python, to change the font of the text returned in the
    > Terminal Window in OS X? For example, lets say I'm running a Python
    > program in Terminal, and it asks me "Please enter an English word to be
    > changed to Greek:". So I then enter "bread". Is it possible for the next
    > answer that Python returns in the Terminal Window to be displayed in the
    > 'Symbols' font so that the Greek text is displayed correctly? I have my
    > doubts, but thought I'd ask.
    >
    > Thanks!
    >
    > Jay
    Doug Morse, Dec 8, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Benner

    Changing fonts in a JTable header

    Tim Benner, Nov 6, 2003, in forum: Java
    Replies:
    1
    Views:
    12,755
    Matthew Zimmer
    Nov 6, 2003
  2. Antoni
    Replies:
    1
    Views:
    824
    Andrew Thompson
    May 10, 2004
  3. bim_bom

    How to disable changing fonts?

    bim_bom, Aug 19, 2006, in forum: HTML
    Replies:
    7
    Views:
    417
    Andy Dingley
    Aug 21, 2006
  4. Guest

    changing fonts?

    Guest, Dec 8, 2007, in forum: Python
    Replies:
    0
    Views:
    291
    Guest
    Dec 8, 2007
  5. sam
    Replies:
    0
    Views:
    405
Loading...

Share This Page