2011-03-05 3 views
1

패널에 tint2를 사용하고 있는데 tint2에 대한 플러그인이 없기 때문에 시스템 트레이 아이콘으로 cpu temp를 표시하려고합니다. 알고 싶습니다. 어쨌든 하나가 있든 없든 이것을하는 법. 지금까지 가지고있는 스크립트는 다음과 같습니다.Python cpu temp in system tray 리눅스

#! /usr/bin/python 
import pygtk,os 
pygtk.require("2.0") 
import gtk 
import egg.trayicon 
t = egg.trayicon.TrayIcon("CPUTemp") 
cpu_temp=os.popen('sensors | grep "temp1:" | cut -d+ -f2 | cut -c1-2').read() 
t.add(gtk.Label(cpu_temp)) 
t.show_all() 
gtk.main() 

기본적으로 처음에는 작동하지만 5 초마다 업데이트하고 싶습니다. 어떤 도움이라도 대단히 감사합니다.

+1

conky conky conky에 관하여 : 아래의 예를 들어 당신을 위해 일하는 것이 있는지 확인 – Orbit

답변

-1

파이썬의 "스레딩"모듈을보십시오. 새 출력 (t.set_text (str))을 사용하여 gtk.Label의 텍스트를 업데이트하는 명령을 실행하는 함수를 만듭니다. 그리고 스레드에서이 함수를 실행하십시오.

http://docs.python.org/library/threading.html

3

당신은 timeout_add_seconds를 통해 타이머를 정의하고 콜백에 트레이 아이콘을 업데이트 할 수 있습니다.)이 도움이

import gtk, gobject, os 

class CPUTimer: 
    def __init__(self, timeout): 

     self.window = gtk.Window() 
     vbox = gtk.VBox() 
     self.window.add(vbox) 
     self.label = gtk.Label('CPU') 
     self.label.set_size_request(200, 40) 
     vbox.pack_start(self.label) 

     # register a timer 
     gobject.timeout_add_seconds(timeout, self.timer_callback) 

     self.window.connect("destroy", lambda w: gtk.main_quit()) 
     self.window.connect("delete_event", lambda w, e: gtk.main_quit()) 

     self.window.show_all() 
     self.timer_callback() 

    def timer_callback(self): 
     cpu_temp = os.popen('sensors | grep "temp1:" | cut -d+ -f2 | cut -c1-2').read() 
     print 'update CPU: ' + cpu_temp 
     self.label.set_text('CPU: ' + cpu_temp) 
     return True 

if __name__ == '__main__': 
    timer = CPUTimer(1) # sets 1 second update interval 
    gtk.main() 

희망,