Newbie wxPython ListCtrl Question
I am new to python and to wxWindows. I have tried searching google, reading the documentation and trying to figure out some of the examples, but I am stumped as to how to get information out of a listctrl at a certain row and column. I tried to write a simple example to learn to work with the listctrl as follows: -- #!/usr/bin/env python # -*- coding: ISO-8859-1 -*- # generated by wxGlade 0.4 on Wed Nov 16 10:23:06 2005 import wx class MyFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.panel_1 = wx.Panel(self, -1) self.list_ctrl_1 = wx.ListCtrl(self.panel_1, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER) self.label_1 = wx.StaticText(self.panel_1, -1, "label_1") self.__set_properties() self.__do_layout() self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelected, self.list_ctrl_1) # end wxGlade self.list_ctrl_1.InsertColumn(0,"Name") self.list_ctrl_1.InsertColumn(1,"Address") self.list_ctrl_1.SetColumnWidth(0, 215) self.list_ctrl_1.SetColumnWidth(1, 55) self.list_ctrl_1.InsertStringItem(0,"John Smith") self.list_ctrl_1.SetStringItem(0,1, "123 Elm") self.list_ctrl_1.InsertStringItem(1,"Tom Clark") self.list_ctrl_1.SetStringItem(1,1, "415 W. 1st") def __set_properties(self): # begin wxGlade: MyFrame.__set_properties self.SetTitle("frame_1") # end wxGlade def __do_layout(self): # begin wxGlade: MyFrame.__do_layout sizer_1 = wx.BoxSizer(wx.VERTICAL) sizer_2 = wx.BoxSizer(wx.HORIZONTAL) sizer_2.Add(self.list_ctrl_1, 1, wx.EXPAND, 0) sizer_2.Add(self.label_1, 0, wx.ADJUST_MINSIZE, 0) self.panel_1.SetAutoLayout(True) self.panel_1.SetSizer(sizer_2) sizer_2.Fit(self.panel_1) sizer_2.SetSizeHints(self.panel_1) sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0) self.SetAutoLayout(True) self.SetSizer(sizer_1) sizer_1.Fit(self) sizer_1.SetSizeHints(self) self.Layout() # end wxGlade def OnSelected(self, event): # wxGlade: MyFrame. self.currentItem = event.m_itemIndex #What do I put here to get the contents of the Address column? #I want to do something like self.label_1.SetLabel(?) #where the ? is the contents of the address column of the selected row event.Skip() # end of class MyFrame class MyApp(wx.App): def OnInit(self): wx.InitAllImageHandlers() frame_1 = MyFrame(None, -1, "") self.SetTopWindow(frame_1) frame_1.Show() return 1 # end of class MyApp if __name__ == "__main__": app = MyApp(0) app.MainLoop() --- But I can't figure out how to get the contents of the second column on the selected row. Any help is appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie wxPython ListCtrl Question
Thank you very much. That is exactly what I needed. limodou <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > 2005/11/17, Todd7 <[EMAIL PROTECTED]>: >> I am new to python and to wxWindows. I have tried searching google, >> reading the documentation and trying to figure out some of the >> examples, but I am stumped as to how to get information out of a >> listctrl at a certain row and column. I tried to write a simple >> example to learn to work with the listctrl as follows: > > I'v made some helper function as that: > > def getRowText(self, index, col): > if index >= 0: > return self.list_ctrl_1.GetItem(index, col).GetText() > else: > return '' > > def getSelRowText(self, col): > return self.getRowText(self.getSelection(), col) > > def getSelection(self): > return self.list_ctrl_1.GetNextItem(-1, wx.LIST_NEXT_ALL, > wx.LIST_STATE_SELECTED) > > You can just use self.getSelRowText(1) to gain the second column text > of selection row. > -- > I like python! > My Blog: http://www.donews.net/limodou > NewEdit Maillist: http://groups.google.com/group/NewEdit > -- http://mail.python.org/mailman/listinfo/python-list
iewin.IEHtmlWindow shutil.move conflict
I am writing a python program to load a pdf file into an IEHtmlWindow which displays it through adobe acrobat reader 7. Depending on the buttons the user clicks, the program moves it to another subdirectory with a new name. I am using python 2.4 with wxpython 2.6 on a windowsxp machine. I encounter a permission denied error when trying to move the file. It appears to be caused due to the loading of the pdf file into the IEHtmlWindow. The program is too long to post here, but below are some snippets of the code. self.PDFPanel = iewin.IEHtmlWindow(self, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE) ... fileName = 'C:\\test.pdf' self.PDFPanel.LoadUrl(fileName) ... # if I do this: self.PDFPanel.Destroy() # then the following shutil.move works # else I get a [Errno 13] Permission denied: 'C:\\test.pdf' # tried loading another pdf file before doing shutil.move # like: self.PDFPanel.LoadUrl(C:\\Temp.pdf) which loaded fine, but # I still got a permission denied error shutil.move(fileName, 'C:\\NewName.pdf') As stated in the comments above, if I destroy the IEHtmlWindow, then the move works fine. I do not want to destroy it because I want to continue using it to load the next pdf file to work on renaming. I tried self.PDFPanel.LoadUrl('about:blank') before the shutil.move command. The window displayed a blank screen, but still the permission denied error. I then tried loading a different pdf file into the window, then doing the shutil.move on the first pdf, but still the permission denied error. If I destroy the window before the shutil.move command, then it works fine, but I need the IEHtmlWindow for other work. Any suggestions on how to get the IEHtmlWindow to let go of the pdf file before the shutil.move command without destroying the IEHtmlWindow all together? Thanks, Todd. -- http://mail.python.org/mailman/listinfo/python-list
Re: iewin.IEHtmlWindow shutil.move conflict
Update: I have found that if I delay the time between when I load a new url into IEHtmlWindow and then do the shutil.move it works fine. Such as: self.PDFPanel.Navigate('about:blank') #Must empty pdf frame so file is not locked Temp_dlg = wx.MessageDialog(self, 'Waiting for delay', 'Time delay', wx.OK | wx.ICON_INFORMATION ) Temp_dlg.ShowModal() Temp_dlg.Destroy() shutil.move(fileName, 'C:\\NewName.pdf') Surely there is a more eloquent way to accomplish this? Todd7 <[EMAIL PROTECTED]> wrote in news:YUslf.74898$2k5.73363 @dukeread09: > I am writing a python program to load a pdf file into an IEHtmlWindow > which displays it through adobe acrobat reader 7. Depending on the > buttons the user clicks, the program moves it to another subdirectory > with a new name. I am using python 2.4 with wxpython 2.6 on a windowsxp > machine. > > I encounter a permission denied error when trying to move the file. It > appears to be caused due to the loading of the pdf file into the > IEHtmlWindow. The program is too long to post here, but below are some > snippets of the code. > > self.PDFPanel = iewin.IEHtmlWindow(self, -1, style = > wx.NO_FULL_REPAINT_ON_RESIZE) > ... > fileName = 'C:\\test.pdf' > > self.PDFPanel.LoadUrl(fileName) > > ... > # if I do this: self.PDFPanel.Destroy() > # then the following shutil.move works > # else I get a [Errno 13] Permission denied: 'C:\\test.pdf' > # tried loading another pdf file before doing shutil.move > # like: self.PDFPanel.LoadUrl(C:\\Temp.pdf) which loaded fine, but > # I still got a permission denied error > > shutil.move(fileName, 'C:\\NewName.pdf') > > > As stated in the comments above, if I destroy the IEHtmlWindow, then the > move works fine. I do not want to destroy it because I want to continue > using it to load the next pdf file to work on renaming. I tried > self.PDFPanel.LoadUrl('about:blank') before the shutil.move command. > The window displayed a blank screen, but still the permission denied > error. I then tried loading a different pdf file into the window, then > doing the shutil.move on the first pdf, but still the permission denied > error. If I destroy the window before the shutil.move command, then it > works fine, but I need the IEHtmlWindow for other work. > > Any suggestions on how to get the IEHtmlWindow to let go of the pdf file > before the shutil.move command without destroying the IEHtmlWindow all > together? > > Thanks, > Todd. > -- http://mail.python.org/mailman/listinfo/python-list