def info_showdata(self, arg=None, menuw=None): """ show info for this item """ actions = self.item.actions() plugins = plugin.get('item') + plugin.get('item_video') plugins.sort(lambda l, o: cmp(l._level, o._level)) for p in plugins: if p != self: for a in p.actions(self.item): if isinstance(a, menu.MenuItem): actions.append(a) else: actions.append(a[:2]) items = [] for a in actions: if not isinstance(a, item.Item): a = menu.MenuItem(a[1], a[0]) a.subtitle = self.item.name a.title = self.item.name items.append(a) m = menu.Menu(_('Details'), items) m.infoitem = self.item m.viewitem = self.item m.item_types = 'video details' m.is_submenu = True menuw.pushmenu(m)
def plugin_eventhandler(self, event, menuw=None): """ eventhandler for special pligins for this item """ if not hasattr(self, '__plugin_eventhandler__'): self.__plugin_eventhandler__ = [] for p in plugin.get('item') + plugin.get('item_%s' % self.type): if hasattr(p, 'eventhandler'): self.__plugin_eventhandler__.append(p.eventhandler) for e in self.__plugin_eventhandler__: if e(self, event, menuw): return True return False
def plugin_eventhandler(self, event, menuw=None): """ eventhandler for special plug-ins for this item """ logger.log( 9, 'plugin_eventhandler(event=%s, menuw=%r)', event, menuw) if not hasattr(self, '__plugin_eventhandler__'): self.__plugin_eventhandler__ = [] for p in plugin.get('item') + plugin.get('item_%s' % self.type): if hasattr(p, 'eventhandler'): self.__plugin_eventhandler__.append(p.eventhandler) for e in self.__plugin_eventhandler__: if e(self, event, menuw): return True return False
def __init__(self, app, mplayer): self.RE_TIME = re.compile("^A: *([0-9]+)").match self.RE_START = re.compile("^Starting playback\.\.\.").match self.RE_EXIT = re.compile("^Exiting\.\.\. \((.*)\)$").match self.item = mplayer.item self.mplayer = mplayer self.exit_type = None # DVD items also store mplayer_audio_broken to check if you can # start them with -alang or not if hasattr(self.item, 'mplayer_audio_broken') or self.item.mode != 'dvd': self.check_audio = 0 else: self.check_audio = 1 import osd self.osd = osd.get_singleton() self.osdfont = self.osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE) # check for mplayer plugins self.stdout_plugins = [] self.elapsed_plugins = [] for p in plugin.get('mplayer_video'): if hasattr(p, 'stdout'): self.stdout_plugins.append(p) if hasattr(p, 'elapsed'): self.elapsed_plugins.append(p) # init the child (== start the threads) childapp.ChildApp2.__init__(self, app)
def eventhandler(self, event, menuw=None): if event == DIRECTORY_CHANGE_DISPLAY_TYPE and menuw.menustack[ -1] == self.menu: possible_display_types = [] for p in plugin.get('mimetype'): for t in p.display_type: if not t in possible_display_types: possible_display_types.append(t) try: pos = possible_display_types.index(self.display_type) type = possible_display_types[(pos + 1) % len(possible_display_types)] menuw.delete_menu(allow_reload=False) newdir = DirItem(self.dir, self.parent, self.name, type, self.add_args) newdir.DIRECTORY_AUTOPLAY_SINGLE_ITEM = False newdir.cwd(menuw=menuw) menuw.menustack[-2].selected = newdir pos = menuw.menustack[-2].choices.index(self) menuw.menustack[-2].choices[pos] = newdir rc.post_event(Event(OSD_MESSAGE, arg='%s view' % type)) return True except (IndexError, ValueError): pass return Playlist.eventhandler(self, event, menuw)
def __init__(self, command, mplayer): self.RE_TIME = re.compile("^[AV]: *([0-9]+)").match self.RE_VO = re.compile("^VO: \[.+\] \d+x\d+ => (\d+)x(\d+)").match self.RE_START = re.compile("^Starting playback\.\.\.").match self.RE_EXIT = re.compile("^Exiting\.\.\. \((.*)\)$").match self.item = mplayer.item self.mplayer = mplayer self.exit_type = None # DVD items also store mplayer_audio_broken to check if you can # start them with -alang or not if hasattr(self.item, 'mplayer_audio_broken') or self.item.mode != 'dvd': self.check_audio = 0 else: self.check_audio = 1 import osd self.osd = osd.get_singleton() self.osdfont = self.osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE) # check for mplayer plugins self.stdout_plugins = [] self.elapsed_plugins = [] for p in plugin.get('mplayer_video'): if hasattr(p, 'stdout'): self.stdout_plugins.append(p) if hasattr(p, 'elapsed'): self.elapsed_plugins.append(p) self.output_event = threading.Event() self.get_property_ans = None # init the child (== start the threads) childapp.ChildApp2.__init__(self, command, callback_use_rc=False)
def start(job): job['tmp_dir'] = tempfile.mkdtemp(suffix='.mkvripper', dir=job['dest_writepath']) ripsize_min = plugin.get('ripsize_min', '600') cmd = plugin.get('makemkvcon_path', 'makemkvcon') cmd = [cmd, '-r', '--progress=-stdout', '--minlength=%s' % ripsize_min, 'mkv', 'dev:%s' % job['dev'], 'all', job['tmp_dir']] job['cmd'] = cmd job['output'] = subprocess.Popen(job['cmd'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) job['pid'] = job['output'].pid plugin.log(plugin.lang(50021) % job['cmd']) #started new makemkvcon with command %s return job
def __init__(self, command, mplayer): self.RE_TIME = re.compile("^[AV]: *([0-9]+)").match self.RE_VO = re.compile("^VO: \[.+\] \d+x\d+ => (\d+)x(\d+)").match self.RE_START = re.compile("^Starting playback\.\.\.").match self.RE_EXIT = re.compile("^Exiting\.\.\. \((.*)\)$").match self.item = mplayer.item self.mplayer = mplayer self.exit_type = None # DVD items also store mplayer_audio_broken to check if you can # start them with -alang or not if hasattr(self.item, 'mplayer_audio_broken') or self.item.mode != 'dvd': self.check_audio = 0 else: self.check_audio = 1 import osd self.osd = osd.get_singleton() self.osdfont = self.osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE) # check for mplayer plugins self.stdout_plugins = [] self.elapsed_plugins = [] for p in plugin.get('mplayer_video'): if hasattr(p, 'stdout'): self.stdout_plugins.append(p) if hasattr(p, 'elapsed'): self.elapsed_plugins.append(p) self.output_event = threading.Event() self.get_property_ans = None if config.MPLAYER_RATE_SET_FROM_VIDEO: # we set a monitor's refresh rate that matches the FPS of the movie screen = xrandr.get_current_screen() # first we save the current rate self.rate = screen.get_current_rate() logger.info('Current refresh rate: %s', self.rate) fps = self.item.getattr('fps') if fps: # get the rate mapping rate = config.MPLAYER_RATE_MAP[fps] if rate: screen.set_refresh_rate(rate[1]) screen.apply_config() else: logger.warning('Unable to set refresh rate to %s', fps) else: logger.warning('Unknown refresh rate: %s', fps) # init the child (== start the threads) childapp.ChildApp2.__init__(self, command, callback_use_rc=False)
def _handle_submenu(self, menu, event): action = None arg = None #try: # action = menu.selected.action #except AttributeError: # pass actions = menu.selected.actions() force = False if not actions: actions = [] force = True if not hasattr(menu, 'is_submenu'): plugins = plugin.get('item') + plugin.get( 'item_%s' % menu.selected.type) if hasattr(menu.selected, 'display_type'): plugins += plugin.get('item_%s' % menu.selected.display_type) plugins.sort(lambda l, o: cmp(l._level, o._level)) for p in plugins: for a in p.actions(menu.selected): if isinstance(a, MenuItem): actions.append(a) else: actions.append(a[:2]) if len(a) == 3 and a[2] == 'MENU_SUBMENU': a[0](menuw=self) return if actions: if len(actions) > 1 or force: self.make_submenu(menu.selected.name, actions, menu.selected) elif len(actions) == 1: # if there is only one action, call it! action = actions[0] if isinstance(action, MenuItem): action = action.function arg = action.arg else: action = action[0] action(arg=arg, menuw=self)
def installed (): path = plugin.get('makemkvcon_path', 'makemkvcon') plugin.log('makemkvcon_path = %s' % path) try: p = Popen(path, stdout=PIPE, stderr=PIPE) p = None return True except Exception, e: plugin.log('error = %s' % e)
def installed(): path = plugin.get('makemkvcon_path', 'makemkvcon') plugin.log('makemkvcon_path = %s' % path) try: p = subprocess.Popen(path, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = None return True except Exception, e: plugin.log(plugin.lang(50017) % e.strerror) #makemkvcon.installed() ERROR: %s
def update_content(self): """ there is no content in this area """ if self.plugins == None: self.plugins = plugin.get('daemon_draw') for p in self.plugins: p.draw((self.widget_type, self.menuw), self)
def installed(): path = plugin.get('makemkvcon_path', 'makemkvcon') plugin.log('makemkvcon_path = %s' % path) try: p = Popen(path, stdout=PIPE, stderr=PIPE) p = None return True except Exception, e: plugin.log('error = %s' % e)
def _handle_submenu(self, menu, event): action = None arg = None #try: # action = menu.selected.action #except AttributeError: # pass actions = menu.selected.actions() force = False if not actions: actions = [] force = True if not hasattr(menu, 'is_submenu'): plugins = plugin.get('item') + plugin.get('item_%s' % menu.selected.type) if hasattr(menu.selected, 'display_type'): plugins += plugin.get('item_%s' % menu.selected.display_type) plugins.sort(lambda l, o: cmp(l._level, o._level)) for p in plugins: for a in p.actions(menu.selected): if isinstance(a, MenuItem): actions.append(a) else: actions.append(a[:2]) if len(a) == 3 and a[2] == 'MENU_SUBMENU': a[0](menuw=self) return if actions: if len(actions) > 1 or force: self.make_submenu(menu.selected.name, actions, menu.selected) elif len(actions) == 1: # if there is only one action, call it! action = actions[0] if isinstance(action, MenuItem): action = action.function arg = action.arg else: action = action[0] action(arg=arg, menuw=self)
def _handle_call_item_action(self, menu, event): logger.debug('calling action %s', event.arg) for a in menu.selected.actions(): if not isinstance(a, Item) and len(a) > 2 and a[2] == event.arg: a[0](arg=None, menuw=self) return plugins = plugin.get('item') + plugin.get('item_%s' % menu.selected.type) if hasattr(menu.selected, 'display_type'): plugins += plugin.get('item_%s' % menu.selected.display_type) for p in plugins: for a in p.actions(menu.selected): if not isinstance(a, MenuItem) and len(a) > 2 and a[2] == event.arg: a[0](arg=None, menuw=self) return logger.debug('action %s not found', event.arg)
def start_saver(self): _debug_("start screensaver") self.screensaver_showing = True if self.plugins is None: self.plugins = plugin.get('screensaver') print 'Plugins =', self.plugins skin.clear() # Start Screensaver thread self.stop_screensaver = False thread.start_new_thread(self.__run__, ())
def main_menu(self, arg, menuw): items = [] if config.TV_CHANNELS: items.append(menu.MenuItem(_('TV Guide'), action=self.start_tvguide)) plugins_list = plugin.get('mainmenu_tv') for p in plugins_list: items += p.items(self) menuw.pushmenu(menu.Menu(_('TV Main Menu'), items, item_types='tv main menu'))
def start_saver(self): _debug_('start_saver()', 2) self.screensaver_showing = True if self.plugins is None: self.plugins = plugin.get('screensaver') _debug_('plugins=%r' % (self.plugins)) skin.clear() # Start Screensaver thread self.stop_screensaver = False self.thread = threading.Thread(target=self.__run__) self.thread.start()
def update_content(self): """ there is no content in this area """ if not osd.active: return if self.plugins == None: self.plugins = plugin.get("daemon_draw") for p in self.plugins: p.draw((self.widget_type, self.menuw), self)
def main_menu(self, arg, menuw): items = [] if config.TV_CHANNELS: items.append( menu.MenuItem(_('TV Guide'), action=self.start_tvguide)) plugins_list = plugin.get('mainmenu_tv') for p in plugins_list: items += p.items(self) menuw.pushmenu( menu.Menu(_('TV Main Menu'), items, item_types='tv main menu'))
def __init__(self): """ get the list of plugins wanting events """ self.eventhandler_plugins = [] self.eventlistener_plugins = [] for p in plugin.get('daemon_eventhandler'): if hasattr(p, 'event_listener') and p.event_listener: self.eventlistener_plugins.append(p) else: self.eventhandler_plugins.append(p)
def __init__(self): """ get the list of plugins wanting events """ self.eventhandler_plugins = [] self.eventlistener_plugins = [] for p in plugin.get('daemon_eventhandler'): if hasattr(p, 'event_listener') and p.event_listener: self.eventlistener_plugins.append(p) else: self.eventhandler_plugins.append(p) kaa.EventHandler(self.eventhandler).register()
def calculatesizes(self, osd, font): """ sizecalcs is not necessery on every pass """ logger.log(8, 'calculatesizes(osd=%r, font=%r)', osd, font) if not hasattr(self, 'idlebar'): self.idlebar = plugin.getbyname('idlebar') if self.idlebar: self.idlebar_max = osd.width + osd.x for p in plugin.get('idlebar'): if hasattr(p, 'clock_left_position'): self.idlebar_max = p.clock_left_position if self.idlebar_max - self.idlebar.free_space < 250: logger.info( 'free space in idlebar to small, using normal detach') self.idlebar = None pad_internal = 5 # internal padding for box vs text if self.calculate: self.calculate = False self.font_h = font.font.height total_width = osd.width + 2 * osd.x total_height = osd.height + 2 * osd.y pad = 10 # padding for safety (overscan may not be 100% correct) bar_height = self.font_h bar_width = 0 for r in self.render: bar_height += self.font_h bar_width = max(bar_width, font.font.stringsize(r)) y = total_height - bar_height - config.OSD_OVERSCAN_BOTTOM - skin.attr_global_dict[ 'buttonbar_height'] x = total_width - bar_width - config.OSD_OVERSCAN_RIGHT self.y = y - osd.y - pad - pad_internal self.x = x - osd.x - pad - pad_internal self.w = bar_width + pad + pad_internal + 10 self.h = 70 self.t_y = self.y + pad_internal self.t_x = self.x + pad_internal self.t_w = bar_width + 5 # in case of shadow if self.idlebar: self.y = osd.y + 5 self.x = self.image and self.idlebar.free_space + 70 or self.idlebar.free_space self.t_y = self.y self.t_x = self.x self.t_w = min(self.t_w, self.idlebar_max - self.x - 30)
def running(dev=None): import glob path = plugin.get('makemkvcon_path', 'makemkvcon') for f in glob.glob('/proc/*/cmdline'): try: cl = open(f).read() if cl.startswith(path): if dev is None: return f.split('/')[2] #pid of running makemkvcon else: if dev in cl: return f.split('/')[2] #pid of running makemkvcon corresponding to dev except Exception, e: raise
def calculatesizes(self, osd, font): """ sizecalcs is not necessery on every pass """ _debug_('calculatesizes(self, osd, font)', 3) if not hasattr(self, 'idlebar'): self.idlebar = plugin.getbyname('idlebar') if self.idlebar: self.idlebar_max = osd.width + osd.x for p in plugin.get('idlebar'): if hasattr(p, 'clock_left_position'): self.idlebar_max = p.clock_left_position if self.idlebar_max - self.idlebar.free_space < 250: _debug_('free space in idlebar to small, using normal detach') self.idlebar = None pad_internal = 5 # internal padding for box vs text if self.calculate: self.calculate = False self.font_h = font.font.height total_width = osd.width + 2*osd.x total_height = osd.height + 2*osd.y pad = 10 # padding for safety (overscan may not be 100% correct) bar_height = self.font_h bar_width = 0 for r in self.render: bar_height += self.font_h bar_width = max(bar_width, font.font.stringsize(r)) self.y = (total_height - bar_height) - osd.y - pad - pad_internal self.x = (total_width - bar_width) - osd.x - pad - pad_internal self.w = bar_width + pad + pad_internal + 10 self.t_y = self.y + pad_internal self.t_x = self.x + pad_internal self.t_w = bar_width + 5 # incase of shadow if self.idlebar: self.y = osd.y + 5 self.t_y = self.y if self.image: self.x = self.idlebar.free_space + 70 else: self.x = self.idlebar.free_space self.t_x = self.x self.t_w = min(self.t_w, self.idlebar_max - self.x - 30)
def get_handlers(self): """ Get all regitered subtitle plugins into the local dictionary @return: Hanlders dictionary keyed by the handler ID. """ if self.handlers is None or len(self.handlers) < 1: handlers = plugin.get('subtitles') logger.info('Available subtitles handlers : %s', handlers) for handler in handlers: self.handlers[handler['id']] = handler logger.info('Successfuly loaded subtitle handler %s', handler.name) return self.handlers
def calculatesizes(self, osd, font): """ sizecalcs is not necessery on every pass """ logger.log( 8, 'calculatesizes(osd=%r, font=%r)', osd, font) if not hasattr(self, 'idlebar'): self.idlebar = plugin.getbyname('idlebar') if self.idlebar: self.idlebar_max = osd.width + osd.x for p in plugin.get('idlebar'): if hasattr(p, 'clock_left_position'): self.idlebar_max = p.clock_left_position if self.idlebar_max - self.idlebar.free_space < 250: logger.info('free space in idlebar to small, using normal detach') self.idlebar = None pad_internal = 5 # internal padding for box vs text if self.calculate: self.calculate = False self.font_h = font.font.height total_width = osd.width + 2*osd.x total_height = osd.height + 2*osd.y pad = 10 # padding for safety (overscan may not be 100% correct) bar_height = self.font_h bar_width = 0 for r in self.render: bar_height += self.font_h bar_width = max(bar_width, font.font.stringsize(r)) y = total_height - bar_height - config.OSD_OVERSCAN_BOTTOM - skin.attr_global_dict['buttonbar_height'] x = total_width - bar_width - config.OSD_OVERSCAN_RIGHT self.y = y - osd.y - pad - pad_internal self.x = x - osd.x - pad - pad_internal self.w = bar_width + pad + pad_internal + 10 self.h = 70 self.t_y = self.y + pad_internal self.t_x = self.x + pad_internal self.t_w = bar_width + 5 # in case of shadow if self.idlebar: self.y = osd.y + 5 self.x = self.image and self.idlebar.free_space + 70 or self.idlebar.free_space self.t_y = self.y self.t_x = self.x self.t_w = min(self.t_w, self.idlebar_max - self.x - 30)
def getcmd(self): """ Setup the main menu and handle events (remote control, etc) """ import plugin menuw = menu.MenuWidget() items = [] for p in plugin.get('mainmenu'): items += p.items(self) for i in items: i.is_mainmenu_item = True mainmenu = menu.Menu(_('Freevo Main Menu'), items, item_types='main', umount_all = 1) menuw.pushmenu(mainmenu) rc.add_app(menuw)
def __init__(self, app, player): self.item = player.item self.player = player self.elapsed = 0 self.stop_reason = 0 # 0 = ok, 1 = error self.RE_TIME = re.compile("^A: *([0-9]+)").match self.RE_TIME_NEW = re.compile("^A: *([0-9]+):([0-9]+)").match # check for mplayer plugins self.stdout_plugins = [] self.elapsed_plugins = [] for p in plugin.get('mplayer_audio'): if hasattr(p, 'stdout'): self.stdout_plugins.append(p) if hasattr(p, 'elapsed'): self.elapsed_plugins.append(p) childapp.ChildApp2.__init__(self, app, stop_osd=0)
def Add(c,playlistid,item): items= plugin.get( **item ) or \ AudioLibrary.Get( **item ) if type(items)!=list: print "not list:",items return "Not found" for i in items: print i i["type"]="song" vlc.command("in_enqueue", input= quote(i["file"],safe='') ) c.items.append( i ) yamc.event.post().Playlist.OnAdd( i, playlistid= playlistid, position= len(c.items) ) c.dirty= True return "OK"
def select(self, arg=None, menuw=None): """ Load the new skin and rebuild the main menu """ import plugin skin.set_base_fxd(self.skin) pos = menuw.menustack[0].choices.index(menuw.menustack[0].selected) parent = menuw.menustack[0].choices[0].parent menuw.menustack[0].choices = [] for p in plugin.get('mainmenu'): menuw.menustack[0].choices += p.items(parent) for i in menuw.menustack[0].choices: i.is_mainmenu_item = True menuw.menustack[0].selected = menuw.menustack[0].choices[pos] menuw.back_one_menu()
def start_saver(self): logger.log( 9, 'start_saver()') if self.screensaver_showing or not skin.active(): return self.screensaver_showing = True if self.plugins is None: self.plugins = plugin.get('screensaver') logger.debug('plugins=%r', self.plugins) osd.screensaver_running = True skin.clear() self.current_saver = None self.index = 0 plugins_count = len(self.plugins) logger.debug('found %s screensaver(s)', plugins_count) if config.SCREENSAVER_SCREEN_OFF_DELAY: logger.debug('Enabling DPMS timer') self.dpms_timer.start(config.SCREENSAVER_SCREEN_OFF_DELAY) self.__next()
def getcmd(self): """ Setup the main menu and handle events (remote control, etc) """ import plugin menuw = menu.MenuWidget() items = [] for p in plugin.get('mainmenu'): items += p.items(self) for i in items: i.is_mainmenu_item = True mainmenu = menu.Menu(_('Freevo Main Menu'), items, item_types='main', umount_all=1) menuw.pushmenu(mainmenu) osd.add_app(menuw)
def main_menu(self, arg, menuw): items = [] if config.TV_CHANNELS: items.append( menu.MenuItem(_('TV Guide'), action=self.start_tvguide)) items.append( DirItem(config.TV_RECORD_DIR, None, name=_('Recorded Shows'), display_type='tv')) # XXX: these are becomming plugins # items.append(menu.MenuItem(_('Search Guide'), action=self.show_search)) plugins_list = plugin.get('mainmenu_tv') for p in plugins_list: items += p.items(self) menuw.pushmenu( menu.Menu(_('TV Main Menu'), items, item_types='tv main menu'))
def main_menu_generate(self): """ generate the items for the main menu. This is needed when first generating the menu and if something changes by pressing the EJECT button """ items = copy.copy(self.normal_items) if config.HIDE_UNUSABLE_DISCS: dir_types = { 'audio': ['dir', 'audiocd', 'audio', 'empty_cdrom'], 'video': ['dir', 'video', 'vcd', 'dvd', 'empty_cdrom'], 'image': ['dir', 'empty_cdrom'], 'games': ['dir', 'empty_cdrom'], } else: dir_types = {} for type in ('audio', 'video', 'image', 'games'): dir_types[type] = [ 'dir', 'audiocd', 'audio', 'video', 'vcd', 'dvd', 'empty_cdrom' ] if self.display_type: plugins_list = plugin.get('mainmenu_%s' % self.display_type) else: plugins_list = [] dir_type = dir_types.get(self.display_type, []) for p in plugins_list: if isinstance(p, plugins.rom_drives.rom_items): # do not show media from other menus for i in p.items(self): if i.type in dir_type: items.append(i) else: items += p.items(self) return items
def actions(self): """ List of actions """ logger.log(9, 'actions()') #list of entries for the menu items = [] #'Play', if this programm is currently running or starts soon if self.context == 'guide': items.append((self.play, _('Play'))) #now = time.time() #if self.prog.start <= now+(7*60) and self.prog.stop > now: # items.append((self.play, _('Play'))) # 'Show full description' items.append((self.show_description, _('Full Description'))) if self.recordclient.pingNow(): # 'Schedule for recording' OR 'Remove from schedule' (status, reason) = self.recordclient.isProgScheduledNow(self.prog) self.scheduled = status if self.scheduled: items.append((self.remove_program, _('Remove from schedule'))) else: items.append( (self.schedule_program, _('Schedule for recording'))) # 'Add to favorites' OR 'Remove from favorites' (status, reason) = self.recordclient.isProgAFavoriteNow(self.prog) self.favorite = status if self.favorite: items.append((self.edit_favorite, _('Edit favorite'))) else: items.append((self.add_favorite, _('Add to favorites'))) plugins_list = plugin.get('tv_program') for p in plugins_list: items += p.items(self) return items
def actions(self): """ List of actions """ logger.log( 9, 'actions()') #list of entries for the menu items = [] #'Play', if this programm is currently running or starts soon if self.context == 'guide': items.append((self.play, _('Play'))) #now = time.time() #if self.prog.start <= now+(7*60) and self.prog.stop > now: # items.append((self.play, _('Play'))) # 'Show full description' items.append((self.show_description, _('Full Description'))) if self.recordclient.pingNow(): # 'Schedule for recording' OR 'Remove from schedule' (status, reason) = self.recordclient.isProgScheduledNow(self.prog) self.scheduled = status if self.scheduled: items.append((self.remove_program, _('Remove from schedule'))) else: items.append((self.schedule_program, _('Schedule for recording'))) # 'Add to favorites' OR 'Remove from favorites' (status, reason) = self.recordclient.isProgAFavoriteNow(self.prog) self.favorite = status if self.favorite: items.append((self.edit_favorite, _('Edit favorite'))) else: items.append((self.add_favorite, _('Add to favorites'))) plugins_list = plugin.get('tv_program') for p in plugins_list: items += p.items(self) return items
def main_menu_generate(self): """ generate the items for the main menu. This is needed when first generating the menu and if something changes by pressing the EJECT button """ items = copy.copy(self.normal_items) if config.HIDE_UNUSABLE_DISCS: dir_types = { 'audio': [ 'dir', 'audiocd', 'audio', 'empty_cdrom' ], 'video': [ 'dir', 'video', 'vcd', 'dvd', 'empty_cdrom' ], 'image': [ 'dir', 'empty_cdrom' ], 'games': [ 'dir', 'empty_cdrom' ], } else: dir_types = {} for type in ('audio', 'video', 'image', 'games'): dir_types[type] = [ 'dir', 'audiocd', 'audio', 'video', 'vcd', 'dvd', 'empty_cdrom' ] if self.display_type: plugins_list = plugin.get('mainmenu_%s' % self.display_type) else: plugins_list = [] dir_type = dir_types.get( self.display_type, [ ] ) for p in plugins_list: if isinstance( p, plugins.rom_drives.rom_items ): # do not show media from other menus for i in p.items( self ): if i.type in dir_type: items.append(i) else: items += p.items( self ) return items
return # Find existing for d in os.listdir('/proc'): p = os.path.join('/proc', d, 'cmdline') if os.path.isfile(p): try: if 'makemkvcon' in open(p).read(): MAKEMKVCONPID = int(d) plugin.log('existing makemkvcon pid %d' % MAKEMKVCONPID) return except Exception, e: plugin.log('ERROR: %s' % e) # Start new cmd = plugin.get('makemkvcon_path', 'makemkvcon') cmd = [cmd, '-r', '--cache=128', 'stream', 'disc:0'] MAKEMKVCON = Popen(cmd, stdout=PIPE, stderr=PIPE) plugin.log('started new makemkvcon') return # # Get remote address # def getHostPort(): host = plugin.get('makemkv_host', 'localhost') port = int(plugin.get('makemkv_port', 51000)) return 'http://%s:%d' % (host, port)
import plugin import webest as w when, lapse = '4pm', '24h' telegram = plugin.get("telegram") def run(): with w.browser.new_auto("http://dilbert.com/") as b: img = w.get_objs(b, "img.img-comic")[0] src = img.get_attribute('src') telegram.send_me_picture(src, tmp_suffix='.gif')
def calculatesizes(self, osd, font): logger.log(9, 'calculatesizes(self, osd, font)') """ sizecalcs is not necessery on every pass """ if config.ENCODING_IDLEBAR: if not hasattr(self, 'idlebar'): self.idlebar = plugin.getbyname('idlebar') if self.idlebar: self.idlebar_max = osd.width + osd.x logger.log(9, 'idlebar_max=%s, free_space=%s', self.idlebar_max, self.idlebar.free_space) for p in plugin.get('idlebar'): if hasattr(p, 'clock_left_position'): self.idlebar_max = p.clock_left_position if self.idlebar_max - self.idlebar.free_space < 250: logger.debug( 'free space in idlebar to small, using normal detach' ) self.idlebar = None else: # this doesn't work, but needs to for the detachbar self.idlebar.take_space(250) else: self.idlebar = None if self.idlebar: self.boxborder = 0 self.padding = 0 if self.calculate: self.calculate = False self.font_h = font.font.height logger.log(9, 'osd.width=%s, osd.height=%s, osd.x=%s, osd.y=%s', osd.width, osd.height, osd.x, osd.y) screen_width = osd.width + 2 * osd.x screen_height = osd.height + 2 * osd.y used_width = font.font.stringsize(self.jobs) - 1 # ensure that the box width is between min and max used_width = max(used_width, 200) used_width = min(used_width, 280) used_height = self.font_h if self.running: w, h = self.getimage(self.boximg, osd).get_size() used_width = max(used_width, w) used_height += h for text in self.text: used_width = max(used_width, font.font.stringsize(text)) - 1 used_height += self.font_h logger.log( 9, 'screen_width=%s, screen_height=%s, used_width=%s, used_height=%s, font_h=%s', screen_width, screen_height, used_width, used_height, self.font_h) self.boxw = used_width + (self.padding + self.boxborder) * 2 self.boxh = used_height + (self.padding + self.boxborder) * 2 self.bx = osd.x self.by = screen_height - osd.y - self.boxh self.textw = used_width self.texth = used_height self.tx = self.bx + self.boxborder + self.padding self.ty = self.by + self.boxborder + self.padding if self.idlebar: if self.image: self.bx = self.idlebar.free_space + 250 + 70 else: self.bx = self.idlebar.free_space + 250 self.by = osd.y self.tx = self.bx + self.boxborder + self.padding self.ty = self.by + self.boxborder + self.padding self.textw = min(self.textw, self.idlebar_max - self.bx - 30)
def eventhandler(self, event): menu = self.menustack[-1] if self.cols == 1 and isinstance(menu, Menu): if config.MENU_ARROW_NAVIGATION: if event == MENU_LEFT: event = MENU_BACK_ONE_MENU elif event == MENU_RIGHT: event = MENU_SELECT else: if event == MENU_LEFT: event = MENU_PAGEUP elif event == MENU_RIGHT: event = MENU_PAGEDOWN if self.eventhandler_plugins == None: self.eventhandler_plugins = plugin.get('daemon_eventhandler') if event == MENU_GOTO_MAINMENU: self.goto_main_menu() return if event == MENU_GOTO_TV: self.goto_media_menu("tv") return if event == MENU_GOTO_TVGUIDE: self.goto_media_menu("tv.guide") return if event == MENU_GOTO_VIDEOS: self.goto_media_menu("video") return if event == MENU_GOTO_MUSIC: self.goto_media_menu("audio") return if event == MENU_GOTO_IMAGES: self.goto_media_menu("image") return if event == MENU_GOTO_GAMES: self.goto_media_menu("games") return if event == MENU_GOTO_RADIO: self.goto_media_menu("audio.radio") return if event == MENU_GOTO_SHUTDOWN: self.goto_media_menu("shutdown") return if event == MENU_BACK_ONE_MENU: self.back_one_menu() return if not isinstance(menu, Menu) and menu.eventhandler(event): return if event == 'MENU_REFRESH': self.refresh() return if event == 'MENU_REBUILD': self.init_page() self.refresh() return if not self.menu_items: if event in (MENU_SELECT, MENU_SUBMENU, MENU_PLAY_ITEM): self.back_one_menu() return menu = self.menustack[-2] if hasattr(menu.selected, 'eventhandler') and menu.selected.eventhandler: if menu.selected.eventhandler(event=event, menuw=self): return for p in self.eventhandler_plugins: if p.eventhandler(event=event, menuw=self): return return if not isinstance(menu, Menu): if self.eventhandler_plugins == None: self.eventhandler_plugins = plugin.get('daemon_eventhandler') for p in self.eventhandler_plugins: if p.eventhandler(event=event, menuw=self): return _debug_('no eventhandler for event %s' % event, 2) return if event == MENU_UP: curr_selected = self.all_items.index(menu.selected) if curr_selected-self.cols < 0 and \ menu.selected != menu.choices[0]: self.goto_prev_page(arg='no_refresh') try: if self.cols == 1: curr_selected = self.rows - 1 elif self.rows != 1: curr_selected = self.all_items.index(menu.selected) else: curr_selected += self.cols except ValueError: curr_selected += self.cols curr_selected = max(curr_selected - self.cols, 0) menu.selected = self.all_items[curr_selected] self.refresh() return elif event == MENU_DOWN: curr_selected = self.all_items.index(menu.selected) if curr_selected+self.cols > len(self.all_items)-1 and \ menu.page_start + len(self.all_items) < len(menu.choices): self.goto_next_page(arg='no_refresh') try: if self.cols == 1: curr_selected = 0 elif self.rows != 1: curr_selected = self.all_items.index(menu.selected) else: curr_selected -= self.cols except ValueError: curr_selected -= self.cols curr_selected = min(curr_selected + self.cols, len(self.all_items) - 1) menu.selected = self.all_items[curr_selected] self.refresh() return elif event == MENU_PAGEUP: # Do nothing for an empty file list if not len(self.menu_items): return curr_selected = self.all_items.index(menu.selected) # Move to the previous page if the current position is at the # top of the list, otherwise move to the top of the list. if curr_selected == 0: self.goto_prev_page() else: curr_selected = 0 menu.selected = self.all_items[curr_selected] self.refresh() return elif event == MENU_PAGEDOWN: # Do nothing for an empty file list if not len(self.menu_items): return if menu.selected == menu.choices[-1]: return curr_selected = self.all_items.index(menu.selected) bottom_index = self.menu_items.index(self.menu_items[-1]) # Move to the next page if the current position is at the # bottom of the list, otherwise move to the bottom of the list. if curr_selected >= bottom_index: self.goto_next_page() else: curr_selected = bottom_index menu.selected = self.all_items[curr_selected] self.refresh() return elif event == MENU_LEFT: # Do nothing for an empty file list if not len(self.menu_items): return curr_selected = self.all_items.index(menu.selected) if curr_selected == 0: self.goto_prev_page(arg='no_refresh') try: curr_selected = self.all_items.index(menu.selected) if self.rows == 1: curr_selected = len(self.all_items) except ValueError: curr_selected += self.cols curr_selected = max(curr_selected - 1, 0) menu.selected = self.all_items[curr_selected] self.refresh() return elif event == MENU_RIGHT: # Do nothing for an empty file list if not len(self.menu_items): return curr_selected = self.all_items.index(menu.selected) if curr_selected == len(self.all_items) - 1: self.goto_next_page(arg='no_refresh') try: curr_selected = self.all_items.index(menu.selected) if self.rows == 1: curr_selected -= 1 except ValueError: curr_selected -= self.cols curr_selected = min(curr_selected + 1, len(self.all_items) - 1) menu.selected = self.all_items[curr_selected] self.refresh() return elif event == MENU_PLAY_ITEM and hasattr(menu.selected, 'play'): menu.selected.play(menuw=self) elif event == MENU_SELECT or event == MENU_PLAY_ITEM: action = None arg = None try: action = menu.selected.action except AttributeError: action = menu.selected.actions() if action: action = action[0] if isinstance(action, MenuItem): action = action.function arg = action.arg else: action = action[0] if not action: print 'No action.. ' AlertBox(text=_('No action defined for this choice!')).show() else: action(arg=arg, menuw=self) return elif event == MENU_SUBMENU: if hasattr(menu, 'is_submenu'): return actions = menu.selected.actions() force = False if not actions: actions = [] force = True plugins = plugin.get('item') + plugin.get( 'item_%s' % menu.selected.type) if hasattr(menu.selected, 'display_type'): plugins += plugin.get('item_%s' % menu.selected.display_type) plugins.sort(lambda l, o: cmp(l._level, o._level)) for p in plugins: for a in p.actions(menu.selected): if isinstance(a, MenuItem): actions.append(a) else: actions.append(a[:2]) if len(a) == 3 and a[2] == 'MENU_SUBMENU': a[0](menuw=self) return if actions and (len(actions) > 1 or force): self.make_submenu(menu.selected.name, actions, menu.selected) return elif event == MENU_CALL_ITEM_ACTION: _debug_('calling action %s' % event.arg) for a in menu.selected.actions(): if not isinstance(a, Item) and len(a) > 2 and a[2] == event.arg: a[0](arg=None, menuw=self) return plugins = plugin.get('item') + plugin.get( 'item_%s' % menu.selected.type) if hasattr(menu.selected, 'display_type'): plugins += plugin.get('item_%s' % menu.selected.display_type) for p in plugins: for a in p.actions(menu.selected): if not isinstance( a, MenuItem) and len(a) > 2 and a[2] == event.arg: a[0](arg=None, menuw=self) return _debug_('action %s not found' % event.arg) elif event == MENU_CHANGE_STYLE and len(self.menustack) > 1: # did the menu change? if skin.toggle_display_style(menu): self.rebuild_page() self.refresh() return elif hasattr(menu.selected, 'eventhandler') and menu.selected.eventhandler: if menu.selected.eventhandler(event=event, menuw=self): return for p in self.eventhandler_plugins: if p.eventhandler(event=event, menuw=self): return _debug_('no eventhandler for event %s' % str(event), 2) return 0
def getHostPort(): host = plugin.get('makemkv_host', 'localhost') port = int(plugin.get('makemkv_port', 51000)) return 'http://%s:%d' % (host, port)
def eventhandler(self, event): menu = self.menustack[-1] if self.cols == 1 and isinstance(menu, Menu): if config.MENU_ARROW_NAVIGATION: if event == MENU_LEFT: event = MENU_BACK_ONE_MENU elif event == MENU_RIGHT: event = MENU_SELECT else: if event == MENU_LEFT: event = MENU_PAGEUP elif event == MENU_RIGHT: event = MENU_PAGEDOWN if self.eventhandler_plugins == None: self.eventhandler_plugins = plugin.get('daemon_eventhandler') if event == MENU_GOTO_MAINMENU: self.goto_main_menu() return True if event == MENU_GOTO_TV: self.goto_media_menu("tv") return True if event == MENU_GOTO_TVGUIDE: self.goto_media_menu("tv.guide") return True if event == MENU_GOTO_VIDEOS: self.goto_media_menu("video") return True if event == MENU_GOTO_MUSIC: self.goto_media_menu("audio") return True if event == MENU_GOTO_IMAGES: self.goto_media_menu("image") return True if event == MENU_GOTO_GAMES: self.goto_media_menu("games") return True if event == MENU_GOTO_RADIO: self.goto_media_menu("audio.radio") return True if event == MENU_GOTO_SHUTDOWN: self.goto_media_menu("shutdown") return True if event == MENU_BACK_ONE_MENU or \ (event == MOUSE_BTN_PRESS and event.button == 3): sounds.play_sound(sounds.MENU_BACK_ONE) self.back_one_menu() return True if not isinstance(menu, Menu) and menu.eventhandler(event): return True if event == 'MENU_RELOAD': self.refresh(True) return True if event == 'MENU_REFRESH': self.refresh() return True if event == 'MENU_REBUILD': self.init_page() self.refresh() return True if not self.menu_items: if event in (MENU_SELECT, MENU_SUBMENU, MENU_PLAY_ITEM): self.back_one_menu() return True menu = self.menustack[-2] if hasattr(menu, 'selected') and hasattr( menu.selected, 'eventhandler') and menu.selected.eventhandler: if menu.selected.eventhandler(event=event, menuw=self): return True for p in self.eventhandler_plugins: if p.eventhandler(event=event, menuw=self): return True return False if not isinstance(menu, Menu): if self.eventhandler_plugins == None: self.eventhandler_plugins = plugin.get('daemon_eventhandler') for p in self.eventhandler_plugins: if p.eventhandler(event=event, menuw=self): return True logger.log(9, 'no eventhandler for event %s', event) return False if event == MENU_UP: self._handle_up(menu, event) return True if event == MENU_DOWN: self._handle_down(menu, event) return True if event == MENU_PAGEUP: self._handle_pageup(menu, event) return True if event == MENU_PAGEDOWN: self._handle_pagedown(menu, event) return True if event == MENU_LEFT: self._handle_left(menu, event) return True if event == MENU_RIGHT: self._handle_right(menu, event) return True if event == MENU_PLAY_ITEM and hasattr(menu.selected, 'play'): menu.selected.play(menuw=self) return True if event == MENU_PLAY_ITEM or event == MENU_SELECT: self._handle_play_item(menu, event) return True if event == MENU_SUBMENU: self._handle_submenu(menu, event) return True if event == MENU_CALL_ITEM_ACTION: self._handle_call_item_action(menu, event) return True if event == MENU_CHANGE_STYLE and len(self.menustack) > 1: # did the menu change? if skin.toggle_display_style(menu): self.rebuild_page() self.refresh() return True if event == MOUSE_MOTION: for menuitem in menu.choices: if menuitem.rect.collidepoint(event.pos): self.highlight_menuitem(menuitem) return True if event == MOUSE_BTN_PRESS: # Left click if event.button == 1: for menuitem in menu.choices: if menuitem.rect.collidepoint(event.pos): self.highlight_menuitem(menuitem) self.select_menuitem(menuitem) # Middle click elif event.button == 2: self.submenu_menuitem() # Wheel up elif event.button == 4: self.up_menuitem() # Wheel down elif event.button == 5: self.down_menuitem() return True if hasattr(menu.selected, 'eventhandler') and menu.selected.eventhandler: if menu.selected.eventhandler(event=event, menuw=self): return True for p in self.eventhandler_plugins: if p.eventhandler(event=event, menuw=self): return True logger.log(9, 'no eventhandler for event %s', str(event)) return False
def get_actions(self, menu): """ Retrieve the Red/Green/Yellow/Blue actions for supplied menu. The actions are returned in an array in the order: [red,green,yellow,blue]. None is returned if no actions are available and the bar should not be drawn. """ result = [None, None, None, None] found_color_actions = False if hasattr(menu, 'selected'): color_object = menu.selected else: color_object = menu for index in range(0, len(self.colors)): if hasattr(color_object, self.colors[index] + '_action'): found_color_actions = True result[index] = eval('color_object.' + self.colors[index] + '_action') if found_color_actions: return result if ((isinstance(menu, Menu) and (menu.item_types == 'main')) or isinstance(menu, MenuItem)): return None if isinstance(menu, TVGuide): dateformat = config.TV_DATE_FORMAT timeformat = config.TV_TIME_FORMAT if not timeformat: timeformat = '%H:%M' if not dateformat: dateformat = '%d-%b' for action in self.tvguide_actions: if action and action.function == self.advance_tv_guide: newtime = menu.start_time + (action.arg * 60 * 60) action.name = Unicode( time.strftime('%s %s' % (dateformat, timeformat), time.localtime(newtime))) return self.tvguide_actions # Make sure this is a menu and not a submenu. if hasattr(menu, 'is_submenu') or (not hasattr(menu, 'selected')): return result # Determine the available actions actions = menu.selected.actions() if not actions: actions = [] plugins = plugin.get('item') + plugin.get( 'item_%s' % menu.selected.type) if hasattr(menu.selected, 'display_type'): plugins += plugin.get('item_%s' % menu.selected.display_type) plugins.sort(lambda l, o: cmp(l._level, o._level)) for p in plugins: for a in p.actions(menu.selected): if isinstance(a, MenuItem): actions.append(a) elif len(a) == 2 or a[2] != 'MENU_SUBMENU': actions.append(a[:2]) if len(actions) > 1: result[0] = actions[1] if len(actions) > 2: result[1] = actions[2] if len(actions) > 3: result[2] = actions[3] if len(actions) > 4: result[3] = actions[4] # Special case for when there are more than 5 possible actions the last button will 'Enter' the submenu if len(actions) > 5: result[3] = MenuItem(_("More Options"), action=self.send_event_to_menu, arg=event.MENU_SUBMENU) return result
def get_actions(self, menu): """ Retrieve the Red/Green/Yellow/Blue actions for supplied menu. The actions are returned in an array in the order: [red,green,yellow,blue]. None is returned if no actions are available and the bar should not be drawn. """ result = [None, None, None, None] found_color_actions = False if hasattr(menu, 'selected'): color_object = menu.selected else: color_object = menu for index in range(0, len(self.colors)): if hasattr(color_object, self.colors[index] + '_action'): found_color_actions = True result[index] = eval('color_object.' + self.colors[index] + '_action') if hasattr(color_object, 'button' + str(index+1) + '_action'): found_color_actions = True result[index] = eval('color_object.button' + str(index+1) + '_action') if found_color_actions: return result if ((isinstance(menu, Menu) and (menu.item_types == 'main')) or isinstance(menu, MenuItem)): return None if isinstance(menu, TVGuide): dateformat = config.TV_DATE_FORMAT timeformat = config.TV_TIME_FORMAT if not timeformat: timeformat = '%H:%M' if not dateformat: dateformat = '%d-%b' for action in self.tvguide_actions: if action and action.function == self.advance_tv_guide: newtime = menu.start_time + (action.arg * 60 *60) action.name = Unicode(time.strftime('%s %s' % (dateformat, timeformat), time.localtime(newtime))) return self.tvguide_actions # Make sure this is a menu and not a submenu. if hasattr(menu, 'is_submenu') or (not hasattr(menu, 'selected')): return result if menu.selected is None: return None # Determine the available actions actions = menu.selected.actions() if not actions: actions = [] plugins = plugin.get('item') + plugin.get('item_%s' % menu.selected.type) if hasattr(menu.selected, 'display_type'): plugins += plugin.get('item_%s' % menu.selected.display_type) plugins.sort(lambda l, o: cmp(l._level, o._level)) for p in plugins: for a in p.actions(menu.selected): if isinstance(a, MenuItem): actions.append(a) elif len(a) == 2 or a[2] != 'MENU_SUBMENU': actions.append(a[:2]) for index in range(1, min(len(actions),5)): result[index-1] = actions[index] # Special case for when there are more than 5 possible actions the last button will 'Enter' the submenu if len(actions) > 5: result[3] = MenuItem(_("More Options"), action=self.show_options, arg=actions) return result
import re import time import plugin import webest as w lapse = '1h' gspreadsheet = plugin.get("gspreadsheet") def get_twitter_count(): with w.browser.new_auto("https://twitter.com/alobbs") as b: raw = w.get_text(b, ".ProfileNav-list") raw = raw.replace('\n', ' ').replace(',', '') fers = re.findall(r'FOLLOWERS (\d+)', raw)[0] fing = re.findall(r'FOLLOWING (\d+)', raw)[0] return (fers, fing) def add_to_spreadsheet(fers, fing): s = gspreadsheet.open_sheet1("Twitter autome") s.append_row([time.strftime("%m/%d/%y %H:%M:%S"), fers, fing]) def run(): add_to_spreadsheet(*get_twitter_count())
def eventhandler(self, event): menu = self.menustack[-1] if self.cols == 1 and isinstance(menu, Menu): if config.MENU_ARROW_NAVIGATION: if event == MENU_LEFT: event = MENU_BACK_ONE_MENU elif event == MENU_RIGHT: event = MENU_SELECT else: if event == MENU_LEFT: event = MENU_PAGEUP elif event == MENU_RIGHT: event = MENU_PAGEDOWN if self.eventhandler_plugins == None: self.eventhandler_plugins = plugin.get('daemon_eventhandler') if event == MENU_GOTO_MAINMENU: self.goto_main_menu() return True if event == MENU_GOTO_TV: self.goto_media_menu("tv") return True if event == MENU_GOTO_TVGUIDE: self.goto_media_menu("tv.guide") return True if event == MENU_GOTO_VIDEOS: self.goto_media_menu("video") return True if event == MENU_GOTO_MUSIC: self.goto_media_menu("audio") return True if event == MENU_GOTO_IMAGES: self.goto_media_menu("image") return True if event == MENU_GOTO_GAMES: self.goto_media_menu("games") return True if event == MENU_GOTO_RADIO: self.goto_media_menu("audio.radio") return True if event == MENU_GOTO_SHUTDOWN: self.goto_media_menu("shutdown") return True if event == MENU_BACK_ONE_MENU or \ (event == MOUSE_BTN_PRESS and event.button == 3): sounds.play_sound(sounds.MENU_BACK_ONE) self.back_one_menu() return True if not isinstance(menu, Menu) and menu.eventhandler(event): return True if event == 'MENU_RELOAD': self.refresh(True) return True if event == 'MENU_REFRESH': self.refresh() return True if event == 'MENU_REBUILD': self.init_page() self.refresh() return True if not self.menu_items: if event in (MENU_SELECT, MENU_SUBMENU, MENU_PLAY_ITEM): self.back_one_menu() return True menu = self.menustack[-2] if hasattr(menu, 'selected') and hasattr(menu.selected, 'eventhandler') and menu.selected.eventhandler: if menu.selected.eventhandler(event=event, menuw=self): return True for p in self.eventhandler_plugins: if p.eventhandler(event=event, menuw=self): return True return False if not isinstance(menu, Menu): if self.eventhandler_plugins == None: self.eventhandler_plugins = plugin.get('daemon_eventhandler') for p in self.eventhandler_plugins: if p.eventhandler(event=event, menuw=self): return True logger.log( 9, 'no eventhandler for event %s', event) return False if event == MENU_UP: self._handle_up(menu, event) return True if event == MENU_DOWN: self._handle_down(menu, event) return True if event == MENU_PAGEUP: self._handle_pageup(menu, event) return True if event == MENU_PAGEDOWN: self._handle_pagedown(menu, event) return True if event == MENU_LEFT: self._handle_left(menu, event) return True if event == MENU_RIGHT: self._handle_right(menu, event) return True if event == MENU_PLAY_ITEM and hasattr(menu.selected, 'play'): menu.selected.play(menuw=self) return True if event == MENU_PLAY_ITEM or event == MENU_SELECT: self._handle_play_item(menu, event) return True if event == MENU_SUBMENU: self._handle_submenu(menu, event) return True if event == MENU_CALL_ITEM_ACTION: self._handle_call_item_action(menu, event) return True if event == MENU_CHANGE_STYLE and len(self.menustack) > 1: # did the menu change? if skin.toggle_display_style(menu): self.rebuild_page() self.refresh() return True if event == MOUSE_MOTION: for menuitem in menu.choices: if menuitem.rect.collidepoint(event.pos): self.highlight_menuitem(menuitem) return True if event == MOUSE_BTN_PRESS: # Left click if event.button == 1: for menuitem in menu.choices: if menuitem.rect.collidepoint(event.pos): self.highlight_menuitem(menuitem) self.select_menuitem(menuitem) # Middle click elif event.button == 2: self.submenu_menuitem() # Wheel up elif event.button == 4: self.up_menuitem() # Wheel down elif event.button == 5: self.down_menuitem() return True if hasattr(menu.selected, 'eventhandler') and menu.selected.eventhandler: if menu.selected.eventhandler(event=event, menuw=self): return True for p in self.eventhandler_plugins: if p.eventhandler(event=event, menuw=self): return True logger.log( 9, 'no eventhandler for event %s', str(event)) return False
import time import plugin util = plugin.get("util") def run(): n = 0 while True: time.sleep(2) n += 1
def _handle_play_item(self, menu, event): action = None arg = None sounds.play_sound(sounds.MENU_SELECT) try: action = menu.selected.action except AttributeError: actions = menu.selected.actions() or [] # Add the actions of the plugins to the list of actions. This is needed when a # Item class has no actions but plugins provides them. This case happens with an # empty disc. # # FIXME The event MENU_SELECT is called when selecting a submenu entry too. The # item passed to the plugin is then the submenu entry instead its parent item. So # if we are in a submenu we don't want to call the actions of the plugins. # because we'll break some (or all) plugins behavior. Does that sound correct? if config.OSD_SOUNDS: if hasattr(menu.selected, 'arg'): try: key = "menu." + menu.selected.arg[0] if config.OSD_SOUNDS[key]: sounds.play_sound(sounds.load_sound(key)) except: pass else: try: key = "menu." + menu.selected.__class__.__name__ if config.OSD_SOUNDS[key]: sounds.play_sound(sounds.load_sound(key)) except: pass if not hasattr(menu, 'is_submenu'): plugins = plugin.get('item') + plugin.get( 'item_%s' % menu.selected.type) if hasattr(menu.selected, 'display_type'): plugins += plugin.get('item_%s' % menu.selected.display_type) plugins.sort(lambda l, o: cmp(l._level, o._level)) for p in plugins: for a in p.actions(menu.selected): if isinstance(a, MenuItem): actions.append(a) else: actions.append(a[:2]) if actions: action = actions[0] if isinstance(action, MenuItem): action = action.function arg = action.arg else: action = action[0] if not action: AlertBox(text=_('No action defined for this choice!')).show() return action(arg=arg, menuw=self)
def _handle_play_item(self, menu, event): action = None arg = None sounds.play_sound(sounds.MENU_SELECT) try: action = menu.selected.action except AttributeError: actions = menu.selected.actions() or [] # Add the actions of the plugins to the list of actions. This is needed when a # Item class has no actions but plugins provides them. This case happens with an # empty disc. # # FIXME The event MENU_SELECT is called when selecting a submenu entry too. The # item passed to the plugin is then the submenu entry instead its parent item. So # if we are in a submenu we don't want to call the actions of the plugins. # because we'll break some (or all) plugins behavior. Does that sound correct? if config.OSD_SOUNDS: if hasattr(menu.selected, 'arg'): try: key = "menu." + menu.selected.arg[0] if config.OSD_SOUNDS[key]: sounds.play_sound(sounds.load_sound(key)) except: pass else: try: key = "menu." + menu.selected.__class__.__name__ if config.OSD_SOUNDS[key]: sounds.play_sound(sounds.load_sound(key)) except: pass if not hasattr(menu, 'is_submenu'): plugins = plugin.get('item') + plugin.get('item_%s' % menu.selected.type) if hasattr(menu.selected, 'display_type'): plugins += plugin.get('item_%s' % menu.selected.display_type) plugins.sort(lambda l, o: cmp(l._level, o._level)) for p in plugins: for a in p.actions(menu.selected): if isinstance(a, MenuItem): actions.append(a) else: actions.append(a[:2]) if actions: action = actions[0] if isinstance(action, MenuItem): action = action.function arg = action.arg else: action = action[0] if not action: AlertBox(text=_('No action defined for this choice!')).show() return action(arg=arg, menuw=self)
import glob import os import re import time import types import plugin import telepot import telepot.namedtuple when = '9am' telegram, util = plugin.get("telegram", "util") def msg_cb(self, msg): content_type, chat_type, chat_id = telepot.glance(msg) print("content_type, chat_type, chat_id", content_type, chat_type, chat_id) k = telegram.Keyboard() if content_type == 'location': print("location", msg['location']) k.hide_keyboard() self.bot.sendMessage(chat_id, **k.get_message_params("Got it!")) elif content_type == 'text' and "🏠 Go home" == msg['text']: k.hide_keyboard() self.bot.sendMessage(chat_id, **k.get_message_params('Welcome home')) # Youtube-dl # elif content_type == 'text' and "/youtube-dl " in msg['text']:
def eventhandler(self, event, menuw=None): logger.log( 9, 'eventhandler(event=%s, menuw=%s)', event, menuw) # SELECT also should act as PLAY/PAUSE (-> could be done with event rerouting!?) if event == PAUSE or event == PLAY or (event == BUTTON and event.arg == 'SELECT'): if self.slideshow: rc.post_event(Event(OSD_MESSAGE, arg=_('pause'))) rc.post_event(Event('IMAGE_PAUSE_INFO', arg='')) self.slideshow = False if self.timer: self.timer.stop() self.timer = None else: rc.post_event(Event(OSD_MESSAGE, arg=_('play')+(' %ss'%self.duration))) rc.post_event(Event('IMAGE_PLAY_INFO', arg='%s' % self.duration)) self.slideshow = True self.timer = kaa.OneShotTimer(self.signalhandler) self.timer.start(self.duration) return True elif event == STOP: self.last_image = None, None self.slideshow = config.IMAGEVIEWER_AUTOPLAY if self.timer: self.timer.stop() self.timer = None if self.blend: self.blend.stop() self.blend.remove() self.blend = None rc.remove_app(self) self.__added_app = False self.fileitem.eventhandler(event) return True # up and down will stop the slideshow and pass the # event to the playlist elif event == PLAYLIST_NEXT or event == PLAYLIST_PREV: if self.timer: self.timer.stop() self.timer = None self.fileitem.eventhandler(event) return True # rotate image elif event == IMAGE_ROTATE: if event.arg == 'left': self.rotation = (self.rotation - 90) % 360 else: self.rotation = (self.rotation + 90) % 360 self.fileitem['rotation'] = self.rotation self.view(self.fileitem, zoom=self.zoom, rotation=self.rotation) if self.timer: self.timer.start(self.duration) return True # print image information elif event == TOGGLE_OSD: self.osd_mode = (self.osd_mode + 1) % (len(config.IMAGEVIEWER_OSD) + 1) # Redraw self.view(self.fileitem, zoom=self.zoom, rotation = self.rotation) return True # zoom to one third of the image # 1 is upper left, 9 is lower right, 0 zoom off elif str(event) in self.zoom_btns: self.zoom = self.zoom_btns[str(event)] if self.timer: self.timer.stop() self.slideshow = False if self.zoom: # Zoom one third of the image, don't load the next # image in the list self.view(self.fileitem, zoom=self.zoom, rotation = self.rotation) else: # Display entire picture, don't load next image in case # the user wants to zoom around some more. self.view(self.fileitem, zoom=0, rotation=self.rotation) return True elif event == IMAGE_MOVE: coord = event.arg if isinstance(self.zoom, int): self.zoom = self.zoom, coord[0], coord[1] else: self.zoom = self.zoom[0], self.zoom[1] + coord[0], self.zoom[2] + coord[1] self.view(self.fileitem, zoom=self.zoom, rotation=self.rotation) return True # save the image with the current rotation elif event == IMAGE_SAVE: if self.rotation and os.path.splitext(self.filename)[1] == ".jpg": cmd = 'jpegtran -copy all -rotate %s -outfile /tmp/freevo-iview %s' \ % ((self.rotation + 180) % 360, self.filename) os.system(cmd) os.system('mv /tmp/freevo-iview %s' % self.filename) self.rotation = 0 self.osd.bitmapcache.__delitem__(self.filename) return True # append the image filename to shoppingcart list elif event == IMAGE_TAG: if plugin.is_active('shoppingcart'): try: plugin.get('item')[0].shuntItemInCart(self.fileitem) return True except Exception, e: print 'getbyname(\'shoppingcart\')', e
BDDIR = 'BDMV' # Check for makemkvcon if not makemkvcon.installed(): plugin.notify(plugin.lang(50001)) # Service loop key_checked = 0 disc_current = None disc_started = 0 disc_ready = False while not xbmc.abortRequested: plugin.log('run') # Update fixed key key = plugin.get('license_key') if key: makemkv.set(makemkv.APP_KEY, key) # Check for beta key elif plugin.get('license_beta_auto'): period = int(plugin.get('license_beta_period')) * 3600 now = time.time() if now - key_checked > period: if makemkv.updateLicense(): plugin.notify(plugin.lang(50002)) key_checked = now # Disc removed if disc_current: path = os.path.join('/media', disc_current, BDDIR)
class PluginInterface(plugin.DaemonPlugin): """ global idlebar plugin. """ def __init__(self): """ init the idlebar """ plugin.DaemonPlugin.__init__(self) self.poll_interval = 3000 self.poll_menu_only = False self.plugins = None plugin.register(self, 'idlebar') self.visible = True self.bar = None self.barfile = '' self.free_space = -1 self.used_space = 0 # Getting current LOCALE try: locale.resetlocale() except: pass def take_space(self, space): ''' reserve some space from the idlebar, this is for DaemonPlugins ''' self.used_space = space def draw(self, (type, object), osd): """ draw a background and all idlebar plugins """ w = osd.width + 2 * osd.x h = osd.y + 60 f = skin.get_image('idlebar') if self.barfile != f: self.barfile = f try: self.bar = transform.scale(image.load(f).convert_alpha(), (w,h)) except: self.bar = None # draw the cached barimage if self.bar: osd.drawimage(self.bar, (0, 0, w, h), background=True) if not self.plugins: self.plugins = plugin.get('idlebar') x = osd.x + 10 for p in self.plugins: add_x = p.draw((type, object), x, osd) if add_x: x += add_x + 20 self.free_space = x - self.used_space