def yesNoBox(self, title, message):
self.topLevel.update_idletasks()
return MessageBox.askyesno(title, message)
python类askyesno()的实例源码
def DeleteCustomKeys(self):
keySetName=self.customKeys.get()
if not tkMessageBox.askyesno('Delete Key Set','Are you sure you wish '+
'to delete the key set %r ?' % (keySetName),
parent=self):
return
#remove key set from config
idleConf.userCfg['keys'].remove_section(keySetName)
if keySetName in self.changedItems['keys']:
del(self.changedItems['keys'][keySetName])
#write changes
idleConf.userCfg['keys'].Save()
#reload user key set list
itemList=idleConf.GetSectionList('user','keys')
itemList.sort()
if not itemList:
self.radioKeysCustom.config(state=DISABLED)
self.optMenuKeysCustom.SetMenu(itemList,'- no custom keys -')
else:
self.optMenuKeysCustom.SetMenu(itemList,itemList[0])
#revert to default key set
self.keysAreBuiltin.set(idleConf.defaultCfg['main'].Get('Keys','default'))
self.builtinKeys.set(idleConf.defaultCfg['main'].Get('Keys','name'))
#user can't back out of these changes, they must be applied now
self.Apply()
self.SetKeysType()
def DeleteCustomTheme(self):
themeName=self.customTheme.get()
if not tkMessageBox.askyesno('Delete Theme','Are you sure you wish '+
'to delete the theme %r ?' % (themeName,),
parent=self):
return
#remove theme from config
idleConf.userCfg['highlight'].remove_section(themeName)
if themeName in self.changedItems['highlight']:
del(self.changedItems['highlight'][themeName])
#write changes
idleConf.userCfg['highlight'].Save()
#reload user theme list
itemList=idleConf.GetSectionList('user','highlight')
itemList.sort()
if not itemList:
self.radioThemeCustom.config(state=DISABLED)
self.optMenuThemeCustom.SetMenu(itemList,'- no custom themes -')
else:
self.optMenuThemeCustom.SetMenu(itemList,itemList[0])
#revert to default theme
self.themeIsBuiltin.set(idleConf.defaultCfg['main'].Get('Theme','default'))
self.builtinTheme.set(idleConf.defaultCfg['main'].Get('Theme','name'))
#user can't back out of these changes, they must be applied now
self.Apply()
self.SetThemeType()
def find_updates(self, verbose=True):
""" Run check_update and as user whether to update. """
if self.check_update():
if tkMessageBox.askyesno('Download update', 'An updated version of PIEFACE exists, do you want to download it?'):
webbrowser.open('https://github.com/jcumby/PIEFACE/releases/latest')
else:
if verbose:
tkMessageBox.showinfo('Update','PIEFACE is up to date')
def decide_who_plays(self):
if tkMessageBox.askyesno(" White ?", "Engine plays White ?"):
self.playerMovesFirst = True
self.draw_player_move_first()
def check_dir(self, dire):
if not os.path.exists(dire):
os.makedirs(dire)
else:
def go_ahead_then(dire):
shutil.rmtree(dire)
os.makedirs(dire)
wte = tkMessageBox.askyesno(
"Warning",
"All files in\n" +
dire +
"\nwill be deleted. Continue?"
)
if wte:
wtd = tkMessageBox.askyesno("Warning", "Are you sure?")
if wtd:
go_ahead_then(dire)
print "Files erased. Continuing."
return 1
else:
tkMessageBox.showinfo(
"PyRy3D info", "Choose a different directory \n\
and try again."
)
return 0
else:
tkMessageBox.showinfo(
"PyRy3D info",
"Choose a different directory \n and try again."
)
return 0
def new_session(self):
rly = tkMessageBox.askyesno(
"Warning",
"This will close all opened models. Continue?"
)
if rly is True:
self.clear()
self.clear_button.configure(state="normal")
self.open_button.configure(state="normal")
self.dens_button.configure(state="normal")
self.comp_button.configure(state="normal")
self.new_session_button.configure("disabled")
chimera.runCommand("close all")
def openandsaveall(self):
if len(self.complist) <= 1:
tkMessageBox.showinfo(
"PyRy3D info",
"You must add at least two structures."
)
else:
rly1 = True
if Paths.mappath == "" or Paths.mappath == ():
rly1 = tkMessageBox.askyesno(
"Warning",
"No shape descriptor provided. Continue?"
)
if rly1 is True:
rly2 = tkMessageBox.askyesno(
"Warning",
"This will close all opened models before loading new data. Continue?"
)
if rly2 is True:
runCommand("close all")
P1F.opencommand(Paths.mappath, self.complist)
P1F.writeAllPDBs(Paths.temppath, Paths.mappath)
runCommand("windowsize 9999 9999")
self.open_button.configure(state="disabled")
self.dens_button.configure(state="disabled")
self.comp_button.configure(state="disabled")
self.clear_button.configure(state="disabled")
self.new_session_button.configure(state="normal")
self.notebook.tab(1).configure(state="normal")
self.notebook.tab(2).configure(state="normal")
self.notebook.tab(3).configure(state="normal")
self.notebook.tab(3).configure(state="normal")
# ----- FUNCTIONS TRIGGERED BY WIDGETS ON THE --- SECOND PAGE ---
def zero_cal():
ok = tkMessageBox.askyesno("Zero power sensor", "Perform zero level adjust? (Disconnect sensor from the signal source)")
if ok:
sensor.cal_zero()
sensor.send_OPC()
print("Zeroing sensor. Please wait.")
wait_on_queue_progress_bar(sensor.event_queue, 6)
tkMessageBox.showinfo("Zero power sensor", "Zero cal complete. Reconnect the power sensor to the signal source.")
def delete(self):
if askyesno(title='Deletion',
message='Are you sure you wish to delete this '
'conversation?'):
self.peer.delete_conversation(self.conversation.contact.name)
self.destroy()
def _on_upload_btn_clicked(self):
selected_rows = self.runresultsview.get_selection()
if len(selected_rows) == 0:
messagebox.showerror('Error', 'No tests selected.')
return
selected_qc_dir = self.qcdir_tree.selection()
if len(selected_qc_dir) != 1:
messagebox.showerror('Error', 'Destination not selected.')
return
qcdir = self.dir_dict[selected_qc_dir[0]]
if not qcdir:
messagebox.showerror('Error', 'path is blank')
return
assert qcdir.startswith('Root\\'), qcdir
# remove "Root\"
qcdir = qcdir[5:]
results = self.results.copy()
results['tests'] = [self.runresultsview.tests[row]
for row in selected_rows]
result = messagebox.askyesno(
'Confirm',
('Are you sure you want to upload to the following '
'location?\n\n{}'.format(qcdir)))
if not result:
return
work_in_background(
self,
lambda: importer.import_results(
self.qcc,
qcdir,
results,
self.attach_report.get()),
lambda: messagebox.showinfo('Success', 'Import complete.'))
def runcode(self, code):
"Override base class method"
if self.tkconsole.executing:
self.interp.restart_subprocess()
self.checklinecache()
if self.save_warnings_filters is not None:
warnings.filters[:] = self.save_warnings_filters
self.save_warnings_filters = None
debugger = self.debugger
try:
self.tkconsole.beginexecuting()
if not debugger and self.rpcclt is not None:
self.active_seq = self.rpcclt.asyncqueue("exec", "runcode",
(code,), {})
elif debugger:
debugger.run(code, self.locals)
else:
exec code in self.locals
except SystemExit:
if not self.tkconsole.closing:
if tkMessageBox.askyesno(
"Exit?",
"Do you want to exit altogether?",
default="yes",
parent=self.tkconsole.text):
raise
else:
self.showtraceback()
else:
raise
except:
if use_subprocess:
print("IDLE internal error in runcode()",
file=self.tkconsole.stderr)
self.showtraceback()
self.tkconsole.endexecuting()
else:
if self.tkconsole.canceled:
self.tkconsole.canceled = False
print("KeyboardInterrupt", file=self.tkconsole.stderr)
else:
self.showtraceback()
finally:
if not use_subprocess:
try:
self.tkconsole.endexecuting()
except AttributeError: # shell may have closed
pass
def runcode(self, code):
"Override base class method"
if self.tkconsole.executing:
self.interp.restart_subprocess()
self.checklinecache()
if self.save_warnings_filters is not None:
warnings.filters[:] = self.save_warnings_filters
self.save_warnings_filters = None
debugger = self.debugger
try:
self.tkconsole.beginexecuting()
if not debugger and self.rpcclt is not None:
self.active_seq = self.rpcclt.asyncqueue("exec", "runcode",
(code,), {})
elif debugger:
debugger.run(code, self.locals)
else:
exec code in self.locals
except SystemExit:
if not self.tkconsole.closing:
if tkMessageBox.askyesno(
"Exit?",
"Do you want to exit altogether?",
default="yes",
parent=self.tkconsole.text):
raise
else:
self.showtraceback()
else:
raise
except:
if use_subprocess:
print("IDLE internal error in runcode()",
file=self.tkconsole.stderr)
self.showtraceback()
self.tkconsole.endexecuting()
else:
if self.tkconsole.canceled:
self.tkconsole.canceled = False
print("KeyboardInterrupt", file=self.tkconsole.stderr)
else:
self.showtraceback()
finally:
if not use_subprocess:
try:
self.tkconsole.endexecuting()
except AttributeError: # shell may have closed
pass
def start_new_project(self):
"""
Starts up a new job.
"""
self.initialize_project_data()
# Cheks for PyMod configuration file.
self.configuration_file_error = False
# If it is not found, then treat this session as the first one and asks the user to input
# the 'PyMod Directory' path before beginning the first PyMod job.
if not os.path.isfile(self.cfg_file_path):
self.show_first_time_usage_message()
self.show_pymod_directory_selection_window()
# The configuration file is found.
else:
try:
# Check if there is 'pymod_temp_directory' left by the PyMod installer script.
if not self.check_installer_script_temp_directory():
# Get values options for each PyMod tool and start a new PyMod job.
self.initialize_session()
# If there is a 'pymod_temp_directory' (the installer script has been used before
# this last PyMod session).
else:
# The installer script was run before configuring PyMod for the first time (it
# left an empty configuratio file).
if self.check_empty_configuration_file():
self.show_first_time_usage_message()
self.show_pymod_directory_selection_window()
# The installer script was run after the first PyMod session (in order to
# install some missing tools).
else:
self.initialize_session()
except Exception, e:
self.show_configuration_file_error(e, "read")
title = 'Configuration file repair'
message = "Would you like to delete PyMod configuration file and build a new functional copy of it?"
repair_choice = tkMessageBox.askyesno(title, message)
self.configuration_file_error = True
if repair_choice:
self.show_pymod_directory_selection_window()
else:
self.main_window.destroy()
def check_sequences_level(self):
"""
This method is used to ask the user a confirmation before performing an alignment in certain
situations (for example when building an alignment only with sequences belonging to the same
cluster).
"""
proceed_with_alignment = False
self.clusters_are_involved = False
# ---
# For regular alignments.
# ---
if self.alignment_strategy == "regular-alignment":
self.rebuild_single_alignment_choice = False
self.extract_siblings_choice = False
if len(self.involved_clusters_mi_list) == 1 and len(self.childless_mothers_mi_list) == 0:
# If there is only one cluster selected with all its elements: the user might want to
# rebuild an alignment with all its elements, ask confirmation.
if self.involved_clusters_mi_list == self.selected_clusters_mi_list:
title = "Rebuild alignment?"
message = "Would you like to rebuild the alignment with all its sequences?"
proceed_with_alignment = tkMessageBox.askyesno(title, message, parent=self.main_window)
self.rebuild_single_alignment_choice = proceed_with_alignment
else:
title = "Extract children?"
message = "Would you like to extract the selected children and build a new alignment?"
proceed_with_alignment = tkMessageBox.askyesno(title, message, parent=self.main_window)
self.extract_siblings_choice = proceed_with_alignment
elif len(self.involved_clusters_mi_list) > 0:
self.clusters_are_involved = True
proceed_with_alignment = True
elif len(self.involved_clusters_mi_list) == 0:
proceed_with_alignment = True
# ---
# For profile alignments.
# ---
elif self.alignment_strategy == "profile-alignment":
proceed_with_alignment = True
self.clusters_are_involved = True
return proceed_with_alignment
def dope_from_main_menu(self):
"""
Called when users decide calculate DOPE of a structure loaded in PyMod.
"""
# Checks if the DOPE profiles can be computed.
selection = self.get_selected_sequences()
if not self.modeller.can_be_launched():
self.show_error_message("MODELLER Error", "MODELLER is missing. In order to compute DOPE scores of a structure, MODELLER has to be installed.")
return False
if len(selection) == 0:
self.show_error_message("Selection Error", "Please select at least one structure to assess.")
return False
if not self.all_sequences_have_structure():
self.show_error_message("Selection Error", "Please select only elements that have a 3D structure currently loaded in PyMOL.")
return False
if len(set([seq.mother_index for seq in selection])) != 1:
self.show_error_message("Selection Error", "You can assess multiple structures DOPE only if they are aligned in the same cluster.")
return False
# Ask users if they would like to color the sequences according to their DOPE values.
title = "Color Option"
message = "Would you like to color the selected sequences by their DOPE values, once they have been calculated?"
color_by_dope_choice = tkMessageBox.askyesno(message=message, title=title, parent=pymod.main_window)
# Initializes MODELLER.
if self.modeller.run_internally():
env = modeller.environ()
env.io.atom_files_directory = []
env.io.atom_files_directory.append(".")
env.io.hetatm = True
env.io.water = True
env.libs.topology.read(file='$(LIB)/top_heav.lib')
env.libs.parameters.read(file='$(LIB)/par.lib')
else:
env = None
# Actually computes the DOPE scores of the polypeptide chains in the user selection.
for element in selection:
self.compute_dope(element,env=env)
# Assigns to each residue of the selected chains a correspoding color according to its DOPE.
self.assign_dope_items(selection)
# Color the elements.
if color_by_dope_choice:
for element in selection:
element.color_element_by_dope()
self.gridder()
# Shows the DOPE profiles plot.
dope_graph_mode = None
if len(selection) == 1:
dope_graph_mode = "single"
elif len(selection) >= 2:
dope_graph_mode = "multiple"
# Prepares the data to show in the plot.
dope_plot_data = self.prepare_dope_plot_data(selection, mode = dope_graph_mode)
# Shows the plot.
self.show_dope_plot(dope_plot_data)
def runcode(self, code):
"Override base class method"
if self.tkconsole.executing:
self.interp.restart_subprocess()
self.checklinecache()
if self.save_warnings_filters is not None:
warnings.filters[:] = self.save_warnings_filters
self.save_warnings_filters = None
debugger = self.debugger
try:
self.tkconsole.beginexecuting()
if not debugger and self.rpcclt is not None:
self.active_seq = self.rpcclt.asyncqueue("exec", "runcode",
(code,), {})
elif debugger:
debugger.run(code, self.locals)
else:
exec code in self.locals
except SystemExit:
if not self.tkconsole.closing:
if tkMessageBox.askyesno(
"Exit?",
"Do you want to exit altogether?",
default="yes",
master=self.tkconsole.text):
raise
else:
self.showtraceback()
else:
raise
except:
if use_subprocess:
print >>self.tkconsole.stderr, \
"IDLE internal error in runcode()"
self.showtraceback()
self.tkconsole.endexecuting()
else:
if self.tkconsole.canceled:
self.tkconsole.canceled = False
print >>self.tkconsole.stderr, "KeyboardInterrupt"
else:
self.showtraceback()
finally:
if not use_subprocess:
try:
self.tkconsole.endexecuting()
except AttributeError: # shell may have closed
pass