def onClosing(self):
if messagebox.askokcancel("Quit","do you want to Quit?"):
self.master.destroy()
self.master.quit()
python类askokcancel()的实例源码
def onClosing(self):
if messagebox.askokcancel("Quit","do you want to Quit?"):
for child in multiprocessing.active_children():
kill_proc_tree(child.pid)
if self.running:
killFCEUX()
self.master.destroy()
self.master.quit()
def canceltrade():
global privapi
global orders
if len(orders) > 0:
if window.lstorders.curselection():
selectedorder = window.lstorders.get(window.lstorders.curselection())
orderid = str(orders[selectedorder].OrderId)
warning = messagebox.askokcancel("############ WARNING!! ############",
"You have requested a cancel on order no: " + orderid)
if warning:
ttype = "Trade"
debugout("Requesting Cancellation of order no. " + orderid)
response = privapi.canceltrade(ttype, orderid)
if isinstance(response, str):
debugout(response)
else:
orderstr = "Cancel Order ID: " + orderid + " Submitted! "
if len(response) > 0:
orderstr = orderstr + "Cancelled Order ID's: "
for corder in response:
orderstr = orderstr + str(corder) + ", "
debugout(orderstr)
getorders()
else:
debugout("User cancelled order: " + orderid + " cancellation after warning.")
else:
debugout("ERROR! - No Order Selected!")
else:
debugout("ERROR! - No Orders Found! Please try again.")
getorders()
# Cancel All trades for a TradePair via TradePairId
def canceltradepair():
global privapi
global orders
if len(orders) > 0:
if window.lstorders.curselection():
selectedorder = window.lstorders.get(window.lstorders.curselection())
tradepairid = str(orders[selectedorder].TradePairId)
marketname = orders[selectedorder].Market
warning = messagebox.askokcancel("############ WARNING!! ############",
"You have requested a cancel on ALL " + marketname + " orders.")
if warning:
ttype = "TradePair"
debugout("Requesting Cancellation of all " + marketname + " trades...")
response = privapi.canceltrade(ttype, tradepairid)
if isinstance(response, str):
debugout(response)
else:
orderstr = marketname + " TradePair Cancel Submitted! "
if len(response) > 0:
orderstr = orderstr + "Cancelled Order ID's: "
for corder in response:
orderstr = orderstr + str(corder) + ", "
debugout(orderstr)
getorders()
else:
debugout("User cancelled All " + tradepairid + " cancellation after warning.")
else:
debugout("ERROR! - No Order Selected!")
else:
debugout("ERROR! - No Orders Found! Please try again.")
getorders()
# Cancel ALL trades
def cancelalltrades():
global privapi
global orders
if len(orders) > 0:
warning = messagebox.askokcancel("############ WARNING!! ############",
"You have requested a cancel on ALL trades!")
if warning:
ttype = "All"
response = privapi.canceltrade(ttype)
if isinstance(response, str):
debugout(response)
else:
orderstr = "All Trade Cancel Submitted! "
if len(response) > 0:
orderstr = orderstr + "Cancelled Order ID's: "
for corder in response:
orderstr = orderstr + str(corder) + ", "
debugout(orderstr)
getorders()
else:
debugout("User Cancelled All Trade Cancellation after warning.")
else:
debugout("ERROR! - No Orders Found! Please try again.")
getorders()
# Just a way to use 2 button handlers to start the trade with a binary choice
def tip():
global privapi
currency = simpledialog.askstring("Currency Required", "Please provide the currency to tip in (eg. 'DOT' or '2')")
if currency == "":
debugout("ERROR! - Cannot tip without a currency!")
else:
amount = simpledialog.askfloat("Amount Required", "Please provide an amount of " + currency + " to tip")
activeusers = simpledialog.askinteger("Number of Users Required",
"Please provide a number of active users to tip (2-100):", initialvalue=2)
formattedamount = "{0:.8f}".format(amount)
activeusers = str(activeusers)
confirm = messagebox.askokcancel("Confirm Tip", "Please confirm that you want to tip the trollbox\r\n" +
"Tip Details:\r\nCurrency: " + currency + "\r\nAmount: " + formattedamount +
"\r\nActive Users receiving: " + activeusers)
if confirm:
debugout("User confirmed " + formattedamount + " " + currency + " tip, to " + activeusers + " users.")
response = privapi.submittip(currency, amount, activeusers)
# The API is supposed to return a string in any event, it doesn't appear to be at the moment.
# Just as well I coded my own confirmation!!
if isinstance(response, str):
# In this case, the response is always a string.
debugout(response)
else:
# This next line is me getting over the fact that the API returns a Nonetype!!
pass
# debugout(str(response) + " is a " + str(type(response)))
else:
debugout("User Cancelled Tip after warning.")
def on_closing(self):
if messagebox.askokcancel("Quit", "Do you want to quit?"):
self.pfr.init_board( { 'value': 0,
'direction': 0,
'pullup': 0},
{ 'value': 0,
'direction': 0, # Makes all pins outputs outputs
'pullup': 0})
self.root.destroy()
def on_closing(self):
if messagebox.askokcancel("Quit", "Do you want to quit?"):
self.pfr.init_board( { 'value': 0,
'direction': 0,
'pullup': 0},
{ 'value': 0,
'direction': 0, # Makes all pins outputs outputs
'pullup': 0})
self.root.destroy()
def on_closing(self):
if messagebox.askokcancel("Quit", "Do you want to quit?"):
self.pfr.init_board( { 'value': 0,
'direction': 0,
'pullup': 0},
{ 'value': 0,
'direction': 0, # Makes all pins outputs outputs
'pullup': 0})
self.root.destroy()
def on_closing(self):
if messagebox.askokcancel("Quit", "Do you want to quit?"):
self.pfr.init_board( { 'value': 0,
'direction': 0,
'pullup': 0},
{ 'value': 0,
'direction': 0, # Makes all pins outputs outputs
'pullup': 0})
self.root.destroy()
def on_closing(self):
if messagebox.askokcancel("Quit", "Do you want to quit?"):
self.root.destroy()
def print_window(self, event):
confirm = tkMessageBox.askokcancel(
title="Print",
message="Print to Default Printer",
default=tkMessageBox.OK,
master=self.text)
if not confirm:
self.text.focus_set()
return "break"
tempfilename = None
saved = self.get_saved()
if saved:
filename = self.filename
# shell undo is reset after every prompt, looks saved, probably isn't
if not saved or filename is None:
(tfd, tempfilename) = tempfile.mkstemp(prefix='IDLE_tmp_')
filename = tempfilename
os.close(tfd)
if not self.writefile(tempfilename):
os.unlink(tempfilename)
return "break"
platform = os.name
printPlatform = True
if platform == 'posix': #posix platform
command = idleConf.GetOption('main','General',
'print-command-posix')
command = command + " 2>&1"
elif platform == 'nt': #win32 platform
command = idleConf.GetOption('main','General','print-command-win')
else: #no printing for this platform
printPlatform = False
if printPlatform: #we can try to print for this platform
command = command % filename
pipe = os.popen(command, "r")
# things can get ugly on NT if there is no printer available.
output = pipe.read().strip()
status = pipe.close()
if status:
output = "Printing failed (exit status 0x%x)\n" % \
status + output
if output:
output = "Printing command: %s\n" % repr(command) + output
tkMessageBox.showerror("Print status", output, master=self.text)
else: #no printing for this platform
message = "Printing is not enabled for this platform: %s" % platform
tkMessageBox.showinfo("Print status", message, master=self.text)
if tempfilename:
os.unlink(tempfilename)
return "break"
def print_window(self, event):
confirm = tkMessageBox.askokcancel(
title="Print",
message="Print to Default Printer",
default=tkMessageBox.OK,
parent=self.text)
if not confirm:
self.text.focus_set()
return "break"
tempfilename = None
saved = self.get_saved()
if saved:
filename = self.filename
# shell undo is reset after every prompt, looks saved, probably isn't
if not saved or filename is None:
(tfd, tempfilename) = tempfile.mkstemp(prefix='IDLE_tmp_')
filename = tempfilename
os.close(tfd)
if not self.writefile(tempfilename):
os.unlink(tempfilename)
return "break"
platform = os.name
printPlatform = True
if platform == 'posix': #posix platform
command = idleConf.GetOption('main','General',
'print-command-posix')
command = command + " 2>&1"
elif platform == 'nt': #win32 platform
command = idleConf.GetOption('main','General','print-command-win')
else: #no printing for this platform
printPlatform = False
if printPlatform: #we can try to print for this platform
command = command % shlex.quote(filename)
pipe = os.popen(command, "r")
# things can get ugly on NT if there is no printer available.
output = pipe.read().strip()
status = pipe.close()
if status:
output = "Printing failed (exit status 0x%x)\n" % \
status + output
if output:
output = "Printing command: %s\n" % repr(command) + output
tkMessageBox.showerror("Print status", output, parent=self.text)
else: #no printing for this platform
message = "Printing is not enabled for this platform: %s" % platform
tkMessageBox.showinfo("Print status", message, parent=self.text)
if tempfilename:
os.unlink(tempfilename)
return "break"
def start_server(self, event=None):
"""
Try to start wpa_supplicant and connect to a Wii U.
:param event: Determines if this was a user initiated start.
:return: None
"""
if event:
LoggerGui.debug("User clicked start server button")
LoggerGui.debug("Start server called")
if self.label_backend_status["text"] != DrcSimC.STOPPED and \
(self.label_wpa_status["text"] not in (WpaSupplicant.DISCONNECTED, WpaSupplicant.TERMINATED)):
messagebox.showerror("Running", "Server is already running")
return
if not os.path.exists(constants.PATH_CONF_CONNECT):
messagebox.showerror("Auth Error",
"No auth details found. Use the \"Get Key\" tab to pair with a Wii U.")
self.activate()
return
self.normal_interface = self.dropdown_normal_interface.get()
self.wii_u_interface = self.dropdown_wiiu_interface.get()
if not self.normal_interface or not self.wii_u_interface:
messagebox.showerror("Interface Error", "Two interfaces need to be selected.")
self.activate()
return
if self.normal_interface == self.wii_u_interface:
messagebox.showerror("Interface Error", "The selected normal and Wii U interfaces must be different.")
self.activate()
return
try:
InterfaceUtil.get_mac(self.normal_interface)
InterfaceUtil.get_mac(self.wii_u_interface)
except ValueError:
messagebox.showerror("Interface Error", "The selected Interface is no longer available.")
self.activate()
return
if InterfaceUtil.is_managed_by_network_manager(self.wii_u_interface):
set_unmanaged = messagebox.askokcancel(
"Managed Interface", "This interface is managed by Network Manager. To use it with DRC Sim it needs "
"to be set to unmanaged. Network Manager will not be able to control the interface"
" after this.\nSet %s to unmanaged?" % self.wii_u_interface)
if set_unmanaged:
InterfaceUtil.set_unmanaged_by_network_manager(self.wii_u_interface)
else:
messagebox.showerror("Managed Interface", "Selected Wii U interface is managed by Network Manager.")
self.activate()
return
LoggerGui.debug("Starting wpa supplicant")
self.wpa_supplicant = WpaSupplicant()
self.wpa_supplicant.add_status_change_listener(self.wpa_status_changed)
self.wpa_supplicant.connect(constants.PATH_CONF_CONNECT, self.wii_u_interface)
self.label_backend_status.config(text="WAITING")
def print_window(self, event):
confirm = tkMessageBox.askokcancel(
title="Print",
message="Print to Default Printer",
default=tkMessageBox.OK,
master=self.text)
if not confirm:
self.text.focus_set()
return "break"
tempfilename = None
saved = self.get_saved()
if saved:
filename = self.filename
# shell undo is reset after every prompt, looks saved, probably isn't
if not saved or filename is None:
(tfd, tempfilename) = tempfile.mkstemp(prefix='IDLE_tmp_')
filename = tempfilename
os.close(tfd)
if not self.writefile(tempfilename):
os.unlink(tempfilename)
return "break"
platform = os.name
printPlatform = True
if platform == 'posix': #posix platform
command = idleConf.GetOption('main','General',
'print-command-posix')
command = command + " 2>&1"
elif platform == 'nt': #win32 platform
command = idleConf.GetOption('main','General','print-command-win')
else: #no printing for this platform
printPlatform = False
if printPlatform: #we can try to print for this platform
command = command % shlex.quote(filename)
pipe = os.popen(command, "r")
# things can get ugly on NT if there is no printer available.
output = pipe.read().strip()
status = pipe.close()
if status:
output = "Printing failed (exit status 0x%x)\n" % \
status + output
if output:
output = "Printing command: %s\n" % repr(command) + output
tkMessageBox.showerror("Print status", output, master=self.text)
else: #no printing for this platform
message = "Printing is not enabled for this platform: %s" % platform
tkMessageBox.showinfo("Print status", message, master=self.text)
if tempfilename:
os.unlink(tempfilename)
return "break"