Thread: [Fxruby-users] Treelist -- can't add new items with data.
Status: Inactive
Brought to you by:
lyle
From: Hugh S. S. E. E. <hg...@dm...> - 2003-08-12 16:28:43
|
I think I am being terminally stupid here or something. I have been fiddling with this thing for far longer than I care to mention. I have a tree list, which is supposed to hold a cross platform directory structure: thus it maps names with spaces onto numbers expressed as base 36 codes. When I add a name on its own, I can add to the tree, but if I put the data in, the item doesn't get added to the tree. I've missed something, but I've been staring at this so long I can't see what it is. The thing isn't happening when the "add category" button is pressed. The crucial code is here. @treeview = Hash.new() @treeview[""] = FXTreeList.new(contents, 10) treelist = @treeview[""] treelist.listStyle |= TREELIST_SHOWS_LINES | TREELIST_SHOWS_BOXES | TREELIST_ROOT_BOXES treelist.layoutHints |= LAYOUT_FILL_X|LAYOUT_FILL_Y @treeview["#{$equipdir}"] = treelist.addItemLast(nil, "equipment",nil, # openIcon nil, # closedIcon TreeData.new(treelist, "#{$equipdir}" ) # data ) # If an item is doubleclicked, we want to expand or contract # it as appropriate treelist.connect(SEL_DOUBLECLICKED) { |sender, selector, data| # puts "data is #{data.inspect} : #{data.class}" puts "data.data is #{data.data.inspect} : #{data.data.class}" treelist.selectItem(data) if treelist.itemOpened?(data) # true if open treelist.collapseTree(data) treelist.closeItem(data) else # false if closed treelist.openItem(data) treelist.expandTree(data) obtain_tree_entry(data.data) end } ops_panel = FXVerticalFrame.new(contents) @add_cat_btn = FXButton.new(ops_panel, "add Category") @add_cat_btn.connect(SEL_COMMAND) { data = EntryData.new(ops_panel,"New Category") result = NameEntryDialog.new(data).execute unless result.zero? newname = data.value.value #Which item was selected from the tree... if treelist.currentItem path = File.join(treelist.currentItem.full_path, Base36code.new($freelist.next).representation) @treeview[path] = treelist.addItemLast(treelist.currentItem, newname, nil, nil, TreeData.new(treelist, path)) else ; # raise "No item selected." end end } I know that an item is selected, because when I had bugs in that branch of the code the thing crashed. Do I need to fire off some kind of event, or something, to see the change to the tree? When I just did treelist.additem(treelist.current, "name") name got added. Hugh |
From: Lyle J. <jl...@cf...> - 2003-08-13 21:18:30
|
Hugh Sasse Staff Elec Eng wrote: > I have a tree list, which is supposed to hold a cross platform > directory structure: thus it maps names with spaces onto numbers > expressed as base 36 codes. When I add a name on its own, I can add > to the tree, but if I put the data in, the item doesn't get added to > the tree. I've missed something, but I've been staring at this so > long I can't see what it is. The thing isn't happening when the > "add category" button is pressed. The crucial code is here. <snip> > I know that an item is selected, because when I had bugs in that > branch of the code the thing crashed. Do I need to fire off some > kind of event, or something, to see the change to the tree? When I > just did treelist.additem(treelist.current, "name") name got added. OK, so you are /sure/ that it's getting inside the if-check inside the SEL_COMMAND handler for @add_cat_btn? @add_cat_btn.connect(SEL_COMMAND) { # collect info from dialog box unless result.zero? if treelist.currentItem puts "Yes, I am here!" @treeview[path] = treelist.addItemLast(...) end end } If we've confirmed that, please see what happens if you add a call to FXTreeList#recalc immediately following that: @treeview[path] = treelist.addItemLast(...) treelist.recalc Calling recalc() marks a widget's layout as "dirty", meaning it nudges the parent layout manager to recalculate the layout for that widget and its siblings. At first glance, I don't see why this should be necessary, and so I'm skeptical that it's going to make a difference. But I've been wrong before ;) If that doesn't work, let me know if you'd like me to take a closer look at the code. Hope this helps, Lyle |
From: Hugh S. S. E. E. <hg...@dm...> - 2003-08-14 10:36:02
|
On Wed, 13 Aug 2003, Lyle Johnson wrote: > Hugh Sasse Staff Elec Eng wrote: > > > expressed as base 36 codes. When I add a name on its own, I can add > > to the tree, but if I put the data in, the item doesn't get added to > > the tree. I've missed something, but I've been staring at this so > > <snip> > > > OK, so you are /sure/ that it's getting inside the if-check inside the > SEL_COMMAND handler for @add_cat_btn? Yes, I added the puts just before your recalc suggestion. > > If we've confirmed that, please see what happens if you add a call to > FXTreeList#recalc immediately following that: > > @treeview[path] = treelist.addItemLast(...) > treelist.recalc > > Calling recalc() marks a widget's layout as "dirty", meaning it nudges > the parent layout manager to recalculate the layout for that widget and > its siblings. At first glance, I don't see why this should be necessary, Agreed: I think additem should trigger that.... > and so I'm skeptical that it's going to make a difference. But I've been > wrong before ;) Well you're right this time, it didn't result in any items getting added to the tree. :-( > > If that doesn't work, let me know if you'd like me to take a closer look > at the code. Thank you, but before I trouble you with that, is there any way to get Fox to produce lots of logging? [If only one could ask it things, like SHRDLU!] > > Hope this helps, > > Lyle Hugh |
From: Hugh S. S. E. E. <hg...@dm...> - 2003-08-14 13:52:04
|
On Thu, 14 Aug 2003, Hugh Sasse Staff Elec Eng wrote: > Well you're right this time, it didn't result in any items getting > added to the tree. :-( further study shows from @add_cat_btn.connect(SEL_COMMAND) { data = EntryData.new(ops_panel,"New Category") result = NameEntryDialog.new(data).execute unless result.zero? newname = data.value.value #Which item was selected from the tree... if treelist.currentItem path = File.join(treelist.currentItem.full_path, Base36code.new($freelist.next).representation) puts "item is #{treelist.currentItem.inspect}, children=#{treelist.currentItem.numChildren}" @treeview[path] = treelist.addItemLast(treelist.currentItem, newname, nil, nil, TreeData.new(treelist, path)) puts "item is #{treelist.currentItem.inspect}, children=#{treelist.currentItem.numChildren}" treelist.recalc # tell treelist it has changed... # Message-ID: # <3F3...@cf...> else ; # raise "No item selected." end end } I get item is equipment, children=0 TreeData.new("/home/hgs/stores_loans/data/equipment/00b1bb0") ./stores_loans.rb:318:in `new' ./stores_loans.rb:318:in `initialize' ./stores_loans.rb:309:in `call' /usr/local/lib/ruby/site_ruby/1.6/fox/responder2.rb:57:in `onHandleMsg' ./stores_loans.rb:393:in `execute' ./stores_loans.rb:393:in `initialize' ./stores_loans.rb:388:in `call' /usr/local/lib/ruby/site_ruby/1.6/fox/responder2.rb:57:in `onHandleMsg' ./stores_loans.rb:461:in `run' ./stores_loans.rb:461 DirIndex.new("/home/hgs/stores_loans/data/equipment/00b1bb0" class: String) item is equipment, children=1 called catdialog.create() Which shows that the number of children is now 1, rather than 0, but none are displayed. Hugh |
From: Hugh S. S. E. E. <hg...@dm...> - 2003-08-15 11:03:54
|
I have just had some interesting results. I was explaining to someone that I have spent ages trying to do this, and, look, doesn't work, and when I double click on the treelist nothing happens, BUT IT DID! I now find that my items are being added to the treeItem but the item is not actually opened/expanded. OK, I can work with this. What is the semantic difference between opeing and expanding in tree lists? At the moment when I want to open I open and expand, and conversely collapse and close together. What is the right thing to do for these? My other problem is that the files do not seem to be being created correctly on the disk, but that is my fault entirely, not a misunderstanding about FXRuby, so I'm further than I was. Thank you. Hugh |
From: Lyle J. <jl...@cf...> - 2003-08-15 21:16:25
|
Hugh Sasse Staff Elec Eng wrote: > I have just had some interesting results. I was explaining to > someone that I have spent ages trying to do this, and, look, doesn't > work, and when I double click on the treelist nothing happens, BUT > IT DID! I now find that my items are being added to the treeItem > but the item is not actually opened/expanded. I should have thought of that. Oh well, glad to hear that it's working. > OK, I can work with this. What is the semantic difference between > opening and expanding in tree lists? At the moment when I want to > open I open and expand, and conversely collapse and close together. > What is the right thing to do for these? I think that what you are doing is the right thing to do, for your application. When you programmatically open or close an item (i.e. by calling the openItem() or closeItem() methods) it only changes that item's state from "opened" to "closed", or vice-versa. If that tree item has different icons for the open and closed state, such as an opened and closed file folder, this will be the only visible cue of the change. There are some situations where it is useful to make this distinction (of opened versus closed); I'll describe one of them in a few paragraphs. But for your application, this may not be a useful distinction. In that, you may want to just use the same icon for both the opened and closed state and ignore that issue altogether (i.e. just worry about expanding or collapsing the subtrees at the appropriate times). Expanding and collapsing parts of the tree is a separate action and is independent of the "root" item's opened or closed state. That is, you can expand the subtree under an item without actually "opening" it. I'm not sure I can give you a precise description of the /semantics/ of open/close versus expand/collapse. This feature of the tree list was specifically added for developing Windows Explorer-like widgets, where there's a tree list on the left and a different view of the current item's contents on the right. So, if the user clicks *once* on a directory folder in the tree list (e.g. "My Documents"), that tree item is *opened*, and that folder's contents are shown in the right-hand pane; but the tree item is not *expanded* unless the user double-clicks on it. Hope this helps, Lyle |
From: Hugh S. S. E. E. <hg...@dm...> - 2003-08-15 17:08:05
|
On Fri, 15 Aug 2003, Lyle Johnson wrote: > Hugh Sasse Staff Elec Eng wrote: > > > IT DID! I now find that my items are being added to the treeItem > > but the item is not actually opened/expanded. > > I should have thought of that. Oh well, glad to hear that it's working. I have made it default to doing that now. > > > OK, I can work with this. What is the semantic difference between > > opening and expanding in tree lists? At the moment when I want to > > open I open and expand, and conversely collapse and close together. > > What is the right thing to do for these? > > I think that what you are doing is the right thing to do, for your > application. Yes, I suspect so. > > When you programmatically open or close an item (i.e. by calling the > openItem() or closeItem() methods) it only changes that item's state > from "opened" to "closed", or vice-versa. If that tree item has > different icons for the open and closed state, such as an opened and > closed file folder, this will be the only visible cue of the change. OK, so it doesn't do anything else. Fair enough. > > There are some situations where it is useful to make this distinction > (of opened versus closed); I'll describe one of them in a few Yes, Windows Explorer does this with the left pane you can open the directory in the right without expanding on the left. It's this sort of feel I wanted to supply to users, so this is good. > paragraphs. But for your application, this may not be a useful > distinction. In that, you may want to just use the same icon for both In fact I haven't drawn or found icons yet, that can wait, but I agree. > > > I'm not sure I can give you a precise description of the /semantics/ of > open/close versus expand/collapse. I think you have actually, but since there is no comment about this that I can find... I'll have to poke about in the FXRuby 1.0.25 dist and add some rdocs for others who tread this way, and bowl a patch in your direction. > > This feature of the tree list was specifically added for developing > Windows Explorer-like widgets, where there's a tree list on the left and > a different view of the current item's contents on the right. So, if the Right. This ability to carry experience over is good. > user clicks *once* on a directory folder in the tree list (e.g. "My > Documents"), that tree item is *opened*, and that folder's contents are > shown in the right-hand pane; but the tree item is not *expanded* unless > the user double-clicks on it. Thanks. and the + signs behave slightly differently I think, in Win, but I'll have to stop "using it by coincidence" and actually note what happens next time! > > Hope this helps, Yes, that's the info I was after. > > Lyle > Hugh |