Hi Jose
I just tried your patches and it is looking good at the first glance.
If you agree, I will keep working on the ProgramItem for programs and
scheduled programs. I will try to integrate your favorite handling and
my ideas (see earlier posting).
Please, let me know, if you have other ideas/plans, as I really
do not want to interfere...
Regards
Tanja
Jose schrieb:
> Hi,
>
> I have added changing a favorites day, start time, stop time and channel
> to the tv.favorite.py class.
> For this I also needed to change other files. See attached diffs.
>
> Some explanation on the changes:
> - tvserver/src/favorite.py:
> This class required a start and stop time in string format, but
> it returned time (via long_list()) as a int. I changed that so
> that it also returns an string format.
> - tvserver/src/server.py:
> Added rpc_favorite_modify() + fixed some problems
> - core/src/ipc/tvserver.py:
> Added modify()
> - ui/src/tv/favorite.py:
> Added new features.
>
> Regards,
> Jose
>
>
> ------------------------------------------------------------------------
>
> Index: favorite.py
> ===================================================================
> --- favorite.py (revision 9583)
> +++ favorite.py (working copy)
> @@ -32,6 +32,7 @@
> #
> -----------------------------------------------------------------------------
>
> # python imports
> +import re
> import time
>
> # kaa imports
> @@ -51,8 +52,12 @@
> # get tvserver interface
> tvserver = freevo.ipc.Instance('freevo').tvserver
>
> -DAY_NAMES = (_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'),
> _('Sat'))
> +DAY_NAMES = [_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'),
> _('Sat')]
>
> +#Define the time slots (when chnaging the time) in minutes
> +TIME_SLOTS = 10
> +TIME_RANGE = (1440 / TIME_SLOTS)
> +
> class FavoriteItem(Item):
> """
> A favorite item to add/delete/change a favorite for the recordserver.
> @@ -63,6 +68,8 @@
>
> self.new = True
> self.id = 0
> + self.start = float(0)
> + self.stop = float(1440*60)-1
> if isinstance(fav, kaa.epg.Program):
> # created with Program object
> # Convert to 0=Sunday - 6=Saterday
> @@ -77,13 +84,18 @@
> if day in f.days:
> self.new = False
> self.id = f.id
> + for t in f.times:
> + self.start, self.stop = self._str_to_time(t)
> else:
> # created with ipc Favorite object
> self.name = self.title = fav.title
> self.days = fav.days
> self.channels = fav.channels
> + #self.start = fav.time
> self.new = False
> self.id = fav.id
> + for t in fav.times:
> + self.start, self.stop = self._str_to_time(t)
>
>
> def __getitem__(self, key):
> @@ -102,6 +114,14 @@
> else:
> channels = ', '.join(['%s' % chan for chan in self.channels])
> return channels
> + if key == 'time':
> + return self['start'] + u' - ' + self['stop']
> + if key == 'start':
> + return unicode(time.strftime(config.tv.timeformat,
> + time.gmtime(self.start)))
> + if key == 'stop':
> + return unicode(time.strftime(config.tv.timeformat,
> + time.gmtime(self.stop)))
> return Item.__getitem__(self, key)
>
>
> @@ -123,6 +143,15 @@
> else:
> items.append(ActionItem(_('Remove favorite'), self, self.remove))
>
> + items.append(ActionItem(_('Change day'), self, self.change_days))
> + items.append(ActionItem(_('Change channel'), self,
> self.change_channels))
> + action = ActionItem(_('Change start time'), self, self.change_time)
> + action.parameter('start')
> + items.append(action)
> + action = ActionItem(_('Change stop time'), self, self.change_time)
> + action.parameter('stop')
> + items.append(action)
> +
> s = Menu(self, items, type = 'tv favorite menu')
> s.submenu = True
> s.infoitem = self
> @@ -132,16 +161,16 @@
> @kaa.notifier.yield_execution()
> def add(self):
> result = tvserver.favorites.add(self.title, self.channels, self.days,
> - 'ANY', 50, False)
> + [self._time_to_str()], 50, False)
> if isinstance(result, kaa.notifier.InProgress):
> yield result
> result = result()
> if result != tvserver.favorites.SUCCESS:
> text = _('Adding favorite Failed')+(': %s' % result)
> else:
> - text = _('"%s" has been scheduled as favorite') % self.title
> + text = _('"%s" has been added to your favorites') % self.title
> MessageWindow(text).show()
> - self.get_menustack().delete_submenu()
> + self.get_menustack().back_one_menu()
>
>
> @kaa.notifier.yield_execution()
> @@ -153,4 +182,126 @@
> if result != tvserver.favorites.SUCCESS:
> text = _('Remove favorite Failed')+(': %s' % result)
> MessageWindow(text).show()
> - self.get_menustack().delete_submenu()
> + self.get_menustack().back_one_menu()
> +
> + @kaa.notifier.yield_execution()
> + def modify(self, info):
> + result = tvserver.favorites.modify(self.id, info)
> + if isinstance(result, kaa.notifier.InProgress):
> + yield result
> + result = result()
> + if result != tvserver.favorites.SUCCESS:
> + text = _('Modified favorite Failed')+(': %s' % result)
> + MessageWindow(text).show()
> +
> + def change_days(self):
> + items = []
> + action = ActionItem('ANY', self, self.handle_change)
> + action.parameter('days', 'ANY')
> + items.append(action)
> + for dayname in DAY_NAMES:
> + action = ActionItem(dayname, self, self.handle_change)
> + action.parameter('days', dayname)
> + items.append(action)
> +
> + s = Menu(self, items, type = 'tv favorite menu')
> + s.submenu = True
> + s.infoitem = self
> + self.get_menustack().pushmenu(s)
> +
> + def change_channels(self):
> + items = []
> + action = ActionItem('ANY', self, self.handle_change)
> + action.parameter('channels', 'ANY')
> + items.append(action)
> +
> + list = kaa.epg.get_channels(sort=True)
> + for chan in list:
> + action = ActionItem(chan.name, self, self.handle_change)
> + action.parameter('channels', chan.name)
> + items.append(action)
> +
> + s = Menu(self, items, type = 'tv favorite menu')
> + s.submenu = True
> + s.infoitem = self
> + self.get_menustack().pushmenu(s)
> +
> + def change_time(self, startstop):
> + items = []
> + action = ActionItem('ANY', self, self.handle_change)
> + action.parameter(startstop, 'ANY')
> + items.append(action)
> + if startstop == 'start':
> + starttime = self.start
> + else:
> + starttime = self.stop - (self.stop % (TIME_SLOTS * 60))
> + for i in range(TIME_RANGE):
> + newtime = float( (i * TIME_SLOTS * 60) + starttime) % (1440 * 60)
> + showtime = unicode(time.strftime(config.tv.timeformat,
> + time.gmtime(newtime)))
> + action = ActionItem(showtime, self, self.handle_change)
> + action.parameter(startstop, newtime)
> + items.append(action)
> +
> + s = Menu(self, items, type = 'tv favorite menu')
> + s.submenu = True
> + s.infoitem = self
> + self.get_menustack().pushmenu(s)
> +
> + def handle_change(self, item, value):
> +
> + info = None
> + infovalue = None
> + if item == 'days':
> + info = 'days'
> + if value == 'ANY':
> + self.days = [0, 1, 2, 3, 4, 5, 6]
> + else:
> + self.days = [DAY_NAMES.index(value)]
> + infovalue = self.days
> + if item == 'channels':
> + info = 'channels'
> + if value == 'ANY':
> + self.channels = []
> + list = kaa.epg.get_channels(sort=True)
> + for chan in list:
> + self.channels.append(chan.name)
> + else:
> + self.channels = [value]
> + infovalue = self.channels
> + if item == 'start':
> + info = 'times'
> + if value == 'ANY':
> + self.start = float(0)
> + self.stop = float(1440*60)-1
> + else:
> + self.start = value
> + infovalue = [self._time_to_str()]
> + if item == 'stop':
> + info = 'times'
> + if value == 'ANY':
> + self.start = float(0)
> + self.stop = float(1440*60)-1
> + else:
> + self.stop = value
> + infovalue = [self._time_to_str()]
> +
> + if not self.new:
> + self.modify([(info, infovalue)])
> +
> + self.get_menustack().back_one_menu()
> +
> + def _time_to_str(self):
> + start = time.strftime('%H:%M', time.gmtime(self.start))
> + stop = time.strftime('%H:%M', time.gmtime(self.stop))
> + return start + '-' + stop
> +
> + def _str_to_time(self, t):
> + # internal regexp for time format
> + _time_re = re.compile('([0-9]*):([0-9]*)-([0-9]*):([0-9]*)')
> +
> + m = _time_re.match(t).groups()
> + start = float(m[0])*3600 + float(m[1])*60
> + stop = float(m[2])*3600 + float(m[3])*60
> +
> + return start, stop
>
>
> ------------------------------------------------------------------------
>
> Index: tvserver.py
> ===================================================================
> --- tvserver.py (revision 9583)
> +++ tvserver.py (working copy)
> @@ -291,7 +291,7 @@
> """
> A favorite object from the recordserver.
> """
> - def __init__(self, id, title, channels, priority, days, time, one_shot,
> + def __init__(self, id, title, channels, priority, days, times, one_shot,
> substring):
> """
> The init function creates the object. The parameters are the complete
> @@ -302,7 +302,7 @@
> self.channels = channels
> self.priority = priority
> self.days = days
> - self.time = time
> + self.times = times
> self.one_shot = one_shot
> self.substring = substring
> self.description = {}
> @@ -414,6 +414,23 @@
> yield self.SUCCESS
>
>
> + @kaa.notifier.yield_execution()
> + def modify(self, id, info):
> + """
> + remove a favorite
> + parameter: id of the favorite,
> + info of the changed item [ ( var, val ) (...) ]
> + """
> + if not self.server:
> + yield _('tvserver unavailable')
> + result = self.rpc('home-theatre.favorite.modify', id, info)
> + yield result
> + if not result():
> + # FIXME: get real error message from tvserver
> + yield 'failed'
> + yield self.SUCCESS
> +
> +
> def list(self):
> """
> """
>
>
> ------------------------------------------------------------------------
>
> Index: favorite.py
> ===================================================================
> --- favorite.py (revision 9583)
> +++ favorite.py (working copy)
> @@ -86,11 +86,7 @@
> self.fxdname = ''
> self.once = once
> self.substring = substring
> - for t in times:
> - m = _time_re.match(t).groups()
> - start = int(m[0])*100 + int(m[1])
> - stop = int(m[2])*100 + int(m[3])
> - self.times.append((start, stop))
> + self.times = times
> self.start_padding = config.record.start_padding
> self.stop_padding = config.record.stop_padding
>
> @@ -119,10 +115,7 @@
> if child.name == 'times':
> self.times = []
> for t in child.children:
> - m = _time_re.match(t.content).groups()
> - start = int(m[0])*100 + int(m[1])
> - stop = int(m[2])*100 + int(m[3])
> - self.times.append((start, stop))
> + self.times.append(t.content)
> if child.name == 'padding':
> self.start_padding = int(child.getattr('start'))
> self.stop_padding = int(child.getattr('stop'))
> @@ -159,8 +152,11 @@
> if not int(time.strftime('%w', timestruct)) in self.days:
> return False
> stime = int(timestruct[3]) * 100 + int(timestruct[4])
> - for t1, t2 in self.times:
> - if stime >= t1 and stime <= t2:
> + for t in self.times:
> + m = _time_re.match(t).groups()
> + start = int(m[0])*100 + int(m[1])
> + stop = int(m[2])*100 + int(m[3])
> + if stime >= start and stime <= stop:
> return True
> return False
>
> @@ -252,8 +248,7 @@
> channels.add_child('channel', chan)
> times = node.add_child('times')
> for t in self.times:
> - times.add_child('start', '%02d:%02d-%02d:%02d' % \
> - (t[0] / 100, t[0] % 100, t[1] / 100, t[1] % 100))
> + times.add_child('start', t)
> if self.once:
> node.add_child('once')
> if self.substring:
>
>
> ------------------------------------------------------------------------
>
> Index: server.py
> ===================================================================
> --- server.py (revision 9583)
> +++ server.py (working copy)
> @@ -433,10 +433,10 @@
>
>
> @freevo.ipc.expose('home-theatre.recording.modify')
> - def rpc_recording_modify(self, int, info):
> + def rpc_recording_modify(self, id, info):
> """
> modify a recording
> - parameter: id [ ( var val ) (...) ]
> + parameter: id, [ ( var, val ) (...) ]
> """
> key_val = dict(info)
> log.info('recording.modify: %s' % id)
> @@ -564,6 +564,12 @@
> return NameError('Already scheduled')
> self.favorites.append(f)
>
> + #Align favorites id(s)
> + next = 0
> + for r in self.favorites:
> + r.id = next
> + next += 1
> +
> # update schedule
> self.epg_update()
>
> @@ -586,6 +592,12 @@
> return NameError('Favorite not found!')
> log.info('favorite.remove: %s', f)
> self.favorites.remove(f)
> +
> + #Align favorites id(s)
> + next = 0
> + for r in self.favorites:
> + r.id = next
> + next += 1
>
> # send update to all clients
> msg = [ f.long_list() for f in self.favorites ]
> @@ -593,6 +605,29 @@
> return []
>
>
> + @freevo.ipc.expose('home-theatre.favorite.modify')
> + def rpc_favorite_modify(self, id, info):
> + """
> + modify a recording
> + parameter: id, [ ( var, val ) (...) ]
> + """
> + key_val = dict(info)
> + log.info('favorite.modify: %s' % id)
> + for r in self.favorites:
> + if r.id == id:
> + cp = copy.copy(self.favorites[id])
> + for key in key_val:
> + setattr(cp, key, key_val[key])
> + self.favorites[self.favorites.index(r)] = cp
> + # update schedule
> + self.epg_update()
> + # send update to all clients
> + msg = [ f.long_list() for f in self.favorites ]
> + self.send_event('home-theatre.favorite.list.update', *msg)
> + return []
> + return IndexError('Favorite not found')
> +
> +
> @freevo.ipc.expose('home-theatre.favorite.list')
> def rpc_favorite_list(self):
> """
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Freevo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freevo-devel
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-devel