예제 #1
0
파일: test_alert.py 프로젝트: khairy/editxt
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)
예제 #2
0
파일: document.py 프로젝트: khairy/editxt
 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)
예제 #3
0
파일: test_alert.py 프로젝트: khairy/editxt
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)
예제 #4
0
파일: document.py 프로젝트: khairy/editxt
    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)
예제 #5
0
파일: document.py 프로젝트: khairy/editxt
 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()
예제 #6
0
파일: document.py 프로젝트: khairy/editxt
    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()