in reply to Re^2: MacOS Finder (Column view) in Tk.
in thread MacOSX Finder (Column view) in Tk.

I like Tk, but I'm also aware of it's drawbacks. If I were you, I would do this in Gtk2, and use the TreeView. The way Gtk2 has it setup, it is extremely configurable, and more suited to expanding/collapsing trees, which can be nested to various depths. The model they use is much more complex, but it makes it more configurable. For instance, you can set it up, that as you click and open your tress, if there are multiple files to choose from, you can nest a drop down box(combbox) at any point in your tree. It would be a very good opportunity to learn Gtk2. You can include icons in your cells too. Check out this, but I'm not sure if Mac has Gtk2 yet .
#! /usr/bin/perl -w use strict; use Gtk2 '-init'; use Glib qw/TRUE FALSE/; #standard window creation, placement, and signal connecting my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); $window->set_border_width(5); $window->set_position('center_always'); #this vbox will geturn the bulk of the gui my $vbox = &ret_vbox(); #add and show the vbox $window->add($vbox); $window->show(); #our main event-loop Gtk2->main(); sub ret_vbox { my $vbox = Gtk2::VBox->new(FALSE,5); #create a scrolled window that will host the treeview my $sw = Gtk2::ScrolledWindow->new (undef, undef); $sw->set_shadow_type ('etched-out'); $sw->set_policy ('automatic', 'automatic'); #This is a method of the Gtk2::Widget class,it will force a mi +nimum #size on the widget. Handy to give intitial size to a #Gtk2::ScrolledWindow class object $sw->set_size_request (300, 300); #method of Gtk2::Container $sw->set_border_width(5); #this is one of the provided base Gtk2::TreeModel classes. my $tree_store = Gtk2::TreeStore->new(qw/Glib::String/); #fill it with arbitry data foreach my $parent_nr (1..30) { #the iter is a pointer in the treestore. We #use to add data. my $iter = $tree_store->append(undef); $tree_store->set ($iter,0 => "Parent $parent_nr"); foreach my $child (1..3){ #here we append child iters to the parent iter #and add data to those chils iters. my $iter_child = $tree_store->append($iter); $tree_store->set ($iter_child,0 => "Child $child of Pare +nt $parent_nr"); foreach my $gchild (1..3){ #here we append child iters to the parent iter #and add data to those chils iters. my $iter_child = $tree_store->append($ +iter_child); $tree_store->set ($iter_child,0 => "GrandC +hild $gchild of Parent $parent_nr"); } } } #this will create a treeview, specify $tree_store as its model my $tree_view = Gtk2::TreeView->new($tree_store); #create a Gtk2::TreeViewColumn to add to $tree_view my $tree_column = Gtk2::TreeViewColumn->new(); $tree_column->set_title ("Click to sort"); #create a renderer that will be used to display info #in the model my $renderer = Gtk2::CellRendererText->new; #add this renderer to $tree_column. This works like a Gtk2::Hb +ox # so you can add more than one renderer to $tree_column + $tree_column->pack_start ($renderer, FALSE); # set the cell "text" attribute to column 0 #- retrieve text from that column in treestore # Thus, the "text" attribute's value will depend on the row's + value # of column 0 in the model($treestore), # and this will be displayed by $renderer, # which is a text renderer $tree_column->add_attribute($renderer, text => 0); #add $tree_column to the treeview $tree_view->append_column ($tree_column); # make it searchable $tree_view->set_search_column(0); # Allow sorting on the column $tree_column->set_sort_column_id(0); # Allow drag and drop reordering of rows $tree_view->set_reorderable(TRUE); $sw->add($tree_view); $vbox->pack_start($sw,TRUE,TRUE,0); $vbox->show_all(); return $vbox; }

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^4: MacOS Finder (Column view) in Tk.
by Ace128 (Hermit) on Feb 21, 2006 at 00:44 UTC
    Hmm, can you elaborate on the problems with Tk here?
      Thats too big of of question. The basic drawback is that each Tk widget is an entity in it's own world, whereas every widget in a gtk2 is all based on the same object model. This makes it difficult in Tk to get low-level interaction between widgets in an app.

      But to just make a list of common complaints about Tk in complex apps...... sorting lists is difficult, memory is not cleaned up very well, getting colors into the various portions of widgets can be a mess(gtk2 with Pango markup lets you mix colors and fonts in a single label), no drag-and-drop support( yes, Gtk2 will let you drag files from one widget, and dump them onto another), better threads support, etc, etc, etc.

      Now I'm not trying to disparage Tk. It is very good for what it is, but Gtk2 has alot more thought being put into it. So which would you choose for a big, long-term project?


      I'm not really a human, but I play one on earth. flash japh
        After some research about Gtk2, and also managing to install it on a windows machine, I really must say I like it. Specially since it really looks alot like Tk. This is good, since I think Im gonna implement this Widget in Tk, and port it all to Gtk2 later instead... I've actually managed to create something that looks like the thing I want with just a few rows in Tk... using HList. Although I think I have to modify the HList widget some for the bindings part... so I can add more callbacks to it and such.