#!/usr/bin/env python # copyright Douglas Peale 2010 # released under GPLv3 #This is a Gnome Pannel Application. #It displays the number of currently recording tuners on a MythTV system. #I hope to make it display more information and look better in the future, but for now, that is all it does. #mythstatus.py should be put in /usr/bin #mythstatus.server should be put in /usr/lib/bonobo/servers import sys import os import MythTV import pygtk pygtk.require('2.0') import gtk import gnomeapplet import gobject class Mythstatus: def mythstatusupdate(self): try: #If the connection to the backend is not already establised, attempt to establish the connection. if not self.backend: self.backend=MythTV.MythBE() #get a list of recorders (tuners) recorders=self.backend.getRecorderList() #count how many of those recorders are busy recording something recording=0 for recorder in recorders: if self.backend.isRecording(recorder): recording+=1 #change the lable to the number of recording recorders self.button.set_label(str(recording)) except: #Something went wrong. Display an 'X' since we can't talk to the backend self.button.set_label('X') self.backend=None self.tooltipuptodate=False return True def Mythstatus_tooltip(self,widget,x,y,keyboard_mode,tooltip,user_param=None): #Unfortunately, this gets called for every mouse event while the mouse is over the widget. #What I was looking for and did not find was a way to change the tooltip just before it is displayed. #This is the closest thing I could find. To prevent unnecessary communication with the backend, only update the tooltip #if the panel app has been updated since this function was last called. #Only do this once per update if not self.tooltipuptodate: try: #Set tool tip to display the next upcoming recording self.tooltiptext=str(self.backend.getUpcomingRecordings()[0]) except: #Disconnect from the backend so we will attempt to re-establish communication on the next update self.tooltiptext="Can't communicate with back end" self.backend=None # I must set this every time, even if most of the time it is never used because if mouse is moved since this was set, the # tooltip is discarded and a new empty tooltip created. tooltip.set_text(self.tooltiptext) self.tooltipuptodate=True return True #If the button is clicked, fork the process, and have the child start mythfrontend def Startfrontend(self,button,data=None): if not os.fork(): os.execlp("mythfrontend","mythfrontend","--service") def __init__(self,applet,iid): #I don't know what to do with these yet, but I'll keep a copy so the garbage collector can't eat them self.applet=applet self.iid=iid #Create the variable, but don't Connect to MythBackend here. self.backend=None #set up timer so I can update the count every 10 seconds gobject.timeout_add_seconds(10,self.mythstatusupdate) #Put a lable in the window self.button = gtk.Button("Success!") self.button.set_property("has-tooltip",True) self.button.connect("query-tooltip",self.Mythstatus_tooltip,None) self.button.connect("clicked",self.Startfrontend,None) self.applet.add(self.button) self.tooltipuptodate=False self.applet.show_all() def mythstatus_factory(applet, iid): Mythstatus(applet,iid) return gtk.TRUE if len(sys.argv) == 2 and sys.argv[1] == "run-in-window": # user wants to run in a window so he can see error messages in the consol he ran from. main_window = gtk.Window(gtk.WINDOW_TOPLEVEL) main_window.set_title("MythTV Status Debug Window") main_window.connect("destroy", gtk.main_quit) app = gnomeapplet.Applet() mythstatus_factory(app, None) app.reparent(main_window) main_window.show_all() gtk.main() sys.exit() else: gnomeapplet.bonobo_factory("OAFIID:GNOME_MythstatusApplet_Factory", gnomeapplet.Applet.__gtype__, "MythStatus", "0", mythstatus_factory)