src/eric7/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesQueueManagementDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
7 Module implementing a dialog used by the queue management functions. 7 Module implementing a dialog used by the queue management functions.
8 """ 8 """
9 9
10 from PyQt6.QtCore import pyqtSlot, Qt, QCoreApplication 10 from PyQt6.QtCore import pyqtSlot, Qt, QCoreApplication
11 from PyQt6.QtWidgets import ( 11 from PyQt6.QtWidgets import (
12 QDialog, QDialogButtonBox, QAbstractItemView, QListWidgetItem, 12 QDialog,
13 QAbstractButton 13 QDialogButtonBox,
14 QAbstractItemView,
15 QListWidgetItem,
16 QAbstractButton,
14 ) 17 )
15 18
16 from .Ui_HgQueuesQueueManagementDialog import Ui_HgQueuesQueueManagementDialog 19 from .Ui_HgQueuesQueueManagementDialog import Ui_HgQueuesQueueManagementDialog
17 20
18 21
19 class HgQueuesQueueManagementDialog(QDialog, Ui_HgQueuesQueueManagementDialog): 22 class HgQueuesQueueManagementDialog(QDialog, Ui_HgQueuesQueueManagementDialog):
20 """ 23 """
21 Class implementing a dialog used by the queue management functions. 24 Class implementing a dialog used by the queue management functions.
22 """ 25 """
26
23 NO_INPUT = 0 27 NO_INPUT = 0
24 NAME_INPUT = 1 28 NAME_INPUT = 1
25 QUEUE_INPUT = 2 29 QUEUE_INPUT = 2
26 30
27 def __init__(self, mode, title, suppressActive, vcs, parent=None): 31 def __init__(self, mode, title, suppressActive, vcs, parent=None):
28 """ 32 """
29 Constructor 33 Constructor
30 34
31 @param mode mode of the dialog (HgQueuesQueueManagementDialog.NO_INPUT 35 @param mode mode of the dialog (HgQueuesQueueManagementDialog.NO_INPUT
32 HgQueuesQueueManagementDialog.NAME_INPUT, 36 HgQueuesQueueManagementDialog.NAME_INPUT,
33 HgQueuesQueueManagementDialog.QUEUE_INPUT) 37 HgQueuesQueueManagementDialog.QUEUE_INPUT)
34 @param title title for the dialog (string) 38 @param title title for the dialog (string)
35 @param suppressActive flag indicating to not show the name of the 39 @param suppressActive flag indicating to not show the name of the
39 @exception ValueError raised to indicate an invalid dialog mode 43 @exception ValueError raised to indicate an invalid dialog mode
40 """ 44 """
41 super().__init__(parent) 45 super().__init__(parent)
42 self.setupUi(self) 46 self.setupUi(self)
43 self.setWindowFlags(Qt.WindowType.Window) 47 self.setWindowFlags(Qt.WindowType.Window)
44 48
45 if mode not in (HgQueuesQueueManagementDialog.NO_INPUT, 49 if mode not in (
46 HgQueuesQueueManagementDialog.NAME_INPUT, 50 HgQueuesQueueManagementDialog.NO_INPUT,
47 HgQueuesQueueManagementDialog.QUEUE_INPUT): 51 HgQueuesQueueManagementDialog.NAME_INPUT,
52 HgQueuesQueueManagementDialog.QUEUE_INPUT,
53 ):
48 raise ValueError("illegal value for mode") 54 raise ValueError("illegal value for mode")
49 55
50 self.__mode = mode 56 self.__mode = mode
51 self.__suppressActive = suppressActive 57 self.__suppressActive = suppressActive
52 self.__hgClient = vcs.getClient() 58 self.__hgClient = vcs.getClient()
53 self.vcs = vcs 59 self.vcs = vcs
54 60
55 self.inputFrame.setHidden( 61 self.inputFrame.setHidden(mode != HgQueuesQueueManagementDialog.NAME_INPUT)
56 mode != HgQueuesQueueManagementDialog.NAME_INPUT) 62 self.selectLabel.setHidden(mode != HgQueuesQueueManagementDialog.QUEUE_INPUT)
57 self.selectLabel.setHidden(
58 mode != HgQueuesQueueManagementDialog.QUEUE_INPUT)
59 if mode != HgQueuesQueueManagementDialog.QUEUE_INPUT: 63 if mode != HgQueuesQueueManagementDialog.QUEUE_INPUT:
60 self.queuesList.setSelectionMode( 64 self.queuesList.setSelectionMode(
61 QAbstractItemView.SelectionMode.NoSelection) 65 QAbstractItemView.SelectionMode.NoSelection
62 66 )
67
63 if mode == HgQueuesQueueManagementDialog.NO_INPUT: 68 if mode == HgQueuesQueueManagementDialog.NO_INPUT:
64 self.buttonBox.removeButton( 69 self.buttonBox.removeButton(
65 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)) 70 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
71 )
66 self.buttonBox.removeButton( 72 self.buttonBox.removeButton(
67 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel)) 73 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel)
74 )
68 self.refreshButton = self.buttonBox.addButton( 75 self.refreshButton = self.buttonBox.addButton(
69 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole) 76 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole
70 self.refreshButton.setToolTip( 77 )
71 self.tr("Press to refresh the queues list")) 78 self.refreshButton.setToolTip(self.tr("Press to refresh the queues list"))
72 self.buttonBox.button( 79 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(
73 QDialogButtonBox.StandardButton.Close).setDefault(True) 80 True
81 )
74 else: 82 else:
75 self.buttonBox.removeButton( 83 self.buttonBox.removeButton(
76 self.buttonBox.button(QDialogButtonBox.StandardButton.Close)) 84 self.buttonBox.button(QDialogButtonBox.StandardButton.Close)
77 self.buttonBox.button( 85 )
78 QDialogButtonBox.StandardButton.Ok).setEnabled(False) 86 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
79 self.refreshButton = None 87 self.refreshButton = None
80 88
81 self.setWindowTitle(title) 89 self.setWindowTitle(title)
82 90
83 self.show() 91 self.show()
84 QCoreApplication.processEvents() 92 QCoreApplication.processEvents()
85 93
86 self.refresh() 94 self.refresh()
87 95
88 def __getQueuesList(self): 96 def __getQueuesList(self):
89 """ 97 """
90 Private method to get a list of all queues and the name of the active 98 Private method to get a list of all queues and the name of the active
91 queue. 99 queue.
92 100
93 @return tuple with a list of all queues and the name of the active 101 @return tuple with a list of all queues and the name of the active
94 queue (list of strings, string) 102 queue (list of strings, string)
95 """ 103 """
96 queuesList = [] 104 queuesList = []
97 activeQueue = "" 105 activeQueue = ""
98 106
99 args = self.vcs.initCommand("qqueue") 107 args = self.vcs.initCommand("qqueue")
100 args.append("--list") 108 args.append("--list")
101 109
102 output = self.__hgClient.runcommand(args)[0] 110 output = self.__hgClient.runcommand(args)[0]
103 111
104 for queue in output.splitlines(): 112 for queue in output.splitlines():
105 queue = queue.strip() 113 queue = queue.strip()
106 if queue.endswith(")"): 114 if queue.endswith(")"):
107 queue = queue.rsplit(None, 1)[0] 115 queue = queue.rsplit(None, 1)[0]
108 activeQueue = queue 116 activeQueue = queue
109 queuesList.append(queue) 117 queuesList.append(queue)
110 118
111 if self.__suppressActive: 119 if self.__suppressActive:
112 if activeQueue in queuesList: 120 if activeQueue in queuesList:
113 queuesList.remove(activeQueue) 121 queuesList.remove(activeQueue)
114 activeQueue = "" 122 activeQueue = ""
115 return queuesList, activeQueue 123 return queuesList, activeQueue
116 124
117 @pyqtSlot(str) 125 @pyqtSlot(str)
118 def on_nameEdit_textChanged(self, txt): 126 def on_nameEdit_textChanged(self, txt):
119 """ 127 """
120 Private slot to handle changes of the entered queue name. 128 Private slot to handle changes of the entered queue name.
121 129
122 @param txt text of the edit (string) 130 @param txt text of the edit (string)
123 """ 131 """
124 if self.__mode == HgQueuesQueueManagementDialog.NAME_INPUT: 132 if self.__mode == HgQueuesQueueManagementDialog.NAME_INPUT:
125 self.buttonBox.button( 133 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
126 QDialogButtonBox.StandardButton.Ok).setEnabled(txt != "") 134 txt != ""
127 135 )
136
128 @pyqtSlot() 137 @pyqtSlot()
129 def on_queuesList_itemSelectionChanged(self): 138 def on_queuesList_itemSelectionChanged(self):
130 """ 139 """
131 Private slot to handle changes of selected queue names. 140 Private slot to handle changes of selected queue names.
132 """ 141 """
133 if self.__mode == HgQueuesQueueManagementDialog.QUEUE_INPUT: 142 if self.__mode == HgQueuesQueueManagementDialog.QUEUE_INPUT:
134 self.buttonBox.button( 143 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
135 QDialogButtonBox.StandardButton.Ok).setEnabled( 144 len(self.queuesList.selectedItems()) > 0
136 len(self.queuesList.selectedItems()) > 0) 145 )
137 146
138 @pyqtSlot(QAbstractButton) 147 @pyqtSlot(QAbstractButton)
139 def on_buttonBox_clicked(self, button): 148 def on_buttonBox_clicked(self, button):
140 """ 149 """
141 Private slot called by a button of the button box clicked. 150 Private slot called by a button of the button box clicked.
142 151
143 @param button button that was clicked (QAbstractButton) 152 @param button button that was clicked (QAbstractButton)
144 """ 153 """
145 if button == self.refreshButton: 154 if button == self.refreshButton:
146 self.refresh() 155 self.refresh()
147 elif button == self.buttonBox.button( 156 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close):
148 QDialogButtonBox.StandardButton.Close
149 ):
150 self.close() 157 self.close()
151 158
152 def refresh(self): 159 def refresh(self):
153 """ 160 """
154 Public slot to refresh the list of queues. 161 Public slot to refresh the list of queues.
155 """ 162 """
156 self.queuesList.clear() 163 self.queuesList.clear()
159 itm = QListWidgetItem(queue, self.queuesList) 166 itm = QListWidgetItem(queue, self.queuesList)
160 if queue == activeQueue: 167 if queue == activeQueue:
161 font = itm.font() 168 font = itm.font()
162 font.setBold(True) 169 font.setBold(True)
163 itm.setFont(font) 170 itm.setFont(font)
164 171
165 def getData(self): 172 def getData(self):
166 """ 173 """
167 Public slot to get the data. 174 Public slot to get the data.
168 175
169 @return queue name (string) 176 @return queue name (string)
170 """ 177 """
171 name = "" 178 name = ""
172 if self.__mode == HgQueuesQueueManagementDialog.NAME_INPUT: 179 if self.__mode == HgQueuesQueueManagementDialog.NAME_INPUT:
173 name = self.nameEdit.text().replace(" ", "_") 180 name = self.nameEdit.text().replace(" ", "_")

eric ide

mercurial