我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用gtk.MESSAGE_WARNING。
def update_view_timeout(self): #print "view: update_view_timeout called at real time ", time.time() # while the simulator is busy, run the gtk event loop while not self.simulation.lock.acquire(False): while gtk.events_pending(): gtk.main_iteration() pause_messages = self.simulation.pause_messages self.simulation.pause_messages = [] try: self.update_view() self.simulation.target_time = ns.core.Simulator.Now ().GetSeconds () + self.sample_period #print "view: target time set to %f" % self.simulation.target_time finally: self.simulation.lock.release() if pause_messages: #print pause_messages dialog = gtk.MessageDialog(parent=self.window, flags=0, type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK, message_format='\n'.join(pause_messages)) dialog.connect("response", lambda d, r: d.destroy()) dialog.show() self.play_button.set_active(False) # if we're paused, stop the update timer if not self.play_button.get_active(): self._update_timeout_id = None return False #print "view: self.simulation.go.set()" self.simulation.go.set() #print "view: done." return True
def open_window(self, url): url = address_bar.get_text() for letter in url: if '.' not in url: a = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CANCEL) a.set_markup("<big><b>WTF!?!? Thats not even a website?</b></big>") a.run() return if 'http://' not in url: w = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK) w.set_markup("<big><b>**mumble, mumble** Force to change {} to {}</b></big>".format(url, 'http://'+url+'/')) w.run() url = 'http://'+url+'/' os.system('python Web-Window.py '+url)
def warning_message(self, msg): msgdlg = self.get('msgdlg') msgdlg.set_property("message-type", gtk.MESSAGE_WARNING) msgdlg.set_transient_for(self.dlg) msgdlg.set_title(_("Warning")) msgdlg.set_markup(msg) msgdlg.show_all()
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 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 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 show_warning(msg, text, parent=None, buttons=None, title="Warning", can_squelch=False): if buttons is None: buttons = gtk.BUTTONS_OK d = gtk.MessageDialog(buttons=buttons, parent=parent, type=gtk.MESSAGE_WARNING) d.set_title(title) d.set_property("text", msg) l = gtk.Label(_("Details") + ":") l.show() d.vbox.pack_start(l, 0, 0, 0) l = gtk.Label(_("Proceed?")) l.show() d.get_action_area().pack_start(l, 0, 0, 0) d.get_action_area().reorder_child(l, 0) textview = _add_text(d, text) textview.set_wrap_mode(gtk.WRAP_WORD) if not parent: d.set_position(gtk.WIN_POS_CENTER_ALWAYS) if can_squelch: cb = gtk.CheckButton(_("Do not show this next time")) cb.show() d.vbox.pack_start(cb, 0, 0, 0) d.set_size_request(600, 400) r = d.run() d.destroy() if can_squelch: return r, cb.get_active() return r
def _info(type, value, tb): """display exception""" #ungrab a potentially "grabbed" mouse pointer gtk.gdk.pointer_ungrab() #create dialog dialog = gtk.MessageDialog( parent = None, flags = 0, type = gtk.MESSAGE_WARNING, buttons = gtk.BUTTONS_NONE, message_format = _("<big><b>Error</b></big>")) dialog.set_title(_("Bug Detected")) dialog.vbox.get_children()[0].get_children()[1].get_children()[0].set_property("use-markup", True) dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) #details textview = gtk.TextView() textview.show() textview.set_editable(False) textview.modify_font(pango.FontDescription("Monospace")) sw = gtk.ScrolledWindow() sw.show() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add(textview) frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_IN) frame.add(sw) frame.set_border_width(6) dialog.vbox.add(frame) textbuffer = textview.get_buffer() trace = StringIO.StringIO() traceback.print_exception(type, value, tb, None, trace) textbuffer.set_text(trace.getvalue()) textview.set_size_request(gtk.gdk.screen_width()/2, gtk.gdk.screen_height()/3) dialog.details = frame dialog.set_position(gtk.WIN_POS_CENTER) dialog.set_gravity(gtk.gdk.GRAVITY_CENTER) dialog.details.show() #display the dialog resp = dialog.run() if resp == gtk.RESPONSE_CLOSE: pass dialog.destroy() sys.exit(1) #sys.excepthook = _info