From: hwg <hw...@ya...> - 2007-03-16 13:11:53
|
I have a treeCtrl and I would like to have the ability to select multiple items in the tree. I know the underlying wxTreeCtrl has some flags: e.g. style = wx.TR_MULTIPLE | wx.TR_HIDE_ROOT But I don't know how (or if) I can access these attributes from my pythoncard code. Any help would be appreciated. hg --------------------------------- Don't pick lemons. See all the new 2007 cars at Yahoo! Autos. |
From: Jussi S. <jus...@pp...> - 2007-03-23 10:11:17
|
hwg kirjoitti: > I have a treeCtrl and I would like to have the ability to select > multiple items in the tree. > > I know the underlying wxTreeCtrl has some flags: > > e.g. style = wx.TR_MULTIPLE | wx.TR_HIDE_ROOT > > But I don't know how (or if) I can access these attributes from my > pythoncard code. > > Any help would be appreciated. > > hg > > ------------------------------------------------------------------------ > Don't pick lemons. > See all the new 2007 cars > <http://autos.yahoo.com/new_cars.html;_ylc=X3oDMTE0OGRsc3F2BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDbmV3Y2Fycw--> > at Yahoo! Autos. > <http://autos.yahoo.com/new_cars.html;_ylc=X3oDMTE0OGRsc3F2BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDbmV3Y2Fycw--> > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users > Here's a part of the PythonCard minimalTree.py file that I have been using to get acquainted with the tree control. I've not really used the tree control for anything but played a little with it last september when someone asked something about this control. So the code may differ from the minimalTree example in othe places also, but the modifications I made to solve your problem are shown with comments: import wx # <== added by JS from PythonCard import model # events # itemActivated, itemExpanding, itemExpanded, # selectionChanging, selectionChanged class Minimal(model.Background): def on_initialize(self, event): tree = self.components.tree self.root = tree.addRoot("1") #print tree.getItemText(self.root) tree.setItemHasChildren(self.root, 1) tree.selectItem(self.root) print dir(tree) # <== added by JS tree.SetWindowStyleFlag(wx.TR_MULTIPLE) # <== added by JS Here's an explanation of what I did (in this order): 1. Added the print and copied its output to an editor 2. Searched among the bunch of interesting sounding methods for names containing 'style' in them 3. Read a litlle bit of the wxTreeCtrl documentation in the wxWidgets docs finding the term 'Window styles' there. 4. Decided that the appropriate method to use must be SetWindowStyleFlag 5. Browsed through the source of tree.py in C:\Python24\Lib\site-packages\PythonCard\components to find any additional info. While doing this found the way to refer to the TR_MULTIPLE constant 6. Made the changes and tested. Seems to work. HTH, Jussi -- Jussi Salmela http://personal.inet.fi/cool/operator/ |
From: hwg <hw...@ya...> - 2007-03-26 16:36:11
|
Thanks for the help. This worked for the TR_MULTIPLE attribute. Curiously, when I tried to set TR_HIDE_ROOT, Python crashed! hg Jussi Salmela <jus...@pp...> wrote: hwg kirjoitti: > I have a treeCtrl and I would like to have the ability to select > multiple items in the tree. > > I know the underlying wxTreeCtrl has some flags: > > e.g. style = wx.TR_MULTIPLE | wx.TR_HIDE_ROOT > > But I don't know how (or if) I can access these attributes from my > pythoncard code. > > Any help would be appreciated. > > hg > > ------------------------------------------------------------------------ > Don't pick lemons. > See all the new 2007 cars > > at Yahoo! Autos. > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users > Here's a part of the PythonCard minimalTree.py file that I have been using to get acquainted with the tree control. I've not really used the tree control for anything but played a little with it last september when someone asked something about this control. So the code may differ from the minimalTree example in othe places also, but the modifications I made to solve your problem are shown with comments: import wx # <== added by JS from PythonCard import model # events # itemActivated, itemExpanding, itemExpanded, # selectionChanging, selectionChanged class Minimal(model.Background): def on_initialize(self, event): tree = self.components.tree self.root = tree.addRoot("1") #print tree.getItemText(self.root) tree.setItemHasChildren(self.root, 1) tree.selectItem(self.root) print dir(tree) # <== added by JS tree.SetWindowStyleFlag(wx.TR_MULTIPLE) # <== added by JS Here's an explanation of what I did (in this order): 1. Added the print and copied its output to an editor 2. Searched among the bunch of interesting sounding methods for names containing 'style' in them 3. Read a litlle bit of the wxTreeCtrl documentation in the wxWidgets docs finding the term 'Window styles' there. 4. Decided that the appropriate method to use must be SetWindowStyleFlag 5. Browsed through the source of tree.py in C:\Python24\Lib\site-packages\PythonCard\components to find any additional info. While doing this found the way to refer to the TR_MULTIPLE constant 6. Made the changes and tested. Seems to work. HTH, Jussi -- Jussi Salmela http://personal.inet.fi/cool/operator/ --------------------------------- Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. |
From: Jussi S. <jus...@pp...> - 2007-03-26 20:18:44
|
hwg kirjoitti: > Thanks for the help. This worked for the TR_MULTIPLE attribute. > Curiously, when I tried to set TR_HIDE_ROOT, Python crashed! > > hg > > *//* I don't even know how the wx.TR_HIDE_ROOT is supposed to make the tree to behave. It 'works' for me and doesn't crash. Are you using new enough versions of Python, wxPython and PythonCard? My environment is: PythonCard version: 0.8.2 wxPython version: 2.6.1.0 Python version: 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] Platform: win32 The only thing I can make wx.TR_HIDE_ROOT to do is hide the whole tree and I can never get it back to visible again. I do this on initialize: tree.SetWindowStyleFlag(wx.TR_MULTIPLE) # <== added by JS self.initialFlags = tree.GetWindowStyleFlag() tree.SetWindowStyleFlag(self.initialFlags | wx.TR_HIDE_ROOT) # <== added by JS print self.initialFlags and it hides the tree alright but then I have a button with code that is supposed to do the opposite i.e. make the tree visible again but doesn't: tree = self.components.tree print tree.GetWindowStyleFlag() if tree.GetWindowStyleFlag() & wx.TR_HIDE_ROOT: tree.SetWindowStyleFlag(self.initialFlags) else: tree.SetWindowStyleFlag(self.initialFlags | wx.TR_HIDE_ROOT) print tree.GetWindowStyleFlag() tree.redraw() I tried tree.Refresh() also with no avail. But on the bright side is that it doesn't crash ;) Sorry I can't be of more help Cheers, Jussi -- Jussi Salmela http://personal.inet.fi/cool/operator/ |