In my first post on apps in tabs, I wrote this: There are three parts to these "tabbed" apps:
1. Creating the top-level QWidget; 2. Inserting it into a tab and controlling the tab (e.g., toggling it on and off); 3. Interacting with the app. Instead of "Creating the top-level Widget" I could better have written "Designing the top-level widget". Item 2. is the heart of the tabbed-app approach, and that's what this post is about. To make it work, we have to: 1. Find the log frame; 2. Create a new tab; 3. Insert our top-level QWidget into it; 4. Be able to toggle the tab on and off. Here is how it's done in the demo outline I posted last time. I have inserted explanatory comment into the code. We start with setting up some useful constants: """A log tab panel for demonstrating plotting techniques.""" log = c.frame.log # Get the log frame TABNAME = 'Pyplot' # We will use these constants when we control the tab later WIDGET_NAME = f'{TABNAME}-widget' VISIBLE = f'{TABNAME}-visible' The core of the code is the toggle() function: # The function to toggle the tab on and off. We use the log's # contentsDict to hold our own, private variables, since it # is always going to exist. These private names are very unlikely # to be duplicated by any other tab. def toggle(log): """Create, show, or hide pyplot tab in Log pane. ARGUMENT log -- the log panel object for this outline. """ # Check whether there is a VISIBLE key. If so, # delete the tab and destroy our widget. if log.contentsDict.get(VISIBLE, False): log.deleteTab(TABNAME) log.contentsDict[VISIBLE] = False w = log.contentsDict[WIDGET_NAME] w.disconnect_all() w.deleteLater() del(log.contentsDict[WIDGET_NAME]) else: # Create our widget and embed it in a tab w = PlotWindow() log.createTab(TABNAME, widget = w, createText = False) log.selectTab(TABNAME) log.contentsDict[VISIBLE] = True log.contentsDict[WIDGET_NAME] = w # If this is the first call of toggle(), create our widget's code # This will work for (nearly?) any subclass of QWidget. # Define the widget's class. It will be instantiated when # toggle(log) runs. if not log.contentsDict.get(WIDGET_NAME, None): << Main Widget >> toggle(log) On Thursday, April 13, 2023 at 9:27:39 AM UTC-4 Thomas Passin wrote: > I have re-organized the code a bit to make to easier to read. It does the > same job as before. Also, I have zipped up the outline to make it easier > to get from the browser. > > More to come soon. > > On Sunday, April 9, 2023 at 1:14:13 PM UTC-4 Edward K. Ream wrote: > >> On Sun, Apr 9, 2023 at 7:32 AM Thomas Passin <tbp1...@gmail.com> wrote: >> >>> Remind me what you mean by an "info item". Would this be a GitHub issue >>> with a "devInfo" or "Info" tag? >>> >> >> Exactly. >> >> Edward >> > -- 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/1abc6a9a-5980-4eed-8eee-c56b28cf6f23n%40googlegroups.com.