如何从另一个框架控制一个框架? [英] How to control a frame from another frame?

查看:138
本文介绍了如何从另一个框架控制一个框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个具有2个独立框架的小型应用程序.

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

第一帧就像视频播放器控制器.它具有播放/停止/暂停"按钮等.它的名称为controller.py.

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

第二帧包含OpenGL渲染及其内部的许多内容,但是所有内容都包裹在如上所述的Frame()类中.它名为model.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.

我要讲的最后一部分是我必须将这两个结合"在一起. 有谁知道如何从另一个框架(controller.py)控制一个框架(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).

推荐答案

没有太多,您可以在控制器中创建模型类的实例并调用其方法.因此,例如,当您单击模型停止按钮时,其处理程序将调用模型类的相应方法来停止播放.

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.

如果您希望框架分离一些,可以使用 pubsub ,并只需设置一些侦听器在模型中用于接收来自控制器的消息.

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.

此处我刚刚找到了有关使用pubsub在两个帧之间进行通信的教程,这并不是您想要做的,但是如果您决定使用pubsub,它应该足以使您朝正确的方向入手.

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.

这篇关于如何从另一个框架控制一个框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆