Changeset 5006:2c4adf9b9233 in orange


Ignore:
Timestamp:
07/23/08 21:11:39 (6 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
a72780b6485eac2c58b74b4adf7b861c53f38501
Message:
  • there is no more widget registry. Widgets are re-read at every session; data is cached in a pickled file for reuse if the file time stamps match
Location:
orange
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeCanvas/orngCanvas.pyw

    r5005 r5006  
    124124        self.addToolBarBreak() 
    125125 
    126         self.createWidgetsToolbar(not os.path.exists(self.registryFileName)) 
     126        self.createWidgetsToolbar() 
    127127 
    128128        self.readShortcuts() 
     
    199199 
    200200 
    201     def createWidgetsToolbar(self, rebuildRegistry): 
     201    def createWidgetsToolbar(self): 
    202202        if hasattr(self, "widgetsToolBar"): 
    203203            if isinstance(self.widgetsToolBar, QToolBar): 
     
    222222            self.widgetsToolBar.addWidget(self.tabs) 
    223223 
    224         ## the registry is now build already in the orngRegistry when setting up the directory names 
    225         if rebuildRegistry == 1: 
    226             parse = orngRegistry.WidgetsToXML() 
    227             parse.ParseWidgetRoot(self.widgetDir, self.canvasSettingsDir) 
    228  
    229         # if registry still doesn't exist then something is very wrong... 
    230         if not os.path.exists(self.registryFileName): 
    231             QMessageBox.critical( self, "Orange Canvas", "Unable to locate widget registry. Exiting...") 
    232             self.quit() 
    233  
    234224        if self.settings.has_key("WidgetTabs") and self.settings["WidgetTabs"] != []: 
    235225            widgetTabList = self.settings["WidgetTabs"] 
     
    237227            widgetTabList = [(name, Qt.Checked) for name in ["Data", "Visualize", "Classify", "Regression", "Evaluate", "Unsupervised", "Associate", "Text", "Genomics", "Prototypes"]] 
    238228 
    239         # read widget registry file and create tab with buttons 
    240         self.tabs.readInstalledWidgets(self.registryFileName, widgetTabList, self.widgetDir, self.picsDir, self.defaultPic) 
     229        # find widgets and create tab with buttons 
     230        self.tabs.readInstalledWidgets(widgetTabList, self.widgetDir, self.picsDir, self.defaultPic) 
    241231        self.settings["WidgetTabs"] = [(name, show) for (name, show, w) in self.tabs.tabs] 
    242232 
     
    308298        #self.menuOptions.addAction( "Channel preferences",  self.menuItemPreferences) 
    309299        #self.menuOptions.addSeparator() 
    310         self.menuOptions.addAction( "&Rebuild Widget Registry",  self.menuItemRebuildWidgetRegistry) 
    311300        self.menuOptions.addAction( "&Customize Shortcuts",  self.menuItemEditWidgetShortcuts) 
    312301        self.menuOptions.addAction( "&Delete Widget Settings",  self.menuItemDeleteWidgetSettings) 
  • orange/OrangeCanvas/orngDlgs.py

    r4963 r5006  
    247247        count = 0 
    248248        for outS in outputs: 
    249             if outInstance.getOutputType(outS.name) == None: continue  # ignore if some signals don't exist any more, since we will dispatch refresh registry somwhere else 
     249            if outInstance.getOutputType(outS.name) == None: continue  # ignore if some signals don't exist any more, since we will report error somewhere else 
    250250            if not issubclass(outInstance.getOutputType(outS.name), outType): continue 
    251251            for inS in inputs: 
    252                 if inInstance.getOutputType(inS.name) == None: continue  # ignore if some signals don't exist any more, since we will dispatch refresh registry somwhere else 
     252                if inInstance.getOutputType(inS.name) == None: continue  # ignore if some signals don't exist any more, since we will report error somewhere else 
    253253                if not issubclass(inType, inInstance.getInputType(inS.name)): continue 
    254254                if issubclass(outInstance.getOutputType(outS.name), inInstance.getInputType(inS.name)): count+= 1 
     
    302302                inConnected.remove(i) 
    303303 
    304         # rebuild registry if necessary 
    305304        for s in majorInputs + minorInputs: 
    306305            if not self.inWidget.instance.hasInputName(s.name): 
  • orange/OrangeCanvas/orngDoc.py

    r4963 r5006  
    121121            return 
    122122        elif connectStatus == -1: 
    123             QMessageBox.critical( self, "Orange Canvas", "Error while connecting widgets. Please rebuild  widget registry (menu Options/Rebuild widget registry) and restart Orange Canvas. Some of the widgets have now different signals.", QMessageBox.Ok) 
     123            QMessageBox.critical( self, "Orange Canvas", "Error while connecting widgets. Some of the widgets have now different signals. Try restarting Orange Canvas.", QMessageBox.Ok) 
    124124            return 
    125125 
     
    219219        if not ok: 
    220220            self.removeLink(outWidget, inWidget, outSignalName, inSignalName) 
    221             QMessageBox.warning( None, "Orange Canvas", "Unable to add link. Please rebuild widget registry and restart Orange Canvas for changes to take effect.", QMessageBox.Ok + QMessageBox.Default ) 
     221            QMessageBox.warning( None, "Orange Canvas", "Unable to add link. Something is really wrong; try restarting Orange Canvas.", QMessageBox.Ok + QMessageBox.Default ) 
    222222            return 0 
    223223 
  • orange/OrangeCanvas/orngOrangeFoldersQt4.py

    r4898 r5006  
    6363        except: pass 
    6464 
    65     registryFileName = os.path.join(canvasSettingsDir, "widgetregistry.xml") 
    6665 
    67     return dict([(name, vars()[name]) for name in ["canvasDir", "orangeDir", "widgetDir", "reportsDir", "picsDir", "widgetSettingsDir", "canvasSettingsDir", "registryFileName", "bufferDir"]]) 
     66    return dict([(name, vars()[name]) for name in ["canvasDir", "orangeDir", "widgetDir", "reportsDir", "picsDir", "widgetSettingsDir", "canvasSettingsDir", "bufferDir"]]) 
    6867 
    6968 
    70 def addOrangeDirectoriesToPath(registryFileName = None): 
     69def addOrangeDirectoriesToPath(): 
    7170    sys.path = [x for x in sys.path if "orange\\orange" not in x.lower() and "orange/orange" not in x.lower()] 
    7271    orangeDir = directoryNames["orangeDir"] 
     
    7473    canvasDir = directoryNames["canvasDir"] 
    7574    sys.path.insert(0, canvasDir) 
    76     if orangeDir not in sys.path: sys.path.insert(0, orangeDir) 
    77     if widgetDir not in sys.path: sys.path.insert(0, widgetDir) 
    78     if os.path.exists(widgetDir): 
    79         for name in os.listdir(widgetDir): 
    80             fullName = os.path.join(widgetDir, name) 
    81             if os.path.isdir(fullName) and fullName not in sys.path and name.lower() not in ["cvs", ".svn", "icons"]: 
    82                 sys.path.insert(0, fullName) 
    83  
    84     if registryFileName != None and os.path.exists(registryFileName): 
    85         import xml.dom.minidom 
    86         doc = xml.dom.minidom.parse(registryFileName) 
    87         for category in doc.getElementsByTagName("category"): 
    88             directory = category.getAttribute("directory") 
    89             if directory and directory not in sys.path: 
    90                 sys.path.insert(0, directory) 
     75    if orangeDir not in sys.path: 
     76        sys.path.insert(0, orangeDir) 
     77    if widgetDir not in sys.path: 
     78        sys.path.insert(0, widgetDir) 
    9179 
    9280directoryNames = __getDirectoryNames() 
    9381#vars().update(directoryNames) 
    94 addOrangeDirectoriesToPath(directoryNames["registryFileName"]) 
     82addOrangeDirectoriesToPath() 
  • orange/OrangeCanvas/orngRegistry.py

    r4903 r5006  
    11# Author: Gregor Leban (gregor.leban@fri.uni-lj.si) 
    2 # Description: 
    3 #    parse widget information to a registry file (.xml) - info is then used inside orngTabs.py 
    42# 
    5 import os, sys, string, re, user 
    6 import xml.dom.minidom 
     3 
     4import os, sys, re, glob, stat 
    75from orngOrangeFoldersQt4 import * 
    86 
    9 class WidgetsToXML: 
     7class WidgetDescription: 
     8    def __init__(self, **attrs): 
     9        self.__dict__.update(attrs) 
    1010 
    11     # read all installed widgets, build a registry and store widgets.pth with directory names in python dir 
    12     def ParseWidgetRoot(self, widgetDirName, canvasSettingsDir): 
    13         widgetDirName = os.path.realpath(widgetDirName) 
    14         canvasSettingsDir = os.path.realpath(canvasSettingsDir) 
     11class WidgetCategory: 
     12    def __init__(self, name, widgets, directory): 
     13        self.name = name 
     14        self.widgets = widgets 
     15        self.directory = directory 
     16    
     17def readCategories(): 
     18    widgetDirName = os.path.realpath(directoryNames["widgetDir"]) 
     19    canvasSettingsDir = os.path.realpath(directoryNames["canvasSettingsDir"]) 
     20    cacheFilename = os.path.join(canvasSettingsDir, "cachedWidgetDescriptions.pickle")  
    1521 
    16         # create xml document 
    17         doc = xml.dom.minidom.Document() 
    18         canvas = doc.createElement("orangecanvas") 
    19         categories = doc.createElement("widget-categories") 
    20         doc.appendChild(canvas) 
    21         canvas.appendChild(categories) 
     22    try: 
     23        import cPickle 
     24        cats = cPickle.load(file(cacheFilename, "rb")) 
     25        cachedWidgetDescriptions = dict([(w.fullname, w) for cat in cats for w in cat.widgets]) 
     26    except: 
     27        cachedWidgetDescriptions = {}  
    2228 
    23         for filename in os.listdir(widgetDirName): 
    24             full_filename = os.path.join(widgetDirName, filename) 
    25             if os.path.isdir(full_filename): 
    26                 self.ParseDirectory(doc, categories, full_filename, filename) 
     29    directories = [] 
     30    for dirName in os.listdir(widgetDirName): 
     31        directory = os.path.join(widgetDirName, dirName) 
     32        if os.path.isdir(directory): 
     33            directories.append((dirName, directory, "")) 
    2734 
    28         additionalFile = os.path.join(canvasSettingsDir, "additionalCategories") 
    29         if os.path.exists(additionalFile): 
    30             for lne in open(additionalFile, "rt"): 
    31                 try: 
    32                     catName, dirName = [x.strip() for x in lne.split("\t")] 
    33                     self.ParseDirectory(doc, categories, dirName, catName, True) 
    34                 except: 
    35                     pass 
     35    additionalFile = os.path.join(canvasSettingsDir, "additionalCategories") 
     36    if os.path.exists(additionalFile): 
     37        for lne in open(additionalFile, "rt"): 
     38            try: 
     39                catName, dirName = [x.strip() for x in lne.split("\t")] 
     40                directories.append((catName, dirName, dirName)) 
     41            except: 
     42                pass 
     43             
     44    categories = [] 
     45    for catName, dirName, plugin in directories: 
     46        widgets = readWidgets(dirName, cachedWidgetDescriptions) 
     47        if widgets: 
     48            categories.append(WidgetCategory(catName, widgets, plugin and dirName or "")) 
     49            if dirName not in sys.path: 
     50                sys.path.insert(0, dirName) 
     51 
     52    cPickle.dump(categories, file(cacheFilename, "wb")) 
     53    return categories 
    3654 
    3755 
    38         # we put widgets that are in the root dir of widget directory to category "Other" 
    39         self.ParseDirectory(doc, categories, widgetDirName, "Other") 
     56re_inputs = re.compile(r'[ \t]+self.inputs\s*=\s*(?P<signals>\[[^]]*\])', re.DOTALL) 
     57re_outputs = re.compile(r'[ \t]+self.outputs\s*=\s*(?P<signals>\[[^]]*\])', re.DOTALL) 
    4058 
    41         xmlText = doc.toprettyxml() 
    42         file = open(os.path.join(canvasSettingsDir, "widgetregistry.xml"), "wt") 
    43         file.write(xmlText) 
    44         file.flush() 
    45         file.close() 
    46         doc.unlink() 
     59def readWidgets(directory, cachedWidgetDescriptions): 
     60    widgets = [] 
     61    for filename in glob.iglob(os.path.join(directory, "*.py")): 
     62        if os.path.isdir(filename) or os.path.islink(filename): 
     63            continue 
     64         
     65        datetime = str(os.stat(filename)[stat.ST_MTIME]) 
     66        cachedDescription = cachedWidgetDescriptions.get(filename, None) 
     67        if cachedDescription and cachedDescription.time == datetime: 
     68            widgets.append(cachedDescription) 
     69            continue 
     70         
     71        data = file(filename).read() 
     72        istart = data.find("<name>") 
     73        if istart < 0: 
     74            continue 
     75        iend = data.find("</name>") 
     76        if iend < 0: 
     77            continue 
    4778 
    48     # parse all widgets in directory widgetDirName\categoryName into new category named categoryName 
    49     def ParseDirectory(self, doc, categories, full_dirname, categoryName, plugin = False): 
    50         if full_dirname not in sys.path:        # add directory to orange path 
    51             sys.path.insert(0, full_dirname)          # this doesn't save the path when you close the canvas, so we have to save also to widgets.pth 
     79        widgetDesc = WidgetDescription( 
     80                         name=data[istart+6:iend], 
     81                         time=datetime, 
     82                         filename=os.path.splitext(os.path.split(filename)[1])[0], 
     83                         fullname = filename, 
     84                         inputList=getSignalList(re_inputs, data), 
     85                         outputList=getSignalList(re_outputs, data) 
     86                         ) 
    5287 
    53         for filename in os.listdir(full_dirname): 
    54             full_filename = os.path.join(full_dirname, filename) 
    55             if os.path.isdir(full_filename) or os.path.islink(full_filename) or os.path.splitext(full_filename)[1] != ".py": 
    56                 continue 
    57  
    58             file = open(full_filename) 
    59             data = file.read() 
    60             file.close() 
    61  
    62             name        = self.GetCustomText(data, '<name>.*</name>') 
    63             #category    = self.GetCustomText(data, '<category>.*</category>') 
    64             author      = self.GetCustomText(data, '<author>.*</author>') 
    65             contact     = self.GetCustomText(data, '<contact>.*</contact>') or "" 
    66             icon        = self.GetCustomText(data, '<icon>.*</icon>') 
    67             priorityStr = self.GetCustomText(data, '<priority>.*</priority>') 
    68             if priorityStr == None:    priorityStr = "5000" 
    69             if author      == None: author = "" 
    70             if icon        == None: icon = "icon/Unknown.png" 
    71  
    72             description = self.GetDescription(data) 
    73             inputList   = self.GetAllInputs(data) 
    74             outputList  = self.GetAllOutputs(data) 
    75  
    76             if (name == None):      # if the file doesn't have a name, we treat it as a non-widget file 
    77                 continue 
    78  
    79             # create XML node for the widget 
    80             child = categories.firstChild 
    81             while (child != None and child.attributes.get("name").nodeValue != categoryName): 
    82                 child= child.nextSibling 
    83  
    84             if (child == None): 
    85                 child = doc.createElement("category") 
    86                 child.setAttribute("name", categoryName) 
    87                 if plugin: 
    88                     child.setAttribute("directory", full_dirname) 
    89                 categories.appendChild(child) 
    90  
    91             widget = doc.createElement("widget") 
    92             widget.setAttribute("file", filename[:-3]) 
    93             widget.setAttribute("name", name) 
    94             widget.setAttribute("in", str(inputList)) 
    95             widget.setAttribute("out", str(outputList)) 
    96             widget.setAttribute("icon", icon) 
    97             widget.setAttribute("priority", priorityStr) 
    98             widget.setAttribute("author", author) 
    99             widget.setAttribute("contact", contact) 
    100  
    101             # description 
    102             if (description != ""): 
    103                 desc = doc.createElement("description") 
    104                 descText = doc.createTextNode(description) 
    105                 desc.appendChild(descText) 
    106                 widget.appendChild(desc) 
    107  
    108             child.appendChild(widget) 
     88        for attr, deflt in (("contact>", "") , ("icon>", "icons/Unknown.png"), ("priority>", "5000"), ("description>", "")): 
     89            istart, iend = data.find("<"+attr), data.find("</"+attr) 
     90            setattr(widgetDesc, attr[:-1], istart >= 0 and iend >= 0 and data[istart+1+len(attr):iend].strip() or deflt) 
     91     
     92        widgets.append(widgetDesc) 
     93         
     94    return widgets 
    10995 
    11096 
    111     def GetDescription(self, data): 
    112         #read the description from widget 
    113         search = re.search('<description>.*</description>', data, re.DOTALL) 
    114         if (search == None): 
    115             return "" 
     97re_tuple = re.compile(r"\(([^)]+)\)") 
    11698 
    117         description = search.group(0)[13:-14]    #delete the <...> </...> 
    118         description = re.sub("#", "", description)  # if description is in multiple lines, delete the comment char 
    119         return string.strip(description) 
    120  
    121     def GetCustomText(self, data, searchString): 
    122         #read the description from widget 
    123         search = re.search(searchString, data) 
    124         if (search == None): 
    125             return None 
    126  
    127         text = search.group(0) 
    128         text = text[text.find(">")+1:-text[::-1].find("<")-1]    #delete the <...> </...> 
    129         return text.strip() 
     99def getSignalList(regex, data): 
     100    inmo = regex.search(data) 
     101    if inmo: 
     102        return str([tuple([y[0] in "'\"" and y[1:-1] or str(y) for y in (x.strip() for x in ttext.group(1).split(","))]) 
     103               for ttext in re_tuple.finditer(inmo.group("signals"))]) 
     104    else: 
     105        return "[]" 
    130106 
    131107 
    132     def GetAllInputs(self, data): 
    133         #result = re.search('self.inputs *= *[[].*]', data) 
    134         result = re.search('[ \t]+self.inputs *= *[[].*]', data) 
    135         if not result: return [] 
    136         text = data[result.start():result.end()] 
    137         text = text[text.index("[")+1:text.index("]")] 
    138         text= text.replace('"',"'") 
    139         #inputs = re.findall("\(.*?\)", text) 
    140         inputs = re.findall("\(.*?[\"\'].*?[\"\'].*?\)", text) 
    141         inputList = [] 
    142         for input in inputs: 
    143             inputList.append(self.GetAllValues(input)) 
    144         return inputList 
    145  
    146     def GetAllOutputs(self, data): 
    147         #result = re.search('self.outputs *= *[[].*]', data) 
    148         result = re.search('[ \t]+self.outputs *= *[[].*]', data) 
    149         if not result: return [] 
    150         text = data[result.start():result.end()] 
    151         text = text[text.index("[")+1:text.index("]")] 
    152         text= text.replace('"',"'") 
    153         #outputs = re.findall("\(.*?\)", text) 
    154         outputs = re.findall("\(.*?[\"\'].*?[\"\'].*?\)", text) 
    155         outputList = [] 
    156         for output in outputs: 
    157             outputList.append(self.GetAllValues(output)) 
    158         return outputList 
    159  
    160     def GetAllValues(self, text): 
    161         text = text[1:-1] 
    162         vals = text.split(",") 
    163         vals[0] = vals[0][1:-1] 
    164         for i in range(len(vals)): 
    165             vals[i] = vals[i].strip() 
    166         return tuple(vals) 
    167  
    168  
    169 def rebuildRegistry(): 
    170     dirs = directoryNames 
    171     parse = WidgetsToXML() 
    172     parse.ParseWidgetRoot(dirs["widgetDir"], dirs["canvasSettingsDir"]) 
    173  
    174108def readAdditionalCategories(): 
    175     dirs = directoryNames 
    176     addCatFile = os.path.join(dirs["canvasSettingsDir"], "additionalCategories") 
     109    addCatFile = os.path.join(directoryNames["canvasSettingsDir"], "additionalCategories") 
    177110    if os.path.exists(addCatFile): 
    178         return [tuple([x.strip() for x in lne.split("\t")]) for lne in open(addCatFile, "r")] 
     111        return [tuple([x.strip() for x in lne.split("\t")]) for lne in file(addCatFile, "r")] 
    179112    else: 
    180113        return [] 
    181114 
    182115def writeAdditionalCategories(categories): 
    183     dirs = directoryNames 
    184     open(os.path.join(dirs["canvasSettingsDir"], "additionalCategories"), "w").write("\n".join(["\t".join(l) for l in categories])) 
     116    file(os.path.join(directoryNames["canvasSettingsDir"], "additionalCategories"), "w").write("\n".join(["\t".join(l) for l in categories])) 
    185117 
    186118def addWidgetCategory(category, directory, add = True): 
     
    188120        directory = os.path.dirname(directory) 
    189121    writeAdditionalCategories([x for x in readAdditionalCategories() if x[0] != category and x[1] != directory] + (add and [(category, directory)] or [])) 
    190     rebuildRegistry() 
    191122 
    192123 
    193124if __name__=="__main__": 
    194     rebuildRegistry() 
     125    readCategories() 
  • orange/OrangeCanvas/orngSignalManager.py

    r4795 r5006  
    2020        self.handler = handler 
    2121 
    22         if type(parameters) == str: parameters = eval(parameters)   # in registry, parameters are stored as strings 
     22        if type(parameters) == str: parameters = eval(parameters)   # parameters are stored as strings 
    2323        # if we have the old definition of parameters then transform them 
    2424        if parameters in [0,1]: 
  • orange/OrangeCanvas/orngTabs.py

    r4992 r5006  
    77import os.path, sys 
    88from string import strip, count, replace 
    9 import orngDoc, orngOutput 
     9import orngDoc, orngOutput, orngRegistry 
    1010from orngSignalManager import InputSignal, OutputSignal 
    11 from xml.dom.minidom import Document, parse 
    1211 
    1312WB_TOOLBOX = 0 
     
    4746        widgetDir = str(self.widgetTabs.widgetInfo[self.nameKey]["directory"])#os.path.split(self.getFileName())[0] 
    4847 
    49         for paths in [(self.canvasDlg.picsDir, name), 
    50                       (self.canvasDlg.widgetDir, name), 
    51                       (name,), 
    52                       (widgetDir, name), 
     48        for paths in [(self.canvasDlg.picsDir, name),  
     49                      (self.canvasDlg.widgetDir, name),  
     50                      (name,),  
     51                      (widgetDir, name),  
    5352                      (widgetDir, "icons", name)]: 
    5453            fname = os.path.join(*paths) 
     
    118117                win.addLine(win.widgets[-2], win.widgets[-1]) 
    119118        elif (isinstance(win, orngOutput.OutputWindow)): 
    120             QMessageBox.information(self,'Orange Canvas','Unable to add widget instance to Output window. Please select a document window first.',QMessageBox.Ok) 
    121         else: 
    122             QMessageBox.information(self,'Orange Canvas','Unable to add widget instance. Please open a document window first.',QMessageBox.Ok) 
     119            QMessageBox.information(self, 'Orange Canvas', 'Unable to add widget instance to Output window. Please select a document window first.', QMessageBox.Ok) 
     120        else: 
     121            QMessageBox.information(self, 'Orange Canvas', 'Unable to add widget instance. Please open a document window first.', QMessageBox.Ok) 
    123122 
    124123 
     
    214213        vrect = QRectF(win.visibleRegion().boundingRect()) 
    215214        inside = win.canvasView.rect().contains(win.canvasView.mapFromGlobal(self.mapToGlobal(e.pos()))) 
    216         p = QPointF(win.canvasView.mapFromGlobal(self.mapToGlobal(e.pos()))) + QPointF(win.canvasView.mapToScene(QPoint(0,0))) 
     215        p = QPointF(win.canvasView.mapFromGlobal(self.mapToGlobal(e.pos()))) + QPointF(win.canvasView.mapToScene(QPoint(0, 0))) 
    217216 
    218217        dinwin, widget = getattr(self, "widgetDragging", (None, None)) 
     
    301300        self.tabs = [] 
    302301 
    303     # read the xml registry and show all installed widgets 
    304     def readInstalledWidgets(self, registryFileName, widgetTabList, widgetDir, picsDir, defaultPic): 
     302    def readInstalledWidgets(self, widgetTabList, widgetDir, picsDir, defaultPic): 
    305303        self.widgetDir = widgetDir 
    306304        self.picsDir = picsDir 
    307305        self.defaultPic = defaultPic 
    308         doc = parse(registryFileName) 
    309         orangeCanvas = doc.firstChild 
    310         categories = orangeCanvas.getElementsByTagName("widget-categories")[0] 
    311         if (categories == None): 
    312             return 
    313  
    314         categoryList = categories.getElementsByTagName("category") 
    315         categoryNames = [str(cat.getAttribute("name")) for cat in categoryList] 
     306        categories = orngRegistry.readCategories() 
    316307 
    317308        # first insert the default tab names 
    318309        for tab in widgetTabList: 
    319             if tab[0] in categoryNames:        # add a category only if there are some widgets in the folder 
    320                 self.insertWidgetTab(tab[0], tab[1]) 
     310            self.insertWidgetTab(tab[0], tab[1]) 
    321311 
    322312        # now insert widgets into tabs + create additional tabs 
    323         for category in categoryList: 
     313        for category in categories: 
    324314            self.insertWidgetsToTab(category) 
    325315 
     
    340330    # add all widgets inside the category to the tab 
    341331    def insertWidgetsToTab(self, category): 
    342         strCategory = str(category.getAttribute("name")) 
     332        strCategory = str(category.name) 
    343333 
    344334        if self.tabDict.has_key(strCategory): 
     
    347337            tab = self.insertWidgetTab(strCategory) 
    348338 
    349         tab.builtIn = not category.hasAttribute("directory") 
    350         directory = not tab.builtIn and str(category.getAttribute("directory")) 
     339        directory = category.directory 
     340        tab.builtIn = not directory 
    351341 
    352342        priorityList = [] 
     
    359349        outputList = [] 
    360350 
    361         widgetList = category.getElementsByTagName("widget") 
    362         for widget in widgetList: 
    363             try: 
    364                 name = str(widget.getAttribute("name")) 
    365                 fileName = str(widget.getAttribute("file")) 
    366                 author = str(widget.getAttribute("author")) 
    367                 inputs = [InputSignal(*signal) for signal in eval(widget.getAttribute("in"))] 
    368                 outputs = [OutputSignal(*signal) for signal in eval(widget.getAttribute("out"))] 
    369                 priority = int(widget.getAttribute("priority")) 
    370                 iconName = widget.getAttribute("icon") 
    371  
    372                 # it's a complicated way to get to the widget description 
    373                 description = "" 
    374                 for node in widget.childNodes: 
    375                     if node.nodeType == node.TEXT_NODE: 
    376                         description = description + node.nodeValue 
    377                     else: 
    378                         for n2 in node.childNodes: 
    379                             if n2.nodeType == node.TEXT_NODE: 
    380                                 description = description + n2.nodeValue 
    381  
    382                 description = strip(description) 
     351        for widget in category.widgets: 
     352#            try: 
    383353                i = 0 
     354                priority = int(widget.priority) 
    384355                while i < len(priorityList) and priority > priorityList[i]: 
    385356                    i = i + 1 
    386357                priorityList.insert(i, priority) 
    387                 nameList.insert(i, name) 
    388                 authorList.insert(i, author) 
    389                 fileNameList.insert(i, fileName) 
    390                 iconNameList.insert(i, iconName) 
    391                 descriptionList.insert(i, description) 
    392                 inputList.insert(i, inputs) 
    393                 outputList.insert(i, outputs) 
    394             except: 
    395                 print "Error at reading settings for %s widget." % (name) 
    396                 tpe, val, traceback = sys.exc_info() 
    397                 sys.excepthook(tpe, val, traceback)  # print the exception 
     358                nameList.insert(i, widget.name) 
     359                authorList.insert(i, widget.contact) 
     360                fileNameList.insert(i, widget.filename) 
     361                iconNameList.insert(i, widget.icon) 
     362                descriptionList.insert(i, widget.description) 
     363                inputList.insert(i, [InputSignal(*signal) for signal in eval(widget.inputList)]) 
     364                outputList.insert(i, [OutputSignal(*signal) for signal in eval(widget.outputList)]) 
     365#            except: 
     366#                print "Error occurred reading settings for %s widget." % (name) 
     367#                tpe, val, traceback = sys.exc_info() 
     368#                sys.excepthook(tpe, val, traceback)  # print the exception 
    398369 
    399370        exIndex = 0 
     
    426397    def __init__(self, canvasDlg, widgetInfo, *args): 
    427398        WidgetListBase.__init__(self, canvasDlg, widgetInfo) 
    428         apply(QTabWidget.__init__,(self,) + args) 
     399        apply(QTabWidget.__init__, (self,) + args) 
    429400 
    430401 
     
    464435        self.setWidget(self.treeWidget) 
    465436        iconSize = self.canvasDlg.iconSizeDict[self.canvasDlg.settings["iconSize"]] 
    466         self.treeWidget.setIconSize(QSize(iconSize,iconSize)) 
     437        self.treeWidget.setIconSize(QSize(iconSize, iconSize)) 
    467438        self.treeWidget.setRootIsDecorated(0)  
    468439                 
     
    566537        vrect = QRectF(win.visibleRegion().boundingRect()) 
    567538        inside = win.canvasView.rect().contains(win.canvasView.mapFromGlobal(self.mapToGlobal(e.pos()))) 
    568         p = QPointF(win.canvasView.mapFromGlobal(self.mapToGlobal(e.pos()))) + QPointF(win.canvasView.mapToScene(QPoint(0,0))) 
     539        p = QPointF(win.canvasView.mapFromGlobal(self.mapToGlobal(e.pos()))) + QPointF(win.canvasView.mapToScene(QPoint(0, 0))) 
    569540 
    570541        dinwin, widget = getattr(self, "widgetDragging", (None, None)) 
     
    619590                win.addLine(win.widgets[-2], win.widgets[-1]) 
    620591        elif (isinstance(win, orngOutput.OutputWindow)): 
    621             QMessageBox.information(self,'Orange Canvas','Unable to add widget instance to Output window. Please select a document window first.',QMessageBox.Ok) 
    622         else: 
    623             QMessageBox.information(self,'Orange Canvas','Unable to add widget instance. Please open a document window first.',QMessageBox.Ok) 
     592            QMessageBox.information(self, 'Orange Canvas', 'Unable to add widget instance to Output window. Please select a document window first.', QMessageBox.Ok) 
     593        else: 
     594            QMessageBox.information(self, 'Orange Canvas', 'Unable to add widget instance. Please open a document window first.', QMessageBox.Ok) 
    624595     
  • orange/updateOrange.py

    r4795 r5006  
    410410 
    411411        self.addText("Update finished. New files: <b>%d</b>. Updated files: <b>%d</b>\n" %(newFiles, updatedFiles)) 
    412  
    413         # remove widgetregistry.xml in orangeCanvas directory 
    414         if os.path.exists(os.path.join(self.orangeDir, "OrangeCanvas/widgetregistry.xml")) and newFiles + updatedFiles > 0: 
    415             os.remove(os.path.join(self.orangeDir, "OrangeCanvas/widgetregistry.xml")) 
    416412 
    417413        self.statusBar.showMessage("Update finished.") 
Note: See TracChangeset for help on using the changeset viewer.