0

I have a WXnotebook that has different number of tabs depending on the amount of information that the program pulls. My goal is to take a screenshot of the information displayed by each tab and store those images. Im having a problem with the program going through the tabs. I was thinking maybe something like

         for i in range(numOfTabs):
            self.waferTab.ChangeSelection(i)
            time.sleep(3)

but this only shows me the last tab in the wxnotebook. If anybody knows anyway of getting this i'd really appreciate it.

EDIT

so I tried the following like suggested below but the GUI shows up but when it shows up It looks like it already iterated through the whole loop and displays the selection is the last tab I still cant see the screen actually going through the tabs

          for i in range(numOfTabs):
            self.waferTab.SetSelection(i)
            Refresh
            wx.SafeYield()
            time.sleep(10)
Jeff Pernia
  • 79
  • 1
  • 13
  • `ChangeSelection` is the right function to change the selected page in a wx.Notebook. Your problem likely is somewhere else, but you don't show enough code so as to search for it. – Ripi2 Oct 17 '18 at 16:39
  • the other lines on my code just help display the information into the tabs. I want to show the first tab then after 3 seconds show the 2nd tab and so on – Jeff Pernia Oct 17 '18 at 16:46
  • @JeffPernia, can you make a script sleep for 1 minute? Or instead of looping just call `self.waferTab.ChangeSelection( 1 )`? – Igor Oct 17 '18 at 16:48
  • Try using `SetSelection` instead. If the GUI is not updated automatically then use `Refresh` – Ripi2 Oct 17 '18 at 16:49
  • I know that is actually looping through it because when the GUI actually pops up it displays the last tab like it should but im unable to see the program actually going through the tabs all – Jeff Pernia Oct 17 '18 at 18:49
  • Try `wx.SafeYield` between `Refresh` and `time.sleep` so the GUI has a chance for updating. – Ripi2 Oct 17 '18 at 19:17
  • I edited my original post trying to do what you suggested not sure if that's what you meant @Ripi2 – Jeff Pernia Oct 17 '18 at 19:44
  • `time.sleep` may terminate early (see [doc](https://docs.python.org/3/library/time.html)). So if you want to see slow page-next page changes use a `wx.Timer` and react at each timer fire. – Ripi2 Oct 17 '18 at 19:51

1 Answers1

1

I don't know why you would want to do this as it seems like a confusing interface for a user to use, but here's an example using a wx.Timer:

import random
import wx


class TabPanel(wx.Panel):

    def __init__(self, parent):
        """"""
        wx.Panel.__init__(self, parent=parent)

        colors = ["red", "blue", "gray", "yellow", "green"]
        self.SetBackgroundColour(random.choice(colors))

        btn = wx.Button(self, label="Press Me")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(btn, 0, wx.ALL, 10)
        self.SetSizer(sizer)


class DemoFrame(wx.Frame):
    """
    Frame that holds all other widgets
    """

    def __init__(self):
        """Constructor"""        
        wx.Frame.__init__(self, None, wx.ID_ANY, 
                          "Notebook Tutorial",
                          size=(600,400)
                          )
        panel = wx.Panel(self)
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.change_tabs, self.timer)
        self.timer.Start(1000)

        self.notebook = wx.Notebook(panel)
        tabOne = TabPanel(self.notebook)
        self.notebook.AddPage(tabOne, "Tab 1")

        tabTwo = TabPanel(self.notebook)
        self.notebook.AddPage(tabTwo, "Tab 2")

        tabThree = TabPanel(self.notebook)
        self.notebook.AddPage(tabThree, 'Tab 3')

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.notebook, 1, wx.ALL|wx.EXPAND, 5)
        panel.SetSizer(sizer)
        self.Layout()

        self.Show()

    def change_tabs(self, event):
        current_selection = self.notebook.GetSelection()
        print(current_selection)
        pages = self.notebook.GetPageCount()
        if current_selection + 1 == pages:
            self.notebook.ChangeSelection(0)
        else:
            self.notebook.ChangeSelection(current_selection + 1)


if __name__ == "__main__":
    app = wx.App(True)
    frame = DemoFrame()
    app.MainLoop()

You could also use a Thread and use something like wx.CallAfter to update your UI, but I think a timer makes more sense in this case.

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88