def _confirm(self): if not self._validate(): return None loader = LoadingWindow() loader.show() name_pattern = _('%(date)s %(channel)s %(start_time)s - %(end_time)s') if self._record_to_remove: old_rec = self._record_to_remove.record old_values = { 'channel': old_rec.service_name, 'date': strftime('%Y/%m/%d', localtime(old_rec.start_time)), 'start_time': seconds_to_hhmm(old_rec.start_time), 'end_time': seconds_to_hhmm(old_rec.stop_time) } computed_old_name = name_pattern % old_values if self._record_to_remove and computed_old_name != self._record_to_remove.name: scheduled_name = self._record_to_remove.name else: values = { 'channel': self.channel_list.selected.name, 'date': strftime('%Y/%m/%d', localtime(self.start_time)), 'start_time': seconds_to_hhmm(self.start_time), 'end_time': seconds_to_hhmm(self.end_time) } scheduled_name = name_pattern % values self._schedule_record(scheduled_name) loader.hide() return None
def record_selected(self): program = self.selected now = int(time()) if program.end_time > now: start_time = max(now, program.start_time) end_time = min(program.end_time, start_time + 21600) channel = program.parent chan_id = int(channel['serviceId']) favorite_name = channel.parent.name values = { 'channel': channel.name, 'title': program.name, 'date': strftime('%Y/%m/%d', localtime(start_time)), 'start_time': seconds_to_hhmm(start_time), 'end_time': seconds_to_hhmm(end_time) } record_name = EPG_RECORDING_NAME_PATTERN % values try: WyRecord().scheduler.ScheduleRecording(chan_id, start_time, end_time, record_name, program_id=program.id, favorite=favorite_name) louie_send('update_record') except SchedulerConflictWithInstantRecordError, e: louie_send('update_record', sender=None) conflicting_rec = e.conflict.getAllRecInConflict()[0] message_pattern = _( 'An instant recording on %(channel)s will be stopped when this recording starts.' ) message = message_pattern % { 'name': ellipsize(conflicting_rec.name, 40), 'start_time': seconds_to_hhmm(conflicting_rec.start_time), 'channel': conflicting_rec.service_name } title = _('Conflict with an instant recording') MessageWindow(message, title, button=None).show(timeout=5) except SchedulerConflictError, e: conflicting_rec = e.conflict.getAllRecInConflict()[0] message_pattern = _( 'The recording you are attempting to schedule conflicts with "%(name)s", starting at %(start_time)s on %(channel)s.' ) message = message_pattern % { 'name': ellipsize(conflicting_rec.name, 40), 'start_time': seconds_to_hhmm(conflicting_rec.start_time), 'channel': conflicting_rec.service_name } title = _('Recording scheduler error') MessageWindow(message, title, button=None).show(timeout=5)
def set(self, **kwargs): if 'reference' in kwargs: self._time_reference = kwargs['reference'] log_val('=============> time_bar class : reference = %s' % seconds_to_hhmm(self._time_reference)) if 'period' in kwargs: self._time_period = kwargs['period'] log_val('=============> time_bar class : _time_period = %s' % seconds_to_hhmmss(self._time_period)) if 'duration' in kwargs: self._duration = kwargs['duration'] log_val('=============> time_bar class : _duration = %s' % seconds_to_hhmmss(self._duration)) if 'begin' in kwargs: self._begin = kwargs['begin'] log_val('=============> time_bar class : _begin = %s' % seconds_to_hhmm(self._begin)) self._redraw()
def __init__(self, name=_('Scheduled recordings'), type='scheduled_navigator'): self.eventhandler = ScheduledRecordMenuEventHandler(self) Menu.__init__(self, name=name, choices=ScheduledRecordRootItem(self).browse(), type=type) self._program = None self._getitems_keywords.update( dict(universe_name=(lambda: UNIVERSE_NAME_DICT[self.type]), parent_icon_name=(lambda: 'parentfolder-%s.png' % self.type), parent_item_name=(lambda: self.name), record_description=self.get_record_description, record_date=( lambda: (seconds_to_long_date(self.selected.record.start_time) if self.selected else '')), record_start_time=( lambda: (seconds_to_hhmm(self.selected.record.start_time) if self.selected else '')), record_stop_time=( lambda: (seconds_to_hhmm(self.selected.record.stop_time) if self.selected else '')), channel_name=(lambda: (self.selected.record.service_name if self.selected else '')), repetition_type=( lambda: (_(self.selected.periodic_rule.extern_rule_name. capitalize()) if (isinstance(self.selected, PeriodicScheduledRecordItem) and _(self.selected.periodic_rule.extern_rule_name. capitalize())) else '')), repetition_number=( lambda: (self.selected.periodic_rule.limit if (isinstance(self.selected, PeriodicScheduledRecordItem) and self.selected.periodic_rule.limit) else '')))) return None
def _schedule_record(self, rec_name): _wyrecord = WyRecord() start_time, stop_time = self.start_time, self.end_time if self._record_to_remove: log.info('Deleting scheduled recording [%s] for replacement', self._record_to_remove) try: rule_id = self._record_to_remove.periodic_rule.id _wyrecord.scheduler.RemovePeriodicRecording( rule_id, delete_records=False) except AttributeError: try: _wyrecord.scheduler.DeleteRecording( self._record_to_remove.record.id) except SchedulerRecordingRunningError: error_title = _('Impossible to cancel recording') message = _('This recording has already started.') MessageWindow(message, error_title, button=None).show(timeout=5) self._record_to_remove = None try: self.scheduled_record = _wyrecord.scheduler.ScheduleRecording( int(self.channel_list.selected['serviceId']), int(start_time), int(stop_time), rec_name, favorite=self['favorite_name']) periodicity_type = self.repetition_type_list.selected periodicity_number = self.repetition_number_list.selected.val rule_id = None if periodicity_type.key != 'none' and periodicity_number > 1: rule_id = _wyrecord.scheduler.createPeriodicityRule( periodicity_type.key) end_date = datetime.fromtimestamp(start_time) + timedelta( days=periodicity_type.val[1] * periodicity_number - 1) res = _wyrecord.scheduler.GeneratePeriodicRecording( self.scheduled_record.id, rule_id, end_date) except SchedulerConflictWithInstantRecordError, e: conflicting_rec = e.conflict.getAllRecInConflict()[0] message_pattern = _( 'An instant recording on %(channel)s will be stopped when this recording starts.' ) message = message_pattern % { 'name': conflicting_rec.name, 'start_time': seconds_to_hhmm(conflicting_rec.start_time), 'channel': conflicting_rec.service_name } title = _('Conflict with an instant recording') MessageWindow(message, title, button=None).show(timeout=5) self.scheduled_record = e.conflict.rec
def select_program(self, event): new_selected = self.selected_program + event if new_selected < 0 and self.lower_limit < self.start_time: self.select_time_slice(-1) new_selected = len(self.displayed_programs) - 1 elif new_selected >= len( self.displayed_programs) and self.end_time < self.upper_limit: self.select_time_slice(0) new_selected = 0 elif 0 <= new_selected < len(self.displayed_programs): self.selected_program = new_selected louie_send('set_selected_program', value=new_selected) prog = self.displayed_programs[self.selected_program] maturity_key = prog['maturityRating'] if maturity_key is not None: maturity = 'maturityrating_%i.png' % int(maturity_key) else: maturity = 'maturityrating_unknown.png' self._summarized_info = { 'program_name': prog.name, 'program_duration': (seconds_to_hhmm_utc(prog.duration) if 'dummy' not in prog['class'] else ''), 'program_start': seconds_to_hhmm(prog.start_time), 'program_date': self.get_selected_program_date(), 'program_maturity_rating': maturity, 'info_press': (_('info') if 'dummy' not in prog['class'] else ''), 'info_icon': self.get_info_icon() } self.refresh_timer.start(AUTO_REFRESH_DELAY, loop=True, consider_idle=True) return None
def __init__(self, name=_('Channels List Menu'), services=[], type='tv_navigator', player=None, fill_root=True): Navigator.__init__(self, name=name, choices=services, type=type, fill_root=fill_root, universe='tv') self.eventhandler = TvNavigatorEventHandler(self) self._all_channel_list = None self._program = None self._player = player self._getitems_keywords.update( dict(program_start_time=( lambda: (seconds_to_hhmm( int(self._program.wymedia_resource['scheduledStartTime'])) if self._program and seconds_to_hhmm( int(self._program.wymedia_resource[ 'scheduledStartTime'])) else '')), program_stop_time=(lambda: (seconds_to_hhmm( int(self._program.wymedia_resource['scheduledEndTime']) ) if self._program and seconds_to_hhmm( int(self._program.wymedia_resource['scheduledEndTime'])) else '')), program_remaining_time=(lambda: (seconds_to_hhmm_utc( min( int(self._program.wymedia_resource['scheduledEndTime'] ) - self._player.real_utc_time, self._program[ 'duration']) ) if self._program and self._player and seconds_to_hhmm_utc( min( int(self._program.wymedia_resource['scheduledEndTime'] ) - self._player.real_utc_time, self._program[ 'duration'])) else '')), program_elapsed_time=(lambda: (seconds_to_hhmm_utc( max( self._player.real_utc_time - int( self._program.wymedia_resource[ 'scheduledStartTime']), 0) ) if self._program and self._player and seconds_to_hhmm_utc( max( self._player.real_utc_time - int( self._program.wymedia_resource[ 'scheduledStartTime']), 0)) else '')), program_duration=( lambda: (seconds_to_hhmm_utc(self._program['duration']) if self._program and seconds_to_hhmm_utc( self._program['duration']) else '')), program_description=( lambda: (self._program.short_description + '\n' + self._program. description if self._program and self._program.short_description + '\n' + self._program.description else '')), program_content_type=(lambda: ( self._program.content_type if self._program and self._program.content_type else '')), live_time=( lambda: (self._player['live_time'] if self._player and self._player['live_time'] else '')), record_timeshift_programbar=self._get_program_bar, recording_info=self._get_recording_info)) self.tasks.update({ 'show_help_left': Task(self._show_help, side=-1), 'show_help_right': Task(self._show_help, side=1) }) return None
def get_end_time(self): return seconds_to_hhmm(self.program.end_time)
def get_start_time(self): return seconds_to_hhmm(self.program.start_time)
self.nodes: {0: <unpyclib.structure.node instance at 0xb75f032c>} nname: 212 n 212(None)[self._redraw() ]: i: 171(), 211() o: nname: 211 n 211(None)[]: i: 159(f) o: 212() nname: 171 n 171(None)[self._begin = kwargs['begin'] log_val('=============> time_bar class : _begin = %s' % seconds_to_hhmm(self._begin)) ]: i: 159(t) o: 212() nname: 159 n 159('begin' in kwargs)[]: i: 118(), 158() o: 171(t), 211(f) nname: 158 n 158(None)[]: i: 106(f) o: 159() nname: 118
def __init__(self, item, name='Scheduled Record information menu'): rec_info = {'start_date': strftime(_('%A %d %B'), localtime(item.record.start_time)), 'start_time': seconds_to_hhmm(item.record.start_time), 'end_time': seconds_to_hhmm(item.record.stop_time)} data = [InfoItem(rec_info, _('Date'), 'start_date', False), InfoItem(rec_info, _('Start time'), 'start_time', False), InfoItem(rec_info, _('End time'), 'end_time', False)] try: repeat_info = {'period': item.period, 'remaining_count': item.remaining_count} data.extend([InfoItem(repeat_info, _('Repeat'), 'period', False), InfoItem(repeat_info, _('Remaining recordings'), 'remaining_count', False)]) if item.remaining_count > 1: data.append(RecordActivationItem(item, self, _('Activation'))) except AttributeError: pass InfoMenu.__init__(self, item, data, name, type='tv_info') return None
class ScheduledRecordMenu(Menu): def __init__(self, name=_('Scheduled recordings'), type_='scheduled_records'): Menu.__init__(self, name, type=type_, universe='tv') self.PERIODICITY = { 'none': (_('Only this time'), 0), 'daily': (_('Every day'), 1), 'weekly': (_('Every week'), 7) } self._favorite_list = [TVRootItem().get_acl(menu=self)] self._favorite_list.extend(TVRootItem().browse_favorites(self)) self._all_channel_list = self._favorite_list[0] self.eventhandler = ModifyScheduledRecordMenuEventHandler(self) self.channel_list = ItemListItem(_('Channels'), menu=self, _list=self._favorite_list, list_name='channel_name_list') self.favorite_list = ItemListItem( _('Favorites'), menu=self, _list=self._all_channel_list.browse(), list_name='favorite_name_list') self.service_list = ItemListItem( _('Channel'), menu=self, _list=[self.channel_list, self.favorite_list], list_name='service_list') self.item_lists_dict['service_list'] = self.service_list _today = date.today() date_list = [[_('Month'), MONTHS], [ _('Year'), [IntegerItem(i) for i in xrange(_today.year + 10)] ], [ _('Day'), [ IntegerItem(i) for i in xrange( 1, days_in_month(_today.year, _today.month) + 1) ] ]] date_order = DATE_ORDERS[user_config['base']['dateformat']] self.day_index = date_order.index(2) self.month_index = date_order.index(0) self.year_index = date_order.index(1) self.date_1_list = ItemListItem(date_list[date_order[0]][0], menu=self, _list=date_list[date_order[0]][1], list_name='date_1_list') self.date_2_list = ItemListItem(date_list[date_order[1]][0], menu=self, _list=date_list[date_order[1]][1], list_name='date_2_list') self.date_3_list = ItemListItem(date_list[date_order[2]][0], menu=self, _list=date_list[date_order[2]][1], list_name='date_3_list') self.date_list = ItemListItem( _('Date'), menu=self, _list=[self.date_1_list, self.date_2_list, self.date_3_list], list_name='date_list') self.item_lists_dict['date_list'] = self.date_list self.start_hour_list = ItemListItem(_('Hour'), menu=self, _list=HOURS, list_name='start_hour_list') self.start_minute_list = ItemListItem(_('Minute'), menu=self, _list=MINUTES, list_name='start_minute_list') self.start_time_list = ItemListItem( _('Start time'), menu=self, _list=[self.start_hour_list, self.start_minute_list], list_name='start_time_list') self.item_lists_dict['start_time_list'] = self.start_time_list self.stop_hour_list = ItemListItem(_('Hour'), menu=self, _list=HOURS, list_name='stop_hour_list') self.stop_minute_list = ItemListItem(_('Minute'), menu=self, _list=MINUTES, list_name='stop_minute_list') self.stop_time_list = ItemListItem( _('End time'), menu=self, _list=[self.stop_hour_list, self.stop_minute_list], list_name='stop_time_list') self.item_lists_dict['stop_time_list'] = self.stop_time_list self.record_name = '' def _fun(key): it = Item(self.PERIODICITY[key][0], 'periodic', self) it.val = self.PERIODICITY[key] it.key = key return it self.repetition_type_list = ItemListItem( _('Frequency'), menu=self, _list=map(_fun, ['none', 'daily', 'weekly']), list_name='repetition_type_list') self.repetition_list = ItemListItem(_('Frequency'), menu=self, _list=[self.repetition_type_list], list_name='repetition_list') self.item_lists_dict['repetition_list'] = self.repetition_list self.repetition_number_list = ItemListItem( _('Number of recordings'), menu=self, _list=REPEAT_NUMBERS, list_name='repetition_number_list') self.repetition_num_list = ItemListItem( _('Number of recordings'), menu=self, _list=[self.repetition_number_list], list_name='repetition_num_list') self.item_lists_dict['repetition_num_list'] = self.repetition_num_list self.confirm_list = ItemListItem( _('Confirm'), menu=self, list_name='confirmation_option_list', _list=[Item(_('Confirm'), 'choice', menu=self)]) self.cancel_list = ItemListItem( _('Cancel'), menu=self, list_name='cancellation_option_list', _list=[Item(_('Cancel'), 'choice', menu=self)]) self.confirm_list.execute = self._confirm self.cancel_list.execute = self.cancel self.confirmation_list = ItemListItem( _('Actions'), menu=self, list_name='confirmation_list', _list=[self.confirm_list, self.cancel_list]) self.confirmation_list.select(None, True) self.item_lists_dict['confirmation_list'] = self.confirmation_list self.set_items([ self.service_list, self.date_list, self.start_time_list, self.stop_time_list, self.repetition_list, self.repetition_num_list, self.confirmation_list ]) self._getitems_keywords.update({ 'channel_name': (lambda: (self.channel_list.selected.name if self.channel_list.selected and self. channel_list.selected.name else _('Unknown'))), 'favorite_name': (lambda: (self.favorite_list.selected.name if self.favorite_list.selected and self.favorite_list. selected.name else _('Unknown'))), 'record_name': (lambda: self.record_name), 'date_1': (lambda: self.date_1_list.selected.name), 'date_2': (lambda: self.date_2_list.selected.name), 'date_3': (lambda: self.date_3_list.selected.name), 'date_weekday': self._get_weekday_from_date, 'start_hour': (lambda: self.start_hour_list.selected.name), 'start_minute': (lambda: self.start_minute_list.selected.name), 'stop_hour': (lambda: self.stop_hour_list.selected.name), 'stop_minute': (lambda: self.stop_minute_list.selected.name), 'repetition_type': (lambda: self.repetition_type_list.selected.name), 'repetition_number': (lambda: self.repetition_number_list.selected.name), 'confirmation_list': (lambda: self.confirmation_list) }) self._record_to_remove = None self.scheduled_record = None return None def show(self, *args, **kw): Menu.show(self, *args, **kw) if self.is_only_this_time(): louie_send('frequency_only_this_time_on', sender=self) else: louie_send('frequency_only_this_time_off', sender=self) return None def is_only_this_time(self): return self.get_item_list('repetition_list')[0].selected_pos == 0 def _get_weekday_from_date(self): date_list = self.date_list return day_dict[date( int(date_list[self.year_index].selected.name), int(date_list[self.month_index].selected.name), int(date_list[self.day_index].selected.name)).weekday()] def update_day_list(self): d_list = self.date_list[self.day_index] d = days_in_month(self.date_list[self.year_index].selected.val, self.date_list[self.month_index].selected.val) if d != len(d_list): self.date_list[self.day_index].set_items( [IntegerItem(i, menu=self) for i in xrange(1, d + 1)], selected=min(d_list.selected_pos, d - 1)) louie_send('date_%d' % (self.day_index + 1), sender=self, value=self.date_list[self.day_index].selected.name) return None def select_date(self, _date, stop=None): struct_t = localtime(_date) self.date_list[self.year_index].select(IntegerItem(struct_t[0])) self.date_list[self.month_index].select(IntegerItem(struct_t[1])) self.date_list[self.day_index].select(IntegerItem(struct_t[2])) louie_send('date_weekday', sender=self, value=self['date_weekday']) self.start_hour_list.select(IntegerItem(struct_t[3])) self.start_minute_list.select(IntegerItem(struct_t[4])) if stop: struct_t = localtime(stop) self.stop_hour_list.select(IntegerItem(struct_t[3])) self.stop_minute_list.select(IntegerItem(struct_t[4])) return None def select_channel(self, chan_info, current_favorite=None): favorite_list = [TVRootItem().get_acl(menu=self)] favorite_list.extend(TVRootItem().browse_favorites(self)) self.favorite_list.set_items(favorite_list) if current_favorite is None: self.favorite_list.select(0, force_pos=True) else: self.favorite_list.select(current_favorite) chans = self.favorite_list.selected.browse() self.channel_list.set_items(chans) self.channel_list.select(chan_info) return None def _set_record(self, scheduled_record): self._record_to_remove = scheduled_record _wyrecord = WyRecord() self.record_name = scheduled_record.name self.select_date(scheduled_record.record.start_time, scheduled_record.record.stop_time) target_channel = TVRootItem().get_acl( self).get_channel_from_service_id( str(scheduled_record.record.service_id)) for i in xrange(len(self.favorite_list)): if self.favorite_list[i]['serviceId'] == str( scheduled_record.record.service_id): target_channel, target_channel = None, self.favorite_list[i] break self.select_channel(target_channel) if isinstance(scheduled_record, PeriodicScheduledRecordItem): _rule = _wyrecord.scheduler.GetPeriodicRuleById( scheduled_record.record.periodicity_rule_id) self.repetition_type_list.select( Item(self.PERIODICITY[_rule.extern_rule_name][0], 'periodic', self)) _num = (mktime(_rule.last_time.timetuple()) - _rule.recording_ref.start_time) / float( self.PERIODICITY[_rule.extern_rule_name][1] * 86400) self.repetition_number_list.select(IntegerItem(int(_num))) return None # Check that the user input is correct. # # If a value is incorrect, send Louie signals to highlight the incorrect # fields, display a pop-up to inform the user and return False. # # Otherwise, clear the input field highlights and return True. def _validate(self): all_fields = set(['date', 'start_time', 'end_date', 'end_time']) invalid_fields = set() error_message = None now = time() start_time, end_time = self.start_time, self.end_time if abs(end_time - start_time) > 21600: error_message = _('The recording cannot be longer than 6 hours.') if end_time < now: error_message = _( 'You are trying to record a program already over.') invalid_fields.add('end_time') if now - end_time >= 86400: invalid_fields.add('date') for field in all_fields.difference(invalid_fields): louie_send('%s_valid' % field, sender=self) if error_message is not None: for field in invalid_fields: louie_send('%s_invalid' % field, sender=self) error_title = _('Invalid data') MessageWindow(error_message, error_title, button=None).show(timeout=5) return False return True # Execute the actual recording scheduling. def _schedule_record(self, rec_name): _wyrecord = WyRecord() start_time, stop_time = self.start_time, self.end_time if self._record_to_remove: log.info('Deleting scheduled recording [%s] for replacement', self._record_to_remove) try: rule_id = self._record_to_remove.periodic_rule.id _wyrecord.scheduler.RemovePeriodicRecording( rule_id, delete_records=False) except AttributeError: try: _wyrecord.scheduler.DeleteRecording( self._record_to_remove.record.id) except SchedulerRecordingRunningError: error_title = _('Impossible to cancel recording') message = _('This recording has already started.') MessageWindow(message, error_title, button=None).show(timeout=5) self._record_to_remove = None try: self.scheduled_record = _wyrecord.scheduler.ScheduleRecording( int(self.channel_list.selected['serviceId']), int(start_time), int(stop_time), rec_name, favorite=self['favorite_name']) periodicity_type = self.repetition_type_list.selected periodicity_number = self.repetition_number_list.selected.val rule_id = None if periodicity_type.key != 'none' and periodicity_number > 1: rule_id = _wyrecord.scheduler.createPeriodicityRule( periodicity_type.key) end_date = datetime.fromtimestamp(start_time) + timedelta( days=periodicity_type.val[1] * periodicity_number - 1) res = _wyrecord.scheduler.GeneratePeriodicRecording( self.scheduled_record.id, rule_id, end_date) except SchedulerConflictWithInstantRecordError, e: conflicting_rec = e.conflict.getAllRecInConflict()[0] message_pattern = _( 'An instant recording on %(channel)s will be stopped when this recording starts.' ) message = message_pattern % { 'name': conflicting_rec.name, 'start_time': seconds_to_hhmm(conflicting_rec.start_time), 'channel': conflicting_rec.service_name } title = _('Conflict with an instant recording') MessageWindow(message, title, button=None).show(timeout=5) self.scheduled_record = e.conflict.rec except SchedulerConflictError, e: conflicting_rec = e.conflict.getAllRecInConflict()[0] message_pattern = _( 'The recording you are attempting to schedule conflicts with "%(name)s", starting at %(start_time)s on %(channel)s.' ) message = message_pattern % { 'name': conflicting_rec.name, 'start_time': seconds_to_hhmm(conflicting_rec.start_time), 'channel': conflicting_rec.service_name } error_title = _('Recording scheduler error') MessageWindow(message, error_title, button=None).show(timeout=5) return None