What can I do in case when no observer to fire? (Pages/Scenes)

Situation:
I want to detect (among others) when a user changes of the properties of a page (Scene) and update my HtmlDialog if it is visible.
image

The problem is that I can’t really find an Observer that can be used.

@DanRathbun has already summarized the good part of my situation very well here, so I won’t repeat it:

As a matter of fact, changes to the above mentioned properties are not currently detectable through the Ruby API.

I have some ideas for workarounds, but none of them seems an ideal:

  1. Open HtmlDialog as a modal dialog.
    So the user has no chance to change…problem solved …Easy :slight_smile:
    Of course, this would all lose the purpose of my dialog to interact or see the information as long as the user is using other tools or operation. So, I do not really like it.

  2. I will instruct the user (RTFM :-)) to update the data (press a button) if they feel that the changes made may affect the data in the dialog.
    This is not elegant at all.

  3. After I open the HtmlDialog, I start a timer (1-5 sec) that periodically collects and sends the changes to the dialog. Then, when the dialog closes, of course I also stop the timer and sending data’s.
    I don’t know how stressful is this for Ruby engine, but sure the dialog will flicker less or more… periodically. (And can be conflicting with the operation what the user is doing inside the HtmlDialog exactly the same time when the updated data arriving …)

  4. After I open the HtmlDialog, I will detect (JavaScript) if the mouse cursor enter or leave the dialog, then send a callback to SU accordingly to update the data.
    The point is, that I can not be perfectly define what the “accordingly” can be in details…

So, what other ideas or comments are there?
Please share your thoughts!

(4) is preferable to using a timer as in (3). Besides if the mouse cursor is inside the dialog, they cannot be making manual changes to the Scenes inspector.


You can also use a mouse over event of the description element to check and update that 1 data item as it 's changes do not fire any observers at all.


Otherwise you will need to cache all values for each page and do comparisons for #onContentsModified as explained in my last post:

PagesObserver#onPageUpdate() observer callback · Issue #26 · SketchUp/api-issue-tracker · GitHub

… and …

Add observer event to detect active scene change · Issue #237 · SketchUp/api-issue-tracker · GitHub


You might have a toggle switch to control (3)'s timer when it interferes with other modeling operations.

But you should only update what changes and only update the values of HTML elements, not redraw the entire page which will cause flickering.

1 Like

Thanks, Dan!

Sounds very reasonable to combine (3) & (4). In my tests, flickering only noticeable when the focus on the dialog and pushing data periodically. If the user working on the model or on SU native UI, update some Html elements (even entirely Html page) every 2 seconds flickering is not visible.

I will check you other suggestion too. :+1: