def OnDeleteButton(self, event):
filepath = self.ManagedDir.GetPath()
if os.path.isfile(filepath):
folder, filename = os.path.split(filepath)
dialog = wx.MessageDialog(self,
_("Do you really want to delete the file '%s'?") % filename,
_("Delete File"),
wx.YES_NO | wx.ICON_QUESTION)
remove = dialog.ShowModal() == wx.ID_YES
dialog.Destroy()
if remove:
os.remove(filepath)
self.ManagedDir.RefreshTree()
event.Skip()
python类MessageDialog()的实例源码
def Paste(self, bbx=None):
if not self.Debug:
element = self.ParentWindow.GetCopyBuffer()
if bbx is None:
mouse_pos = self.Editor.ScreenToClient(wx.GetMousePosition())
middle = wx.Rect(0, 0, *self.Editor.GetClientSize()).InsideXY(mouse_pos.x, mouse_pos.y)
if middle:
x, y = self.CalcUnscrolledPosition(mouse_pos.x, mouse_pos.y)
else:
x, y = self.CalcUnscrolledPosition(0, 0)
new_pos = [int(x / self.ViewScale[0]), int(y / self.ViewScale[1])]
else:
middle = True
new_pos = [bbx.x, bbx.y]
result = self.Controler.PasteEditedElementInstances(self.TagName, element, new_pos, middle, self.Debug)
if not isinstance(result, (StringType, UnicodeType)):
self.RefreshBuffer()
self.RefreshView(selection=result)
self.RefreshVariablePanel()
self.ParentWindow.RefreshPouInstanceVariablesPanel()
else:
message = wx.MessageDialog(self.Editor, result, "Error", wx.OK | wx.ICON_ERROR)
message.ShowModal()
message.Destroy()
def OnClose(self,event):
if self.CHANGES_TO_BE_SAVED:
dlg=wx.MessageDialog(self, "There are Unsaved Changes..Don't You Want to Save them?",'', wx.YES_NO|wx.YES_DEFAULT | wx.ICON_QUESTION)
#dlg = wx.MessageDialog(None, )
#dlg = wx.MessageDialog(None, "Don't You Want to Save Changes?", wx.NO_DEFAULT | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
self.Save_Clicked(None)
self.Parent.IsGridChild=0
self.Parent.Show()
self.P=None
self.DB=None
event.Skip()
def on_button_email_passwd(self,event):# Button save email and password
email=self.text_ctrl_email.Value
passwd=self.text_ctrl_email_passwd.Value
if not self.V.validate_email(email)[0]:
msg="Invalid Email"
dlg = wx.MessageDialog(self, msg, 'Error',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
return 0
self.DB.Set_SMS_Sender_Mail(email)
self.DB.Set_SMS_Sender_Mail_Password(passwd)
msg="Successfully Saved"
dlg = wx.MessageDialog(self, msg, 'Success',wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def validate_email(self):
self.CHECK_LIST_ITEMS=[]
sending_numbers=self.text_ctrl_selected_email.Value
sending_numbers=sending_numbers.split(";")
for email in sending_numbers:
print email
if not email:
continue
if self.V.validate_email(email)[0]:
self.CHECK_LIST_ITEMS.append(email)
else:
#msg=email+" is invalid email id. Either edit or delete it to continue!"
#dlg = wx.MessageDialog(self, msg, 'Error',wx.OK | wx.ICON_ERROR)
#dlg.ShowModal()
#dlg.Destroy()
return 0
return True
def Login_Check(self,user,password):
print "login check"
passw=self.EN.Encrypt_Password(self.Secret_Key+password)
query="SELECT PASSWORD FROM USER WHERE USER='%s' AND PASSWORD='%s'" %(user,passw)
#self.DB.cur.execute(query,(user,self.Secret_Key+password,))
self.DB.cur.execute(query)
#self.DB.con.commit()
row=self.DB.cur.fetchone()
if row:
return True
else:
dlg = wx.MessageDialog(self.parent, 'Incorrect Password', '',wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
return False
def validate_pass(self):
if not self.UO.Login_Check(self.combo_box_1.Value,self.text_ctrl_1.Value):
return False
if len(self.text_ctrl_2.Value)<5:
dlg = wx.MessageDialog(self, 'Password must be of at least five characters', '',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
return False
if self.text_ctrl_2.Value!=self.text_ctrl_3.Value:
dlg = wx.MessageDialog(self, 'Passwords do not match', '',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
return False
return True
def send_sms(self):
print "sending",self.NO_MOBILE_LIST
if self.NO_MOBILE_LIST:
msg="The following Student(s) got no valid mobile numbers. Go to Student Profile to add/edit mobile numbers\n"
no=0
for pupil in self.NO_MOBILE_LIST:
no+=1
msg+=str(no)+". "+str(pupil)+"\n"
#app = wx.PySimpleApp(0)
dlg = wx.MessageDialog(None, msg,"No Mobile Number",wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def Failed_Report(self):
if len(self.Failed_List)==0:
msg="All Students Passed"
else:
msg="The following Student(s) detained\n"
no=0
for pupil in self.Failed_List:
no+=1
msg+=str(no)+". "+str(pupil)+"\n"
#app = wx.PySimpleApp(0)
dlg = wx.MessageDialog(None, msg,str(self.class_)+self.div,wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def OnSave(self, event): # wxGlade: MyFrame2.<event_handler>
CE=[self.ce_1,self.ce_2,self.ce_3,self.ce_4,self.ce_5,self.ce_6,self.ce_7,self.ce_8,self.ce_9,self.ce_10,self.ce_11,self.ce_12,self.ce_13]
TE=[self.te_1,self.te_2,self.te_3,self.te_4,self.te_5,self.te_6,self.te_7,self.te_8,self.te_9,self.te_10,self.te_11,self.te_12,self.te_13]
try:
for i in range(13):
if self.YEAR=='Select' or self.STD=='Select':
break
else:
index=i#in deb oper Get_CE_CE() index for work exp starts at 12
if i>=10:
index+=2
self.DB.Set_CE_TE(self.YEAR,self.STD,index,CE[i].Value,TE[i].Value)
dlg = wx.MessageDialog(self, 'Successfully Saved', '',wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
except:
dlg = wx.MessageDialog(self, 'Error! Could not Save', '',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
event.Skip()
def place(self, e):
if not hasattr(self, "brackets"):
errortext = "Make bracket before doing that"
w = wx.MessageDialog(self.parent, errortext,
"Error", wx.ICON_ERROR)
w.ShowModal()
w.Destroy()
return
placel = bracketfuncs.placing(self.brackets)
d = wx.Dialog(None)
d.SetTitle("Results")
a = wx.TextCtrl(d, style=wx.TE_MULTILINE)
a.SetEditable(False)
ptxt = ""
for p in placel:
if not p.isbye():
ptxt += str(placel[p]) + ". " + p.tag + "\n"
a.SetValue(ptxt)
d.SetSize((250, 320))
d.Show(True)
def OnAdd(self, evt):
dialog = wx.TextEntryDialog(self,
"Enter name:",
"Add", style = wx.OK | wx.CANCEL)
dialog.Centre(wx.BOTH)
if dialog.ShowModal() == wx.ID_OK:
name = dialog.GetValue()
if name not in ("CURRENT", ) and name not in self.all_hosts:
fpath = os.path.join(DataPath, name)
shutil.copy(os.path.join(DataPath, "default"), fpath)
call_editor(fpath)
self.all_hosts.append(name)
self.combo_box_1.AppendItems([name])
else:
msg_dialog = wx.MessageDialog(self,
"Failed to create \"%s\".\nFile already exists." % name,
'Failed to create "%s"' % name, wx.OK | wx.ICON_ERROR)
msg_dialog.Centre(wx.BOTH)
msg_dialog.ShowModal()
msg_dialog.Destroy()
dialog.Destroy()
def OnDelete(self, evt):
name = self.combo_box_1.GetValue()
fpath = os.path.join(DataPath, name)
if name != "default":
msg_dialog = wx.MessageDialog(self,
"Are you sure that you want to delete file \"%s\"" % name,
"Delete \"%s\"" % name, wx.YES_NO | wx.ICON_EXCLAMATION)
msg_dialog.Centre(wx.BOTH)
r = msg_dialog.ShowModal()
if r == wx.ID_YES:
if os.path.exists(fpath) and os.path.isfile(fpath):
os.remove(fpath)
index = self.combo_box_1.GetSelection()
self.combo_box_1.Delete(index)
self.combo_box_1.Select(0)
msg_dialog.Destroy()
else:
msg_dialog = wx.MessageDialog(self,
"\"%s\" can't be deleted.\nYou can edit it only." % name,
"\"%s\" can't be deleted." % name, wx.OK | wx.ICON_ERROR)
msg_dialog.Centre(wx.BOTH)
msg_dialog.ShowModal()
msg_dialog.Destroy()
def OnSet(self, evt):
name = self.combo_box_1.GetValue()
fpath = os.path.join(DataPath, name)
msg_dialog = wx.MessageDialog(self,
"Are you sure that you want to set file \"%s\" as current hosts" % name,
"Set \"%s\"" % name, wx.YES_NO | wx.ICON_EXCLAMATION)
msg_dialog.Centre(wx.BOTH)
r = msg_dialog.ShowModal()
if r == wx.ID_YES:
with open(fpath, "rb") as fp_src:
with open("/etc/hosts", "wb") as fp_des:
fp_des.write(fp_src.read())
self.current = name
with open(CurrentHosts, "wb") as fp:
fp.write(name)
self.statusbar.SetStatusText("Current: %s" % self.current)
msg_dialog.Destroy()
def button_clicked(self, event):
log.debug("[Settings] Button clicked: {0}".format(IDS[event.GetId()]))
button_id = event.GetId()
keys = IDS[button_id].split(MODULE_KEY)
last_key = keys[-1]
if last_key in ['list_add', 'list_remove']:
self.on_list_operation(MODULE_KEY.join(keys[:-1]), action=last_key)
elif last_key in ['ok_button', 'apply_button']:
if self.save_settings():
log.debug('Got non-dynamic changes')
dialog = wx.MessageDialog(self,
message=translate_key(MODULE_KEY.join(['main', 'save', 'non_dynamic'])),
caption="Caption",
style=wx.OK_DEFAULT,
pos=wx.DefaultPosition)
dialog.ShowModal()
if last_key == 'ok_button':
self.on_exit(event)
self.settings_saved = True
elif last_key == 'cancel_button':
self.on_close(event)
event.Skip()
def OnInit(self):
"""
Run automatically when the wxPython application starts.
"""
self.frame = wx.Frame(None, title="PyUpdater wxPython Demo")
self.frame.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
self.frame.SetSize(wx.Size(400, 100))
self.statusBar = wx.StatusBar(self.frame)
self.statusBar.SetStatusText(self.status)
self.frame.SetStatusBar(self.statusBar)
self.panel = wx.Panel(self.frame)
self.sizer = wx.BoxSizer()
self.sizer.Add(
wx.StaticText(self.frame, label="Version %s" % __version__))
self.panel.SetSizerAndFit(self.sizer)
self.frame.Show()
if hasattr(sys, "frozen") and \
not os.environ.get('PYUPDATER_FILESERVER_DIR'):
dlg = wx.MessageDialog(
self.frame,
"The PYUPDATER_FILESERVER_DIR environment variable "
"is not set!", "PyUpdaterWxDemo File Server Error",
wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
return True
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 Send(self,message,level):
message = message
label = ('' if level>(len(self.labels)-1) else self.labels[level])
iconStyle = (0 if level>(len(self.iconStyles)-1) else self.iconStyles[level])
if self.logfile != None:
self.logfile.write(label+": "+message)
if level<=self.level:
wx.MessageDialog(self.frame, message, label, wx.CENTRE | iconStyle).ShowModal()
elif level<=self.silencelevel:
self.frame.SetStatusText(label+": "+message)
def read_config(self):
try:
self.config = PadConfig()
except ConfigException as e:
msg = "Config error: {}. Load defaults?".format(e)
dlg = wx.MessageDialog(self.pnl, msg, "Config Error", wx.YES_NO | wx.ICON_QUESTION)
result = dlg.ShowModal() == wx.ID_YES
dlg.Destroy()
if result:
self.config = PadConfig(load_defaults=True)
else:
sys.exit(1)
for key, item in self._config_map.items():
item.Set3StateValue(getattr(self.config, key))
def onAbout(self,event):
dlg = wx.MessageDialog(self,message="For more information visit:\n\nhttp://pyvision.sourceforge.net",style = wx.OK )
result = dlg.ShowModal()