rendered paste body#!/usr/bin/env python
import pygtk, gtk, pango, os, popen2
pygtk.require('2.0')
class Tuner:
__device = "/dev/video1 " # tv card device to use
__minChannel = 2 # the minimun channel found
__maxChannel = 80 # the maximun channel found
__initialChannel = 38 # the first channel to tune into
__x = "720" # the Width of the screen
__y = "480" # the Height of the screen
__player = "/usr/bin/mplayer " + __device + " -nomouseinput -nolirc -really-quiet -x " + __x + " -y " + __y
__listing = {2:'WPBT', 3:'WBFS', 4:'WFOR', 5:'QVC', 6:'WTVJ', 7:'WSVN', 8:'WGEN', 9:'WLTV', 10:'WPLG', \
11:'WSFL', 12:'WJANCA', 13:'WSCV', 14:'CSPAN', 15:'CSPAN2', 16:'WPXM', 17:'WLRN', 18:'TVGC', 19:'LOOR019', 20:'FL40MI', \
21:'WHFT', 22:'WSBS', 23:'WAMI', 26:'HSN', 27:'TWC', 28:'CNN', 29:'CNNH', 30:'MSNBC', \
31:'CNBC', 32:'FNC', 33:'COURT', 34:'ESPN', 35:'ESPN2', 36:'GOLF', 37:'VERSUS', 38:'SUNSMA', 39:'FSNFL', 40:'FSE', \
41:'FX', 42:'TNT', 43:'TBS', 44:'SPIKETV', 45:'USA', 46:'HALMRK', 47:'AMC', 48:'TVLAND', 50:'NIK', \
51:'DISN', 52:'TOON', 53:'FAM', 54:'ANIMAL', 55:'DSC', 56:'TLC', 57:'TRAV', 58:'ETV', 59:'STYLE', 60:'FOOD',\
61:'HGTV', 62:'LIFE', 63:'CSS', 64:'AETV', 65:'HISTORY', 66:'BRAVO', 67:'COMEDY', 68:'SCIFI', 69:'MTV',\
70:'MTV2', 71:'VH1', 72:'BET', 73:'OXYGEN', 74:'GALA', 75:'MUN2', 76:'LOOR076', 77:'GOAC077', 78:'EDAC078', 79:'EDAC079', 80:'AZTSAT'}
def __init__(self):
# Create a new window
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("TV Tuner")
window.connect("delete_event", self.delete_event)
box = gtk.HBox(False, 0)
window.add(box)
# add the down channel button
buttonDown = gtk.Button(label="Down", stock=gtk.STOCK_GO_DOWN)
buttonDown.connect("clicked", self.channelDown)
box.pack_start(buttonDown, True, True, 0)
buttonDown.show()
# add the channel display text box
self.combobox = gtk.ComboBox()
liststore = gtk.ListStore(str)
cell = gtk.CellRendererText()
self.combobox.pack_start(cell)
self.combobox.add_attribute(cell, 'text', 0)
self.combobox.set_wrap_width(5)
for n in range(self.__minChannel, self.__maxChannel + 1):
if (self.__listing.has_key(n)):
liststore.append(['%d %s' % (n, self.__listing[n])])
else:
liststore.append(['%d' % n])
self.combobox.set_model(liststore)
self.combobox.connect("changed", self.channelSet)
box.pack_start(self.combobox, True, True, 0)
self.combobox.set_active(self.__initialChannel - self.__minChannel)
# add the up channel button
buttonUp = gtk.Button(label="Up", stock=gtk.STOCK_GO_UP)
buttonUp.connect("clicked", self.channelUp)
box.pack_start(buttonUp, True, True, 0)
buttonUp.show()
# start the player
self.__player = popen2.Popen3(self.__player)
# display the window
box.show()
window.show_all()
def channelSet(self, args):
channel = self.combobox.get_active() + self.__minChannel
os.system('ivtv-tune -d %s -c %d' % (self.__device, channel))
def channelUp(self, args):
# loop around if going over the max channel
if ((self.combobox.get_active() + self.__minChannel) >= self.__maxChannel):
self.combobox.set_active(0)
else:
self.combobox.set_active(self.combobox.get_active() + 1)
def channelDown(self, args):
# loop around if going under the min channel
if (self.combobox.get_active() <= 0):
self.combobox.set_active(self.__maxChannel - self.__minChannel)
else:
self.combobox.set_active(self.combobox.get_active() - 1)
def delete_event(self, args, data=None):
os.kill(self.__player.pid, 9) # close the player before exiting.
gtk.main_quit()
return False
if __name__ == "__main__":
tune = Tuner()
gtk.main()