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) if self._resultCallback is not None: self._resultCallback(self._value) else: alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_( parentWindow, self, "alertDidEnd:returnCode:contextInfo:", 0) return self
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
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 # self.alert = NSAlert.alloc().init() self.alert.setMessageText_(messageText) self.alert.setInformativeText_(informativeText) self.alert.setAlertStyle_(alertStyle) for buttonTitle, value in buttonTitlesValues: self.alert.addButtonWithTitle_(buttonTitle) self._value = None if parentWindow is None: code = self.alert.runModal() self._translateValue(code) if self._resultCallback is not None: self._resultCallback(self._value) else: self.alert.beginSheetModalForWindow_completionHandler_( parentWindow, self.completionHandler_) return self
def run(self): self.alert = NSAlert.alloc().init() self.alert.setDelegate_(self) self.alert.setMessageText_(self.messageText) self.alert.setInformativeText_(self.informativeText) self.alert.setAlertStyle_(self.alertStyle) if self.accessoryView: self.alert.setAccessoryView_(self.accessoryView) if self.icon: self.alert.setIcon_(self.icon) if self.showsHelpCallback: self.alert.setShowsHelp_(True) for buttonTitle in self.buttonTitlesValues: self.alert.addButtonWithTitle_(buttonTitle["title"]) self._value = None if self._parentWindow is None: code = self.alert.runModal() self._translateValue(code) if self._resultCallback is not None: self._resultCallback(self._value) else: self.alert.beginSheetModalForWindow_completionHandler_( self._parentWindow, self.completionHandler_)
def __init__(self, title, message, icon=None, hide_dock=True, buttons=None): if hide_dock: self.hide_dock_icon() self.alert = NSAlert.alloc().init() self.alert.setTitle_andMessage_(title, message) self.alert.addButtonWithTitle_('OK') if icon: icon_image = NSImage.alloc().initWithContentsOfFile_(icon) self.alert.setIcon_(icon_image)
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
def runAndStop_(self, timer): self.alert = NSAlert.alloc().init() self.alert.setAlertStyle_(NSInformationalAlertStyle) self.alert.setMessageText_(self.message) if self.buttons is None: self.alert.addButtonWithTitle_('OK') else: for x in self.buttons: self.alert.addButtonWithTitle_(x) NSApp.activateIgnoringOtherApps_(True) self.result_code = self.alert.runModal() NSApp.stop_(None)
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()
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:'******'Password:'******'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)
def windowShouldClose_(self, sender): if self._controller.done: self._controller.do_finish() else: alert = NSAlert.alloc().init() alert.addButtonWithTitle_(WizkitStrings.ok_text) alert.addButtonWithTitle_(WizkitStrings.cancel_text) alert.setInformativeText_(WizkitStrings.exit_wizard_prompt) alert.setMessageText_(WizkitStrings.exit_wizard_caption) alert.setAlertStyle_(NSCriticalAlertStyle) alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(self, self, self.alertDidEnd_returnCode_contextInfo_.selector, 0) return objc.NO
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()
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:'******'Password:'******'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)
def displayAlert(self): alert = NSAlert.alloc().init() alert.setMessageText_(self.messageText) alert.setInformativeText_(self.informativeText) alert.setAlertStyle_(NSInformationalAlertStyle) for button in self.buttons: alert.addButtonWithTitle_(button) if os.path.exists(alertIconPath): icon = NSImage.alloc().initWithContentsOfFile_(alertIconPath) alert.setIcon_(icon) # Don't show the Python rocketship in the dock NSApp.setActivationPolicy_(1) NSApp.activateIgnoringOtherApps_(True) alert.runModal()
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
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
def __init__(self, title, message): self.alert = NSAlert.alloc().init() self.alert.setTitle_andMessage_(title, message) self.button_return = None
def showAlert(messageText, InformativeText=""): alert = NSAlert.alloc().init() alert.setMessageText_(messageText) alert.setInformativeText_(InformativeText) alert.runModal()
def __init__(self, title, message): self.nsalert = NSAlert.alloc().init() self.nsalert.setAlertStyle_(NSInformationalAlertStyle) self.nsalert.setMessageText_(title) self.nsalert.setInformativeText_(message)