widget demo for new text module features. 
Author Message
 widget demo for new text module features.

This is a multi-part message in MIME format.
--------------B2CC53364DA1A003D45842B8
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

widget demo for new text module features.

the attached file is a widget demo to show
the new text module features.

the file is called TEMPLATE.pl

if you copy it into your local area,
setenv WIDTRIB /path/to/template/file

then type:
widget

it will run the widget demo and the
very last demo will be this one.
--------------B2CC53364DA1A003D45842B8
Content-Type: application/x-perl;
 name="TEMPLATE.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="TEMPLATE.pl"

# Gedi master advanced text editor.

use vars qw/$TOP/;

my $TOP;
my $text_frame;
my $counter_frame;
my $textwindow;
my $current_line_label;
my $total_line_label;
my $current_column_label;
my $insert_overstrike_mode_label;
my $about_pop_up_reference;
my $menu;
my $help_menu;

sub about_pop_up
{
        my $name = ref($about_pop_up_reference);
        if (defined($about_pop_up_reference))
                {
                $about_pop_up_reference->raise;
                $about_pop_up_reference->focus;
                }
        else
                {
                my $pop = $TOP->Toplevel();
                $pop->title("About");

                $pop->Label(text=>"Gedi (Gregs EDItor)")->pack();
                $pop->Label(text=>"Ver. 1.0")->pack();
                $pop->Label(text=>"Copyright 1999")->pack();
                $pop->Label(text=>"Greg London")->pack();
                $pop->Label(text=>"All Rights Reserved.")->pack();
                $pop->Label(text=>"This program is free software.")->pack();
                $pop->Label(text=>"You can redistribute it and/or")->pack();
                $pop->Label(text=>"modify it under the same terms")->pack();
                $pop->Label(text=>"as Perl itself.")->pack();
                $pop->Label(text=>"Special Thanks to")->pack();
                $pop->Label(text=>"Nick Ing-Simmons.")->pack();

                my $button_ok = $pop->Button(text=>'OK',
                        command => sub {$pop->destroy();
                        $about_pop_up_reference = undef;
                        } )
                        ->pack();
                $pop->resizable('no','no');
                $about_pop_up_reference = $pop;
                }

Quote:
}

sub update_indicators
{
        my ($line,$column)= split(/\./,$textwindow->index('insert'));
        $current_line_label->configure (text=> "line: $line");
        $current_column_label->configure (text=> "column: $column");

        my ($last_line,$last_col) = split(/\./,$textwindow->index('end'));
        $total_line_label->configure (text=> "total lines: $last_line");

        my $mode = $textwindow->OverstrikeMode;
        my $overstrke_insert='Insert Mode';
        if ($mode)
                {$overstrke_insert='Overstrike Mode';}
        $insert_overstrike_mode_label->configure
                (text=> "$overstrke_insert");

        my $filename = $textwindow->FileName;
        $filename = 'NoName' unless(defined($filename));
        my $edit_flag='';
        if($textwindow->numberChanges)
                {$edit_flag='edited';}
        $TOP->configure(-title => "Gedi  $edit_flag $filename");
        $textwindow->idletasks;

Quote:
}

sub TEMPLATE {

    $TOP = $MW->WidgetDemo(
        -name             => $demo,
        -text             => 'Gedi master advanced text editor ',
        -geometry_manager => 'grid',
        -title            => 'GEDI Text Editor',
        -iconname         => 'GEDI',
    );

$text_frame = $TOP->Frame->pack
        (-anchor=>'nw', expand=>'yes', -fill => 'both'); # autosizing
$counter_frame = $TOP->Frame->pack(-anchor=>'nw');

$textwindow = $text_frame->Scrolled(
        'TextEdit',
        exportselection => 'true',  # 'sel' tag is associated with selections
        # initial height, if it isnt 1, then autosizing fails
        # once window shrinks below height
        # and the line counters go off the screen.
        # seems to be a problem with the Tk::pack command;
        height => 40,        
        -background => 'white',
        -wrap=> 'none',
        -setgrid => 'true', # use this for autosizing
        -scrollbars =>'se')
        -> pack(-expand => 'yes' , -fill => 'both');   # autosizing

$TOP->protocol('WM_DELETE_WINDOW'=>
 sub{$textwindow->ConfirmExit;}
 );

$SIG{INT} = sub {$textwindow->ConfirmExit;};

$current_line_label = $counter_frame
        -> Label(text=>'line: 1')
        -> grid(-row=>1,-column=>1, -sticky=>'nw' );

$total_line_label = $counter_frame
        -> Label(text=>'total lines: 1')
        -> grid(-row=>2,-column=>1, -sticky=>'nw' );

$current_column_label = $counter_frame
        -> Label(text=>'column: 0')
        -> grid(-row=>3,-column=>1, -sticky=>'nw' );

$insert_overstrike_mode_label = $counter_frame
        -> Label(text=>' ')
        -> grid(-row=>5,-column=>1, -sticky=>'nw' );

$textwindow->SetGUICallbacks (
 [
  \&update_indicators,
  sub{$textwindow->HighlightAllPairsBracketingCursor}
 ]
);

$menu = $textwindow->GetMenu;

$TOP->configure(-menu => $menu);

$help_menu = $menu->cascade(-label=>'~Help', -tearoff => 0, -menuitems => [
         [Command => 'A~bout', -command => \&about_pop_up]
         ]);

#$TOP->minsize(30,1);
#$TOP->geometry("80x24");

while(<DATA>)
        {$textwindow->insert('insert',$_);}
$textwindow->ResetUndo;

$textwindow->CallNextGUICallback;

Quote:
}

__DATA__

Tk800.015 contains many modifications to the
text based modules, as well as new text modules
and an application that uses them all.
Text.pm, TextUndo.pm, TextEdit.pm, and gedi
have all been updated since the release prior
to Tk800.015.  

This demo contains a rundown of all the features
of the text modules, and

What is available in the text modules?
================================================

Text.pm
========

Text.pm is the base text editing module.
Beyond the core functionality of typing text,
Text.pm has built in menu support for basic
editing features such as Find/Replace text,
Copy/Cut/Paste, Goto Line Number, and What
Line Number queries.

These functions are available simply by right
clicking the mouse over the text area. Doing
so will cause a pop-up menu to appear which will
contain cascading menus to give access to all of
these new functions.

Many of these functions will create their own
pop-up windows. Find/Replace will create a pop-up
window which contains an entry for text to
find, an entry for replace text, a number of
radio buttons to control options such as
case sensitivity, and several command buttons to
perform functions such as Find, Find All,
Replace, Replace All.

All of these features have corresponding methods
built into the Text widget. This allows the basic
functions to be built into the widget, and also
allows added features to be built on the lower
level methods as needed. No one should have to
reinvent the wheel when it comes to text editing
features.

Insert and Overstrike modes are also supported
in the Text.pm module. Pressing the <Insert>
key will toggle modes back and forth.

Column based copy/cut/paste features are also
available in the Text.pm module. They are bound
to the following keys:

<F1> clipboardColumnCopy
<F2> clipboardColumnCut
<F3> clipboardColumnPaste

Currently, column based operations are beta versions.
They compensate for tabs, but they will not behave
properly unless the text is all the same font, and
is the same width per character.

Hopefully some future version of Text.pm will correct
for this deficiency.

Column paste should work with overstrike mode.

TextUndo.pm
=============

TextUndo.pm is the second level module, being
derived from the Text.pm module. As it's name
implies, TextUndo supports "UNDO" capability.
It now also supports "REDO" capability.

Undo/redo works on user typed commands and
also programmatically, so that any application
that causes text to be inserted or deleted
can be undone/redone, whether it was directly
typed by the user or indirectly through another
method.

The undo/redo functions support tags, so that
if you delete text with tags, undo will re-insert
the text and re-tag it as well. This will eventually
allow the text modules to support more sophisticated
word processing type features. Such functionality
should be available in a future release of the
text modules.

The TextUndo.pm module also has several added
features to support file based operations.
File based methods include ->Save, ->Load, and
->Include. All methods take a filename as a
parameter. These methods will create a progress
widget to indicate the progress of the operation.

The other feature of the TextUndo.pm module
is the ConfirmDiscard method. This method checks to
see if the text has been modified since it was
last saved. If it has been modified, and the
it will create a pop-up menu asking the user
if they want to save the text to a file before
exiting. This method can easily be tied into
the exit routines, and signal handlers, to provide
a consistent "save before exit?" feel.

TextEdit.pm
=============

The TextEdit.pm is a new module in prototype version
which adds further features to the text modules.
TextEdit is based off of the TextUndo module,
and so has all of the features of TextUndo and
Text.

Features of the TextEdit.pm module include
parenthesis matching. The module looks at the
current cursor position and then tries to find
the parenthesis that bracket the cursor.
Character pairs that are searched for are:
() {} [] "" ''

It also checks the position of the pairs to
try to highlight bad positions. The module
assumes that if the pairs are not on the same
line or not on the same column, then there
might be a missing parenthesis somewhere.
Characters that appear to not align are
highlighted in red.

(quotations must start and end on the same line)

PARENTHISIS MATCHING DEMO:
move the cursor to the x between the quotes
on the line below:

{
                (  )
        (       {       }
                [
        '       ">> x <<" '
        []      ]
        )

Quote:
}

PARENTHESIS MISMATCHING DEMO:
move the cursor to the x between the quotes
on the line below:

{
                (  )
         ( <<RED possible error           {       }
                [
        '       ">> x <<" '
        []      ]
        ) <<RED possible error

Quote:
}

Another feature of the TextEdit module is support
for application level indicators which reflect
the status of certain internals.  The line and
column position of the cursor, the total length
of the file, whether the widget is in insert or
overstrike mode.  Anytime anything occurs that could
affect these values, a user supplied callback
is invoked. This callback is supplied by the
application so that the application can update
whatever indicators it uses, ...

read more »



Tue, 15 Jan 2002 03:00:00 GMT  
 widget demo for new text module features.

Quote:

> widget demo for new text module features.

> the attached file is a widget demo to show
> the new text module features.

> the file is called TEMPLATE.pl

> if you copy it into your local area,
> setenv WIDTRIB /path/to/template/file

> then type:
> widget

> it will run the widget demo and the
> very last demo will be this one.

(Aside - you can also say: widget /path/to/template/file)

Wow!  Very impressive.  Now look at all the work you've caused me (-:
Is it safe to assume you'll have POD documentation, upon which I can
base errata to the Pocket Ref (and I assume Nancy would use for
Learning Perl/Tk)? (Or, a simple list of the new methods/tags/marks/
variables and what not (-:)

FYI, here are some "things" I see playing with the demo:

1)
Assuming 'require Tk::TextEdit;' at /tmp/TEMPLATE.pl line 100
Argument "49.38h" isn't numeric in eq at /usr/local/lib/perl5/site_perl/5.005/sgi-irix/Tk/TextUndo.pm line 718, <DATA> chunk 254.

2)
 there is supposed to be one selection pair:

3)
substr outside of string at /usr/local/lib/perl5/site_perl/5.005/sgi-irix/Tk/Text.pm line 1505, <DATA> chunk 254.
Use of uninitialized value at /usr/local/lib/perl5/site_perl/5.005/sgi-irix/Tk/Text.pm line 1507, <DATA> chunk 254.

I can't begin to tell you what I was doing at the time - this is just a first heads-up.
==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Tue, 15 Jan 2002 03:00:00 GMT  
 widget demo for new text module features.

Quote:

> Wow!  Very impressive.  Now look at all the work you've caused me (-:
> Is it safe to assume you'll have POD documentation, upon which I can
> base errata to the Pocket Ref (and I assume Nancy would use for
> Learning Perl/Tk)? (Or, a simple list of the new methods/tags/marks/
> variables and what not (-:)

yes, it woud be safe; defining safe as "not causing injury".
would it be "accurate"? that is a totally different question.

;)

I suppose I should do something with it as far as documentation
is concerned. I'd hoped that some of my long winded method names
would be fairly self-documenting, but alas, I guess I was wrong.

I'll try and come up with something to document all the additions.
dont know when I'll have it completed. hopefully it will be part
of the next Tk release, at the latest.

I'm still of the opinion that I'll have it to you by monday,
its only a matter of figuring out which monday that will be...
wednesdays, as always, are quite out.

Quote:
> FYI, here are some "things" I see playing with the demo:

> 1)
> Assuming 'require Tk::TextEdit;' at /tmp/TEMPLATE.pl line 100
> Argument "49.38h" isn't numeric in eq at /usr/local/lib/perl5/site_perl/5.005/sgi-irix/Tk/TextUndo.pm line 718, <DATA> chunk 254.

> 2)
>  there is supposed to be one selection pair:

I remember seeing this pop up before and thought I'd cleared it up.
I'll take another look.

Quote:

> 3)
> substr outside of string at /usr/local/lib/perl5/site_perl/5.005/sgi-irix/Tk/Text.pm line 1505, <DATA> chunk 254.
> Use of uninitialized value at /usr/local/lib/perl5/site_perl/5.005/sgi-irix/Tk/Text.pm line 1507, <DATA> chunk 254.

> I can't begin to tell you what I was doing at the time - this is just a first heads-up.

the others, I'm not sure about, but will investigate.

"Aren't you men going to do something about those cannons?"
"No sir."
"No?!? Why not???"
"Its Wednesday, sir."

        from Baron Munchausen

Greg
==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Tue, 15 Jan 2002 03:00:00 GMT  
 widget demo for new text module features.
This is a multi-part message in MIME format.
--------------756A5813FEAA2DE584E5B3AD
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Quote:

> FYI, here are some "things" I see playing with the demo:

> 1)
> Assuming 'require Tk::TextEdit;' at /tmp/TEMPLATE.pl line 100
> Argument "49.38h" isn't numeric in eq at /usr/local/lib/perl5/site_perl/5.005/sgi-irix/Tk/TextUndo.pm line 718, <DATA> chunk 254.

> 2)
>  there is supposed to be one selection pair:

rectangular copy or cut was called and it only
works if you have one selection. this was a debug
statement that indicated you have either no selections
or more than one selection. it was supposed to have
been removed, but I must have missed it.

Quote:
> 3)
> substr outside of string at /usr/local/lib/perl5/site_perl/5.005/sgi-irix/Tk/Text.pm line 1505, <DATA> chunk 254.
> Use of uninitialized value at /usr/local/lib/perl5/site_perl/5.005/sgi-irix/Tk/Text.pm line 1507, <DATA> chunk 254.

you did a rectangular copy or cut across multiple lines.
and one of the intermediate lines was so short that the
rectangle was past the end of the line.

a simple fix pads the string with enough spaces so that
it isn't a problem.

Quote:
> I can't begin to tell you what I was doing at the time - this is just a first heads-up.

rectangle copy/cut/paste is in prototype version right now.
it will act weird if you start using funky fonts and stuff like
that, since it assumes that all characters are the same width.
the attached patch file will fix problems 2 and 3, but you
may still see strange behaviour in some cases.

Greg
--------------756A5813FEAA2DE584E5B3AD
Content-Type: text/plain; charset=us-ascii;
 name="text_patch.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="text_patch.txt"

*** backup/Text.pm      Thu Jul 29 11:45:30 1999
--- Text.pm     Fri Jul 30 14:28:54 1999
***************
*** 10,15 ****
--- 10,20 ----
  # See the file "license.terms" for information on usage and redistribution
  # of this file, and for a DISCLAIMER OF ALL WARRANTIES.

+ #
+ # Acknowlegements: Nick Ing-Simmons and Greg London made significant
+ #                code contributions in 1999
+ #
+
  package Tk::Text;
  use AutoLoader;
  use Carp;
***************
*** 1467,1473 ****
   # this only makes sense if there is one selected block
   unless ($range_total==2)
    {
-   print " there is supposed to be one selection pair: \n";
    $w->bell;
    return;
    }
--- 1472,1477 ----
***************
*** 1498,1507 ****
   # clear the clipboard
   $w->clipboardClear;
   my ($clipstring, $startstring, $endstring);
   for(my $line = $start_line; $line <= $end_line; $line++)
    {
    $string = $w->get($line.'.0', $line.'.0 lineend');
!   $string = expand($string);
    $clipstring = substr($string, $tab_start_column, $length);
    #$clipstring = unexpand($clipstring);
    $w->clipboardAppend($clipstring."\n");
--- 1502,1512 ----
   # clear the clipboard
   $w->clipboardClear;
   my ($clipstring, $startstring, $endstring);
+  my $padded_string = ' 'x$tab_end_column;
   for(my $line = $start_line; $line <= $end_line; $line++)
    {
    $string = $w->get($line.'.0', $line.'.0 lineend');
!   $string = expand($string) . $padded_string;
    $clipstring = substr($string, $tab_start_column, $length);
    #$clipstring = unexpand($clipstring);
    $w->clipboardAppend($clipstring."\n");

--------------756A5813FEAA2DE584E5B3AD--

==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Tue, 15 Jan 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. pTk 8.4.24 widget patch #1 - widget demo and friends bug fixes/modernizations

2. New modules: Text::Query::Simple and Text::Query::Advanced

3. Newer version of Enhanced Text widget available

4. Newer version of Enhanced Text widget available

5. Tk::CodeText new Text widget, capable of syntax highlighting

6. RFC: Namespace for new module (tab widgets in HTML)

7. RFC: Namespace for new module (tab widgets in HTML)

8. Tk widget demo crash

9. Curses::Widgets demo OK on Linux, goofed on Solaris

10. 5.005_02, Tk800.011, X error on widget demo

11. Problem running demo/widget.

12. 5.005_02, Tk800.011, X error on widget demo

 

 
Powered by phpBB® Forum Software