在 PyObjC 中,如何在使用 runModalForWindow_ 后让工作表结束?

发布于 2024-08-20 23:41:19 字数 1046 浏览 3 评论 0原文

我有一个由第二个 WindowController 控制的对话框的辅助窗口(一张纸)。由于某种原因,在显示工作表后,NSObject 子类中永远不会调用这些操作。我已经确认并重新链接了这些操作。代码运行到 runModalForWindow_ 但从未收到“确定”或“取消”操作。所以这张纸永远不会消失。我在这里缺少什么?我似乎无法在他们的网站上找到任何执行 runModalForWindow_... 的 pyobjc 示例

    @objc.IBAction
def okSelected(self, sender):
    self.dialogResult = objc.YES
    NSLog("OK")
    #NSApp.endSheet_(self.newTurnWindowOutlet)
    NSApp.stopModalWithCode_(objc.OK)

@objc.IBAction
def cancelSelected(self, sender):
    self.dialogResult = objc.NO
    #NSApp.endSheet_(self.newTurnWindowOutlet)
    NSApp.stopModalWithCode_(objc.NO)

def runSheet(self, parent):
    NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(
        self.newTurnWindowOutlet, parent, None, 
        self.sheetDidEnd_returnCode_contextInfo_, None)
    NSLog("runModelForWindow")
    result = NSApp.runModalForWindow_(self.newTurnWindowOutlet)
    NSLog(str(result))
    NSApp.endSheet_(self.newTurnWindowOutlet)
    self.newTurnWindowOutlet.orderOut_(self)
    return self.dialogResult

I have a secondary window (a sheet) for a dialog controlled by a secondard WindowController. For some reason, the actions never get called in NSObject subclass after the sheet is displayed. I have confirmed and re-linked the actions. The code runs to runModalForWindow_ but then never receives the ok or cancel actions. So the sheet never goes away. What am I missing here? I cant seem to find any pyobjc examples on thier website that does a runModalForWindow_...

    @objc.IBAction
def okSelected(self, sender):
    self.dialogResult = objc.YES
    NSLog("OK")
    #NSApp.endSheet_(self.newTurnWindowOutlet)
    NSApp.stopModalWithCode_(objc.OK)

@objc.IBAction
def cancelSelected(self, sender):
    self.dialogResult = objc.NO
    #NSApp.endSheet_(self.newTurnWindowOutlet)
    NSApp.stopModalWithCode_(objc.NO)

def runSheet(self, parent):
    NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(
        self.newTurnWindowOutlet, parent, None, 
        self.sheetDidEnd_returnCode_contextInfo_, None)
    NSLog("runModelForWindow")
    result = NSApp.runModalForWindow_(self.newTurnWindowOutlet)
    NSLog(str(result))
    NSApp.endSheet_(self.newTurnWindowOutlet)
    self.newTurnWindowOutlet.orderOut_(self)
    return self.dialogResult

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑寡妇 2024-08-27 23:41:19

你的行

    @objc.IBAction
    def okSelected(self, sender):

应该是

    @objc.IBAction
    def okSelected_(self, sender):

等。记住,Objective-C 选择器中的每个冒号在 Python 中都变成了 _!

Your lines

    @objc.IBAction
    def okSelected(self, sender):

should be

    @objc.IBAction
    def okSelected_(self, sender):

etc. Remember, every colon in an Objective-C selector becomes an _ in Python!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文