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 = text_type(message) if title is not None: title = text_type(title) _require_string_or_none(ok) if not isinstance(cancel, string_types): 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()
def __init__(self, message='', title='', default_text='', ok=None, cancel=None, dimensions=(320, 160)): message = text_type(message) title = text_type(title) self._cancel = bool(cancel) self._icon = None _require_string_or_none(ok) if not isinstance(cancel, string_types): 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
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()
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()
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()
def alert(title=None, message='', ok=None, cancel=None, other=None, icon_path=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. .. versionchanged:: 0.3.0 Add `other` button functionality as well as `icon_path` to change the alert icon. :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. :param other: the text for the "other" button. If a string, the button will have that text. Otherwise, this button will not be created. :param icon_path: a path to an image. If ``None``, the applications icon is used. :return: a number representing the button pressed. The "ok" button is ``1`` and "cancel" is ``0``. """ message = text_type(message) message = message.replace('%', '%%') if title is not None: title = text_type(title) _internal.require_string_or_none(ok) if not isinstance(cancel, string_types): cancel = 'Cancel' if cancel else None alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( title, ok, cancel, other, message) if NSUserDefaults.standardUserDefaults().stringForKey_( 'AppleInterfaceStyle') == 'Dark': alert.window().setAppearance_( AppKit.NSAppearance.appearanceNamed_( 'NSAppearanceNameVibrantDark')) alert.setAlertStyle_(0) # informational style if icon_path is not None: icon = _nsimage_from_file(icon_path) alert.setIcon_(icon) _log('alert opened with message: {0}, title: {1}'.format( repr(message), repr(title))) return alert.runModal()
def alertLoop(self): raise_application() alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(self._title, None, None, None, self._message) alert.setAlertStyle_(NSCriticalAlertStyle) if self._help_link: alert.setShowsHelp_(YES) alert.setHelpAnchor_(self._help_link) alert.setDelegate_(self) if hasattr(alert, 'setAccessoryView_') and self._text: alert.setAccessoryView_(self.createAccessoryView(alert)) alert.runModal() AppHelper.stopEventLoop() if self._done_event: self._done_event.set()
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)
def __init__(self, message: str = '', title: str = '', ok: Optional[str] = None, cancel: Optional[str] = None): message = text_type(message) title = text_type(title) self._cancel = bool(cancel) self._icon = None _require_string_or_none(ok) if not isinstance(cancel, string_types): cancel = 'Cancel' if cancel else None self._alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( title, ok, cancel, None, message) self._alert.setAlertStyle_(0) NSApp.activateIgnoringOtherApps_(True)
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)
def open_license(_): print(0) alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( 'License', None, None, None, 'GNU General Public License, version 3') alert.setAlertStyle_(0) textview = NSTextView.alloc().initWithFrame_(NSMakeRect(0, 0, 420, 180)) textview.setEditable_(False) if getattr(sys, 'frozen', False): # noinspection PyUnresolvedReferences textview.setString_('\n' + open(sys._MEIPASS[:len(sys._MEIPASS) - 5] + 'Resources/LICENSE').read()) else: textview.setString_('\n' + open('LICENSE').read()) sv = NSScrollView.alloc().initWithFrame_(textview.frame()) sv.setBorderType_(1) sv.setHasVerticalScroller_(True) sv.setAutoresizingMask_(2 | 16) sv.setDocumentView_(textview) alert.setAccessoryView_(sv) alert.runModal()
def _removeDirectory(self): ''' Remove directory from settings ''' if self.tableView.selectedRow() == -1: alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( "Error", "Confirm", None, None, "Please select a row first.") alert.runModal() else: self.tableView.beginUpdates() self.data['paths'].removeObjectAtIndex_( self.tableView.selectedRow()) index = NSIndexSet.indexSetWithIndex_(self.tableView.selectedRow()) self.tableView.removeRowsAtIndexes_withAnimation_( index, NSTableViewAnimationEffectFade) self.tableView.endUpdates() # Save to file self.saveSettings()
def alert(title=None, message='', ok=None, cancel=None): """ Repackaged from rumps, so we can try to make the window float above the others. 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 = text_type(message) if title is not None: title = text_type(title) rumps.rumps._require_string_or_none(ok) if not isinstance(cancel, string_types): cancel = 'Cancel' if cancel else None alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( title, ok, cancel, None, message) alert.setAlertStyle_(0) # informational style #panel = alert.window() #panel.setLevel_(NSStatusWindowLevel) # alert.window().setFloatingPanel_(True) # import ipdb; ipdb.set_trace(); rumps.rumps._log('alert opened with message: {0}, title: {1}'.format(repr(message), repr(title))) #app = NSRunningApplication.currentApplication() #app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps) nsapplication = NSApplication.sharedApplication() nsapplication.activateIgnoringOtherApps_(True) result = alert.runModal() return result
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
def saveSettings(self): ''' Save the path setting to setting file ''' jsonData = NSMutableDictionary.dictionaryWithDictionary_(self.data) paths = NSMutableArray.array() for directory in self.data['paths']: paths.addObject_(directory.directoryToDict()) jsonData['paths'] = paths data = NSJSONSerialization.dataWithJSONObject_options_error_( jsonData, 0, None) if len(data) > 0 and not data[0].writeToFile_atomically_( self.settingPath, True): alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( "Error", "Confirm", None, None, "Save setting failed.") alert.runModal() else: # Notify the app to reload settings self.callback(*self.args)