diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 0000000..61a546d --- /dev/null +++ b/.bzrignore @@ -0,0 +1,2 @@ +mythicon.pyc +mythnownext.pyc diff --git a/mythview/mythicon.py b/mythview/mythicon.py index 5f2deae..58bc9c7 100644 --- a/mythview/mythicon.py +++ b/mythview/mythicon.py @@ -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", {}) diff --git a/mythview/mythnownext.py b/mythview/mythnownext.py new file mode 100644 index 0000000..dbb0a50 --- /dev/null +++ b/mythview/mythnownext.py @@ -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 diff --git a/mythview/mythview.glade b/mythview/mythview.glade index 6143ef2..e202595 100644 --- a/mythview/mythview.glade +++ b/mythview/mythview.glade @@ -1,9 +1,10 @@ - + Myth View + GTK_WIN_POS_CENTER 500 500 @@ -38,10 +39,18 @@ - + True True - True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + + + True + True + True + + 1 diff --git a/mythview/mythview.py b/mythview/mythview.py index d29916a..ff3b4fa 100755 --- a/mythview/mythview.py +++ b/mythview/mythview.py @@ -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):