Tkinter <<Modified>> and bindtags ordering

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bytecolor

    Tkinter <<Modified>> and bindtags ordering

    I'm trying to extract the text of the current line on the <<Modified>>
    event.
    It doesnt work if I delete a character. If I type 'abc' I get 'abc' in
    text_changed().
    If I hit backspace I still get 'abc'. Backspace once more, I get 'ab'.
    So the
    callback is called before the text is changed. But only on a delete.
    Someone told me it has to do with bindtags ordering. I've read what
    docs I can
    find on the subject, but I cant figure out why it's not working. Maybe
    I should
    learn a bit of Tcl, eh?

    import Tkinter as tk

    def text_changed(ev t):
    global changing
    if changing: return
    changing = True
    line, col = t.index('insert ').split('.')
    txt = t.get('%s.0' % line, '%s.end' % line)
    print '|%s|' % txt
    t.tk.call(t._w, 'edit', 'modified', 0)
    changing = False

    changing = False
    root = tk.Tk()
    t = tk.Text(master= root)
    t.pack()
    t.focus_set()
    t.tk.call(t._w, 'edit', 'modified', 0)
    t.bind('<<Modif ied>>', text_changed)
    root.mainloop()

    --
    bytecolor

  • Rob Wolfe

    #2
    Re: Tkinter &lt;&lt;Modifie d&gt;&gt; and bindtags ordering


    bytecolor wrote:

    [...]
    changing = False
    root = tk.Tk()
    t = tk.Text(master= root)
    t.pack()
    t.focus_set()
    t.tk.call(t._w, 'edit', 'modified', 0)
    What about instead of:
    t.bind('<<Modif ied>>', text_changed)
    this event:

    t.bind('<KeyRel ease>', text_changed)
    root.mainloop()
    --
    HTH,
    Rob

    Comment

    • bytecolor

      #3
      Re: Tkinter &lt;&lt;Modifie d&gt;&gt; and bindtags ordering

      On Apr 3, 3:16 am, "Rob Wolfe" <r...@smsnet.pl wrote:
      What about instead of:
      >
      t.bind('<<Modif ied>>', text_changed)
      >
      this event:
      >
      t.bind('<KeyRel ease>', text_changed)
      >
      root.mainloop()
      >
      --
      HTH,
      Rob
      Hey Rob,
      I actually started with that event, until I came across the modified
      event. I'm working on syntax highlighting. So I need any text change.
      Also, colorizing on a key release is annoyingly noticeable to the
      user. I tried it :)

      I'm sure there are going to be other perils along the way as this is
      my first attempt at syntax highlighing. I can load a file and the
      highlighting works very well. I used an elaborate regex with named
      groups and re.finditer(). I either use the names directly as edit
      tags, or they help me look up other tags in a dict. It's quite fast.

      screenshot with random (ugly) colors:


      That part wasn't bad at all. Now I need to code the text change
      logistics but this bindtags ordering has got me perplexed.

      --
      bytecolor

      Comment

      • Rob Wolfe

        #4
        Re: Tkinter &lt;&lt;Modifie d&gt;&gt; and bindtags ordering


        bytecolor wrote:
        Hey Rob,
        I actually started with that event, until I came across the modified
        event. I'm working on syntax highlighting. So I need any text change.
        Also, colorizing on a key release is annoyingly noticeable to the
        user. I tried it :)
        >
        I'm sure there are going to be other perils along the way as this is
        my first attempt at syntax highlighing. I can load a file and the
        highlighting works very well. I used an elaborate regex with named
        groups and re.finditer(). I either use the names directly as edit
        tags, or they help me look up other tags in a dict. It's quite fast.
        >
        screenshot with random (ugly) colors:

        >
        That part wasn't bad at all. Now I need to code the text change
        logistics but this bindtags ordering has got me perplexed.
        Have you looked at ColorDelegator. py from idlelib?
        There has been done such a syntax highlighting based on Tkinter.Text.

        --
        HTH,
        Rob

        Comment

        • bytecolor

          #5
          Re: Tkinter &lt;&lt;Modifie d&gt;&gt; and bindtags ordering

          On Apr 3, 5:48 am, "Rob Wolfe" <r...@smsnet.pl wrote:
          Have you looked at ColorDelegator. py from idlelib?
          There has been done such a syntax highlighting based on Tkinter.Text.
          >
          --
          HTH,
          Rob
          I've been poking around it a bit. I actually use the tabpage module in
          my app. Guess I should take a harder look at it. Nice bit of software.

          --
          bytecolor

          Comment

          Working...