Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Python wxTree saving the tree to file
  2. def project_save(self):
  3.  
  4.  
  5.     try:
  6.         output = open(self.project_file, 'w+')
  7.         output.write(self.tree.GetItemText(self.root) + 'n')
  8.         count = self.tree.GetChildrenCount(self.root)
  9.         iter = 0
  10.         child = ''
  11.  
  12.         for i in range(count):
  13.             if i == 0:
  14.                 child, cookie = self.tree.GetFirstChild(self.root)
  15.  
  16.             else:
  17.                 child, cookie = self.tree.GetNextChild(self.root, cookie)
  18.  
  19.             output.write(self.tree.GetItemText(child) + 'n')
  20.         output.close()
  21.         self.projectdirty = False
  22.  
  23.     except IOError:
  24.         MsgDlg(self, 'There was an error saving the new project file.', 'Error!', wx.OK)
  25.        
  26. root
  27.  |
  28.   ---item
  29.  |
  30.   ---item
  31.        
  32. root
  33. |
  34.   ---item
  35.  |
  36.   ---item
  37.  |
  38.   -node
  39.     |
  40.      ---item
  41.     |
  42.      ---item