Update of /cvsroot/freevo/freevo/src/tv
In directory sc8-pr-cvs1:/tmp/cvs-serv10703

Added Files:
        edit_favorite.py program_display.py program_search.py 
        view_favorites.py 
Log Message:
Better to commit these before I mess something up.  Still event code to fix I think, 
among other things.


--- NEW FILE: edit_favorite.py ---
#!/usr/bin/env python
#-----------------------------------------------------------------------
# EditFavorite - 
#-----------------------------------------------------------------------
# $Id: edit_favorite.py,v 1.1 2003/06/01 19:05:15 rshortt Exp $
#
# Todo: 
# Notes: 
#
#-----------------------------------------------------------------------
# $Log: edit_favorite.py,v $
# Revision 1.1  2003/06/01 19:05:15  rshortt
# Better to commit these before I mess something up.  Still event code to fix I think, 
among other things.
#
#
#
#-----------------------------------------------------------------------
#
# Freevo - A Home Theater PC framework
#
# Copyright (C) 2002 Krister Lagerstrom, et al.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------

import time

import config, record_client, epg_xmltv, view_favorites
import event as em

from record_types import Favorite
import record_types
from epg_types import TvProgram

from gui.GUIObject      import *
from gui.Border         import *
from gui.Label          import *
from gui.AlertBox       import *
from gui.OptionBox      import *
from gui.LetterBoxGroup import *

DEBUG = 1
TRUE = 1
FALSE = 0


class EditFavorite(PopupBox):
    """
    prog      the program to record
    left      x coordinate. Integer
    top       y coordinate. Integer
    width     Integer
    height    Integer
    """
    
    def __init__(self, parent=None, subject=None, left=None, top=None, width=500,
                 height=350):

        self.oldname = None

        print 'DEBUG::subject: %s' % dir(subject)
        print 'DEBUG::subject::__module__ %s' % subject.__module__
        #if isinstance(subject, record_types.Favorite):
        #    print 'DEBUG::subject: FUCK'
        #    self.fav = subject
        #    self.oldname = self.fav.name
        #elif isinstance(subject, TvProgram):
        if isinstance(subject, TvProgram):
            (result, favs) = record_client.getFavorites()
            if result:
                num_favorites = len(favs)
                self.priority = num_favorites + 1
            else:
                self.priority = 1

            self.fav = Favorite(subject.title, subject, TRUE, TRUE, TRUE, 
self.priority)
        else:
            self.fav = subject
            self.oldname = self.fav.name
            


        PopupBox.__init__(self, text='Edit Favorite', left=left, top=top, width=width, 
                          height=height)

        self.v_spacing = 15
        self.h_margin = 20
        self.v_margin = 20

        self.internal_h_align = Align.LEFT

        if not self.left:     self.left   = self.osd.width/2 - self.width/2
        if not self.top:      self.top    = self.osd.height/2 - self.height/2

        guide = epg_xmltv.get_guide()

        name = Label('Name:\t', self, Align.LEFT)
        self.name_input = LetterBoxGroup(text=self.fav.name)
        self.name_input.h_align = Align.NONE
        self.add_child(self.name_input)


        title = Label('Title:\t%s' % self.fav.title, self, Align.LEFT)

        chan = Label('Channel:\t', self, Align.LEFT)

        self.chan_box = OptionBox('ANY')
        self.chan_box.h_align = Align.NONE
        self.chan_box.add_item(text='ANY', value='ANY')
      
        i = 0
        chan_index = 0
        for ch in guide.chan_list:
            if ch.id == self.fav.channel_id:
                chan_index = i
            i += 1
            self.chan_box.add_item(text=ch.id, value=ch.id)


        self.chan_box.toggle_selected_index(chan_index)
        self.add_child(self.chan_box)

        dow = Label('Day of Week:\t', self, Align.LEFT)
        self.dow_box = OptionBox('ANY DAY')
        self.dow_box.h_align = Align.NONE

        self.dow_box.add_item(text='ANY DAY', value='ANY')
        self.dow_box.add_item(text='Mon', value=0)
        self.dow_box.add_item(text='Tues', value=1)
        self.dow_box.add_item(text='Wed', value=2)
        self.dow_box.add_item(text='Thurs', value=3)
        self.dow_box.add_item(text='Fri', value=4)
        self.dow_box.add_item(text='Sat', value=5)
        self.dow_box.add_item(text='Sun', value=6)

        self.dow_box.toggle_selected_index(0)
        self.add_child(self.dow_box)

        tod = Label('Time of Day:\t', self, Align.LEFT)
        self.tod_box = OptionBox('ANY')
        self.tod_box.h_align = Align.NONE
        self.tod_box.add_item(text='ANY TIME', value='ANY')
        self.tod_box.add_item(text='12:00 AM', value=0)
        self.tod_box.add_item(text='11:30 AM', value=30)
        self.tod_box.add_item(text='1:00 AM', value=60)
        self.tod_box.add_item(text='1:30 AM', value=90)
        self.tod_box.add_item(text='2:00 AM', value=120)
        self.tod_box.add_item(text='2:30 AM', value=150)
        self.tod_box.add_item(text='3:00 AM', value=180)
        self.tod_box.add_item(text='3:30 AM', value=210)
        self.tod_box.add_item(text='4:00 AM', value=240)
        self.tod_box.add_item(text='4:30 AM', value=270)
        self.tod_box.add_item(text='5:00 AM', value=300)
        self.tod_box.add_item(text='5:30 AM', value=330)
        self.tod_box.add_item(text='6:00 AM', value=360)
        self.tod_box.add_item(text='6:30 AM', value=390)
        self.tod_box.add_item(text='7:00 AM', value=420)
        self.tod_box.add_item(text='7:30 AM', value=450)
        self.tod_box.add_item(text='8:00 AM', value=480)
        self.tod_box.add_item(text='8:30 AM', value=510)
        self.tod_box.add_item(text='9:00 AM', value=540)
        self.tod_box.add_item(text='9:30 AM', value=570)
        self.tod_box.add_item(text='10:00 AM', value=600)
        self.tod_box.add_item(text='10:30 AM', value=630)
        self.tod_box.add_item(text='11:00 AM', value=660)
        self.tod_box.add_item(text='11:30 AM', value=690)
        self.tod_box.add_item(text='12:00 PM', value=720)
        self.tod_box.add_item(text='12:30 PM', value=750)
        self.tod_box.add_item(text='1:00 PM', value=780)
        self.tod_box.add_item(text='1:30 PM', value=810)
        self.tod_box.add_item(text='2:00 PM', value=840)
        self.tod_box.add_item(text='2:30 PM', value=870)
        self.tod_box.add_item(text='3:00 PM', value=900)
        self.tod_box.add_item(text='3:30 PM', value=930)
        self.tod_box.add_item(text='4:00 PM', value=960)
        self.tod_box.add_item(text='4:30 PM', value=990)
        self.tod_box.add_item(text='5:00 PM', value=1020)
        self.tod_box.add_item(text='5:30 PM', value=1050)
        self.tod_box.add_item(text='6:00 PM', value=1080)
        self.tod_box.add_item(text='6:30 PM', value=1110)
        self.tod_box.add_item(text='7:00 PM', value=1140)
        self.tod_box.add_item(text='7:30 PM', value=1170)
        self.tod_box.add_item(text='8:00 PM', value=1200)
        self.tod_box.add_item(text='8:30 PM', value=1230)
        self.tod_box.add_item(text='9:00 PM', value=1260)
        self.tod_box.add_item(text='9:30 PM', value=1290)
        self.tod_box.add_item(text='10:00 PM', value=1320)
        self.tod_box.add_item(text='10:30 PM', value=1350)
        self.tod_box.add_item(text='11:00 PM', value=1380)
        self.tod_box.add_item(text='11:30 PM', value=1410)
      
        self.tod_box.toggle_selected_index(0)
        self.add_child(self.tod_box)

        self.save = Button('Save')
        self.add_child(self.save)


    def eventhandler(self, event):
        print 'SELECTED CHILD: %s' % self.get_selected_child()
        if self.get_selected_child() == self.name_input:
            if event == em.INPUT_LEFT:
                self.name_input.change_selected_box('left')
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_RIGHT:
                self.name_input.change_selected_box('right')
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_ENTER:
                self.name_input.get_selected_box().toggle_selected()
                self.chan_box.toggle_selected()
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_UP:
                self.name_input.get_selected_box().charUp()
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_DOWN:
                self.name_input.get_selected_box().charDown()
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event in em.INPUT_ALL_NUMBERS: 
                self.name_input.get_selected_box().cycle_phone_char(event)
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_EXIT:
                self.destroy()
                return

        elif self.get_selected_child() == self.chan_box:
            if event in (em.INPUT_UP, em.INPUT_DOWN):
                self.chan_box.change_item(event)
                self.draw()
            elif event == em.INPUT_ENTER:
                if self.chan_box.selected or self.chan_box.list.is_visible():
                    if DEBUG: print '  Want to toggle_box'
                    self.chan_box.toggle_box()
                    self.draw()
            elif event in (em.INPUT_LEFT, em.MENU_PAGEUP):
                self.chan_box.toggle_selected()
                self.name_input.boxes[0].toggle_selected()
                self.draw()
            elif event in (em.INPUT_RIGHT, em.MENU_PAGEDOWN):
                self.chan_box.toggle_selected()
                self.dow_box.toggle_selected()
                self.draw()
            elif event == em.INPUT_EXIT:
                self.destroy()
                return
            self.osd.update(self.get_rect())
            return

        elif self.get_selected_child() == self.dow_box:
            if event in (em.INPUT_UP, em.INPUT_DOWN):
                self.dow_box.change_item(event)
                self.draw()
            elif event == em.INPUT_ENTER:
                if self.dow_box.selected or self.dow_box.list.is_visible():
                    self.dow_box.toggle_box()
                    self.draw()
            elif event in (em.INPUT_LEFT, em.MENU_PAGEUP):
                self.dow_box.toggle_selected()
                self.chan_box.toggle_selected()
                self.draw()
            elif event in (em.INPUT_RIGHT, em.MENU_PAGEDOWN):
                self.dow_box.toggle_selected()
                self.tod_box.toggle_selected()
                self.draw()
            elif event == em.INPUT_EXIT:
                self.destroy()
                return
            self.osd.update(self.get_rect())
            return

        elif self.get_selected_child() == self.tod_box:
            if event in (em.INPUT_UP, em.INPUT_DOWN):
                self.tod_box.change_item(event)
                self.draw()
            elif event == em.INPUT_ENTER:
                if self.tod_box.selected or self.tod_box.list.is_visible():
                    self.tod_box.toggle_box()
                    self.draw()
            elif event in (em.INPUT_LEFT, em.MENU_PAGEUP):
                self.tod_box.toggle_selected()
                self.dow_box.toggle_selected()
                self.draw()
            elif event in (em.INPUT_RIGHT, em.MENU_PAGEDOWN):
                self.tod_box.toggle_selected()
                self.save.toggle_selected()
                self.draw()
            elif event == em.INPUT_EXIT:
                self.destroy()
                return
            self.osd.update(self.get_rect())
            return

        elif self.get_selected_child() == self.save:
            if event == em.INPUT_ENTER:
                if self.oldname:
                    record_client.removeFavorite(self.oldname)
                (result, msg) = record_client.addEditedFavorite(
                             self.name_input.get_word(), 
                             self.fav.title, 
                             self.fav.channel_id, 
                             self.dow_box.list.get_selected_item().value, 
                             self.tod_box.list.get_selected_item().value, 
                             self.fav.priority)
                if result:
                    view_favorites.ViewFavorites(parent=self.parent, 
text='Favorites').show()
                    self.destroy()
                else:
                    AlertBox(parent=self, text='Failed: %s' % msg)
                return
            elif event in (em.INPUT_LEFT, em.MENU_PAGEUP):
                self.save.toggle_selected()
                self.tod_box.toggle_selected()
                self.draw()
            elif event == em.INPUT_EXIT:
                self.destroy()
                return

        if event == em.INPUT_EXIT:
            self.destroy()
            return
        else:
            return self.parent.eventhandler(event)


--- NEW FILE: program_display.py ---
#!/usr/bin/env python
#-----------------------------------------------------------------------
# ProgramDisplay - Information and actions for TvPrograms.
#-----------------------------------------------------------------------
# $Id: program_display.py,v 1.1 2003/06/01 19:05:15 rshortt Exp $
#
# Todo: 
# Notes: 
#
#-----------------------------------------------------------------------
# $Log: program_display.py,v $
# Revision 1.1  2003/06/01 19:05:15  rshortt
# Better to commit these before I mess something up.  Still event code to fix I think, 
among other things.
#
#
#
#-----------------------------------------------------------------------
#
# Freevo - A Home Theater PC framework
#
# Copyright (C) 2002 Krister Lagerstrom, et al.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------

import time

import config, record_client, edit_favorite
import view_favorites, program_search
import event as em

from gui.GUIObject import *
from gui.Border    import *
from gui.Label     import *
from gui.ListBox   import *
from gui.AlertBox  import *

DEBUG = 1


class ProgramDisplay(PopupBox):
    """
    prog      the program to record
    left      x coordinate. Integer
    top       y coordinate. Integer
    width     Integer
    height    Integer
    """
    
    def __init__(self, parent=None, prog=None, left=None, top=None, width=600,
                 height=520):

        self.left = left
        self.top = top
        self.prog = prog
        self.font = None

        PopupBox.__init__(self, left=left, top=top, width=width, 
                          height=height)

        self.v_spacing = 15
        self.h_margin = 20
        self.v_margin = 20

        self.internal_h_align = Align.LEFT

        if self.prog.sub_title:
            title_txt = 'Title:\t%s - %s' % (self.prog.title, self.prog.sub_title)
        else:
            title_txt = 'Title:\t%s' % self.prog.title

        title = Label(title_txt, self, Align.LEFT)

        desc = Label('Description:\t%s' % self.prog.desc, self, Align.LEFT)

        start = Label('Start:\t%s on %s' % (time.strftime('%A %b %d %I:%M %p', 
                                        time.localtime(self.prog.start)),
                                        self.prog.channel_id), 
                                        self, Align.LEFT)

        stop = Label('Stop:\t%s' % time.strftime('%A %b %d %I:%M %p', 
                                     time.localtime(self.prog.stop)), 
                                     self, Align.LEFT)

        self.options = ListBox(width=(self.width-2*self.h_margin), 
                               height=200, show_v_scrollbar=0)
        self.options.items_height = 40
        self.options.add_item(text='Record this episode', value=1)
        self.options.add_item(text='Search for more of this program', value=2)
        self.options.add_item(text='Add "%s" to favorites' % prog.title, value=3)
        self.options.add_item(text='View favorites', value=4)
        self.options.add_item(text='View scheduled recordings', value=5)

        self.options.set_h_align(Align.CENTER)
        self.options.toggle_selected_index(0)
        self.add_child(self.options)


    def eventhandler(self, event):
        if DEBUG: print 'ProgramDisplay: event = %s' % event

        trapped = em.MENU_EVENTS.values()

        #if event in trapped:
        #    return
        if event in (em.INPUT_UP, em.INPUT_DOWN, em.INPUT_LEFT, em.INPUT_RIGHT):
            if DEBUG: print 'ProgramDisplay: should scroll'
            return self.options.eventhandler(event)

        elif event == em.INPUT_ENTER:
            if self.options.get_selected_item().value == 1:
                (result, msg) = record_client.scheduleRecording(self.prog)
                if result:
                    AlertBox(parent=self, 
                             text='%s has been scheduled for recording' % \
                              self.prog.title, handler=self.destroy).show()
                else:
                    AlertBox(parent=self, 
                             text='Scheduling Failed: %s' % msg).show()
            elif self.options.get_selected_item().value == 2:
                program_search.ProgramSearch(parent=self, 
                                             search=self.prog.title).show()
            elif self.options.get_selected_item().value == 3:
                edit_favorite.EditFavorite(parent=self, 
                                           subject=self.prog).show()
            elif self.options.get_selected_item().value == 4:
                view_favorites.ViewFavorites(parent=self).show()
            elif self.options.get_selected_item().value == 5:
                view_recordings.ViewScheduledRecordings(parent=self).show()

        elif event == em.INPUT_EXIT:
            self.destroy()
        else:
            return self.parent.eventhandler(event)


--- NEW FILE: program_search.py ---
#if 0 /*
# -----------------------------------------------------------------------
# ProgramSearch - a popup that allows the user to search the EPG
#                 using a remote.
#               
# -----------------------------------------------------------------------
# $Id: program_search.py,v 1.1 2003/06/01 19:05:15 rshortt Exp $
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# $Log: program_search.py,v $
# Revision 1.1  2003/06/01 19:05:15  rshortt
# Better to commit these before I mess something up.  Still event code to fix I think, 
among other things.
#
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2003 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#   
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#                
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif

import time

import config, record_client, program_display
import event as em

from gui.GUIObject      import *
from gui.PopupBox       import *
from gui.Border         import *
from gui.Label          import *
from gui.LetterBoxGroup import *
from gui.ListBox        import *

DEBUG = 0


class ProgramSearch(PopupBox):
    """
    left      x coordinate. Integer
    top       y coordinate. Integer
    width     Integer
    height    Integer
    text      String to print.
    handler   Function to call after pressing ENTER.
    bg_color  Background color (Color)
    fg_color  Foreground color (Color)
    icon      icon
    border    Border
    bd_color  Border color (Color)
    bd_width  Border width Integer
    """

        
    def __init__(self, parent='osd', text=None, search=None, handler=None, 
                 left=None, top=None, width=600, height=450, bg_color=None, 
                 fg_color=None, icon=None, border=None, bd_color=None, 
                 bd_width=None):

        if not text:
            text = 'Program Search'
        
        PopupBox.__init__(self, parent, text, handler, left, top, width, height, 
                          bg_color, fg_color, icon, border, bd_color, bd_width)

        (self.server_available, msg) = record_client.connectionTest()

        self.internal_h_align = Align.CENTER

        self.lbg = LetterBoxGroup(text=search)
        self.add_child(self.lbg)

        items_height = 40
        self.num_shown_items = 6
        self.results = ListBox(width=(self.width-2*self.h_margin),
                               height=self.num_shown_items*items_height,
                               show_v_scrollbar=0)
        self.results.items_height = items_height
        max_results = 10

        self.results.set_h_align(Align.CENTER)
        self.add_child(self.results)

        if search:
            self.searchProg(search)


    def searchProg(self, find):
        if DEBUG: print 'SEARCHING FOR: %s' % find
        (result, matches) = record_client.findMatches(find)

        if result:
            if DEBUG: print 'FOUND: %s' % len(matches)
            i = 0
            self.results.items = []

            if len(matches) > self.num_shown_items:
                self.results.show_v_scrollbar = 1
            else:
                self.results.show_v_scrollbar = 0

            f = lambda a, b: cmp(a.start, b.start)
            matches.sort(f)
            for prog in matches:
                i += 1
                self.results.add_item(text='%s %s: %s' % \
                                        (time.strftime('%b %d %I:%M %p', 
                                           time.localtime(prog.start)), 
                                         prog.channel_id,
                                         prog.title),
                                      value=prog)

            space_left = self.num_shown_items - i
            if space_left > 0:
                for i in range(space_left):
                    self.results.add_item(text=' ', value=0)


    def eventhandler(self, event):

        print 'SELECTED CHILD: %s' % self.get_selected_child()
        if self.get_selected_child() == self.lbg:
            if event == em.INPUT_LEFT:
                self.lbg.change_selected_box('left')
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_RIGHT:
                self.lbg.change_selected_box('right')
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_ENTER:
                self.searchProg(self.lbg.get_word())
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_UP:
                self.lbg.get_selected_box().charUp()
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_DOWN:
                self.lbg.get_selected_box().charDown()
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.MENU_PAGEDOWN:
                self.lbg.get_selected_box().toggle_selected()
                self.results.toggle_selected_index(0)
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event in em.INPUT_ALL_NUMBERS:
                self.lbg.get_selected_box().cycle_phone_char(event)
                self.draw()
                self.osd.update(self.get_rect())
                return

        elif self.get_selected_child() == self.results:
            if event == em.INPUT_UP or event == em.INPUT_DOWN:
                return self.results.eventhandler(event)
            elif event in (em.INPUT_LEFT, em.INPUT_RIGHT, em.MENU_PAGEUP):
                self.results.get_selected_child().toggle_selected()
                self.lbg.boxes[0].toggle_selected()
                self.draw()
                self.osd.update(self.get_rect())
                return
            elif event == em.INPUT_ENTER:
                prog = self.results.get_selected_child().value
                if prog:
                    program_display.ProgramDisplay(parent=self, prog=prog).show()
                return

        if event == em.INPUT_EXIT:
            self.destroy()
            return
        else:
            return self.parent.eventhandler(event)


--- NEW FILE: view_favorites.py ---
#if 0 /*
# -----------------------------------------------------------------------
# ViewFavorites.py -
#                    
#               
# -----------------------------------------------------------------------
# $Id: view_favorites.py,v 1.1 2003/06/01 19:05:15 rshortt Exp $
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# $Log: view_favorites.py,v $
# Revision 1.1  2003/06/01 19:05:15  rshortt
# Better to commit these before I mess something up.  Still event code to fix I think, 
among other things.
#
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2003 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#   
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#                
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif

import time

import config, record_client, edit_favorite
import event as em

from gui.GUIObject      import *
from gui.PopupBox       import *
from gui.Border         import *
from gui.Label          import *
from gui.ListBox        import *

DEBUG = 0


class ViewFavorites(PopupBox):
    """
    left      x coordinate. Integer
    top       y coordinate. Integer
    width     Integer
    height    Integer
    text      String to print.
    handler   Function to call after pressing ENTER.
    bg_color  Background color (Color)
    fg_color  Foreground color (Color)
    icon      icon
    border    Border
    bd_color  Border color (Color)
    bd_width  Border width Integer
    """

        
    def __init__(self, parent='osd', text=None, search=None, handler=None, 
                 left=None, top=None, width=600, height=520, bg_color=None, 
                 fg_color=None, icon=None, border=None, bd_color=None, 
                 bd_width=None):

        if not text:
            text = 'View Favorites'
        
        PopupBox.__init__(self, parent, text, handler, left, top, width, height, 
                          bg_color, fg_color, icon, border, bd_color, bd_width)

        (self.server_available, msg) = record_client.connectionTest()
        if not self.server_available:
            errormsg = Label('Record server unavailable: %s' % msg, 
                             self, Align.CENTER)
            return 

        self.internal_h_align = Align.CENTER

        legend = Label('Name\tTitle\tChannel\tDOW\tTOD', self, Align.CENTER)

        items_height = 40
        self.num_shown_items = 7
        self.results = ListBox(width=(self.width-2*self.h_margin),
                               height=self.num_shown_items*items_height,
                               show_v_scrollbar=0)
        self.results.items_height = items_height
        max_results = 10

        self.results.set_h_align(Align.CENTER)
        self.add_child(self.results)

        (result, favorites) = record_client.getFavorites()

        if result:
            i = 0

            if len(favorites) > self.num_shown_items:
                self.results.show_v_scrollbar = 1
            else:
                self.results.show_v_scrollbar = 0

            f = lambda a, b: cmp(a.priority, b.priority)
            favorites = favorites.values()
            favorites.sort(f)
            for fav in favorites:
                i += 1
                self.results.add_item(text='%s : %s : %s : %s : %s' % \
                                        (fav.name, 
                                         fav.title,
                                         fav.channel_id,
                                         fav.dow,
                                         fav.mod),
                                      value=fav)

            space_left = self.num_shown_items - i
            if space_left > 0:
                for i in range(space_left):
                    self.results.add_item(text=' ', value=0)

            self.results.toggle_selected_index(0)


    def eventhandler(self, event):

        if event in (em.INPUT_UP, em.INPUT_DOWN, em.INPUT_LEFT, em.INPUT_RIGHT):
            return self.results.eventhandler(event)
        elif event == em.INPUT_ENTER:
            edit_favorite.EditFavorite(parent=self.parent,
                           subject=self.results.get_selected_item().value).show()
            # self.destroy()
            return
        elif event == em.INPUT_EXIT:
            self.destroy()
        else:
            return self.parent.eventhandler(event)





-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to