eric7/VCS/StatusWidget.py

branch
eric7
changeset 8619
2dc55ddafc68
child 8620
84f7f7867b5f
diff -r 356a2f1b04b0 -r 2dc55ddafc68 eric7/VCS/StatusWidget.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric7/VCS/StatusWidget.py	Mon Sep 20 07:29:27 2021 +0200
@@ -0,0 +1,135 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a VCS Status widget for the sidebar/toolbar.
+"""
+
+from PyQt6.QtCore import pyqtSlot, Qt
+from PyQt6.QtWidgets import (
+    QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QListView,
+    QListWidget, QListWidgetItem, QToolButton
+)
+
+import UI.PixmapCache
+
+
+class StatusWidget(QWidget):
+    """
+    Class implementing a VCS Status widget for the sidebar/toolbox.
+    """
+    def __init__(self, project, parent=None):
+        """
+        Constructor
+        
+        @param project reference to the project object
+        @type Project
+        @param parent reference to the parent widget (defaults to None)
+        @type QWidget (optional)
+        """
+        super().__init__(parent)
+        self.setObjectName("VcsStatusWidget")
+        
+        self.__project = project
+        
+        self.__layout = QVBoxLayout()
+        self.__layout.setObjectName("MainLayout")
+        self.__layout.setContentsMargins(0, 3, 0, 0)
+        self.__topLayout = QHBoxLayout()
+        self.__topLayout.setObjectName("topLayout")
+        
+        # Create the top row
+        self.__infoLabel = QLabel(self)
+        self.__infoLabel.setSizePolicy(
+            QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
+        self.__topLayout.addWidget(self.__infoLabel)
+        
+        self.__reloadButton = QToolButton(self)
+        self.__reloadButton.setIcon(UI.PixmapCache.getIcon("reload"))
+        self.__reloadButton.clicked.connect(self.__reload)
+        self.__topLayout.addWidget(self.__reloadButton)
+        
+        self.__layout.addLayout(self.__topLayout)
+        
+        self.__statusList = QListWidget(self)
+        self.__statusList.setAlternatingRowColors(True)
+        self.__statusList.setSortingEnabled(True)
+        self.__statusList.setViewMode(QListView.ViewMode.ListMode)
+        self.__statusList.setTextElideMode(Qt.TextElideMode.ElideLeft)
+        self.__layout.addWidget(self.__statusList)
+        
+        self.setLayout(self.__layout)
+        
+        if self.__project.isOpen():
+            self.__projectOpened()
+        else:
+            self.__projectClosed()
+        
+        self.__project.projectOpened.connect(self.__projectOpened)
+        self.__project.projectClosed.connect(self.__projectClosed)
+        self.__project.vcsStatusMonitorInfo.connect(self.__setInfoText)
+        self.__project.vcsStatusMonitorData.connect(self.__processStatusData)
+    
+    @pyqtSlot()
+    def __projectOpened(self):
+        """
+        Private slot to handle the opening of a project.
+        """
+        self.__reloadButton.setEnabled(True)
+    
+    @pyqtSlot()
+    def __projectClosed(self):
+        """
+        Private slot to handle the closing of a project.
+        """
+        self.__infoLabel.setText(self.tr("No project open."))
+        
+        self.__reloadButton.setEnabled(False)
+        
+        self.__statusList.clear()
+    
+    @pyqtSlot(str)
+    def __setInfoText(self, info):
+        """
+        Private slot to set the info label text.
+        
+        @param info text to be shown
+        @type str
+        """
+        self.__infoLabel.setText(info)
+    
+    @pyqtSlot()
+    def __reload(self):
+        """
+        Private slot to reload the status list.
+        """
+        self.__project.checkVCSStatus()
+    
+    @pyqtSlot(list)
+    def __processStatusData(self, data):
+        """
+        Private slot to process the status data emitted by the project.
+        
+        Each entry of the status data consists of a status flag and and the
+        path relative to the project directory starting with the third column.
+        The known status flags are:
+        <ul>
+            <li>"A" path was added but not yet committed</li>
+            <li>"M" path has local changes</li>
+            <li>"O" path was removed</li>
+            <li>"R" path was deleted and then re-added</li>
+            <li>"U" path needs an update</li>
+            <li>"Z" path contains a conflict</li>
+            <li>" " path is back at normal</li>
+        </ul>
+        
+        @param data list of VCS status data
+        @type list of str
+        """
+        self.__statusList.clear()
+        
+        for entry in data:
+            QListWidgetItem(entry, self.__statusList)
+        self.__statusList.sortItems(Qt.SortOrder.AscendingOrder)

eric ide

mercurial