QScintilla/MiniEditor.py

changeset 564
b3d966393ba9
parent 555
3c3836000c07
child 701
fc587a1c2f8b
equal deleted inserted replaced
563:e35d2cda9a74 564:b3d966393ba9
302 @param act reference to the action object (E5Action) 302 @param act reference to the action object (E5Action)
303 @param category category the action belongs to (string) 303 @param category category the action belongs to (string)
304 @param prefClass preferences class used as the storage area 304 @param prefClass preferences class used as the storage area
305 """ 305 """
306 if act.objectName(): 306 if act.objectName():
307 accel = Preferences.Prefs.settings.value(\ 307 accel = Preferences.Prefs.settings.value(
308 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName())) 308 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName()))
309 if accel is not None: 309 if accel is not None:
310 act.setShortcut(QKeySequence(accel)) 310 act.setShortcut(QKeySequence(accel))
311 accel = Preferences.Prefs.settings.value(\ 311 accel = Preferences.Prefs.settings.value(
312 "Shortcuts/{0}/{1}/AltAccel".format(category, act.objectName())) 312 "Shortcuts/{0}/{1}/AltAccel".format(category, act.objectName()))
313 if accel is not None: 313 if accel is not None:
314 act.setAlternateShortcut(QKeySequence(accel)) 314 act.setAlternateShortcut(QKeySequence(accel))
315 315
316 def __createActions(self): 316 def __createActions(self):
346 UI.PixmapCache.getIcon("new.png"), 346 UI.PixmapCache.getIcon("new.png"),
347 self.trUtf8('&New'), 347 self.trUtf8('&New'),
348 QKeySequence(self.trUtf8("Ctrl+N", "File|New")), 348 QKeySequence(self.trUtf8("Ctrl+N", "File|New")),
349 0, self, 'vm_file_new') 349 0, self, 'vm_file_new')
350 self.newAct.setStatusTip(self.trUtf8('Open an empty editor window')) 350 self.newAct.setStatusTip(self.trUtf8('Open an empty editor window'))
351 self.newAct.setWhatsThis(self.trUtf8(\ 351 self.newAct.setWhatsThis(self.trUtf8(
352 """<b>New</b>""" 352 """<b>New</b>"""
353 """<p>An empty editor window will be created.</p>""" 353 """<p>An empty editor window will be created.</p>"""
354 )) 354 ))
355 self.newAct.triggered[()].connect(self.__newFile) 355 self.newAct.triggered[()].connect(self.__newFile)
356 self.fileActions.append(self.newAct) 356 self.fileActions.append(self.newAct)
359 UI.PixmapCache.getIcon("open.png"), 359 UI.PixmapCache.getIcon("open.png"),
360 self.trUtf8('&Open...'), 360 self.trUtf8('&Open...'),
361 QKeySequence(self.trUtf8("Ctrl+O", "File|Open")), 361 QKeySequence(self.trUtf8("Ctrl+O", "File|Open")),
362 0, self, 'vm_file_open') 362 0, self, 'vm_file_open')
363 self.openAct.setStatusTip(self.trUtf8('Open a file')) 363 self.openAct.setStatusTip(self.trUtf8('Open a file'))
364 self.openAct.setWhatsThis(self.trUtf8(\ 364 self.openAct.setWhatsThis(self.trUtf8(
365 """<b>Open a file</b>""" 365 """<b>Open a file</b>"""
366 """<p>You will be asked for the name of a file to be opened.</p>""" 366 """<p>You will be asked for the name of a file to be opened.</p>"""
367 )) 367 ))
368 self.openAct.triggered[()].connect(self.__open) 368 self.openAct.triggered[()].connect(self.__open)
369 self.fileActions.append(self.openAct) 369 self.fileActions.append(self.openAct)
372 UI.PixmapCache.getIcon("fileSave.png"), 372 UI.PixmapCache.getIcon("fileSave.png"),
373 self.trUtf8('&Save'), 373 self.trUtf8('&Save'),
374 QKeySequence(self.trUtf8("Ctrl+S", "File|Save")), 374 QKeySequence(self.trUtf8("Ctrl+S", "File|Save")),
375 0, self, 'vm_file_save') 375 0, self, 'vm_file_save')
376 self.saveAct.setStatusTip(self.trUtf8('Save the current file')) 376 self.saveAct.setStatusTip(self.trUtf8('Save the current file'))
377 self.saveAct.setWhatsThis(self.trUtf8(\ 377 self.saveAct.setWhatsThis(self.trUtf8(
378 """<b>Save File</b>""" 378 """<b>Save File</b>"""
379 """<p>Save the contents of current editor window.</p>""" 379 """<p>Save the contents of current editor window.</p>"""
380 )) 380 ))
381 self.saveAct.triggered[()].connect(self.__save) 381 self.saveAct.triggered[()].connect(self.__save)
382 self.fileActions.append(self.saveAct) 382 self.fileActions.append(self.saveAct)
385 UI.PixmapCache.getIcon("fileSaveAs.png"), 385 UI.PixmapCache.getIcon("fileSaveAs.png"),
386 self.trUtf8('Save &as...'), 386 self.trUtf8('Save &as...'),
387 QKeySequence(self.trUtf8("Shift+Ctrl+S", "File|Save As")), 387 QKeySequence(self.trUtf8("Shift+Ctrl+S", "File|Save As")),
388 0, self, 'vm_file_save_as') 388 0, self, 'vm_file_save_as')
389 self.saveAsAct.setStatusTip(self.trUtf8('Save the current file to a new one')) 389 self.saveAsAct.setStatusTip(self.trUtf8('Save the current file to a new one'))
390 self.saveAsAct.setWhatsThis(self.trUtf8(\ 390 self.saveAsAct.setWhatsThis(self.trUtf8(
391 """<b>Save File as</b>""" 391 """<b>Save File as</b>"""
392 """<p>Save the contents of current editor window to a new file.""" 392 """<p>Save the contents of current editor window to a new file."""
393 """ The file can be entered in a file selection dialog.</p>""" 393 """ The file can be entered in a file selection dialog.</p>"""
394 )) 394 ))
395 self.saveAsAct.triggered[()].connect(self.__saveAs) 395 self.saveAsAct.triggered[()].connect(self.__saveAs)
399 UI.PixmapCache.getIcon("close.png"), 399 UI.PixmapCache.getIcon("close.png"),
400 self.trUtf8('&Close'), 400 self.trUtf8('&Close'),
401 QKeySequence(self.trUtf8("Ctrl+W", "File|Close")), 401 QKeySequence(self.trUtf8("Ctrl+W", "File|Close")),
402 0, self, 'vm_file_close') 402 0, self, 'vm_file_close')
403 self.closeAct.setStatusTip(self.trUtf8('Close the editor window')) 403 self.closeAct.setStatusTip(self.trUtf8('Close the editor window'))
404 self.closeAct.setWhatsThis(self.trUtf8(\ 404 self.closeAct.setWhatsThis(self.trUtf8(
405 """<b>Close Window</b>""" 405 """<b>Close Window</b>"""
406 """<p>Close the current window.</p>""" 406 """<p>Close the current window.</p>"""
407 )) 407 ))
408 self.closeAct.triggered[()].connect(self.close) 408 self.closeAct.triggered[()].connect(self.close)
409 self.fileActions.append(self.closeAct) 409 self.fileActions.append(self.closeAct)
444 self.trUtf8('&Undo'), 444 self.trUtf8('&Undo'),
445 QKeySequence(self.trUtf8("Ctrl+Z", "Edit|Undo")), 445 QKeySequence(self.trUtf8("Ctrl+Z", "Edit|Undo")),
446 QKeySequence(self.trUtf8("Alt+Backspace", "Edit|Undo")), 446 QKeySequence(self.trUtf8("Alt+Backspace", "Edit|Undo")),
447 self, 'vm_edit_undo') 447 self, 'vm_edit_undo')
448 self.undoAct.setStatusTip(self.trUtf8('Undo the last change')) 448 self.undoAct.setStatusTip(self.trUtf8('Undo the last change'))
449 self.undoAct.setWhatsThis(self.trUtf8(\ 449 self.undoAct.setWhatsThis(self.trUtf8(
450 """<b>Undo</b>""" 450 """<b>Undo</b>"""
451 """<p>Undo the last change done in the current editor.</p>""" 451 """<p>Undo the last change done in the current editor.</p>"""
452 )) 452 ))
453 self.undoAct.triggered[()].connect(self.__undo) 453 self.undoAct.triggered[()].connect(self.__undo)
454 self.editActions.append(self.undoAct) 454 self.editActions.append(self.undoAct)
457 UI.PixmapCache.getIcon("editRedo.png"), 457 UI.PixmapCache.getIcon("editRedo.png"),
458 self.trUtf8('&Redo'), 458 self.trUtf8('&Redo'),
459 QKeySequence(self.trUtf8("Ctrl+Shift+Z", "Edit|Redo")), 459 QKeySequence(self.trUtf8("Ctrl+Shift+Z", "Edit|Redo")),
460 0, self, 'vm_edit_redo') 460 0, self, 'vm_edit_redo')
461 self.redoAct.setStatusTip(self.trUtf8('Redo the last change')) 461 self.redoAct.setStatusTip(self.trUtf8('Redo the last change'))
462 self.redoAct.setWhatsThis(self.trUtf8(\ 462 self.redoAct.setWhatsThis(self.trUtf8(
463 """<b>Redo</b>""" 463 """<b>Redo</b>"""
464 """<p>Redo the last change done in the current editor.</p>""" 464 """<p>Redo the last change done in the current editor.</p>"""
465 )) 465 ))
466 self.redoAct.triggered[()].connect(self.__redo) 466 self.redoAct.triggered[()].connect(self.__redo)
467 self.editActions.append(self.redoAct) 467 self.editActions.append(self.redoAct)
471 self.trUtf8('Cu&t'), 471 self.trUtf8('Cu&t'),
472 QKeySequence(self.trUtf8("Ctrl+X", "Edit|Cut")), 472 QKeySequence(self.trUtf8("Ctrl+X", "Edit|Cut")),
473 QKeySequence(self.trUtf8("Shift+Del", "Edit|Cut")), 473 QKeySequence(self.trUtf8("Shift+Del", "Edit|Cut")),
474 self, 'vm_edit_cut') 474 self, 'vm_edit_cut')
475 self.cutAct.setStatusTip(self.trUtf8('Cut the selection')) 475 self.cutAct.setStatusTip(self.trUtf8('Cut the selection'))
476 self.cutAct.setWhatsThis(self.trUtf8(\ 476 self.cutAct.setWhatsThis(self.trUtf8(
477 """<b>Cut</b>""" 477 """<b>Cut</b>"""
478 """<p>Cut the selected text of the current editor to the clipboard.</p>""" 478 """<p>Cut the selected text of the current editor to the clipboard.</p>"""
479 )) 479 ))
480 self.cutAct.triggered[()].connect(self.__textEdit.cut) 480 self.cutAct.triggered[()].connect(self.__textEdit.cut)
481 self.editActions.append(self.cutAct) 481 self.editActions.append(self.cutAct)
485 self.trUtf8('&Copy'), 485 self.trUtf8('&Copy'),
486 QKeySequence(self.trUtf8("Ctrl+C", "Edit|Copy")), 486 QKeySequence(self.trUtf8("Ctrl+C", "Edit|Copy")),
487 QKeySequence(self.trUtf8("Ctrl+Ins", "Edit|Copy")), 487 QKeySequence(self.trUtf8("Ctrl+Ins", "Edit|Copy")),
488 self, 'vm_edit_copy') 488 self, 'vm_edit_copy')
489 self.copyAct.setStatusTip(self.trUtf8('Copy the selection')) 489 self.copyAct.setStatusTip(self.trUtf8('Copy the selection'))
490 self.copyAct.setWhatsThis(self.trUtf8(\ 490 self.copyAct.setWhatsThis(self.trUtf8(
491 """<b>Copy</b>""" 491 """<b>Copy</b>"""
492 """<p>Copy the selected text of the current editor to the clipboard.</p>""" 492 """<p>Copy the selected text of the current editor to the clipboard.</p>"""
493 )) 493 ))
494 self.copyAct.triggered[()].connect(self.__textEdit.copy) 494 self.copyAct.triggered[()].connect(self.__textEdit.copy)
495 self.editActions.append(self.copyAct) 495 self.editActions.append(self.copyAct)
499 self.trUtf8('&Paste'), 499 self.trUtf8('&Paste'),
500 QKeySequence(self.trUtf8("Ctrl+V", "Edit|Paste")), 500 QKeySequence(self.trUtf8("Ctrl+V", "Edit|Paste")),
501 QKeySequence(self.trUtf8("Shift+Ins", "Edit|Paste")), 501 QKeySequence(self.trUtf8("Shift+Ins", "Edit|Paste")),
502 self, 'vm_edit_paste') 502 self, 'vm_edit_paste')
503 self.pasteAct.setStatusTip(self.trUtf8('Paste the last cut/copied text')) 503 self.pasteAct.setStatusTip(self.trUtf8('Paste the last cut/copied text'))
504 self.pasteAct.setWhatsThis(self.trUtf8(\ 504 self.pasteAct.setWhatsThis(self.trUtf8(
505 """<b>Paste</b>""" 505 """<b>Paste</b>"""
506 """<p>Paste the last cut/copied text from the clipboard to""" 506 """<p>Paste the last cut/copied text from the clipboard to"""
507 """ the current editor.</p>""" 507 """ the current editor.</p>"""
508 )) 508 ))
509 self.pasteAct.triggered[()].connect(self.__textEdit.paste) 509 self.pasteAct.triggered[()].connect(self.__textEdit.paste)
514 self.trUtf8('Cl&ear'), 514 self.trUtf8('Cl&ear'),
515 QKeySequence(self.trUtf8("Alt+Shift+C", "Edit|Clear")), 515 QKeySequence(self.trUtf8("Alt+Shift+C", "Edit|Clear")),
516 0, 516 0,
517 self, 'vm_edit_clear') 517 self, 'vm_edit_clear')
518 self.deleteAct.setStatusTip(self.trUtf8('Clear all text')) 518 self.deleteAct.setStatusTip(self.trUtf8('Clear all text'))
519 self.deleteAct.setWhatsThis(self.trUtf8(\ 519 self.deleteAct.setWhatsThis(self.trUtf8(
520 """<b>Clear</b>""" 520 """<b>Clear</b>"""
521 """<p>Delete all text of the current editor.</p>""" 521 """<p>Delete all text of the current editor.</p>"""
522 )) 522 ))
523 self.deleteAct.triggered[()].connect(self.__textEdit.clear) 523 self.deleteAct.triggered[()].connect(self.__textEdit.clear)
524 self.editActions.append(self.deleteAct) 524 self.editActions.append(self.deleteAct)
1316 self.aboutAct.triggered[()].connect(self.__about) 1316 self.aboutAct.triggered[()].connect(self.__about)
1317 self.helpActions.append(self.aboutAct) 1317 self.helpActions.append(self.aboutAct)
1318 1318
1319 self.aboutQtAct = E5Action(self.trUtf8('About Qt'), 1319 self.aboutQtAct = E5Action(self.trUtf8('About Qt'),
1320 self.trUtf8('About &Qt'), 0, 0, self, 'about_qt') 1320 self.trUtf8('About &Qt'), 0, 0, self, 'about_qt')
1321 self.aboutQtAct.setStatusTip(\ 1321 self.aboutQtAct.setStatusTip(
1322 self.trUtf8('Display information about the Qt toolkit')) 1322 self.trUtf8('Display information about the Qt toolkit'))
1323 self.aboutQtAct.setWhatsThis(self.trUtf8( 1323 self.aboutQtAct.setWhatsThis(self.trUtf8(
1324 """<b>About Qt</b>""" 1324 """<b>About Qt</b>"""
1325 """<p>Display some information about the Qt toolkit.</p>""" 1325 """<p>Display some information about the Qt toolkit.</p>"""
1326 )) 1326 ))
1683 self.__textEdit.setTabWidth(Preferences.getEditor("TabWidth")) 1683 self.__textEdit.setTabWidth(Preferences.getEditor("TabWidth"))
1684 self.__textEdit.setIndentationWidth(Preferences.getEditor("IndentWidth")) 1684 self.__textEdit.setIndentationWidth(Preferences.getEditor("IndentWidth"))
1685 if self.lexer_ and self.lexer_.alwaysKeepTabs(): 1685 if self.lexer_ and self.lexer_.alwaysKeepTabs():
1686 self.__textEdit.setIndentationsUseTabs(True) 1686 self.__textEdit.setIndentationsUseTabs(True)
1687 else: 1687 else:
1688 self.__textEdit.setIndentationsUseTabs(\ 1688 self.__textEdit.setIndentationsUseTabs(
1689 Preferences.getEditor("TabForIndentation")) 1689 Preferences.getEditor("TabForIndentation"))
1690 self.__textEdit.setTabIndents(Preferences.getEditor("TabIndents")) 1690 self.__textEdit.setTabIndents(Preferences.getEditor("TabIndents"))
1691 self.__textEdit.setBackspaceUnindents(Preferences.getEditor("TabIndents")) 1691 self.__textEdit.setBackspaceUnindents(Preferences.getEditor("TabIndents"))
1692 self.__textEdit.setIndentationGuides(Preferences.getEditor("IndentationGuides")) 1692 self.__textEdit.setIndentationGuides(Preferences.getEditor("IndentationGuides"))
1693 if Preferences.getEditor("ShowWhitespace"): 1693 if Preferences.getEditor("ShowWhitespace"):
1707 self.__textEdit.setUnmatchedBraceForegroundColor( 1707 self.__textEdit.setUnmatchedBraceForegroundColor(
1708 Preferences.getEditorColour("NonmatchingBrace")) 1708 Preferences.getEditorColour("NonmatchingBrace"))
1709 self.__textEdit.setUnmatchedBraceBackgroundColor( 1709 self.__textEdit.setUnmatchedBraceBackgroundColor(
1710 Preferences.getEditorColour("NonmatchingBraceBack")) 1710 Preferences.getEditorColour("NonmatchingBraceBack"))
1711 if Preferences.getEditor("CustomSelectionColours"): 1711 if Preferences.getEditor("CustomSelectionColours"):
1712 self.__textEdit.setSelectionBackgroundColor(\ 1712 self.__textEdit.setSelectionBackgroundColor(
1713 Preferences.getEditorColour("SelectionBackground")) 1713 Preferences.getEditorColour("SelectionBackground"))
1714 else: 1714 else:
1715 self.__textEdit.setSelectionBackgroundColor(\ 1715 self.__textEdit.setSelectionBackgroundColor(
1716 QApplication.palette().color(QPalette.Highlight)) 1716 QApplication.palette().color(QPalette.Highlight))
1717 if Preferences.getEditor("ColourizeSelText"): 1717 if Preferences.getEditor("ColourizeSelText"):
1718 self.__textEdit.resetSelectionForegroundColor() 1718 self.__textEdit.resetSelectionForegroundColor()
1719 elif Preferences.getEditor("CustomSelectionColours"): 1719 elif Preferences.getEditor("CustomSelectionColours"):
1720 self.__textEdit.setSelectionForegroundColor(\ 1720 self.__textEdit.setSelectionForegroundColor(
1721 Preferences.getEditorColour("SelectionForeground")) 1721 Preferences.getEditorColour("SelectionForeground"))
1722 else: 1722 else:
1723 self.__textEdit.setSelectionForegroundColor(\ 1723 self.__textEdit.setSelectionForegroundColor(
1724 QApplication.palette().color(QPalette.HighlightedText)) 1724 QApplication.palette().color(QPalette.HighlightedText))
1725 self.__textEdit.setSelectionToEol(Preferences.getEditor("ExtendSelectionToEol")) 1725 self.__textEdit.setSelectionToEol(Preferences.getEditor("ExtendSelectionToEol"))
1726 self.__textEdit.setCaretForegroundColor( 1726 self.__textEdit.setCaretForegroundColor(
1727 Preferences.getEditorColour("CaretForeground")) 1727 Preferences.getEditorColour("CaretForeground"))
1728 self.__textEdit.setCaretLineBackgroundColor( 1728 self.__textEdit.setCaretLineBackgroundColor(
1739 self.__textEdit.setEdgeColumn(Preferences.getEditor("EdgeColumn")) 1739 self.__textEdit.setEdgeColumn(Preferences.getEditor("EdgeColumn"))
1740 self.__textEdit.setEdgeColor(Preferences.getEditorColour("Edge")) 1740 self.__textEdit.setEdgeColor(Preferences.getEditorColour("Edge"))
1741 1741
1742 if Preferences.getEditor("WrapLongLines"): 1742 if Preferences.getEditor("WrapLongLines"):
1743 self.__textEdit.setWrapMode(QsciScintilla.WrapWord) 1743 self.__textEdit.setWrapMode(QsciScintilla.WrapWord)
1744 self.__textEdit.setWrapVisualFlags(\ 1744 self.__textEdit.setWrapVisualFlags(
1745 QsciScintilla.WrapFlagByBorder, QsciScintilla.WrapFlagByBorder) 1745 QsciScintilla.WrapFlagByBorder, QsciScintilla.WrapFlagByBorder)
1746 else: 1746 else:
1747 self.__textEdit.setWrapMode(QsciScintilla.WrapNone) 1747 self.__textEdit.setWrapMode(QsciScintilla.WrapNone)
1748 self.__textEdit.setWrapVisualFlags(\ 1748 self.__textEdit.setWrapVisualFlags(
1749 QsciScintilla.WrapFlagNone, QsciScintilla.WrapFlagNone) 1749 QsciScintilla.WrapFlagNone, QsciScintilla.WrapFlagNone)
1750 1750
1751 self.searchIndicator = QsciScintilla.INDIC_CONTAINER 1751 self.searchIndicator = QsciScintilla.INDIC_CONTAINER
1752 self.__textEdit.indicatorDefine(self.searchIndicator, QsciScintilla.INDIC_BOX, 1752 self.__textEdit.indicatorDefine(self.searchIndicator, QsciScintilla.INDIC_BOX,
1753 Preferences.getEditorColour("SearchMarkers")) 1753 Preferences.getEditorColour("SearchMarkers"))
1929 lexerList = sorted([l[0] for l in get_all_lexers()]) 1929 lexerList = sorted([l[0] for l in get_all_lexers()])
1930 try: 1930 try:
1931 lexerSel = lexerList.index(self.getLanguage()) 1931 lexerSel = lexerList.index(self.getLanguage())
1932 except ValueError: 1932 except ValueError:
1933 lexerSel = 0 1933 lexerSel = 0
1934 lexerName, ok = QInputDialog.getItem(\ 1934 lexerName, ok = QInputDialog.getItem(
1935 self, 1935 self,
1936 self.trUtf8("Pygments Lexer"), 1936 self.trUtf8("Pygments Lexer"),
1937 self.trUtf8("Select the Pygments lexer to apply."), 1937 self.trUtf8("Select the Pygments lexer to apply."),
1938 lexerList, 1938 lexerList,
1939 lexerSel, 1939 lexerSel,

eric ide

mercurial