在 PyObjC 中,如何在使用 runModalForWindow_ 后让工作表结束?
我有一个由第二个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的行
应该是
等。记住,Objective-C 选择器中的每个冒号在 Python 中都变成了 _!
Your lines
should be
etc. Remember, every colon in an Objective-C selector becomes an _ in Python!