我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用wx.YES_DEFAULT。
def OnStartButton(self, e): if wpkg_running(): dlg_msg = _(u"WPKG is currently running,\n" u"please wait a few seconds and try again.") dlg = wx.MessageDialog(self, dlg_msg, app_name, wx.OK | wx.ICON_EXCLAMATION) dlg.ShowModal() dlg.Destroy() return dlg_title = _(u"2. Warning") dlg_msg = _(u"Close all open programs!\n\nThe System could restart without further confirmation!\n\n" \ u"Continue?") dlg = wx.MessageDialog(self, dlg_msg, dlg_title, wx.YES_NO|wx.YES_DEFAULT|wx.ICON_EXCLAMATION) if dlg.ShowModal() == wx.ID_YES: dlg.Destroy() # Disable/enable buttons and disable Close Window option! self.startButton.Disable() self.abortButton.Enable() self.EnableCloseButton(enable=False) # Set Start Time self.wpkg_start_time = datetime.datetime.now() # Reset Log self.log = None startWorker(self.LongTaskDone, self.LongTask)
def OnAbortButton(self, e): if not self.running: self.Close() return dlg_title = _(u"Cancel") dlg_msg = _(u"System update in progress!\n\n Canceling this Progress could result in installation issues.\n" u"Cancel?") dlg = wx.MessageDialog(self, dlg_msg, dlg_title, wx.YES_NO|wx.YES_DEFAULT|wx.ICON_EXCLAMATION) if dlg.ShowModal() == wx.ID_YES: dlg.Destroy() if not self.running: # WPKG Process by this client has finished, no cancel possible return print 'Aborting WPKG Process' #TODO: MOVE TO DEBUG LOGGER self.shouldAbort = True msg = 'Cancel' try: pipeHandle = CreateFile("\\\\.\\pipe\\WPKG", GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, None) except pywintypes.error, (n, f, e): print "Error when generating pipe handle: %s" % e #TODO: MOVE TO DEBUG LOGGER return 1 SetNamedPipeHandleState(pipeHandle, PIPE_READMODE_MESSAGE, None, None) WriteFile(pipeHandle, msg)
def onClose(self,event): dlg = wx.MessageDialog(self,message="Would you like to save the coordinates before exiting?",style = wx.YES_NO | wx.YES_DEFAULT) result = dlg.ShowModal() if result == wx.ID_YES: print "Saving..." self.onSave(event) else: print "Discarding changes..." # Pass this on to the default handler. event.Skip()
def WorkSpace(self,e ): ''' Load in a project. ''' logging.exception(self.clargs) dbfile = self.clargs['project'] if not os.path.isfile(dbfile): dlg = wx.MessageDialog(self, 'Project not found. Browse for the file?', '',wx.YES_NO | wx.YES_DEFAULT | wx.CANCEL | wx.ICON_QUESTION) val = dlg.ShowModal() if val == wx.ID_YES: self.OpenFile(e,False) elif val == wx.ID_CANCEL: dlg.Destroy() else: self.OpenFile(False,dbfile) self.bplay.SetBitmapLabel(self.bplayicon) self.panel2.Refresh() #update timeline view self.Layout() self.panel3.SetFocus()
def on_upgrade(self, event): try: if self.wpkg_dialog.IsShown(): # If dialog is opened already, raise window to top self.wpkg_dialog.Raise() return except AttributeError: # Dialog is not opened yet # Check if Reboot is Pending try: reboot_pending = ReadRebootPendingTime() except WindowsError: dlg_msg = _(u'Registry Error\n\nNo access to necessary registry key.') dlg = wx.MessageDialog(None, dlg_msg, app_name, wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return if reboot_pending and reboot_pending > self.bootup_time: dlg_msg = _(u"Reboot required!\n\n" u"A reboot is required before the system\n" u"can be updated again.\n" u"Reboot now?") dlg = wx.MessageDialog(None, dlg_msg, app_name, wx.YES_NO | wx.YES_DEFAULT | wx.ICON_EXCLAMATION) if dlg.ShowModal() == wx.ID_YES: # Initiate Reboot shutdown(1, time=5, msg=_(u"System will reboot now!")) return else: return elif reboot_pending: SetRebootPendingTime(reset=True) if update_method and update_interval: self.timer.Stop() self.wpkg_dialog = RunWPKGDialog(parent=self, title=_(u'System Update')) self.wpkg_dialog.ShowModal() if self.wpkg_dialog.shutdown_scheduled == True: # Shutdown Scheduled add Cancel Option to Popup Menu self.shutdown_scheduled = True if self.wpkg_dialog.reboot_scheduled == True: # Reboot Scheduled add Cancel Option to Popup Menu self.shutdown_scheduled = True self.reboot_scheduled = True self.wpkg_dialog.Destroy() if update_method and update_interval: self.timer.Start()
def LongTask(self): return_msg = None return_code = None reboot = False # Checking if System is connected through VPN if check_vpn and vpn_connected(arch=arch): dlg_msg = _(u"WPKG-GP Client detected a active VPN Connection using Cisco Anyconnect.\n" u"This could result in slow upgrade progress and updates for the AnyConnect\n" u"Software will be blocked.\n" u"Continue?") dlg = wx.MessageDialog(self, dlg_msg, app_name, wx.YES_NO | wx.YES_DEFAULT | wx.ICON_INFORMATION) if dlg.ShowModal() == wx.ID_NO: # Canceled by user because of active VPN Connection return_msg = 'WPKG process start canceled by user.' # Make translate able? return 400, return_msg, None # LONG TASK is the PipeConnection to the WPKG-GP Windows Service self.running = True msg = 'ExecuteNoReboot' try: pipeHandle = CreateFile("\\\\.\\pipe\\WPKG", GENERIC_READ|GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, None) except pywintypes.error, (n, f, e): # print "Error when generating pipe handle: %s" % e # Can't connect to pipe error, probably service not running return_msg = u"Error: WPKG-GP Service not running" return 208, return_msg, None SetNamedPipeHandleState(pipeHandle, PIPE_READMODE_MESSAGE, None, None) WriteFile(pipeHandle, msg) while 1: try: (hr, readmsg) = ReadFile(pipeHandle, 512) out = readmsg[4:].decode('utf-8') #Strip 3 digit status code, decode characters status_code = int(readmsg[:3]) if status_code < 102: # default status code for pipe updates percentage = getPercentage(out) wx.CallAfter(self.update_box.SetValue, out) wx.CallAfter(self.gauge.SetValue, percentage) elif status_code > 300: # reboot necessary reboot = True elif status_code > 200: # possible error return_code = status_code return_msg = out except win32api.error as exc: if exc.winerror == winerror.ERROR_PIPE_BUSY: win32api.Sleep(5000) print 'Pipe Busy Error' continue break return return_code, return_msg, reboot