mac compatibility
parent
12f93c04d2
commit
23a3f27b57
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.pythonPath": "/usr/bin/python3"
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
import wx
|
||||||
|
from wx.adv import Wizard, WizardPageSimple
|
||||||
|
|
||||||
|
class TitlePage(WizardPageSimple):
|
||||||
|
|
||||||
|
def __init__(self, parent, title):
|
||||||
|
WizardPageSimple.__init__(self, parent)
|
||||||
|
|
||||||
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
self.SetSizer(sizer)
|
||||||
|
|
||||||
|
title = wx.StaticText(self, wx.ID_ANY, title)
|
||||||
|
title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
|
||||||
|
sizer.Add(title, 0, wx.ALIGN_CENTER|wx.ALL, 5)
|
||||||
|
sizer.Add(wx.StaticLine(self, wx.ID_ANY), 0, wx.EXPAND|wx.ALL, 5)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
wizard = Wizard(None, wx.ID_ANY, "Simple Wizard")
|
||||||
|
page1 = TitlePage(wizard, "Page 1")
|
||||||
|
page2 = TitlePage(wizard, "Page 2")
|
||||||
|
page3 = TitlePage(wizard, "Page 3")
|
||||||
|
|
||||||
|
WizardPageSimple.Chain(page1, page2)
|
||||||
|
WizardPageSimple.Chain(page2, page3)
|
||||||
|
wizard.FitToPage(page1)
|
||||||
|
|
||||||
|
wizard.RunWizard(page1)
|
||||||
|
wizard.Destroy()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = wx.App()
|
||||||
|
main()
|
||||||
|
app.MainLoop()
|
@ -0,0 +1,111 @@
|
|||||||
|
import wx
|
||||||
|
########################################################################
|
||||||
|
class WizardPage(wx.Panel):
|
||||||
|
""""""
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def __init__(self, parent, title=None):
|
||||||
|
"""Constructor"""
|
||||||
|
wx.Panel.__init__(self, parent)
|
||||||
|
|
||||||
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
self.SetSizer(sizer)
|
||||||
|
|
||||||
|
if title:
|
||||||
|
title = wx.StaticText(self, -1, title)
|
||||||
|
title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
|
||||||
|
sizer.Add(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
|
||||||
|
sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.ALL, 5)
|
||||||
|
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
class WizardPanel(wx.Panel):
|
||||||
|
""""""
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def __init__(self, parent):
|
||||||
|
"""Constructor"""
|
||||||
|
wx.Panel.__init__(self, parent=parent)
|
||||||
|
self.pages = []
|
||||||
|
self.page_num = 0
|
||||||
|
|
||||||
|
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
self.panelSizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
|
||||||
|
# add prev/next buttons
|
||||||
|
self.prevBtn = wx.Button(self, label="Previous")
|
||||||
|
self.prevBtn.Bind(wx.EVT_BUTTON, self.onPrev)
|
||||||
|
btnSizer.Add(self.prevBtn, 0, wx.ALL|wx.ALIGN_RIGHT, 5)
|
||||||
|
|
||||||
|
self.nextBtn = wx.Button(self, label="Next")
|
||||||
|
self.nextBtn.Bind(wx.EVT_BUTTON, self.onNext)
|
||||||
|
btnSizer.Add(self.nextBtn, 0, wx.ALL|wx.ALIGN_RIGHT, 5)
|
||||||
|
|
||||||
|
# finish layout
|
||||||
|
self.mainSizer.Add(self.panelSizer, 1, wx.EXPAND)
|
||||||
|
self.mainSizer.Add(btnSizer, 0, wx.ALIGN_RIGHT)
|
||||||
|
self.SetSizer(self.mainSizer)
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def addPage(self, title=None):
|
||||||
|
""""""
|
||||||
|
panel = WizardPage(self, title)
|
||||||
|
self.panelSizer.Add(panel, 2, wx.EXPAND)
|
||||||
|
self.pages.append(panel)
|
||||||
|
if len(self.pages) > 1:
|
||||||
|
# hide all panels after the first one
|
||||||
|
panel.Hide()
|
||||||
|
self.Layout()
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def onNext(self, event):
|
||||||
|
""""""
|
||||||
|
pageCount = len(self.pages)
|
||||||
|
if pageCount-1 != self.page_num:
|
||||||
|
self.pages[self.page_num].Hide()
|
||||||
|
self.page_num += 1
|
||||||
|
self.pages[self.page_num].Show()
|
||||||
|
self.panelSizer.Layout()
|
||||||
|
else:
|
||||||
|
print("End of pages!")
|
||||||
|
|
||||||
|
if self.nextBtn.GetLabel() == "Finish":
|
||||||
|
# close the app
|
||||||
|
self.GetParent().Close()
|
||||||
|
|
||||||
|
if pageCount == self.page_num+1:
|
||||||
|
# change label
|
||||||
|
self.nextBtn.SetLabel("Finish")
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def onPrev(self, event):
|
||||||
|
""""""
|
||||||
|
pageCount = len(self.pages)
|
||||||
|
if self.page_num-1 != -1:
|
||||||
|
self.pages[self.page_num].Hide()
|
||||||
|
self.page_num -= 1
|
||||||
|
self.pages[self.page_num].Show()
|
||||||
|
self.panelSizer.Layout()
|
||||||
|
else:
|
||||||
|
print("You're already on the first page!")
|
||||||
|
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
class MainFrame(wx.Frame):
|
||||||
|
""""""
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def __init__(self):
|
||||||
|
"""Constructor"""
|
||||||
|
wx.Frame.__init__(self, None, title="Generic Wizard", size=(800,600))
|
||||||
|
|
||||||
|
self.panel = WizardPanel(self)
|
||||||
|
self.panel.addPage("Page 1")
|
||||||
|
self.panel.addPage("Page 2")
|
||||||
|
self.panel.addPage("Page 3")
|
||||||
|
|
||||||
|
self.Show()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = wx.App()
|
||||||
|
frame = MainFrame()
|
||||||
|
app.MainLoop()
|
Loading…
Reference in New Issue