使用 py2app 时,有没有办法自定义显示的回溯对话框? (或者显示不同的 Cocoa 对话框?)
有没有一种简单的方法可以更好地控制 py2app 回溯对话框,或者只是一种显示 GUI 消息的好方法?
如果我在 py2app 脚本中引发异常,我会看到一个对话框,内容如下:
MyAppName 错误
我的应用程序名称错误
执行主脚本期间发生意外错误
MyRaishedError:这是我在引发错误时可以控制的文本。
它有打开控制台和终止按钮。我的脚本需要检查驱动器中是否有某个 DVD,如果没有,我想显示一个错误对话框并退出。我希望对它有更多的控制权,因为我只能更改一些文本而无法控制按钮。
我尝试通过 applescript 调用 osascript 来执行“显示对话框”,但它给了我这样的错误:0:19:执行错误:不允许用户交互。 (-1713)我不是特别喜欢这种方式,但如果这是我能做的一切......
我真的不想包括像 Cocoa Dialogs 或类似 PyObjC 项目的东西...脚本本身非常小,我看不到仅仅为了获得对话框而添加 10 倍的脚本内容。
Is there an easy way to get any more control over the py2app traceback dialogs, or just a nice way to display GUI messages?
If I raise an exception in my py2app script, I get a dialog that says something like this:
MyAppName Error
MyAppName Error
An unexpected error has occurred during execution of the main script
MyRaisedError: This is the text that I can control when I raise the error.
It has Open Console and Terminate buttons. My script needs to check if a certain DVD is in the drive, if it's not, I want to show an error dialog and quit. I would like to have more control over it than this, as I can only change some of the text and can't control the buttons.
I tried calling osascript to do 'display dialog' via applescript, but it gave me an error like this: 0:19: execution error: No user interaction allowed. (-1713) I don't particularly like this way of doing it, but if it's all I can do...
I would really prefer not to include a big project like Cocoa Dialogs or something like a PyObjC project... the script itself is very tiny and I can't see adding 10x the meat of my script just to get the dialog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过 py-appscript 如果您的 python 站点库中还没有它,可以通过
easy_install
安装。此示例在 py2app 生成的应用程序内部运行:Instead of using
osascript
, you can calldisplay dialog
via py-appscript which, if you don't already have it in your python site-library, can be installed viaeasy_install
. This example works inside of a py2app-generated app:只需在引发异常的代码部分放置一个标准的 Python try/catch 块,然后使用 NSAlert 告诉用户他们需要将 DVD 放入
Just put a standard Python try/catch block around the section of code that throws the exception, then use NSAlert to tell your users they need to put the DVD in