in reply to MacOSX Finder (Column view) in Tk.

Just brainstorming......you are asking to do alot, packing alot of functionality into a Tk widget. In Gtk2, what you are describing is called TreeView.

As a start, you can look at Tk::DirTree.

#!/usr/bin/perl use strict; use Tk; require Tk::DirTree; #### DEBUG #### $main::DEBUG = 1; # The initial directory my $initial_dir = '/'; # The main window... my $main_window = new MainWindow( -title => 'one test' ); # A scrolled directory tree my $tree = $main_window->Scrolled( 'DirTree', -width => 35, -height => 25, -scrollbars => 'osoe', -background => 'White', -selectmode => 'single', -selectbackground => 'DarkBlue', -selectforeground => 'White', -showhidden => 1, -directory => $initial_dir ); $tree->pack( -expand => 'yes', -fill => 'both', -padx => 2, -pady => 2, -side => 'left' ); # create the menu to be used for poping up my $menu = $main_window->Menu( -tearoff => 0, -menuitems => [ [ 'Button' => 'What?', -command => sub { print STDERR "Item is '", ( $tree->selectionGet() )[0] +, "'\n"; } ] ] ); # Create the binding for the right mouse button $tree->bind( '<Button-3>' => [ sub { my $widget = shift; my $y = shift; my $current_item = $widget->nearest($y); my $previous_item = ( $widget->selectionGet() )[0]; $main::DEBUG and print STDERR "old :", $previous_item, +"\n"; $main::DEBUG and print STDERR "current:", $current_item, +"\n"; # Clear selection and then set it to the new item $widget->selectionClear(); $widget->selectionSet($current_item); ### $$$$ Doesn't work: &destructor never called $menu->OnDestroy( [ \&destructor, $widget, $previous_item +] ); # Displaying the menu... # $menu->Popup( # -popover => 'cursor', # -popanchor => 'nw' # ); $menu->post($widget->pointerxy); destructor($widget, $previous_item); }, Ev('y') ] ); sub destructor { my $widget = shift; my $item = shift; $main::DEBUG and print STDERR "in destructor, item:", $item, "\n"; # Set selection to a particular item... $widget->selectionClear(); $widget->selectionSet($item); } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +- - - - $tree->waitVisibility(); $tree->selectionSet($initial_dir); MainLoop(); #### program sends above ####################
Whenever you want to make something really complex, and you want full control over all the views, colors, fonts. etc. you are best off making it on a canvas, where you have full control. ( I would say use Zinc even, so you can do some nice zooming, when open files .)

Finally, I will mention that you are probably trying to do something in Perl which is better suited for C. Perl will be slower than alot of the currently available file manager/browsers like midnight commander, and the slew of new ones that can be found on freshmeat.net. So it will be a very educational experience for you, but may not fill any need, that already isn't already being done by c-based apps. Plus alot of the functionality you are musing about, falls under the realm of Desktop Manager, and you might consider approaching this from the viewpoint of managing the Desktop, like perlbox or perltop


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

Replies are listed 'Best First'.
Re^2: MacOS Finder (Column view) in Tk.
by Ace128 (Hermit) on Feb 20, 2006 at 20:09 UTC
    Ok, I appreciate your feedback, but I'm not sure I totally agree with the better suited for C. Ok, well, maybe it is, if I wanna spend time controlling every byte. Doing this in Perl is surely far more faster creating, and I'm not sure its gonna be alot slower compared to C - even if the user gets the data from harddrive. Besides, Im not getting it ALL recursivly like this Tk::DirTree seems to be doing, I just get for the directory I'm in (ONE directory that is). And thus, not many millisecs different getting that info from Perl, compared to C.

    Also, I have a rather generic solution in mind, so, the user can get the data from a database (like mp3 data), and do this - like I briefly mentioned - with that info instead. And show stuff like Genre -> Polka/Trance/... -> Artistname... User can get this from a db in realtime.
      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 .

      I'm not really a human, but I play one on earth. flash japh
        Hmm, can you elaborate on the problems with Tk here?