Skip to content Skip to sidebar Skip to footer

Wxpython Refresh Window On Button Press

I have been having some trouble with my Python program. Basically, it is a very very simple file manager. I have been trying to get it to move between folders (user clicks a folde

Solution 1:

I think the problem is that you

  • Create new panel for each folder
  • Don't delete the old panels

I would suggest you to save the old panel somewhere at self.panel and call self.panel.Destroy();self.panel = wx.Panel(self) on each time.

The better option is to use wx.ListCtrl, catch EVT_LIST_ITEM_ACTIVATED and then delete the list and fill it with the items:

__init__:
self.ListCtrl = wx.ListCtrl(self)
self.listCtrl.InsertColumn(0, 'name')
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnChangeFolder, self.listCtrl)
self.il = wx.ImageList(16, 16)
self.il.Add(wx.Image("folder.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap())
self.listCtrl.AssignImageList(self.il)
self.folders = fileBrowser.print_items("/home/gum/Documents")
self.UpdateList()
UpdateList:
self.listCtrl.DeleteAllItems()
for index, item inenumerate(self.folders):
    self.listCtrl.Append((item, ))
    self.listCtrl.SetItemImage(index, 0)
    # 0 is the ImageList index, change it for other icons
OnChangeFolder:
self.folders = file.Browser.print_items(self.listCtrl.GetFocusedItem().GetText())
self.UpdateList

BTW, the wx style indicates that methods and classes are also CamelCased, just that you know :)

Post a Comment for "Wxpython Refresh Window On Button Press"