Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Extensibility of Tk::TableMatrix

by elef (Friar)
on Feb 06, 2011 at 17:52 UTC ( #886535=perlquestion: print w/ replies, xml ) Need Help??
elef has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, I would like to write a GUI for editing two parallel texts. Essentially, what's needed is a scrollable two-column spreadsheet where the user can split and merge cells to bring the two texts in sync. Doing this in a spreadsheet program with copy-pasting is pretty slow and inconvenient, so I would like to have a specialized ui that has buttons and/or keyboard shortcuts for split and merge.
Tk::TableMatrix or Tk::TableMatrix::Spreadsheet seem like a good place to start, but obviously neither has merge/split facilities. How difficult would it be to add that? Basically I would need one shortcut that merges the active/selected cell with the next, shifting the rest of the column up a cell, and a shortcut that splits the current cell at the cursor location and pushes the rest of the column down a cell.
I have read some of the documentation for Tk::TableMatrix, and it seems it can just load hashes or arrays into a spreadsheet and automatically save the changes back to the hash or array, which would suit my purposes pretty well. All I would need is these two extra features. Mind you, I'm a novice perl programmer and I don't know anything about these modules in particular.

So, my question is: is this something a novice coder could get done in a couple of days, and how would one go about it? Also, would performance be a problem if there are a couple of thousand records in the table, each with 2x100 characters of text? I imagine not, as the data isn't that much, but who knows how efficient Tk::TableMatrix is.

Comment on Extensibility of Tk::TableMatrix
Re: Extensibility of Tk::TableMatrix
by vkon (Deacon) on Feb 06, 2011 at 19:22 UTC
    As I currently see your task, you do not need any of Tk::TableMatrix.

    You only need two Text widgets, placed together, with maybe a separator between them so the user could adjust widths.
    from time to time, I tend to write such kind of tasks, but I have different approach to usage of Tk from within Perl.
    if you wish, I can extract proper GUI building parts from my recent GUI program to show how your could do the task.

    as for another part of your question - efficiency of Text widgets - it is rather efficient. No worries about editing several thousand of lines in each.

    Regards,
    Vadim

      Thanks, I would appreciate any guidance and code snippets.
      The reason why I'm considering TableMatrix is that I would like the layout to be like a spreadsheet with word wrap. I.e. grid lines around the text, wrapped into as many lines as needed, and with the rows of the two columns in sync. I.e. if the A1 cell is 2 lines, and B1 is 5 lines, than both A2 and B2 start after the fifth line etc.
      I'm fairly sure Tk::TableMatrix can do this easily, but coding this layout from scratch would probably take a while.
        I've built an app with TableMatrix - I'm not sure that this is going to be the best for you.

        One thing to investigate is wordwrapping. My app just uses the default behavior where text just disappears off the screen if column width is too small. I seem to remember a post that mentioned some trouble getting word wrap to work - so I'd definitely investigate that issue with a little prototype first - make sure your major feature works before getting too far into this.

        You should also be aware that the data storage is a bit strange. TableMatrix uses a hash with keys like: "0,3" or "45,14" to indicate row 0, col 3, etc. That means that inserting a row is a hassle. I didn't do any inserts, but I did do sorts. To sort, on some combination of columns, I wound up just copying to an AoA, sort and then copy back. As it turned out even with 80,000 hash keys, the performance of this was noticeable, but "ok". I don't know what to recommend, but I'd spend some more time looking for something that would allow easier insert operations.

        on a second thought - maybe you need table indeed.

        There is a number of tk widgets to deal with task, and tablelist widget is one of them (another alternatives could be treeview from tile package and tktable).

        use strict; use Tcl::Tk; my $int = new Tcl::Tk; my $mw = $int->mainwindow; # the tablelist widget is described at # http://docs.activestate.com/activetcl/8.5/tablelist/tablelistWidget. +html $int->pkg_require('tablelist'); $int->Eval('namespace import tablelist::*'); my $w_t = $mw->Scrolled('tablelist',-columns =>[0, "First Column", 0, +"Another column"], -stretch =>'all', -background =>'white')->pack(-fill=>'both', + -expand=>1, -side=>'top'); $w_t->columnconfigure(0, -editable=>1); $w_t->columnconfigure(1, -editable=>1); $w_t->insert('end', ["row $_;", "$_ bla bla"]) for 'a'..'zzz'; $int->MainLoop;
        look at description of tablelist - it is really powerful - it allows editing with text or checkbutton or 'edit' widget.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://886535]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-09-20 16:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls