Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Now, I would like to capture any user changes/inputs and write a text file consisting of: LABEL=ENTRY\n LABEL=ENTRY\n ..

So open a file, and loop thru your hash and print to the file. You can do this by adding code in the run callback, to open the file, loop thru your hash, print the keys values, then close the file. I will show how this is done in the script below, which shows how to sort your keys properly.

The problem with sorting your keys, is that you have a mixed alpha-numeric string. if you just use sort on the keys, you will end up with the typical alpha order 1,10,2,3, etc. So you must split you keys into alpha and numeric fields, then sort on them. I show this below. Now sorting is a big topic, and I won't explain the details here, but you can see List Processing, Filtering, and Sorting. As you work thru it, save the examples as recipes for various sorts. So here is sort, and print to file.

#!/usr/bin/perl use warnings; use strict; my %tools = ( 'program1' => { 'PARM1' => 1, 'PARM2' => 'n', 'PARM3' => + 'y', 'PARM4' => 'n', 'PARM5' => 'y', 'PARM6' +=> 'n', 'PARM7' => 'y', 'PARM8' => 'n', 'PARM9' +=> 'y', 'PARM10' => 'n' }, 'program2' => { 'PARM1' => 1, 'PARM2' => 2, 'PARM3' => 3 +, 'PARM4' => 4, 'PARM5' => 5, 'PARM6' => 6, 'PARM7' => 7 +, 'PARM8' => 8, 'PARM9' => 9, 'PARM10' => 10 }); open (my $oh,"> $0-settings.txt") or warn "$!\n"; foreach my $tab (sort keys %tools){ print $oh "\n$tab\n"; foreach my $parm (custom_sort(\%{$tools{$tab}})) { print $oh " $parm = $tools{$tab}{$parm}\n"; } } close $oh; #for my $key ( custom_sort(\%hash) ) { # print "Key: $key\n"; #} sub custom_sort { my $hash = shift; return map { $_->[0] } sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2]} map { [ $_, /(\w+)(\d+)$/ ] } keys %$hash; }

As far as detecting changes go, there are a few ways to do it. One way, is to make a callback for the -raisecmd of the notebook options. Google for examples. The idea is when a tab is selected (raised), the -raisecmd callback loops thru all the values on that page and stores them somehow.. You would need to store the previous tab, as well as the current tab. When a new tab is raised, the -raisecmd would loop thru all entries on the previous page, and compare them to the original. It is simple bookkeeping. If a difference is detected, do whatever.

Another option, might be to try to use the validate callback of the entry widgets... it might be a simpler approach. If an attempt is made to an entry, a callback is triggered. That can flag that entry as "changed", whether you actually change the data or not.

So it's really up to you and your program's needs, as to how you detect changes. The absolute simplest approach, is to maintain a separate hash of all the values, and on every -raisecmd, loop thru the backup hash, and compare the entries, and detect differences. It may waste a few cpu cycles, but it is a simple way.


I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re^7: clunky Tk GUI by zentara
in thread clunky Tk GUI by honyok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found