mirror of
https://github.com/nikdoof/mythview.git
synced 2025-12-13 02:22:17 +00:00
MythNowNext added, and related coding to pull channel data from MythTV
This commit is contained in:
2
.bzrignore
Normal file
2
.bzrignore
Normal file
@@ -0,0 +1,2 @@
|
||||
mythicon.pyc
|
||||
mythnownext.pyc
|
||||
@@ -12,10 +12,9 @@ from MythTV import *
|
||||
|
||||
class MythIcon:
|
||||
|
||||
def __init__(self, id, h, w):
|
||||
def __init__(self, mythtv, id, h=None, w=None):
|
||||
|
||||
self.loaded = False
|
||||
mythtv = MythTV()
|
||||
pixbufload = gtk.gdk.PixbufLoader()
|
||||
|
||||
if os.path.isfile("/tmp/mythtv/%d.jpg" % id):
|
||||
@@ -29,9 +28,8 @@ class MythIcon:
|
||||
pixbufload.write(data)
|
||||
if pixbufload.get_pixbuf() != None:
|
||||
self.pixbuf = pixbufload.get_pixbuf()
|
||||
self.loaded = True
|
||||
pixbufload.close()
|
||||
|
||||
self.loaded = True
|
||||
|
||||
if os.path.exists('/tmp/mythtv') == False:
|
||||
os.mkdir('/tmp/mythtv')
|
||||
self.save('/tmp/mythtv/%d.jpg' % id, "jpeg", {})
|
||||
|
||||
31
mythview/mythnownext.py
Normal file
31
mythview/mythnownext.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from MythTV import *
|
||||
|
||||
class MythNowNext:
|
||||
|
||||
def __init__(self,mythtv):
|
||||
if mythtv:
|
||||
self.db = mythtv.db
|
||||
else:
|
||||
self.db = MythDB()
|
||||
|
||||
def get_nownext(self):
|
||||
c = self.db.cursor()
|
||||
|
||||
c.execute("""
|
||||
SELECT channel.chanid, channel.icon, cast(channel.channum as signed) as channum,
|
||||
channel.name, program.title,
|
||||
time_to_sec(timediff(time(program.endtime), time(now()) )) as timetoend
|
||||
FROM channel, program
|
||||
WHERE program.chanid = channel.chanid
|
||||
AND program.starttime <= NOW( )
|
||||
AND program.endtime >= NOW( )
|
||||
AND channum <> 0
|
||||
ORDER BY channum """)
|
||||
|
||||
rows = c.fetchall()
|
||||
c.close()
|
||||
|
||||
if rows:
|
||||
return rows
|
||||
else:
|
||||
return None
|
||||
@@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
||||
<!--Generated with glade3 3.4.3 on Sat Apr 26 19:31:17 2008 -->
|
||||
<!--Generated with glade3 3.4.3 on Sat Apr 26 23:58:28 2008 -->
|
||||
<glade-interface>
|
||||
<widget class="GtkWindow" id="MainWindow">
|
||||
<property name="title" translatable="yes">Myth View</property>
|
||||
<property name="window_position">GTK_WIN_POS_CENTER</property>
|
||||
<property name="default_width">500</property>
|
||||
<property name="default_height">500</property>
|
||||
<child>
|
||||
@@ -38,10 +39,18 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkTreeView" id="ChannelView">
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="headers_clickable">True</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<child>
|
||||
<widget class="GtkTreeView" id="ChannelView">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="enable_tree_lines">True</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
|
||||
@@ -14,6 +14,8 @@ except:
|
||||
sys.exit(1)
|
||||
|
||||
from mythicon import MythIcon
|
||||
from mythnownext import MythNowNext
|
||||
from MythTV import *
|
||||
|
||||
class MythViewUI:
|
||||
def __init__(self):
|
||||
@@ -21,6 +23,8 @@ class MythViewUI:
|
||||
#Set the Glade file
|
||||
self.gladefile = "mythview.glade"
|
||||
self.wTree = gtk.glade.XML(self.gladefile)
|
||||
|
||||
self.mythtv = MythTV()
|
||||
|
||||
#Get the Main Window, and connect the "destroy" event
|
||||
self.window = self.wTree.get_widget("MainWindow")
|
||||
@@ -30,31 +34,49 @@ class MythViewUI:
|
||||
self.channelStore = gtk.ListStore(int, gtk.gdk.Pixbuf, str)
|
||||
|
||||
# Setup the TreeView
|
||||
def addTreeColumn(tree, title, ctype, datafunc, visible,size):
|
||||
def addTreeColumn(title, ctype, visible,size):
|
||||
column = gtk.TreeViewColumn(title, ctype)
|
||||
if datafunc: column.set_cell_data_func(ctype, datafunc)
|
||||
column.set_resizable(False)
|
||||
column.set_cell_data_func(ctype, self.FillCellIcon)
|
||||
column.set_resizable(True)
|
||||
column.set_expand(True)
|
||||
column.set_visible(visible)
|
||||
#if size:
|
||||
# column.set_width(size)
|
||||
tree.append_column(column)
|
||||
if size > 0:
|
||||
column.set_fixed_width(size)
|
||||
self.channelTree.append_column(column)
|
||||
|
||||
self.channelTree = self.wTree.get_widget("ChannelView")
|
||||
addTreeColumn(self.channelTree, "Channel", gtk.CellRendererText(), None, False,64)
|
||||
addTreeColumn(self.channelTree, "Icon", gtk.CellRendererPixbuf(), self.FillChanIcon, True, 0)
|
||||
addTreeColumn(self.channelTree, "Now", gtk.CellRendererText(), None, True, 0)
|
||||
addTreeColumn("Channel", gtk.CellRendererText(), False,64)
|
||||
addTreeColumn("Icon", gtk.CellRendererPixbuf(), True, 0)
|
||||
addTreeColumn("Now", gtk.CellRendererText(), True, 0)
|
||||
|
||||
# Test Data
|
||||
self.channelStore.append([1,MythIcon(1126,64,64).pixbuf,"test 1"])
|
||||
self.channelStore.append([2,None,"test 2"])
|
||||
|
||||
self.channelTree.set_model(self.channelStore)
|
||||
self.UpdateTree()
|
||||
|
||||
self.window.show()
|
||||
|
||||
def FillChanIcon(self, column, cell, model, iter):
|
||||
cell.set_property('pixbuf', model.get_value(iter, 1) )
|
||||
def UpdateTree(self):
|
||||
# Test Data
|
||||
#self.channelStore.append([1,MythIcon(1805,64,64).pixbuf,"BBC One"])
|
||||
#self.channelStore.append([2,MythIcon(1172,64,64).pixbuf,"BBC Two"])
|
||||
|
||||
rows = MythNowNext(self.mythtv).get_nownext()
|
||||
|
||||
for row in rows:
|
||||
|
||||
if row[1]:
|
||||
self.channelStore.append([row[0], MythIcon(self.mythtv, row[0], 64, 64).pixbuf, row[3]])
|
||||
else:
|
||||
self.channelStore.append([row[0], None, row[3]])
|
||||
|
||||
print row[0]
|
||||
|
||||
self.channelTree.set_model(self.channelStore)
|
||||
|
||||
def FillCellIcon(self, column, cell, model, iter):
|
||||
|
||||
if column.get_title() == 'Icon':
|
||||
cell.set_property('pixbuf', model.get_value(iter, 1) )
|
||||
if column.get_title() == 'Now':
|
||||
cell.set_property('text', model.get_value(iter, 2))
|
||||
return
|
||||
|
||||
def main(self):
|
||||
|
||||
Reference in New Issue
Block a user