Beispiel #1
0
def test_beginSheetModalForWindow_withCallback_():
    m = Mocker()
    alert = Alert.alloc().init()
    beginSheet = m.method(alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_)
    callback = m.mock()
    win = m.mock(ak.NSWindow)
    def do(win, dgt, sel, context):
        dgt.alertDidEnd_returnCode_contextInfo_(alert, 42, 0)
    expect(beginSheet(win, ANY, "alertDidEnd:returnCode:contextInfo:", 0)).call(do)
    callback(42)
    with m:
        alert.beginSheetModalForWindow_withCallback_(win, callback)
Beispiel #2
0
 def prompt(self, message, infotext, buttons, callback):
     window = self.window()
     if window is None:
         callback(len(buttons) - 1)
     else:
         self.alert = alert = Alert.alloc().init()
         alert.setAlertStyle_(ak.NSInformationalAlertStyle)
         alert.setMessageText_(message)
         if infotext:
             alert.setInformativeText_(infotext)
         for button in buttons:
             alert.addButtonWithTitle_(button)
         def respond(response):
             callback(response - ak.NSAlertFirstButtonReturn)
         alert.beginSheetModalForWindow_withCallback_(window, respond)
Beispiel #3
0
def test_beginSheetModalForWindow_withCallback_():
    m = Mocker()
    alert = Alert.alloc().init()
    beginSheet = m.method(
        alert.
        beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_)
    callback = m.mock()
    win = m.mock(ak.NSWindow)

    def do(win, dgt, sel, context):
        dgt.alertDidEnd_returnCode_contextInfo_(alert, 42, 0)

    expect(beginSheet(win, ANY, "alertDidEnd:returnCode:contextInfo:",
                      0)).call(do)
    callback(42)
    with m:
        alert.beginSheetModalForWindow_withCallback_(win, callback)
Beispiel #4
0
    def prompt(self, message, infotext, buttons, callback):
        window = self.window()
        if window is None:
            callback(len(buttons) - 1)
        else:
            self.alert = alert = Alert.alloc().init()
            alert.setAlertStyle_(ak.NSInformationalAlertStyle)
            alert.setMessageText_(message)
            if infotext:
                alert.setInformativeText_(infotext)
            for button in buttons:
                alert.addButtonWithTitle_(button)

            def respond(response):
                callback(response - ak.NSAlertFirstButtonReturn)

            alert.beginSheetModalForWindow_withCallback_(window, respond)
Beispiel #5
0
 def check_for_external_changes(self, window):
     if not self.is_externally_modified():
         return
     if self.isDocumentEdited():
         if window is None:
             return # ignore change (no gui for alert)
         stat = filestat(self.fileURL().path())
         if self._filestat == stat:
             return
         self._filestat = stat
         def callback(code):
             if code == ak.NSAlertFirstButtonReturn:
                 self.reload_document()
         alert = Alert.alloc().init()
         alert.setMessageText_("“%s” source document changed" % self.displayName())
         alert.setInformativeText_("Discard changes and reload?")
         alert.addButtonWithTitle_("Reload")
         alert.addButtonWithTitle_("Cancel")
         alert.beginSheetModalForWindow_withCallback_(window, callback)
     else:
         self.reload_document()
Beispiel #6
0
    def check_for_external_changes(self, window):
        if not self.is_externally_modified():
            return
        if self.isDocumentEdited():
            if window is None:
                return  # ignore change (no gui for alert)
            stat = filestat(self.fileURL().path())
            if self._filestat == stat:
                return
            self._filestat = stat

            def callback(code):
                if code == ak.NSAlertFirstButtonReturn:
                    self.reload_document()

            alert = Alert.alloc().init()
            alert.setMessageText_("“%s” source document changed" %
                                  self.displayName())
            alert.setInformativeText_("Discard changes and reload?")
            alert.addButtonWithTitle_("Reload")
            alert.addButtonWithTitle_("Cancel")
            alert.beginSheetModalForWindow_withCallback_(window, callback)
        else:
            self.reload_document()