eric6/WebBrowser/SpellCheck/ManageDictionariesDialog.py

changeset 8143
2c730d5fd177
parent 7946
6901746220fc
child 8218
7c09585bd960
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
30 30
31 class ManageDictionariesDialog(QDialog, Ui_ManageDictionariesDialog): 31 class ManageDictionariesDialog(QDialog, Ui_ManageDictionariesDialog):
32 """ 32 """
33 Class implementing a dialog to install spell checking dictionaries. 33 Class implementing a dialog to install spell checking dictionaries.
34 """ 34 """
35 FilenameRole = Qt.UserRole 35 FilenameRole = Qt.ItemDataRole.UserRole
36 UrlRole = Qt.UserRole + 1 36 UrlRole = Qt.ItemDataRole.UserRole + 1
37 DocumentationDirRole = Qt.UserRole + 2 37 DocumentationDirRole = Qt.ItemDataRole.UserRole + 2
38 LocalesRole = Qt.UserRole + 3 38 LocalesRole = Qt.ItemDataRole.UserRole + 3
39 39
40 def __init__(self, writeableDirectories, parent=None): 40 def __init__(self, writeableDirectories, parent=None):
41 """ 41 """
42 Constructor 42 Constructor
43 43
48 """ 48 """
49 super(ManageDictionariesDialog, self).__init__(parent) 49 super(ManageDictionariesDialog, self).__init__(parent)
50 self.setupUi(self) 50 self.setupUi(self)
51 51
52 self.__refreshButton = self.buttonBox.addButton( 52 self.__refreshButton = self.buttonBox.addButton(
53 self.tr("Refresh"), QDialogButtonBox.ActionRole) 53 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole)
54 self.__installButton = self.buttonBox.addButton( 54 self.__installButton = self.buttonBox.addButton(
55 self.tr("Install Selected"), QDialogButtonBox.ActionRole) 55 self.tr("Install Selected"),
56 QDialogButtonBox.ButtonRole.ActionRole)
56 self.__installButton.setEnabled(False) 57 self.__installButton.setEnabled(False)
57 self.__uninstallButton = self.buttonBox.addButton( 58 self.__uninstallButton = self.buttonBox.addButton(
58 self.tr("Uninstall Selected"), QDialogButtonBox.ActionRole) 59 self.tr("Uninstall Selected"),
60 QDialogButtonBox.ButtonRole.ActionRole)
59 self.__uninstallButton.setEnabled(False) 61 self.__uninstallButton.setEnabled(False)
60 self.__cancelButton = self.buttonBox.addButton( 62 self.__cancelButton = self.buttonBox.addButton(
61 self.tr("Cancel"), QDialogButtonBox.ActionRole) 63 self.tr("Cancel"), QDialogButtonBox.ButtonRole.ActionRole)
62 self.__cancelButton.setEnabled(False) 64 self.__cancelButton.setEnabled(False)
63 65
64 self.locationComboBox.addItems(writeableDirectories) 66 self.locationComboBox.addItems(writeableDirectories)
65 67
66 self.dictionariesUrlEdit.setText( 68 self.dictionariesUrlEdit.setText(
102 104
103 self.__uninstallButton.setEnabled( 105 self.__uninstallButton.setEnabled(
104 self.locationComboBox.count() > 0 and 106 self.locationComboBox.count() > 0 and
105 len([itm 107 len([itm
106 for itm in self.dictionariesList.selectedItems() 108 for itm in self.dictionariesList.selectedItems()
107 if itm.checkState() == Qt.Checked 109 if itm.checkState() == Qt.CheckState.Checked
108 ]) 110 ])
109 ) 111 )
110 112
111 @pyqtSlot(bool) 113 @pyqtSlot(bool)
112 def on_dictionariesUrlEditButton_toggled(self, checked): 114 def on_dictionariesUrlEditButton_toggled(self, checked):
145 self.statusLabel.setText(url) 147 self.statusLabel.setText(url)
146 148
147 self.__downloadCancelled = False 149 self.__downloadCancelled = False
148 150
149 request = QNetworkRequest(QUrl(url)) 151 request = QNetworkRequest(QUrl(url))
150 request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, 152 request.setAttribute(
151 QNetworkRequest.AlwaysNetwork) 153 QNetworkRequest.Attribute.CacheLoadControlAttribute,
154 QNetworkRequest.CacheLoadControl.AlwaysNetwork)
152 reply = WebBrowserWindow.networkManager().get(request) 155 reply = WebBrowserWindow.networkManager().get(request)
153 reply.finished.connect( 156 reply.finished.connect(
154 lambda: self.__listFileDownloaded(reply)) 157 lambda: self.__listFileDownloaded(reply))
155 reply.downloadProgress.connect(self.__downloadProgress) 158 reply.downloadProgress.connect(self.__downloadProgress)
156 self.__replies.append(reply) 159 self.__replies.append(reply)
170 173
171 if reply in self.__replies: 174 if reply in self.__replies:
172 self.__replies.remove(reply) 175 self.__replies.remove(reply)
173 reply.deleteLater() 176 reply.deleteLater()
174 177
175 if reply.error() != QNetworkReply.NoError: 178 if reply.error() != QNetworkReply.NetworkError.NoError:
176 if not self.__downloadCancelled: 179 if not self.__downloadCancelled:
177 E5MessageBox.warning( 180 E5MessageBox.warning(
178 self, 181 self,
179 self.tr("Error downloading dictionaries list"), 182 self.tr("Error downloading dictionaries list"),
180 self.tr( 183 self.tr(
261 @type list of str 264 @type list of str
262 """ 265 """
263 itm = QListWidgetItem( 266 itm = QListWidgetItem(
264 self.tr("{0} ({1})").format(short, " ".join(locales)), 267 self.tr("{0} ({1})").format(short, " ".join(locales)),
265 self.dictionariesList) 268 self.dictionariesList)
266 itm.setCheckState(Qt.Unchecked) 269 itm.setCheckState(Qt.CheckState.Unchecked)
267 270
268 itm.setData(ManageDictionariesDialog.FilenameRole, filename) 271 itm.setData(ManageDictionariesDialog.FilenameRole, filename)
269 itm.setData(ManageDictionariesDialog.UrlRole, url) 272 itm.setData(ManageDictionariesDialog.UrlRole, url)
270 itm.setData(ManageDictionariesDialog.DocumentationDirRole, 273 itm.setData(ManageDictionariesDialog.DocumentationDirRole,
271 documentationDir) 274 documentationDir)
289 292
290 for row in range(self.dictionariesList.count()): 293 for row in range(self.dictionariesList.count()):
291 itm = self.dictionariesList.item(row) 294 itm = self.dictionariesList.item(row)
292 locales = set(itm.data(ManageDictionariesDialog.LocalesRole)) 295 locales = set(itm.data(ManageDictionariesDialog.LocalesRole))
293 if locales.intersection(installedLocales): 296 if locales.intersection(installedLocales):
294 itm.setCheckState(Qt.Checked) 297 itm.setCheckState(Qt.CheckState.Checked)
295 else: 298 else:
296 itm.setCheckState(Qt.Unchecked) 299 itm.setCheckState(Qt.CheckState.Unchecked)
297 else: 300 else:
298 for row in range(self.dictionariesList.count()): 301 for row in range(self.dictionariesList.count()):
299 itm = self.dictionariesList.item(row) 302 itm = self.dictionariesList.item(row)
300 itm.setCheckState(Qt.Unchecked) 303 itm.setCheckState(Qt.CheckState.Unchecked)
301 304
302 def __installSelected(self): 305 def __installSelected(self):
303 """ 306 """
304 Private method to install the selected dictionaries. 307 Private method to install the selected dictionaries.
305 """ 308 """
327 self.statusLabel.setText(url) 330 self.statusLabel.setText(url)
328 331
329 self.__downloadCancelled = False 332 self.__downloadCancelled = False
330 333
331 request = QNetworkRequest(QUrl(url)) 334 request = QNetworkRequest(QUrl(url))
332 request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, 335 request.setAttribute(
333 QNetworkRequest.AlwaysNetwork) 336 QNetworkRequest.Attribute.CacheLoadControlAttribute,
337 QNetworkRequest.CacheLoadControl.AlwaysNetwork)
334 reply = WebBrowserWindow.networkManager().get(request) 338 reply = WebBrowserWindow.networkManager().get(request)
335 reply.finished.connect( 339 reply.finished.connect(
336 lambda: self.__installDictionary(reply)) 340 lambda: self.__installDictionary(reply))
337 reply.downloadProgress.connect(self.__downloadProgress) 341 reply.downloadProgress.connect(self.__downloadProgress)
338 self.__replies.append(reply) 342 self.__replies.append(reply)
350 """ 354 """
351 if reply in self.__replies: 355 if reply in self.__replies:
352 self.__replies.remove(reply) 356 self.__replies.remove(reply)
353 reply.deleteLater() 357 reply.deleteLater()
354 358
355 if reply.error() != QNetworkReply.NoError: 359 if reply.error() != QNetworkReply.NetworkError.NoError:
356 if not self.__downloadCancelled: 360 if not self.__downloadCancelled:
357 E5MessageBox.warning( 361 E5MessageBox.warning(
358 self, 362 self,
359 self.tr("Error downloading dictionary file"), 363 self.tr("Error downloading dictionary file"),
360 self.tr( 364 self.tr(
407 return 411 return
408 412
409 itemsToDelete = [ 413 itemsToDelete = [
410 itm 414 itm
411 for itm in self.dictionariesList.selectedItems() 415 for itm in self.dictionariesList.selectedItems()
412 if itm.checkState() == Qt.Checked 416 if itm.checkState() == Qt.CheckState.Checked
413 ] 417 ]
414 for itm in itemsToDelete: 418 for itm in itemsToDelete:
415 documentationDir = itm.data( 419 documentationDir = itm.data(
416 ManageDictionariesDialog.DocumentationDirRole) 420 ManageDictionariesDialog.DocumentationDirRole)
417 shutil.rmtree(os.path.join(installLocation, documentationDir), 421 shutil.rmtree(os.path.join(installLocation, documentationDir),

eric ide

mercurial