Ace128 has asked for the wisdom of the Perl Monks concerning the following question:

Hey,

I have this bigger app I made in Tk, and I was planing of "borrowing" Finder's column view from MacOSX, and add that to my app. Hehe :). I'm sure I can do this all without any help, but I was thinking that I ask here so I get some bright feedback/suggestions before I start. So I get it perfect! Many brains are (usually) better than one ;). Also, dont wanna do something that is already made (if now this was, although I doubt it. Couldn't find it searching). I assume that doing this would be best as some module, and using other modules. But, Im not really sure what modules would be best suitable... (MListbox?, HList?, Listbox?) I dont really need header title. And how to put the nice > on the far right in the list?

And, in case someone don't know what I'm talking about:

We have columns of files and directories showing. One column for a particular directory. And when a directry is selected, contents in that directory is shown in another column, next to the previous one (added to the right). (Otherwise a preview may be shown for the file selected). You can enter the selected directory by right-arrow (or, well, let that be configurable!) You can also go back. In short, you can navigate through the hierarchy here...
file1 dir1 > [file1] some preview maybe file2 file1 file2 file3 [dir2] > [dir1] > dir2 > file4 dir3 >
where the [...] means selected. In this example, we have selected dir1, then dir2 in the second column, and then file1 in the third column.

So, I wanna create this using some Tk List. Question is, which module(s) do you guys here think I should use? And other feedback is welcome. Even some requests. :) . I was also thinking that it should be rather easy adding a new column (natrually). $columnview->addColumn(@file_and_dir_list); something... where the array contains hashes. (array to keep order, hash so its both easy expandable, and convenient using). That is, for now the hash should contain either 'file' => "file1" or 'dir' => "dir1".

Also, I suppose that adding should happend in "realtime". That is, some sub is called when something is selected. In that sub the user adds whatever wanted. (hey, one can use this module for more than just files and directories!! Like browsing through music. Album -> All titles)

Hmm, typing and thinking more about it, maybe there should be a possability to shoose adding either a list of stuff, or a new Tk thing (Canvas, Frame, whatever). That way user can do alot of cool stuff! And is not limited at all.

Oh, and, what name could be suitable? Tk::ColumnView?

Thanks,
Ace

Replies are listed 'Best First'.
Re: MacOS Finder (Column view) in Tk.
by zentara (Cardinal) on Feb 20, 2006 at 18:39 UTC
    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.

    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
      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