自己写的眼保程序(pynotify,pygtk)
dcy
posted @ 2009年6月09日 00:31
in Python
with tags
Python Pythonic pynotify pygtk
, 3367 阅读
每天对着电脑N久,有时在电脑前一坐就是N个钟,视力越来越差,突然想到写条程序定时提醒我休息一下做做眼保健操,最近在学习python,就用python来吧,很简单的几句话,punotify部分灵感来源于PT大牛的某篇日志《玩转libnotify》;
pygtk部分的只是最基本的功能而已,自己随便写写的
程序作出来后的效果是每隔两个钟后弹出来一次
效果截图:
pynotify小图:
pygtk小图:
大图:
代码:
-
#!/usr/bin/env python
-
#coding:UTF-8
-
-
import time
-
import pynotify
-
import gtk
-
import pygtk
-
-
class Warning:
-
-
def destroy(self, widget):
-
gtk.main_quit()
-
-
def __init__(self):
-
self.window=gtk.Window(gtk.WINDOW_TOPLEVEL)
-
self.window.connect("destroy", self.destroy)
-
self.window.set_border_width(16)
-
self.button=gtk.Button("保护视力,休息一下")
-
self.button.connect_object("clicked", gtk.Widget.destroy, self.window)
-
self.window.add(self.button)
-
self.button.show()
-
self.window.show()
-
-
def main2(self):
-
gtk.main()
-
-
def Notify():
-
pynotify.init("DCY-Title")
-
n = pynotify.Notification("DCY温馨提示:保护视力", "休息一下,眼保健操")
-
n.show()
-
-
def main():
-
while True:
-
time.sleep(7200)
-
Notify()
-
warn = Warning()
-
warn.main2()
-
-
if __name__ == "__main__":
-
main()
接下来要做的就是把这条Python脚本程序设置为开机自启动,我的系统是Ubuntu,把我的notify.py放进/bin里,再修改~/.bashrc的配置,再后面加上
nohup notify.py &,把它设置为后台执行
搞掂……现在只要开机什么都不用理每隔两个钟就会提示我一次了……
2023年1月20日 19:23
It's really interesting that you have shared details regarding the eye protection program using the python programming language. It's a different idea and I really loved engagement rings these. Nice to see your work on the corresponding program over here. I am looking here to more updates on that and keep sharing more details here.