Ignore:
Timestamp:
11/13/12 20:05:23 (17 months ago)
Author:
Matija Polajnar <matija.polajnar@…>
Branch:
default
Message:

Rewrite the add-on support modules and GUI to support the new properly packed add-ons, published on PyPI.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/orngRegistry.py

    r10879 r11018  
    2828            return os.path.join(orngEnviron.orangeDocDir, "widgets", subDir) 
    2929        else:  # An add-on widget 
    30             addOnDocDir = self.addOn.directory_documentation() 
    31             return os.path.join(addOnDocDir, "widgets") 
     30            return None  # new style add-ons only have on-line documentation 
     31            #addOnDocDir = self.addOn.directory_documentation() 
     32            #return os.path.join(addOnDocDir, "widgets") 
    3233 
    3334 
     
    3738            self.update(widgets) 
    3839        self.name = name 
    39     
     40 
     41def load_new_addons(directories = []): 
     42    # New-type add-ons 
     43    for entry_point in pkg_resources.iter_entry_points(WIDGETS_ENTRY_POINT): 
     44        try: 
     45            module = entry_point.load() 
     46            if hasattr(module, '__path__'): 
     47                # It is a package 
     48                directories.append((entry_point.name, module.__path__[0], entry_point.name, False, module)) 
     49            else: 
     50                # It is a module 
     51                # TODO: Implement loading of widget modules 
     52                # (This should be default way to load widgets, not parsing them as files, or traversing directories, just modules and packages (which load modules)) 
     53                pass 
     54        except ImportError, err: 
     55            print "While loading, importing widgets '%s' failed: %s" % (entry_point.name, err) 
     56        except pkg_resources.DistributionNotFound, err: 
     57            print "Loading add-on '%s' failed because of a missing dependency: '%s'" % (entry_point.name, err) 
     58        except Exception, err: 
     59            print "An exception occurred during the loading of '%s':\n%r" %(entry_point.name, err) 
     60    return directories 
     61 
    4062def readCategories(silent=False): 
    4163    try: 
     
    7799             
    78100    # read list of add-ons 
    79     for addOn in Orange.utils.addons.installed_addons.values() + Orange.utils.addons.registered_addons: 
    80         addOnWidgetsDir = os.path.join(addOn.directory, "widgets") 
    81         if os.path.isdir(addOnWidgetsDir): 
    82             directories.append((addOn.name, addOnWidgetsDir, addOn, False, None)) 
    83         addOnWidgetsPrototypesDir = os.path.join(addOnWidgetsDir, "prototypes") 
    84         if os.path.isdir(addOnWidgetsPrototypesDir): 
    85             directories.append((None, addOnWidgetsPrototypesDir, addOn, True, None)) 
    86  
    87     # New-type add-ons 
    88     for entry_point in pkg_resources.iter_entry_points(WIDGETS_ENTRY_POINT): 
    89         try: 
    90             module = entry_point.load() 
    91             if hasattr(module, '__path__'): 
    92                 # It is a package 
    93                 addOn = addons.OrangeAddOn() 
    94                 addOn.name = entry_point.name 
    95                 addOn.directory = module.__path__[0] # This is invalid and useless as documentation is not there, but to set it to something 
    96                 directories.append((entry_point.name, module.__path__[0], addOn, False, module)) 
    97             else: 
    98                 # It is a module 
    99                 # TODO: Implement loading of widget modules 
    100                 # (This should be default way to load widgets, not parsing them as files, or traversing directories, just modules and packages (which load modules)) 
    101                 pass 
    102         except ImportError, err: 
    103             print "While loading, importing widgets '%s' failed: %s" % (entry_point.name, err) 
    104         except pkg_resources.DistributionNotFound, err: 
    105             print "Loading add-on '%s' failed because of a missing dependency: '%s'" % (entry_point.name, err) 
    106         except Exception, err: 
    107             print "An exception occurred during the loading of '%s':\n%r" %(entry_point.name, err) 
     101    #TODO Load registered add-ons! 
     102 
     103    load_new_addons(directories) 
    108104 
    109105    categories = {}      
     
    272268                    formatedOutList += " &nbsp; &nbsp; - " + signal.name + " (" + signal.type + ")<br>" 
    273269 
    274             addOnName = "" if not widgetInfo.addOn else " (from add-on %s)" % widgetInfo.addOn.name 
     270            addOnName = "" if not widgetInfo.addOn else " (from add-on %s)" % widgetInfo.addOn 
    275271     
    276272            widgetInfo.tooltipText = "<b><b>&nbsp;%s</b></b>%s<hr><b>Description:</b><br>&nbsp;&nbsp;%s<hr>%s<hr>%s" % (meta.name, addOnName, widgetInfo.description, formatedInList[:-4], formatedOutList[:-4])  
Note: See TracChangeset for help on using the changeset viewer.