如何从一个框架控制另一个框架?

发布于 2024-09-26 23:38:23 字数 341 浏览 1 评论 0原文

我正在编写一个小应用程序,它有 2 个独立的框架。

第一帧就像视频播放器控制器。它有播放/停止/暂停按钮等。它被命名为controller.py。

第二帧包含 OpenGL 渲染以及其中的许多内容,但所有内容都包装在 Frame() 类中,如上所述。它被命名为 model.py。

我已经完成了最后一部分,我必须将这两者“结合”在一起。 有谁知道如何从另一个框架(controller.py)控制一个框架(model.py)?

我想做一些类似电影播放器​​的事情,当您单击播放时,它会弹出一个新窗口并播放,直到单击停止按钮。

如果您知道如何,请告诉我。 (只是笼统地告诉我,不需要具体)。

I'm writing a small app which has 2 separate frames.

The first frame is like a video player controller. It has Play/Stop/Pause buttons etc. It's named controller.py.

The second frame contains OpenGL rendering and many things inside it, but everything is wrapped inside a Frame() class as the above. It's named model.py.

I'm up to the final part where I have to "join" these two together.
Does anyone know how to control a frame (model.py) from another frame (controller.py)?

I would like to do something like a movie player when you clicks play it pops up a new window and play until the stop button is clicked.

If you know how, please let me know. (Just tell me in general no need to specific).

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

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

发布评论

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

评论(2

可爱暴击 2024-10-03 23:38:23

没有太多,您在控制器中创建模型类的实例并调用其方法。例如,当您单击模型停止按钮时,其处理程序会调用模型类的适当方法来停止播放。

如果您希望框架在某种程度上解耦,您可以使用 pubsub,并简单地在模型中设置一些侦听器来自控制器的消息。

这是我的一个教程刚刚发现使用 pubsub 在两个框架之间进行通信,这并不完全是您想要做的,但如果您决定使用 pubsub,它应该足以让您朝着正确的方向开始。

Theres not much too it, you create an instance of your model class in your controller and call its methods. So for example when you click the models stop button its handler calls the appropriate method of your model class to stop playback.

If you would like your frames to be decoupled somewhat, you could use pubsub, and simply setup some listeners in your model for messages from your controller.

Here's a tutorial I just found on communciating between two frames using pubsub, it's not exactly what you want to do, but it should be enough to get you started in the right direction if you decide to use pubsub.

勿忘心安 2024-10-03 23:38:23

我肯定会使用 PubSub,因为这可能是我能想到的最简洁的方法。您还可以使用 wx.PostEvent 或使用模式框架来完成此操作。

I'd definitely use PubSub as it's probably the cleanest way I can think of to do it. You can also do it with wx.PostEvent or use a modal frame.

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