Hi all,
I'm watching the Treebook example of demo application, but I don't understand how I can put different control into different page and sub-page.
Now all widgets are share to all sub-page, I don't understand if is possible (I think that there is a way but I'm a newbie) that all page and sub-page have different control like statictext or textctrl.
My code:
#!/usr/bin/env python
import wx
#import images
···
#----------------------------------------------------------------------------
#def getNextImageID(count):
# imID = 0
# while True:
# yield imID
# imID += 1
# if imID == count:
# imID = 0
class ColoredPanel(wx.Window):
def __init__(self, parent, color):
wx.Window.__init__(self, parent, -1, style = wx.SIMPLE_BORDER)
self.SetBackgroundColour(color)
if wx.Platform == '__WXGTK__':
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
class TestTB(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Test Treebook')
#Get some inputs information
self.num_linea = []
self.i = 0
self.createMenuBar()
self.CreateStatusBar()
self.SetStatusText('Application ready...')
self.RagioneSociale()
self.NumeroLinea()
self.TipoServizio()
self.TipoLinea()
#Create GUI
self.colourList = [self.rag_soc]
self.tb = wx.Treebook(self, id, style=wx.BK_DEFAULT)
self.TreeBook()
#self.log = log
# make an image list using the LBXX images
#il = wx.ImageList(32, 32)
#for x in range(12):
# f = getattr(images, 'getLB%02dBitmap' % (x+1))
# bmp = f()
# il.Add(bmp)
#self.AssignImageList(il)
#imageIdGenerator = getNextImageID(il.GetImageCount())
# Now make a bunch of panels for the list book
#first = True
#self.Bind(wx.EVT_TREEBOOK_PAGE_CHANGED, self.OnPageChanged)
#self.Bind(wx.EVT_TREEBOOK_PAGE_CHANGING, self.OnPageChanging)
def TreeBook(self):
for self.colour in self.colourList:
win = self.makeColorPanel(self.colour)
self.tb.AddPage(win, self.colour)#, imageId=imageIdGenerator.next())
self.st = wx.StaticText(win.win, -1, "This is a page", (10,10))
self.TreeBookSubPage()
#if first:
# st = wx.StaticText(self.tb, -1,'Pippo', wx.Point(10, 10))
# first = False
def TreeBookSubPage(self):
win_sub = self.makeColorPanel(self.colour)
self.tb.AddPage(win_sub, self.num_linea[self.i])#, imageId=imageIdGenerator.next())
self.tb.AddSubPage(win_sub, 'Canone attuale')
self.sta = wx.StaticText(win_sub.win, -1, "Pippo", (10,50))
self.tb.AddSubPage(win_sub, 'Canone MR')
self.stc = wx.TextCtrl(win_sub.win, -1, "Sub Page", (10,10))
# This is a workaround for a sizing bug on Mac...
wx.FutureCall(100, self.AdjustSize)
def AdjustSize(self):
#print self.GetTreeCtrl().GetBestSize()
self.tb.GetTreeCtrl().InvalidateBestSize()
self.tb.SendSizeEvent()
#print self.GetTreeCtrl().GetBestSize()
def makeColorPanel(self, color):
p = wx.Panel(self.tb, -1)
win = ColoredPanel(p, color)
p.win = win
def OnCPSize(evt, win=win):
win.SetPosition((0,0))
win.SetSize(evt.GetSize())
p.Bind(wx.EVT_SIZE, OnCPSize)
return p
#def OnPageChanged(self, event):
# old = event.GetOldSelection()
# new = event.GetSelection()
# sel = self.tb.GetSelection()
#self.log.write('OnPageChanged, old:%d, new:%d, sel:%d\n' % (old, new, sel))
# event.Skip()
#def OnPageChanging(self, event):
# old = event.GetOldSelection()
# new = event.GetSelection()
# sel = self.tb.GetSelection()
#self.log.write('OnPageChanging, old:%d, new:%d, sel:%d\n' % (old, new, sel))
# event.Skip()
def RagioneSociale(self):
dialog = wx.TextEntryDialog(None, 'Inserire la ragione sociale del cliente', 'Advising text entry',
'Ragione Sociale', style = wx.OK|wx.CANCEL)
if dialog.ShowModal() == wx.ID_OK:
self.rag_soc = dialog.GetValue()
else:
self.rag_soc = 'Ragione Sociale'
dialog.Destroy()
def NumeroLinea(self):
dialog = wx.TextEntryDialog(None, 'Inserire il numero della linea urbana', 'Advising text entry',
'Numero urbano', style = wx.OK|wx.CANCEL)
if dialog.ShowModal() == wx.ID_OK:
self.num_linea.append(dialog.GetValue())
else:
self.num_linea.append('Numero Linea')
dialog.Destroy()
def TipoServizio(self):
choices = ['Fonia','Dati']
dialog = wx.SingleChoiceDialog(None, 'Seleziona il tipo di servizio', 'Advising text entry',
choices)
if dialog.ShowModal() == wx.ID_OK:
self.tipo_serv = dialog.GetStringSelection()
print self.tipo_serv
dialog.Destroy()
def TipoLinea(self):
if self.tipo_serv == 'Fonia':
self.LineaFonia()
if self.tipo_serv == 'Dati':
self.LineaDati()
def LineaFonia(self):
choices = ['Analogica', 'ISDN', 'PRI']
dialog = wx.SingleChoiceDialog(None, 'Seleziona il tipo di linea', 'Advising text entry',
choices)
if dialog.ShowModal() == wx.ID_OK:
self.tipo_linea = dialog.GetStringSelection()
print self.tipo_linea
dialog.Destroy()
def LineaDati(self):
choices = ['ADSL', 'HDSL', 'CDN']
dialog = wx.SingleChoiceDialog(None, 'Seleziona il tipo di linea', 'Advising text entry',
choices)
if dialog.ShowModal() == wx.ID_OK:
self.tipo_linea = dialog.GetStringSelection()
print self.tipo_linea
dialog.Destroy()
def menuData(self):
return (('&File',
('&Open\tCtrl+O', 'Open a saved file', self.OnOpen),
('&New\tCtrl+N', 'New line description', self.OnNew),
('', '', ''),
('&Quit\tCtrl+Q', 'Quit application', self.OnCloseWindow)),
('&Edit',
('&Copy\tCtrl+C', 'Copy', self.OnCopy),
('C&ut\tCtrl+X', 'Cut', self.OnCut),
('&Paste\tCtrl+P', 'Paste', self.OnPaste),
('', '', ''),
('O&ption\tCtrl+T', 'Display Option', self.OnOptions)),
('&Help',
('&About\tCtrl+A', 'About Advising applcation', self.OnAbout)))
def createMenuBar(self):
menuBar = wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel = eachMenuData[0]
menuItems = eachMenuData[1:]
menuBar.Append(self.createMenu(menuItems), menuLabel)
self.SetMenuBar(menuBar)
def createMenu(self, menuData):
menu = wx.Menu()
for eachLabel, eachStatus, eachHandler in menuData:
if not eachLabel:
menu.AppendSeparator()
continue
menuItem = menu.Append(-1, eachLabel, eachStatus)
self.Bind(wx.EVT_MENU, eachHandler, menuItem)
return menu
def OnNew(self, event):
self.i = self.i + 1
self.NumeroLinea()
self.TreeBookSubPage()
self.TipoServizio()
self.TipoLinea()
def OnOpen(self, event): pass
def OnCopy(self, event): print self.num_linea
def OnCut(self, event): pass
def OnPaste(self, event): pass
def OnOptions(self, event): pass
def OnAbout(self, event): pass
def OnCloseWindow(self, event):
self.Destroy()
class MyApp(wx.App):
def OnInit(self):
self.frame = TestTB(parent=None, id=-1)
self.frame.SetSize((800,600))
self.frame.SetIcon(wx.Icon('ubuntu_logo.png', wx.BITMAP_TYPE_PNG))
self.frame.Center()
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == '__main__':
app = MyApp()
app.MainLoop()
--------------------------------------------------------
Thanks a lot
Andrea