f



Confusing behavior regarding selected text in a text widget

Greetings one and all,

I am having trouble understanding how lines of text that have been
"selected" in a text widget are placed in the clipboard.  Here's what's
happening.

I have a text widget that contains only lines of text.  Some of the lines
are covered by a tag that makes them invisible to the user.  Specifically,
if ".t" is a text widget, I have defined the tag "hide_tag":

    .t tag configure hide_tag -elide 1

and apply it from start of line through end of line.

If one then "selects" lines of text that contain these "invisible" lines
and copies them to the clipboard using control-C, all selected lines show
up in the clipboard, including the "invisible" ones.

I understand why this is happening and, in hindsight, I should have
anticipated it, but nonetheless, it is undesirable behavior and needs to
be fixed in my application.

I've attempted to fix this by binding a proc to the <<Copy>> virtual event
and having that proc copy all selected text that is not "invisible" to the
clipboard using "clipboard clear" and "clipboard append" commands.
Although the proc appears to do the correct thing, i.e., excludes the
"invisible" lines, nonetheless, all selected lines, even the "invisible"
ones, still appear in the clipboard.

Something's going on here and I don't know what it is!  Can anyone help?

I have attached below example code that demonstrates the problem.

Thanks in advance!

Mike


#                    Start of example code.
#
# After sourcing this code in wish, you will see lines 1, 3, and 4 in the
# text widget.  Select the top two lines, press control-C to copy those lines
# to the clipboard, and then type "clipboard get -displayof .t" at the wish
# command prompt.  It will return lines 1, 2, and 3.
#
text .t -width 50 -height 10
pack .t

# Create tag that makes text "invisible".
#
..t tag configure hide_tag -elide 1

# Put some lines in the text widget.  Make the second line invisible.
#
..t insert end "Line #1 in text widget\n"
..t insert end "Line #2 in text widget (hidden)\n" hide_tag
..t insert end "Line #3 in text widget\n"
..t insert end "Line #4 in text widget\n"

# Change the callback for the "Copy" virtual event.
#
bind .t <<Copy>> {doCopyToClipboard .t}

proc doCopyToClipboard {tw} {
     set text_is_hidden 0
     set text_is_selected 0
     set text_for_clipboard [list]
     foreach {key value index} [$tw dump -tag -text 1.0 end] {
         switch -exact $key {
             tagon  {
                         switch -exact $value {
                             hide_tag {set text_is_hidden   1}
                             sel      {set text_is_selected 1}
                         }
                    }
             tagoff {
                         switch -exact $value {
                             hide_tag {set text_is_hidden   0}
                             sel      {set text_is_selected 0}
                         }
                    }
             text   {
                         if {$text_is_selected == 1 && $text_is_hidden == 0} {
                             lappend text_for_clipboard $value
                         }
                    }
         }
     }
     clipboard clear  -displayof $tw
     clipboard append -displayof $tw $text_for_clipboard
}
0
7/7/2008 2:39:31 PM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

1 Replies
775 Views

Similar Articles

[PageSpeed] 42

The problem is that the <<Copy>> event bound to the Text widget class
binding fires after the binding to .t, replacing the stuff you put on
the clipboard.  One possible solution would be to add [break] to your
binding:

    bind .t <<Copy>> {doCopyToClipboard .t; break}

I imagine you will also want to de-listify the value your proc sticks
on the clipboard; otherwise it seems to accomplish your goal.
0
aric.bills (466)
7/7/2008 9:04:17 PM
Reply:

Similar Artilces:

re: Confusing behavior regarding selected text in a text widget
This message is directed to whoever replied to my original post. I read it but it was deleted before I could reply. Thank you for your reply and explanation. I knew something was going on but didn't know that the text widget class binding would be triggered. I thought that overriding the widget instance would suffice. Something to learn about. Also, thanks for your observation on my "clipboard append" call- join should be used. By the way, your suggestions did the trick! Thanks again. Mike ...

text in a widget, text-widget
hello i have an application with a couple of text widgets but i would like to add some functionalities that at first and second sight are not directly supported by the plain text widget itself - ? for example i would like certain lines of text within the textwidget to take different background colors according to certain parameters also i would like to be able to detect certain sentences or words that would become 'links' and by clicking them i would open up different windows any suggestions to solutions and widgets for the above problems ? - i probably could...

Using Control-a to select all text in a text widget
I'm having a difficult time binding Control-a so it selects all the text in a widget just like the default Control-/ binding does. I've tried: ..t bind <Control-a> [.t bind <Control-/>] But [.t bind <Control-/>] returns nothing. If I do: ..t bind <Control-/> {puts "Selecting all"} ..t bind <Control-a> [.t bind <Control-/>] When I hit Control-/ I get at the prompt "Selecting all" and all the text is selected. But when I hit Control-a all I get is the "Selecting all" at the prompt and no text is selected. I've also tried: ..t bind <Control-a> {.t tag add sel 1.0 end} And that doesn't work either. In fact, with this code if you do Control-/ and then Control-a it unselects everything. And dumping the tags for the entire region show the tagon/tagoff for sel are gone. Does anyone know the semantics of Control-/? There's got to be more to it. - Ian I've just found this thread: http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/5c1df73696e94962/38ec894e32bafcd2?lnk=gst&q=select+all&rnum=8#38ec894e32bafcd2 Which seems to suggest there's nothing fancy about Control-/. - Ian And to answer my own question, the following works: bind .t <Control-a> {%W tag add sel 1.0 end; break;} - Ian On Wed, 01 Aug 2007 16:54:06 -0000, sniff.scratch@gmail.com wrote: >I'm having a difficult time binding Control-a so it selects all the >text in a w...

Text Widget Selection confusion
Hi all and Happy New Year I am getting confused trying to programatically set the selection in a text widget. I am implementing a search dialog which uses the text widget search command to return the match indexes. This works. I then add the "sel" tag to the matched range and this works too because if I use tk_textCopy the correct text is copied to the clipboard. The problem I have is that I cannot see the text that is tagged with "sel". If I drag select with the mouse I do see the selection highlighted but using tag add sel first last does not seem to give a visible selection. If I create a tag to use as a highlighter (e.g .t tag configure YELLOW -background YELLOW) and then do .t tag add YELLOW sel.first sel.last The correct text is highlighted As ever a kick in the right direction will be gratefully recieved ! Thanks in advance Julian I think I have solved it, I needed to give the text widget focus first... Unless a guru can steer me on a better path :) On Jan 13, 6:44=A0pm, JHJL <j...@hippospace.com> wrote: > Hi all and Happy New Year > > I am getting confused trying to programatically set the selection in a > text widget. I am implementing a search dialog which uses the text > widget search command to return the match indexes. This works. I then > add the "sel" tag to the matched range and this works too because if I > use tk_textCopy the correct text is copied to the clipboard. > > The problem...

Re: text in a widget, text-widget @ 1145998849
Intrah onat Diria .. Tue, 25 Apr 2006 13:55:44 -0700 , ****** wrote "Revera y": > of "unsubscribe ptk" to majordomo@lists.stanford.edu > If you wish to unsubscribe from this mailing list, send the message body > This message was posted through the Stanford campus mailing list server. > ++**=3D=3D > -++**=3D=3D--++**=3D=3D--++**=3D=3D--++**=3D=3D--++**=3D=3D--++**=3D=3D--= > > > > > ,=20 > , _________________ > , |---| > , | > , lead > , ::::::opthe > , oo,loent,uaha > , }, > ,...

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 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). What would this gain except for bloat? It's not like SQL is utterly compatible with any programming language; users will still have to learn all the operators anyway. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match Peter Eisentraut wrote: >>What is "text + text" supposed to do right now? > > Nothing. Then are these bugs? (7.4.5 and 8.0.0beta1 give same results). Frankly, the current behaviour is quite strange to me. ------------------ =...

Re: text in a widget, text-widget @ 1146167556
Intrah onat Diria .. Tue, 25 Apr 2006 13:55:44 -0700 ,Van Nieuwenhuize, Mike wrote "Noalim y": > > Johan, > > Here this will give you an idea how to create a link in a text widget as > well as some other tags. > > HTH > > Mike > > use strict; > use Tk; > use Tk::Dialog; > > my $mainWindow = MainWindow->new(-title => "Test Tags"); > > my $sc_width = 100; > my $sc_height = 15; > > my $scrolled = $mainWindow->Scrolled( > ...

RE: text in a widget, text-widget #2
Johan, Here this will give you an idea how to create a link in a text widget as well as some other tags. HTH Mike use strict; use Tk; use Tk::Dialog; my $mainWindow = MainWindow->new(-title => "Test Tags"); my $sc_width = 100; my $sc_height = 15; my $scrolled = $mainWindow->Scrolled( "Text", -scrollbars => 'se', -background => 'white', -wrap => &...

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 ...

highlight text in text widget
Hi, I am trying to make widget that displays text. I also want a search keywords available. The way I have envisioned is something similar to emacs search, i.e. it highlights all the occurrences of the keyword that you are interested in. I am trying to find out if that kind of highlighting be done in widget_text or some other widgets. Can anyone help? Thanks neon writes: > I am trying to make widget that displays text. I also want a search > keywords available. The way I have envisioned is something similar to > emacs search, i.e. it highlights all the occurrences of the keyword &g...

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 = MainW...

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...

text widget: loading dumped text?
Is there an easy way to reload information dumped from a text widget? I'm trying to reproduce and report a bug in the text widget and this would help a lot. -- Russell P.S. the bug is that in Aqua 8.4.15 if I scroll to the top of the text widget while some text is elided, often a few lines that *should* be displayed are simply blank. It's fairly reproducible but the data is rather complex. Russell E. Owen wrote: > Is there an easy way to reload information dumped from a text widget? > I'm trying to reproduce and report a bug in the text widget and this > would help a lot. > > -- Russell > > P.S. the bug is that in Aqua 8.4.15 if I scroll to the top of the text > widget while some text is elided, often a few lines that *should* be > displayed are simply blank. It's fairly reproducible but the data is > rather complex. What do you mean by "dumped"? Saved? -- Kevin Walzer Code by Kevin http://www.codebykevin.com Russell E. Owen wrote: > Is there an easy way to reload information dumped from a text widget? > I'm trying to reproduce and report a bug in the text widget and this > would help a lot. > It's possible to write code to do this, but there's nothing built-in to Tk or available in tklib. -- Bryan Oakley http://www.tclscripting.com Russell E. Owen wrote: > Is there an easy way to reload information dumped from a text widget? > I'm trying to reproduce and repo...

redirect text to file from text widget
I'm looking for a handle for the text widget so that I can redirect edited text orginally loaded from a file back into a file. If there was an attribute like the "-textvariable" option in label and entry widgets, I could simply echo it into a file from another widget (button, etc.). Thanks John Peters wrote: > I'm looking for a handle for the text widget so that I can redirect > edited text orginally loaded from a file back into a file. If there > was an attribute like the "-textvariable" option in label and entry > widgets, I could simply echo it into...

Replace text with image in text widget
I'm trying to replace an emoticon with an actual image in a text widget. I know I'm not doing this correctly: the sample code below inserts two images randomly and seems to garble the text in other ways. The idea is to have two emoticons (one on each line) and replace them with an image, nothing more. Can anyone take a look and suggest how I might get this to work? Thanks. --- SPfHZvvOGvfQEvfGdvjQE/rNMfrOMfrNPfvQHfzQHfjQLfrNRvjQL/vRJfzRJvrOWvbMh/3VHPfM h/3WHPzVMP7XF/zVMfrPdv7YGP7YG/7YHPzWPPzWPfvUVP7ZHf7ZIPvWVf7aJv7aJ/7bJv7bM/7b NP7cLf7dMPvXeP7dNvrVlv7eOPrWlvvaevrYmP7gRP7gRf7gRv7iTf7iWf7jUf3hav7jVv7jV/7k YP7lYfzioPzjn/zjoP7ocvzkoP7oc/7pcf7pcvzlp/7pe/7pfP3mp/7si/7tjf/tkf/tkv7uj/3r tf3stf/voP/vo//woP/wof/wpf/wp/7xuf7xvP/zqv7xwf/zq/7yuf/zsP/zsf/zsv7yv//zs/7y xP/zuf/zu//1vP70zv/2vP/2wv/2w//3wv/20P/3zf/3zv/30P/4zv/5z//51P/51f/61f/61v/5 4v/63v/64v/73//85v/85//87f/87v/98v/+9v////////////////////////////////////// /////////////////////////////////////////////////////yH+GkNyZWF0ZWQgd2l0aCBH SU1QIG9uIGEgTWFjACH5BAEKAP8ALAAAAAAWABYAAAj+AP8JHEiwoMGDA3cUMfID4UEZVlBB+/YN miosNxwKHAIrXLlz6NCdMxduVhKHQXJVs7YN3Dhy4rhdw6bryMEYqYL9QiYtWzdv2qYtA2aMFQ6D YIg5s9Xr2DNq1KIl83WrGTM3BU9YEsYrFq0ID4YVczChlqxdyjaxIAhj0ahQplYZGIALl4ADrU6F GuWoBsEZcwRJ6kQKiA9Xr3oAKfVpEiE6OQi+4GLnz6NLnUCJEgXKUyZIge58oUEQRRU2FeAcekSp UiVKkRDJobDmiguCJJ6QgaKgySBGjRoxMtRkQZQxUkoQBEGECxshBBho4MGDQ4MCQth4QRKCYAYb U8JosNGDIUEAAAgw4GEThoqODQVFMMkiBg2bPYkU8XmDRkwXJyMclIIWaZhxRhlkkFHGGWa0scUK CEGgghqF9JFHHXXk0UchcbQggU...

Text widget
I'm trying to write a text editor with Tk::Text. The Tk::Text widget has a very sophisticated mechanisms using 'tags' for applying formatting (font, size, bold, etc) to the text in the widget. Is there any way to save this formatting when saving the text from the widget to a file? The Tk::TextUndo widget has the Save method - but it strips all tags out and just saves the plain text. I presume one needs a markup language of some sort to represent the tags - and when reading the file back in you apply the tags again. So ... a rich text widget in Tk? Any fancy wa...

Selectable text in Widget?
Does someone know how to make text selectable in a widget. This text is inside a div. I have already defined a dashboard-region, but I still can't select the text. Any suggestions would be appreciated. Thanks, Daniel ...

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 ...

Text Widget: Highlighting search terms with the text.
I'm writing a little application to search through data. I would like to be able to go through the text displayed in the Text Widget and highlight (change the colour or bold) the words which were used as the search term. In this little example, I would like to use the highlightText sub to bold the word "line" throughout the Text Widget. Is this possible? use Tk; my $mw = MainWindow->new(-title => 'Hymns GUI'); my $but1 = $mw -> Button(-text => 'Insert Text', -command => \&insertText)->pack(-side =>...

how to change foreground color of text in text widget
hi, i have a program in which i am reading from a file and displaying contents of file in a text widgets now on a particular event i read one line of text widget & i need to change color of that line same as it occurs during debugging a program what i feel a tag has to be created suppose .t is my text widget ..t tag configure color1 -foreground red now how do i change color of the line which i have read and how to use this tag if so now i am able to do that what i did is while inserting line in text widget i added diff tag names to each line and while reading each line i configured tag o...

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; ...

select block in text widget
Hi all, I found at http://mini.net/tcl/8406 Martin S. Weber's package which allows selection column block of the text widget. But, if I perform copy-paste or delete action, its copied/deleted all characters between left-upper index to right-lower index of the selected rectangle, including characters outside the selected area. As if I was select between these points by regular selection. Is it possible to "say" to the text widget: delete only selected area? Ilya. Ilya Ginzburg wrote: > Hi all, > I found at http://mini.net/tcl/8406 Martin S. Weber's package whic...

Text from required text box to read-only text box
Hello, I am fairly new to JavaScript and its use in Acrobat Professional. My situation is this: I have a form with a text box field which is required for the user to enter his/her name. I would like the required text box to display the name in all caps. I also need the user's name to appear in a read-only text box later in the form, which I would like to have the first letter of the user's first, middle initial, and last names to be capitalized. I would also like to have all required fields on the form highlighted in yellow, but the highlighting not printed. Lastly, I would like the...

Web resources about - Confusing behavior regarding selected text in a text widget - comp.lang.tcl

Confusing similarity - Wikipedia, the free encyclopedia
In trademark law , confusing similarity is a test used during the examination process to determine whether a trademark conflicts with another, ...

Facebook COO Sheryl Sandberg Admits That Privacy Changes Have Been Confusing
One of the chief complaints among Facebook users is that the changes to privacy controls have been far too confusing, with little effort in educating ...

RIM Updates Facebook For Blackberry App With Confusing Push Notifications
Research In Motion released a new version of its Facebook for Blackberry mobile application yesterday. The app includes improvements to news ...

Confusing Question of the Day: Donald Trump, Wiz Khalifa, Emojis, & Harry Styles - YouTube
... a lot going on in the news right now, so we thought it would be fun to jam a bunch of subjects together in order to ask people a very confusing ...

Surface RT was confusing: Microsoft
Microsoft dropped the 'RT' branding from its second generation Surface tablet to avoid consumer confusion, the company has revealed.

Better day for Pistorius: detective admits account adds up during confusing testimony
The detective leading the police investigation into Oscar Pistorius' fatal shooting of his girlfriend offered confusing testimony on Wednesday, ...

Figures don't lie, but they sure can get confusing
Is Kings Cross getting more violent at night? It should be a simple question but, as Sean Nicholls finds, the truth is a little more blurred. ...

How to Get Away with Murder, The Blacklist: TV’s most confusing shows
IF you’ve ever watched a TV show and asked why you’re wasting your time, you are not alone. These series are so confusing, convoluted and frustrating ...

'Borders, genders – all a bit confusing right now!': Russian ministry refers to Julie Bishop as a 'he' ...
Australia's ambassador teases his Russian hosts during a diplomatic ding-dong on Twitter.

MH370 search: the most confusing moments
Malaysian authorities have regularly issued confusing statements in the 17 months since Malaysia Airlines flight MH370 disappeared.

Resources last updated: 3/13/2016 12:37:52 PM