号码球
筛选法求素数

自己写的眼保程序(pynotify,pygtk)

dcy posted @ 2009年6月09日 00:31 in Python with tags Python Pythonic pynotify pygtk , 3336 阅读

每天对着电脑N久,有时在电脑前一坐就是N个钟,视力越来越差,突然想到写条程序定时提醒我休息一下做做眼保健操,最近在学习python,就用python来吧,很简单的几句话,punotify部分灵感来源于PT大牛的某篇日志《玩转libnotify》;

pygtk部分的只是最基本的功能而已,自己随便写写的

程序作出来后的效果是每隔两个钟后弹出来一次

效果截图:

pynotify小图:

pygtk小图:

大图:

代码:

 

  1. #!/usr/bin/env python
  2. #coding:UTF-8
  3.  
  4. import time
  5. import pynotify
  6. import gtk
  7. import pygtk
  8.  
  9. class Warning:
  10.    
  11.     def destroy(self, widget):
  12.         gtk.main_quit()
  13.  
  14.     def __init__(self):
  15.         self.window=gtk.Window(gtk.WINDOW_TOPLEVEL)
  16.         self.window.connect("destroy", self.destroy)
  17.         self.window.set_border_width(16)
  18.         self.button=gtk.Button("保护视力,休息一下")
  19.         self.button.connect_object("clicked", gtk.Widget.destroy, self.window)
  20.         self.window.add(self.button)
  21.         self.button.show()
  22.         self.window.show()
  23.  
  24.     def main2(self):
  25.         gtk.main()
  26.  
  27. def Notify():
  28.     pynotify.init("DCY-Title")
  29.     n = pynotify.Notification("DCY温馨提示:保护视力", "休息一下,眼保健操")
  30.     n.show()
  31.  
  32. def main():
  33.     while True:
  34.         time.sleep(7200)
  35.         Notify()
  36.         warn = Warning()
  37.         warn.main2()
  38.  
  39. if __name__ == "__main__":
  40.     main()

 

接下来要做的就是把这条Python脚本程序设置为开机自启动,我的系统是Ubuntu,把我的notify.py放进/bin里,再修改~/.bashrc的配置,再后面加上

nohup notify.py &,把它设置为后台执行

搞掂……现在只要开机什么都不用理每隔两个钟就会提示我一次了……

 

Emma 说:
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.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter