So what im trying to do is, if the user select his location then the listbox should be filled in with values. I always get NameError: global name 'listcomputers' is not defined but i dont understand why.
can anybody help me ?
import os
import wx
class MyForm(wx.Frame):
def __init__(self):
global location
wx.Frame.__init__(self, None, wx.ID_ANY, "Remote Administrator v1.0", (500,500), (425,250))
panel = wx.Panel(self, wx.ID_ANY)
listcomputers_list = []
listcomputers = wx.ListBox(panel, 1, (8,16), (120, 96), listcomputers_list, wx.LB_MULTIPLE)
listcomputers.SetBackgroundColour(wx.Colour(255, 255, 255))
listcomputers.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
listcomputers.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
listcomputers.Bind(wx.EVT_LISTBOX, self.onListComputers)
start = wx.Button(panel, -1, 'Start', (8,136), (75, 23))
start.Bind(wx.EVT_BUTTON, self.onStart)
timer = wx.Slider(panel, -1, 0, 0, 10, (136,48), (104, 45), wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_BOTTOM | wx.SL_RIGHT | wx.SL_LABELS)
timer.Bind(wx.EVT_SLIDER, self.onAdjust)
label = wx.StaticText(panel, -1, 'Timer:', (144,32), (100, 23))
label.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
label.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
RadioShutdown = wx.RadioButton(panel, -1, 'Shutdown', (136,88), (104, 24))
RadioShutdown.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
RadioShutdown.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
RadioShutdown.SetValue(0)
RadioShutdown.Bind(wx.EVT_RADIOBUTTON, self.onRadio)
RadioLogoff = wx.RadioButton(panel, -1, 'Logoff', (136,112), (104, 24))
RadioLogoff.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
RadioLogoff.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
RadioLogoff.SetValue(0)
RadioLogoff.Bind(wx.EVT_RADIOBUTTON, self.onRadio)
RadioReboot = wx.RadioButton(panel, -1, 'Reboot', (136,136), (104, 24))
RadioReboot.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
RadioReboot.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
RadioReboot.SetValue(0)
RadioReboot.Bind(wx.EVT_RADIOBUTTON, self.onRadio)
self.CreateStatusBar()
loc_list = ['Atel','Sint-Andries','Permeke']
loc = wx.ComboBox(panel, -1, 'Select Location', (269,21), (121, 21), loc_list)
loc.SetBackgroundColour(wx.Colour(255, 255, 255))
loc.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
loc.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
loc.Bind(wx.EVT_COMBOBOX, self.onLocation)
self.progressbar = wx.Gauge(panel, -1, 100, (264,128), (137, 17))
self.progressbar.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
self.progressbar.SetValue(0)
def onLocation(self, event):
get = event.GetEventObject()
location = get.GetValue()
self.Hide()
self.Update()
self.Refresh()
self.Show()
self.SetStatusText(location)
if location == "Atel":
listcomputers.Append("PC1")
listcomputers.Append("PC2")
listcomputers.Append("PC3")
listcomputers.Append("PC4")
listcomputers.Append("PC5")
listcomputers.Append("PC6")
listcomputers.Append("PC7")
listcomputers.Append("PC8")
listcomputers.Append("PC9")
listcomputers.Append("PC10")
listcomputers.Append("PC11")
listcomputers.Append("PC12")
if location == "Sint-Andries":
listcomputers.Append("PC1")
listcomputers.Append("PC2")
listcomputers.Append("PC3")
listcomputers.Append("PC4")
listcomputers.Append("PC5")
listcomputers.Append("PC6")
listcomputers.Append("PC7")
listcomputers.Append("PC8")
listcomputers.Append("PC8")
if location == "Permeke":
listcomputers.Append("PC1")
listcomputers.Append("PC2")
listcomputers.Append("PC3")
listcomputers.Append("PC4")
listcomputers.Append("PC5")
def onListComputers(self, event):
lst = event.GetEventObject()
global pclst
PcName = lst.GetSelections()
pclst = []
for x in PcName:
x = x + 1
pclst.append(x)
self.SetStatusText("Selected Computers: " + str(pclst))
def onAdjust(self, event):
adj = event.GetEventObject()
global tmr
tmr = adj.GetValue()
self.SetStatusText("Timer set to: " + str(tmr))
def onRadio(self, event):
obj = event.GetEventObject()
label = obj.GetLabel()
self.SetStatusText("Selected " + label)
global RadioResult
if label == "Shutdown":
RadioResult = "Shutdown"
if label == "Logoff":
RadioResult = "Logoff"
if label == "Reboot":
RadioResult = "Reboot"
def onStart(self, event):
obj = event.GetEventObject()
label = obj.GetLabel()
if label == "Start":
self.SetStatusText("Trying to start with actions")
try:
RadioResult
tmr
pclst
print RadioResult
print tmr
print pclst
except NameError:
self.SetStatusText("Failed starting actions")
wx.MessageBox('Not all required fields are filled in!\nPlease correct this and try again.', 'Error')
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()