Changeset 4059
- Timestamp:
- 05/03/2008 05:33:31 PM (2 months ago)
- Files:
-
- trunk/dabo/ui/uiwx/dTreeView.py (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/ui/uiwx/dTreeView.py
r3303 r4059 24 24 # Nodes can have objects associated with them 25 25 self._object = None 26 # Custom text to display as a tooltip 27 self._toolTipText = None 26 28 # Add minimal Dabo functionality 27 29 self.afterInit() … … 262 264 263 265 266 def _getToolTipText(self): 267 return self._toolTipText 268 269 def _setToolTipText(self, val): 270 if self._constructed(): 271 self._toolTipText = val 272 else: 273 self._properties["ToolTipText"] = val 274 275 264 276 BackColor = property(_getBackColor, _setBackColor, None, 265 277 _("Background color of this node (str, 3-tuple, or wx.Colour)") ) … … 325 337 Siblings = property(_getSiblings, None, None, 326 338 _("List of all nodes with the same parent node. (list of dNodes)") ) 327 339 340 ToolTipText = property(_getToolTipText, _setToolTipText, None, 341 _("""Text to display when the mouse hovers over this node. The tree's 342 UseNodeToolTips property must be True for this to have any effect. (str)""")) 343 344 328 345 329 346 DynamicBackColor = makeDynamicProperty(BackColor) … … 338 355 DynamicImage = makeDynamicProperty(Image) 339 356 DynamicSelected = makeDynamicProperty(Selected) 340 357 DynamicToolTipText = makeDynamicProperty(ToolTipText) 358 341 359 342 360 … … 352 370 # Class to use for creating nodes 353 371 self._nodeClass = dNode 372 # Default size for images added to the tree. 373 self._imageSize = (16, 16) 374 # Do we set tooltips from the nodes? 375 self._useNodeToolTips = False 376 # Store the default ToolTipText while UseNodeToolTips is True 377 self._storedToolTipText = None 354 378 355 379 style = self._extractKey((properties, attProperties, kwargs), "style", 0) | wx.TR_HAS_VARIABLE_ROW_HEIGHT … … 405 429 self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.__onTreeBeginDrag) 406 430 self.Bind(wx.EVT_TREE_END_DRAG, self.__onTreeEndDrag) 431 self.Bind(wx.EVT_MOTION, self.__onTreeMouseMove) 407 432 408 433 … … 446 471 447 472 448 def clear(self ):473 def clear(self, clearImageList=False): 449 474 self.DeleteAllItems() 450 475 self.nodes = [] 476 if clearImageList: 477 il = self.GetImageList() 478 if il: 479 il.RemoveAll() 480 self.__imageList = {} 451 481 452 482 … … 531 561 a reference to it that is retrievable via the key value. 532 562 """ 563 # Default image size 564 wd, ht = self.ImageSize 565 il = self.GetImageList() 566 if not il: 567 il = wx.ImageList(wd, ht, initialCount=0) 568 self.AssignImageList(il) 569 else: 570 if il.GetImageCount(): 571 wd, ht = il.GetSize(0) 533 572 if key is None: 534 573 key = str(img) 535 574 if isinstance(img, basestring): 536 img = dabo.ui.strToBmp(img) 537 il = self.GetImageList() 538 if not il: 539 il = wx.ImageList(16, 16, initialCount=0) 540 self.AssignImageList(il) 575 img = dabo.ui.strToBmp(img, width=wd, height=ht) 541 576 idx = il.Add(img) 542 577 self.__imageList[key] = idx … … 783 818 784 819 785 def makeDirTree(self, dirPath, wildcard=None, showHidden=False): 786 """Make this dTreeView show a filesystem directory hierarchy. 820 def makeDirTree(self, dirPath, wildcard=None, ignored=None, 821 showHidden=False, expand=False): 822 """Make this dTreeView show a filesystem directory hierarchy. You 823 can specify a wildcard pattern: e.g., "*py" will only include files 824 ending in 'py'. If no wildcard is specified, all files will be included. 825 826 You can also specify file patterns to ignore in the 'ignore' parameter. 827 This can be a single string of a file pattern, or a list of such patterns. 828 Any file matching any of these patterns will not be included in the tree. 829 830 By default, hidden files (i.e., those beginning with a period) are ignored. 831 You can optionally show them by passing True in the showHidden 832 parameter. 833 834 The tree defaults to fully collapsed; you can change it to fully 835 expanded by passing True in the 'expand' parameter. 787 836 788 837 Warning: Don't use this for huge hierarchies, as it blocks while … … 790 839 they are opened. 791 840 """ 792 self.clear() 841 self.clear(clearImageList=True) 842 # Add the standard images for a directory tree 843 self.addImage("folder", "folder") 844 self.addImage("folderopen", "folderopen") 845 self.addImage("normalfile", "file") 846 self.addImage("executablefile", "executablefile") 847 793 848 # Add any trailing slash character 794 849 self._pathNode = {} … … 796 851 def addNode(showHid, currDir, fNames): 797 852 prnt, nm = os.path.split(currDir) 798 if not showHid: 799 if nm[:1] == ".": 800 return 853 if not showHid and nm.startswith("."): 854 return 801 855 try: 802 856 nd = self._pathNode[currDir] = self._pathNode[prnt].appendChild(nm) … … 808 862 # parent wasn't added, because it was hidden 809 863 return 864 self.setNodeImg(nd, "folder", "normal") 865 self.setNodeImg(nd, "folderopen", "expanded") 866 nd.ToolTipText = currDir 867 acceptedNames = ignoredNames = None 868 if wildcard is not None: 869 acceptedNames = glob.glob(os.path.join(currDir, wildcard)) 870 if ignored is not None: 871 ignoredNames = [] 872 for ig in ignored: 873 ignoredNames += glob.glob(os.path.join(currDir, ig)) 810 874 for f in fNames: 811 875 fullName = os.path.join(currDir, f) … … 813 877 # it will be added as a directory 814 878 continue 815 if not showHid: 816 if f[:1] == ".": 879 if not showHid and f.startswith("."): 880 continue 881 if acceptedNames is not None: 882 if fullName not in acceptedNames: 817 883 continue 818 if wildcard is not None: 819 res = glob.glob(os.path.join(currDir, wildcard)) 820 if not fullName in res: 884 if ignoredNames is not None: 885 if fullName in ignoredNames: 821 886 continue 822 nd.appendChild(f) 887 kid = nd.appendChild(f) 888 self.setNodeImg(kid, "file", "normal") 889 kid.ToolTipText = fullName 823 890 824 891 def sortNode(arg, currDir, fNames): … … 826 893 self.SortChildren(self._pathNode[currDir].itemID) 827 894 895 if ignored and not isinstance(ignored, (list, tuple)): 896 # single string passed 897 ignored = [ignored] 828 898 os.path.walk(dirPath, addNode, showHidden) 829 899 os.path.walk(dirPath, sortNode, None) 900 if expand: 901 self.expandAll() 830 902 831 903 … … 965 1037 966 1038 1039 def __onTreeMouseMove(self, evt): 1040 if self._useNodeToolTips: 1041 nd = self.getNodeUnderMouse() 1042 if nd: 1043 if nd.ToolTipText: 1044 self.ToolTipText = nd.ToolTipText 1045 else: 1046 self.ToolTipText = nd.Caption 1047 else: 1048 if self._storedToolTipText is not None: 1049 self.ToolTipText = self._storedToolTipText 1050 else: 1051 self.ToolTipText = "" 1052 1053 967 1054 def _getBaseNodes(self): 968 1055 if self.ShowRootNode: … … 981 1068 if val: 982 1069 self._addWindowStyleFlag(wx.TR_EDIT_LABELS) 1070 1071 1072 def _getImageSize(self): 1073 return self._imageSize 1074 1075 def _setImageSize(self, val): 1076 if self._constructed(): 1077 self._imageSize = val 1078 else: 1079 self._properties["ImageSize"] = val 983 1080 984 1081 … … 1100 1197 # Control may not be constructed yet 1101 1198 pass 1102 1199 1200 1201 def _getUseNodeToolTips(self): 1202 return self._useNodeToolTips 1203 1204 def _setUseNodeToolTips(self, val): 1205 if self._constructed(): 1206 if val: 1207 self._storedToolTipText = self.ToolTipText 1208 else: 1209 if self._storedToolTipText is not None: 1210 self.ToolTipText = self._storedToolTipText 1211 self._useNodeToolTips = val 1212 else: 1213 self._properties["UseNodeToolTips"] = val 1214 1103 1215 1104 1216 BaseNodes = property(_getBaseNodes, None, None, … … 1110 1222 _("""Specifies whether the tree labels can be edited by the user.""")) 1111 1223 1224 ImageSize = property(_getImageSize, _setImageSize, None, 1225 _("Size of images added to the tree. Default=(15, 15) (2-tuple of int)")) 1226 1112 1227 MultipleSelect = property(_getMultipleSelect, _setMultipleSelect, None, 1113 1228 _("""Specifies whether more than one node may be selected at once.""")) … … 1138 1253 ShowRootNodeLines = property(_getShowRootNodeLines, _setShowRootNodeLines, None, 1139 1254 _("""Specifies whether vertical lines are shown between root siblings.""")) 1255 1256 UseNodeToolTips = property(_getUseNodeToolTips, _setUseNodeToolTips, None, 1257 _("""When True, the ToolTipText displayed is taken from the node. 1258 Default=False (bool)""")) 1259 1140 1260 1141 1261 … … 1163 1283 self.expandAll() 1164 1284 self.Hover = True 1165 1166 def onMouseMove(self, evt): 1167 nd = self.getNodeUnderMouse() 1168 if nd: 1169 self.ToolTipText = nd.Caption 1170 else: 1171 self.ToolTipText = "" 1172 1285 self.ToolTipText = _("Default ToolTip for the Tree") 1286 self.ImageSize = (16, 16) 1287 1173 1288 def onHit(self, evt): 1174 ## pkm: currently, Hit happens on left mouse up, which totally ignores1175 ## keyboarding through the tree. I'm wondering about mapping1176 ## TreeSelection instead... thoughts?1177 1289 print "Hit!" 1178 1290 … … 1240 1352 chk = dabo.ui.dCheckBox(mp, Caption="ShowRootNodeLines", 1241 1353 DataSource=tree, DataField="ShowRootNodeLines") 1354 sz.append(chk, halign="Left") 1355 1356 chk = dabo.ui.dCheckBox(mp, Caption="UseNodeToolTips", 1357 DataSource=tree, DataField="UseNodeToolTips") 1242 1358 sz.append(chk, halign="Left") 1243 1359 … … 1255 1371 sz.appendSpacer(10) 1256 1372 1257 1258 1373 def onExpandAll(self, evt): 1259 1374 self.tree.expandAll() 1260 1261 1375 1262 1376 def onCollapseAll(self, evt):
