Pygtk + Glade 自刷新标签
首先,我是编程语言世界的新手,当然对 Python 也很陌生。
在我的工作中,我们使用 Linux 系统。我有时需要检查终端上的一些命令和脚本输出。因此,我想使用非常基本的 GUI 编写一个小型应用程序,并选择了 Python 和 Pygtk 以及 Glade。不幸的是,我们的 Linux 发行版不是最新的,我只能使用 Python 2.4.3 和 Glade 2.12.1。我知道它们太旧了,但我必须使用它们。
在学习了一点 Python 和 Pygyk 之后,在大量教程的帮助下,我成功地使用原始 GUI 编写了一个基本应用程序。例如,当我单击按钮时,它会收集一些系统信息并将其写入标签。等等。我为不同的目的创建不同的按钮。这还可以,但没那么有用。正如您所猜测的,我希望这些标签在一段时间内自动刷新(即每十分钟)。我在网上搜索并找到了 Timer 类。另外,我遇到了线程问题。但我无法将这些应用到我的简单代码中,因为我是菜鸟。这是我的代码:
#!/usr/bin/env python
import os
import ...
class MyProject:
def __init__(self):
self.gladefile = "myproject.glade"
self.wTree = gtk.glade.XML(self.gladefile)
dic = { "on_window1_destroy" : gtk.main_quit,
"on_sis_button.clicked" : self.sis_button_clicked,
"on_...... }
self.wTree.signal_autoconnect(dic)
def sis_button_clicked(self, widget):
sislbl = self.wTree.get_widget("sis_label1")
def ......
if __name__ == "__main__":
frm = MyProject()
gtk.main()
现在,我如何将自动刷新或类似的东西应用到我的代码中。我是否必须为每个标签贴上标签,还是可以在全球范围内贴上标签?我的方法正确吗,还是应该完全改变我的代码概念?
谢谢。
注意:如果你指点我,我可以阅读手册。直接的代码建议会让我很高兴。
First of all I am a newcomer to programming languages world and of course very new to Python.
In my job, we are using Linux systems. Time to time I need to check some command and script outputs on the terminal. So, I wanted to code a small application with a very basic GUI and chose Python and Pygtk with Glade. Unfortunately, our Linux distros are not so up to date and I can only use Python 2.4.3 and Glade 2.12.1. I know those are too old, but I have to use them.
Ater studying Python and Pygyk just a bit and with the help of tons of tutorials, I managed to code a basic application with a primitive GUI. For example when I click a button, it collects some system info and write those to a label. And so on. I create different buttons for different purposes. This is ok but not so useful. As you guess, I want those labels are auto refreshed for some period (i.e for every ten min). I search the web and found Timer class. Also, I encounter thread issues. But I can't apply those to my simple code since I am a noob. Here is my code:
#!/usr/bin/env python
import os
import ...
class MyProject:
def __init__(self):
self.gladefile = "myproject.glade"
self.wTree = gtk.glade.XML(self.gladefile)
dic = { "on_window1_destroy" : gtk.main_quit,
"on_sis_button.clicked" : self.sis_button_clicked,
"on_...... }
self.wTree.signal_autoconnect(dic)
def sis_button_clicked(self, widget):
sislbl = self.wTree.get_widget("sis_label1")
def ......
if __name__ == "__main__":
frm = MyProject()
gtk.main()
Now, how can I apply auto refresh or something like that to my code. Do I have to apply it label per label, or is it possible to do it globally? Am I on the right way, or should I totally change my code concept?
Thank you.
Note: I can read manuals if you point me. Direct code suggestions will make me so pleased.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有一个有效的示例 http://tuxion.com/2010 /04/16/periodic-timers-in-pygtk.html
There is a worked example here http://tuxion.com/2010/04/16/periodic-timers-in-pygtk.html