eric7/PluginManager/PluginRepositoryDialog.py

branch
eric7
changeset 8595
ce2034bc1c6e
parent 8586
6a315398a554
child 8597
57cdd880326b
equal deleted inserted replaced
8594:f254ab0d42fa 8595:ce2034bc1c6e
17 pyqtSignal, pyqtSlot, Qt, QFile, QIODevice, QUrl, QProcess, QPoint, 17 pyqtSignal, pyqtSlot, Qt, QFile, QIODevice, QUrl, QProcess, QPoint,
18 QCoreApplication 18 QCoreApplication
19 ) 19 )
20 from PyQt6.QtWidgets import ( 20 from PyQt6.QtWidgets import (
21 QWidget, QDialogButtonBox, QAbstractButton, QTreeWidgetItem, QDialog, 21 QWidget, QDialogButtonBox, QAbstractButton, QTreeWidgetItem, QDialog,
22 QVBoxLayout, QMenu 22 QVBoxLayout, QMenu, QLabel
23 ) 23 )
24 from PyQt6.QtNetwork import ( 24 from PyQt6.QtNetwork import (
25 QNetworkAccessManager, QNetworkRequest, QNetworkReply, QNetworkInformation 25 QNetworkAccessManager, QNetworkRequest, QNetworkReply, QNetworkInformation
26 ) 26 )
27 27
67 PluginStatusNew = 1 67 PluginStatusNew = 1
68 PluginStatusLocalUpdate = 2 68 PluginStatusLocalUpdate = 2
69 PluginStatusRemoteUpdate = 3 69 PluginStatusRemoteUpdate = 3
70 PluginStatusError = 4 70 PluginStatusError = 4
71 71
72 def __init__(self, pluginManager, parent=None): 72 def __init__(self, pluginManager, integrated=False, parent=None):
73 """ 73 """
74 Constructor 74 Constructor
75 75
76 @param pluginManager reference to the plugin manager object 76 @param pluginManager reference to the plugin manager object
77 @type PluginManager 77 @type PluginManager
78 @param integrated flag indicating the integration into the sidebar
79 @type bool
78 @param parent parent of this dialog 80 @param parent parent of this dialog
79 @type QWidget 81 @type QWidget
80 """ 82 """
81 super().__init__(parent) 83 super().__init__(parent)
82 self.setupUi(self) 84 self.setupUi(self)
87 self.__pluginManager = PluginManager() 89 self.__pluginManager = PluginManager()
88 self.__external = True 90 self.__external = True
89 else: 91 else:
90 self.__pluginManager = pluginManager 92 self.__pluginManager = pluginManager
91 self.__external = False 93 self.__external = False
94 self.__integratedWidget = integrated
92 95
93 self.__updateButton = self.buttonBox.addButton( 96 self.__updateButton = self.buttonBox.addButton(
94 self.tr("Update"), QDialogButtonBox.ButtonRole.ActionRole) 97 self.tr("Update"), QDialogButtonBox.ButtonRole.ActionRole)
95 self.__downloadButton = self.buttonBox.addButton( 98 self.__downloadButton = self.buttonBox.addButton(
96 self.tr("Download"), QDialogButtonBox.ButtonRole.ActionRole) 99 self.tr("Download"), QDialogButtonBox.ButtonRole.ActionRole)
101 self.__downloadInstallButton.setEnabled(False) 104 self.__downloadInstallButton.setEnabled(False)
102 self.__downloadCancelButton = self.buttonBox.addButton( 105 self.__downloadCancelButton = self.buttonBox.addButton(
103 self.tr("Cancel"), QDialogButtonBox.ButtonRole.ActionRole) 106 self.tr("Cancel"), QDialogButtonBox.ButtonRole.ActionRole)
104 self.__downloadCancelButton.setEnabled(False) 107 self.__downloadCancelButton.setEnabled(False)
105 self.__installButton = self.buttonBox.addButton( 108 self.__installButton = self.buttonBox.addButton(
109 self.tr("Install") if self.__integratedWidget else
106 self.tr("Close && Install"), 110 self.tr("Close && Install"),
107 QDialogButtonBox.ButtonRole.ActionRole) 111 QDialogButtonBox.ButtonRole.ActionRole)
108 self.__installButton.setEnabled(False) 112 self.__installButton.setEnabled(False)
109 self.__closeButton = self.buttonBox.button( 113 if not self.__integratedWidget:
110 QDialogButtonBox.StandardButton.Close) 114 self.__closeButton = self.buttonBox.addButton(
111 self.__closeButton.setEnabled(True) 115 self.tr("Close"), QDialogButtonBox.ButtonRole.RejectRole)
116 self.__closeButton.setEnabled(True)
112 117
113 self.repositoryUrlEdit.setText( 118 self.repositoryUrlEdit.setText(
114 Preferences.getUI("PluginRepositoryUrl7")) 119 Preferences.getUI("PluginRepositoryUrl7"))
115 120
116 self.repositoryList.headerItem().setText( 121 if self.__integratedWidget:
117 self.repositoryList.columnCount(), "") 122 self.repositoryList.setHeaderHidden(True)
118 self.repositoryList.header().setSortIndicator( 123 else:
119 0, Qt.SortOrder.AscendingOrder) 124 self.repositoryList.headerItem().setText(
125 self.repositoryList.columnCount(), "")
126 self.repositoryList.header().setSortIndicator(
127 0, Qt.SortOrder.AscendingOrder)
120 128
121 self.__pluginContextMenu = QMenu(self) 129 self.__pluginContextMenu = QMenu(self)
122 self.__hideAct = self.__pluginContextMenu.addAction( 130 self.__hideAct = self.__pluginContextMenu.addAction(
123 self.tr("Hide"), self.__hidePlugin) 131 self.tr("Hide"), self.__hidePlugin)
124 self.__hideSelectedAct = self.__pluginContextMenu.addAction( 132 self.__hideSelectedAct = self.__pluginContextMenu.addAction(
178 self.__online = online 186 self.__online = online
179 187
180 self.__updateButton.setEnabled(online) 188 self.__updateButton.setEnabled(online)
181 self.on_repositoryList_itemSelectionChanged() 189 self.on_repositoryList_itemSelectionChanged()
182 190
183 msg = ( 191 if not self.__integratedWidget:
184 self.tr("Internet Reachability Status: Reachable") 192 msg = (
185 if online else 193 self.tr("Internet Reachability Status: Reachable")
186 self.tr("Internet Reachability Status: Not Reachable") 194 if online else
187 ) 195 self.tr("Internet Reachability Status: Not Reachable")
188 self.statusLabel.setText(msg) 196 )
197 self.statusLabel.setText(msg)
189 198
190 @pyqtSlot(QAbstractButton) 199 @pyqtSlot(QAbstractButton)
191 def on_buttonBox_clicked(self, button): 200 def on_buttonBox_clicked(self, button):
192 """ 201 """
193 Private slot to handle the click of a button of the button box. 202 Private slot to handle the click of a button of the button box.
194 203
195 @param button reference to the button pressed (QAbstractButton) 204 @param button reference to the button pressed (QAbstractButton)
196 """ 205 """
197 if button == self.__updateButton: 206 if button == self.__updateButton:
198 self.__updateList() 207 self.updateList()
199 elif button == self.__downloadButton: 208 elif button == self.__downloadButton:
200 self.__isDownloadInstall = False 209 self.__isDownloadInstall = False
201 self.__downloadPlugins() 210 self.__downloadPlugins()
202 elif button == self.__downloadInstallButton: 211 elif button == self.__downloadInstallButton:
203 self.__isDownloadInstall = True 212 self.__isDownloadInstall = True
304 enable = bool(self.__selectedItems()) 313 enable = bool(self.__selectedItems())
305 self.__downloadButton.setEnabled(enable and self.__online) 314 self.__downloadButton.setEnabled(enable and self.__online)
306 self.__downloadInstallButton.setEnabled(enable and self.__online) 315 self.__downloadInstallButton.setEnabled(enable and self.__online)
307 self.__installButton.setEnabled(enable) 316 self.__installButton.setEnabled(enable)
308 317
309 def __updateList(self): 318 def updateList(self):
310 """ 319 """
311 Private slot to download a new list and display the contents. 320 Public slot to download a new list and display the contents.
312 """ 321 """
313 url = self.repositoryUrlEdit.text() 322 url = self.repositoryUrlEdit.text()
314 self.__downloadFile(url, 323 self.__downloadFile(url,
315 self.pluginRepositoryFile, 324 self.pluginRepositoryFile,
316 self.__downloadRepositoryFileDone) 325 self.__downloadRepositoryFileDone)
482 """ 491 """
483 if self.__online: 492 if self.__online:
484 self.__updateButton.setEnabled(False) 493 self.__updateButton.setEnabled(False)
485 self.__downloadButton.setEnabled(False) 494 self.__downloadButton.setEnabled(False)
486 self.__downloadInstallButton.setEnabled(False) 495 self.__downloadInstallButton.setEnabled(False)
487 self.__closeButton.setEnabled(False) 496 if not self.__integratedWidget:
497 self.__closeButton.setEnabled(False)
488 self.__downloadCancelButton.setEnabled(True) 498 self.__downloadCancelButton.setEnabled(True)
489 499
490 self.statusLabel.setText(url) 500 self.statusLabel.setText(url)
491 501
492 request = QNetworkRequest(QUrl(url)) 502 request = QNetworkRequest(QUrl(url))
518 @type str 528 @type str
519 @param doneMethod method to be called when done 529 @param doneMethod method to be called when done
520 @type func 530 @type func
521 """ 531 """
522 self.__updateButton.setEnabled(True) 532 self.__updateButton.setEnabled(True)
523 self.__closeButton.setEnabled(True) 533 if not self.__integratedWidget:
534 self.__closeButton.setEnabled(True)
524 self.__downloadCancelButton.setEnabled(False) 535 self.__downloadCancelButton.setEnabled(False)
525 536
526 ok = True 537 ok = True
527 if reply in self.__replies: 538 if reply in self.__replies:
528 self.__replies.remove(reply) 539 self.__replies.remove(reply)
635 if self.__unknownItem is None: 646 if self.__unknownItem is None:
636 self.__unknownItem = QTreeWidgetItem( 647 self.__unknownItem = QTreeWidgetItem(
637 self.repositoryList, [self.tr("Unknown")]) 648 self.repositoryList, [self.tr("Unknown")])
638 self.__unknownItem.setExpanded(True) 649 self.__unknownItem.setExpanded(True)
639 parent = self.__unknownItem 650 parent = self.__unknownItem
640 itm = QTreeWidgetItem(parent, [name, version, short]) 651
652 if self.__integratedWidget:
653 entryFormat = "<b>{0}</b> - Version: <i>{1}</i><br/>{2}"
654 itm = QTreeWidgetItem(parent)
655 itm.setFirstColumnSpanned(True)
656 label = QLabel(entryFormat.format(name, version, short))
657 self.repositoryList.setItemWidget(itm, 0, label)
658 else:
659 itm = QTreeWidgetItem(parent, [name, version, short])
641 660
642 itm.setData(0, PluginRepositoryWidget.UrlRole, url) 661 itm.setData(0, PluginRepositoryWidget.UrlRole, url)
643 itm.setData(0, PluginRepositoryWidget.FilenameRole, filename) 662 itm.setData(0, PluginRepositoryWidget.FilenameRole, filename)
644 itm.setData(0, PluginRepositoryWidget.AuthorRole, author) 663 itm.setData(0, PluginRepositoryWidget.AuthorRole, author)
645 itm.setData(0, PluginRepositoryWidget.DescrRole, description) 664 itm.setData(0, PluginRepositoryWidget.DescrRole, description)
646 665
666 iconColumn = 0 if self.__integratedWidget else 1
647 updateStatus = self.__updateStatus(filename, version) 667 updateStatus = self.__updateStatus(filename, version)
648 if updateStatus == PluginRepositoryWidget.PluginStatusUpToDate: 668 if updateStatus == PluginRepositoryWidget.PluginStatusUpToDate:
649 itm.setIcon(1, UI.PixmapCache.getIcon("empty")) 669 itm.setIcon(iconColumn, UI.PixmapCache.getIcon("empty"))
650 itm.setToolTip(1, self.tr("up-to-date")) 670 itm.setToolTip(iconColumn, self.tr("up-to-date"))
651 elif updateStatus == PluginRepositoryWidget.PluginStatusNew: 671 elif updateStatus == PluginRepositoryWidget.PluginStatusNew:
652 itm.setIcon(1, UI.PixmapCache.getIcon("download")) 672 itm.setIcon(iconColumn, UI.PixmapCache.getIcon("download"))
653 itm.setToolTip(1, self.tr("new download available")) 673 itm.setToolTip(iconColumn, self.tr("new download available"))
654 self.__newItems += 1 674 self.__newItems += 1
655 elif updateStatus == PluginRepositoryWidget.PluginStatusLocalUpdate: 675 elif updateStatus == PluginRepositoryWidget.PluginStatusLocalUpdate:
656 itm.setIcon(1, UI.PixmapCache.getIcon("updateLocal")) 676 itm.setIcon(iconColumn, UI.PixmapCache.getIcon("updateLocal"))
657 itm.setToolTip(1, self.tr("update installable")) 677 itm.setToolTip(iconColumn, self.tr("update installable"))
658 self.__updateLocalItems += 1 678 self.__updateLocalItems += 1
659 elif updateStatus == PluginRepositoryWidget.PluginStatusRemoteUpdate: 679 elif updateStatus == PluginRepositoryWidget.PluginStatusRemoteUpdate:
660 itm.setIcon(1, UI.PixmapCache.getIcon("updateRemote")) 680 itm.setIcon(iconColumn, UI.PixmapCache.getIcon("updateRemote"))
661 itm.setToolTip(1, self.tr("updated download available")) 681 itm.setToolTip(iconColumn, self.tr("updated download available"))
662 self.__updateRemoteItems += 1 682 self.__updateRemoteItems += 1
663 elif updateStatus == PluginRepositoryWidget.PluginStatusError: 683 elif updateStatus == PluginRepositoryWidget.PluginStatusError:
664 itm.setIcon(1, UI.PixmapCache.getIcon("warning")) 684 itm.setIcon(iconColumn, UI.PixmapCache.getIcon("warning"))
665 itm.setToolTip(1, self.tr("error determining status")) 685 itm.setToolTip(iconColumn, self.tr("error determining status"))
666 686
667 def __updateStatus(self, filename, version): 687 def __updateStatus(self, filename, version):
668 """ 688 """
669 Private method to check the given archive update status. 689 Private method to check the given archive update status.
670 690
844 864
845 self.__layout = QVBoxLayout(self) 865 self.__layout = QVBoxLayout(self)
846 self.__layout.setContentsMargins(0, 0, 0, 0) 866 self.__layout.setContentsMargins(0, 0, 0, 0)
847 self.setLayout(self.__layout) 867 self.setLayout(self.__layout)
848 868
849 self.cw = PluginRepositoryWidget(pluginManager, self) 869 self.cw = PluginRepositoryWidget(pluginManager, parent=self)
850 size = self.cw.size() 870 size = self.cw.size()
851 self.__layout.addWidget(self.cw) 871 self.__layout.addWidget(self.cw)
852 self.resize(size) 872 self.resize(size)
853 self.setWindowTitle(self.cw.windowTitle()) 873 self.setWindowTitle(self.cw.windowTitle())
854 874
880 Constructor 900 Constructor
881 901
882 @param parent reference to the parent widget (QWidget) 902 @param parent reference to the parent widget (QWidget)
883 """ 903 """
884 super().__init__(parent) 904 super().__init__(parent)
885 self.cw = PluginRepositoryWidget(None, self) 905 self.cw = PluginRepositoryWidget(None, parent=self)
886 size = self.cw.size() 906 size = self.cw.size()
887 self.setCentralWidget(self.cw) 907 self.setCentralWidget(self.cw)
888 self.resize(size) 908 self.resize(size)
889 self.setWindowTitle(self.cw.windowTitle()) 909 self.setWindowTitle(self.cw.windowTitle())
890 910

eric ide

mercurial