f



Text bind command not selecting text

I am putting together a small report editor and need some help with
the following problem. I would like the user to type in some text and
then later be able to select either all of it or a portion of it for
formatting (ie. centering, bold, italic,etc.) by typing in a command
like Ctrl-A. The following code is what I came up for this process but
for some reason the text does not get selected. Can someone tell why
this code doesn't work?


################################################################
#

use strict ;
use Tk ;
use Tk::NoteBook ;


my $fTab ;
my $mw = MainWindow->new;
$fTab  = $mw->Frame()->pack( -anchor => 'n', -fill => 'both', -expand
=> 1 ) ;

my $nb  = $fTab->NoteBook()->pack( -anchor => 'n', -fill=>'both', -
expand=>1 );
my $rpt = $nb->add("Report", -label => "Report");
my $hdr = $nb->add("Header", -label => "Header" );
my $tle = $nb->add("Title",  -label => "Title");
my $dtl = $nb->add("Detail", -label => "Detail");
my $ftr = $nb->add("Footer", -label => "Footer");
my $fin = $nb->add("Final",  -label => "Final");

my $rpt_txt = $rpt->Text( -width => 80
                        , -height => 20
                        , -state => 'disable'
                        , -relief => 'flat'
                        )->pack( -anchor => 'n' ) ;

my $hdr_txt = $hdr->Text( -width => 80
                        , -height => 6
                        )->pack( -anchor => 'n' ) ;
$hdr_txt->tagConfigure( 'center', justify => 'center', -foreground =>
'red' ) ;
$hdr_txt->bind( '<Control-Key-a>', sub { print "In sub\n" ;
                                         my $t = shift ;
                                         $t->tagAdd( 'center',
'sel.first', 'sel.last') if( $t->tagRanges( 'sel' ) ) ;
                                       } ) ;

my $tle_txt = $tle->Text( -width => 80, -height => 6 )->pack( -anchor
=> 'n' ) ;
my $dtl_txt = $dtl->Text( -width => 80, -height => 6 )->pack( -anchor
=> 'n' ) ;
my $ftr_txt = $ftr->Text( -width => 80, -height => 6 )->pack( -anchor
=> 'n' ) ;
my $fin_txt = $fin->Text( -width => 80, -height => 6 )->pack( -anchor
=> 'n' ) ;



MainLoop;

0
sajohn
7/10/2007 12:46:32 AM
comp.lang.perl.tk 4721 articles. 0 followers. pharrendorf (19) is leader. Post Follow

2 Replies
740 Views

Similar Articles

[PageSpeed] 40

"sajohn" <sajohn52@yahoo.com> wrote in message 
news:1184028392.176358.236900@q75g2000hsh.googlegroups.com...
>I am putting together a small report editor and need some help with
> the following problem. I would like the user to type in some text and
> then later be able to select either all of it or a portion of it for
> formatting (ie. centering, bold, italic,etc.) by typing in a command
> like Ctrl-A. The following code is what I came up for this process but
> for some reason the text does not get selected. Can someone tell why
> this code doesn't work?
>
>
> ################################################################
> #
>
> use strict ;
> use Tk ;
> use Tk::NoteBook ;
>
>
> my $fTab ;
> my $mw = MainWindow->new;
> $fTab  = $mw->Frame()->pack( -anchor => 'n', -fill => 'both', -expand
> => 1 ) ;
>
> my $nb  = $fTab->NoteBook()->pack( -anchor => 'n', -fill=>'both', -
> expand=>1 );
> my $rpt = $nb->add("Report", -label => "Report");
> my $hdr = $nb->add("Header", -label => "Header" );
> my $tle = $nb->add("Title",  -label => "Title");
> my $dtl = $nb->add("Detail", -label => "Detail");
> my $ftr = $nb->add("Footer", -label => "Footer");
> my $fin = $nb->add("Final",  -label => "Final");
>
> my $rpt_txt = $rpt->Text( -width => 80
>                        , -height => 20
>                        , -state => 'disable'
>                        , -relief => 'flat'
>                        )->pack( -anchor => 'n' ) ;
>
> my $hdr_txt = $hdr->Text( -width => 80
>                        , -height => 6
>                        )->pack( -anchor => 'n' ) ;
> $hdr_txt->tagConfigure( 'center', justify => 'center', -foreground =>
> 'red' ) ;
> $hdr_txt->bind( '<Control-Key-a>', sub { print "In sub\n" ;
>                                         my $t = shift ;
>                                         $t->tagAdd( 'center',

#Make sure you bind to a cApitAl A too...
$hdr_txt->bind( '<Control-Key-a>', [$hdr_txt => 'selectAll']);
$hdr_txt->bind( '<Control-Key-A>', [$hdr_txt => 'selectAll']);



> 'sel.first', 'sel.last') if( $t->tagRanges( 'sel' ) ) ;
>                                       } ) ;
>
> my $tle_txt = $tle->Text( -width => 80, -height => 6 )->pack( -anchor
> => 'n' ) ;
> my $dtl_txt = $dtl->Text( -width => 80, -height => 6 )->pack( -anchor
> => 'n' ) ;
> my $ftr_txt = $ftr->Text( -width => 80, -height => 6 )->pack( -anchor
> => 'n' ) ;
> my $fin_txt = $fin->Text( -width => 80, -height => 6 )->pack( -anchor
> => 'n' ) ;
>
>
>
> MainLoop;
>

Jack 


0
Jack
7/11/2007 2:49:46 AM
sajohn wrote:
> I am putting together a small report editor and need some help with
> the following problem. I would like the user to type in some text and
> then later be able to select either all of it or a portion of it for
> formatting (ie. centering, bold, italic,etc.) by typing in a command
> like Ctrl-A. The following code is what I came up for this process but
> for some reason the text does not get selected. Can someone tell why
> this code doesn't work?
> 

Hello,

the Ctrl-A event is processed by a Class binding first. Therefore your 'sel' tag 
does no longer exist at the time your instance-binding is invoked.
So you have to bind to the Text class, change the bindtags order or derive a 
Class from Tk::Text which provides the behaviour that you need.

The first approach is the simplest.
The drawback here is, that all Text widgets in your application will respond to 
the binding:

use warnings;
use strict;
use Tk;



my $fTab ;
my $mw = MainWindow->new;
$fTab  = $mw->Frame()->pack( -anchor => 'n',
                              -fill   => 'both',
                              -expand => 1 ) ;



my $hdr_txt = $fTab->Text( -width => 80,
                            -height => 6
                         )->pack( -anchor => 'n' ) ;
$hdr_txt->tagConfigure( 'center',
                         -justify    => 'center',
                         -foreground => 'red' ) ;
$mw->bind( 'Tk::Text','<Control-Key-a>',\&event_);

MainLoop;

sub event_{
     my $t = shift ;
     $t->tagAdd( 'center',
                 'sel.first',
                 'sel.last') if( $t->tagRanges( 'sel' ) ) ;
}


-- 
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
0
Ch
7/11/2007 8:45:10 PM
Reply:

Similar Artilces:

How to select all texts of the document of the format of the selected text?
Hi,i have selected a text of the document with the specified font face, color and size in MS Word 2000. Now , I want to select all the relevant texts from the entire document with the same format(face,color and size) as of the selected text. so Is there any method or shortcut to do this op.? Not really. You have to "walk" the document checking the styles as you go along. And You have to watch out for cases where the style changes in the middle of a word (!) and code accordingly to get the desired results. chetan26nov@gmail.com wrote: > Hi,i have selected a text of the documen...

text + text
What is "text + text" supposed to do right now? It doesn't seem very useful to me. What about making "text + text" as an equivalent for "text || text"? Most strongly-typed programming languages do this. And MS SQL Server too, I think (CMIIW). -- dave ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org Am Freitag, 8. Oktober 2004 12:57 schrieb David Garamond: > What is "text + text" supposed to do right now? Nothing. > What a...

text-text
Wondering how what I input to my UTF-8 terminal gets passed along through my patched [1] trn ... Cyrillic: А Б В Г Д Е Ж З И Й К Л М Н О П а б в г д е ж з и й к л м н о п IPA: ᴀ ᴁ ᴂ ᴃ ᴄ ᴅ ᴆ ᴇ ᴈ ᴉ ᴊ ᴋ ᴌ ᴍ ᴎ ᴏ ɀ Ɂ ɂ Ƀ Ʉ Ʌ Ɇ ɇ Ɉ ɉ Ɋ ɋ Ɍ ɍ Ɏ ɏ [1] https://groups.google.com/d/msg/comp.sys.raspberry-pi/7Z37Hdrm0DM/6aqD-reXFzAJ ...

Perl/Tk: 'selection conversion left too many bytes unconverted' error on large text selection
Hi all, I've written about this before, but it's come back and I still haven't found what the problem is. Basically, in Perl/Tk if a textbox has a lot of text in it (no idea on the limit yet - all I know is that it has to be a _lot_ of text), and all the text is selected (and therefore copied to the clipboard) the entire perl process is halted, the gui disappears and the error: selection conversion left too many bytes unconverted appears on the command line. This appears to be a tcl panic error (hence the cross-post to comp.lang.tcl as I'm not sure where the problem i...

Solution [ Perl/Tk: 'selection conversion left too many bytes unconverted' error on large text selection ]
After I got bitten enough by this error and found no solution on the web I had to debug it myself. For me it looks like the following: - text get selected from Tk::Text - TkSelPropProc in ./pTk/mTk/unix/tkUnixSelect.c gets called to handle the selection which determines that the display supports utf-8 and thus gets Encoding::utf8 as the responsable encoder (see Encode::Encoding for the interface) - then it calls Tcl_UtfToExternal to convert the selection from internal format to utf8, this function is defined in encGlue.c and just calls CallEncode in the same fil...

Selecting text in a text box
When I attempt to select text in a text box, the text from the cursor position to the end of the text is instantly selected as soon as I click the mouse down. There seems to be no way to select just a small portion of the text in a text box. This seems pretty basic. What am I missing? I'm using Access 97 on an XP system. Steve Richfield First, (I don't remember if this is an option in 97) check Tools|Options|Keyboard tab, Behavior Entering Field. This setting will adjust the behavior for all forms and controls. Next, you would need to click at the start of the area you want to hi...

wxSTC: New text selection not possible within selected text
A rather annoying effect, when I want to start a new text selection within an already selected text nothing happens. I first have to deselect the text (by clicking outside of the selected text) and then can set a new overlapping selection. SciTe doesn't have this problem so it must be either in wxSTC or wxWindows. O. Wyss -- See "http://wxguide.sourceforge.net/" for ideas how to design your app. otto.wyss@bluewin.ch: > A rather annoying effect, when I want to start a new text selection > within an already selected text nothing happens. I first have to >...

Tk text search and elided text
All, I'm having trouble understanding the following text widget behavior. I'm using Tcl/Tk 8.4.9. I've got a text widget with some elided text. A search returns the position L.C (properly), but a subsequent search starting at L.C for the same string fails to return L.C. However, a search with the option -elide does return L.C. The elided text is at the beginning of the line, a good 60 characters before the text in question. Here's the example: # -------------------------------- end toplevel .bfw pack [set t [text .bfw.t]] -expand 1 -fill both set elidetext "to elid...

Deleting selected text from text area
I was wondering if anyone could help. I'm trying to find how to delete text from a selected text Area. I'm a beginner in Java Netbeans. So go easy! This is what I tried but its not happening. int start = 0, end = 1; while ( start < end ) { start = SpeechText.getSelectionStart(); end = SpeechText.getSelectionEnd(); if ( start != end ) remove( SpeechText.getText() ); } tom79l@googlemail.com wrote: > I was wondering if anyone could help. I'm trying to find how to > delete text from a selected text Area. > > I'm a beginn...

Tk::Text, is there a selection?
Hi, from the documentation to Tk::Text i concluded that i can get the selection by: $txt->get('sel.first', 'sel.last'); But i need to test if there IS a selection. To do this i should test if the option "exportSelection" is true. How do i do that? I tried: $t->cget('exportSelection') But that was always true. How do i test for the selection? Best regards, Torsten. In article <chil14$bpn$1@schleim.qwe.de>, tmohr@s.netic.de says... > Hi, > > from the documentation to Tk::Text i concluded that i can get &...

Can JavaScript select text in a text-field?
Hi, I would like to have a text-field (in html form) with a selected text. In other words, it user loads the form, he/she can see a text in the text field (this text should explain what should be put in the text field). It is convenient to have a selected text, so that it user start to write something in the text filed the selected text will be immediately deleted. Thank you in advance for any help. On 2009-01-20 02:07, Kurda Yon wrote: > I would like to have a text-field (in html form) with a selected text. You can use fieldElement.focus() and fieldElement.select(). - Conrad ...

How do I 'SELECT All' text in a text box
I want to select all text in a multi line text box from a command butten. Thank for help Dave Try this... Private Sub Command1_Click() With Text1 .SelStart = 0 .SelLength = Len(.Text) .SetFocus End With End Sub Rick - MVP "Dave" <last2try@earthlink.net> wrote in message news:fo0b90h0j9imbvntdea3uu2mefth5teufr@4ax.com... > I want to select all text in a multi line text box from a command > butten. > > Thank for help > Dave ...

Select and get text from Edit text filed
Hi, I need to make a simple text editor in matlab gui. I want is the user to be able to select part of the text he had typed and make the fontweight bold. I don't know how to get the selected text. Can you give me some clues? Thanks. ...

How to get selected text from a text edit control?
I created a text edit control using CreateEditTextControl. I can get the current text by calling char buf[256]; Size textSize = 0; GetControlData(controlRef, kControlEditTextPart, kControlEditTextTextTag, 255, buf, &textSize); but how do I get only the text that is currently selected (highlighted)? thanks, Shai In article <1111086224.345185.78280@g14g2000cwa.googlegroups.com>, shai@waves.com wrote: > I created a text edit control using CreateEditTextControl. > I can get the current text by calling > > char buf[256]; > Size textSize = 0; ...

Web resources about - Text bind command not selecting text - comp.lang.perl.tk

Consultation Document on the Methods for Selecting the Chief Executive and for Forming the LegCo in 2012 ...
The " Consultation Document on the Methods for Selecting the Chief Executive and for Forming the LegCo in 2012 " was a document published on ...

Voting Machine Caught on Camera Casting Ballot for Democrat when Selecting Republican - YouTube
**UPDATE.... I've heard many reports that this is "just a calibration issue." I will say this... when I went to page 2 and began voting for city ...

Selecting The Right Jeans
Fit, style, cut, colour and wash all factor into the pursuit for great denim.

Clock ticking on selecting successor to Leigh Clifford at Qantas
With Qantas on course to chalk up its largest annual profit since 2008, the question now is whether chairman Leigh Clifford is looking to hang ...

Why are the reserves selecting the team?
Backbenchers are the reserves of the parliamentary system. They are newcomers.

Jackie French: Why selecting the right place for your plants is important
The secret of growing anything easily is to choose the best spot for what you want to grow.

Netflix turns to pirates when selecting new shows
Imagine the surprise, then, when the popular video streaming site admitted that it actually turns to torrenters for inspiration. "With the purchase ...

Boston Marathon bombing trial: Judge, lawyers face challenges in selecting jurors - CTV News
As the second phase of jury selection began in the federal death penalty trial of Boston Marathon bombing suspect Dzhokhar Tsarnaev, it immediately ...

Selecting cabinet one of first orders of business for Trudeau
One of the first orders of business for any new prime minister is picking a cabinet. Who is likely to make the cut?

Agile Analysis, Self-Selecting Teams, TDD & BDD in Methods & Tools Winter 2014 issue
... for software developers, testers and project managers – has just published its Winter 2014 issue that discusses Agile Analysis, Self-Selecting ...

Resources last updated: 2/2/2016 3:23:34 PM