in reply to Extracting information from a Text widget

sorry for not giving a direct answer...as i think the design is a kludge. Why would you store line.char references to text, when you could store these shapes in a hash and refer to any attribute directly. i.e. populate the hash as you're reading the Text widget.
if you really must (why) refer to text positionally, then perl's tk module has good facilities for this, as well as for generating graphics/widgets.
the hardest line to type correctly is: stty erase ^H
  • Comment on Re: Extracting information from a Text widget

Replies are listed 'Best First'.
Re^2: Extracting information from a Text widget
by jlnelson19 (Initiate) on Jul 03, 2007 at 17:55 UTC
    Well, I need to be able to add shapes into the text widget, say if the user right-clicks on the red circle (in the tree widget), and requests to duplicate the red circle 3 times. Could the hash design accomodate this?

    The reason I was thinking of using the line.char references was so that I could insert the new circles in the correct place in the text (i.e. after the original red circle).

      use a suitable linked list module, or there might be something similar under "sequence" in CPAN. this will help keep the design logic separate from implementation.
      as per your clarification, you're interested in being able to follow sequences. An artificial contrivance such as text box co-ordinates will surely slow you down in implementation, not to mention horrible maintenance. the basic idea is of sequences or linked lists or such. if you use text box co-ordinates, they'll need to be re-computed for shapes following an insert.
      all the best in your project
      the hardest line to type correctly is: stty erase ^H
      ... I was thinking of using the line.char references was so that I could insert the new circles in the correct place in the text ...

      Rather than fighting to translate character offsets to line/char offsets in order to insert the additions, why not query the entire text, perform substitutions on that and then replace (delete/insert) the entire text?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.