def fillSearchPanel(self, update=False, movies=False): self.lastSearchRefresh = time.time() items = [] try: searchResults = hdhr.guide.search(self.devices.apiAuthID(),category=self.category,terms=self.searchTerms) or [] except: searchResults = [] e = util.ERROR() util.showNotification(e,header=T(32831)) util.setGlobalProperty('NO_RESULTS',not searchResults and T(32802) or '') for r in searchResults: item = kodigui.ManagedListItem(r.title,r.synopsis,thumbnailImage=r.icon,data_source=r) item.setProperty('series.title',r.title) item.setProperty('channel.number',r.channelNumber) item.setProperty('channel.name',r.channelName) item.setProperty('channel.icon',r.channelIcon) item.setProperty('has.rule',r.hasRule and '1' or '') item.setProperty('hidden',r.hidden and '1' or '') items.append(item) if update: if self.category == 'movie': self.moviePanel.replaceItems(items) else: self.searchPanel.replaceItems(items) else: if self.category == 'movie': self.moviePanel.reset() self.moviePanel.addItems(items) else: self.searchPanel.reset() self.searchPanel.addItems(items)
def test(): from torchtext import data from datasets import build_bible_datasets from options import get_options bucket_iter_train, _ = build_bible_datasets() sample = next(iter(bucket_iter_train)) merge_dim = 1 en_sem, en_sty, decoder, adv_disc = build_models(bucket_iter_train.dataset, get_options()) in_var, in_len = sample.sent_0 #print(in_var.shape, in_len.shape) # torch.Size([32, 56 or 66]) torch.Size([32]) # print ('length0',sample.sent_0[1]) # print ('length1',sample.sent_1[1]) sem_out = T(en_sem(sample.sent_0)) print('result of en_sem', sem_out.shape) # [1, 32, 20] sty_out = T(en_sty(sample.sent_1)) #print('sty_out', sty_out.shape, 'concat', T(torch.cat([sty_out, sty_out], dim=merge_dim)).shape) merged = T(torch.cat([sem_out, sty_out], dim=merge_dim)) disc_out = T(adv_disc(merged)) merged.unsqueeze_(0) #print('merged2', merged.shape) decoder_outputs, _, _ = decoder( inputs= None, # pass not None for teacher focring (batch, seq_len, input_size) encoder_hidden= merged, # (num_layers * num_directions, batch_size, hidden_size) encoder_outputs=None, # pass not None for attention teacher_forcing_ratio=0 # range 0..1 , must pass inputs if >0 ) decoder_outputs = decoder_outputs
def fillRules(self, update=False): self.lastRulesRefresh = time.time() if update: self.storageServer.updateRules() items = [] for r in self.storageServer.rules: item = kodigui.ManagedListItem(r.title, data_source=r) if r.dateTimeOnly: item.setProperty( 'rule.recent_only', '{0} at {1}'.format(r.displayDateDTO(), r.displayTimeDTO())) elif r.teamOnly: item.setProperty('rule.recent_only', '{0}: {1}'.format('TEAM', r.teamOnly)) else: item.setProperty('rule.recent_only', r.recentOnly and T(32805) or T(32806)) item.setProperty('seriesID', r.seriesID) #print '{0} {1}'.format(r.ruleID, r.title) items.append(item) if not items: util.setGlobalProperty( 'NO_RULES', self.storageServer.getRulesFailed and u'[COLOR 80FF0000]{0}[/COLOR]'.format(T(32830)) or T(32804)) else: util.setGlobalProperty('NO_RULES', '') self.ruleList.reset() self.ruleList.addItems(items)
def deleteRule(self, rule=None, ep=None): if ep: self.storageServer.deleteRule(rule, ep) else: if not rule: item = self.ruleList.getSelectedItem() if not item: return rule = item.dataSource yes = xbmcgui.Dialog().yesno(T(32035),T(32037)) if not yes: return util.withBusyDialog(self.storageServer.deleteRule,'DELETING',rule) def update(sitem): if rule.seriesID == sitem.dataSource.ID: sitem.dataSource['RecordingRule'] = '' sitem.setProperty('has.rule','') for control in (self.searchPanel, self.moviePanel, self.nowShowingPanel1, self.nowShowingPanel2): for sItem in control: update(sItem) self.fillRules(update=True)
def init(self): self.started = False self.showList = None self.searchPanel = None self.moviePanel = None self.ruleList = None self.searchTerms = '' self.category = 'series' self.play = None self.options = None self.devices = self.main.devices self.storageServer = hdhr.storageservers.StorageServers(self.devices) self.lineUp = self.main.lineUp self.cron = self.main.cron self.lastRecordingsRefresh = 0 self.lastSearchRefresh = 0 self.lastRulesRefresh = 0 self.nowShowing = None self.nowShowingHalfHour = None self.nsPanel2 = False self.nowShowingPanel1LastItem = None self.nowShowingPanel2LastItem = None self.wheelIgnore = False self.movingRule = None self.mode = 'WATCH' util.setGlobalProperty('now.showing','') util.setGlobalProperty('movie.posters','') util.setGlobalProperty('NO_RESULTS',T(32802)) util.setGlobalProperty('NO_RECORDINGS',T(32803)) util.setGlobalProperty('NO_RULES',T(32804))
def add(self, episode=None, team=None): try: self.storageServer.addRule(self.series, episode=episode, team=team, StartPadding=self.startPadding, EndPadding=self.endPadding) if self.series: if not episode and not team: self.rule = self.storageServer.getSeriesRule( self.series.ID) or self.rule self.ruleAdded = True except hdhr.errors.RuleModException as e: util.showNotification(e.message, header=T(32832)) return if self.parent: self.parent.fillRules(update=True) self.parent.delayedUpdateRecordings() # else: # self.series['RecordingRule'] = 1 xbmcgui.Dialog().ok(T(32800), T(32801), '', self.series.title) if self.rule: self.setProperty('show.hasRule', '1') if not episode: self.fillEpisodeList() self.series['RecordingRule'] = any([e.hasRule for e in self.episodes]) self.showHideButton()
class Action(Item): _type = 'action' _elements = ({ 'attr': 'file', 'type': None, 'limits': LIMIT_FILE, 'name': T(32085, 'Action file path'), 'default': '' }, { 'attr': 'eval', 'type': None, 'limits': LIMIT_ACTION, 'name': T(32089, 'Test'), 'default': '' }) displayName = T(32083, 'Actions') typeChar = '!' fileChar = '_' def __init__(self): Item.__init__(self) self.file = '' self.eval = None def elementVisible(self, e): attr = e['attr'] if attr == 'eval': return bool(self.file) return True
def train_scene_discriminator(b, models, dont_optimize): models.adv_disc.zero_grad() h_sty0 = models.en_sty(T(b.sent_1)) h_sty0or2 = models.en_sty( T(b.sent_x )) # same style, same or different semantics with random chance merged = torch.cat([h_sty0, h_sty0or2], dim=1) out = models.adv_disc(merged).flatten() y = T(b.is_x_0) bce = bce2(out, y) if not dont_optimize: bce.backward() optimizer_adv_disc.step() acc = np.round(N(out.detach())) == np.round(N(y)) logger.debug(f'adv_disc out {out.shape} is_x_0 {y.shape}') logger.debug( f'out {out.flatten()} y {y.flatten()} acc {acc} bce {bce.data}') acc = acc.reshape(-1) acc = acc.sum() / len(acc) return N(bce.data), N(acc)
def fillShows(self, update=False): self.lastRecordingsRefresh = time.time() groupItems = [] seriesItems = [] groups = {} for r in self.storageServer.recordings: if r.displayGroupID in groups: item = groups[r.displayGroupID] ct = int(item.getProperty('show.count')) ct += 1 item.setProperty('show.count', str(ct)) else: if r.category == 'movie': title = T(32843) elif r.category == 'sport': title = T(32844) else: title = r.seriesTitle item = kodigui.ManagedListItem(title, r.seriesSynopsis, thumbnailImage=r.icon, data_source=r) item.setProperty('show.count', '1') item.setProperty('groupID', r.displayGroupID) groups[r.displayGroupID] = item if r.groupIsSeries: seriesItems.append(item) else: groupItems.append(item) groupItems.sort(key=lambda x: util.sortTitle(x.getLabel())) seriesItems.sort(key=lambda x: util.sortTitle(x.getLabel())) items = groupItems + seriesItems if not items: util.setGlobalProperty( 'NO_RECORDINGS', self.storageServer.getRecordingsFailed and u'[COLOR 80FF0000]{0}[/COLOR]'.format(T(32829)) or T(32803)) else: util.setGlobalProperty('NO_RECORDINGS', '') if items: allItem = kodigui.ManagedListItem( 'ALL RECORDINGS', thumbnailImage='script-hdhomerun-view-dvr_all.png') items.insert(0, allItem) if update: self.showList.replaceItems(items) else: self.showList.reset() self.showList.addItems(items)
def doContextMenu(self): return items = [('delete', T(32809))] idx = xbmcgui.Dialog().select(T(32810),[i[1] for i in items]) if idx < 0: return choice = items[idx][0] if choice == 'delete': self.doDelete()
def getSettingDisplay(self, setting): val = getattr(self, setting) limits = self.getLimits(setting) if limits == LIMIT_BOOL_DEFAULT: if val is None: return u'{0} ({1})'.format(T(32322, 'Default'), settingDisplay(util.getSettingDefault('{0}.{1}'.format(self._type, setting)))) return val is True and T(32320, 'Yes') or T(32321, 'No') if val is None or val is 0: return u'{0} ({1})'.format(T(32322, 'Default'), settingDisplay(util.getSettingDefault('{0}.{1}'.format(self._type, setting)))) return unicode(settingDisplay(val))
def doRuleContext(self): options = [T(32807), T(32809)] idx = xbmcgui.Dialog().select(T(32810), options) if idx < 0: return try: if idx == 0: self.toggleRuleRecent() elif idx == 1: self.deleteRule() except hdhr.errors.RuleModException, e: util.showNotification(e.message, header=T(32827))
def showHideButton(self, show=True): if self.series.hidden: show = True elif self.series.hasRule: show = False else: show = self.showHide if show: hideText = self.series.hidden and T(32841) or T(32840) self.setProperty('show.hide', hideText) else: self.setProperty('show.hide', '')
def setWindowProperties(self): if self.groupID: if self.groupID == 'movie': self.setProperty('sort.name.label', T(32845)) elif self.groupID == 'sport': self.setProperty('sort.name.label', T(32845)) else: self.setProperty('sort.name.label', T(32842)) else: self.setProperty('sort.name.label', T(32815)) self.setProperty('sort.mode',self.sortMode) self.setProperty('sort.asc',self.sortASC and '1' or '')
def hide(self): try: util.withBusyDialog(self.storageServer.hideSeries, 'HIDING', self.series) except hdhr.errors.SeriesHideException, e: util.showNotification(e.message, header=T(32838)) return
def make_grad_solve_triangular(ans, a, b, trans=0, lower=False, **kwargs): tri = anp.tril if (lower ^ (_flip(a, trans) == 'N')) else anp.triu transpose = lambda x: x if _flip(a, trans) != 'N' else T(x) ans = anp.reshape(ans, a.shape[:-1] + (-1,)) def solve_triangular_grad(g): v = solve_triangular(a, g, trans=_flip(a, trans), lower=lower) return -transpose(tri(anp.matmul(anp.reshape(v, ans.shape), T(ans)))) return solve_triangular_grad
def add(self, episode=None, team=None): try: self.storageServer.addRule(self.series, episode=episode, team=team, StartPadding=self.startPadding, EndPadding=self.endPadding) if self.series: if not episode and not team: self.rule = self.storageServer.getSeriesRule( self.series.ID) or self.rule self.ruleAdded = True except hdhr.errors.RuleModException, e: util.showNotification(e.message, header=T(32832)) return
def setSearch(self, category=None): #self.searchTerms = self.getControl(self.SEARCH_EDIT_ID).getText() or '' if category: self.searchTerms = '' self.category = category catDisplay = { 'series': 'Shows', 'movie': 'Movies', 'sport': 'Sports', 'nowshowing': 'Now Showing' } util.setGlobalProperty('search.terms', catDisplay[category]) if category == 'nowshowing': self.fillNowShowing() util.setGlobalProperty('movie.posters', '') util.setGlobalProperty('now.showing', '1') else: if self.nowShowing: self.nowShowing.pos = 0 util.setGlobalProperty('now.showing', '') if category == 'movie': util.setGlobalProperty('movie.posters', '1') else: util.setGlobalProperty('movie.posters', '') self.fillSearchPanel() else: self.searchTerms = xbmcgui.Dialog().input(T(32812), self.searchTerms) if not self.searchTerms: return util.setGlobalProperty('now.showing', '') util.setGlobalProperty('movie.posters', '') self.category = '' util.setGlobalProperty('search.terms', self.searchTerms) self.fillSearchPanel() if util.getGlobalProperty('NO_RESULTS'): self.setFocusId(202) else: if category != 'nowshowing': if category == 'movie': self.setFocusId(self.MOVIE_PANEL_ID) else: self.setFocusId(self.SEARCH_PANEL_ID)
class Feature(Item): _type = 'feature' _elements = ({ 'attr': 'count', 'type': int, 'limits': (0, 10, 1), 'name': T(32060, 'Count'), 'default': 0 }, { 'attr': 'ratingBumper', 'type': None, 'limits': [None, 'none', 'video', 'image'], 'name': T(32077, 'Rating bumper'), 'default': None }, { 'attr': 'ratingStyleSelection', 'type': None, 'limits': [None, 'random', 'style'], 'name': T(32080, 'Rating style selection'), 'default': None }, { 'attr': 'ratingStyle', 'type': None, 'limits': LIMIT_DB_CHOICE, 'name': T(32081, 'Rating style'), 'default': None }, { 'attr': 'volume', 'type': int, 'limits': (0, 100, 1), 'name': T(32025, 'Volume (% of current)'), 'default': 0 }) displayName = T(32073, 'Features') typeChar = 'F' def __init__(self): Item.__init__(self) self.count = 0 self.ratingBumper = None self.ratingStyleSelection = None self.ratingStyle = None self.volume = 0 def display(self): name = self.name or self.displayName if self.count > 1: return u'{0} x {1}'.format(name, self.count) return name def elementVisible(self, e): attr = e['attr'] if attr == 'ratingStyle': return self.getLive( 'ratingStyleSelection') == 'style' and self.getLive( 'ratingBumper') in ('video', 'image') elif attr == 'ratingStyleSelection': return self.getLive('ratingBumper') in ('video', 'image') return True @staticmethod def DBChoices(attr): import database as DB DB.initialize() ratingSystem = util.getSettingDefault('rating.system.default') DB.connect() try: return [(x.style, x.style) for x in DB.RatingsBumpers.select( DB.fn.Distinct(DB.RatingsBumpers.style)).where( DB.RatingsBumpers.system == ratingSystem)] finally: DB.close()
class Command(Item): _type = 'command' _elements = ({ 'attr': 'command', 'type': None, 'limits': ['back', 'skip'], 'name': T(32331, 'Command') }, { 'attr': 'arg', 'type': None, 'limits': None, 'name': T(32332, 'Argument') }, { 'attr': 'condition', 'type': None, 'limits': ['feature.queue=full', 'feature.queue=empty', 'none'], 'name': T(32333, 'Condition') }) displayName = T(32331, 'Command') typeChar = 'C' def _set(self, attr, value): if self.command in ('back', 'skip'): if attr == 'arg': value = int(value) Item._set(self, attr, value) def __init__(self): Item.__init__(self) self.command = '' self.arg = '' self.condition = '' def getLimits(self, attr): e = self.getElement(attr) if not e['attr'] == 'arg' or self.command not in ('skip', 'back'): return Item.getLimits(self, attr) return (1, 99, 1) def getType(self, attr): e = self.getElement(attr) if not e['attr'] == 'arg' or self.command not in ('skip', 'back'): return Item.getType(self, attr) return int def getSettingOptions(self, setting): if setting == 'arg': if self.command in ('back', 'skip'): return (1, 99, 1) else: return Item.getSettingOptions(self, setting) def setSetting(self, setting, value): Item.setSetting(self, setting, value) if setting == 'command': if self.command == 'back': if not self.condition: self.condition = 'feature.queue=full' if not self.arg: self.arg = 2 elif self.command == 'skip': if not self.condition: self.condition = 'feature.queue=empty' if not self.arg: self.arg = 2 else: self.condition = '' def getSetting(self, setting): if self.command in ('back', 'skip'): if setting == 'arg': if not self.arg: self.arg = 2 return Item.getSetting(self, setting) def display(self): name = self.name or self.displayName command = self.command and u' ({0}:{1})'.format( self.command, self.arg) or '' return u'{0}{1}'.format(name, command)
class AudioFormat(Item): _type = 'audioformat' _elements = ({ 'attr': 'method', 'type': None, 'limits': [None, 'af.detect', 'af.format', 'af.file'], 'name': T(32068, 'Method'), 'default': None }, { 'attr': 'fallback', 'type': None, 'limits': [None, 'af.format', 'af.file'], 'name': T(32072, 'Fallback'), 'default': None }, { 'attr': 'file', 'type': None, 'limits': LIMIT_FILE_DEFAULT, 'name': T(32325, 'Path'), 'default': '' }, { 'attr': 'format', 'type': None, 'limits': [ None, 'Auro-3D', 'Dolby Digital', 'Dolby Digital Plus', 'Dolby TrueHD', 'Dolby Atmos', 'DTS', 'DTS-HD Master Audio', 'DTS-X', 'Datasat', 'THX', 'Other' ], 'name': T(32030, 'Format'), 'default': None }, { 'attr': 'play3D', 'type': strToBool, 'limits': LIMIT_BOOL, 'name': T(32328, 'Play 3D if 3D feature'), 'default': True }, { 'attr': 'volume', 'type': int, 'limits': (0, 100, 1), 'name': T(32025, 'Volume (% of current)'), 'default': 0 }) displayName = T(32329, 'Audio Format Bumper') typeChar = 'A' def __init__(self): Item.__init__(self) self.method = None self.fallback = None self.format = None self.file = None self.play3D = True self.volume = 0 def elementVisible(self, e): attr = e['attr'] if attr == 'fallback': return self.getLive('method') == 'af.detect' elif attr == 'file': return self.getLive('method') == 'af.file' or ( self.getLive('method') == 'af.detect' and self.getLive('fallback') == 'af.file') elif attr == 'format': return self.getLive('method') == 'af.format' or ( self.getLive('method') == 'af.detect' and self.getLive('fallback') == 'af.format') elif attr == 'play3D': return self.getLive('method') in (None, 'af.detect', 'af.format') return True
import util from util import T SAVE_VERSION = 2 LIMIT_FILE = 0 LIMIT_FILE_DEFAULT = 1 LIMIT_DIR = 2 LIMIT_DB_CHOICE = 3 LIMIT_BOOL = 4 LIMIT_BOOL_DEFAULT = 5 LIMIT_MULTI_SELECT = 6 LIMIT_ACTION = 7 SETTINGS_DISPLAY = { '3D.intro': T(32300, '3D Intro'), '3D.outro': T(32301, '3D Outro'), 'countdown': T(32302, 'Countdown'), 'courtesy': T(32303, 'Courtesy'), 'feature.intro': T(32304, 'Feature Intro'), 'feature.outro': T(32305, 'Feature Outro'), 'intermission': T(32306, 'Intermission'), 'short.film': T(32307, 'Short Film'), 'theater.intro': T(32308, 'Theater Intro'), 'theater.outro': T(32309, 'Theater Outro'), 'trailers.intro': T(32310, 'Trailers Intro'), 'trailers.outro': T(32311, 'Trailers Outro'), 'trivia.intro': T(32312, 'Trivia Intro'), 'trivia.outro': T(32313, 'Trivia Outro'), 'back': T(32314, 'Back'), 'skip': T(32315, 'Skip'),
class Video(Item): _type = 'video' _elements = ({ 'attr': 'vtype', 'type': None, 'limits': [ '3D.intro', '3D.outro', 'countdown', 'courtesy', 'feature.intro', 'feature.outro', 'intermission', 'short.film', 'theater.intro', 'theater.outro', 'trailers.intro', 'trailers.outro', 'trivia.intro', 'trivia.outro', 'dir', 'file' ], 'name': T(32327, 'Type') }, { 'attr': 'random', 'type': strToBool, 'limits': LIMIT_BOOL, 'name': T(32057, 'Random'), 'default': True }, { 'attr': 'source', 'type': None, 'limits': LIMIT_DB_CHOICE, 'name': T(32052, 'Source') }, { 'attr': 'dir', 'type': None, 'limits': LIMIT_DIR, 'name': T(32047, 'Directory') }, { 'attr': 'count', 'type': int, 'limits': (1, 10, 1), 'name': T(32060, 'Count'), 'default': 0 }, { 'attr': 'file', 'type': None, 'limits': LIMIT_FILE_DEFAULT, 'name': T(32048, 'File'), }, { 'attr': 'play3D', 'type': strToBool, 'limits': LIMIT_BOOL, 'name': T(32328, 'Play 3D If 3D Feature'), 'default': True }, { 'attr': 'volume', 'type': int, 'limits': (0, 100, 1), 'name': T(32025, 'Volume (% of current)'), 'default': 0 }) displayName = T(32023, 'Video') typeChar = 'V' def __init__(self): Item.__init__(self) self.vtype = '' self.random = True self.source = '' self.dir = '' self.count = 1 self.file = '' self.play3D = True self.volume = 0 def elementVisible(self, e): attr = e['attr'] if attr == 'source': return self.vtype not in ('file', 'dir') and not self.random elif attr == 'dir': return self.vtype == 'dir' elif attr == 'count': return self.vtype == 'dir' or (self.vtype != 'file' and self.random) elif attr == 'file': return self.vtype == 'file' elif attr == 'random': return self.vtype != 'file' elif attr == 'play3D': return self.random and self.vtype not in ('3D.intro', '3D.outro', 'dir', 'file') return True def display(self): if self.name: name = self.name elif not self.vtype: name = self.displayName else: name = settingDisplay(self.vtype) if self.count > 1 and (self.vtype == 'dir' or (self.vtype != 'file' and self.random)): return u'{0} x {1}'.format(name, self.count) return name def DBChoices(self, attr): import database as DB DB.initialize() DB.connect() try: return [(x.path, os.path.basename(x.path)) for x in DB.VideoBumpers.select().where( DB.VideoBumpers.type == self.vtype)] finally: DB.close()
def solve_triangular_grad(g): v = solve_triangular(a, g, trans=_flip(a, trans), lower=lower) return -transpose(tri(anp.matmul(anp.reshape(v, ans.shape), T(ans))))
class DVRBase(util.CronReceiver): SHOW_LIST_ID = 101 SEARCH_PANEL_ID = 201 MOVIE_PANEL_ID = 211 NOW_SHOWING_PANEL1_ID = 271 NOW_SHOWING_PANEL1_DOWN_BUTTON_ID = 281 NOW_SHOWING_PANEL1_UP_BUTTON_ID = 283 NOW_SHOWING_PANEL2_ID = 272 NOW_SHOWING_PANEL2_DOWN_BUTTON_ID = 282 NOW_SHOWING_PANEL2_UP_BUTTON_ID = 284 SEARCH_EDIT_ID = 204 SEARCH_EDIT_BUTTON_ID = 204 RULE_LIST_ID = 301 WATCH_BUTTON = 103 SEARCH_BUTTON = 203 RULES_BUTTON = 303 RECORDINGS_REFRESH_INTERVAL = 600 SEARCH_REFRESH_INTERVAL = 3600 RULES_REFRESH_INTERVAL = 3660 def __init__(self, *args, **kwargs): self._BASE.__init__(self, *args, **kwargs) self.main = kwargs.get('main') self.actionHandler = ActionHandler(self.checkMouseWheel) self.init() @property def mode(self): return util.getGlobalProperty('DVR_MODE') @mode.setter def mode(self, val): if util.getGlobalProperty('DVR_MODE') == 'RULES' and val != 'RULES': self.moveRule(None) util.setGlobalProperty('DVR_MODE', val) def onFirstInit(self): self.start() @util.busyDialog('LOADING DVR') def init(self): self.started = False self.showList = None self.searchPanel = None self.moviePanel = None self.ruleList = None self.searchTerms = '' self.category = 'series' self.play = None self.options = None self.devices = self.main.devices self.storageServer = hdhr.storageservers.StorageServers(self.devices) self.lineUp = self.main.lineUp self.cron = self.main.cron self.lastRecordingsRefresh = 0 self.lastSearchRefresh = 0 self.lastRulesRefresh = 0 self.nowShowing = None self.nowShowingHalfHour = None self.nsPanel2 = False self.nowShowingPanel1LastItem = None self.nowShowingPanel2LastItem = None self.wheelIgnore = False self.movingRule = None self.mode = 'WATCH' util.setGlobalProperty('now.showing', '') util.setGlobalProperty('movie.posters', '') util.setGlobalProperty('NO_RESULTS', T(32802)) util.setGlobalProperty('NO_RECORDINGS', T(32803)) util.setGlobalProperty('NO_RULES', T(32804)) def start(self): if self.showList: self.showList.reInit(self, self.SHOW_LIST_ID) else: self.showList = kodigui.ManagedControlList(self, self.SHOW_LIST_ID, 5) self.fillShows() self.searchPanel = kodigui.ManagedControlList(self, self.SEARCH_PANEL_ID, 6) self.fillSearchPanel() self.moviePanel = kodigui.ManagedControlList(self, self.MOVIE_PANEL_ID, 6) self.nowShowingPanel1 = kodigui.ManagedControlList( self, self.NOW_SHOWING_PANEL1_ID, 6) self.nowShowingPanel2 = kodigui.ManagedControlList( self, self.NOW_SHOWING_PANEL2_ID, 6) self.ruleList = kodigui.ManagedControlList(self, self.RULE_LIST_ID, 10) self.fillRules() if self.showList.size(): self.setFocusId(self.SHOW_LIST_ID) else: self.setMode('SEARCH') self.cron.registerReceiver(self) def onAction(self, action): try: if action == xbmcgui.ACTION_PREVIOUS_MENU or action == xbmcgui.ACTION_NAV_BACK: util.setGlobalProperty('dvr.active', '') self.moveRule(None) self.options = True #self.main.showOptions(from_dvr=True) self.doClose() elif self.mode == 'SEARCH': return self.onActionSearch(action) elif self.mode == 'WATCH': return self.onActionWatch(action) elif self.mode == 'RULES': return self.onActionRules(action) except: self._BASE.onAction(self, action) util.ERROR() return self._BASE.onAction(self, action) def onActionSearch(self, action): if action == xbmcgui.ACTION_GESTURE_SWIPE_LEFT: return self.setMode('RULES') elif action == xbmcgui.ACTION_GESTURE_SWIPE_RIGHT: return self.setMode('WATCH') elif action == xbmcgui.ACTION_CONTEXT_MENU: if xbmc.getCondVisibility( 'ControlGroup(551).HasFocus(0) | Control.HasFocus(201) | Control.HasFocus(211)' ): return self.setFocusId(self.SEARCH_EDIT_BUTTON_ID) elif action == xbmcgui.ACTION_MOVE_DOWN or action == xbmcgui.ACTION_MOVE_UP or action == xbmcgui.ACTION_MOVE_RIGHT or action == xbmcgui.ACTION_MOVE_LEFT: if not xbmc.getCondVisibility( 'ControlGroup(550).HasFocus(0) | ControlGroup(551).HasFocus(0) | ControlGroup(552).HasFocus(0) | Control.HasFocus(201) | Control.HasFocus(211)' ): return self.setFocusId(self.SEARCH_EDIT_ID) elif action in (xbmcgui.ACTION_MOUSE_WHEEL_DOWN, xbmcgui.ACTION_MOUSE_WHEEL_UP): return self.checkMouseWheelInitial(action) elif action == xbmcgui.ACTION_PAGE_UP: if self.getFocusId() == self.NOW_SHOWING_PANEL1_ID: return self.onFocus(self.NOW_SHOWING_PANEL1_UP_BUTTON_ID, from_action=True) elif self.getFocusId() == self.NOW_SHOWING_PANEL2_ID: return self.onFocus(self.NOW_SHOWING_PANEL2_UP_BUTTON_ID, from_action=True) elif action == xbmcgui.ACTION_PAGE_DOWN: if self.getFocusId() == self.NOW_SHOWING_PANEL1_ID: return self.onFocus(self.NOW_SHOWING_PANEL1_DOWN_BUTTON_ID, from_action=True) elif self.getFocusId() == self.NOW_SHOWING_PANEL2_ID: return self.onFocus(self.NOW_SHOWING_PANEL2_DOWN_BUTTON_ID, from_action=True) elif action.getButtonCode() in (61575, 61486): if self.getFocusId() in (self.SEARCH_PANEL_ID, self.NOW_SHOWING_PANEL1_ID, self.NOW_SHOWING_PANEL2_ID): return self.removeSeries() def onActionWatch(self, action): if action == xbmcgui.ACTION_GESTURE_SWIPE_LEFT: return self.setMode('SEARCH', focus=self.SEARCH_EDIT_ID) elif action == xbmcgui.ACTION_MOVE_DOWN or action == xbmcgui.ACTION_MOVE_UP or action == xbmcgui.ACTION_MOVE_RIGHT or action == xbmcgui.ACTION_MOVE_LEFT: if self.getFocusId( ) != self.SHOW_LIST_ID and not util.getGlobalProperty( 'NO_RECORDINGS'): return self.setFocusId(self.SHOW_LIST_ID) def onActionRules(self, action): # if action == xbmcgui.ACTION_GESTURE_SWIPE_RIGHT: # return self.setMode('SEARCH', focus=self.SEARCH_EDIT_ID) # elif action == xbmcgui.ACTION_CONTEXT_MENU: # if self.getFocusId() == self.RULE_LIST_ID: # return self.doRuleContext() if action == xbmcgui.ACTION_MOVE_DOWN or action == xbmcgui.ACTION_MOVE_UP or action == xbmcgui.ACTION_MOVE_RIGHT or action == xbmcgui.ACTION_MOVE_LEFT: if self.getFocusId() != self.RULE_LIST_ID: if self.ruleList.size(): self.setFocusId(self.RULE_LIST_ID) if self.movingRule and action == xbmcgui.ACTION_MOVE_DOWN or action == xbmcgui.ACTION_MOVE_UP: self.moveRule(True) # elif action == xbmcgui.ACTION_SELECT_ITEM and self.getFocusId() == self.RULE_LIST_ID: # self.moveRule() # elif action == xbmcgui.ACTION_MOUSE_LEFT_CLICK: # if self.getFocusId() == self.RULE_LIST_ID: # #print action.getAmount1() # if 620 < action.getAmount1() < 710: # self.toggleRuleRecent() # elif action.getAmount1() < 619: # self.moveRule() elif action == xbmcgui.ACTION_MOUSE_MOVE and self.getFocusId( ) == self.RULE_LIST_ID: if self.movingRule: self.moveRule(True) elif action.getButtonCode() in (61575, 61486): if self.getFocusId() == self.RULE_LIST_ID: return self.deleteRule() def onClick(self, controlID): #print 'click: {0}'.format(controlID) if controlID == self.SHOW_LIST_ID: self.openEpisodeDialog() elif controlID in (self.SEARCH_PANEL_ID, self.MOVIE_PANEL_ID): self.openRecordDialog('SEARCH') elif controlID == self.RULE_LIST_ID: if self.movingRule: self.moveRule() else: self.openRecordDialog('RULES') elif controlID == self.NOW_SHOWING_PANEL1_ID or controlID == self.NOW_SHOWING_PANEL2_ID: self.openRecordDialog('NOWSHOWING') # self.nowShowingClicked(controlID) # elif controlID == self.RULE_LIST_ID: # self.toggleRuleRecent() elif controlID == self.WATCH_BUTTON: self.setMode('WATCH') elif controlID == self.SEARCH_BUTTON: if self.mode == 'SEARCH': self.setSearch() else: return self.setMode('SEARCH', focus=self.SEARCH_EDIT_ID) elif controlID == self.RULES_BUTTON: self.setMode('RULES') elif controlID == self.SEARCH_EDIT_BUTTON_ID: self.setSearch() elif 290 < controlID < 295: self.nowShowingTimeClicked(controlID) elif 204 < controlID < 209: idx = controlID - 205 self.setSearch(category=('series', 'movie', 'sport', 'nowshowing')[idx]) def onFocus(self, controlID, from_action=False, from_scroll=False): #print 'focus: {0}'.format(controlID) if xbmc.getCondVisibility('ControlGroup(100).HasFocus(0)'): self.mode = 'WATCH' elif xbmc.getCondVisibility('ControlGroup(200).HasFocus(0)'): if self.mode != 'SEARCH': return self.setMode('SEARCH', focus=self.SEARCH_EDIT_ID) self.mode = 'SEARCH' elif xbmc.getCondVisibility('ControlGroup(300).HasFocus(0)'): self.mode = 'RULES' if controlID == self.NOW_SHOWING_PANEL2_DOWN_BUTTON_ID: self.nsPanel2 = False self.fillNowShowing(next_section=True, fix_selection=not from_action) elif controlID == self.NOW_SHOWING_PANEL1_DOWN_BUTTON_ID: self.nsPanel2 = True self.fillNowShowing(next_section=True, fix_selection=not from_action) elif controlID == self.NOW_SHOWING_PANEL2_UP_BUTTON_ID: if not self.nowShowing: return self.nowShowing.pos -= 1 if self.nowShowing.pos < 0: self.nowShowing.pos = 0 self.setFocusId( self.NOW_SHOWING_PANEL2_ID ) # Touch focus on the panel so that it's focus will be remembered in the 551 control group if not from_action and not from_scroll: self.setFocusId(self.SEARCH_EDIT_BUTTON_ID) return self.nsPanel2 = False self.fillNowShowing(prev_section=True, fix_selection=not from_action) elif controlID == self.NOW_SHOWING_PANEL1_UP_BUTTON_ID: if not self.nowShowing: return self.nowShowing.pos -= 1 if self.nowShowing.pos < 0: self.nowShowing.pos = 0 self.setFocusId( self.NOW_SHOWING_PANEL1_ID ) # Touch focus on the panel so that it's focus will be remembered in the 551 control group if not from_action and not from_scroll: self.setFocusId(self.SEARCH_EDIT_BUTTON_ID) return self.nsPanel2 = True self.fillNowShowing(prev_section=True, fix_selection=not from_action) def tick(self): now = time.time() if now - self.lastRecordingsRefresh > self.RECORDINGS_REFRESH_INTERVAL: self.updateRecordings() if now - self.lastSearchRefresh > self.SEARCH_REFRESH_INTERVAL: if self.category != 'nowshowing': self.fillSearchPanel(update=True) if now - self.lastRulesRefresh > self.RULES_REFRESH_INTERVAL: self.fillRules(update=True) if self.nowShowing: if self.nowShowing.checkTime(): self.updateNowShowing() # def halfHour(self): # self.updateNowShowing() def setMode(self, mode, focus=None): self.mode = mode if mode == 'WATCH': self.setFocusId(focus or 100) elif mode == 'SEARCH': self.setFocusId(focus or 200) elif mode == 'RULES': self.setFocusId(focus or 300) def checkMouseWheelInitial(self, action): if self.category != 'nowshowing': return try: if self.getFocusId() == self.NOW_SHOWING_PANEL1_ID: item = self.nowShowingPanel1.getSelectedItem() if item == self.nowShowingPanel1LastItem: self.actionHandler.onAction(action) self.nowShowingPanel1LastItem = item return True elif self.getFocusId() == self.NOW_SHOWING_PANEL2_ID: item = self.nowShowingPanel2.getSelectedItem() if item == self.nowShowingPanel2LastItem: self.actionHandler.onAction(action) self.nowShowingPanel2LastItem = item return True except RuntimeError: # Get this (Index out of range) when the list has changed since being triggered pass return False def checkMouseWheel(self, action): if action == xbmcgui.ACTION_MOUSE_WHEEL_DOWN: if self.getFocusId() == self.NOW_SHOWING_PANEL1_ID: self.onFocus(self.NOW_SHOWING_PANEL1_DOWN_BUTTON_ID, from_scroll=True) elif self.getFocusId() == self.NOW_SHOWING_PANEL2_ID: self.onFocus(self.NOW_SHOWING_PANEL2_DOWN_BUTTON_ID, from_scroll=True) elif action == xbmcgui.ACTION_MOUSE_WHEEL_UP: if self.getFocusId() == self.NOW_SHOWING_PANEL1_ID: self.onFocus(self.NOW_SHOWING_PANEL1_UP_BUTTON_ID, from_scroll=True) elif self.getFocusId() == self.NOW_SHOWING_PANEL2_ID: self.onFocus(self.NOW_SHOWING_PANEL2_UP_BUTTON_ID, from_scroll=True) def nowShowingTimeClicked(self, controlID): if controlID == 291: self.onFocus(self.NOW_SHOWING_PANEL1_UP_BUTTON_ID, from_action=True) elif controlID == 293: self.onFocus(self.NOW_SHOWING_PANEL1_DOWN_BUTTON_ID, from_action=True) if controlID == 292: self.onFocus(self.NOW_SHOWING_PANEL2_UP_BUTTON_ID, from_action=True) elif controlID == 294: self.onFocus(self.NOW_SHOWING_PANEL2_DOWN_BUTTON_ID, from_action=True) def updateRecordings(self): util.DEBUG_LOG('DVR: Refreshing recordings') self.storageServer.updateRecordings() self.fillShows(update=True) def delayedUpdateRecordings(self): self.lastRecordingsRefresh = (time.time() - self.RECORDINGS_REFRESH_INTERVAL) + 5 @util.busyDialog('LOADING SHOWS') def fillShows(self, update=False): self.lastRecordingsRefresh = time.time() groupItems = [] seriesItems = [] groups = {} for r in self.storageServer.recordings: if r.displayGroupID in groups: item = groups[r.displayGroupID] ct = int(item.getProperty('show.count')) ct += 1 item.setProperty('show.count', str(ct)) else: if r.category == 'movie': title = T(32843) elif r.category == 'sport': title = T(32844) else: title = r.seriesTitle item = kodigui.ManagedListItem(title, r.seriesSynopsis, thumbnailImage=r.icon, data_source=r) item.setProperty('show.count', '1') item.setProperty('groupID', r.displayGroupID) groups[r.displayGroupID] = item if r.groupIsSeries: seriesItems.append(item) else: groupItems.append(item) groupItems.sort(key=lambda x: util.sortTitle(x.getLabel())) seriesItems.sort(key=lambda x: util.sortTitle(x.getLabel())) items = groupItems + seriesItems if not items: util.setGlobalProperty( 'NO_RECORDINGS', self.storageServer.getRecordingsFailed and u'[COLOR 80FF0000]{0}[/COLOR]'.format(T(32829)) or T(32803)) else: util.setGlobalProperty('NO_RECORDINGS', '') if items: allItem = kodigui.ManagedListItem( 'ALL RECORDINGS', thumbnailImage='script-hdhomerun-view-dvr_all.png') items.insert(0, allItem) if update: self.showList.replaceItems(items) else: self.showList.reset() self.showList.addItems(items) @util.busyDialog('LOADING GUIDE') def fillSearchPanel(self, update=False, movies=False): self.lastSearchRefresh = time.time() items = [] try: searchResults = hdhr.guide.search(self.devices.apiAuthID(), category=self.category, terms=self.searchTerms) or [] except: searchResults = [] e = util.ERROR() util.showNotification(e, header=T(32831)) util.setGlobalProperty('NO_RESULTS', not searchResults and T(32802) or '') for r in searchResults: item = kodigui.ManagedListItem(r.title, r.synopsis, thumbnailImage=r.icon, data_source=r) item.setProperty('series.title', r.title) item.setProperty('channel.number', r.channelNumber) item.setProperty('channel.name', r.channelName) item.setProperty('channel.icon', r.channelIcon) item.setProperty('has.rule', r.hasRule and '1' or '') item.setProperty('hidden', r.hidden and '1' or '') items.append(item) if update: if self.category == 'movie': self.moviePanel.replaceItems(items) else: self.searchPanel.replaceItems(items) else: if self.category == 'movie': self.moviePanel.reset() self.moviePanel.addItems(items) else: self.searchPanel.reset() self.searchPanel.addItems(items) @util.busyDialog('LOADING NOW SHOWING') def fillNowShowing(self, next_section=False, prev_section=False, fix_selection=True, current=False): if not self.nowShowing: self.nowShowing = hdhr.guide.NowShowing(self.devices) if current: if self.nowShowing.pos > 0: self.nsPanel2 = bool(self.nowShowing.pos % 2) prev_section = True if next_section: self.nowShowing.pos += 1 try: searchResults, nextDisp, footerDisp = self.nowShowing.upNext() except hdhr.guide.EndOfNowShowingException: self.nowShowing.pos -= 1 if self.nsPanel2: self.setFocusId(self.NOW_SHOWING_PANEL1_ID) util.setGlobalProperty('ns.panel1.footer', 'END') else: self.setFocusId(self.NOW_SHOWING_PANEL2_ID) util.setGlobalProperty('ns.panel2.footer', 'END') self.nsPanel2 = not self.nsPanel2 return if self.nsPanel2: util.setGlobalProperty('ns.panel2.heading', nextDisp) util.setGlobalProperty('ns.panel2.footer', footerDisp) self.fillNSPanel2(searchResults) if fix_selection: off1 = self.nowShowingPanel1.getSelectedPosition() % 5 if self.nowShowingPanel2.positionIsValid(off1): self.nowShowingPanel2.selectItem(off1) self.setFocusId(self.NOW_SHOWING_PANEL2_ID) self.slideNSUp() else: util.setGlobalProperty('ns.panel1.heading', nextDisp) util.setGlobalProperty('ns.panel1.footer', footerDisp) self.fillNSPanel1(searchResults) if fix_selection: off2 = self.nowShowingPanel2.getSelectedPosition() % 5 if self.nowShowingPanel1.positionIsValid(off2): self.nowShowingPanel1.selectItem(off2) self.setFocusId(self.NOW_SHOWING_PANEL1_ID) self.slideNSUp() elif prev_section: searchResults, prevDisp, footerDisp = self.nowShowing.upNext() if self.nsPanel2: util.setGlobalProperty('ns.panel2.heading', prevDisp) util.setGlobalProperty('ns.panel2.footer', footerDisp) self.fillNSPanel2(searchResults) if fix_selection: off1 = (self.nowShowingPanel1.getSelectedPosition() + 1) % 5 off2 = self.nowShowingPanel2.size() % 5 if off1 < off2: self.nowShowingPanel2.selectItem( (self.nowShowingPanel2.size() - 1) - (off2 - off1)) elif off2 < off1: self.nowShowingPanel2.selectItem( (self.nowShowingPanel2.size() - 6) + (off1 - off2)) else: self.nowShowingPanel2.selectItem( (self.nowShowingPanel2.size() - 1)) self.setFocusId(self.NOW_SHOWING_PANEL2_ID) self.slideNSDown() else: util.setGlobalProperty('ns.panel1.heading', prevDisp) util.setGlobalProperty('ns.panel1.footer', footerDisp) self.fillNSPanel1(searchResults) if fix_selection: off1 = self.nowShowingPanel1.size() % 5 off2 = (self.nowShowingPanel2.getSelectedPosition() + 1) % 5 if off2 < off1: self.nowShowingPanel1.selectItem( (self.nowShowingPanel1.size() - 1) - (off1 - off2)) elif off1 < off2: self.nowShowingPanel1.selectItem( (self.nowShowingPanel1.size() - 6) + (off2 - off1)) else: self.nowShowingPanel1.selectItem( (self.nowShowingPanel1.size() - 1)) self.setFocusId(self.NOW_SHOWING_PANEL1_ID) self.slideNSDown() else: self.nowShowing.pos = 0 searchResults, nowDisp, nextDisp = self.nowShowing.nowShowing() util.setGlobalProperty('ns.panel1.heading', 'NOW SHOWING') self.nsPanel2 = False util.setGlobalProperty('ns.panel2.heading', nextDisp) util.setGlobalProperty('ns.panel1.footer', nextDisp) self.fillNSPanel1(searchResults) self.slideNSUp(1) self.setFocusId(self.NOW_SHOWING_PANEL1_ID) util.setGlobalProperty('NO_RESULTS', not searchResults and T(32802) or '') def updateNowShowing(self): if not self.category == 'nowshowing': return util.DEBUG_LOG('UPDATING NOW SHOWING') selectedSeries = None try: panel = self.currentNowShowingPanel() if panel.size(): selectedSeries = panel.getSelectedItem().dataSource except: util.ERROR() self.fillNowShowing(current=True) panel = self.currentNowShowingPanel() for item in panel: if item.dataSource.ID == selectedSeries.ID: panel.selectItem(item.pos()) return def currentNowShowingPanel(self): if self.nsPanel2: return self.nowShowingPanel2 else: return self.nowShowingPanel1 def slideNSUp(self, duration=400): self.getControl(self.nsPanel2 and 262 or 261).setAnimations([ ('conditional', 'effect=slide start=0,985 end=0,0 time={0} condition=true'.format( duration)) ]) self.getControl(self.nsPanel2 and 261 or 262).setAnimations([ ('conditional', 'effect=fade start=100 end=0 time={0} condition=true'.format( duration)), ('conditional', 'effect=slide start=0,0 end=0,-985 time={0} condition=true'. format(duration)) ]) def slideNSDown(self, duration=400): self.getControl(self.nsPanel2 and 262 or 261).setAnimations([ ('conditional', 'effect=slide start=0,-985 end=0,0 time={0} condition=true'. format(duration)) ]) self.getControl(self.nsPanel2 and 261 or 262).setAnimations([ ('conditional', 'effect=fade start=100 end=0 time={0} condition=true'.format( duration)), ('conditional', 'effect=slide start=0,0 end=0,985 time={0} condition=true'.format( duration)) ]) def fillNSPanel1(self, searchResults, now=False): now = self.nowShowing.pos == 0 and '1' or '' self.fillNSPanel(self.nowShowingPanel1, searchResults, now) def fillNSPanel2(self, searchResults): self.fillNSPanel(self.nowShowingPanel2, searchResults) def fillNSPanel(self, panel, searchResults, on_now=''): items = [] for r in searchResults: if r.hidden: continue item = kodigui.ManagedListItem(r.title, r.synopsis, thumbnailImage=r.icon, data_source=r) item.setProperty('series.title', r.title) item.setProperty('channel.number', r.channelNumber) item.setProperty('channel.name', r.channelName) item.setProperty('channel.icon', r.channelIcon) item.setProperty('has.rule', r.hasRule and '1' or '') item.setProperty('hidden', r.hidden and '1' or '') item.setProperty('on.now', on_now) items.append(item) panel.reset() panel.addItems(items) @util.busyDialog('LOADING RULES') def fillRules(self, update=False): self.lastRulesRefresh = time.time() if update: self.storageServer.updateRules() items = [] for r in self.storageServer.rules: item = kodigui.ManagedListItem(r.title, data_source=r) if r.dateTimeOnly: item.setProperty( 'rule.recent_only', '{0} at {1}'.format(r.displayDateDTO(), r.displayTimeDTO())) elif r.teamOnly: item.setProperty('rule.recent_only', '{0}: {1}'.format('TEAM', r.teamOnly)) else: item.setProperty('rule.recent_only', r.recentOnly and T(32805) or T(32806)) item.setProperty('seriesID', r.seriesID) #print '{0} {1}'.format(r.ruleID, r.title) items.append(item) if not items: util.setGlobalProperty( 'NO_RULES', self.storageServer.getRulesFailed and u'[COLOR 80FF0000]{0}[/COLOR]'.format(T(32830)) or T(32804)) else: util.setGlobalProperty('NO_RULES', '') self.ruleList.reset() self.ruleList.addItems(items) def doRuleContext(self): options = [T(32807), T(32809)] idx = xbmcgui.Dialog().select(T(32810), options) if idx < 0: return try: if idx == 0: self.toggleRuleRecent() elif idx == 1: self.deleteRule() except hdhr.errors.RuleModException, e: util.showNotification(e.message, header=T(32827)) except hdhr.errors.RuleDelException, e: util.showNotification(e.message, header=T(32828))
ans = anp.reshape(ans, a.shape[:-1] + (-1,)) def solve_triangular_grad(g): v = solve_triangular(a, g, trans=_flip(a, trans), lower=lower) return -transpose(tri(anp.matmul(anp.reshape(v, ans.shape), T(ans)))) return solve_triangular_grad solve_triangular.defgrad(make_grad_solve_triangular) solve_triangular.defgrad(lambda ans, a, b, trans=0, lower=False, **kwargs: lambda g: solve_triangular(a, g, trans=_flip(a, trans), lower=lower), argnum=1) ### cholesky solve_trans = lambda L, X: solve_triangular(L, X, lower=True, trans='T') solve_conj = lambda L, X: solve_trans(L, T(solve_trans(L, T(X)))) phi = lambda X: anp.tril(X) / (1. + anp.eye(X.shape[-1])) cholesky = primitive(np.linalg.cholesky) cholesky.defgrad(lambda L, A: lambda g: symm(solve_conj(L, phi(anp.matmul(T(L), g))))) ### operations on cholesky factors solve_tri = partial(solve_triangular, lower=True) solve_posdef_from_cholesky = lambda L, x: solve_tri(L, solve_tri(L, x), trans='T') @primitive def inv_posdef_from_cholesky(L, lower=True): flat_L = np.reshape(L, (-1,) + L.shape[-2:]) return np.reshape(cyla.inv_posdef_from_cholesky(C(flat_L), lower), L.shape)
class Trivia(Item): _type = 'trivia' _elements = ({ 'attr': 'format', 'type': None, 'limits': [None, 'slide', 'video'], 'name': T(32030, 'Format'), 'default': None }, { 'attr': 'duration', 'type': int, 'limits': (0, 60, 1), 'name': T(32031, 'Duration (minutes)'), 'default': 0 }, { 'attr': 'qDuration', 'type': int, 'limits': (0, 60, 1), 'name': T(32032, 'Question Duration (seconds)'), 'default': 0 }, { 'attr': 'cDuration', 'type': int, 'limits': (0, 60, 1), 'name': T(32033, 'Clue Duration (seconds)'), 'default': 0 }, { 'attr': 'aDuration', 'type': int, 'limits': (0, 60, 1), 'name': T(32034, 'Answer Duration (seconds)'), 'default': 0 }, { 'attr': 'sDuration', 'type': int, 'limits': (0, 60, 1), 'name': T(32035, 'Single Duration (seconds)'), 'default': 0 }, { 'attr': 'transition', 'type': None, 'limits': [None, 'none', 'fade', 'slideL', 'slideR', 'slideU', 'slideD'], 'name': T(32036, 'Transition'), 'default': None }, { 'attr': 'transitionDuration', 'type': int, 'limits': (0, 2000, 100), 'name': T(32043, 'Transition: Duration (milliseconds)'), 'default': 0 }, { 'attr': 'music', 'type': None, 'limits': [None, 'off', 'content', 'dir', 'file'], 'name': T(32027, 'Music'), 'default': None }, { 'attr': 'musicDir', 'type': None, 'limits': LIMIT_DIR, 'name': T(32044, 'Music: Path'), 'default': None }, { 'attr': 'musicFile', 'type': None, 'limits': LIMIT_FILE_DEFAULT, 'name': T(32045, 'Music: File'), 'default': None }) displayName = T(32026, 'Trivia Slides') typeChar = 'Q' def __init__(self): Item.__init__(self) self.format = None self.duration = 0 self.qDuration = 0 self.cDuration = 0 self.aDuration = 0 self.sDuration = 0 self.transition = None self.transitionDuration = 0 self.music = None self.musicDir = None self.musicFile = None def display(self): name = self.name or self.displayName if self.duration > 0: return u'{0} ({1}m)'.format(name, self.duration) return name def getLive(self, attr): if not attr == 'musicDir' or self.music is not None: return Item.getLive(self, attr) return util.getSettingDefault('{0}.{1}'.format(self._type, attr)) def elementVisible(self, e): attr = e['attr'] if attr != 'format' and self.getLive('format') == 'video': return False if attr == 'musicDir': if self.getLive('music') != 'dir': return False elif attr == 'musicFile': if self.getLive('music') != 'file': return False elif attr == 'transitionDuration': transition = self.getLive('transition') if not transition or transition == 'none': return False return True
def doDelete(self): item = self.recordingList.getSelectedItem() if not item: return yes = xbmcgui.Dialog().yesno(T(32035),T(32036)) if yes: self.storageServer.deleteRecording(item.dataSource)
class Trailer(Item): _type = 'trailer' _elements = ({ 'attr': 'source', 'type': None, 'limits': [None, 'content', 'dir', 'file'], 'name': T(32052, 'Source'), 'default': None }, { 'attr': 'scrapers', 'type': None, 'limits': LIMIT_MULTI_SELECT, 'name': u'- {0}'.format(T(32323, 'Scrapers filter (scrapers)')), 'default': None }, { 'attr': 'order', 'type': None, 'limits': [None, 'newest', 'random'], 'name': u'- {0}'.format(T(32324, 'Content order')), 'default': None }, { 'attr': 'file', 'type': None, 'limits': LIMIT_FILE_DEFAULT, 'name': u'- {0}'.format(T(32325, 'Path')), 'default': '' }, { 'attr': 'dir', 'type': None, 'limits': LIMIT_DIR, 'name': u'- {0}'.format(T(32325, 'Path')), 'default': '' }, { 'attr': 'count', 'type': int, 'limits': (0, 10, 1), 'name': T(32060, 'Count'), 'default': 0 }, { 'attr': 'ratingLimit', 'type': None, 'limits': [None, 'none', 'max', 'match'], 'name': T(32061, 'Rating Limit'), 'default': None }, { 'attr': 'ratingMax', 'type': None, 'limits': LIMIT_DB_CHOICE, 'name': u'- {0}'.format(T(32062, 'Max')), 'default': None }, { 'attr': 'limitGenre', 'type': strToBoolWithDefault, 'limits': LIMIT_BOOL_DEFAULT, 'name': T(32065, 'Match feature genres'), 'default': None }, { 'attr': 'filter3D', 'type': strToBoolWithDefault, 'limits': LIMIT_BOOL_DEFAULT, 'name': T(32066, 'Filter for 3D based on feature'), 'default': None }, { 'attr': 'quality', 'type': None, 'limits': [None, '480p', '720p', '1080p'], 'name': T(32067, 'Quality'), 'default': None }, { 'attr': 'volume', 'type': int, 'limits': (0, 100, 1), 'name': T(32025, 'Volume (% of current)'), 'default': 0 }) displayName = T(32049, 'Trailers') typeChar = 'T' _scrapers = [['Content', T(32326, 'Trailers Folder'), 'content'], ['KodiDB', T(32318, 'Kodi Database'), 'kodidb'], ['iTunes', 'Apple iTunes', 'itunes'], ['StereoscopyNews', 'StereoscopyNews.com', 'stereoscopynews']] _settingsDisplay = { 'Content': T(32326, 'Trailers Folder'), 'KodiDB': T(32318, 'Kodi Database'), 'iTunes': 'Apple iTunes', 'StereoscopyNews': 'StereoscopyNews.com', } def __init__(self): Item.__init__(self) self.count = 0 self.scrapers = None self.source = None self.order = None self.file = None self.dir = None self.ratingLimit = None self.ratingMax = None self.limitGenre = None self.filter3D = None self.quality = None self.volume = 0 def display(self): name = self.name or self.displayName if self.count > 1: return u'{0} x {1}'.format(name, self.count) return name def liveScrapers(self): return (self.getLive('scrapers') or '').split(',') def elementVisible(self, e): attr = e['attr'] if attr == 'file': if self.getLive('source') != 'file': return False elif attr == 'dir': if self.getLive('source') != 'dir': return False elif attr == 'count': if self.getLive('source') not in ('dir', 'content'): return False elif attr == 'filter3D': if self.getLive('source') not in ('content', 'dir'): return False elif attr in ('scrapers', 'order', 'limitRating', 'limitGenre'): if self.getLive('source') != 'content': return False elif attr == 'quality': if self.getLive( 'source' ) != 'content' or 'iTunes' not in self.liveScrapers(): return False elif attr == 'ratingMax': if self.getLive('ratingLimit') != 'max': return False return True @staticmethod def DBChoices(attr): default = util.getSettingDefault('rating.system.default') import ratings system = ratings.getRatingsSystem(default) if not system: return None return [(u'{0}.{1}'.format(r.system, r.name), str(r)) for r in system.ratings] def Select(self, attr): selected = [s.strip().lower() for s in self.liveScrapers()] contentScrapers = util.contentScrapers() temp = [list(x) for x in self._scrapers] ret = [] for s in temp: for ctype, c in contentScrapers: if ctype == 'trailers' and c == s[0]: s[2] = s[2] in selected ret.append(s) ret.sort(key=lambda i: i[0].lower() in selected and selected.index(i[ 0].lower()) + 1 or 99) return ret def getLive(self, attr): if attr != 'scrapers': return Item.getLive(self, attr) val = Item.getLive(self, attr) if not val: return val inSettings = (val).split(',') contentScrapers = [ s for t, s in util.contentScrapers() if t == 'trailers' ] return ','.join([s for s in inSettings if s in contentScrapers]) def getSettingDisplay(self, setting): if setting == 'scrapers': val = getattr(self, setting) or '' return u','.join( [self._settingsDisplay.get(v, v) for v in val.split(',')]) return Item.getSettingDisplay(self, setting)
def fillNowShowing(self, next_section=False, prev_section=False, fix_selection=True, current=False): if not self.nowShowing: self.nowShowing = hdhr.guide.NowShowing(self.devices) if current: if self.nowShowing.pos > 0: self.nsPanel2 = bool(self.nowShowing.pos % 2) prev_section = True if next_section: self.nowShowing.pos += 1 try: searchResults, nextDisp, footerDisp = self.nowShowing.upNext() except hdhr.guide.EndOfNowShowingException: self.nowShowing.pos -= 1 if self.nsPanel2: self.setFocusId(self.NOW_SHOWING_PANEL1_ID) util.setGlobalProperty('ns.panel1.footer', 'END') else: self.setFocusId(self.NOW_SHOWING_PANEL2_ID) util.setGlobalProperty('ns.panel2.footer', 'END') self.nsPanel2 = not self.nsPanel2 return if self.nsPanel2: util.setGlobalProperty('ns.panel2.heading', nextDisp) util.setGlobalProperty('ns.panel2.footer', footerDisp) self.fillNSPanel2(searchResults) if fix_selection: off1 = self.nowShowingPanel1.getSelectedPosition() % 5 if self.nowShowingPanel2.positionIsValid(off1): self.nowShowingPanel2.selectItem(off1) self.setFocusId(self.NOW_SHOWING_PANEL2_ID) self.slideNSUp() else: util.setGlobalProperty('ns.panel1.heading', nextDisp) util.setGlobalProperty('ns.panel1.footer', footerDisp) self.fillNSPanel1(searchResults) if fix_selection: off2 = self.nowShowingPanel2.getSelectedPosition() % 5 if self.nowShowingPanel1.positionIsValid(off2): self.nowShowingPanel1.selectItem(off2) self.setFocusId(self.NOW_SHOWING_PANEL1_ID) self.slideNSUp() elif prev_section: searchResults, prevDisp, footerDisp = self.nowShowing.upNext() if self.nsPanel2: util.setGlobalProperty('ns.panel2.heading', prevDisp) util.setGlobalProperty('ns.panel2.footer', footerDisp) self.fillNSPanel2(searchResults) if fix_selection: off1 = (self.nowShowingPanel1.getSelectedPosition() + 1) % 5 off2 = self.nowShowingPanel2.size() % 5 if off1 < off2: self.nowShowingPanel2.selectItem((self.nowShowingPanel2.size() - 1) - (off2 - off1)) elif off2 < off1: self.nowShowingPanel2.selectItem((self.nowShowingPanel2.size() - 6) + (off1 - off2)) else: self.nowShowingPanel2.selectItem((self.nowShowingPanel2.size() - 1)) self.setFocusId(self.NOW_SHOWING_PANEL2_ID) self.slideNSDown() else: util.setGlobalProperty('ns.panel1.heading', prevDisp) util.setGlobalProperty('ns.panel1.footer', footerDisp) self.fillNSPanel1(searchResults) if fix_selection: off1 = self.nowShowingPanel1.size() % 5 off2 = (self.nowShowingPanel2.getSelectedPosition() + 1) % 5 if off2 < off1: self.nowShowingPanel1.selectItem((self.nowShowingPanel1.size() - 1) - (off1 - off2)) elif off1 < off2: self.nowShowingPanel1.selectItem((self.nowShowingPanel1.size() - 6) + (off2 - off1)) else: self.nowShowingPanel1.selectItem((self.nowShowingPanel1.size() - 1)) self.setFocusId(self.NOW_SHOWING_PANEL1_ID) self.slideNSDown() else: self.nowShowing.pos = 0 searchResults, nowDisp, nextDisp = self.nowShowing.nowShowing() util.setGlobalProperty('ns.panel1.heading', 'NOW SHOWING') self.nsPanel2 = False util.setGlobalProperty('ns.panel2.heading', nextDisp) util.setGlobalProperty('ns.panel1.footer', nextDisp) self.fillNSPanel1(searchResults) self.slideNSUp(1) self.setFocusId(self.NOW_SHOWING_PANEL1_ID) util.setGlobalProperty('NO_RESULTS',not searchResults and T(32802) or '')