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

Hello Monks,

I've been working on a project in ActiveState Perl 5.8.9 where I want to allow a Windows user to query a SQL database to request a subset of data that matches a few search parameters. I'd present this list of records to the users in a "Windows-friendly" grid and the user would then select a single specific record for editing. From that point the user would supply info on how the record is to be updated -- changing page counts or pricing. (These are records of copy transactions billable to clients.)

My program would then produce the SQL update query and submit it to the database after testing the user input

From what I've read of the TK::TixGrid widget it looks like it would fit the bill. However, I've had no luck finding a working sample of one anywhere. Neither the ActiveState documentation, nor any of the various books include an example script that actually renders one. Neither Google Searches of the web at large nor Super Searches within these hallowed walls have turned up an example.

As a visual learner, I benefit from starting with a working example and modifying it till I understand what I'm working with.

Can any of the monks suggest where I might find an example of TK::TixGrid in a script? I'm also open to alternative strategies if anyone thinks I've chosen the wrong path with TK.

With thanks up front,

Generator

  • Comment on Have there been sightings of TK::TixGrid in the wild?

Replies are listed 'Best First'.
Re: Have there been sightings of TK::TixGrid in the wild?
by zentara (Cardinal) on Apr 10, 2009 at 13:29 UTC
    Look at ztkdb-sql. My labels and entries are somewhat scattered in that, but it could easily be changed to use a nice stack of frames and LabEntry's. I purposely left it that way, so I would have something to offer, in the PAY version....bwaha haa.

    You are better off sticking with a nesting of more standard widgets, in my experience.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
      zentara

      Thanks for the feedback. Your program looks interesting. My current approach is to use a text entry widget to ask the user to provide info on the records to be edited (UserCode?, Between what dates?, etc). Based on user provided parameters, I'll build and submit the SQL query and return the list of pontential candidate data records. From that list I'll have the user click on the one they wish to edit which will move it into another "editing" grid. When entries are completed there, the user will click an "save changes" button. At that point the program will build and submit the SQL update via the ODBC connection and prompt for another set of general parameters.

      Given that I'm addressing an MS SQL database using Win32::ODBC in a Windows XP user environment, I'm not sure yours is the tool for the current project.

      Rest assured I'll be downloading it and poaching any good ideas I discover within your code.

      Thanks again for the feedback and for your willingness to share your skills.

      Oh, and I appreciated your comment...

      "You are better off sticking with a nesting of more standard widgets, in my experience."
      ...it reinforced a growing suspicion I had.

      Respectfully

      Generator

        When entries are completed there, the user will click an "save changes" button.

        If you dig deep into my program, you can automatically submit the SQL update, when you change tabs, if an md5sum change was detected in the fields. No need to have a Save Changes button.(This avoids lost changes if you accidently switch tabs :-) ) Do your automatic magic in the "raisecmd" and "lowercmd" callbacks of the Notebook widgets. But you are probably starting to figure this out. :-)

        FWIW, Tk the Tk Text widget dosn't have a "is_edited" flag, so you need to rely on md5sums, or something similar. However, Gtk2 does has an "has_been_edited" signal.


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku
Re: Have there been sightings of TK::TixGrid in the wild?
by Anonymous Monk on Apr 10, 2009 at 06:22 UTC
      Thank you! That is just what I was looking for. I'm especially pleased that it is so well #doc-commented.

      Generator

Re: Have there been sightings of TK::TixGrid in the wild?
by hangon (Deacon) on Apr 10, 2009 at 16:57 UTC

    Take a look at Tk::TableMatrix. It's included in the Activestate distribution, and has more documentation than Tk::TixGrid. Here's some example code with notes, extracted from one of my projects. This should give you a good start with the widget, but be sure to read the docs, there's a lot more to it.

    # set up the Tk::TableMatrix grid my $grid = $mw->Scrolled('TableMatrix', -scrollbars => 'osoe', -sparsearray => 0, -titlecols => 1, # first col does not scroll -titlerows => 1, # top row does not scroll -roworigin => -1, # first scrolling (data) row is 0 -colorigin => -1, # first scrolling (data) col is 0 -padx => 2, -colwidth => 20, -anchor => 'w', -background => 'white', -resizeborders => 'none', -justify => 'left', -browsecommand => \&clickLeft, )->pack( -side =>'right', -expand => 1, -fill => 'both', ); # collect the data # column labels my @colLabels = qw( column labels here ... etc ); # from database my $data = $dbh->selectall_arrayref($sql); # number of columns my $cols = scalar @{$data->[0]}; # number of rows my $rows = 20; # populate the grid with data # hashref to hold Tk type list for grid values my $vals = {}; # add column labels to first row for (0..$cols -1){ $vals->{"-1,$_"} = $colLabels[$_]; } # add data to subsequent rows for my $ro (0..$rows -1){ # put row numbering into first column $vals->{"$ro,-1"} = $ro +1; # put data from Perl array ref into Tk list for my $co (0..$cols -1){ $vals->{"$ro,$co"} = $data->[$ro][$co]; } } # configure binds Tk list to the grid $grid->configure( -rows => $rows +1, -cols => $cols +1, -variable => $vals, );
      hangon

      Thanks for the suggestion. I will certainly explore TK::TableMatrix as an option.

      I haven't seen it rendered yet as I need to edit your snippet to beat the errors its throwing when run in isolation from your original project.

      Thanks for your willingness to share and for the recommendation of the module.

      Respectfully,

      generator

Re: Have there been sightings of TK::TixGrid in the wild?
by Anonymous Monk on Apr 09, 2009 at 22:45 UTC
    Would it not be easier to use a browser-based solution? Sorry I have nothing constructive to add.
Re: Have there been sightings of TK::TixGrid in the wild?
by Anonymous Monk on Apr 10, 2009 at 07:50 UTC
    If you are only using ms windows, have a look at Win32::GUI and the Win32::GUI::Grid control.
      Thanks for the suggestion. I had not been aware of the existence of Win32::GUI until you mentioned it here. I have since taken a look and it appears promising.

      I'm new to Perl having spent only the last 4 months applying it to several projects. PerlMonks is a lifesaver and I particularly appreciate your willingness to give some informed guidance in the selection of appropriate modules for my current project.

      Mahalo,

      Generator