예제 #1
0
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()
예제 #2
0
파일: rumps.py 프로젝트: 4m1g0/duplicati
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()
예제 #3
0
    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_)
예제 #4
0
    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
예제 #5
0
    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
예제 #6
0
 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
예제 #7
0
 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
예제 #8
0
 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)
예제 #9
0
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
예제 #10
0
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
예제 #11
0
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()
예제 #12
0
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 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()
예제 #14
0
 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)
예제 #15
0
    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)
예제 #16
0
 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
예제 #17
0
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()
예제 #18
0
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()
예제 #19
0
 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()
예제 #20
0
    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)
예제 #21
0
파일: alert.py 프로젝트: rebryk/neurox
    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)
예제 #22
0
    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)
예제 #23
0
    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)
예제 #24
0
    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()
예제 #25
0
    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()
예제 #26
0
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
예제 #27
0
 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()
예제 #28
0
    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)
예제 #29
0
파일: rumps.py 프로젝트: 4m1g0/duplicati
    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
예제 #30
0
    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
예제 #31
0
def ensure_permissions() -> None:
    from ApplicationServices import AXIsProcessTrusted
    from AppKit import NSAlert, NSAlertFirstButtonReturn, NSWorkspace, NSURL
    accessibility_permissions = AXIsProcessTrusted()
    if not accessibility_permissions:
        title = "Missing accessibility permissions"
        info = "To let ActivityWatch capture window titles grant it accessibility permissions. \n If you've already given ActivityWatch accessibility permissions and are still seeing this dialog, try removing and re-adding them."

        alert = NSAlert.new()
        alert.setMessageText_(title)
        alert.setInformativeText_(info)

        ok_button = alert.addButtonWithTitle_("Open accessibility settings")

        alert.addButtonWithTitle_("Close")
        choice = alert.runModal()
        print(choice)
        if choice == NSAlertFirstButtonReturn:
            NSWorkspace.sharedWorkspace().openURL_(
                NSURL.URLWithString_(
                    "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"
                ))
예제 #32
0
 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
예제 #33
0
 def __init__(self, title, message):
     self.alert = NSAlert.alloc().init()
     self.alert.setTitle_andMessage_(title, message)
     self.button_return = None
예제 #34
0
 def __init__(self, title, message):
     self.alert = NSAlert.alloc().init()
     self.alert.setTitle_andMessage_(title, message)
     self.button_return = None
예제 #35
0
 def __init__(self, title, message):
     self.nsalert = NSAlert.alloc().init()
     self.nsalert.setAlertStyle_(NSInformationalAlertStyle)
     self.nsalert.setMessageText_(title)
     self.nsalert.setInformativeText_(message)
예제 #36
0
def showAlert(messageText, InformativeText=""):
	alert = NSAlert.alloc().init()
	alert.setMessageText_(messageText)
	alert.setInformativeText_(InformativeText)
	alert.runModal()