我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用gtk.RESPONSE_YES。
def save(self, action=None): """Called when the Save button is clicked.""" if confirmDialog(self, "Overwrite configuration file?") == gtk.RESPONSE_YES: self.tw.defaults["font"] = self.font.get_font_name() self.tw.defaults["bgColor"] = rgbToHex(self.bgColor.get_color().red, self.bgColor.get_color().green, self.bgColor.get_color().blue) self.tw.defaults["fgColor"] = rgbToHex(self.fgColor.get_color().red, self.fgColor.get_color().green, self.fgColor.get_color().blue) self.tw.defaults["borderColor"] = rgbToHex(self.borderColor.get_color().red, self.borderColor.get_color().green, self.borderColor.get_color().blue) try: self.tw.defaults["bgCount"] = int(self.bgCount.get_text()) except: errorDialog(self, "Invalid value for background count") return self.tw.writeConf() self.quit()
def delBgClick(self, widget=None, prompt=True, init=False): """Deletes the selected background after confirming with the user.""" selected = self.bgNotebook.get_current_page() if selected == -1: # Nothing to remove return if prompt: if confirmDialog(self, "Remove this background?") != gtk.RESPONSE_YES: return self.bgNotebook.remove_page(selected) self.bgs.pop(selected) for i in range(self.bgNotebook.get_n_pages()): self.bgNotebook.set_tab_label_text(self.bgNotebook.get_nth_page(i), "Background ID %d" % (i+1)) self.bgNotebook.show_all() self.updateComboBoxes(len(self.bgs) + 1, "remove") if not init: self.changeOccurred()
def quit(self, widget, event=None): """Asks if user would like to save file before quitting, then quits the program.""" if self.toSave: if self.oneConfigFile: response = gtk.RESPONSE_YES else: dialog = gtk.Dialog("Save config?", self, gtk.DIALOG_MODAL, (gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) dialog.get_content_area().add(gtk.Label("Save config before quitting?")) dialog.get_content_area().set_size_request(300, 100) dialog.show_all() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_CANCEL: return True # Return True to stop it quitting when we hit "Cancel" elif response == gtk.RESPONSE_NO: gtk.main_quit() elif response == gtk.RESPONSE_YES: self.save() gtk.main_quit() else: gtk.main_quit()
def _confirm_experimental(self, rclass): sql_key = "warn_experimental_%s" % directory.radio_class_id(rclass) if CONF.is_defined(sql_key, "state") and \ not CONF.get_bool(sql_key, "state"): return True title = _("Proceed with experimental driver?") text = rclass.get_prompts().experimental msg = _("This radio's driver is experimental. " "Do you want to proceed?") resp, squelch = common.show_warning(msg, text, title=title, buttons=gtk.BUTTONS_YES_NO, can_squelch=True) if resp == gtk.RESPONSE_YES: CONF.set_bool(sql_key, not squelch, "state") return resp == gtk.RESPONSE_YES
def show_confirmation_dialog(self, msg): dialog = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_YES_NO, msg) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_YES: return True return False
def saveAs(self, widget=None, event=None): """Prompts the user to select a file and then saves the generated config file.""" self.generateConfig() chooser = gtk.FileChooserDialog("Save Config File As...", self, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) chooser.set_default_response(gtk.RESPONSE_OK) if self.curDir != None: chooser.set_current_folder(self.curDir) chooserFilter = gtk.FileFilter() chooserFilter.set_name("All files") chooserFilter.add_pattern("*") chooser.add_filter(chooserFilter) chooser.show() response = chooser.run() if response == gtk.RESPONSE_OK: self.filename = chooser.get_filename() if os.path.exists(self.filename): overwrite = confirmDialog(self, "This file already exists. Overwrite this file?") if overwrite == gtk.RESPONSE_YES: self.writeFile() chooser.destroy() return True else: self.filename = None chooser.destroy() return False else: self.writeFile() chooser.destroy() return True else: self.filename = None chooser.destroy() return False
def savePrompt(self): """Prompt the user to save before creating a new file.""" if confirmDialog(self, "Save current config?") == gtk.RESPONSE_YES: self.save(None)
def mess_yesno(mess, title = ""): return mess_with_buttons(mess, (gtk.STOCK_YES, gtk.RESPONSE_YES, \ gtk.STOCK_NO, gtk.RESPONSE_NO), title) == gtk.RESPONSE_YES
def question(msg, window=None): if mac: response = macutils.question(msg) return response else: dialog = gtk.MessageDialog(window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_NONE, msg) dialog.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO) dialog.set_default_response(gtk.RESPONSE_NO) dialog.set_skip_taskbar_hint(False) response = dialog.run() dialog.destroy() return response in (gtk.RESPONSE_OK, gtk.RESPONSE_YES)
def apply(self, widget, event=None, confirmChange=True): """Applies the current config to tint2.""" # Check if tint2 is running procs = os.popen('pgrep -x "tint2"') # Check list of active processes for tint2 pids = [] # List of process ids for tint2 for proc in procs.readlines(): pids += [int(proc.strip().split(" ")[0])] procs.close() if self.oneConfigFile: # Save and copy as default self.save() tmpSrc = self.filename tmpDest = os.path.expandvars("${HOME}") + "/.config/tint2/tint2rc" try: shutil.copyfile(tmpSrc, tmpDest) except shutil.Error: pass # Ask tint2 to reload config for pid in pids: os.kill(pid, signal.SIGUSR1) else: if confirmDialog(self, "This will terminate all currently running instances of tint2 before applying config. Continue?") == gtk.RESPONSE_YES: if not self.save(): return #shutil.copyfile(self.filename, self.filename+".backup") # Create backup # If it is - kill it for pid in pids: os.kill(pid, signal.SIGTERM) # Lastly, start it os.spawnv(os.P_NOWAIT, self.tint2Bin, [self.tint2Bin, "-c", self.filename]) if confirmChange and self.filename != (os.path.expandvars("${HOME}") + "/.config/tint2/tint2rc") and confirmDialog(self, "Use this as default tint2 config?") == gtk.RESPONSE_YES: tmp = self.filename self.filename = os.path.expandvars("${HOME}") + "/.config/tint2/tint2rc" try: shutil.copyfile(tmp, self.filename) except shutil.Error: pass #if confirmChange and confirmDialog(self, "Keep this config?") == gtk.RESPONSE_NO: # shutil.copyfile(self.filename+".backup", self.filename) # Create backup # self.apply(widget, event, False)
def do_test(self, domsgbox=True): global myconfig self._tmp_home = None home_dir, config_name = gconsole.check_args() if not (config_name.find('/') >= 0 or config_name.find('\\') >= 0): config_name = os.path.join(home_dir, config_name) log.debug("config file used: %s", config_name) myconfig = config.Config(file=config_name) initialize.locations(self, home_dir) gettext.install('griffith', self.locations['i18n'], unicode=1) search_successful = '' search_unsuccessful = '' get_successful = '' get_unsuccessful = '' # test all plugins ? test_all = True dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_NONE, 'Test all plugins ?') dialog.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO) dialog.set_default_response(gtk.RESPONSE_NO) dialog.set_skip_taskbar_hint(False) response = dialog.run() dialog.destroy() if not response == gtk.RESPONSE_YES: test_all = False # iterate through all testable plugins for i in self.test_plugins: if domsgbox and test_all == False: # ask for test of that specific plugin dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_NONE, 'Test plugin %s ?' %i) dialog.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO) dialog.set_default_response(gtk.RESPONSE_NO) dialog.set_skip_taskbar_hint(False) response = dialog.run() dialog.destroy() if not response == gtk.RESPONSE_YES: continue print "Starting test of plugin: %s" % i plugin = __import__(i) # search test if self.do_test_searchplugin(i, False): search_successful = search_successful + i + ', ' else: search_unsuccessful = search_unsuccessful + i + ', ' # movie test if self.do_test_plugin(i, False): get_successful = get_successful + i + ', ' else: get_unsuccessful = get_unsuccessful + i + ', ' if domsgbox: gutils.info('SearchPluginTests\n Success: %s\n Failed: %s\n\nPluginTests\n Success: %s\n Failed: %s' % (search_successful, search_unsuccessful, get_successful, get_unsuccessful)) # # Start the tests #
def do_close(self, tab_child=None): if tab_child: eset = tab_child else: eset = self.get_current_editorset() if not eset: return False if eset.is_modified(): dlg = miscwidgets.YesNoDialog( title=_("Save Changes?"), parent=self, buttons=(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) dlg.set_text(_("File is modified, save changes before closing?")) res = dlg.run() dlg.destroy() if res == gtk.RESPONSE_YES: self.do_save(eset) elif res != gtk.RESPONSE_NO: raise ModifiedError() eset.rthread.stop() eset.rthread.join() eset.prepare_close() if eset.radio.pipe: eset.radio.pipe.close() if isinstance(eset.radio, chirp_common.LiveRadio): action = self.menu_ag.get_action("openlive") if action: action.set_sensitive(True) page = self.tabs.page_num(eset) if page is not None: self.tabs.remove_page(page) return True