Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

Seeking a rich text editing widget


Hi,
I am seeking a widget (or megawidget) that supports rich-text/html editing.

Any suggestions?

Thanks.

Geoffrey King wrote:
> Hi,
> I am seeking a widget (or megawidget) that supports rich-text/html editing.

> Any suggestions?

Have you checked out the text widget?

With the addition of your key bindings for formatting (or buttons on top, or
menus) I think you will have what you are asking for.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

The text widget would seem to require a *lot* of work. So I am trying to
find an alternative or some existing basis to work from.

Geoffrey King wrote:
> The text widget would seem to require a *lot* of work. So I am trying to
> find an alternative or some existing basis to work from.

ntext aims to remove the anachronisms in the text widget bindings.

http://wiki.tcl.tk/17976

It does not add rich text editing, but might be an easier starting point for
that.

Keith.

On May 29, 7:35 am, Geoffrey King <lordergeoff@optushome.com.au>
wrote:

> Hi,
> I am seeking a widget (or megawidget) that supports rich-text/html editing.

What do you mean "supports rich-text/html editing"? Do you mean:

allows me to load plain text and then edit that text, applying bold,
italic, underlining, fonts, etc. and then writing the text out in rich-
text or html format?

or do you mean

allows me to load rich-text or html and then edit said text in a GUI
fashion

On 30 mei, 13:16, "Larry W. Virden" <lvir@gmail.com> wrote:

Actually, the text widget is capable of both types of editing.

Hm, besides ntext, you may want to consider using ctext from Tklib, as
that allows you to easily implement such things as syntax
highlighting.

Regards,

Arjen

On May 30, 8:06 am, Arjen Markus <arjen.mar@wldelft.nl> wrote:

Either case, however, requires various degree of additional
programming in support of the functionality.  Without more
information, I am uncertain, but if I were a betting person, I'd be
betting the original poster is looking for a megawidget with all the
menuing, toolbars, etc. to provide what many web apps or applications
describe, at times as rich text editing. Something that the developer
could instantiate and have buttons for selecting bold, italic, etc.,
font selection of selected text, etc. and then built in ability to
save (and later load) the data in an industry standard format (html or
rtf), so that the user of the widget doesn't need to know any of the
underlying details and a megawidget which does not expect the
developer to have to code any of the above features.

But, maybe I am off base. If so, sorry - that's where I was heading
with my questions... trying to understand better the requirements.

Does anyone know of a Tcl/Tk megawidget which implements extensive
rich text editing? Something that doesn't require coding additional
tcl procs, etc.?

Larry, you would be right. In a phrase i would like "simple MS Word" style
editing or "HTML editing" might be better. It would have : font variations,
tables, bullet points, inline images, nestings of the above. Any more is a
bonus. From the posts I suspect that meagre list will be hard to find.

Geoffrey King wrote:
> Larry, you would be right. In a phrase i would like "simple MS Word"
> style editing or "HTML editing" might be better. It would have : font
> variations, tables, bullet points, inline images, nestings of the above.
> Any more is a bonus. From the posts I suspect that meagre list will be
> hard to find.

I'm pretty certain no megawidget exists that does that. However, it's
honestly not that hard to write your own given what's built in to the
text widget already. Tables and embedded images would be the only thing
remotely hard (flowing around images, for example, can't be done). If
you just want to be able to pick fonts, colors, text size and alignment,
bullets, etc., that stuff is easy.

As a starting point, here's some code that shows one way to implement a
bold and italic button. It's not complete, but it illustrates how to
intercept text insertions and apply any tags that you want.

First, a simple megawidget (pure tcl, no megawidget package required!)
that adds a new "tags" command to the text widget, and code to apply
those tags to all newly inserted text (here's hoping line boundaries
don't get screwed up as it passes through the ether!):

namespace eval rtext {
   namespace eval instance {}

}

proc rtext::rtext {path args} {
   upvar \#0 [namespace current]::data-$path data

   set data(tags) ""
   set data(actual) [namespace current]::instance::$path
   text $path
   rename $path $data(actual)
   interp alias \
       {} $path \
       {} [namespace code [list widgetProxy $path]]
   eval $data(actual) configure $args

   return $path

}

# this gets called instead of the actual widget
# command. Mostly it passes things through to the
# actual widget, but "insert" and a new "tags"
# command are treated specially. You could use
# the "wcb" package to accomplish the same thing.

proc rtext::widgetProxy {path cmd args} {
   upvar \#0 [namespace current]::data-$path data

   if {$cmd eq "insert"} {
     # for each block of text being inserted, add the list of
     # current tags to the list of tags to be applied to the block
     set statement [list $data(actual) insert [lindex $args 0]]
     foreach {string tags} [lrange $args 1 end] {
       lappend statement $string [concat $tags $data(tags)]
     }
     set result [uplevel $statement]

   } elseif {$cmd eq "tags"} {
     # usage: $path tags ?tag ?tag ...??
     # if tags are given, apply the tags to any new text that is
     # inserted
     if {[llength $args] > 0} {
       set data(tags) $args
     }
     set result $data(tags)

   } else {
     set result [uplevel [concat [list $data(actual) $cmd] $args]]
   }

   return $result

}

Next, here's a little test program that creates an instance of the
widget along with two toolbar buttons for bold and italic so you see how
you would tie toolbar buttons to the new widget. Expanding the above to
do underline, overstrike, text alignment, etc should be fairly
straight-forward. Just create tags for every attribute you want on the
toolbar and lather, rinse, repeat.

package require Tk

global style

frame .tb -borderwidth 2 -relief groove
rtext::rtext .rtext \
   -wrap word \
   -yscrollcommand [list .vsb set]
scrollbar .vsb -command [list .rtext yview]
pack .tb -side top -fill x
pack .vsb -side right -fill y
pack .rtext -side bottom -fill both -expand true

font create boldFont \
     -family Helvetica -weight bold
font create italicFont \
     -family Helvetica -slant italic
font create boldItalicFont \
     -family Helvetica -weight bold -slant italic
font create normalFont \
     -family Helvetica

checkbutton .tb.bold \
     -indicatoron false -text "B" -bd 1 \
     -command [list toggleStyles .rtext] \
     -variable style(bold) -font boldFont \
     -onvalue 1 -offvalue 0
checkbutton .tb.italic \
     -indicatoron false -text "I" -bd 1 \
     -command [list toggleStyles .rtext] \
     -variable style(italic) -font italicFont \
     -onvalue 1 -offvalue 0 -font italicFont
pack .tb.bold .tb.italic -side left

set style(bold) 0
set style(italic) 0

.rtext tag configure normal -font normalFont
.rtext tag configure italic -font italicFont
.rtext tag configure bold -font boldFont
.rtext tag configure boldItalic -font boldItalicFont

.rtext tags "normal"

proc ::toggleStyles {w} {
   global style
   set tags {}
   if {$style(bold)} {lappend tags bold}
   if {$style(italic)} {lappend tags italic}
   if {$style(bold) && $style(italic)} {lappend tags boldItalic}
   if {[llength $tags] == 0} {set tags [list "normal"]}
   eval \$w tags $tags

   # if there is a selection, apply the current styles to the selection
   set sel [$w tag ranges sel]
   if {[llength $sel] > 0} {
     foreach {start end} $sel {
       # this could be generalized, but it's good enough
       # for this example..
       $w tag remove bold $start $end
       $w tag remove italic $start $end
       $w tag remove boldItalic $start $end
       $w tag remove normal $start $end
       foreach tag $tags {
         $w tag add $tag $start $end
       }
     }
   }

}

--
Bryan Oakley
http://www.tclscripting.com
Thanks Bryan. The code is useful in a more general sense because i am a
newbie and it makes a nice little "framework". But as far as making a rich
text editor, it would take as a wild as a guess:
  o styles - a day
  o bullet points - 3 days?
  o text flow - ?
  o tables - using nested grid geometry and texts for each cell - 5 days?

which as a basis isn't too bad - and kinda interesting - but sure not a drop
in ready to go.

[code]
Geoffrey King schrieb:
> Thanks Bryan. The code is useful in a more general sense because i am a
> newbie and it makes a nice little "framework". But as far as making a
> rich text editor, it would take as a wild as a guess:
>  o styles - a day
>  o bullet points - 3 days?

Probably less. Lifting code from the right sources might help (e.g.
tkoutline or the notebook app).

>  o text flow - ?

Depends. Some of the textutil stuff in tcllib might be handy for doing
things there.
http://tcllib.sourceforge.net/doc/textutil.html
Producing good and nice looking text flow is hard, take a look at MS
Word in contrast to LaTeX or DTP programs like InDesign for fully
justified paragraphs.

>  o tables - using nested grid geometry and texts for each cell - 5 days?

Or an embedded tktable widget for example (or an embedded canvas or
similar drawing area if you want to do fancy stuff)

Michael

I think you really need to define *exactly* what you want this "rich text
editing widget" to do so we can point you in the right directions.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
On May 31, 9:26 pm, "Gerald W. Lester" <Gerald.Les@cox.net> wrote:

> I think you really need to define *exactly* what you want this "rich text
> editing widget" to do so we can point you in the right directions.

Take a look at http://docs.google.com/?action=newdoc&title=

See the megawidget for entering documents? I suspect that if the
orginal poster could get a megawidget that provided this
functionality, that would be a good start towards their goal.

I also would be surprised to find out that none of the tk megawidget
collections had such a widget. I'm just not up on what each of the
collections have at this time. Seems like this would be a wonderful
project for someone to work on at http://wiki.tcl.tk/ ...

Larry W. Virden wrote:
> On May 31, 9:26 pm, "Gerald W. Lester" <Gerald.Les@cox.net> wrote:
>> I think you really need to define *exactly* what you want this "rich text
>> editing widget" to do so we can point you in the right directions.

> Take a look at http://docs.google.com/?action=newdoc&title=

> See the megawidget for entering documents? I suspect that if the
> orginal poster could get a megawidget that provided this
> functionality, that would be a good start towards their goal.

> I also would be surprised to find out that none of the tk megawidget
> collections had such a widget. I'm just not up on what each of the
> collections have at this time. Seems like this would be a wonderful
> project for someone to work on at http://wiki.tcl.tk/ ...

Like maybe the OP since he needs it?

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

> > I also would be surprised to find out that none of the tk megawidget
> > collections had such a widget. I'm just not up on what each of the
> > collections have at this time. Seems like this would be a wonderful
> > project for someone to work on athttp://wiki.tcl.tk/...

> Like maybe the OP since he needs it?

Certainly seems like a nice project, if no one knows, off the top of
their head, of such a widget.

Note that I just took a look around the wiki and I don't see a page
specifically dedicated to listing, for instance, all the Tk related
extensions that are around. The closest appears to be Extensions for
Tcl and Tk, but it appears to be woefully out of date, providing a
great area for people to work in!

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc