Trouble with wxListCtrl

Discussion in 'Python' started by chauhan, Sep 22, 2003.

  1. chauhan

    chauhan Guest

    Hi,

    I am new to pogramming.

    I have written a small program which retrieves emails from server,
    unless all the messages are loaded only then it displays on screen
    properlely. Whole thing works fine if I use events to activate
    logMail() after start but I don't know how to activate an event at the
    start (witout pressing mouse or menu key) as I want this to load
    messages at the start of the program.

    I am also having problem with statement
    self.list.GetItemText(self.currentItem). The statement
    self.currentItem gives the current selected item position on listctrl
    this statement works fine in wxPanel (demo example wxlistctrl in
    wxPython) and not with
    wxFrame which I am using now as I want menubar in my application. Can
    some body tell me how to get the current selected items position in
    wxListCtrl with wxFrame? Same kind of problem with wxPoint(self.x,
    self.y) but I can use wxGetMousePosition().

    Also I would like to know how to check if internet connection is on.

    Thanks in advance

    Chauhan

    #########
    from wxPython.wx import *
    import poplib
    from poplib import *

    emailloglist=[2,('mail.icenter.net','username?','password?'),('pop.netzero.com','username?',
    'password?'),]
    list_items = [ "item value", "on any", "Right click", ]
    class main_window(wxFrame):
    def __init__(self, parent, id, title):
    wxFrame.__init__(self, parent, -1, title, size = (800, 600),
    style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
    splitter = wxSplitterWindow(self, -1, style=wxNO_3D|wxSP_3D)
    tID=wxNewId()
    self.list = wxListCtrl(splitter, tID,
    style=wxLC_REPORT|wxSUNKEN_BORDER|wxLC_SINGLE_SEL)
    self.log = wxTextCtrl(splitter, -1, style=wxTE_MULTILINE)
    splitter.SplitHorizontally(self.list, self.log, 450)
    splitter.SetMinimumPaneSize(20)
    self.list.InsertColumn( 0, 'listTitle' )
    for x in list_items: self.list.InsertStringItem(0,x)
    self.Show(true)
    EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick)
    EVT_RIGHT_UP(self.list, self.OnRightClick)
    self.log.WriteText(emailloglist[emailloglist[0]][2]+'\r\n')
    p=self.logMail()
    def OnRightClick(self, event):
    self.log.WriteText("OnRightClick %s\n" %
    self.list.GetItemText(1))#GetItemText(self.currentItem)
    if not hasattr(self, "popupID1"):
    self.popupID1 = wxNewId()
    EVT_MENU(self, self.popupID1, self.OnPopupOne)
    menu = wxMenu()
    menu.Append(self.popupID1, "FindItem tests")
    self.PopupMenu(menu, wxGetMousePosition()) #wxPoint(self.x,
    self.y)
    menu.Destroy()
    def OnPopupOne(self, event): self.log.WriteText("Popup one Find:
    "+str(self.list.FindItem(-1, 'on any'))+'\r\n')
    def logMail(self):
    try:
    print wxSocketBase.IsConnected
    p = POP3 (emailloglist[emailloglist[0]][0])
    self.log.WriteText(p.user
    (emailloglist[emailloglist[0]][1])+'\r\n')
    self.log.WriteText(p.pass_
    (emailloglist[emailloglist[0]][2])+'\r\n')
    return p
    except error_proto:
    self.log.WriteText('msg')
    class App(wxApp):
    def OnInit(self):
    frame = main_window(None, -1, "wxPython: (A Demonstration)")
    self.SetTopWindow(frame)
    return true
    app = App(0)
    app.MainLoop()
    ########
    chauhan, Sep 22, 2003
    #1
    1. Advertising

  2. (chauhan) writes:

    > I am also having problem with statement
    > self.list.GetItemText(self.currentItem). The statement
    > self.currentItem gives the current selected item position on listctrl
    > this statement works fine in wxPanel (demo example wxlistctrl in
    > wxPython) and not with
    > wxFrame which I am using now as I want menubar in my application. Can
    > some body tell me how to get the current selected items position in
    > wxListCtrl with wxFrame? Same kind of problem with wxPoint(self.x,
    > self.y) but I can use wxGetMousePosition().
    >


    Hi, wxPanel or wxFrame has nothing to do with self.currentItem, this
    attribute is set to 0 in TestListCtrlPanel.PopulateList in mentioned
    example, they register a handler for item selection

    EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected)

    and in this hanler they set it to currently selected item:

    def OnItemSelected(self, event):
    ##print event.GetItem().GetTextColour()
    self.currentItem = event.m_itemIndex
    # [...]

    This method tracks user selection, the other way is to find the
    selected item when you need it:

    currentItem = self.list.GetNextItem(
    -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)

    this finds first selected item (first after -1).

    --

    =*= Lukasz Pankowski =*=
    Lukasz Pankowski, Sep 22, 2003
    #2
    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. Joost van Rooij

    Delete item from wxListCtrl

    Joost van Rooij, Jul 4, 2003, in forum: Python
    Replies:
    1
    Views:
    639
    Joost van Rooij
    Jul 7, 2003
  2. Replies:
    1
    Views:
    394
    David C. Fox
    Jul 22, 2003
  3. Mark Carter
    Replies:
    1
    Views:
    522
    Steve Zatz
    Dec 1, 2003
  4. simo

    wxListCtrl with CheckBox?

    simo, Apr 10, 2004, in forum: Python
    Replies:
    7
    Views:
    7,661
  5. Piet
    Replies:
    3
    Views:
    492
Loading...

Share This Page