Thanks, this looks very interesting...
I have one question - something I have wondered about before. If I have
your example code as a button command, say ... then where/how can I put the
def toggle_app_tab(log, tabname, top_widget):
# ...
code, in order for it to accessible by multiple such buttons/commands? I've
never been sure about this.
Thanks, J^n
On Sunday, October 30, 2022 at 3:09:26 PM UTC [email protected] wrote:
> I have made several apps (really, "applets") to run in tabs in Leo's Log
> frame. I find this convenient because they don't need to take up a whole
> panel, as Viewrendered/Viewrendered3 do, and they don't even need to be
> plugins so they can be simpler. They are mostly intended to be used in a
> specific outline; their code can reside in the outline.
>
> I wanted to share how I open these apps in the Log frame. Since they are
> not plugins, they don't load automatically when Leo starts. I don't find
> that to be a problem, since it's easy to provide a Leo command, button, or
> menu item to open them when you want to use them.
>
> I open a tabbed app with the following command:
>
> def toggle_app_tab(log, tabname, top_widget):
> """Create or remove our app's tab.
>
> ARGUMENTS
> log -- the log panel object for this outline.
> tabname -- a string to use as the display name of our tab.
> top_widget -- an instance of top level widget of our app.
> """
> # If our tab is visible, remove it
> if log.contentsDict.get(f'{tabname}-visible', False):
> log.deleteTab(tabname)
> log.contentsDict[f'{tabname}-visible'] = False
> else:
> # Show our tab, reusing our widget if already loaded
> if log.contentsDict.get(f'{tabname}-loaded', False):
> log.createTab(tabname,
> widget = log.contentsDict[f'{tabname}-widget'],
> createText = False)
> log.contentsDict[f'{tabname}-visible'] = True
> log.selectTab(tabname)
> else:
> # Create our tab for the first time
> log.createTab(tabname, widget = w,
> createText = False)
> log.selectTab(tabname)
> log.contentsDict[f'{tabname}-loaded'] = True
> log.contentsDict[f'{tabname}-visible'] = True
> log.contentsDict[f'{tabname}-widget'] = w
>
> By "widget", I mean a PyQt widget. It will usually contain other GUI
> widgets and code. Here's how this function would typically be called. The
> widget does not need to have the signature shown here, but it's an obvious
> way to get Leo's key objects into the app.
>
> log = c.frame.log
> TABNAME = 'The App'
> import theApp
> w = theApp.MainWidget(g, c)
> toggle_app_tab(log, TABNAME, w)
>
> Notice that when we "remove" the app - meaning the app's tab is removed
> from the Log frame - we keep a reference to the main widget. This way,
> when we make the tab visible again, the app will have retained all its
> state and you can pick up where you left off.
>
> I have attached a screen shot of one of my tabbed apps in session.
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/3b9b231b-220f-4d95-8f65-ff89f6ff24d5n%40googlegroups.com.