aplsimple / pave

Tcl/Tk library for GUI development
https://aplsimple.github.io/en/tcl/pave/
MIT License
7 stars 1 forks source link

Gutter appears only when I hover mouse over text widget #8

Closed georgtree closed 2 months ago

georgtree commented 2 months ago

Hello! Gutter works well, the only issue is that it appears near text widget only after hovering mouse over the text widget. How could I resolve this? Thank you in advance!

aplsimple commented 2 months ago

Use the snippet from alited's code as a sample:

proc main::UpdateGutter {} {
  # Redraws the gutter.

  namespace upvar ::alited obPav obPav
  set wtxt [CurrentWTXT]
  after idle [list after 0 "$obPav fillGutter $wtxt"]
}

Here, $obPav refers to the apave object that layouts the text and its gutter, $wtxt is the text's path. In some cases (as yours) the gutter needs to be updated directly.

georgtree commented 2 months ago

Hello, I don't quite understand the command CurrentWTXT and where I should run this procedure :(

georgtree commented 2 months ago

I tried like that:

  proc UpdateGutter {} {
      namespace upvar ::modelTestVerTool::gui::unifiedTestWin objPave objPave
      set wtxt .winUnTest.fra.pan.panCode.lfrCode.texCode
      after idle [list after 0 "$objPave fillGutter $wtxt"]
  }
  UpdateGutter

.winUnTest.fra.pan.panCode.lfrCode.texCode - full path to text widget, The error is:

invalid command name "paveUnifiedTestWin"
invalid command name "paveUnifiedTestWin"
    while executing
"paveUnifiedTestWin fillGutter .winUnTest.fra.pan.panCode.lfrCode.texCode"
    ("after" script)

paveUnifiedTestWin - name of pave object

aplsimple commented 2 months ago

UpdateGutter proc needs no "namespace upvar", the sample above is just a sample. You can use your own variable for the $objPave, including a global one if not a fully qualified or passed as an argument to UpdateGutter.

As for calling it: supposedly, at problems, you call UpdateGutter after a fully layouted Tk window and before it goes in the event cycle.

At using apave package, this means after paveWindow and before showModal procedures. Also, I should note that filling/updating the gutter can be needed in some other cases and can present some problems in those cases which are very individual. No universal recepts for any case, alas.

Try and keep much of patience at dealing with Tcl/Tk, excuse me for the moralising (I've passed through this stuff some years ago, so I may do this moralising, sorry). At that, Tcl/Tk provides a great deal of choice freedom to solve problems: if not this then that you find from time to time.

georgtree commented 2 months ago

Hello, no problems, I updated procedure to:

proc UpdateGutter {} {
            # Redraws the gutter.
            set wtxt .winUnTest.fra.pan.panCode.lfrCode.texCode
            after idle [list after 0 "::modelTestVerTool::gui::unifiedTestWin::paveUnifiedTestWin fillGutter $wtxt"]
        }

it doesn't throw a error, but issue still persist. I tried to call this procedure in many places, before text insert and after, before showModal call, no effect :(

proc fillCodeText {} {
            variable locVars
            .winUnTest.fra.pan.panCode.lfrCode.texCode delete 0.0 end
            UpdateGutter
            .winUnTest.fra.pan.panCode.lfrCode.texCode insert end [string trim $locVars(code)]
            UpdateGutter
            return
       }
fillCodeText
UpdateGutter
UpdateGutter
set res [$objPave showModal $win -decor 1 -escape no -resizable 1 -modal no]

Where could I look also?

UPD: Gutter appears not only because of mouse hovering over the widget, but also when scrolling and when event occurs which is binded to select box that updates the text.

georgtree commented 2 months ago

I think the issue is that UpdateGutter isn't called right after the showModal call, but how to call it right after that if we got into event loop immediately?

georgtree commented 2 months ago

I found the issue, I should update gutter with delay:

after idle [list after 200 "::modelTestVerTool::gui::unifiedTestWin::paveUnifiedTestWin fillGutter $wtxt"]

Thank you for help!

P.S. It's often happens when I solve the problem talking to myself like here...

aplsimple commented 2 months ago

In v4.4.10, I made it more simple. So that the issue is reopen.

The simplification means you can call fillGutter just after the text updated:

.tex insert end $texcont
apave::obj fillGutter .tex

I.e. no "after" command is required. Of course, at a user's manual modifications of the text, its gutter should be updated without troubles. Only the programmatical modifications need the calling fillGutter method, just after them made.

That said, I personally prefer call such updates with "after idle" command. Just to save a user's time.

georgtree commented 2 months ago

Got it, thank you, all works!