i can make the comboboxes self. so as to collect the selections but I have this error when trying to do same for text box
NameError: global name 'inputTxtOne' is not defined
import wx
#import easygui
#import pyExcelerator
#import xlrd
import MySQLdb
#import psycopg2
db = MySQLdb.connect(user="root", passwd="", db="automate-cisss")
cursor = db.cursor()
cursor.execute("""SELECT DISTINCT r.`Runtype` FROM runtype r;""")
runtypes = [item[0] for item in cursor.fetchall()]
cursor.execute("""SELECT DISTINCT e.`Environment Name` FROM environments e;""")
envs = [item[0] for item in cursor.fetchall()]
cursor.execute("""SELECT DISTINCT a.`AUT` FROM `application under test` a;""")
AUT = [item[0] for item in cursor.fetchall()]
cursor.execute("""SELECT DISTINCT p.`Phase` FROM `phase` p;""")
phases = [item[0] for item in cursor.fetchall()]
#wb = xlrd.open_workbook('C:\Data\CISSS\Resources\UserIDPassword.xls')
#sh = wb.sheet_by_name(u'Sheet1')
#authors = [sh.cell(rowx=0,colx=1).value, sh.cell(rowx=1,colx=1).value ]
#book = pyExcelerator.parse_xls("C:\Data\CISSS\Resources\UserIDPassword.xls")
#data = book[0][1]
#envs = [sh.cell(rowx=0,colx=1).value, sh.cell(rowx=1,colx=1).value ]
class MyForm(wx.Frame):
def __init__(self):
self.runs = self.frame = wx.Frame.__init__(self, None, wx.ID_ANY, title='My Form')
font1 = wx.Font(14, wx.DECORATIVE, wx.NORMAL, wx.BOLD, False, u'Arial')
# Add a panel so it looks correct on all platforms
self.panel = wx.Panel(self, wx.ID_ANY)
bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (16, 16))
titleIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
title = wx.StaticText(self.panel, wx.ID_ANY, 'Enter Automation Run Details')
title.SetFont(font1)
bmp = wx.ArtProvider.GetBitmap(wx.ART_HELP, wx.ART_OTHER, (16, 16))
# select Application under test
inputOneIcoAUT = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
labelOneAUT = wx.StaticText(self.panel, wx.ID_ANY, 'Select AUT')
#inputTxtOne1 = wx.TextCtrl(self.panel, wx.ID_ANY,'')
self.cbAUT = wx.ComboBox(self.panel, -1, pos=(50, 70), size=(150, -1),
choices=AUT, style=wx.CB_READONLY)
self.cbAUT.Bind(wx.EVT_COMBOBOX, self.OnSelect)
# select Run Typr
inputOneIcoruntype = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
labelOneruntype = wx.StaticText(self.panel, wx.ID_ANY, 'Select Run Type')
self.cbruntype = wx.ComboBox(self.panel, -1, pos=(50, 70), size=(150, -1),
choices=runtypes, style=wx.CB_READONLY)
self.cbruntype.Bind(wx.EVT_COMBOBOX, self.OnSelect)
inputOneIcoenvs = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
# select Run Environment
labelOneenvs = wx.StaticText(self.panel, wx.ID_ANY, 'Select Run Environment')
self.cbenvs = wx.ComboBox(self.panel, -1, pos=(50, 70), size=(150, -1),
choices=envs, style=wx.CB_READONLY)
self.cbenvs.Bind(wx.EVT_COMBOBOX, self.OnSelect)
# Select Release Phase
inputOneIcophases = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
labelOnephases = wx.StaticText(self.panel, wx.ID_ANY, 'Select Phase')
self.cbphases = wx.ComboBox(self.panel, -1, pos=(50, 70), size=(150, -1),
choices=phases, style=wx.CB_READONLY)
self.cbphases.Bind(wx.EVT_COMBOBOX, self.OnSelect)
# Select Starting point
inputOneIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
labelOne = wx.StaticText(self.panel, wx.ID_ANY, 'Starting point. Press OK to accept or type new start point. Include Header Row')
self.inputTxtOne = wx.TextCtrl(self.panel, wx.ID_ANY,'2')
# Select End Point
inputTwoIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
labelTwo = wx.StaticText(self.panel, wx.ID_ANY, 'Ending point. Press OK to accept or type new end point.')
inputTxtTwo = wx.TextCtrl(self.panel, wx.ID_ANY,'99')
# Select Scheduled Start Time
inputThreeIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
labelThree = wx.StaticText(self.panel, wx.ID_ANY, 'Starting at what hour? - e.g. for tomorrow at 6 then just enter 6, 24 hour clock. For immediate start just accept (please note 99 should display). Press OK to accept .')
labelThree.Wrap(700)
inputTxtThree = wx.TextCtrl(self.panel, wx.ID_ANY, '99')
okBtn = wx.Button(self.panel, wx.ID_ANY, 'OK')
cancelBtn = wx.Button(self.panel, wx.ID_ANY, 'Cancel')
self.Bind(wx.EVT_BUTTON, self.onOK, okBtn)
self.Bind(wx.EVT_BUTTON, self.onCancel, cancelBtn)
topSizer = wx.BoxSizer(wx.VERTICAL)
titleSizer = wx.BoxSizer(wx.HORIZONTAL)
gridSizer = wx.GridSizer(rows=7, cols=2, hgap=5, vgap=5)
inputOneSizer1 = wx.BoxSizer(wx.HORIZONTAL)
inputOneSizerruntype = wx.BoxSizer(wx.HORIZONTAL)
inputOneSizerenvs = wx.BoxSizer(wx.HORIZONTAL)
inputOneSizerphases = wx.BoxSizer(wx.HORIZONTAL)
inputOneSizer = wx.BoxSizer(wx.HORIZONTAL)
#inputOneSizer = wx.BoxSizer(wx.HORIZONTAL)
inputTwoSizer = wx.BoxSizer(wx.HORIZONTAL)
inputThreeSizer = wx.BoxSizer(wx.HORIZONTAL)
#inputFourSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
titleSizer.Add(titleIco, 0, wx.ALL, 5)
titleSizer.Add(title, 0, wx.ALL, 5)
# each input sizer will contain 3 items
# A spacer (proportion=1),
# A bitmap (proportion=0),
# and a label (proportion=0)
···
#
inputOneSizer1.Add((20,20), proportion=1) # this is a spacer
inputOneSizer1.Add(inputOneIcoAUT, 0, wx.ALL, 5)
inputOneSizer1.Add(labelOneAUT, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
inputOneSizerruntype.Add((20,20), proportion=1) # this is a spacer
inputOneSizerruntype.Add(inputOneIcoruntype, 0, wx.ALL, 5)
inputOneSizerruntype.Add(labelOneruntype, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
inputOneSizerenvs.Add((20,20), proportion=1) # this is a spacer
inputOneSizerenvs.Add(inputOneIcoenvs, 0, wx.ALL, 5)
inputOneSizerenvs.Add(labelOneenvs, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
inputOneSizerphases.Add((20,20), proportion=1) # this is a spacer
inputOneSizerphases.Add(inputOneIcophases, 0, wx.ALL, 5)
inputOneSizerphases.Add(labelOnephases, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
inputOneSizer.Add((20,20), proportion=1) # this is a spacer
inputOneSizer.Add(inputOneIco, 0, wx.ALL, 5)
inputOneSizer.Add(labelOne, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
inputTwoSizer.Add((20,20), 1, wx.EXPAND) # this is a spacer
inputTwoSizer.Add(inputTwoIco, 0, wx.ALL, 5)
inputTwoSizer.Add(labelTwo, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
inputThreeSizer.Add((20,20), 1, wx.EXPAND) # this is a spacer
inputThreeSizer.Add(inputThreeIco, 0, wx.ALL, 5)
inputThreeSizer.Add(labelThree, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
# Add the 3-item sizer to the gridsizer and
# Right align the labels and icons
#gridSizer.Add(inputOneSizer1, 0, wx.ALIGN_RIGHT)
# Set the TextCtrl to expand on resize
gridSizer.Add(inputOneSizer1, 0, wx.ALIGN_RIGHT)
gridSizer.Add(self.cbAUT,0,wx.EXPAND)
gridSizer.Add(inputOneSizerruntype, 0, wx.ALIGN_RIGHT)
gridSizer.Add(self.cbruntype,0,wx.EXPAND)
gridSizer.Add(inputOneSizerenvs, 0, wx.ALIGN_RIGHT)
gridSizer.Add(self.cbenvs,0,wx.EXPAND)
gridSizer.Add(inputOneSizerphases, 0, wx.ALIGN_RIGHT)
gridSizer.Add(self.cbphases,0,wx.EXPAND)
gridSizer.Add(inputOneSizer, 0, wx.ALIGN_RIGHT)
gridSizer.Add(inputTxtOne, 0, wx.EXPAND)
gridSizer.Add(inputTwoSizer, 0, wx.ALIGN_RIGHT)
gridSizer.Add(inputTxtTwo, 0, wx.EXPAND)
gridSizer.Add(inputThreeSizer, 0, wx.ALIGN_RIGHT)
gridSizer.Add(inputTxtThree, 0, wx.EXPAND)
btnSizer.Add(okBtn, 0, wx.ALL, 5)
btnSizer.Add(cancelBtn, 0, wx.ALL, 5)
topSizer.Add(titleSizer, 0, wx.CENTER)
topSizer.Add(wx.StaticLine(self.panel), 0, wx.ALL|wx.EXPAND, 5)
topSizer.Add(gridSizer, 0, wx.ALL|wx.EXPAND, 5)
topSizer.Add(wx.StaticLine(self.panel), 0, wx.ALL|wx.EXPAND, 5)
topSizer.Add(btnSizer, 0, wx.ALL|wx.CENTER, 5)
# SetSizeHints(minW, minH, maxW, maxH)
self.SetSizeHints(250,300,600,500)
self.panel.SetSizer(topSizer)
topSizer.Fit(self)
def onOK(self, event):
# we append to runs the current values of the dialog
results =
for dialog in self.cbAUT, self.cbruntype, self.cbenvs, self.cbphases:
results.append(dialog.GetValue())
self.runs.append('|'.join(results))
print self.runs
def onCancel(self, event):
self.closeProgram()
def closeProgram(self):
# self.runs should now have the full list of different options for runs
self.Close()
def OnSelect(self, event):
item = event.GetSelection()
print item
#v1 = cb.GetValue()
#print item
#print v1
#win = event.GetEventObject() # call this if you want to know which box was clicked
#for ix, item in enumerate(self.cbAUT):
# if win == item:
# break
#item = event.GetSelection()
#print "You selected item %s in combobox number %s" % (item,ix)
#mld = "You selected '"
#for cb in self.cbs:
# v1 = cb.GetValue()
# if v1:
# mld = v1.join((mld,"', "))
# print mld[:-2]
# #easygui.msgbox(mld[:-2])
# Run the program
if __name__ == '__main__':
app = wx.PySimpleApp()
form = MyForm()
frame = form.Show()
app.MainLoop()|