def afterTest(self, earlyStop):
if not earlyStop:
self.saveCap()
ca = np.mean(np.diag(self.confusion))/self.nTestTrial
confusion = np.round(100*self.confusion/self.nTestTrial)
resultText = (('Test Selection CA: %f\n' % ca) +
('Confusion Matrix:\n' + str(confusion) + '\n') +
('Choices: ' + str(self.choices)))
wx.MessageBox(message=resultText,
caption='Testing Complete',
style=wx.OK | wx.ICON_INFORMATION)
self.saveResultText(resultText)
else:
self.pieMenu.zeroBars(refresh=False)
self.pieMenu.clearAllHighlights()
python类MessageBox()的实例源码
def list_fs_ctrls_click(self, e):
print("this is supposed to fswebcam -d v4l2:/dev/video0 --list-controls on the pi")
target_ip = self.tb_ip.GetValue()
target_user = self.tb_user.GetValue()
target_pass = self.tb_pass.GetValue()
try:
ssh.connect(target_ip, username=target_user, password=target_pass, timeout=3)
print "Connected to " + target_ip
found_login = True
cam_choice = self.cam_select_cb.GetValue()
cam_cmd = "fswebcam -d v4l2:" + cam_choice + " --list-controls"
print("---Doing: " + cam_cmd)
stdin, stdout, stderr = ssh.exec_command(cam_cmd)
cam_output = stderr.read().strip()
print "Camera output; " + cam_output
ssh.close()
except Exception as e:
print("Some form of problem; " + str(e))
ssh.close()
if not cam_output == None:
msg_text = 'Camera located and interorgated; copy-paste a controll name from the following into the settings text box \n \n'
msg_text += str(cam_output)
wx.MessageBox(msg_text, 'Info', wx.OK | wx.ICON_INFORMATION)
def cat_script(self, e):
#opens an ssh pipe and runs a cat command to get the text of the script
target_ip = pi_link_pnl.target_ip
target_user = pi_link_pnl.target_user
target_pass = pi_link_pnl.target_pass
script_path = self.cron_path_combo.GetValue()
script_name = self.cron_script_cb.GetValue()
script_to_ask = script_path + script_name
try:
# ssh.connect(target_ip, username=target_user, password=target_pass, timeout=3)
print "Connected to " + target_ip
print("running; cat " + str(script_to_ask))
stdin, stdout, stderr = ssh.exec_command("cat " + str(script_to_ask))
script_text = stdout.read().strip()
error_text = stderr.read().strip()
if not error_text == '':
msg_text = 'Error reading script \n\n'
msg_text += str(error_text)
else:
msg_text = script_to_ask + '\n\n'
msg_text += str(script_text)
wx.MessageBox(msg_text, 'Info', wx.OK | wx.ICON_INFORMATION)
except Exception as e:
print("oh bother, this seems wrong... " + str(e))
def OnConnect(self,event):
Username = self.username.GetValue()
Password = self.pwd.GetValue()
mac = get.get_mac_address()
self.MAC=mac
ip = get.Get_local_ip()
self.IP=ip
upnet_net = packet.generate_upnet(mac, ip, Username, Password)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
hosts = '210.45.194.10'
status,message= connect.upnet(sock, upnet_net, hosts,self.getsession)
if status == 0:
msgbox = wx.MessageDialog(None, "",message,wx.OK)
msgbox.ShowModal()
frame=MainFrame()
frame.Show()
else:
self.connect.Disable()
self.disconnect.Enable()
self.username.SetEditable(False)
self.pwd.SetEditable(False)
wx.MessageBox(u'??????',message)
self.SetStatusText(u"????")
self.OnStartThread()
def run(self):
self.timeToQuit.wait(10)
while True:
if self.timeToQuit.isSet():
self.sock.close()
break
else:
breathe = packet.generate_breathe(self.mac, self.ip, self.session, self.index)
status = connect.breathe(self.sock, breathe, self.hosts)
if status == 0:
self.sock.close()
wx.MessageBox(u"?????????????",u"??!!",wx.OK | wx.ICON_INFORMATION,self)
sys.exit()
break
else:
self.index += 3
self.timeToQuit.wait(self.messageDelay)
def open(self, event):
dialog = wx.DirDialog(self, 'Select a Turrican II CDTV directory', '', wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
if dialog.ShowModal() != wx.ID_OK:
return
directory = dialog.GetPath()
test_files = ['L1-1', 'L2-1', 'L3-1', 'L4-1', 'L5-1', 'LOADER', 'MAIN']
for filename in test_files:
if not os.path.exists(os.path.join(directory, filename)):
wx.MessageBox('Not a valid Turrican II CDTV directory.', 'Invalid directory', wx.OK | wx.ICON_EXCLAMATION)
return
self._game_dir = directory
self._graphics = Graphics(self._game_dir)
self.load_worlds()
self.Entities.set_graphics(self._graphics)
self.Entities.set_font(self._font)
self.LevelSelect.SetSelection(0)
self.select_level(0, 0)
self.update_menu_state()
self.update_title()
def close(self, event):
if not self._world:
event.Skip()
return
modified = False
for level in self._world.levels:
modified = modified | level.modified
if modified:
result = wx.MessageBox('Do you want to save your changes?', 'Unsaved changes', wx.YES_NO | wx.CANCEL | wx.ICON_EXCLAMATION)
if result == wx.YES:
self._world.save()
elif result == wx.CANCEL:
return
event.Skip()
def _init_coll_HelpMenu_Items(self, parent):
AppendMenu(parent, help='', id=wx.ID_HELP,
kind=wx.ITEM_NORMAL, text=_(u'PLCOpenEditor') + '\tF1')
# AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS,
# kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2')
# AppendMenu(parent, help='', id=wx.ID_HELP_CONTEXT,
# kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3')
def handler(event):
return wx.MessageBox(
version.GetCommunityHelpMsg(),
_(u'Community support'),
wx.OK | wx.ICON_INFORMATION)
id = wx.NewId()
parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support'))
self.Bind(wx.EVT_MENU, handler, id=id)
AppendMenu(parent, help='', id=wx.ID_ABOUT,
kind=wx.ITEM_NORMAL, text=_(u'About'))
self.Bind(wx.EVT_MENU, self.OnPLCOpenEditorMenu, id=wx.ID_HELP)
# self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, id=wx.ID_HELP_CONTENTS)
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
def open_pdf(pdffile, pagenum=None):
if wx.Platform == '__WXMSW__':
try:
readerpath = get_acroversion()
except Exception:
wx.MessageBox("Acrobat Reader is not found or installed !")
return None
readerexepath = os.path.join(readerpath, "AcroRd32.exe")
if(os.path.isfile(readerexepath)):
open_win_pdf(readerexepath, pdffile, pagenum)
else:
return None
else:
readerexepath = os.path.join("/usr/bin", "xpdf")
if(os.path.isfile(readerexepath)):
open_lin_pdf(readerexepath, pdffile, pagenum)
else:
wx.MessageBox("xpdf is not found or installed !")
return None
def Validate(self, win):
tc = self.GetWindow()
val = tc.GetValue()
nm = tc.GetName()
try:
v = self.func(val)
if self.flag and v <= 0.0:
wx.MessageBox("%s must be positive" % nm, "Error")
elif v < 0.0:
wx.MessageBox("%s must be non-negative" % nm, "Error")
else:
tc.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))
tc.Refresh()
return True
except ValueError:
wx.MessageBox("%s is not a valid number" % nm, "Error")
tc.SetBackgroundColour("YELLOW")
tc.Clear()
tc.SetFocus()
tc.Refresh()
return False
def alerts(message='multiplierz', title='multiplierz', method='popup'):
"""Alert system for displaying popup or writing message to a file
Available methods equal 'popup' or 'file'.
If a file type method is chosen, the title represents the file name and location.
Example:
>> alerts('popup', 'Test', 'Hello. The test worked. Please click OK.')
"""
message = str(message)
title = str(title)
if method == 'popup':
try:
wx.MessageBox(message, title)
except wx._core.PyNoAppError:
app = mzApp()
app.launch()
wx.MessageBox(message, title)
elif method == 'file':
fh = open(title,'w')
fh.write(message)
fh.close()
def onShorten(self, event):
"""
Shortens a URL using the service specified.
Then sets the text control to the new URL.
"""
text = self.inputURLTxt.GetValue()
textLength = len(text)
if re.match("^https?://[^ ]+", text) and textLength > 20:
pass
else:
wx.MessageBox("URL is already tiny!", "Error")
return
URL = self.URLCbo.GetValue()
if URL == "is.gd":
self.shortenWithIsGd(text)
elif URL == "bit.ly":
self.shortenWithBitly(text)
elif URL == "tinyurl":
self.shortenWithTinyURL(text)
def on_new_rocktable(event):
OM = ObjectManager(event.GetEventObject())
rocktable_dlg = RockTableEditor.NewRockTableDialog(wx.App.Get().GetTopWindow())
try:
if rocktable_dlg.ShowModal() == wx.ID_OK:
# wx.MessageBox('It was created a partition.')
name = rocktable_dlg.get_value()
print 'name', name, type(str(name)), str(name).strip(''), str(name).strip()
if name == '': name = 'Table'
rock = OM.new('rocktable', name = name)
# partition_dlg.Destroy()
OM.add(rock)
except Exception as e:
print 'ERROR:', e
finally:
rocktable_dlg.Destroy()
def on_edit_rocktable(event):
OM = ObjectManager(event.GetEventObject())
if not OM.list('rocktable'):
try:
wx.MessageBox('Please create a new Rock Table first!')
except Exception as e:
print 'ERROR:', e
finally:
return
dlg = RockTableEditor.Dialog(wx.App.Get().GetTopWindow())
dlg.ShowModal()
dlg.Destroy()
_UIM = UIManager()
tree_ctrl = _UIM.list('tree_controller')[0]
tree_ctrl.refresh()
def on_new_partition(event):
OM = ObjectManager(event.GetEventObject())
partition_dlg = PartitionEditor.NewPartitionDialog(wx.App.Get().GetTopWindow())
try:
if partition_dlg.ShowModal() == wx.ID_OK:
# wx.MessageBox('It was created a partition.')
name = partition_dlg.get_value()
print 'name', name, type(str(name)), str(name).strip(''), str(name).strip()
if name == '': name = 'NEW'
rock = OM.new('partition', name = name)
# partition_dlg.Destroy()
OM.add(rock)
except Exception as e:
print 'ERROR:', e
finally:
partition_dlg.Destroy()
def Run( self ):
fileName = GetBoard().GetFileName()
if len(fileName)==0:
wx.LogMessage("a board needs to be saved/loaded!")
else:
dirpath = os.path.abspath(os.path.expanduser(fileName))
path, fname = os.path.split(dirpath)
ext = os.path.splitext(os.path.basename(fileName))[1]
name = os.path.splitext(os.path.basename(fileName))[0]
LogMsg="reading from "+ dirpath
out_filename=path+os.sep+name+".dxf"
LogMsg+="writing to "+out_filename
content=[]
txtFile = open(fileName,"r")
content = txtFile.readlines()
content.append(" ")
txtFile.close()
#wx.MessageDialog(None, 'This is a message box. ONLY TEST!', 'Test', wx.OK | wx.ICON_INFORMATION).ShowModal()
#wx.MessageDialog(None, 'This is a message box. ONLY TEST!', content, wx.OK | wx.ICON_INFORMATION).ShowModal()
#found_selected=False
#board = pcbnew.GetBoard()
dlg=wx.MessageBox( 'Only SAVED board file will be exported to DXF file', 'Confirm', wx.OK | wx.CANCEL | wx.ICON_INFORMATION )
if dlg == wx.OK:
if os.path.isfile(out_filename):
dlg=wx.MessageBox( 'Overwrite DXF file?', 'Confirm', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION )
if dlg == wx.YES:
export_dxf(content, out_filename)
else:
export_dxf(content, out_filename)
def Error(self, dialog):
wx.MessageBox(dialog , 'Info',
wx.OK | wx.ICON_INFORMATION)
def onSendFailed(self, reason, line):
"""Called if a send failed"""
wx.MessageBox(str(reason), 'Could not send %s' % line, wx.OK|wx.ICON_ERROR, self)
# Event handlers for net framework
def onServerFailed(self, reason):
"""Called if the server can't listen"""
self.btnListen.SetValue(False)
wx.MessageBox(reason, 'Server Failed', wx.OK|wx.ICON_ERROR, self)
self.GetStatusBar().SetStatusText('Server failed: %s' % reason)
def onClientFailed(self, reason):
self.btnConnect.SetValue(False)
wx.MessageBox(str(reason), 'Client Connection Failed', wx.OK|wx.ICON_ERROR, self)
self.GetStatusBar().SetStatusText('Client Connection Failed: %s' % reason)
def OnOpenEtotV(self, event):
wildcard = "dat file (*.dat)|*.dat|" \
"All files (*)|*"
dialog = wx.FileDialog(None, "Choose a file with total energies", os.getcwd(),"", wildcard)
if dialog.ShowModal() == wx.ID_OK:
try:
fname = dialog.GetPath()
self.V, self.E = read_EtotV(fname)
self.IsEtotVRead = True
self.SetStatusText("E_tot(V) file "+fname+" read")
except:
wx.MessageBox("Something wrong while opening the E_tot file... not loaded.",
"", wx.OK | wx.ICON_EXCLAMATION, self)
dialog.Destroy()
def OnFitisoEtot(self, event):
try:
self.a, self.cov, self.chi = fit_Murn(self.V,self.E)
print_eos_data(self.V,self.E,self.a,self.chi,"Etot")
fig1 = plot_EV(self.V,self.E,self.a) # plot the E(V) data and the fitting line
fig1.savefig("figure_1.png")
except:
wx.MessageBox("Something wrong while fitting total energies...",
"", wx.OK | wx.ICON_EXCLAMATION, self)
def OnFitanisoEtot(self, event):
try:
wx.MessageBox("Not implemented yet...",
"", wx.OK | wx.ICON_EXCLAMATION, self)
except:
wx.MessageBox("Something wrong while fitting total energies...",
"", wx.OK | wx.ICON_EXCLAMATION, self)
def OnHelp(self, event):
wx.MessageBox("A program to perform quasi-harmonic calculations based on the pyqha module",
"Help Contents", wx.OK | wx.ICON_INFORMATION, self)
def OnAbout(self, event):
wx.MessageBox("pyqhaGUI: a program to perform quasi-harmonic calculations",
"About pyQHA", wx.OK | wx.ICON_INFORMATION, self)
def on_ok(self, e):
self.session_file_path = self.session_picker.GetPath()
if not self.session_file_path:
wx.MessageBox(_("Please specify the Current Fest file."), "No Fest File", wx.OK | wx.ICON_ERROR, self)
return
self.config[Config.PROJECTOR_SCREEN] = self.screens_combobox.GetSelection()
self.config[Config.FILENAME_RE] = self.filename_re.GetValue()
self.config[Config.BG_TRACKS_DIR] = self.bg_tracks.GetPath()
self.config[Config.BG_ZAD_PATH] = self.bg_zad.GetPath()
self.config[Config.FILES_DIRS] = [picker.GetPath() for picker in self.dir_pickers]
self.EndModal(e.Id)
def OnButtonSave(self, msg):
if not self.model.status:
wx.MessageBox('No export file has been successfully loaded yet!')
return
ret = wx.MessageBox('Overwrite the original file?', 'Attention!',
wx.YES_NO | wx.ICON_QUESTION)
if ret == wx.YES:
self.model.save(self.fileread.path)
def OnButtonSaveAs(self, msg):
if not self.model.status:
wx.MessageBox('No export file has been successfully loaded yet!')
return
dialog = wx.FileDialog(
self, 'Save As ...', style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
result = dialog.ShowModal()
if result != wx.ID_OK:
return
# Show filedialog and get value
self.model.save(dialog.GetPath())
def On_ModelLoaded(self, msg):
ret, error = msg
if not ret:
wx.MessageBox(str(error), 'An error happened')
return
self.crcold.value = self.model.crcold
self.crcnew.value = self.model.crcnew
def On_ModelSaved(self, msg):
ret, error = msg
if not ret:
wx.MessageBox(str(error), 'An error happened!')
return
wx.MessageBox('File saved!', 'File Saved!')