src/eric7/Plugins/VcsPlugins/vcsMercurial/HgBookmarksInOutDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
6 """ 6 """
7 Module implementing a dialog to show a list of incoming or outgoing bookmarks. 7 Module implementing a dialog to show a list of incoming or outgoing bookmarks.
8 """ 8 """
9 9
10 from PyQt6.QtCore import Qt, QCoreApplication 10 from PyQt6.QtCore import Qt, QCoreApplication
11 from PyQt6.QtWidgets import ( 11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem
12 QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem
13 )
14 12
15 from .Ui_HgBookmarksInOutDialog import Ui_HgBookmarksInOutDialog 13 from .Ui_HgBookmarksInOutDialog import Ui_HgBookmarksInOutDialog
16 14
17 15
18 class HgBookmarksInOutDialog(QDialog, Ui_HgBookmarksInOutDialog): 16 class HgBookmarksInOutDialog(QDialog, Ui_HgBookmarksInOutDialog):
19 """ 17 """
20 Class implementing a dialog to show a list of incoming or outgoing 18 Class implementing a dialog to show a list of incoming or outgoing
21 bookmarks. 19 bookmarks.
22 """ 20 """
21
23 INCOMING = 0 22 INCOMING = 0
24 OUTGOING = 1 23 OUTGOING = 1
25 24
26 def __init__(self, vcs, mode, parent=None): 25 def __init__(self, vcs, mode, parent=None):
27 """ 26 """
28 Constructor 27 Constructor
29 28
30 @param vcs reference to the vcs object 29 @param vcs reference to the vcs object
31 @param mode mode of the dialog (HgBookmarksInOutDialog.INCOMING, 30 @param mode mode of the dialog (HgBookmarksInOutDialog.INCOMING,
32 HgBookmarksInOutDialog.OUTGOING) 31 HgBookmarksInOutDialog.OUTGOING)
33 @param parent reference to the parent widget (QWidget) 32 @param parent reference to the parent widget (QWidget)
34 @exception ValueError raised to indicate an invalid dialog mode 33 @exception ValueError raised to indicate an invalid dialog mode
35 """ 34 """
36 super().__init__(parent) 35 super().__init__(parent)
37 self.setupUi(self) 36 self.setupUi(self)
38 self.setWindowFlags(Qt.WindowType.Window) 37 self.setWindowFlags(Qt.WindowType.Window)
39 38
40 self.buttonBox.button( 39 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False)
41 QDialogButtonBox.StandardButton.Close).setEnabled(False) 40 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True)
42 self.buttonBox.button( 41
43 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
44
45 if mode not in [self.INCOMING, self.OUTGOING]: 42 if mode not in [self.INCOMING, self.OUTGOING]:
46 raise ValueError("Bad value for mode") 43 raise ValueError("Bad value for mode")
47 if mode == self.INCOMING: 44 if mode == self.INCOMING:
48 self.setWindowTitle(self.tr("Mercurial Incoming Bookmarks")) 45 self.setWindowTitle(self.tr("Mercurial Incoming Bookmarks"))
49 elif mode == self.OUTGOING: 46 elif mode == self.OUTGOING:
50 self.setWindowTitle(self.tr("Mercurial Outgoing Bookmarks")) 47 self.setWindowTitle(self.tr("Mercurial Outgoing Bookmarks"))
51 48
52 self.vcs = vcs 49 self.vcs = vcs
53 self.mode = mode 50 self.mode = mode
54 self.__hgClient = vcs.getClient() 51 self.__hgClient = vcs.getClient()
55 52
56 self.bookmarksList.headerItem().setText( 53 self.bookmarksList.headerItem().setText(self.bookmarksList.columnCount(), "")
57 self.bookmarksList.columnCount(), "") 54 self.bookmarksList.header().setSortIndicator(3, Qt.SortOrder.AscendingOrder)
58 self.bookmarksList.header().setSortIndicator( 55
59 3, Qt.SortOrder.AscendingOrder)
60
61 self.show() 56 self.show()
62 QCoreApplication.processEvents() 57 QCoreApplication.processEvents()
63 58
64 def closeEvent(self, e): 59 def closeEvent(self, e):
65 """ 60 """
66 Protected slot implementing a close event handler. 61 Protected slot implementing a close event handler.
67 62
68 @param e close event (QCloseEvent) 63 @param e close event (QCloseEvent)
69 """ 64 """
70 if self.__hgClient.isExecuting(): 65 if self.__hgClient.isExecuting():
71 self.__hgClient.cancel() 66 self.__hgClient.cancel()
72 67
73 e.accept() 68 e.accept()
74 69
75 def start(self): 70 def start(self):
76 """ 71 """
77 Public slot to start the bookmarks command. 72 Public slot to start the bookmarks command.
78 73
79 @exception ValueError raised to indicate an invalid dialog mode 74 @exception ValueError raised to indicate an invalid dialog mode
80 """ 75 """
81 self.errorGroup.hide() 76 self.errorGroup.hide()
82 77
83 self.intercept = False 78 self.intercept = False
84 self.activateWindow() 79 self.activateWindow()
85 80
86 if self.mode not in (self.INCOMING, self.OUTGOING): 81 if self.mode not in (self.INCOMING, self.OUTGOING):
87 raise ValueError("Bad value for mode") 82 raise ValueError("Bad value for mode")
88 83
89 args = ( 84 args = (
90 self.vcs.initCommand("incoming") 85 self.vcs.initCommand("incoming")
91 if self.mode == self.INCOMING else 86 if self.mode == self.INCOMING
92 self.vcs.initCommand("outgoing") 87 else self.vcs.initCommand("outgoing")
93 ) 88 )
94 89
95 args.append('--bookmarks') 90 args.append("--bookmarks")
96 91
97 out, err = self.__hgClient.runcommand(args) 92 out, err = self.__hgClient.runcommand(args)
98 if err: 93 if err:
99 self.__showError(err) 94 self.__showError(err)
100 if out: 95 if out:
101 for line in out.splitlines(): 96 for line in out.splitlines():
102 self.__processOutputLine(line) 97 self.__processOutputLine(line)
103 if self.__hgClient.wasCanceled(): 98 if self.__hgClient.wasCanceled():
104 break 99 break
105 self.__finish() 100 self.__finish()
106 101
107 def __finish(self): 102 def __finish(self):
108 """ 103 """
109 Private slot called when the process finished or the user pressed 104 Private slot called when the process finished or the user pressed
110 the button. 105 the button.
111 """ 106 """
112 self.buttonBox.button( 107 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True)
113 QDialogButtonBox.StandardButton.Close).setEnabled(True) 108 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
114 self.buttonBox.button( 109 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
115 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) 110 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setFocus(
116 self.buttonBox.button( 111 Qt.FocusReason.OtherFocusReason
117 QDialogButtonBox.StandardButton.Close).setDefault(True) 112 )
118 self.buttonBox.button( 113
119 QDialogButtonBox.StandardButton.Close).setFocus(
120 Qt.FocusReason.OtherFocusReason)
121
122 if self.bookmarksList.topLevelItemCount() == 0: 114 if self.bookmarksList.topLevelItemCount() == 0:
123 # no bookmarks defined 115 # no bookmarks defined
124 self.__generateItem(self.tr("no bookmarks found"), "") 116 self.__generateItem(self.tr("no bookmarks found"), "")
125 self.__resizeColumns() 117 self.__resizeColumns()
126 self.__resort() 118 self.__resort()
127 119
128 def on_buttonBox_clicked(self, button): 120 def on_buttonBox_clicked(self, button):
129 """ 121 """
130 Private slot called by a button of the button box clicked. 122 Private slot called by a button of the button box clicked.
131 123
132 @param button button that was clicked (QAbstractButton) 124 @param button button that was clicked (QAbstractButton)
133 """ 125 """
134 if button == self.buttonBox.button( 126 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close):
135 QDialogButtonBox.StandardButton.Close
136 ):
137 self.close() 127 self.close()
138 elif button == self.buttonBox.button( 128 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel):
139 QDialogButtonBox.StandardButton.Cancel
140 ):
141 if self.__hgClient: 129 if self.__hgClient:
142 self.__hgClient.cancel() 130 self.__hgClient.cancel()
143 else: 131 else:
144 self.__finish() 132 self.__finish()
145 133
146 def __resort(self): 134 def __resort(self):
147 """ 135 """
148 Private method to resort the tree. 136 Private method to resort the tree.
149 """ 137 """
150 self.bookmarksList.sortItems( 138 self.bookmarksList.sortItems(
151 self.bookmarksList.sortColumn(), 139 self.bookmarksList.sortColumn(),
152 self.bookmarksList.header().sortIndicatorOrder()) 140 self.bookmarksList.header().sortIndicatorOrder(),
153 141 )
142
154 def __resizeColumns(self): 143 def __resizeColumns(self):
155 """ 144 """
156 Private method to resize the list columns. 145 Private method to resize the list columns.
157 """ 146 """
158 self.bookmarksList.header().resizeSections( 147 self.bookmarksList.header().resizeSections(
159 QHeaderView.ResizeMode.ResizeToContents) 148 QHeaderView.ResizeMode.ResizeToContents
149 )
160 self.bookmarksList.header().setStretchLastSection(True) 150 self.bookmarksList.header().setStretchLastSection(True)
161 151
162 def __generateItem(self, changeset, name): 152 def __generateItem(self, changeset, name):
163 """ 153 """
164 Private method to generate a bookmark item in the bookmarks list. 154 Private method to generate a bookmark item in the bookmarks list.
165 155
166 @param changeset changeset of the bookmark (string) 156 @param changeset changeset of the bookmark (string)
167 @param name name of the bookmark (string) 157 @param name name of the bookmark (string)
168 """ 158 """
169 QTreeWidgetItem(self.bookmarksList, [ 159 QTreeWidgetItem(self.bookmarksList, [name, changeset])
170 name, 160
171 changeset])
172
173 def __processOutputLine(self, line): 161 def __processOutputLine(self, line):
174 """ 162 """
175 Private method to process the lines of output. 163 Private method to process the lines of output.
176 164
177 @param line output line to be processed (string) 165 @param line output line to be processed (string)
178 """ 166 """
179 if line.startswith(" "): 167 if line.startswith(" "):
180 li = line.strip().split() 168 li = line.strip().split()
181 changeset = li[-1] 169 changeset = li[-1]
182 del li[-1] 170 del li[-1]
183 name = " ".join(li) 171 name = " ".join(li)
184 self.__generateItem(changeset, name) 172 self.__generateItem(changeset, name)
185 173
186 def __showError(self, out): 174 def __showError(self, out):
187 """ 175 """
188 Private slot to show some error. 176 Private slot to show some error.
189 177
190 @param out error to be shown (string) 178 @param out error to be shown (string)
191 """ 179 """
192 self.errorGroup.show() 180 self.errorGroup.show()
193 self.errors.insertPlainText(out) 181 self.errors.insertPlainText(out)
194 self.errors.ensureCursorVisible() 182 self.errors.ensureCursorVisible()

eric ide

mercurial