problem with text and list ctrl

Hi everyone,

Missed u all verymuch since i was not able to post any query for a long time.

I am having a problem. I have a textctrl that gets appended by certain maessages randomly…
but when it becomes too long i want to delete a no:of messages from the
top. i now wrote a fn() that performs the above requirement.
Itz like…

self.textWindow = wx.TextCtrl(bottomwin, -1, “”, wx.DefaultPosition,(900 100),style = textctrlStyle)
def clearBottomWindow_usingTextCtrl(self,strMsg):

    if self.window.textWindow.GetNumberOfLines() > self.maxlines:

self.window.textWindow.Remove( 0,
self.window.textWindow.XYToPosition(0,self.removeLines))

self.window.textWindow.AppendText(time.strftime("%b %d %H:%M:%S
",time.localtime()))

        self.window.textWindow.AppendText(strMsg)

    else:

self.window.textWindow.AppendText(time.strftime("%b %d %H:%M:%S
",time.localtime()))

        self.window.textWindow.AppendText(strMsg)

this works fine in windows but won’t work in linux becoz i think
functions like Remove() and XYToPosition() won’t work in Linux (thats
what i think so, not sure). more over when i am using a textctrl and
error called gtktextlayout.c is coming so i changed the textctrl to a
list ctrl.(since i was not able to slove that).

But in listctrl i see only Clear() fn; that clears all the items, not
certain items frm the top. Also the vertical scroll bar is not coming
is Linux eventhough i have specified teh style as ’ style = wx.LB_SINGLE|wx.LB_ALWAYS_SB ’

While using the Listctrl the function i wrote is ;

self.textWindow = wx.ListBox(bottomwin, -1, wx.DefaultPosition,(1000, 120), sampleList, style = wx.LB_SINGLE|wx.LB_ALWAYS_SB )

def clearBottomWindow_usingListCtrl(self,strMsg):

    if self.window.textWindow.GetCount() > self.maxlines:

        self.window.textWindow.Clear()

self.window.textWindow.Append(time.strftime("%b %d %H:%M:%S
"+strMsg,time.localtime()))

        #self.window.textWindow.AppendText(strMsg)

    else:

self.window.textWindow.Append(time.strftime("%b %d %H:%M:%S
"+strMsg,time.localtime()))

        #self.window.textWindow.AppendText(strMsg)

Now what happening is when count reaches maxlines the whole items are deleted…

My probs are:

  1. any method to delete only a few number of items from the top of the list if using Listbox,
  2. why is that vertical scroll bar is not coming in linux?
  3. The Vscroll bar comes in windows but its default position is at d
    top. I want the vertical scroll bar to comes down as when messages are
    appended. Any method by which we can bring the scrolll bar down( like
    the scroll bar of a textctrl)

Hoping to get a favourable reply. i am in this problem for a very long
time. Maybe itz a simple thing but i’m not able to figure it out

···


Regards,

Shine Anne

Hi everyone,

Missed u all verymuch since i was not able to post any query for a long
time.

I am having a problem. I have a textctrl that gets appended by certain
maessages randomly...
but when it becomes too long i want to delete a no:of messages from the top.
i now wrote a fn() that performs the above requirement.
Itz like..

self.textWindow = wx.TextCtrl(bottomwin, -1, "", wx.DefaultPosition,(900
100),style = textctrlStyle)
    def clearBottomWindow_usingTextCtrl(self,strMsg):
        if self.window.textWindow.GetNumberOfLines() > self.maxlines:
            self.window.textWindow.Remove( 0,
self.window.textWindow.XYToPosition(0,self.removeLines))
            self.window.textWindow.AppendText(time.strftime("%b %d %H:%M:%S
",time.localtime()))
            self.window.textWindow.AppendText(strMsg)
        else:
            self.window.textWindow.AppendText(time.strftime("%b %d %H:%M:%S
",time.localtime()))
            self.window.textWindow.AppendText(strMsg)

this works fine in windows but won't work in linux becoz i think functions
like Remove() and XYToPosition() won't work in Linux (thats what i think so,
not sure). more over when i am using a textctrl and error called
gtktextlayout.c is coming so i changed the textctrl to a list ctrl.(since i
was not able to slove that).

Why do you think it does not work? What does XYToPosition return? If it's the case that XYToPosition really fails, you can always find the position yourself by searching for the first '\n' in the text string and then use that to remove the first line.

But in listctrl i see only Clear() fn; that clears all the items, not
certain items frm the top. Also the vertical scroll bar is not coming is
Linux eventhough i have specified teh style as ' style =
wx.LB_SINGLE|wx.LB_ALWAYS_SB '

I guess you are using this for some kind of log. Usually you want that your users can copy and paste from it easily. With a listctrl you can't do that nicely. So you might consider sticking to the TextCtrl. Of course if you want to use it for something else, then the ListCtrl will be just fine.

While using the Listctrl the function i wrote is ;

self.textWindow = wx.ListBox(bottomwin, -1, wx.DefaultPosition,(1000, 120),
sampleList, style = wx.LB_SINGLE|wx.LB_ALWAYS_SB )

    def clearBottomWindow_usingListCtrl(self,strMsg):
        if self.window.textWindow.GetCount() > self.maxlines:
            self.window.textWindow.Clear()
            self.window.textWindow.Append(time.strftime("%b %d %H:%M:%S
"+strMsg,time.localtime()))
            #self.window.textWindow.AppendText(strMsg)
        else:
            self.window.textWindow.Append(time.strftime("%b %d %H:%M:%S
"+strMsg,time.localtime()))
            #self.window.textWindow.AppendText(strMsg)

Now what happening is when count reaches maxlines the whole items are
deleted..

My probs are:

1) any method to delete only a few number of items from the top of the list if using Listbox,

wxListBox::Delete(index) will do that.

2) why is that vertical scroll bar is not coming in linux?

No idea, maybe somebody else can step up on this.

3) The Vscroll bar comes in windows but its default position is at d top. I
want the vertical scroll bar to comes down as when messages are appended.
Any method by which we can bring the scrolll bar down( like the scroll bar
of a textctrl)

listbox.SetScrollPos() could do that, but it's not very elegant i guess. You could switch to a ListCtrl instead of a Listbox and then use EnsureVisible() to do the scrolling.

···

Am Fri, 05 May 2006 10:54:39 +0200 hat Shine Anne <m2ids2005@gmail.com> geschrieben:

Shine Anne wrote:

Hi everyone,

Missed u all verymuch since i was not able to post any query
for a long time.

I am having a problem. I have a textctrl that gets appended
by certain maessages randomly...
but when it becomes too long i want to delete a no:of
messages from the top. i now wrote a fn() that performs the
above requirement.
Itz like..

self.textWindow = wx.TextCtrl(bottomwin, -1, "",
wx.DefaultPosition,(900 100),style = textctrlStyle)
    def clearBottomWindow_usingTextCtrl(self,strMsg):
        if self.window.textWindow.GetNumberOfLines() > self.maxlines:
            self.window.textWindow.Remove( 0,
self.window.textWindow.XYToPosition(0,self.removeLines))
            
self.window.textWindow.AppendText(time.strftime("%b %d
%H:%M:%S ",time.localtime()))
            self.window.textWindow.AppendText(strMsg)
        else:
            
self.window.textWindow.AppendText(time.strftime("%b %d
%H:%M:%S ",time.localtime()))
            self.window.textWindow.AppendText(strMsg)

this works fine in windows but won't work in linux becoz i
think functions like Remove() and XYToPosition() won't work
in Linux (thats what i think so, not sure). more over when i
am using a textctrl and error called gtktextlayout.c is
coming so i changed the textctrl to a list ctrl.(since i was
not able to slove that).

It works in Windows and in Linux for me - see the attached program. I think
(hope) it illustrates what you are trying to achieve.

A couple of small points on your code snippet above -

1. You will see from the attached program that I have subclassed
wx.TextCtrl. It makes the code much cleaner, and avoids the need for
"self.window.textWindow..." that you have in a number of places. It is a
good technique to learn and use.

2. The following lines -

  if self.window.textWindow.GetNumberOfLines() > self.maxlines:
      self.window.textWindow.Remove( 0,
self.window.textWindow.XYToPosition(0,self.removeLines))
      self.window.textWindow.AppendText(time.strftime("%b %d %H:%M:%S
",time.localtime()))
      self.window.textWindow.AppendText(strMsg)
  else:
      self.window.textWindow.AppendText(time.strftime("%b %d %H:%M:%S
",time.localtime()))
      self.window.textWindow.AppendText(strMsg)

can be written like this -

  if self.window.textWindow.GetNumberOfLines() > self.maxlines:
      self.window.textWindow.Remove( 0,
self.window.textWindow.XYToPosition(0,self.removeLines))
  self.window.textWindow.AppendText(time.strftime("%b %d %H:%M:%S
",time.localtime()))
  self.window.textWindow.AppendText(strMsg)

Using Python's indentation rules, any lines with the same indentation level
as the "if" statement are treated not as part of the "if" block, but as the
continuation of the program after the "if" block has completed.

HTH

Frank Millman

fm44.py (1.28 KB)