Thanks All,
I modified what Marc Tompkins shared and have a working Button Menu
Class
[code]
# Base Class for Button Version of Main Menu
class Menu_Btn(wx.Dialog):
def __init__(self, *args, **kwds):
# begin wxGlade: Menu_2.__init__
kwds["style"] = wx.DEFAULT_DIALOG_STYLE
wx.Dialog.__init__(self, *args, **kwds)
self.label_1 = wx.StaticText(self, -1, " Main Menu For ")
self.UUT_Name = wx.StaticText(self, -1, "Name for UUT")
self.label_2 = wx.StaticText(self, -1, "")
self.button_1 = wx.Button(self, -1, "")
self.command_1 = wx.Button(self, -1, "Rerun Last Module")
self.button_2 = wx.Button(self, -1, "")
self.Alpha_1 = wx.StaticText(self, -1, "")
self.button_3 = wx.Button(self, -1, "")
self.command_2 = wx.Button(self, -1, "Print Ticket")
self.button_4 = wx.Button(self, -1, "")
self.Alpha_2 = wx.StaticText(self, -1, "")
self.button_5 = wx.Button(self, -1, "")
self.command_3 = wx.Button(self, -1, "Next UUT (Same Type)")
self.button_6 = wx.Button(self, -1, "")
self.Alpha_3 = wx.StaticText(self, -1, "")
self.button_7 = wx.Button(self, -1, "")
self.command_4 = wx.Button(self, -1, "Run All Modules End To
End")
self.button_8 = wx.Button(self, -1, "")
self.Alpha_4 = wx.StaticText(self, -1, "")
self.button_9 = wx.Button(self, -1, "")
self.command_5 = wx.Button(self, -1, "View Instrument Set-Up
Instructions")
self.button_10 = wx.Button(self, -1, "")
self.Alpha_5 = wx.StaticText(self, -1, "")
self.button_11 = wx.Button(self, -1, "")
self.command_6 = wx.Button(self, -1, "Access IETM")
self.button_12 = wx.Button(self, -1, "")
self.Alpha_6 = wx.StaticText(self, -1, "")
self.button_13 = wx.Button(self, -1, "")
self.command_7 = wx.Button(self, -1, "EXIT")
self.button_14 = wx.Button(self, -1, "")
self.Alpha_7 = wx.StaticText(self, -1, "")
self.button_15 = wx.Button(self, -1, "")
self.command_8 = wx.Button(self, -1, "Next Menu")
self.button_16 = wx.Button(self, -1, "")
self.Alpha_8 = wx.StaticText(self, -1, "")
self.label_55 = wx.StaticText(self, -1, " Color Code: ")
self.NotRun = wx.StaticText(self, -1, " Not Run ")
self.Passed = wx.StaticText(self, -1, " Passed ")
self.Failed = wx.StaticText(self, -1, " Failed ")
self.NotImp = wx.StaticText(self, -1, " Not Implemented ")
for i in range(16):
self.Bind(wx.EVT_BUTTON, self.OnSelectionClick,
getattr(self, "button_%d" %(i+1)))
for j in range(8):
self.Bind(wx.EVT_BUTTON, self.OnCommandClick,
getattr(self, "command_%d" %(j+1)))
self.__set_properties()
self.__do_layout()
self.UpDateMenu()
# end wxGlade
def __set_properties(self):
# begin wxGlade: Menu_2.__set_properties
self.SetTitle("Main Menu")
self.SetSize((640, 700))
self.SetBackgroundColour(wx.Colour(200, 200, 200))
self.label_1.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL,
wx.NORMAL, 0, ""))
self.UUT_Name.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.button_1.SetMinSize((311, 34))
self.button_1.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.command_1.SetBackgroundColour(wx.Colour(104, 100, 255))
self.command_1.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.button_2.SetMinSize((101, 29))
self.button_2.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Alpha_1.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.NORMAL, 0, ""))
self.button_3.SetMinSize((101, 29))
self.button_3.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.command_2.SetBackgroundColour(wx.Colour(104, 100, 255))
self.command_2.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.button_4.SetMinSize((101, 29))
self.button_4.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Alpha_2.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.NORMAL, 0, ""))
self.button_5.SetMinSize((101, 29))
self.button_5.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.command_3.SetBackgroundColour(wx.Colour(104, 100, 255))
self.command_3.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.button_6.SetMinSize((101, 29))
self.button_6.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Alpha_3.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.NORMAL, 0, ""))
self.button_7.SetMinSize((101, 29))
self.button_7.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.command_4.SetBackgroundColour(wx.Colour(104, 100, 255))
self.command_4.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.button_8.SetMinSize((101, 29))
self.button_8.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Alpha_4.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.NORMAL, 0, ""))
self.button_9.SetMinSize((101, 29))
self.button_9.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.command_5.SetBackgroundColour(wx.Colour(104, 100, 255))
self.command_5.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.button_10.SetMinSize((101, 29))
self.button_10.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Alpha_5.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.NORMAL, 0, ""))
self.button_11.SetMinSize((101, 29))
self.button_11.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.command_6.SetBackgroundColour(wx.Colour(104, 100, 255))
self.command_6.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.button_12.SetMinSize((101, 29))
self.button_12.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Alpha_6.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.NORMAL, 0, ""))
self.button_13.SetMinSize((101, 29))
self.button_13.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.command_7.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.button_14.SetMinSize((101, 29))
self.button_14.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Alpha_7.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.NORMAL, 0, ""))
self.button_15.SetMinSize((101, 29))
self.button_15.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.command_8.SetBackgroundColour(wx.Colour(104, 100, 255))
self.command_8.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.button_16.SetMinSize((101, 29))
self.button_16.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Alpha_8.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.NORMAL, 0, ""))
self.label_55.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.NotRun.SetBackgroundColour(wx.Colour(250, 255, 15))
self.NotRun.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Passed.SetBackgroundColour(wx.Colour(35, 255, 0))
self.Passed.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.Failed.SetBackgroundColour(wx.Colour(255, 30, 0))
self.Failed.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
self.NotImp.SetBackgroundColour(wx.Colour(104, 100, 255))
self.NotImp.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL,
wx.BOLD, 0, ""))
# end wxGlade
def __do_layout(self):
# begin wxGlade: Menu_2.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
grid_sizer_1 = wx.GridSizer(16, 2, 0, 0)
sizer_1.Add(self.label_1, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
sizer_1.Add(self.UUT_Name, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
sizer_1.Add(self.label_2, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_1, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.command_1, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_2, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.Alpha_1, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_3, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.command_2, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_4, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.Alpha_2, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_5, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.command_3, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_6, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.Alpha_3, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_7, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.command_4, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_8, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.Alpha_4, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_9, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.command_5, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_10, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.Alpha_5, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_11, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.command_6, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_12, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.Alpha_6, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_13, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.command_7, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_14, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.Alpha_7, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_15, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.command_8, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_16, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.Alpha_8, 0, wx.EXPAND, 0)
sizer_4.Add(grid_sizer_1, 1, wx.EXPAND, 0)
sizer_3.Add(sizer_4, 1, wx.EXPAND, 0)
sizer_1.Add(sizer_3, 1, wx.EXPAND, 0)
sizer_5.Add(self.label_55, 0, wx.ALIGN_BOTTOM, 0)
sizer_5.Add(self.NotRun, 0, wx.ALIGN_BOTTOM, 0)
sizer_5.Add(self.Passed, 0, 0, 0)
sizer_5.Add(self.Failed, 0, wx.ALIGN_BOTTOM, 0)
sizer_5.Add(self.NotImp, 0, wx.ALIGN_RIGHT, 0)
sizer_1.Add(sizer_5, 0, 0, 0)
self.SetSizer(sizer_1)
self.Layout()
self.Centre()
def OnSelectionClick(self,event):
# print "On Selection Click: " + str(event.GetId())
MenuSelection = (abs(event.GetId()) - 247)/2
print "On Selection Click: " + str(MenuSelection)
if MenuSelection <= int(TC_Config.Test_Modules):
TC_Config.TPS_Status = "Running"
TC_Config.Error_Message = "No Error"
TC_Config.CurrentModule = MenuSelection
self.Hide()
event.Skip()
def OnCommandClick(self, event):
print "On Command Click: " + str(event.GetId())
if event.GetId()==-275:
TC_Config.TPS_Status = "Exit"
self.Destroy()
# Uses the Variables set in TC_Config to setup or refresh the Main
Menu
def UpDateMenu(self):
self.Selection=[]
for i in range(16):
self.Selection.append(getattr(self, "button_%d" %(i+1)) )
self.Selection[i].SetLabel(TC_Config.ModuleName[i])
print TC_Config.ModuleName[i] + " Status: " +
TC_Config.ModuleStatus[i]
if TC_Config.ModuleName[i] != "":
# Set "Yellow" Highlight if "Not Run"
if TC_Config.ModuleStatus[i] == "Not Run":
self.Selection[i].SetBackgroundColour(wx.Colour(255, 255, 0))
# Set "Green" highlight if "Passed"
elif TC_Config.ModuleStatus[i] == "Passed":
self.Selection[i].SetBackgroundColour(wx.Colour(0,
255, 0))
# Set "Red" highlight if "Falied"
elif TC_Config.ModuleStatus[i] == "Failed":
self.Selection[i].SetBackgroundColour(wx.Colour(255, 0, 0))
# end of class Menu_Btn
[/code]
NOTE: The Button Event ID has to be tailored once the Class is in its
correct place in the Application. It was a bit of a shock to see my
Class stop working went I moved it from the text bed into my App. ![:slight_smile: :slight_smile:](/images/emoji/apple/slight_smile.png?v=9)
I am sure that wxGlade adds some stuff that doesn;t need to be there.
And, I am pretty sure most of you guys that have been programming
longer than my four weeks can come up with all sorts of improvements.
Have at ![:slight_smile: :slight_smile:](/images/emoji/apple/slight_smile.png?v=9)
Of course I probably wouldn't understand any of them...
The above code is instantiated by the following code:
[code]
# This is the Master Control Function
def Test_Control(ptf):
# Initialize the UUT and Menu Information
ptf.get("UUT_Info")()
ptf.get("Menu_Info")()
# The False prevents print statements from opening a command
window
app = wx.App(False)
wx.InitAllImageHandlers()
# Create the Logging Screen
LogScrn = Lines_24(None, -1, "")
LogScrn.AddLine("This is the Initial Log Screen Entry: ")
LogScrn.Show()
# Create the initial tcDict Entry
tcDict = {"LogScrn":LogScrn}
# Create the UUT Information Display
# LogScrn.AddLine("Creating UUT Information Display")
UUTInfo = DiaInfoUUT(None, -1, "")
UUTInfo.Man_Name.SetLabel(" " + TC_Config.Man_Name)
UUTInfo.ModNumber.SetLabel(" " + TC_Config.ModNumber)
UUTInfo.MilDesig.SetLabel(" " + TC_Config.MilDesig)
UUTInfo.Nomen.SetLabel(" " + TC_Config.Nomen)
UUTInfo.PartNo.SetLabel(" " + TC_Config.PartNo)
UUTInfo.SerNo.SetLabel(" " + TC_Config.SerNo)
UUTInfo.Revision.SetLabel(" " + TC_Config.Rev)
UUTInfo.ShowModal()
# Create the Main Menu
# Main_Menu = Menu_2(None, -1, "")
Main_Menu = Menu_Btn(None, -1, "")
# Enter the Main Menu Loop
while TC_Config.TPS_Status != "Exit":
LogScrn.AddLine("Creating the Main Menu")
Main_Menu.ShowModal()
if TC_Config.TPS_Status == "Exit":
# Don't leave the Logging Display Orphaned on the Screen
# If exiting from UUT Info
LogScrn.Destroy()
else:
# Always test that it is Safe to turn on before continuing
if TC_Config.STTO == False:
# False try running Safe To Turn On
TC_Config.STTO = ptf.get("SafeToTurnOn")(tcDict)
# Not! elseif because we need to have a separate test
# after we have (re) attempted to run Safe To Turn On
if TC_Config.STTO == True:
LogScrn.AddLine("UUT Passed Safe To Turn On")
ptf.get("Module_Launcher")(tcDict)
Main_Menu.UpDateMenu()
# Don't leave the Logging Display Orphaned on the Screen when menu
Exits
LogScrn.Destroy()
app.MainLoop()
[/code]