SIP4 python bindings for TQt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dirview.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python
  2. import sys
  3. from python_tqt.qt import *
  4. class Directory(TQListViewItem):
  5. def __init__(self, parent, name=None):
  6. apply(TQListViewItem.__init__,(self,parent))
  7. if isinstance(parent, TQListView):
  8. self.p = None
  9. self.f = '/'
  10. else:
  11. self.p = parent
  12. self.f = name
  13. self.c = []
  14. self.readable = 1
  15. def setOpen(self, o):
  16. if o and not self.childCount():
  17. s = self.fullName()
  18. thisDir = TQDir(s)
  19. if not thisDir.isReadable():
  20. self.readable = 0
  21. return
  22. files = thisDir.entryInfoList()
  23. if files:
  24. for f in files:
  25. fileName = str(f.fileName())
  26. if fileName == '.' or fileName == '..':
  27. continue
  28. elif f.isSymLink():
  29. d = TQListViewItem(self, fileName, 'Symbolic Link')
  30. elif f.isDir():
  31. d = Directory(self, fileName)
  32. else:
  33. if f.isFile():
  34. s = 'File'
  35. else:
  36. s = 'Special'
  37. d = TQListViewItem(self, fileName, s)
  38. self.c.append(d)
  39. TQListViewItem.setOpen(self, o)
  40. def setup(self):
  41. self.setExpandable(1)
  42. TQListViewItem.setup(self)
  43. def fullName(self):
  44. if self.p:
  45. s = self.p.fullName() + self.f + '/'
  46. else:
  47. s = '/'
  48. return s
  49. def text(self, column):
  50. if column == 0:
  51. return self.f
  52. elif self.readable:
  53. return 'Directory'
  54. else:
  55. return 'Unreadable Directory'
  56. a = TQApplication(sys.argv)
  57. mw = TQListView()
  58. a.setMainWidget(mw)
  59. mw.setCaption('Directory Browser')
  60. mw.addColumn('Name')
  61. mw.addColumn('Type')
  62. mw.resize(400, 400)
  63. mw.setTreeStepSize(20)
  64. root = Directory(mw)
  65. root.setOpen(1)
  66. mw.show()
  67. a.exec_loop()