From MythTV Official Wiki
Jump to: navigation, search

If you'd like a simple icon in your system tray / notification area that indicates whether mythtv is currently recording or not, then this python script is for you.

Now I always know whether it's okay to reboot or not, and when to expect my disk activity to be high.

(It's my first python script, so be kind. -- harvest316)

PythonIcon.png SystemTrayIcon

"""Script to display a system-tray icon showing mythtv recording status

Based on code from:
Which was based on code from:

Change Log:
	12/12/08 Harvest316 removed sudo dependency by using mythtv-status instead of /dev/video*, and expanded tooltip
import commands, re, time

def getRecordingStatus( ):
	"""Retrieve recording status from mythtv-status"""
	global mythtv_status_output
	mythtv_status_output = commands.getoutput('nice -19 mythtv-status --auto-expire')

	patternprog = re.compile( "Recording Now:" )
	a_match = mythtv_status_output )
	if ( a_match ):
		return "actively recording"

if __name__ == "__main__":
	import wx
	class RDApp( wx.App ):
		duration = 60 # seconds
		def OnInit( self ):
			"""Initialise, kicking off our operations"""
			self.frame = wx.Frame( None, -1, 'RecordingDevicesApp' )
			self.icon = wx.TaskBarIcon()
			wx.EVT_TASKBAR_LEFT_DCLICK( self.icon, self.OnClickIcon )
			class MyTimer( wx.Timer ):
				def Notify( self, event=None ):
			self.timer = MyTimer(  )
			# fire every self.duration seconds 
			self.timer.Start( self.duration * 1000, False ) 
			self.frame.Show( False )
			self.SetTopWindow( self.frame )
			return True
		def MainOperation( self, event ):
			"""Check every few seconds for current status"""
			self.setStatus( getRecordingStatus() )
		def setStatus( self, recording ):
			"""Set the icon's current representation"""
			width = 14
			bitmap = wx.EmptyBitmap(width, width)
			dc = wx.MemoryDC( )
			dc.SelectObject( bitmap )
				dc.SetBackground( wx.BLUE_BRUSH )
				if recording:
					brush = wx.RED_BRUSH
					brush = wx.GREEN_BRUSH
				dc.SetBrush( brush )
				dc.DrawCircle( width/2,width/2,width/2-2 )
				dc.SelectObject( wx.NullBitmap )
			bitmap.SetMaskColour( wx.BLUE )
			icon = wx.IconFromBitmap(bitmap)
			self.icon.SetIcon( icon, mythtv_status_output )
		def OnClickIcon( self, event ):
			"""Handle double-click of icon (close)"""

	app = RDApp()