ViewManager/ViewManager.py

changeset 2211
86bdcfac4a4a
parent 2162
4627e6ea7b6b
child 2213
022f4ad3ed19
equal deleted inserted replaced
2210:e02bb8cbf145 2211:86bdcfac4a4a
33 from QScintilla.SpellChecker import SpellChecker 33 from QScintilla.SpellChecker import SpellChecker
34 import QScintilla.Lexers 34 import QScintilla.Lexers
35 import QScintilla.Exporters 35 import QScintilla.Exporters
36 from QScintilla.Shell import Shell 36 from QScintilla.Shell import Shell
37 from QScintilla.Terminal import Terminal 37 from QScintilla.Terminal import Terminal
38 from QScintilla.SpellingDictionaryEditDialog import SpellingDictionaryEditDialog
38 39
39 import Utilities 40 import Utilities
40 41
41 import UI.PixmapCache 42 import UI.PixmapCache
42 import UI.Config 43 import UI.Config
3446 Private method to initialize the spell checking actions. 3447 Private method to initialize the spell checking actions.
3447 """ 3448 """
3448 self.spellingActGrp = createActionGroup(self) 3449 self.spellingActGrp = createActionGroup(self)
3449 3450
3450 self.spellCheckAct = E5Action(QApplication.translate('ViewManager', 3451 self.spellCheckAct = E5Action(QApplication.translate('ViewManager',
3451 'Spell check'), 3452 'Check spelling'),
3452 UI.PixmapCache.getIcon("spellchecking.png"), 3453 UI.PixmapCache.getIcon("spellchecking.png"),
3453 QApplication.translate('ViewManager', 3454 QApplication.translate('ViewManager',
3454 '&Spell Check...'), 3455 'Check &spelling...'),
3455 QKeySequence(QApplication.translate('ViewManager', 3456 QKeySequence(QApplication.translate('ViewManager',
3456 "Shift+F7", "Spelling|Spell Check")), 3457 "Shift+F7", "Spelling|Spell Check")),
3457 0, 3458 0,
3458 self.spellingActGrp, 'vm_spelling_spellcheck') 3459 self.spellingActGrp, 'vm_spelling_spellcheck')
3459 self.spellCheckAct.setStatusTip(QApplication.translate('ViewManager', 3460 self.spellCheckAct.setStatusTip(QApplication.translate('ViewManager',
3460 'Perform spell check of current editor')) 3461 'Perform spell check of current editor'))
3461 self.spellCheckAct.setWhatsThis(QApplication.translate('ViewManager', 3462 self.spellCheckAct.setWhatsThis(QApplication.translate('ViewManager',
3462 """<b>Spell check</b>""" 3463 """<b>Check spelling</b>"""
3463 """<p>Perform a spell check of the current editor.</p>""" 3464 """<p>Perform a spell check of the current editor.</p>"""
3464 )) 3465 ))
3465 self.spellCheckAct.triggered[()].connect(self.__spellCheck) 3466 self.spellCheckAct.triggered[()].connect(self.__spellCheck)
3466 self.spellingActions.append(self.spellCheckAct) 3467 self.spellingActions.append(self.spellCheckAct)
3467 3468
3498 3499
3499 def addToExtrasMenu(self, menu): 3500 def addToExtrasMenu(self, menu):
3500 """ 3501 """
3501 Public method to add some actions to the extras menu. 3502 Public method to add some actions to the extras menu.
3502 """ 3503 """
3504 self.__editSpellingMenu = QMenu(QApplication.translate('ViewManager',
3505 "Edit Dictionary"))
3506 self.__editProjectPwlAct = self.__editSpellingMenu.addAction(
3507 QApplication.translate('ViewManager', "Project Word List"),
3508 self.__editProjectPWL)
3509 self.__editProjectPelAct = self.__editSpellingMenu.addAction(
3510 QApplication.translate('ViewManager', "Project Exception List"),
3511 self.__editProjectPEL)
3512 self.__editSpellingMenu.addSeparator()
3513 self.__editSpellingMenu.addAction(
3514 QApplication.translate('ViewManager', "User Word List"),
3515 self.__editUserPWL)
3516 self.__editSpellingMenu.addAction(
3517 QApplication.translate('ViewManager', "User Exception List"),
3518 self.__editUserPEL)
3519 self.__editProjectPwlAct.setEnabled(False)
3520 self.__editProjectPelAct.setEnabled(False)
3521
3503 menu.addAction(self.spellCheckAct) 3522 menu.addAction(self.spellCheckAct)
3504 menu.addAction(self.autoSpellCheckAct) 3523 menu.addAction(self.autoSpellCheckAct)
3524 menu.addMenu(self.__editSpellingMenu)
3505 menu.addSeparator() 3525 menu.addSeparator()
3506 3526
3507 def initSpellingToolbar(self, toolbarManager): 3527 def initSpellingToolbar(self, toolbarManager):
3508 """ 3528 """
3509 Public method to create the Spelling toolbar 3529 Public method to create the Spelling toolbar
4237 """ 4257 """
4238 Public slot to handle the projectOpened signal. 4258 Public slot to handle the projectOpened signal.
4239 """ 4259 """
4240 for editor in self.editors: 4260 for editor in self.editors:
4241 editor.projectOpened() 4261 editor.projectOpened()
4262
4263 self.__editProjectPwlAct.setEnabled(True)
4264 self.__editProjectPelAct.setEnabled(True)
4242 4265
4243 def projectClosed(self): 4266 def projectClosed(self):
4244 """ 4267 """
4245 Public slot to handle the projectClosed signal. 4268 Public slot to handle the projectClosed signal.
4246 """ 4269 """
4247 for editor in self.editors: 4270 for editor in self.editors:
4248 editor.projectClosed() 4271 editor.projectClosed()
4272
4273 self.__editProjectPwlAct.setEnabled(False)
4274 self.__editProjectPelAct.setEnabled(False)
4249 4275
4250 def projectFileRenamed(self, oldfn, newfn): 4276 def projectFileRenamed(self, oldfn, newfn):
4251 """ 4277 """
4252 Public slot to handle the projectFileRenamed signal. 4278 Public slot to handle the projectFileRenamed signal.
4253 4279
5203 Private slot to perform a spell check of the current editor. 5229 Private slot to perform a spell check of the current editor.
5204 """ 5230 """
5205 aw = self.activeWindow() 5231 aw = self.activeWindow()
5206 if aw: 5232 if aw:
5207 aw.checkSpelling() 5233 aw.checkSpelling()
5234
5235 def __editProjectPWL(self):
5236 """
5237 Private slot to edit the project word list.
5238 """
5239 pwl = e5App().getObject("Project").getProjectDictionaries()[0]
5240 if pwl:
5241 self.__editSpellingDictionary(pwl)
5242 else:
5243 E5MessageBox.warning(self.ui,
5244 QApplication.translate('ViewManager', "Edit Project Word List"),
5245 QApplication.translate('ViewManager',
5246 """No word list defined for the current project."""))
5247
5248 def __editProjectPEL(self):
5249 """
5250 Private slot to edit the project exception list.
5251 """
5252 pel = e5App().getObject("Project").getProjectDictionaries()[1]
5253 if pel:
5254 self.__editSpellingDictionary(pel)
5255 else:
5256 E5MessageBox.warning(self.ui,
5257 QApplication.translate('ViewManager', "Edit Project Exception List"),
5258 QApplication.translate('ViewManager',
5259 """No exception list defined for the current project."""))
5260
5261 def __editUserPWL(self):
5262 """
5263 Private slot to edit the user word list.
5264 """
5265 pwl = SpellChecker.getUserDictionaryPath()
5266 self.__editSpellingDictionary(pwl)
5267
5268 def __editUserPEL(self):
5269 """
5270 Private slot to edit the user exception list.
5271 """
5272 pel = SpellChecker.getUserDictionaryPath(True)
5273 self.__editSpellingDictionary(pel)
5274
5275 def __editSpellingDictionary(self, dictionaryFile):
5276 """
5277 Private slot to edit the given spelling dictionary.
5278 """
5279 if os.path.exists(dictionaryFile):
5280 try:
5281 f = open(dictionaryFile, "r", encoding="utf-8")
5282 data = f.read()
5283 f.close()
5284 except (IOError, OSError) as err:
5285 E5MessageBox.critical(self.ui,
5286 QApplication.translate('ViewManager', "Edit Spelling Dictionary"),
5287 QApplication.translate('ViewManager',
5288 """<p>The spelling dictionary file <b>{0}</b> could"""
5289 """ not be read.</p><p>Reason: {1}</p>""").format(
5290 dictionaryFile, str(err)))
5291 return
5292
5293 fileInfo = dictionaryFile if len(dictionaryFile) < 40 \
5294 else "...{0}".format(dictionaryFile[-40:])
5295 dlg = SpellingDictionaryEditDialog(data,
5296 QApplication.translate('ViewManager', "Editing {0}").format(fileInfo),
5297 self.ui)
5298 if dlg.exec_() == QDialog.Accepted:
5299 data = dlg.getData()
5300 try:
5301 f = open(dictionaryFile, "w", encoding="utf-8")
5302 f.write(data)
5303 f.close()
5304 except (IOError, OSError) as err:
5305 E5MessageBox.critical(self.ui,
5306 QApplication.translate('ViewManager', "Edit Spelling Dictionary"),
5307 QApplication.translate('ViewManager',
5308 """<p>The spelling dictionary file <b>{0}</b> could"""
5309 """ not be written.</p><p>Reason: {1}</p>""").format(
5310 dictionaryFile, str(err)))
5311 return
5312
5313 if self.ui.notificationsEnabled():
5314 self.ui.showNotification(
5315 UI.PixmapCache.getPixmap("spellchecking48.png"),
5316 QApplication.translate('ViewManager', "Edit Spelling Dictionary"),
5317 QApplication.translate('ViewManager',
5318 "The spelling dictionary was saved successfully."))
5208 5319
5209 ################################################################## 5320 ##################################################################
5210 ## Below are general utility methods 5321 ## Below are general utility methods
5211 ################################################################## 5322 ##################################################################
5212 5323

eric ide

mercurial