Here''s my first try at a contribution to the wxRuby project: The tree control seemed to lack a more Ruby-ish way to add a bulk of items to a tree control (and to easily connect a data structure to a tree). Since tree view can be seen as an array of arrays, I simply added a method called append_array (see attached file). With it, you can add a full tree as simple as: --- root = treectrl.add_root("Root") treectrl.append_array(root, ["one", "two", ["sub1", "sub2"], "three"]) --- It also gives your objects the possibility to interact a bit more with the tree item, if needed. See the docs for the method. My plans are also to add at least an update_array_item() method, to be able to refresh an object''s visual tree state dynamically. However, the wxRuby docs for TreeCtrl#set_item_image isn''t in Ruby syntax, so I don''t know how to figure out the last parameter (which I need). Would this be an useful addition to the existing wxRuby tree control? Comments are welcome! Best regards, Jari Williamsson _______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users
Hi Jari Jari Williamsson wrote:> Here''s my first try at a contribution to the wxRuby project: > The tree control seemed to lack a more Ruby-ish way to add a bulk of > items to a tree control (and to easily connect a data structure to a > tree). Since tree view can be seen as an array of arrays, I simply > added a method called append_array (see attached file). With it, you > can add a full tree as simple as: > > --- > root = treectrl.add_root("Root") > treectrl.append_array(root, ["one", "two", ["sub1", "sub2"], "three"]) > ---Thanks, I like this. If it''s OK with you, I''m going to add it to wxSugar, where there are some other convenient methods. Things to consider in developing this approach might be: * How can we create a more general "nice" API for bulk adding items to all multi-item classes, like ListBox, ListCtrl etc * It would be useful to have a way of adding item data, which I usually need to use with these type of classes> My plans are also to add at least an update_array_item() method, to be > able to refresh an object''s visual tree state dynamically. However, > the wxRuby docs for TreeCtrl#set_item_image isn''t in Ruby syntax, so I > don''t know how to figure out the last parameter (which I need).The values are Wx::TREE_ITEM_ICON_EXPANDED, Wx::TREE_ITEM_ICON_NORMAL etc - see samples/treectrl/ for an example of their usage. The docs needed a little tidy-up, thanks for the report. On a tangent, it would also be nice to have a way to remember and reestore a TreeCtrl''s state in terms of the expanded and collapsed items. I''ve written something that does this for an app, but I wonder if it would be more generally useful. alex PS - I''ve just committed the whole set of Graphics* classes (except Renderer, which didn''t appear useful in Ruby) to SVN trunk. The transforms (shears etc), gradient fills and so on work really impressively, and all anti-aliased
>On a tangent, it would also be nice to have a way to remember and >reestore a TreeCtrl''s state in terms of the expanded and collapsed >items. I''ve written something that does this for an app, but I wonder if >it would be more generally useful.I would really like to see that functionality added, I have thought about adding something similar but it is very low on my priority list. Sean
Alex Fenton wrote:> Thanks, I like this. If it''s OK with you, I''m going to add it to > wxSugar, where there are some other convenient methods.That sounds good, but I need to first add a small thing to the tree_item_ref callback method that I missed. When the object (optionally) receives the info about the treeitem id, it has to get the TreeCtrl object as well. Otherwise the object can''t reference the tree id in a good way, if the object resides in another module etc. I''ll e-mail you an update later today.> * How can we create a more general "nice" API for bulk adding items to > all multi-item classes, like ListBox, ListCtrl etcI''ll look into this! Perhaps the API terminology should be streamlined for these kind of Ruby bulk-add (and related) methods? Any suggestions?> * It would be useful to have a way of adding item data, which I usually > need to use with these type of classesAs you''ve seen, present in my TreeCtrl implementation, but probably harder to do in a ListBox, since there''s no item_data for the strings. However, I''m thinking of adding a ListBox#insert_obj_items(), with the syntax: ListBox#insert_obj_items(array, method, pos) This would work like ListBox#insert_items(), appart from that you can specify the method in the array objects where the data should be retrieved (and then a to_s conversion to make sure the data is in string format). Often, the data for list boxes are already available in object arrays, but not necessarily in string arrays.> PS - I''ve just committed the whole set of Graphics* classes (except > Renderer, which didn''t appear useful in Ruby) to SVN trunk. The > transforms (shears etc), gradient fills and so on work really > impressively, and all anti-aliasedSounds great! I''ll see if I can get the SVN to work. Best regards, Jari Williamsson