Changeset 7735:22867997305f in orange


Ignore:
Timestamp:
03/11/11 14:28:05 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
11c0018a8d3965f15fe1f69b350846ce75b82404
Message:

Added updateWidgetRegistry method (ensures the settingsWidgetTabs? is consistent with widgetRegistry).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeCanvas/orngCanvas.pyw

    r7731 r7735  
    6565#        self.lineColor = QColor(*self.settings["lineColor"]) 
    6666 
    67         if not self.settings.has_key("WidgetTabs") or self.settings["WidgetTabs"] == []: 
    68             f = open(os.path.join(self.canvasDir, "WidgetTabs.txt"), "r") 
    69             defaultTabs = [c for c in [line.split("#")[0].strip() for line in f.readlines()] if c!=""] 
    70             for i in xrange(len(defaultTabs)-1,0,-1): 
    71                 if defaultTabs[i] in defaultTabs[0:i]: 
    72                     del defaultTabs[i] 
    73             self.settings["WidgetTabs"] = [(name, Qt.Checked) for name in defaultTabs] + [("Prototypes", Qt.Unchecked)]  
    74          
    7567        # output window 
    7668        self.output = orngOutput.OutputWindow(self) 
    7769        self.output.catchException(1) 
    7870        self.output.catchOutput(1) 
     71         
     72        self.updateWidgetRegistry() 
    7973 
    8074        # create error and warning icons 
     
    9589 
    9690        self.setStatusBar(MyStatusBar(self)) 
    97                  
    98         self.widgetRegistry = orngRegistry.readCategories() 
     91         
    9992        self.updateStyle() 
    10093         
     
    176169        orngTabs.constructCategoriesPopup(self) 
    177170        self.createWidgetsToolbar() 
    178         orngTabs.constructCategoriesPopup(self) 
    179171        self.readShortcuts() 
    180172         
    181173        def addOnRefreshCallback(): 
    182             self.widgetRegistry = orngRegistry.readCategories() 
     174            self.updateWidgetRegistry() 
    183175            orngTabs.constructCategoriesPopup(self) 
    184176            self.createWidgetsToolbar() 
     
    225217                webbrowser.open("http://sourceforge.net/projects/numpy/") 
    226218 
     219    def updateWidgetRegistry(self): 
     220        """ Update the widget registry and add new category tabs to the 
     221        settings dict.   
     222        """ 
     223        # The default Widget tabs order 
     224        if not self.settings.has_key("WidgetTabs") or self.settings["WidgetTabs"] == []: 
     225            f = open(os.path.join(self.canvasDir, "WidgetTabs.txt"), "r") 
     226            defaultTabs = [c for c in [line.split("#")[0].strip() for line in f.readlines()] if c!=""] 
     227            for i in xrange(len(defaultTabs)-1,0,-1): 
     228                if defaultTabs[i] in defaultTabs[0:i]: 
     229                    del defaultTabs[i] 
     230            self.settings["WidgetTabs"] = [(name, Qt.Checked) for name in defaultTabs] + [("Prototypes", Qt.Unchecked)] 
     231             
     232        widgetTabList = self.settings["WidgetTabs"] 
     233        self.widgetRegistry = orngRegistry.readCategories() 
     234         
     235        extraTabs = [(name, 1) for name in self.widgetRegistry.keys() if name not in [tab for (tab, s) in widgetTabList]] 
     236        extraTabs = sorted(extraTabs) 
     237         
     238        # Keep Prototypes as last in list 
     239        if widgetTabList[-1][0] == "Prototypes": 
     240            widgetTabList = widgetTabList[: -1] + extraTabs + widgetTabList[-1 :] 
     241        else: 
     242            widgetTabList = widgetTabList + extraTabs 
     243        self.settings["WidgetTabs"] = widgetTabList 
     244             
    227245    def createWidgetsToolbar(self): 
    228246        if self.widgetsToolBar: 
     
    255273 
    256274        # find widgets and create tab with buttons 
    257         self.settings["WidgetTabs"] = self.tabs.createWidgetTabs(self.settings["WidgetTabs"], self.widgetRegistry, self.widgetDir, self.picsDir, self.defaultPic) 
     275        self.tabs.createWidgetTabs(self.settings["WidgetTabs"], self.widgetRegistry, self.widgetDir, self.picsDir, self.defaultPic) 
    258276        if not self.settings.get("showWidgetToolbar", True):  
    259277            self.widgetsToolBar.hide() 
    260  
    261278 
    262279    def readShortcuts(self): 
Note: See TracChangeset for help on using the changeset viewer.