Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Trouble with wxListCtrl

Reply
Thread Tools

Trouble with wxListCtrl

 
 
chauhan
Guest
Posts: n/a
 
      09-22-2003
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()
########
 
Reply With Quote
 
 
 
 
Lukasz Pankowski
Guest
Posts: n/a
 
      09-22-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (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 =*=
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making items visible in wxPython wxListCtrl Piet Python 3 05-19-2004 05:57 AM
wxListCtrl with CheckBox? simo Python 7 04-21-2004 04:34 PM
wxPython: combining wxListCtrl and wxCheckBox Mark Carter Python 1 12-01-2003 04:21 PM
How do I get more events from a wxListCtrl in a panel? bmoore@integrian.com Python 1 07-22-2003 09:13 PM
Delete item from wxListCtrl Joost van Rooij Python 1 07-07-2003 07:14 AM



Advertisments