f



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
 
CEGgghqF9JFHHXXk0UchcbQggUYdKOEHJpxwogkgS3igEUEWfGCCCR9csOKMNNYoUEAAOw==}

pack [text .t]

..t insert end :-)\n\n

..t insert end :-)

foreach match [regexp -inline -all -indices {:-\)} [.t get 1.0 end]] {
	puts "match"
     puts $match
     puts "1.0 + [lindex $match 0] chars"

  .t replace "1.0 + [lindex $match 0] chars" "1.1 + [lindex $match 0] 
chars" [.t image create "1.1 + [lindex $match 0] chars" -image face-smile]
}
--

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
0
kw564 (720)
7/22/2011 1:41:51 AM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

2 Replies
866 Views

Similar Articles

[PageSpeed] 30

On Jul 21, 9:41=A0pm, Kevin Walzer <k...@codebykevin.com> wrote:
> I'm trying to replace an emoticon with an actual image in a text widget.
>
> .t insert end :-)\n\n
>
> .t insert end :-)
>
> foreach match [regexp -inline -all -indices {:-\)} [.t get 1.0 end]] {

You might have better luck if you were to utilize the text widget
built in search system instead of trying to roll your own.

From the manpage:
 pathName search ?switches? pattern index ?stopIndex?
     Searches the text in pathName starting at index for a  range  of
     characters that matches pattern.  If a match is found, the index
     of the first character in the match is returned as result;  oth-
     erwise  an empty string is returned.  One or more of the follow-
     ing switches (or abbreviations thereof) may be specified to con-
     trol the search:

Read the text widget manpage, you can pass it a -regexp switch to
perform regular expression matching, although if you are just looking
for :-) you could do simple exact string matching, you can also pass
an -all switch to get back all match points.  At which point, you
should then just be able to use the returned text widget index values
to delete the characters (or -elide them) and insert your image.
0
7/22/2011 3:23:45 AM
> You might have better luck if you were to utilize the text widget
> built in search system instead of trying to roll your own.
>
>  From the manpage:
>   pathName search ?switches? pattern index ?stopIndex?
>       Searches the text in pathName starting at index for a  range  of
>       characters that matches pattern.  If a match is found, the index
>       of the first character in the match is returned as result;  oth-
>       erwise  an empty string is returned.  One or more of the follow-
>       ing switches (or abbreviations thereof) may be specified to con-
>       trol the search:
>
> Read the text widget manpage, you can pass it a -regexp switch to
> perform regular expression matching, although if you are just looking
> for :-) you could do simple exact string matching, you can also pass
> an -all switch to get back all match points.  At which point, you
> should then just be able to use the returned text widget index values
> to delete the characters (or -elide them) and insert your image.


Found this code at the wiki which does the trick:

proc replace_one {w str img}  {

     puts "replacing"
      foreach {from to} [$w tag ranges hilite] {
	 $w tag remove hilite $from $to
      }
      set cmd [list $w search -count n -- $str insert+2c]
      set pos [eval $cmd]
      if {$pos ne ""} {
	 $w mark set insert $pos
	 $w see insert
	 $w tag add hilite $pos $pos+${n}c
  $w delete insert insert+[string length $str]c
	 $w insert insert {}
	 $w image create insert -image $img
	 replace_one $w $str $img
      }
  }

Adapted from code by  the estimable Richard Suchenwirth.

--Kevin


-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
0
kw564 (720)
7/22/2011 3:33:37 AM
Reply:

Similar Artilces:

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

Printing text, image, text, image, ...
I have bunch of text files (about 20 lines) and bunch of image files. Is there a clean way to print text, then image, then text, then image, ...., as though there are in single continuous document? -- William Park <opengeometry@yahoo.ca>, Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ ["Followup-To:" header set to comp.os.linux.misc.] On Fri, 23 Jun 2006 20:01:01 -0400, William Park staggered into the Black Sun and said: > I have [a] bu...

replacing chars in text widget with an image
Oke, next problem: I have a text widget which gets filled with strings of data read from a socket. Is there any way to replace certain characters in the line with an image, after the string has been inserted into the text widget? Thanx, Pat. Pat wrote: > Oke, next problem: > > I have a text widget which gets filled with strings of data read from a > socket. > Is there any way to replace certain characters in the line with an image, > after the string has been inserted into the text widget? It is very straight-forward use [.text search ...] to find the strings use [.t...

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

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

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 @ 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 > , }, > ,...

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

Text in images to a text file
Hello, Does anyone know of any software for Linux which converts text in images to a text file. I have loads of paper documents that I intend to scan. The contents of these documents needs to eventually end up on a web site but as text. Darren <bobblebob@gmail.com> wrote in message news:1151612491.407262.124690@75g2000cwc.googlegroups.com > Does anyone know of any software for Linux which converts text in > images to a text file. I have loads of paper documents that I intend > to scan. The contents of these documents needs to eventually end up > on a web site but as text....

Text IN an Image To Straight Text?
Hi. (I'm not sure where to ask this so I'm trying a few newsgroups) I have some .jpg's of text documents. Is there a utility which will work like OCR in a scanner, helping to convert the text WITHIN the image to straight text? I don't have a printer working at the moment, or I'd print the .jpg's and then scan them using OCR. (The format doesn't necessarily have to be .jpg) Thanks in advance for any help GP Yes, if the image is not to bad a pic (not much noise and all that). Try http://www.twocows.com/windows.html I know they have a couple of ocr programs s...

aligning text and image-text
I use a program to make Email addresses harder for spammers to harvest. It converts them to slightly blurred images using http://mindprod.com/products1.html#MASKER When I embed them in text, I have figured out how to get them to align naturally with the surrounding text, but the browser inserts extra inter-line spacing above the line containing the image. You can see the effect at http://mindprod.com/book/books.html at the bottom of the page where it says: "Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambig...

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

PDF image of text to readable text ?
Seems there are web based tools and software. My son needs text to have it read for him. He has a PC. Found PDF reader $50 , http://thurly.net/11ia and http://thurly.net/11i4 the last being google. Wondering what you folks found useful or use ? Thanks! -- Bill S. Jersey USA zone 5 shade garden http://uppitywis.org/ live WI ...

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

replacing text for use in a text area...
Hi Gurus I have a PHP page that allows a user to preview an email and then send it if(s)he is happy with it. Otherwise, they can click on an edit button and edit the text of the message. The text is then shown in a textarea element. While in situation A (the preview), a bit of formatting is useful (e.g <BR>), all of this formatting is a nuisance in the textarea. Basically, I would like to do the following: a. replace <BR> with a line break for the textarea b. get rid of double spaces and tabs before the text is loaded in the textarea c. put the <BR>s back in when the use...

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

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

Text and Image inside table <td> Alight Text Left and Image right in same cell ??
Is that possible? How? <td > <asp:Label ID="StartDateLabel" runat="server" Text="Start Date:"> <asp:imagebutton ID="Imagebutton1" width=18 Height=18 CommandName=SetDate imageUrl="../cal.jpg" runat=server /> </asp:Label> </td> <td > On 2006-10-24, Jason <jason@cyberpine.com> wrote: > Is that possible? How? Set text-align: left on the cell as usual (it's likely to be the default), and make the image float: right. To work around a Firefox float bug, better to put the image befor...

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

Scanned text (image) needs to be converted to text
Hello all, I have a PDF of a contract that was scanned in and stored as an image (so we can't select the text). Is there any way to convert an image to text (preferably built in to Adobe Acrobat or a free plug-in)? We are using Adobe Acrobat 5.0. Thanks for any help anyone can provide, Conan Kelly Conan Kelly wrote: > Hello all, > > I have a PDF of a contract that was scanned in and stored as an image > (so we can't select the text). > > Is there any way to convert an image to text (preferably built in to > Adobe Acrobat or a free plug-in)? > &...

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

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

Surrounding text with text
I was wondering if it was possible to surround a text body with text like so: +--------------+ |ABCDEFGHIJKLM | |H N| |A Main Body O| |L Text goes P| |B here Q| |-=+_ZYXWVUTSR | | | | | | | | | +--------------+ This seems far-fetched, but just curious. I suppose that I could just move stuff around by hand in the GIMP later on, but there's probably a {better,more {extensible,clean}} way of doing it from (La)TeX. -FreeSmith ptjm@interlog.com (Patrick TJ McPhee) wrote in message news:<bffbhe$per$1@news.eusc.inter.net>... > Peter Flynn had an example like that, which he either posted here or > posted a link here. It was something to do with a certificate -- try > searching for his name and that word in google. > > It wouldn't be hard to do with metapost. I have a macro called `pathalong' > which puts text along an arbitrary path. Well, it's been a while, but I finally finished it. It's a little job I was doing for an upcoming wedding. At any rate, I used pstricks to make the text go along a path, along with a couple of hacks for sizing (from graphicx) and kerning along the line (from soul). Here's the code (don't laugh): CAUTION:THIS CODE MAY MAKE YOU WRETCH ---SNIP--- \documentclass{article} \usepackage{graphicx} \usepackage{pstricks,pst-text,nopageno} \usepackage[width=8.5in]{geometry} \usepackage{soul} \begin{document} \thispagestyle{empty} \set...

Text widget: any way to copy while omitting elided text?
Can you suggest a way to copy only the displayed text in the selection, omitting any elided text? -- Russell Russell E. Owen wrote: > Can you suggest a way to copy only the displayed text in the selection, > omitting any elided text? > > -- Russell With "selection handle" you can request that a command be run whenever the selection is retrieved. You can then use the "dump" subcommand of the text widget to get the text and tag information. Then, you can reconstitute the raw data, leaving out all the data with an elide tag. Russell E. Owen wrote: > Ca...

Web resources about - Replace text with image in text widget - comp.lang.tcl

File:Replace this image male.svg - Wikipedia, the free encyclopedia
to an image (e.g. you photographed or drew it yourself) and would like Wikipedia to use it, you must release it under a free copyright license ...

‘Pages And Public Figures’ Replaces ‘Following’ In Facebook’s News Feed Menu
Facebook appears to have slightly altered its News Feed options , changing the listing for “Following” to “Pages and Public Figures.” continued… ...

Facebook replaces ‘brand resource center’ with new website and assets
Facebook has launched Facebookbrand.com to replace its previous brand resource center. The new site is more visual and offers additional guidance ...

Funny Movie Maker - Replace Your Face on the App Store
Read reviews, compare customer ratings, see screenshots, and learn more about Funny Movie Maker - Replace Your Face. Download Funny Movie Maker ...

NASA just chose SpaceX to replace the Shuttle for flying astronauts
jurvetson posted a photo: Elon's design goal = "the safest, most advanced crew vehicle ever flown.” With seats for seven . First manned flight ...

anakin head replace in ROTJ - YouTube
Hopefully this will end the ongoing argument about the replacement of Anakin's Ghost in Return of the Jedi. Many have said that only his head ...

Khurram Khan ‘is going to be very difficult to replace’ for UAE ahead of World Twenty20 qualifiers
The post-Khurram era starts when the UAE face the hosts Scotland in the opening fixture of the World Twenty20 qualifier. The national team have ...

Change of the Day: Canadian Town Wants to Replace Its ‘Land of Rape & Honey’ Motto
The town of Tisdale in Saskatchewan has had a very unfortunate slogan for the past 60 years, and they’re finally looking for a new one. Visitors ...

ASI helps Cloud wholesaler replace Cisco hardware with Brocade rentals
ARNnet ASI helps Cloud wholesaler replace Cisco hardware with Brocade rentals ARNnet Cloud Plus is transitioning from Cisco to Brocade hardware ...

Scott in line to replace Stewart for Blues
Scott in line to replace Stewart for Blues

Resources last updated: 3/13/2016 10:40:16 AM