将进度值发送到python中的进度条 [英] Sending progress value to progress bar in python

查看:81
本文介绍了将进度值发送到python中的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的游戏中,我有两个模块, island.py ,它将岛加载到我的游戏中,第二个模块是 gui.py ,它在游戏开始前处理gui小部件.开始.我的问题是如何将island.py模块中的进度值发送到在 gui.py 模块 EDIT中创建的进度条中:还可以使用加载屏幕的实例来访问进度条并更改其值.

In my game I have two modules, island.py which loads the islands into my game and the second module is gui.py which handles the gui widgets before game starting. My problem is how to send the progress values from the island.py module to the progress bar created in gui.py module also with an instance of the loading screen to access the progress bar in it and change its value.

在模块island.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

在模块gui.py

def show_loading_screen(self):
    self._switch_current_widget('loadingscreen', center=True, show=True) # Creates the loading screen and its associated widgets, except the progress bar.

@staticmethod
def set_progress(progress):
    # Now I have the progress values, and it will be updated automatically... how can I pass it to the progress bar widget?
    # I need to create the progress bar widget here, but to do that I need to have the self instance to give me the current screen that I will create the progress bar for **AND HERE IS THE PROBLEM!!**
    def update_loading_screen(progress):
        """updates the widget."""
        **self,current**.findChild(name="progressBar")._set_progress(progress)
    update_loading_screen(progress)

如何使此update_loading_screen功能正常?

How I can make this update_loading_screen function?

推荐答案

如果我理解的正确,您正在调用静态方法,因此您无法访问self. 我想您只有一个GUI类实例可以设置

If I understand you right you are calling a static method and thus you have no access to self. As I suppose that you have only one instance of your GUI class you can set

 GUI.self = self

在GUI中.__init __

in GUI.__init__

然后,静态方法可以访问GUI.self.

The static method then can access GUI.self.

要进一步阅读,请参见 http://en.wikipedia.org/wiki/Singleton_pattern http://code.activestate.com/recipes /52558-singleton-pattern-implemented-with-python/

For further reading look at http://en.wikipedia.org/wiki/Singleton_pattern and http://code.activestate.com/recipes/52558-the-singleton-pattern-implemented-with-python/

这篇关于将进度值发送到python中的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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