对话响应后如何在正确的地方恢复程序工作流程?
我正在编写的程序可以一次编辑一个项目。这意味着打开一个新文件/项目意味着关闭前一个文件/项目。现在我想要实现的是以下工作流程:
- 用户对他以前从未保存过的项目进行了未提交的更改,因此该项目还没有文件名。
- 用户按下“打开保存的项目”。
- 弹出一个对话框“A”并显示:“您当前的项目有未提交的更改,您想做什么?中止新项目操作,放弃对当前项目的更改,还是保存它们?”。
- 用户选择“保存”对话框。
- 对话A结束。
- 弹出对话框 B1(为保存操作配置的文件选择器)。
- 用户选择要保存的项目的文件名。
- 对话 B1 关闭,项目被保存。
- 弹出对话框 B2(相同的文件选择器,但配置为加载操作)。
- 用户选择要打开的文件。
- 对话 B2 关闭,项目已加载。
实际上,在上面的示例中,步骤 3 到 8 是打开已保存项目的明显工作流程中的一种“中断”,因此当对话 A 和 B1 打开时,明显的工作流程会停止,并且当这些对话获取时会恢复。回应道。
我的问题是:如何实现这种停止/恢复正常操作流程的机制?到目前为止,我实现它的方式是通过一个堆栈,每当我打开弹出对话框时,我都会推送“从此处恢复回调”,并且每当我响应时,我都会从中弹出回调。
...但看来我的情况是一个非常常见的场景,应该有一个更简单的方法(也许是 PyGTK 的特定功能!)。
非常感谢您的帮助/时间!
The program I am writing can edit a single project at a time. This means that opening a new file/project implies closing the previous one. Now what I want to achieve is the following workflow:
- User has uncommitted changes to a project he never previously saved, so the project doesn't have a file name yet.
- User presses "open saved project".
- A dialogue "A" pops up and says: "Your current project has uncommitted changes, what would you like to do? Abort new project operation, discard changes to current project, or save them?".
- User selects "save" dialogue.
- Dialogue A closes.
- Dialogue B1 (file chooser configured for save operation) pops up.
- User select file name for project to save.
- Dialogue B1 closes, project gets saved.
- Dialogue B2 (same file chooser but configured for load operation) pops up.
- User select file to open.
- Dialogue B2 closes, project is loaded.
So really, in the above example steps 3 to 8 are a sort of "interruption" in the obvious workflow of opening a saved project, so when dialogue A and B1 open, the obvious workflow is halted, and it is resumed when those dialogue get responded.
My question is: how to implement this mechanism of halting/resuming the normal flow of operation? So far the way I implemented it is via a stack on which - any time I open a popup dialogue - I push the "resume-from-here callback", and any time I respond I pop the callback from.
...yet it seems as mine is a very common scenario for which there should be an easier method (maybe a specific function of PyGTK!).
Many thanks in advance for your help/time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GtkDialog.run()
是您需要的方法吗?您“运行”对话框,在您需要询问用户的地方,当它返回时您就会得到答案。Would
GtkDialog.run()
be the method you need? You "run" the dialog, at the point where you need to ask the user, and when it returns you have your answer.