eric7/PluginManager/PluginRepositoryDialog.py

branch
eric7
changeset 8595
ce2034bc1c6e
parent 8586
6a315398a554
child 8597
57cdd880326b
diff -r f254ab0d42fa -r ce2034bc1c6e eric7/PluginManager/PluginRepositoryDialog.py
--- a/eric7/PluginManager/PluginRepositoryDialog.py	Sat Sep 11 19:59:21 2021 +0200
+++ b/eric7/PluginManager/PluginRepositoryDialog.py	Sun Sep 12 17:30:38 2021 +0200
@@ -19,7 +19,7 @@
 )
 from PyQt6.QtWidgets import (
     QWidget, QDialogButtonBox, QAbstractButton, QTreeWidgetItem, QDialog,
-    QVBoxLayout, QMenu
+    QVBoxLayout, QMenu, QLabel
 )
 from PyQt6.QtNetwork import (
     QNetworkAccessManager, QNetworkRequest, QNetworkReply, QNetworkInformation
@@ -69,12 +69,14 @@
     PluginStatusRemoteUpdate = 3
     PluginStatusError = 4
     
-    def __init__(self, pluginManager, parent=None):
+    def __init__(self, pluginManager, integrated=False, parent=None):
         """
         Constructor
         
         @param pluginManager reference to the plugin manager object
         @type PluginManager
+        @param integrated flag indicating the integration into the sidebar
+        @type bool
         @param parent parent of this dialog
         @type QWidget
         """
@@ -89,6 +91,7 @@
         else:
             self.__pluginManager = pluginManager
             self.__external = False
+        self.__integratedWidget = integrated
         
         self.__updateButton = self.buttonBox.addButton(
             self.tr("Update"), QDialogButtonBox.ButtonRole.ActionRole)
@@ -103,20 +106,25 @@
             self.tr("Cancel"), QDialogButtonBox.ButtonRole.ActionRole)
         self.__downloadCancelButton.setEnabled(False)
         self.__installButton = self.buttonBox.addButton(
+            self.tr("Install") if self.__integratedWidget else
             self.tr("Close && Install"),
             QDialogButtonBox.ButtonRole.ActionRole)
         self.__installButton.setEnabled(False)
-        self.__closeButton = self.buttonBox.button(
-            QDialogButtonBox.StandardButton.Close)
-        self.__closeButton.setEnabled(True)
+        if not self.__integratedWidget:
+            self.__closeButton = self.buttonBox.addButton(
+                self.tr("Close"), QDialogButtonBox.ButtonRole.RejectRole)
+            self.__closeButton.setEnabled(True)
         
         self.repositoryUrlEdit.setText(
             Preferences.getUI("PluginRepositoryUrl7"))
         
-        self.repositoryList.headerItem().setText(
-            self.repositoryList.columnCount(), "")
-        self.repositoryList.header().setSortIndicator(
-            0, Qt.SortOrder.AscendingOrder)
+        if self.__integratedWidget:
+            self.repositoryList.setHeaderHidden(True)
+        else:
+            self.repositoryList.headerItem().setText(
+                self.repositoryList.columnCount(), "")
+            self.repositoryList.header().setSortIndicator(
+                0, Qt.SortOrder.AscendingOrder)
         
         self.__pluginContextMenu = QMenu(self)
         self.__hideAct = self.__pluginContextMenu.addAction(
@@ -180,12 +188,13 @@
         self.__updateButton.setEnabled(online)
         self.on_repositoryList_itemSelectionChanged()
         
-        msg = (
-            self.tr("Internet Reachability Status: Reachable")
-            if online else
-            self.tr("Internet Reachability Status: Not Reachable")
-        )
-        self.statusLabel.setText(msg)
+        if not self.__integratedWidget:
+            msg = (
+                self.tr("Internet Reachability Status: Reachable")
+                if online else
+                self.tr("Internet Reachability Status: Not Reachable")
+            )
+            self.statusLabel.setText(msg)
     
     @pyqtSlot(QAbstractButton)
     def on_buttonBox_clicked(self, button):
@@ -195,7 +204,7 @@
         @param button reference to the button pressed (QAbstractButton)
         """
         if button == self.__updateButton:
-            self.__updateList()
+            self.updateList()
         elif button == self.__downloadButton:
             self.__isDownloadInstall = False
             self.__downloadPlugins()
@@ -306,9 +315,9 @@
         self.__downloadInstallButton.setEnabled(enable and self.__online)
         self.__installButton.setEnabled(enable)
     
-    def __updateList(self):
+    def updateList(self):
         """
-        Private slot to download a new list and display the contents.
+        Public slot to download a new list and display the contents.
         """
         url = self.repositoryUrlEdit.text()
         self.__downloadFile(url,
@@ -484,7 +493,8 @@
             self.__updateButton.setEnabled(False)
             self.__downloadButton.setEnabled(False)
             self.__downloadInstallButton.setEnabled(False)
-            self.__closeButton.setEnabled(False)
+            if not self.__integratedWidget:
+                self.__closeButton.setEnabled(False)
             self.__downloadCancelButton.setEnabled(True)
             
             self.statusLabel.setText(url)
@@ -520,7 +530,8 @@
         @type func
         """
         self.__updateButton.setEnabled(True)
-        self.__closeButton.setEnabled(True)
+        if not self.__integratedWidget:
+            self.__closeButton.setEnabled(True)
         self.__downloadCancelButton.setEnabled(False)
         
         ok = True
@@ -637,32 +648,41 @@
                     self.repositoryList, [self.tr("Unknown")])
                 self.__unknownItem.setExpanded(True)
             parent = self.__unknownItem
-        itm = QTreeWidgetItem(parent, [name, version, short])
+        
+        if self.__integratedWidget:
+            entryFormat = "<b>{0}</b> - Version: <i>{1}</i><br/>{2}"
+            itm = QTreeWidgetItem(parent)
+            itm.setFirstColumnSpanned(True)
+            label = QLabel(entryFormat.format(name, version, short))
+            self.repositoryList.setItemWidget(itm, 0, label)
+        else:
+            itm = QTreeWidgetItem(parent, [name, version, short])
         
         itm.setData(0, PluginRepositoryWidget.UrlRole, url)
         itm.setData(0, PluginRepositoryWidget.FilenameRole, filename)
         itm.setData(0, PluginRepositoryWidget.AuthorRole, author)
         itm.setData(0, PluginRepositoryWidget.DescrRole, description)
         
+        iconColumn = 0 if self.__integratedWidget else 1
         updateStatus = self.__updateStatus(filename, version)
         if updateStatus == PluginRepositoryWidget.PluginStatusUpToDate:
-            itm.setIcon(1, UI.PixmapCache.getIcon("empty"))
-            itm.setToolTip(1, self.tr("up-to-date"))
+            itm.setIcon(iconColumn, UI.PixmapCache.getIcon("empty"))
+            itm.setToolTip(iconColumn, self.tr("up-to-date"))
         elif updateStatus == PluginRepositoryWidget.PluginStatusNew:
-            itm.setIcon(1, UI.PixmapCache.getIcon("download"))
-            itm.setToolTip(1, self.tr("new download available"))
+            itm.setIcon(iconColumn, UI.PixmapCache.getIcon("download"))
+            itm.setToolTip(iconColumn, self.tr("new download available"))
             self.__newItems += 1
         elif updateStatus == PluginRepositoryWidget.PluginStatusLocalUpdate:
-            itm.setIcon(1, UI.PixmapCache.getIcon("updateLocal"))
-            itm.setToolTip(1, self.tr("update installable"))
+            itm.setIcon(iconColumn, UI.PixmapCache.getIcon("updateLocal"))
+            itm.setToolTip(iconColumn, self.tr("update installable"))
             self.__updateLocalItems += 1
         elif updateStatus == PluginRepositoryWidget.PluginStatusRemoteUpdate:
-            itm.setIcon(1, UI.PixmapCache.getIcon("updateRemote"))
-            itm.setToolTip(1, self.tr("updated download available"))
+            itm.setIcon(iconColumn, UI.PixmapCache.getIcon("updateRemote"))
+            itm.setToolTip(iconColumn, self.tr("updated download available"))
             self.__updateRemoteItems += 1
         elif updateStatus == PluginRepositoryWidget.PluginStatusError:
-            itm.setIcon(1, UI.PixmapCache.getIcon("warning"))
-            itm.setToolTip(1, self.tr("error determining status"))
+            itm.setIcon(iconColumn, UI.PixmapCache.getIcon("warning"))
+            itm.setToolTip(iconColumn, self.tr("error determining status"))
     
     def __updateStatus(self, filename, version):
         """
@@ -846,7 +866,7 @@
         self.__layout.setContentsMargins(0, 0, 0, 0)
         self.setLayout(self.__layout)
         
-        self.cw = PluginRepositoryWidget(pluginManager, self)
+        self.cw = PluginRepositoryWidget(pluginManager, parent=self)
         size = self.cw.size()
         self.__layout.addWidget(self.cw)
         self.resize(size)
@@ -882,7 +902,7 @@
         @param parent reference to the parent widget (QWidget)
         """
         super().__init__(parent)
-        self.cw = PluginRepositoryWidget(None, self)
+        self.cw = PluginRepositoryWidget(None, parent=self)
         size = self.cw.size()
         self.setCentralWidget(self.cw)
         self.resize(size)

eric ide

mercurial