I'm writing a script button in which I want to transform some outline data
into html and then display that html in a leo doc. The viewrendered
functionality doesn't seem to really fit my needs as the render pane output
is tied to whatever node is currently selected.

I just want to be able to display the html "on-demand" (i.e. through script
button click) and refresh it on-demand.

I have working code for it, but it requires storing the dock object
somewhere so it can be used again the next time the script is called. I was
wondering if there is some good, already-established convention for storing
"global" state for scripts.

In my case, the variable makes sense to be on a per-commander basis, so I
just stored my information on the commander 'c'. That doesn't seem very
clean to me and I was wondering if there is a better approach?

Here is my function which stores and uses global state on c:

def display_widget_in_leo_pane(c, w, name):
    """
        w is the widget to display
        name is the name the widget should appear in pane menu
    """
    dw = c.frame.top
    if not hasattr(c, '*my_docks*'): c.my_docks = {}
    dock = c.*my_docks*.get(name)
    if not dock:
        dock = g.app.gui.create_dock_widget(
                 closeable=True, moveable=True, height=50, name=name)
        c.*my_docks*[name] = dock
        dw.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)
    dock.setWidget(w)
    dock.show()


And a function to use the above:

def display_html(html, name = 'test html'):
    w = QtWidgets.QTextBrowser()
    w.setHtml(html)
    display_widget_in_leo_pane(c, w, name)

Also, could someone comment on whether the above code is "leaking" widgets?
Should I be calling dock.widget() to retrieve the old widget each time to
perform some sort of delete/cleanup?

Brian

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAO5X8CyrW7Uy7aaN_eMPiHu3FR1ay3o8PVAgLRb7OmGzscPRZw%40mail.gmail.com.

Reply via email to