Append/Write of wx.TextCtrl for already aligned column of text input

Dear all,

I have a question related with the wx.TextCtrl. I have a background
subprocess for an application with outputs aligned in columns, as
follows.

[system] -> standard sys
[back] -> xxxx xxxxxx
[utilities] -> commands
[arbi] -> yyy
[code] -> code

the "->" and the following text are all left aligned in 2nd column and
3rd column,

Based on the above, I guess, the application uses the following code
to align the outputs in columns and print to the stdout.

printf("%-20s%-5s%s\n", $Var1, $Var2,$Var3).

Now I am developing a GUI, and use the wx.TextCtrl to directly log
out the application outputs, briefly the code is as follows:

child = Popen("App", shell=False, stdout=PIPE)
char=child.stdout.read(1)
textctrl = wx.TextCtrl(self, -1, '', style=wx.TE_PROCESS_ENTER|
wx.TE_MULTILINE)
textctrl.WriteText(char)

However, the output on TextCtrl is not left aligned in columns. it is
as follows.
[system] -> standard sys
[back] -> xxxx xxxxxx
[utilities] -> commands
[arbi] -> yyy
[code] -> code

I thought I should get the exactly the same output format. So what is
happening? what should I do to make the output aligned in columns?

Thanks for any suggestions.

Hi,

···

On Mon, Feb 7, 2011 at 8:12 AM, pploo <beilushao@gmail.com> wrote:

I thought I should get the exactly the same output format. So what is
happening? what should I do to make the output aligned in columns?

Your terminal is using a fixed width font. The default font used by
most gui components (including the TextCtrl) is a proportional font
(meaning each character is a different width). Try changing the
TextCtrl's Font to a fixed width one like Courier New and it should
line up the same as in the terminal.

Cody

hi, Cody, thank you for your answer. But where can I change this for
the TextCtrl?
Can you share more details or some examples? Thanks in advance.

···

On Feb 7, 3:37 pm, Cody Precord <codyprec...@gmail.com> wrote:

Hi,

On Mon, Feb 7, 2011 at 8:12 AM, pploo <beilus...@gmail.com> wrote:

> I thought I should get the exactly the same output format. So what is
> happening? what should I do to make the output aligned in columns?

Your terminal is using a fixed width font. The default font used by
most gui components (including the TextCtrl) is a proportional font
(meaning each character is a different width). Try changing the
TextCtrl's Font to a fixed width one like Courier New and it should
line up the same as in the terminal.

Cody

Hi,

···

On Mon, Feb 7, 2011 at 8:47 AM, pploo <beilushao@gmail.com> wrote:

hi, Cody, thank you for your answer. But where can I change this for
the TextCtrl?
Can you share more details or some examples? Thanks in advance.

The wxPython demo and google have plenty of examples.

http://tinyurl.com/5u7843f

Cody

Thank you Cody. It works.
I tried with the following code.
font1 = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier
New')
self.textctrl.SetFont(font1)

But the font style (I use as your case Courier New) is different from
the print on the bash.
How can I get to know what font the application uses, or preferrably
how can I set the font as fixed width without changing the size and
style?

Thanks a lot!

···

On Feb 7, 3:52 pm, Cody Precord <codyprec...@gmail.com> wrote:

Hi,

On Mon, Feb 7, 2011 at 8:47 AM, pploo <beilus...@gmail.com> wrote:
> hi, Cody, thank you for your answer. But where can I change this for
> the TextCtrl?
> Can you share more details or some examples? Thanks in advance.

The wxPython demo and google have plenty of examples.

http://tinyurl.com/5u7843f

Cody

Hi,

Thank you Cody. It works.
I tried with the following code.
font1 = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier
New')
self.textctrl.SetFont(font1)

But the font style (I use as your case Courier New) is different from
the print on the bash.
How can I get to know what font the application uses, or preferrably
how can I set the font as fixed width without changing the size and
style?

Sorry, not sure I completely understand what your asking. If you want
to keep the same size you can just do something like this to produce a
fixed width font.

font = self.textctrl.GetFont()
newFont = wx.Font(font.PointSize, wx.FONTFAMILY_MODERN,
                             wx.FONTSTYLE_NORMAL,
                             wx.FONTWEIGHT_NORMAL)
self.textctrl.SetFont()

Also see the SystemSettings demo in the wxPython Demo application if
you want to retrieve the default system fixed width font.

Cody

p.s) please don't top post (Why is Bottom-posting better than Top-posting)

···

On Mon, Feb 7, 2011 at 9:11 AM, pploo <beilushao@gmail.com> wrote:

It works very well!!
Thanks a lot, Cody, you are my hero!

···

On Feb 7, 4:23 pm, Cody Precord <codyprec...@gmail.com> wrote:

Sorry, not sure I completely understand what your asking. If you want
to keep the same size you can just do something like this to produce a
fixed width font.

font = self.textctrl.GetFont()
newFont = wx.Font(font.PointSize, wx.FONTFAMILY_MODERN,
wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL)
self.textctrl.SetFont()

wx.FONTFAMILY_TELETYPE would be a better choice. The _MODERN family may or may not be a monospaced font, depending on platform.

···

On 2/7/11 7:23 AM, Cody Precord wrote:

Hi,

On Mon, Feb 7, 2011 at 9:11 AM, pploo<beilushao@gmail.com> wrote:

Thank you Cody. It works.
I tried with the following code.
font1 = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier
New')
self.textctrl.SetFont(font1)

But the font style (I use as your case Courier New) is different from
the print on the bash.
How can I get to know what font the application uses, or preferrably
how can I set the font as fixed width without changing the size and
style?

Sorry, not sure I completely understand what your asking. If you want
to keep the same size you can just do something like this to produce a
fixed width font.

font = self.textctrl.GetFont()
newFont = wx.Font(font.PointSize, wx.FONTFAMILY_MODERN,
                              wx.FONTSTYLE_NORMAL,
                              wx.FONTWEIGHT_NORMAL)
self.textctrl.SetFont()

--
Robin Dunn
Software Craftsman