Commits

Marko Toplak committed 69e2cda

Add-on update interface available from the new canvas.

Comments (0)

Files changed (3)

Orange/OrangeCanvas/application/addons.py

+#until we support the new interface only add-ons should have common dialogs
+
+from Orange.OrangeCanvas.orngDlgs import AddOnManagerDialog

Orange/OrangeCanvas/application/canvasmain.py

 
 import pkg_resources
 
+import Orange.utils.addons
+
 from PyQt4.QtGui import (
     QMainWindow, QWidget, QAction, QActionGroup, QMenu, QMenuBar, QDialog,
     QFileDialog, QMessageBox, QVBoxLayout, QSizePolicy, QColor, QKeySequence,
 from .schemeinfo import SchemeInfoDialog
 from .outputview import OutputView
 from .settings import UserSettingsDialog
+from .addons import AddOnManagerDialog
+
 from ..document.schemeedit import SchemeEditWidget
 
 from ..scheme import widgetsscheme
                        [self.freeze_action,
                         self.dock_help_action]
 
+
+        def addOnRefreshCallback():
+            pass #TODO add new category
+
+        Orange.utils.addons.addon_refresh_callback.append(addOnRefreshCallback)
+
         # Tool bar in the collapsed dock state (has the same actions as
         # the tool bar in the CanvasToolDock
         actions_toolbar = QToolBar(orientation=Qt.Vertical)
                     shortcut=QKeySequence.Preferences
                     )
 
+        self.canvas_addons_action = \
+            QAction(self.tr("&Add-ons..."), self,
+                    objectName="canvas-addons-action",
+                    toolTip=self.tr("Manage add-ons."),
+                    triggered=self.open_addons,
+                    menuRole=QAction.PreferencesRole
+                    )
+
+
         self.show_output_action = \
             QAction(self.tr("Show Output View"), self,
                     toolTip=self.tr("Show application output."),
 #        self.options_menu.addAction("Attach Python Console")
         self.options_menu.addSeparator()
         self.options_menu.addAction(self.canvas_settings_action)
+        self.options_menu.addAction(self.canvas_addons_action)
 
         # Widget menu
         menu_bar.addMenu(self.widget_menu)
         if status == 0:
             self.__update_from_settings()
 
+    def open_addons(self):
+
+        def getlr():
+            settings = QSettings()
+            settings.beginGroup("addons")
+            lastRefresh = settings.value("addons-last-refresh",
+                          defaultValue=0, type=int)
+            settings.endGroup()
+            return lastRefresh
+        
+        def setlr(v):
+            settings = QSettings()
+            settings.beginGroup("addons")
+            lastRefresh = settings.setValue("addons-last-refresh", int(v))
+            settings.endGroup()
+            
+        dlg = AddOnManagerDialog(self, self)
+        dlg.loadtimefn = getlr
+        dlg.savetimefn = setlr
+        dlg.show()
+        dlg.reloadQ()
+        status = dlg.exec_()
+
     def show_output_view(self):
         """Show a window with application output.
         """

Orange/OrangeCanvas/orngDlgs.py

 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 from orngCanvasItems import MyCanvasText
+import time
 
 import OWGUI
+import Orange.utils.addons
 
 has_pip = True
 try:
         self.topLayout.setSpacing(0)
         self.resize(600,500)
         self.layout().setSizeConstraint(QLayout.SetMinimumSize)
+        self.savetimefn = None
+        self.loadtimefn = None
         
         mainBox = OWGUI.widgetBox(self, orientation="vertical", sizePolicy=QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
         
         QObject.connect(lst, SIGNAL("itemChanged(QListWidgetItem *)"), self.cbToggled)
         QObject.connect(lst, SIGNAL("currentItemChanged(QListWidgetItem *, QListWidgetItem *)"), self.currentItemChanged)
 
-        import Orange.utils.addons
-
         # Bottom info pane
         
         self.infoPane = infoPane = OWGUI.widgetBox(mainBox, orientation="vertical", sizePolicy=QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored))
     
     def accept(self):
         self.to_upgrade.difference_update(self.to_remove())
-        import Orange.utils.addons
         add, remove, upgrade = self.to_install(), self.to_remove(), self.to_upgrade
         if len(add) + len(remove) + len(upgrade) > 0:
             summary = AddOnManagerSummary(add, remove, upgrade, self)
 
     def reloadRepo(self):
         # Reload add-on list.
-        import Orange.utils.addons
         try:
             self.busy("Reloading add-on repository ...")
             self.repaint()
             Orange.utils.addons.refresh_available_addons(progress_callback = self.pcb)
+            if self.savetimefn:
+                self.savetimefn(int(time.time()))
         except Exception, e:
             QMessageBox.critical(self, "Error", "Could not reload repository: %s." % e)
         finally:
             self.busy(False)
         # Finally, refresh the tree on GUI.
         self.refreshView()
+
+    def reloadQ(self):
+        #ask the user if he would like to reload the repository
+        lastRefresh = 0
+        if self.loadtimefn:
+            lastRefresh = self.loadtimefn()
+        t = time.time()
+        if t - lastRefresh > 7*24*3600 or Orange.utils.addons.addons_corrupted:
+            if Orange.utils.addons.addons_corrupted or \
+               QMessageBox.question(self, "Refresh",
+                                    "List of available add-ons has not been refreshed for more than a week. Do you want to download the list now?",
+                                     QMessageBox.Yes | QMessageBox.Default,
+                                     QMessageBox.No | QMessageBox.Escape) == QMessageBox.Yes:
+                self.reloadRepo()
             
     def upgradeCandidates(self):
         result = []