heres a small sample as i promised. it won't run becuase i chopped out as much as i could to cut the size down.
···
################################################################################
#Main module, holds window and app information
################################################################################
import wx
import wx.lib.rcsizer as rcs
#Create ID's for buttons and menus
mID_CREATE_REPORTS = wx.NewId()
class MainFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size = (1024,768))
#setup login screen
LoginPanel = wx.Panel(self, -1)
#make refference so i can destroy outside of __init__
self.LoginPanel = LoginPanel
self.CurrentPanel = LoginPanel
self.UserName = wx.TextCtrl(LoginPanel, 0,)
self.UserName.SetFocus()
self.PassWord = wx.TextCtrl(LoginPanel,0, style = wx.TE_PASSWORD)
LoginButton = wx.Button(LoginPanel, bID_LOGIN_BUTTON, 'Login')
wx.EVT_BUTTON(self, bID_LOGIN_BUTTON, self.ValidateLogin)
#setup grid sizer
LoginGrid = rcs.RowColSizer()
LoginGrid.Add(self.UserName, col=0, row=0)
LoginGrid.Add(self.PassWord, col=0, row=1)
LoginGrid.Add(LoginButton, col=0, row=2)
#Setup layout contsraints
LoginLayout = wx.LayoutConstraints()
LoginLayout.top.SameAs(self, wx.Top, 100)
LoginLayout.bottom.SameAs(self, wx.Bottom, 10)
LoginLayout.left.SameAs(self, wx.Left, 10)
LoginLayout.right.SameAs(self, wx.Right, 10)
LoginButton.SetConstraints(LoginLayout)
#setup panel sizer
LoginSizer = wx.GridSizer(1,1)
LoginSizer.Add(LoginGrid,1,wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL)
LoginPanel.SetSizer(LoginSizer)
LoginPanel.Layout()
def ValidateLogin(self, evt_button):
#####CALL DATABASE USERS HERE THE FOLLOWING IS ONLY FOR TESTING
self.UserNameValue = self.UserName.GetValue()
self.PassWordValue = self.PassWord.GetValue()
Successful = 'true'
if Successful == 'true':
self.CurrentPanel.Destroy()
self.ShowMainFrameItems()
else:
Warning = wx.MessageDialog(self, 'Invalid Username or Password', 'Input Error' , wx.OK)
Warning.ShowModal()
Warning.Destroy()
def ShowMainFrameItems(self): #create title panel
WelcomePanel = wx.Panel(self, -1)
self.WelcomePanel = WelcomePanel
self.CurrentPanel = WelcomePanel
#Create status bar
self.CreateStatusBar()
MenuItems = ["Create Reports"]
MenuList = ["Reports"]
####################TO ADD MORE MENU ITEMS################
#list containing menu item text and it's ID
MenuItemIDs = {'Create Reports': mID_CREATE_REPORTS,
'Weekly': mID_WEEKLY_ENTRY,
'Daily': mID_DAILY_ENTRY}
MenuItemsDict = { 'Create Reports' : 'Reports',
'Weekly' : 'Entry',
'Daily': 'Entry'}
#Make menu items
ReportMenu = wx.Menu()
EntriesMenu = wx.Menu()
for item in MenuItems:
for menuitem, menu in MenuItemsDict.items():
if item[0] == menuitem:
#when we find an item with a corrisponding menu, append it
if menu == 'Reports':
ReportMenu.Append(MenuItemIDs[menuitem], menuitem)
if menu == 'Entry':
EntriesMenu.Append(MenuItemIDs[menuitem], menuitem)
#####################TO ADD MORE MENU ITEMS###############
#####################TO ADD MORE MENUS################## #dictionary of Menu's and their function names and text
MenusDict = {'Reports' : ReportMenu,
'Entry' : EntriesMenu}
#####################TO ADD MORE MENUS##################
#Make menu bar to hold all our Menu items
Menu = wx.MenuBar()
for menu in MenuList:
Menu.Append(MenusDict[menu[0]], menu[0])
#Set the menu bar
self.SetMenuBar(Menu)
#Create event handlers to make menu items do something
wx.EVT_MENU(self, mID_CREATE_REPORTS, self.ReportPanel)
def ReportPanel(self, EvtMenu):
"""This creates the panel which allows report options to be specified"""
self.CurrentPanel.Destroy()
ReportPanel = wx.Panel(self, -1)
self.ReportPanel = ReportPanel
self.CurrentPanel = ReportPanel
#setup gridbag sizer for information Report layout
ReportGrid = rcs.RowColSizer()
ReportGrid.Add(wx.StaticText(ReportPanel, -1, "REPORTS"), flag=wx.ALIGN_CENTER, pos=(0,1), colspan=5)
#make panel sizer and layout panel items
ReportSizer = wx.GridSizer(1,1)
ReportSizer.Add(ReportGrid,1,wx.ALIGN_CENTER_HORIZONTAL)
ReportPanel.SetSizer(ReportSizer)
ReportPanel.Layout()
ReportPanel.Fit()
class PubWareApp(wx.App):
"""This class is the application handle for wxPython"""
def OnInit(self):
frame = MainFrame(None, -1, 'PubWare - Hospitality reporting tool')
frame.Show(True)
return True
def Main():
"""Main function, the last thing to run, runs
the wxPython application in a loop"""
PubWareApp().MainLoop()
Main()