當前位置: 首頁>>代碼示例>>Python>>正文


Python AppKit.NSAlert類代碼示例

本文整理匯總了Python中AppKit.NSAlert的典型用法代碼示例。如果您正苦於以下問題:Python NSAlert類的具體用法?Python NSAlert怎麽用?Python NSAlert使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了NSAlert類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: alert

def alert(title=None, message='', ok=None, cancel=None):
    """Generate a simple alert window.

    .. versionchanged:: 0.2.0
        Providing a `cancel` string will set the button text rather than only using text "Cancel". `title` is no longer
        a required parameter.

    :param title: the text positioned at the top of the window in larger font. If ``None``, a default localized title
                  is used. If not ``None`` or a string, will use the string representation of the object.
    :param message: the text positioned below the `title` in smaller font. If not a string, will use the string
                    representation of the object.
    :param ok: the text for the "ok" button. Must be either a string or ``None``. If ``None``, a default
               localized button title will be used.
    :param cancel: the text for the "cancel" button. If a string, the button will have that text. If `cancel`
                   evaluates to ``True``, will create a button with text "Cancel". Otherwise, this button will not be
                   created.
    :return: a number representing the button pressed. The "ok" button is ``1`` and "cancel" is ``0``.
    """
    message = unicode(message)
    if title is not None:
        title = unicode(title)
    _require_string_or_none(ok)
    if not isinstance(cancel, basestring):
        cancel = 'Cancel' if cancel else None
    alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
        title, ok, cancel, None, message)
    alert.setAlertStyle_(0)  # informational style
    _log('alert opened with message: {0}, title: {1}'.format(repr(message), repr(title)))
    return alert.runModal()
開發者ID:4m1g0,項目名稱:duplicati,代碼行數:29,代碼來源:rumps.py

示例2: displayAlert

def displayAlert(message, info, buttons):
	alert = NSAlert.alloc().init()
	alert.setMessageText_(message)
	alert.setInformativeText_(info)
	alert.setAlertStyle_(NSInformationalAlertStyle)
	for button in buttons:
		alert.addButtonWithTitle_(button)
	NSApp.activateIgnoringOtherApps_(True)	
	buttonPressed = alert.runModal()
	return buttonPressed
開發者ID:benwiggy,項目名稱:PDFsuite,代碼行數:10,代碼來源:countpages.py

示例3: alert

def alert(title, message='', ok=None, cancel=False):
    """
    Simple alert window.
    """
    message = str(message)
    title = str(title)
    alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
        title, ok, 'Cancel' if cancel else None, None, message)
    alert.setAlertStyle_(0)  # informational style
    _log('alert opened with message: {}, title: {}'.format(repr(message), repr(title)))
    return alert.runModal()
開發者ID:philippeowagner,項目名稱:rumps,代碼行數:11,代碼來源:rumps.py

示例4: display_alert

def display_alert(title, message):
    """Display a warning alert with the given ``title`` and ``message``.

    :param str title: the big bold title
    :param str message: the body of the alert
    """
    alert = NSAlert.alloc().init()
    alert.setAlertStyle_(NSWarningAlertStyle)
    alert.setMessageText_(title)
    alert.setInformativeText_(message)
    NSApp.activateIgnoringOtherApps_(True)
    alert.runModal()
開發者ID:kennydo,項目名稱:rename-archive-extension,代碼行數:12,代碼來源:RenameArchiveService.py

示例5: log_std

def log_std(msg):
	from AppKit import NSAlert, NSInformationalAlertStyle, NSRunningApplication, NSApplicationActivateIgnoringOtherApps

	# initialize
	# tip from: http://graphicsnotes.blogspot.fr/2010/01/programmatically-creating-window-in-mac.html
	NSApplication.sharedApplication()
	NSRunningApplication.currentApplication().activateWithOptions_(NSApplicationActivateIgnoringOtherApps);

	alert = NSAlert.alloc().init()
	alert.autorelease()
	alert.setAlertStyle_(NSInformationalAlertStyle)
	alert.setMessageText_(msg)
	alert.runModal()
開發者ID:ChennyBaBy,項目名稱:bin-scripts,代碼行數:13,代碼來源:export-current-omnigraffle-canvas.py

示例6: __init__

    def __init__(self, message, title='', default_text='', ok=None, cancel=False, dimensions=(320, 160)):
        message = str(message)
        title = str(title)
        self._default_text = default_text
        self._cancel = bool(cancel)
        self._icon = None

        self._alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
            title, ok, 'Cancel' if cancel else None, None, message)
        self._alert.setAlertStyle_(0)  # informational style

        self._textfield = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 0, *dimensions))
        self._textfield.setSelectable_(True)
        if default_text:
            self._textfield.setStringValue_(default_text)
        self._alert.setAccessoryView_(self._textfield)
開發者ID:philippeowagner,項目名稱:rumps,代碼行數:16,代碼來源:rumps.py

示例7: __init__

    def __init__(self):
        ''' initializes an alert with custom view containing username and
            password fields with a save to keychain checkbox'''
        # Create an dialog with ok and cancel buttons
        self.alert = NSAlert.alloc().init()
        self.alert.setMessageText_('Please enter your username and password!')
        self.alert.addButtonWithTitle_('Ok')
        self.alert.addButtonWithTitle_('Cancel')

        # create the view for username and password fields
        accessory_view = NSView.alloc().initWithFrame_(NSMakeRect(0, 114, 250, 110))

        # setup username field and label
        self.username_field = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 70, 250, 22))
        username_label = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 94, 250, 20))
        username_label.setStringValue_('Username:')
        username_label.setBezeled_(False)
        username_label.setDrawsBackground_(False)
        username_label.setEditable_(False)
        username_label.setSelectable_(False)

        # setup password field and label
        self.password_field = NSSecureTextField.alloc().initWithFrame_(NSMakeRect(0, 24, 250, 22))
        password_label = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 48, 250, 20))
        password_label.setStringValue_('Password:')
        password_label.setBezeled_(False)
        password_label.setDrawsBackground_(False)
        password_label.setEditable_(False)
        password_label.setSelectable_(False)

        # setup keychain checkbox and label
        self.keychain_checkbox = NSButton.alloc().initWithFrame_(NSMakeRect(0, 0, 200, 20))
        self.keychain_checkbox.setButtonType_(NSSwitchButton)
        self.keychain_checkbox.cell().setTitle_('Save to Keychain')
        self.keychain_checkbox.cell().setBordered_(False)
        self.keychain_checkbox.cell().setEnabled_(True)
        self.keychain_checkbox.cell().setState_(True)

        # add various objects as subviews
        accessory_view.addSubview_(self.keychain_checkbox)
        accessory_view.addSubview_(username_label)
        accessory_view.addSubview_(self.username_field)
        accessory_view.addSubview_(password_label)
        accessory_view.addSubview_(self.password_field)

        # add custom view to alert dialog
        self.alert.setAccessoryView_(accessory_view)
開發者ID:kylecrawshaw,項目名稱:ShareMounter,代碼行數:47,代碼來源:PyDialog.py

示例8: __init__

    def __init__(self, message='', title='', default_text='', ok=None, cancel=None, dimensions=(320, 160)):
        message = unicode(message)
        title = unicode(title)

        self._cancel = bool(cancel)
        self._icon = None

        _require_string_or_none(ok)
        if not isinstance(cancel, basestring):
            cancel = 'Cancel' if cancel else None

        self._alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
            title, ok, cancel, None, message)
        self._alert.setAlertStyle_(0)  # informational style

        self._textfield = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 0, *dimensions))
        self._textfield.setSelectable_(True)
        self._alert.setAccessoryView_(self._textfield)

        self.default_text = default_text
開發者ID:4m1g0,項目名稱:duplicati,代碼行數:20,代碼來源:rumps.py

示例9: initWithMessageText_informativeText_alertStyle_buttonTitlesValues_window_resultCallback_

    def initWithMessageText_informativeText_alertStyle_buttonTitlesValues_window_resultCallback_(self,
        messageText="", informativeText="", alertStyle=NSInformationalAlertStyle, buttonTitlesValues=[], parentWindow=None, resultCallback=None):

        self = super(BaseMessageDialog, self).init()
        self.retain()
        self._resultCallback = resultCallback
        self._buttonTitlesValues = buttonTitlesValues
        #
        alert = NSAlert.alloc().init()
        alert.setMessageText_(messageText)
        alert.setInformativeText_(informativeText)
        alert.setAlertStyle_(alertStyle)
        for buttonTitle, value in buttonTitlesValues:
            alert.addButtonWithTitle_(buttonTitle)
        self._value = None
        if parentWindow is None:
            code = alert.runModal()
            self._translateValue(code)
        else:
            alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(parentWindow, self, "alertDidEnd:returnCode:contextInfo:", 0)
        return self
開發者ID:schriftgestalt,項目名稱:vanilla,代碼行數:21,代碼來源:dialogs.py

示例10: initWithMessageText_informativeText_alertStyle_buttonTitlesValues_window_resultCallback_

 def initWithMessageText_informativeText_alertStyle_buttonTitlesValues_window_resultCallback_(self,
         messageText="",
         informativeText="", 
         alertStyle=NSInformationalAlertStyle,
         buttonTitlesValues=None,
         parentWindow=None,
         resultCallback=None):
     if buttonTitlesValues is None:
         buttonTitlesValues = []
     self = super(BaseMessageDialog, self).init()
     self.retain()
     self._resultCallback = resultCallback
     self._buttonTitlesValues = buttonTitlesValues
     #
     alert = NSAlert.alloc().init()
     alert.setMessageText_(messageText)
     alert.setInformativeText_(informativeText)
     alert.setAlertStyle_(alertStyle)
     for buttonTitle, value in buttonTitlesValues:
         alert.addButtonWithTitle_(buttonTitle)
     self._value = None
     code = alert.runModal()
     self._translateValue(code)
     return self
開發者ID:anthrotype,項目名稱:robofab,代碼行數:24,代碼來源:dialogs_fontlab_legacy2.py

示例11: __init__

 def __init__(self, title, message):
     self.nsalert = NSAlert.alloc().init()
     self.nsalert.setAlertStyle_(NSInformationalAlertStyle)
     self.nsalert.setMessageText_(title)
     self.nsalert.setInformativeText_(message)
開發者ID:xoconusco,項目名稱:verano16,代碼行數:5,代碼來源:osx_panel.py


注:本文中的AppKit.NSAlert類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。