Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Tk Babelizer

by {NULE} (Hermit)
on Jan 04, 2003 at 15:39 UTC ( [id://224264]=CUFP: print w/replies, xml ) Need Help??

My co-workers were joking (I hope that they were joking at least) that my e-mails (which are always technical, detailed and sometimes boring) come across as no more than "blah, blah, blah, blah..." I replied that I would simplify things for them by writing a program to translate them to that literally before I sent it. Whipping up a one-liner to work on files or pipes was easy, but a Tk app that you can cut and past into was more useful (um, not that this is useful in any way).

I decided that it would be fun to write such a program and that more importantly, it might be useful to some of the folks around here that want to learn Tk. It doesn't include nearly all of the features of Tk, but it does include some that are perhaps less than obvious. It uses scrolled text windows, adjuster bars, and packing nested frames. It also shows a simple dialog box.

Anyway - I hope someone finds my waste of time useful.

#! /usr/bin/perl # Like all good Perl programmers use strict; use warnings; # Tk elements we will be using use Tk; use Tk::Adjuster; use Tk::DialogBox; use Tk::ROText; use Tk::Text; # A hash to hold all Tk widgets my $w = {}; # Main window $w->{main} = MainWindow->new(-title => 'Tk Babelizer'); # Scrolled Text widget for the input. $w->{in} = $w->{main}->Scrolled( 'Text', -width => 60, -height => 15, -wrap => 'word', -scrollbars => 'osoe' )->pack( -fill => 'both', -expand => 1 ); # An adjuster bar so the user can change the in box to out box ratio. $w->{adj} = $w->{main}->Adjuster->packAfter($w->{in}, -side => 'top'); # Frame to hold the stuff on the bottom. $w->{bottom} = $w->{main}->Frame->pack(-fill => 'both', -expand => 1); # A frame within the bottom frame to hold some buttons. $w->{buttons} = $w->{bottom}->Frame->pack( -expand => 1 ); # A button to run the babelizer process $w->{buttons}->Button( -text => 'Translate me!', -command => [ \&babelizer, $w ] )->pack( -side => 'left' ); # A button to clear the windows $w->{buttons}->Button( -text => 'Clear the windows', -command => [ \&clear_windows, $w ] )->pack( -side => 'left' ); # A button to exit $w->{buttons}->Button( -text => 'Quit', -command => [ \&quit, $w ] )->pack( -side => 'left' ); # The read-only text output (Scrolled again) $w->{out} = $w->{bottom}->Scrolled( 'ROText', -width => 60, -height => 15, -wrap => 'word', -scrollbars => 'osoe' )->pack( -fill => 'both', -expand => 1 ); # Done creating widgets, enter event loop. MainLoop; # Events # This sub runs the babelizer sub babelizer { my $w = shift; # No globals here - $w is passed to us my $text = $w->{in}->get('1.0', 'end') || ''; $text =~ s/\w+/blah/g; $w->{out}->delete('1.0', 'end'); $w->{out}->insert('1.0', $text); $w->{main}->update; } # This sub just clears the windows sub clear_windows { my $w = shift; $w->{in}->delete('1.0', 'end'); $w->{out}->delete('1.0', 'end'); $w->{main}->update; } # Pop open a confirm window to quit sub quit { my $w = shift; my $dialog = $w->{main}->DialogBox( -title => 'Confirm exit', -buttons => [ 'OK', 'Cancel' ] ); $dialog->Label( -text => 'Are you sure you want to quit?' )->pack; my $popup = $dialog->Show; if ($popup eq "OK") { exit; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://224264]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found