eric7/VCS/StatusWidget.py

branch
eric7
changeset 8619
2dc55ddafc68
child 8620
84f7f7867b5f
equal deleted inserted replaced
8618:356a2f1b04b0 8619:2dc55ddafc68
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a VCS Status widget for the sidebar/toolbar.
8 """
9
10 from PyQt6.QtCore import pyqtSlot, Qt
11 from PyQt6.QtWidgets import (
12 QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QListView,
13 QListWidget, QListWidgetItem, QToolButton
14 )
15
16 import UI.PixmapCache
17
18
19 class StatusWidget(QWidget):
20 """
21 Class implementing a VCS Status widget for the sidebar/toolbox.
22 """
23 def __init__(self, project, parent=None):
24 """
25 Constructor
26
27 @param project reference to the project object
28 @type Project
29 @param parent reference to the parent widget (defaults to None)
30 @type QWidget (optional)
31 """
32 super().__init__(parent)
33 self.setObjectName("VcsStatusWidget")
34
35 self.__project = project
36
37 self.__layout = QVBoxLayout()
38 self.__layout.setObjectName("MainLayout")
39 self.__layout.setContentsMargins(0, 3, 0, 0)
40 self.__topLayout = QHBoxLayout()
41 self.__topLayout.setObjectName("topLayout")
42
43 # Create the top row
44 self.__infoLabel = QLabel(self)
45 self.__infoLabel.setSizePolicy(
46 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
47 self.__topLayout.addWidget(self.__infoLabel)
48
49 self.__reloadButton = QToolButton(self)
50 self.__reloadButton.setIcon(UI.PixmapCache.getIcon("reload"))
51 self.__reloadButton.clicked.connect(self.__reload)
52 self.__topLayout.addWidget(self.__reloadButton)
53
54 self.__layout.addLayout(self.__topLayout)
55
56 self.__statusList = QListWidget(self)
57 self.__statusList.setAlternatingRowColors(True)
58 self.__statusList.setSortingEnabled(True)
59 self.__statusList.setViewMode(QListView.ViewMode.ListMode)
60 self.__statusList.setTextElideMode(Qt.TextElideMode.ElideLeft)
61 self.__layout.addWidget(self.__statusList)
62
63 self.setLayout(self.__layout)
64
65 if self.__project.isOpen():
66 self.__projectOpened()
67 else:
68 self.__projectClosed()
69
70 self.__project.projectOpened.connect(self.__projectOpened)
71 self.__project.projectClosed.connect(self.__projectClosed)
72 self.__project.vcsStatusMonitorInfo.connect(self.__setInfoText)
73 self.__project.vcsStatusMonitorData.connect(self.__processStatusData)
74
75 @pyqtSlot()
76 def __projectOpened(self):
77 """
78 Private slot to handle the opening of a project.
79 """
80 self.__reloadButton.setEnabled(True)
81
82 @pyqtSlot()
83 def __projectClosed(self):
84 """
85 Private slot to handle the closing of a project.
86 """
87 self.__infoLabel.setText(self.tr("No project open."))
88
89 self.__reloadButton.setEnabled(False)
90
91 self.__statusList.clear()
92
93 @pyqtSlot(str)
94 def __setInfoText(self, info):
95 """
96 Private slot to set the info label text.
97
98 @param info text to be shown
99 @type str
100 """
101 self.__infoLabel.setText(info)
102
103 @pyqtSlot()
104 def __reload(self):
105 """
106 Private slot to reload the status list.
107 """
108 self.__project.checkVCSStatus()
109
110 @pyqtSlot(list)
111 def __processStatusData(self, data):
112 """
113 Private slot to process the status data emitted by the project.
114
115 Each entry of the status data consists of a status flag and and the
116 path relative to the project directory starting with the third column.
117 The known status flags are:
118 <ul>
119 <li>"A" path was added but not yet committed</li>
120 <li>"M" path has local changes</li>
121 <li>"O" path was removed</li>
122 <li>"R" path was deleted and then re-added</li>
123 <li>"U" path needs an update</li>
124 <li>"Z" path contains a conflict</li>
125 <li>" " path is back at normal</li>
126 </ul>
127
128 @param data list of VCS status data
129 @type list of str
130 """
131 self.__statusList.clear()
132
133 for entry in data:
134 QListWidgetItem(entry, self.__statusList)
135 self.__statusList.sortItems(Qt.SortOrder.AscendingOrder)

eric ide

mercurial