Disable While Hidden

Smallworld™ uses tabboxes to present overlapping GUIs. The tabboxes provide easy access for the users to these GUIs.
To maintain a good performance it is important that the tabs that are not selected, not on top, do not use up processing power. In practice that means that the hidden tabs should not react to changes in the database, events in the map or tokens on the databus.
The best way to keep track of the visibility of the plugin is by using the visible_notify_selector.
You should set the selector when building the gui, like this:

_pragma(classify_level=basic, topic={demo})
_method supply_point_embed_plugin.build_gui(p_container)
    _local dialog << supply_point_info_model.new(_self)
    _local gui << dialog.build_embedded_gui(p_container)
    gui.tab_label << dialog.title

    _self.cache_dialog(:the_dialog, dialog)

    # defines the handler to invoke when self becomes
    # visible. Initialise self as invisible.
    gui.visible_notify_selector << handler.new(_self, :|handle_gui_visibility()|)

    _return gui

When the panel becomes visible (or hidden) the handler is invoked. If the plugin became visible then it should attach to the databus, start observing the database, listen to the map, etc. If the plugin became hidden it should disconnect. Something like this:
_pragma(classify_level=restricted, topic={demo})
_method supply_point_embed_plugin.handle_gui_visibility(p_visible?)
    ## Callback method when the visibility changes.
    _if p_visible? _is _true

There are plenty of examples of methods named handle_gui_visibility() in the core application.
If you are interested in the topic, an example plugin named supply_point_embed_plugin is attached for further reading. sleep_while_hidden.zip
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License