TextCtrl - formatting coloumn based plain text question

Hi all,

I am struggling to find a way so that my wxPython based application would display column based outputs nicely into TextCtrl areas. I would like to get something like this:

show cable modem 0023.be36.8a98 phy

MAC Address I/F Sid USPwr USMER Timing DSPwr DSMER Mode DOCSIS
(dBmV) (SNR) Offset (dBmV) (SNR) Prov
(dB) (dB)
0023.be36.8a98 C7/0/1/U0 761 23.25 38.31 1499 0.00 ----- atdma* 1.1
0023.be36.8a98 C7/0/1/U1 761 23.50 38.36 1508 0.00 ----- atdma* 1.1

Whereas I get this:

#show cable modem 0023.be36.8a98 phy
MAC Address I/F Sid USPwr USMER Timing DSPwr DSMER Mode DOCSIS
(dBmV) (SNR) Offset (dBmV) (SNR) Prov
(dB) (dB)
0023.be36.8a98 C7/0/1/U0 761 23.25 38.31 1499 0.00 ----- atdma* 1.1
0023.be36.8a98 C7/0/1/U1 761 23.50 38.36 1508 0.00 ----- atdma* 1.1

Basically, for some reason the spacing between elements of columns is changed.

Now, I know this is probably an application dependent behavior, I get the same messed up output when pasting into Word. I do get the proper one when pasting into notepad like applications, so probably there is a certain mechanism integrated into those that takes care of formatting. I’m not an expert on text formatting, neither in wxPython, but it would really be great if I could manage to achieve this somehow.

Could you point me to any documentation or other ideas that might help?

Thanks,
Dan

You sure you want to use a TextCtrl for that, looks to me to be a better fit to use one of the ListCtrl things (e.g. wx.ListCtrl, dataview.ListCtrl, agw.HyperTreeList, agw.UltimateListCtrl), check out the wxPython demo.

Werner

···

On 10/17/2014 16:05, Neamtu Dan wrote:

Hi all,

I am struggling to find a way so that my wxPython based application would display column based outputs nicely into TextCtrl areas. I would like to get something like this:

show cable modem 0023.be36.8a98 phy

MAC Address I/F Sid USPwr USMER Timing DSPwr DSMER Mode DOCSIS
(dBmV) (SNR) Offset (dBmV) (SNR) Prov
               (dB) (dB)
0023.be36.8a98 C7/0/1/U0 761 23.25 38.31 1499 0.00 ----- atdma* 1.1
0023.be36.8a98 C7/0/1/U1 761 23.50 38.36 1508 0.00 ----- atdma* 1.1

Whereas I get this:

#show cable modem 0023.be36.8a98 phy
MAC Address I/F Sid USPwr USMER Timing DSPwr DSMER Mode DOCSIS
                                   (dBmV) (SNR) Offset (dBmV) (SNR) Prov
                                          (dB) (dB)
0023.be36.8a98 C7/0/1/U0 761 23.25 38.31 1499 0.00 ----- atdma* 1.1
0023.be36.8a98 C7/0/1/U1 761 23.50 38.36 1508 0.00 ----- atdma* 1.1

Basically, for some reason the spacing between elements of columns is changed.

Now, I know this is probably an application dependent behavior, I get the same messed up output when pasting into Word. I do get the proper one when pasting into notepad like applications, so probably there is a certain mechanism integrated into those that takes care of formatting. I'm not an expert on text formatting, neither in wxPython, but it would really be great if I could manage to achieve this somehow.

Could you point me to any documentation or other ideas that might help?

Neamtu Dan wrote:

I am struggling to find a way so that my wxPython based application
would display column based outputs nicely into TextCtrl areas. I would
like to get something like this:

show cable modem 0023.be36.8a98 phy

MAC Address I/F Sid USPwr USMER
Timing DSPwr DSMER Mode DOCSIS
                                                             (dBmV)
(SNR) Offset (dBmV) (SNR) Prov
                                                                     
         (dB) (dB)
0023.be36.8a98 C7/0/1/U0 761 23.25 38.31 1499
      0.00 ----- atdma* 1.1
0023.be36.8a98 C7/0/1/U1 761 23.50 38.36
1508 0.00 ----- atdma* 1.1

Whereas I get this:

#show cable modem 0023.be36.8a98 phy
MAC Address I/F Sid USPwr USMER Timing DSPwr DSMER
Mode DOCSIS
                                   (dBmV) (SNR) Offset (dBmV)
(SNR) Prov
                                          (dB) (dB)
0023.be36.8a98 C7/0/1/U0 761 23.25 38.31 1499 0.00 -----
atdma* 1.1
0023.be36.8a98 C7/0/1/U1 761 23.50 38.36 1508 0.00 -----
atdma* 1.1

Basically, for some reason the spacing between elements of columns is
changed.

Are you aware of the different between a proportional font and a
fixed-pitch font? If you really want to do your spacing like this, you
either need to draw the text yourself instead of using a control, or you
need to use a fixed-pitch font like Courier or Consolas.

I would agree with Werner that this kind of information seems much
better suited to a grid control or a list view control. It's very
difficult to manage and maintain spacing in a text control.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

This seems to be more of a Python string-formatting question, more than a wxPython widget question. Ask google something like: Python print columns. Something I looked at a while ago was:

Then as others said, you would want to use a mono-space font. I’m not sure if you’d need to use a Rich style on the TextCtrl to change the font or not, but once you get the strings formatted correctly it should behave pretty much the same as text printed to a console window.

···

On Friday, October 17, 2014 7:05:21 AM UTC-7, Neamtu Dan wrote:

Hi all,

I am struggling to find a way so that my wxPython based application would display column based outputs nicely into TextCtrl areas. I would like to get something like this:

Neamtu Dan wrote:
>
> I am struggling to find a way so that my wxPython based application
> would display column based outputs nicely into TextCtrl areas.

  If you really want to do your spacing like this, you

either need to draw the text yourself instead of using a control, or you
need to use a fixed-pitch font like Courier or Consolas.

Exactly -- the easy way is a fixed-pitch font, you should be able to get
one on any platform with wx.MODERN for the font Family:

http://docs.wxwidgets.org/3.0/overview_font.html

seems much

better suited to a grid control or a list view control. It's very
difficult to manage and maintain spacing in a text control.

or wxHTML, and make an html table, if this is just for display.

-Chris

···

On Fri, Oct 17, 2014 at 9:41 AM, Tim Roberts <timr@probo.com> wrote:

--

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

Thanks all,

It was very simple after all, just had to change the font. Unrelated to Python or to wxPython.

···

On Friday, October 17, 2014 10:53:58 PM UTC+2, Chris Barker wrote:

On Fri, Oct 17, 2014 at 9:41 AM, Tim Roberts ti...@probo.com wrote:

Neamtu Dan wrote:

I am struggling to find a way so that my wxPython based application

would display column based outputs nicely into TextCtrl areas.

If you really want to do your spacing like this, you

either need to draw the text yourself instead of using a control, or you

need to use a fixed-pitch font like Courier or Consolas.

Exactly – the easy way is a fixed-pitch font, you should be able to get one on any platform with wx.MODERN for the font Family:

http://docs.wxwidgets.org/3.0/overview_font.html

seems much

better suited to a grid control or a list view control. It’s very

difficult to manage and maintain spacing in a text control.

or wxHTML, and make an html table, if this is just for display.

-Chris

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....@noaa.gov

Fix - change the font. Simple solution, but hard to figure out. Thanks!

···

On Friday, October 17, 2014 4:05:21 PM UTC+2, Neamtu Dan wrote:

Hi all,

I am struggling to find a way so that my wxPython based application would display column based outputs nicely into TextCtrl areas. I would like to get something like this:

show cable modem 0023.be36.8a98 phy

MAC Address I/F Sid USPwr USMER Timing DSPwr DSMER Mode DOCSIS
(dBmV) (SNR) Offset (dBmV) (SNR) Prov
(dB) (dB)
0023.be36.8a98 C7/0/1/U0 761 23.25 38.31 1499 0.00 ----- atdma* 1.1
0023.be36.8a98 C7/0/1/U1 761 23.50 38.36 1508 0.00 ----- atdma* 1.1

Whereas I get this:

#show cable modem 0023.be36.8a98 phy
MAC Address I/F Sid USPwr USMER Timing DSPwr DSMER Mode DOCSIS
(dBmV) (SNR) Offset (dBmV) (SNR) Prov
(dB) (dB)
0023.be36.8a98 C7/0/1/U0 761 23.25 38.31 1499 0.00 ----- atdma* 1.1
0023.be36.8a98 C7/0/1/U1 761 23.50 38.36 1508 0.00 ----- atdma* 1.1

Basically, for some reason the spacing between elements of columns is changed.

Now, I know this is probably an application dependent behavior, I get the same messed up output when pasting into Word. I do get the proper one when pasting into notepad like applications, so probably there is a certain mechanism integrated into those that takes care of formatting. I’m not an expert on text formatting, neither in wxPython, but it would really be great if I could manage to achieve this somehow.

Could you point me to any documentation or other ideas that might help?

Thanks,
Dan