我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用gtk.DIALOG_MODAL。
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 connectionLost(self, reason): if len(self.buffer) == 0: dialog = gtk.MessageDialog(self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "An error occurred; file could not be retrieved.") dialog.run() dialog.destroy() return fd = gtk.FileChooserDialog(title=None, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK)) fd.set_default_response(gtk.RESPONSE_OK) fd.set_current_name(self.filename) response = fd.run() if response == gtk.RESPONSE_OK: destfilename = fd.get_filename() f = open(destfilename, 'w') f.write(self.buffer) f.close() fd.destroy()
def delete_format(self, widget, data=None): # ???? ???????? gtk.RadioButton for format_id in self.format_radio: if format_id.get_active(): # ?????????? ??????, ? ??????? ???????? ???????????? ?????????? ???? ????? dialog = gtk.Dialog('???????? ??????? "' + self.data['formats'][self.format_radio.index(format_id)]['name'] + '"', self.window, gtk.DIALOG_NO_SEPARATOR | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_NO, gtk.RESPONSE_CANCEL, gtk.STOCK_YES, gtk.RESPONSE_OK)) dialog.set_position(gtk.WIN_POS_CENTER_ALWAYS) dialog.set_resizable(False) dialog.set_border_width(10) self.confirmation_label = gtk.Label('?? ????????????? ?????? ??????? ?????? "' + self.data['formats'][self.format_radio.index(format_id)]['name'] + '"?') dialog.vbox.pack_start(self.confirmation_label, True, True, 5) dialog.show_all() response = dialog.run() if response == gtk.RESPONSE_CANCEL: dialog.hide() dialog.destroy() if response == gtk.RESPONSE_OK: # ??????? ?????? name = self.data['formats'][self.format_radio.index(format_id)]['name'] del self.data['formats'][self.format_radio.index(format_id)] config = open(self.path, 'wb') json.dump(self.data, config) config.close() self.format_radio[self.format_radio.index(format_id)].hide() if len(self.format_radio) == 1: pass elif self.format_radio.index(format_id) + 1 <= len(self.format_radio) - 1: self.format_radio[self.format_radio.index(format_id) + 1].set_active(True) elif self.format_radio.index(format_id) + 1 > len(self.format_radio) - 1: self.format_radio[self.format_radio.index(format_id) - 1].set_active(True) del self.format_radio[self.format_radio.index(format_id)] if len(self.format_radio) < 1: self.delete_button.set_sensitive(False) self.edit_button.set_sensitive(False) self.add_success_label.set_markup('<span foreground="#008600">"' + str(name) + '" ??????? ??????\n</span>') dialog.hide() dialog.destroy() break # ??? ??????? ???????????? ?????????? ?????? ???????
def get_password(self,parent): dialog = gtk.Dialog("Configure System Password",parent,gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,(gtk.STOCK_CANCEL,gtk.RESPONSE_REJECT,gtk.STOCK_OK,gtk.RESPONSE_ACCEPT)) self.pass1 = gtk.HBox() self.label1 = gtk.Label(" Passsword: ") self.pass1.pack_start(self.label1,False,True,0) self.password1 = gtk.Entry() self.password1.set_visibility(False) self.pass1.pack_start(self.password1,False,True,0) dialog.vbox.add(self.pass1) self.pass2 = gtk.HBox() self.label2 = gtk.Label(" Verify Password: ") self.pass2.pack_start(self.label2,False,True,0) self.password2 = gtk.Entry() self.password2.set_visibility(False) self.pass2.pack_start(self.password2,False,True,0) dialog.vbox.add(self.pass2) dialog.show_all() response = dialog.run() if response == gtk.RESPONSE_ACCEPT: self.a = self.password1.get_text() self.b = self.password2.get_text() dialog.destroy() else: self.a = '' self.b = '' dialog.destroy() # Configure Network Dialog
def exitfc_button_cb(self, button): label = gtk.Label("Are you sure you want the FC to exit?") dialog = gtk.Dialog("Confirm Exit", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.vbox.pack_start(label) label.show() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_ACCEPT: msg = ZarjExitCommand() self.zarj_comm.push_message(msg)
def confirmDialog(parent=None, message="Confirm?"): """Creates a confirmation dialog and returns the response.""" dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, message) dialog.show() response = dialog.run() dialog.destroy() return response
def errorDialog(parent=None, message="An error has occured!"): """Creates an error dialog.""" dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message) dialog.show() dialog.run() dialog.destroy()
def show_about(self, widget): dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, """ PiJuice battery level status """) dialog.run() dialog.destroy()
def downloadFile(self, treeView, path, column): model = treeView.get_model() iter = model.get_iter(path) filename = model.get(iter, 0)[0] h = hashlib.sha1() h.update(filename) key = h.digest() def getTargetNode(result): targetNodeID = result[key] df = self.node.findContact(targetNodeID) return df def getFile(protocol): if protocol != None: protocol.requestFile(filename, self) def connectToPeer(contact): if contact == None: dialog = gtk.MessageDialog(self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "File could not be retrieved.\nThe host that published this file is no longer on-line.") dialog.run() dialog.destroy() else: c = ClientCreator(twisted.internet.reactor, FileGetter) df = c.connectTCP(contact.address, contact.port) return df df = self.node.iterativeFindValue(key) df.addCallback(getTargetNode) df.addCallback(connectToPeer) df.addCallback(getFile)
def _tupleFromStr(self, text): tp = None try: exec 'tp = %s' % text if type(tp) != tuple: raise Exception except Exception: dialog = gtk.MessageDialog(self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Please enter a valid Python tuple,\ne.g. (1, 'abc', 3.14)") dialog.set_title('Error') dialog.run() dialog.destroy() finally: return tp
def gui_message_box(self, message): dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, \ gtk.BUTTONS_NONE, message) dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) dialog.run() dialog.destroy()
def mess_dlg(mess, title = "NativeCAM"): dlg = gtk.MessageDialog(parent = None, flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, type = gtk.MESSAGE_WARNING, buttons = gtk.BUTTONS_OK, message_format = '%s' % mess) dlg.set_title(title) dlg.set_keep_above(True) dlg.run() dlg.destroy()
def mess_with_buttons(mess, buttons, title = ""): mwb = gtk.Dialog(parent = None, buttons = buttons, flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, ) mwb.set_title(title) finbox = mwb.get_content_area() l = gtk.Label(mess) finbox.pack_start(l) mwb.set_keep_above(True) mwb.show_all() response = mwb.run() mwb.hide() mwb.destroy() return response
def create_M_file() : p = os.path.join(NCAM_DIR, NGC_DIR, 'M123') with open(p, 'wb') as f : f.write('#!/usr/bin/env python\n# coding: utf-8\n') f.write("import gtk\nimport os\nimport pygtk\npygtk.require('2.0')\nfrom gtk import gdk\n\n") f.write("fname = '%s'\n" % os.path.join(NCAM_DIR, CATALOGS_DIR, 'no_skip_dlg.conf')) f.write('if os.path.isfile(fname) :\n exit(0)\n\n') f.write("msg = '%s'\n" % _('Stop LinuxCNC program, toggle the shown button, then restart')) f.write("msg1 = '%s'\n" % _('Skip block not active')) f.write("icon_fname = '%s'\n\n" % os.path.join(NCAM_DIR, GRAPHICS_DIR, 'skip_block.png')) f.write('dlg = gtk.MessageDialog(parent = None, flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, type = gtk.MESSAGE_WARNING, buttons = gtk.BUTTONS_NONE, message_format = msg1)\n\n') f.write("dlg.set_title('NativeCAM')\ndlg.format_secondary_markup(msg)\n\n") f.write('dlg.set_image(gtk.Image())\n') f.write('dlg.get_image().set_from_pixbuf(gdk.pixbuf_new_from_file_at_size(icon_fname, 80, 80))\n\n') f.write('cb = gtk.CheckButton(label = "%s")\n' % _("Do not show again")) f.write('dlg.get_content_area().pack_start(cb, True, True, 0)\n') f.write('dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK).grab_focus()\n\n') f.write('dlg.set_keep_above(True)\ndlg.show_all()\n\ndlg.run()\n') f.write("if cb.get_active() :\n open(fname, 'w').close()\n") f.write('exit(0)\n') os.chmod(p, 0o755) mess_dlg(_('LinuxCNC needs to be restarted now'))
def msg_inv(self, msg, msgid): msg = msg.replace('°', '°') print('\n%(feature_name)s : %(msg)s' % {'feature_name':self.get_name(), 'msg':msg}) if (("ALL:msgid-0" in EXCL_MESSAGES) or ("%s:msgid-0" % (self.get_type()) in EXCL_MESSAGES) or (("%s:msgid-%d" % (self.get_type(), msgid)) in EXCL_MESSAGES)) : return # create dialog with image and checkbox dlg = gtk.MessageDialog(parent = None, flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, type = gtk.MESSAGE_WARNING, buttons = gtk.BUTTONS_NONE, message_format = self.get_name()) dlg.set_title('NativeCAM') dlg.format_secondary_text(msg) img = gtk.Image() img.set_from_pixbuf(self.get_icon(add_dlg_icon_size)) dlg.set_image(img) cb = gtk.CheckButton(label = _("Do not show again")) dlg.get_content_area().pack_start(cb, True, True, 0) dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK).grab_focus() dlg.set_keep_above(True) dlg.show_all() dlg.run() if cb.get_active() : GLOBAL_PREF.add_excluded_msg(self.get_type(), msgid) dlg.destroy()
def action_renameF(self, *arg): self.newnamedlg = gtk.MessageDialog(parent = None, flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, type = gtk.MESSAGE_QUESTION, buttons = gtk.BUTTONS_OK_CANCEL ) old_name = self.selected_feature.get_attr('name') self.newnamedlg.set_markup(_('Enter new name for')) self.newnamedlg.format_secondary_markup(old_name) self.newnamedlg.set_title('NativeCAM') edit_entry = gtk.Entry() edit_entry.set_editable(True) edit_entry.set_text(old_name) edit_entry.connect('key-press-event', self.action_rename_keyhandler) self.newnamedlg.vbox.add(edit_entry) self.newnamedlg.set_keep_above(True) (tree_x, tree_y) = self.treeview.get_bin_window().get_origin() self.newnamedlg.move(tree_x, tree_y + self.click_y) self.newnamedlg.show_all() response = self.newnamedlg.run() if (response == gtk.RESPONSE_OK) : newname = edit_entry.get_text().lstrip(' ') if newname > '' : self.selected_feature.attr['name'] = newname self.refresh_views() self.newnamedlg.destroy()
def __init__(self, window, title='', message=''): self.status = False self.dialog = gtk.Dialog(title, window, gtk.DIALOG_MODAL, ()) self.dialog.set_urgency_hint(False) self.label = gtk.Label() self.label.set_markup(message) self.dialog.vbox.pack_start(self.label) self.progress = gtk.ProgressBar() self.progress.set_pulse_step(0.01) self.dialog.vbox.pack_start(self.progress, False, False) self.button = gtk.Button(_("Cancel"), gtk.STOCK_CANCEL) self.button.connect("clicked", self.callback) self.dialog.vbox.pack_start(self.button, False, False) self.dialog.show_all()
def __init__(self, window): self.dialog = gtk.Dialog('Debug Window', window, gtk.DIALOG_MODAL, ()) self.dialog.set_destroy_with_parent(True) self.dialog.set_transient_for(window) self.dialog.set_modal(False) self.textview = gtk.TextView() self.textview.set_editable(False) self.textview.set_wrap_mode(gtk.WRAP_WORD_CHAR) self.textview.set_scroll_adjustments(gtk.Adjustment(1.0, 1.0, 100.0, 1.0, 10.0, 10.0), gtk.Adjustment(1.0, 1.0, 100.0, 1.0, 10.0, 10.0)) self.scrolledwindow = gtk.ScrolledWindow(None, None) self.scrolledwindow.add(self.textview) self.dialog.vbox.pack_start(self.scrolledwindow) self.dialog.set_default_size(640, 480)
def error(msg, parent=None): dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg) dialog.set_skip_taskbar_hint(False) dialog.run() dialog.destroy()
def urllib_error(msg, parent=None): dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg) dialog.set_skip_taskbar_hint(False) dialog.run() dialog.destroy()
def warning(msg, parent=None): if mac: macutils.createAlert(msg) else: dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, msg) dialog.set_skip_taskbar_hint(False) dialog.run() dialog.destroy()
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 msgbox(text, parent=None): msgBox = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, text) msgBox.set_icon_from_file(ICON_PATH) msgBox.run() msgBox.destroy()
def msgconfirm(text): msgBox = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, text) msgBox.set_icon_from_file(ICON_PATH) response = msgBox.run() msgBox.destroy() return response
def msg(self, text, parent): self.msgBox = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, text) self.msgBox.set_icon_from_file(ICON_PATH) self.msgBox.connect('response', self.on_clicked) self.msgBox.show_all() return False
def __init__(self, settings=None, parent=None, title=_("Radio")): buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK) gtk.Dialog.__init__(self, title, parent=parent, flags=gtk.DIALOG_MODAL) self.__make_ui(settings) self.__cancel_button = self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.__okay_button = self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) self.__okay_button.grab_default() self.__okay_button.grab_focus()
def save_shot(self): # create a new window dialog = gtk.Dialog("Manual ScreenShot", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.set_size_request(400, 250) dialog.set_title("Manual ScreenShot Comment ECEL V2.0") table = gtk.Table(5,2,False) table.show() # create ip row ipLabel = gtk.Label("IP") ipEntry = gtk.Entry() table.attach(ipLabel, 0, 1, 0, 1) table.attach(ipEntry, 1, 2, 0, 1) ipLabel.show() ipEntry.show() # create Port row portLabel = gtk.Label("Port") portEntry = gtk.Entry() table.attach(portLabel, 0, 1, 1, 2) table.attach(portEntry, 1, 2, 1, 2) portLabel.show() portEntry.show() # create initial row initialLabel = gtk.Label("Initials") initialEntry = gtk.Entry() table.attach(initialLabel, 0, 1, 2, 3) table.attach(initialEntry, 1, 2, 2, 3) initialLabel.show() initialEntry.show() #create the comment entry field maxChar = 64 commentEntry = gtk.Entry() commentEntry.set_max_length(maxChar) commentEntry.insert_text("Enter Comment") commentEntry.select_region(0, len(commentEntry.get_text())) table.attach(commentEntry, 0, 2, 3, 4) commentEntry.show() dialog.vbox.pack_start(table) response = dialog.run() self.ip_entry_text = ipEntry.get_text() self.port_entry_text = portEntry.get_text() self.initial_entry_text = initialEntry.get_text() self.comment_entry_text = commentEntry.get_text() dialog.hide_all() dialog.destroy() return response
def cb_ok(self, widget, data=None): buf = self._text.get_buffer() self.text = buf.get_text(buf.get_start_iter(), buf.get_end_iter()) if isinstance(self._preamble, gtk.FileChooser): self.preamble_file = self._preamble.get_filename() if not self.preamble_file: self.preamble_file = "" else: self.preamble_file = self._preamble.get_text() if self.scale_factor is not None: self.scale_factor = self._scale_adj.get_value() try: self.callback(self.text, self.preamble_file, self.scale_factor) except StandardError, e: err_msg = traceback.format_exc() dlg = gtk.Dialog("Textext Error", self._window, gtk.DIALOG_MODAL) dlg.set_default_size(600, 400) btn = dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_CLOSE) btn.connect("clicked", lambda w, d=None: dlg.destroy()) msg = gtk.Label() msg.set_markup("<b>Error occurred while converting text from Latex to SVG:</b>") txtw = gtk.ScrolledWindow() txtw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) txtw.set_shadow_type(gtk.SHADOW_IN) txt = gtk.TextView() txt.set_editable(False) txt.get_buffer().set_text(err_msg) txtw.add(txt) dlg.vbox.pack_start(msg, expand=False, fill=True) dlg.vbox.pack_start(txtw, expand=True, fill=True) dlg.show_all() dlg.run() return False gtk.main_quit() return 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 #