Formatting Strings for List Control Display.

On a 2-column, report-style list control, I have a list of terms in the
first column and a list of numbers associated with each term in the second
column.

   The numbers look like this:

0.127806090625
0.0477315667073
0.0629966210202
0.240125900354
0.159317312615
0.0733673083882
0.0980827347105
0.190572465581

   The code to place the text and numbers is this:

     ngc = None
     nwt = None

     idx = 0
     for item in self.appData.polNat:
       idx += 1
       ngc = self.naturalPanel.lc.InsertStringItem(idx, item[0])
     idx = 0
     for item in self.appData.natWt:
       idx += 1
       print item[2]
       nwt = self.naturalPanel.lc.SetStringItem(idx, 1, str(item[2]))

(which I'm sure can be condensed, but I'm not yet good enough with Python to
do so). And a screen shot of this widget is attached.

   The screenshot shows that the second column displays 7 characters followed
by an ellipsis because the entire string is not diplayed. I would like to
trim it to 6 digits. Can that slicing be added to the 'nwt' line above? If
not how can I do this formatting.

Rich

screenshot.png

···

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Just after I mailed off this message I noticed that the right column was
moved down by one row. I moved the index incrementation below the display
line and that's fixed that issue. No need to let me know it's off by one.
:wink:

Rich

···

On Wed, 28 Feb 2007, Rich Shepard wrote:

The screenshot shows that the second column displays 7 characters
followed by an ellipsis because the entire string is not diplayed. I would
like to trim it to 6 digits. Can that slicing be added to the 'nwt' line
above? If not how can I do this formatting.

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

You can use C-style formatting:
      nwt = self.naturalPanel.lc.SetStringItem(idx, 1, '%.5f'%item[2])

···

At 03:03 PM 2/28/2007, you wrote:

  On a 2-column, report-style list control, I have a list of terms in the
first column and a list of numbers associated with each term in the second
column.

  The numbers look like this:

0.127806090625
0.0477315667073
0.0629966210202
0.240125900354
0.159317312615
0.0733673083882
0.0980827347105
0.190572465581

  The code to place the text and numbers is this:

    ngc = None
    nwt = None

    idx = 0
    for item in self.appData.polNat:
      idx += 1
      ngc = self.naturalPanel.lc.InsertStringItem(idx, item[0])
    idx = 0
    for item in self.appData.natWt:
      idx += 1
      print item[2]
      nwt = self.naturalPanel.lc.SetStringItem(idx, 1, str(item[2]))

(which I'm sure can be condensed, but I'm not yet good enough with Python to
do so). And a screen shot of this widget is attached.

  The screenshot shows that the second column displays 7 characters followed
by an ellipsis because the entire string is not diplayed. I would like to
trim it to 6 digits. Can that slicing be added to the 'nwt' line above? If
not how can I do this formatting.

Rich

Phil,

   Thank you. I did not realize that I could do that within the parameters of
the function call.

Much appreciated,

Rich

···

On Wed, 28 Feb 2007, Phil Mayes wrote:

You can use C-style formatting:
    nwt = self.naturalPanel.lc.SetStringItem(idx, 1, '%.5f'%item[2])

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863