469,319 Members | 2,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

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.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?'),('p op.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_R ESIZE)
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.current Item)
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()
########
Jul 18 '05 #1
1 4267
pk*******@dea.spamcon.org (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 =*=
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Joost van Rooij | last post: by
1 post views Thread by Mark Carter | last post: by
3 posts views Thread by Piet | last post: by
4 posts views Thread by Piet | last post: by
reply views Thread by kalyan.abbaraju | last post: by
6 posts views Thread by Daniel Walzenbach | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.