本文整理汇总了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()
示例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
示例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()
示例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()
示例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()
示例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)
示例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)
示例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
示例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
示例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
示例11: __init__
def __init__(self, title, message):
self.nsalert = NSAlert.alloc().init()
self.nsalert.setAlertStyle_(NSInformationalAlertStyle)
self.nsalert.setMessageText_(title)
self.nsalert.setInformativeText_(message)