Trouble with wxListCtrl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chauhan

    Trouble with wxListCtrl

    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.GetIt emText(self.cur rentItem). The statement
    self.currentIte m 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 wxGetMousePosit ion().

    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.icente r.net','usernam e?','password?' ),('pop.netzero .com','username ?',
    'password?'),]
    list_items = [ "item value", "on any", "Right click", ]
    class main_window(wxF rame):
    def __init__(self, parent, id, title):
    wxFrame.__init_ _(self, parent, -1, title, size = (800, 600),
    style=wxDEFAULT _FRAME_STYLE|wx NO_FULL_REPAINT _ON_RESIZE)
    splitter = wxSplitterWindo w(self, -1, style=wxNO_3D|w xSP_3D)
    tID=wxNewId()
    self.list = wxListCtrl(spli tter, tID,
    style=wxLC_REPO RT|wxSUNKEN_BOR DER|wxLC_SINGLE _SEL)
    self.log = wxTextCtrl(spli tter, -1, style=wxTE_MULT ILINE)
    splitter.SplitH orizontally(sel f.list, self.log, 450)
    splitter.SetMin imumPaneSize(20 )
    self.list.Inser tColumn( 0, 'listTitle' )
    for x in list_items: self.list.Inser tStringItem(0,x )
    self.Show(true)
    EVT_COMMAND_RIG HT_CLICK(self.l ist, tID, self.OnRightCli ck)
    EVT_RIGHT_UP(se lf.list, self.OnRightCli ck)
    self.log.WriteT ext(emailloglis t[emailloglist[0]][2]+'\r\n')
    p=self.logMail( )
    def OnRightClick(se lf, event):
    self.log.WriteT ext("OnRightCli ck %s\n" %
    self.list.GetIt emText(1))#GetI temText(self.cu rrentItem)
    if not hasattr(self, "popupID1") :
    self.popupID1 = wxNewId()
    EVT_MENU(self, self.popupID1, self.OnPopupOne )
    menu = wxMenu()
    menu.Append(sel f.popupID1, "FindItem tests")
    self.PopupMenu( menu, wxGetMousePosit ion()) #wxPoint(self.x ,
    self.y)
    menu.Destroy()
    def OnPopupOne(self , event): self.log.WriteT ext("Popup one Find:
    "+str(self.list .FindItem(-1, 'on any'))+'\r\n')
    def logMail(self):
    try:
    print wxSocketBase.Is Connected
    p = POP3 (emailloglist[emailloglist[0]][0])
    self.log.WriteT ext(p.user
    (emailloglist[emailloglist[0]][1])+'\r\n')
    self.log.WriteT ext(p.pass_
    (emailloglist[emailloglist[0]][2])+'\r\n')
    return p
    except error_proto:
    self.log.WriteT ext('msg')
    class App(wxApp):
    def OnInit(self):
    frame = main_window(Non e, -1, "wxPython: (A Demonstration)" )
    self.SetTopWind ow(frame)
    return true
    app = App(0)
    app.MainLoop()
    ########
  • Lukasz Pankowski

    #2
    Re: Trouble with wxListCtrl

    pkbf-tspx@dea.spamco n.org (chauhan) writes:
    [color=blue]
    > I am also having problem with statement
    > self.list.GetIt emText(self.cur rentItem). The statement
    > self.currentIte m 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 wxGetMousePosit ion().
    >[/color]

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

    EVT_LIST_ITEM_S ELECTED(self, tID, self.OnItemSele cted)

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

    def OnItemSelected( self, event):
    ##print event.GetItem() .GetTextColour( )
    self.currentIte m = event.m_itemInd ex
    # [...]

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

    currentItem = self.list.GetNe xtItem(
    -1, wxLIST_NEXT_ALL , wxLIST_STATE_SE LECTED)

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

    --

    =*= Lukasz Pankowski =*=

    Comment

    Working...