<?xml version="1.0" encoding="windows-1252"?>
<node id="160673" title="ptknotes" created="2002-04-19 17:13:15" updated="2005-08-11 08:07:09">
<type id="1748">
sourcecode</type>
<author id="13922">
strredwolf</author>
<data>
<field name="doctext">
&lt;code&gt;
#!/usr/bin/perl

use Tk;

$num=1;
sub newnote {
    my $txt=shift; my $t=shift; my %win;
    $t=$num++ unless($t); return if($winlist{$t});
    $win{main}=$main-&gt;Toplevel;
    $win{main}-&gt;geometry("240x320");$win{main}-&gt;title($t);
    $win{main}-&gt;protocol('WM_DELETE_WINDOW',[ sub{
	my $t = shift; my $w=$winlist{$t};
	$tlist{$t}=$w-&gt;{main_txt}-&gt;get("0.0","end");
	$tlist{$t}=~ s/\n+$/\n/m;
	$w-&gt;{main}-&gt;destroy; delete $winlist{$t};
    }, $t]);
    $win{main_txt}=$win{main}-&gt;Text(-background=&gt;"#ffff00",-takefocus=&gt;1)
	-&gt;pack;
    $win{main_txt}-&gt;insert("end",$txt);
    $winlist{$t}=\%win;
}

$main=MainWindow-&gt;new; 
$main_new=$main-&gt;Button(-text=&gt;"New",-command=&gt;'newnote',
			-padx=&gt;0,-pady=&gt;0)-&gt;pack;
$main_old=$main-&gt;Button(-text=&gt;"Saved",-command=&gt;sub {
    foreach $t (keys %tlist) {
	newnote($tlist{$t},$t);
    }
},-padx=&gt;0,-pady=&gt;0)-&gt;pack;
$main-&gt;protocol('WM_DELETE_WINDOW',sub{
    my $t;
    foreach $t (keys %winlist) {
	my $w=$winlist{$t};
	$tlist{$t}=$w-&gt;{main_txt}-&gt;get("0.0","end");
    }
    system "rm $v/*";
    foreach $t (keys %tlist) {
	open(OUT,"&gt;$v/$t");
	print OUT $tlist{$t};
    }
    $main-&gt;destroy;
});

$v=$ENV{HOME}."/.ptknotes"; mkdir $v unless(-e $v);
opendir(DIR,$v); @n=readdir(DIR); closedir(DIR);
foreach $i (@n) { 
    next unless(-f "$v/$i");
    local $/; open(IN,"&lt;$v/$i"); 
    $tlist{$num++}=&lt;IN&gt;;
}

MainLoop;


&lt;/code&gt;</field>
<field name="codedescription">
Sticky notes in Perl/Tk.  Crude but effective.  Hit 'new' to make a new note, 'saved' to show all notes you've written and closed.  Saves in ~/.ptknotes
</field>
<field name="codecategory">
GUI Programming</field>
<field name="codeauthor">
[strredwolf]</field>
</data>
</node>
