66import logging
77import os
88import re
9- import types
109
1110# Fix attemp for
1211import _strptime
1716
1817# Package imports
1918from codequick .script import Script
20- from codequick .support import auto_sort , build_path , logger_id , dispatcher
19+ from codequick .support import auto_sort , build_path , logger_id , dispatcher , Route
2120from codequick .utils import ensure_unicode , ensure_native_str , unicode_type , PY3 , bold
2221
2322if PY3 :
@@ -620,30 +619,29 @@ def set_callback(self, callback, *args, **kwargs):
620619 * :class:`codequick.Script<codequick.script.Script>` callback.
621620 * :class:`codequick.Route<codequick.route.Route>` callback.
622621 * :class:`codequick.Resolver<codequick.resolver.Resolver>` callback.
623- * The path to a callback function. i.e. "/main/menu /"
622+ * The path to a callback function. i.e. "/resources/lib/ main/video_list /"
624623 * Any kodi path, e.g. "plugin://" or "script://"
625624 * Directly playable URL.
626625
627626 .. note::
628627
629- By default kodi plugin / script paths are treated as playable items .
628+ When specifying a external plugin / script path as a callback, Kodi treats it as a playable item by default .
630629 To override this behavior, you can pass in the ``is_playable`` and ``is_folder`` parameters.
631630 If only ``is_folder`` is given, then ``is_playable`` will default to ``not is_folder``.
632631
633632 :param callback: The "callback" or playable URL.
634633 :param args: "Positional" arguments that will be passed to the callback.
635634 :param kwargs: "Keyword" arguments that will be passed to the callback.
636635 """
637- self . is_folder = is_folder = kwargs . pop ( "is_folder" , self . is_folder )
638- self . is_playable = kwargs . pop ( "is_playable" , not is_folder )
639- if callback in dispatcher . registered_routes :
640- callback = dispatcher . registered_routes [ callback ]. callback
636+ if not hasattr ( callback , "route" ):
637+ # Only used for external plugin / script paths, ignored otherwise
638+ self . is_folder = is_folder = kwargs . pop ( "is_folder" , self . is_folder )
639+ self . is_playable = kwargs . pop ( "is_playable" , not is_folder )
641640
642- # Handle case where callback is a full path to a callback function (i.e. "/resources/lib/foo/boo/")
643- # but not registered yet because in another python file that the current one
644- elif not isinstance (callback , types .FunctionType ) and self .is_folder :
645- dispatcher .get_route (callback )
646- callback = dispatcher .registered_routes [callback ].callback
641+ # We don't have a plugin / http path,
642+ # So we should then have a callback path
643+ if "://" not in callback :
644+ callback = dispatcher .get_route (callback ).callback
647645
648646 self .path = callback
649647 self ._args = args
@@ -654,16 +652,19 @@ def set_callback(self, callback, *args, **kwargs):
654652 def _close (self ):
655653 path = self .path
656654 listitem = self .listitem
655+ # When we have a callback function
657656 if hasattr (path , "route" ):
658657 isfolder = path .route .is_folder
659658 listitem .setProperty ("isplayable" , str (path .route .is_playable ).lower ())
660659 listitem .setProperty ("folder" , str (path .route .is_folder ).lower ())
661660 path = build_path (path , self ._args , self .params .raw_dict )
661+ # When we have a blank listitem that does nothing
662662 elif not path :
663663 listitem .setProperty ("isplayable" , "false" )
664664 listitem .setProperty ("folder" , "false" )
665665 isfolder = False
666666 else :
667+ # Directly playable item or plugin path that calls another addon.
667668 listitem .setProperty ("isplayable" , str (self .is_playable ).lower ())
668669 listitem .setProperty ("folder" , str (self .is_folder ).lower ())
669670 isfolder = self .is_folder
@@ -823,21 +824,24 @@ def search(cls, callback, *args, **kwargs):
823824 :param kwargs: "Keyword" arguments that will be passed to the callback.
824825 :raises ValueError: If the given "callback" function does not have a ``search_query`` parameter.
825826 """
826- from codequick .search import SavedSearches
827+ if hasattr (callback , "route" ):
828+ route = callback
829+ else :
830+ route = dispatcher .get_route (callback )
827831
828832 # Check that callback function has required parameter(search_query)
829- if "search_query" not in callback . route .arg_names ():
833+ if "search_query" not in route .arg_names ():
830834 raise ValueError ("callback function is missing required argument: 'search_query'" )
831835
832836 if args :
833837 # Convert positional arguments to keyword arguments
834- callback . route .args_to_kwargs (args , kwargs )
838+ route .args_to_kwargs (args , kwargs )
835839
836840 item = cls ()
837841 item .label = bold (Script .localize (SEARCH ))
838842 item .art .global_thumb ("search.png" )
839843 item .info ["plot" ] = Script .localize (SEARCH_PLOT )
840- item .set_callback (SavedSearches , _route = callback . route .path , first_load = True , ** kwargs )
844+ item .set_callback ("/codequick/search/savedsearches/" , _route = route .path , first_load = True , ** kwargs )
841845 return item
842846
843847 @classmethod
0 commit comments