在我的游戏中,我有两个模块,岛屿.py将岛屿加载到我的游戏中,第二个模块是图形用户界面.py在游戏开始前处理gui小部件。我的问题是如何从岛屿.py在图形用户界面.py模块编辑:还可以使用加载屏幕的实例访问其中的进度条并更改其值。
在模块中岛屿.py
def __iter__(self):
total = float(len(self.ground_map))
import game.gui
for i in self.get_coordinates():
yield i
global count
count+=1
progress = (count/total) * 100
game.gui.Gui.set_progress(progress)
global count
count = 0
在模块中图形用户界面.py
^{pr2}$如何使这个更新加载屏幕功能?在
我会用一点不同的方式来处理这个问题。调度器可能不知道什么叫“Pyos”,或者“你不知道”什么信号。这些信号,当“发出”或执行一系列或一组函数时,您已经附加到该信号上。slot是执行的函数,dispatcher保存了对slot的弱引用字典,并使用信号发出的参数调用它们。在
请参阅examples for pydispatch以了解它们是如何组合在一起的。在
但是你可以做一些类似的事情:
dispatcher.connect(reciever, signal, sender)
或者connect(game.gui.Gui.set_progress, 'update_progress', island.Class)
,然后在__iter__
中发送一个类似send('update_progress', sender=island.Class, progress=progress)
的信号,这将使用kwargs来调用update_progressprogress=progress
。通过这种方式,您可以将更新进度从静态方法更改为直接更新gui。在扩展rocksport的答案…我就是这样做的
如果我对你的理解是正确的,你正在调用一个静态方法,因此你无法访问self。 我假设您只有一个可以设置的GUI类实例
在图形用户界面中
然后静态方法可以访问图形用户界面. 在
进一步阅读请看http://en.wikipedia.org/wiki/Singleton_pattern和{a2}
相关问题 更多 >
编程相关推荐