QScintilla/MiniEditor.py

changeset 3190
a9a94491c4fd
parent 3160
209a07d7e401
child 3201
0f115f6db6cb
equal deleted inserted replaced
3189:9a21c547de5f 3190:a9a94491c4fd
247 """ 247 """
248 Private slot to show a little About message. 248 Private slot to show a little About message.
249 """ 249 """
250 E5MessageBox.about( 250 E5MessageBox.about(
251 self, 251 self,
252 self.trUtf8("About eric5 Mini Editor"), 252 self.tr("About eric5 Mini Editor"),
253 self.trUtf8( 253 self.tr(
254 "The eric5 Mini Editor is an editor component" 254 "The eric5 Mini Editor is an editor component"
255 " based on QScintilla. It may be used for simple" 255 " based on QScintilla. It may be used for simple"
256 " editing tasks, that don't need the power of" 256 " editing tasks, that don't need the power of"
257 " a full blown editor.")) 257 " a full blown editor."))
258 258
308 308
309 self.sbWritable.setText(writ) 309 self.sbWritable.setText(writ)
310 310
311 if line is None: 311 if line is None:
312 line = '' 312 line = ''
313 self.sbLine.setText(self.trUtf8('Line: {0:5}').format(line)) 313 self.sbLine.setText(self.tr('Line: {0:5}').format(line))
314 314
315 if pos is None: 315 if pos is None:
316 pos = '' 316 pos = ''
317 self.sbPos.setText(self.trUtf8('Pos: {0:5}').format(pos)) 317 self.sbPos.setText(self.tr('Pos: {0:5}').format(pos))
318 318
319 def __readShortcut(self, act, category): 319 def __readShortcut(self, act, category):
320 """ 320 """
321 Private function to read a single keyboard shortcut from the settings. 321 Private function to read a single keyboard shortcut from the settings.
322 322
362 def __createFileActions(self): 362 def __createFileActions(self):
363 """ 363 """
364 Private method to create the File actions. 364 Private method to create the File actions.
365 """ 365 """
366 self.newAct = E5Action( 366 self.newAct = E5Action(
367 self.trUtf8('New'), 367 self.tr('New'),
368 UI.PixmapCache.getIcon("new.png"), 368 UI.PixmapCache.getIcon("new.png"),
369 self.trUtf8('&New'), 369 self.tr('&New'),
370 QKeySequence(self.trUtf8("Ctrl+N", "File|New")), 370 QKeySequence(self.tr("Ctrl+N", "File|New")),
371 0, self, 'vm_file_new') 371 0, self, 'vm_file_new')
372 self.newAct.setStatusTip(self.trUtf8('Open an empty editor window')) 372 self.newAct.setStatusTip(self.tr('Open an empty editor window'))
373 self.newAct.setWhatsThis(self.trUtf8( 373 self.newAct.setWhatsThis(self.tr(
374 """<b>New</b>""" 374 """<b>New</b>"""
375 """<p>An empty editor window will be created.</p>""" 375 """<p>An empty editor window will be created.</p>"""
376 )) 376 ))
377 self.newAct.triggered[()].connect(self.__newFile) 377 self.newAct.triggered[()].connect(self.__newFile)
378 self.fileActions.append(self.newAct) 378 self.fileActions.append(self.newAct)
379 379
380 self.openAct = E5Action( 380 self.openAct = E5Action(
381 self.trUtf8('Open'), 381 self.tr('Open'),
382 UI.PixmapCache.getIcon("open.png"), 382 UI.PixmapCache.getIcon("open.png"),
383 self.trUtf8('&Open...'), 383 self.tr('&Open...'),
384 QKeySequence(self.trUtf8("Ctrl+O", "File|Open")), 384 QKeySequence(self.tr("Ctrl+O", "File|Open")),
385 0, self, 'vm_file_open') 385 0, self, 'vm_file_open')
386 self.openAct.setStatusTip(self.trUtf8('Open a file')) 386 self.openAct.setStatusTip(self.tr('Open a file'))
387 self.openAct.setWhatsThis(self.trUtf8( 387 self.openAct.setWhatsThis(self.tr(
388 """<b>Open a file</b>""" 388 """<b>Open a file</b>"""
389 """<p>You will be asked for the name of a file to be opened.</p>""" 389 """<p>You will be asked for the name of a file to be opened.</p>"""
390 )) 390 ))
391 self.openAct.triggered[()].connect(self.__open) 391 self.openAct.triggered[()].connect(self.__open)
392 self.fileActions.append(self.openAct) 392 self.fileActions.append(self.openAct)
393 393
394 self.saveAct = E5Action( 394 self.saveAct = E5Action(
395 self.trUtf8('Save'), 395 self.tr('Save'),
396 UI.PixmapCache.getIcon("fileSave.png"), 396 UI.PixmapCache.getIcon("fileSave.png"),
397 self.trUtf8('&Save'), 397 self.tr('&Save'),
398 QKeySequence(self.trUtf8("Ctrl+S", "File|Save")), 398 QKeySequence(self.tr("Ctrl+S", "File|Save")),
399 0, self, 'vm_file_save') 399 0, self, 'vm_file_save')
400 self.saveAct.setStatusTip(self.trUtf8('Save the current file')) 400 self.saveAct.setStatusTip(self.tr('Save the current file'))
401 self.saveAct.setWhatsThis(self.trUtf8( 401 self.saveAct.setWhatsThis(self.tr(
402 """<b>Save File</b>""" 402 """<b>Save File</b>"""
403 """<p>Save the contents of current editor window.</p>""" 403 """<p>Save the contents of current editor window.</p>"""
404 )) 404 ))
405 self.saveAct.triggered[()].connect(self.__save) 405 self.saveAct.triggered[()].connect(self.__save)
406 self.fileActions.append(self.saveAct) 406 self.fileActions.append(self.saveAct)
407 407
408 self.saveAsAct = E5Action( 408 self.saveAsAct = E5Action(
409 self.trUtf8('Save as'), 409 self.tr('Save as'),
410 UI.PixmapCache.getIcon("fileSaveAs.png"), 410 UI.PixmapCache.getIcon("fileSaveAs.png"),
411 self.trUtf8('Save &as...'), 411 self.tr('Save &as...'),
412 QKeySequence(self.trUtf8("Shift+Ctrl+S", "File|Save As")), 412 QKeySequence(self.tr("Shift+Ctrl+S", "File|Save As")),
413 0, self, 'vm_file_save_as') 413 0, self, 'vm_file_save_as')
414 self.saveAsAct.setStatusTip(self.trUtf8( 414 self.saveAsAct.setStatusTip(self.tr(
415 'Save the current file to a new one')) 415 'Save the current file to a new one'))
416 self.saveAsAct.setWhatsThis(self.trUtf8( 416 self.saveAsAct.setWhatsThis(self.tr(
417 """<b>Save File as</b>""" 417 """<b>Save File as</b>"""
418 """<p>Save the contents of current editor window to a new file.""" 418 """<p>Save the contents of current editor window to a new file."""
419 """ The file can be entered in a file selection dialog.</p>""" 419 """ The file can be entered in a file selection dialog.</p>"""
420 )) 420 ))
421 self.saveAsAct.triggered[()].connect(self.__saveAs) 421 self.saveAsAct.triggered[()].connect(self.__saveAs)
422 self.fileActions.append(self.saveAsAct) 422 self.fileActions.append(self.saveAsAct)
423 423
424 self.closeAct = E5Action( 424 self.closeAct = E5Action(
425 self.trUtf8('Close'), 425 self.tr('Close'),
426 UI.PixmapCache.getIcon("close.png"), 426 UI.PixmapCache.getIcon("close.png"),
427 self.trUtf8('&Close'), 427 self.tr('&Close'),
428 QKeySequence(self.trUtf8("Ctrl+W", "File|Close")), 428 QKeySequence(self.tr("Ctrl+W", "File|Close")),
429 0, self, 'vm_file_close') 429 0, self, 'vm_file_close')
430 self.closeAct.setStatusTip(self.trUtf8('Close the editor window')) 430 self.closeAct.setStatusTip(self.tr('Close the editor window'))
431 self.closeAct.setWhatsThis(self.trUtf8( 431 self.closeAct.setWhatsThis(self.tr(
432 """<b>Close Window</b>""" 432 """<b>Close Window</b>"""
433 """<p>Close the current window.</p>""" 433 """<p>Close the current window.</p>"""
434 )) 434 ))
435 self.closeAct.triggered[()].connect(self.close) 435 self.closeAct.triggered[()].connect(self.close)
436 self.fileActions.append(self.closeAct) 436 self.fileActions.append(self.closeAct)
437 437
438 self.printAct = E5Action( 438 self.printAct = E5Action(
439 self.trUtf8('Print'), 439 self.tr('Print'),
440 UI.PixmapCache.getIcon("print.png"), 440 UI.PixmapCache.getIcon("print.png"),
441 self.trUtf8('&Print'), 441 self.tr('&Print'),
442 QKeySequence(self.trUtf8("Ctrl+P", "File|Print")), 442 QKeySequence(self.tr("Ctrl+P", "File|Print")),
443 0, self, 'vm_file_print') 443 0, self, 'vm_file_print')
444 self.printAct.setStatusTip(self.trUtf8('Print the current file')) 444 self.printAct.setStatusTip(self.tr('Print the current file'))
445 self.printAct.setWhatsThis(self.trUtf8( 445 self.printAct.setWhatsThis(self.tr(
446 """<b>Print File</b>""" 446 """<b>Print File</b>"""
447 """<p>Print the contents of the current file.</p>""" 447 """<p>Print the contents of the current file.</p>"""
448 )) 448 ))
449 self.printAct.triggered[()].connect(self.__printFile) 449 self.printAct.triggered[()].connect(self.__printFile)
450 self.fileActions.append(self.printAct) 450 self.fileActions.append(self.printAct)
451 451
452 self.printPreviewAct = E5Action( 452 self.printPreviewAct = E5Action(
453 self.trUtf8('Print Preview'), 453 self.tr('Print Preview'),
454 UI.PixmapCache.getIcon("printPreview.png"), 454 UI.PixmapCache.getIcon("printPreview.png"),
455 QApplication.translate('ViewManager', 'Print Preview'), 455 QApplication.translate('ViewManager', 'Print Preview'),
456 0, 0, self, 'vm_file_print_preview') 456 0, 0, self, 'vm_file_print_preview')
457 self.printPreviewAct.setStatusTip(self.trUtf8( 457 self.printPreviewAct.setStatusTip(self.tr(
458 'Print preview of the current file')) 458 'Print preview of the current file'))
459 self.printPreviewAct.setWhatsThis(self.trUtf8( 459 self.printPreviewAct.setWhatsThis(self.tr(
460 """<b>Print Preview</b>""" 460 """<b>Print Preview</b>"""
461 """<p>Print preview of the current file.</p>""" 461 """<p>Print preview of the current file.</p>"""
462 )) 462 ))
463 self.printPreviewAct.triggered[()].connect(self.__printPreviewFile) 463 self.printPreviewAct.triggered[()].connect(self.__printPreviewFile)
464 self.fileActions.append(self.printPreviewAct) 464 self.fileActions.append(self.printPreviewAct)
466 def __createEditActions(self): 466 def __createEditActions(self):
467 """ 467 """
468 Private method to create the Edit actions. 468 Private method to create the Edit actions.
469 """ 469 """
470 self.undoAct = E5Action( 470 self.undoAct = E5Action(
471 self.trUtf8('Undo'), 471 self.tr('Undo'),
472 UI.PixmapCache.getIcon("editUndo.png"), 472 UI.PixmapCache.getIcon("editUndo.png"),
473 self.trUtf8('&Undo'), 473 self.tr('&Undo'),
474 QKeySequence(self.trUtf8("Ctrl+Z", "Edit|Undo")), 474 QKeySequence(self.tr("Ctrl+Z", "Edit|Undo")),
475 QKeySequence(self.trUtf8("Alt+Backspace", "Edit|Undo")), 475 QKeySequence(self.tr("Alt+Backspace", "Edit|Undo")),
476 self, 'vm_edit_undo') 476 self, 'vm_edit_undo')
477 self.undoAct.setStatusTip(self.trUtf8('Undo the last change')) 477 self.undoAct.setStatusTip(self.tr('Undo the last change'))
478 self.undoAct.setWhatsThis(self.trUtf8( 478 self.undoAct.setWhatsThis(self.tr(
479 """<b>Undo</b>""" 479 """<b>Undo</b>"""
480 """<p>Undo the last change done in the current editor.</p>""" 480 """<p>Undo the last change done in the current editor.</p>"""
481 )) 481 ))
482 self.undoAct.triggered[()].connect(self.__undo) 482 self.undoAct.triggered[()].connect(self.__undo)
483 self.editActions.append(self.undoAct) 483 self.editActions.append(self.undoAct)
484 484
485 self.redoAct = E5Action( 485 self.redoAct = E5Action(
486 self.trUtf8('Redo'), 486 self.tr('Redo'),
487 UI.PixmapCache.getIcon("editRedo.png"), 487 UI.PixmapCache.getIcon("editRedo.png"),
488 self.trUtf8('&Redo'), 488 self.tr('&Redo'),
489 QKeySequence(self.trUtf8("Ctrl+Shift+Z", "Edit|Redo")), 489 QKeySequence(self.tr("Ctrl+Shift+Z", "Edit|Redo")),
490 0, self, 'vm_edit_redo') 490 0, self, 'vm_edit_redo')
491 self.redoAct.setStatusTip(self.trUtf8('Redo the last change')) 491 self.redoAct.setStatusTip(self.tr('Redo the last change'))
492 self.redoAct.setWhatsThis(self.trUtf8( 492 self.redoAct.setWhatsThis(self.tr(
493 """<b>Redo</b>""" 493 """<b>Redo</b>"""
494 """<p>Redo the last change done in the current editor.</p>""" 494 """<p>Redo the last change done in the current editor.</p>"""
495 )) 495 ))
496 self.redoAct.triggered[()].connect(self.__redo) 496 self.redoAct.triggered[()].connect(self.__redo)
497 self.editActions.append(self.redoAct) 497 self.editActions.append(self.redoAct)
498 498
499 self.cutAct = E5Action( 499 self.cutAct = E5Action(
500 self.trUtf8('Cut'), 500 self.tr('Cut'),
501 UI.PixmapCache.getIcon("editCut.png"), 501 UI.PixmapCache.getIcon("editCut.png"),
502 self.trUtf8('Cu&t'), 502 self.tr('Cu&t'),
503 QKeySequence(self.trUtf8("Ctrl+X", "Edit|Cut")), 503 QKeySequence(self.tr("Ctrl+X", "Edit|Cut")),
504 QKeySequence(self.trUtf8("Shift+Del", "Edit|Cut")), 504 QKeySequence(self.tr("Shift+Del", "Edit|Cut")),
505 self, 'vm_edit_cut') 505 self, 'vm_edit_cut')
506 self.cutAct.setStatusTip(self.trUtf8('Cut the selection')) 506 self.cutAct.setStatusTip(self.tr('Cut the selection'))
507 self.cutAct.setWhatsThis(self.trUtf8( 507 self.cutAct.setWhatsThis(self.tr(
508 """<b>Cut</b>""" 508 """<b>Cut</b>"""
509 """<p>Cut the selected text of the current editor to the""" 509 """<p>Cut the selected text of the current editor to the"""
510 """ clipboard.</p>""" 510 """ clipboard.</p>"""
511 )) 511 ))
512 self.cutAct.triggered[()].connect(self.__textEdit.cut) 512 self.cutAct.triggered[()].connect(self.__textEdit.cut)
513 self.editActions.append(self.cutAct) 513 self.editActions.append(self.cutAct)
514 514
515 self.copyAct = E5Action( 515 self.copyAct = E5Action(
516 self.trUtf8('Copy'), 516 self.tr('Copy'),
517 UI.PixmapCache.getIcon("editCopy.png"), 517 UI.PixmapCache.getIcon("editCopy.png"),
518 self.trUtf8('&Copy'), 518 self.tr('&Copy'),
519 QKeySequence(self.trUtf8("Ctrl+C", "Edit|Copy")), 519 QKeySequence(self.tr("Ctrl+C", "Edit|Copy")),
520 QKeySequence(self.trUtf8("Ctrl+Ins", "Edit|Copy")), 520 QKeySequence(self.tr("Ctrl+Ins", "Edit|Copy")),
521 self, 'vm_edit_copy') 521 self, 'vm_edit_copy')
522 self.copyAct.setStatusTip(self.trUtf8('Copy the selection')) 522 self.copyAct.setStatusTip(self.tr('Copy the selection'))
523 self.copyAct.setWhatsThis(self.trUtf8( 523 self.copyAct.setWhatsThis(self.tr(
524 """<b>Copy</b>""" 524 """<b>Copy</b>"""
525 """<p>Copy the selected text of the current editor to the""" 525 """<p>Copy the selected text of the current editor to the"""
526 """ clipboard.</p>""" 526 """ clipboard.</p>"""
527 )) 527 ))
528 self.copyAct.triggered[()].connect(self.__textEdit.copy) 528 self.copyAct.triggered[()].connect(self.__textEdit.copy)
529 self.editActions.append(self.copyAct) 529 self.editActions.append(self.copyAct)
530 530
531 self.pasteAct = E5Action( 531 self.pasteAct = E5Action(
532 self.trUtf8('Paste'), 532 self.tr('Paste'),
533 UI.PixmapCache.getIcon("editPaste.png"), 533 UI.PixmapCache.getIcon("editPaste.png"),
534 self.trUtf8('&Paste'), 534 self.tr('&Paste'),
535 QKeySequence(self.trUtf8("Ctrl+V", "Edit|Paste")), 535 QKeySequence(self.tr("Ctrl+V", "Edit|Paste")),
536 QKeySequence(self.trUtf8("Shift+Ins", "Edit|Paste")), 536 QKeySequence(self.tr("Shift+Ins", "Edit|Paste")),
537 self, 'vm_edit_paste') 537 self, 'vm_edit_paste')
538 self.pasteAct.setStatusTip(self.trUtf8( 538 self.pasteAct.setStatusTip(self.tr(
539 'Paste the last cut/copied text')) 539 'Paste the last cut/copied text'))
540 self.pasteAct.setWhatsThis(self.trUtf8( 540 self.pasteAct.setWhatsThis(self.tr(
541 """<b>Paste</b>""" 541 """<b>Paste</b>"""
542 """<p>Paste the last cut/copied text from the clipboard to""" 542 """<p>Paste the last cut/copied text from the clipboard to"""
543 """ the current editor.</p>""" 543 """ the current editor.</p>"""
544 )) 544 ))
545 self.pasteAct.triggered[()].connect(self.__textEdit.paste) 545 self.pasteAct.triggered[()].connect(self.__textEdit.paste)
546 self.editActions.append(self.pasteAct) 546 self.editActions.append(self.pasteAct)
547 547
548 self.deleteAct = E5Action( 548 self.deleteAct = E5Action(
549 self.trUtf8('Clear'), 549 self.tr('Clear'),
550 UI.PixmapCache.getIcon("editDelete.png"), 550 UI.PixmapCache.getIcon("editDelete.png"),
551 self.trUtf8('Cl&ear'), 551 self.tr('Cl&ear'),
552 QKeySequence(self.trUtf8("Alt+Shift+C", "Edit|Clear")), 552 QKeySequence(self.tr("Alt+Shift+C", "Edit|Clear")),
553 0, 553 0,
554 self, 'vm_edit_clear') 554 self, 'vm_edit_clear')
555 self.deleteAct.setStatusTip(self.trUtf8('Clear all text')) 555 self.deleteAct.setStatusTip(self.tr('Clear all text'))
556 self.deleteAct.setWhatsThis(self.trUtf8( 556 self.deleteAct.setWhatsThis(self.tr(
557 """<b>Clear</b>""" 557 """<b>Clear</b>"""
558 """<p>Delete all text of the current editor.</p>""" 558 """<p>Delete all text of the current editor.</p>"""
559 )) 559 ))
560 self.deleteAct.triggered[()].connect(self.__textEdit.clear) 560 self.deleteAct.triggered[()].connect(self.__textEdit.clear)
561 self.editActions.append(self.deleteAct) 561 self.editActions.append(self.deleteAct)
1955 def __createHelpActions(self): 1955 def __createHelpActions(self):
1956 """ 1956 """
1957 Private method to create the Help actions. 1957 Private method to create the Help actions.
1958 """ 1958 """
1959 self.aboutAct = E5Action( 1959 self.aboutAct = E5Action(
1960 self.trUtf8('About'), 1960 self.tr('About'),
1961 self.trUtf8('&About'), 1961 self.tr('&About'),
1962 0, 0, self, 'about_eric') 1962 0, 0, self, 'about_eric')
1963 self.aboutAct.setStatusTip(self.trUtf8( 1963 self.aboutAct.setStatusTip(self.tr(
1964 'Display information about this software')) 1964 'Display information about this software'))
1965 self.aboutAct.setWhatsThis(self.trUtf8( 1965 self.aboutAct.setWhatsThis(self.tr(
1966 """<b>About</b>""" 1966 """<b>About</b>"""
1967 """<p>Display some information about this software.</p>""")) 1967 """<p>Display some information about this software.</p>"""))
1968 self.aboutAct.triggered[()].connect(self.__about) 1968 self.aboutAct.triggered[()].connect(self.__about)
1969 self.helpActions.append(self.aboutAct) 1969 self.helpActions.append(self.aboutAct)
1970 1970
1971 self.aboutQtAct = E5Action( 1971 self.aboutQtAct = E5Action(
1972 self.trUtf8('About Qt'), 1972 self.tr('About Qt'),
1973 self.trUtf8('About &Qt'), 1973 self.tr('About &Qt'),
1974 0, 0, self, 'about_qt') 1974 0, 0, self, 'about_qt')
1975 self.aboutQtAct.setStatusTip( 1975 self.aboutQtAct.setStatusTip(
1976 self.trUtf8('Display information about the Qt toolkit')) 1976 self.tr('Display information about the Qt toolkit'))
1977 self.aboutQtAct.setWhatsThis(self.trUtf8( 1977 self.aboutQtAct.setWhatsThis(self.tr(
1978 """<b>About Qt</b>""" 1978 """<b>About Qt</b>"""
1979 """<p>Display some information about the Qt toolkit.</p>""" 1979 """<p>Display some information about the Qt toolkit.</p>"""
1980 )) 1980 ))
1981 self.aboutQtAct.triggered[()].connect(self.__aboutQt) 1981 self.aboutQtAct.triggered[()].connect(self.__aboutQt)
1982 self.helpActions.append(self.aboutQtAct) 1982 self.helpActions.append(self.aboutQtAct)
1983 1983
1984 self.whatsThisAct = E5Action( 1984 self.whatsThisAct = E5Action(
1985 self.trUtf8('What\'s This?'), 1985 self.tr('What\'s This?'),
1986 UI.PixmapCache.getIcon("whatsThis.png"), 1986 UI.PixmapCache.getIcon("whatsThis.png"),
1987 self.trUtf8('&What\'s This?'), 1987 self.tr('&What\'s This?'),
1988 QKeySequence(self.trUtf8("Shift+F1", "Help|What's This?'")), 1988 QKeySequence(self.tr("Shift+F1", "Help|What's This?'")),
1989 0, self, 'help_help_whats_this') 1989 0, self, 'help_help_whats_this')
1990 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help')) 1990 self.whatsThisAct.setStatusTip(self.tr('Context sensitive help'))
1991 self.whatsThisAct.setWhatsThis(self.trUtf8( 1991 self.whatsThisAct.setWhatsThis(self.tr(
1992 """<b>Display context sensitive help</b>""" 1992 """<b>Display context sensitive help</b>"""
1993 """<p>In What's This? mode, the mouse cursor shows an arrow""" 1993 """<p>In What's This? mode, the mouse cursor shows an arrow"""
1994 """ with a question mark, and you can click on the interface""" 1994 """ with a question mark, and you can click on the interface"""
1995 """ elements to get a short description of what they do and""" 1995 """ elements to get a short description of what they do and"""
1996 """ how to use them. In dialogs, this feature can be""" 1996 """ how to use them. In dialogs, this feature can be"""
2002 2002
2003 def __createMenus(self): 2003 def __createMenus(self):
2004 """ 2004 """
2005 Private method to create the menus of the menu bar. 2005 Private method to create the menus of the menu bar.
2006 """ 2006 """
2007 self.fileMenu = self.menuBar().addMenu(self.trUtf8("&File")) 2007 self.fileMenu = self.menuBar().addMenu(self.tr("&File"))
2008 self.fileMenu.addAction(self.newAct) 2008 self.fileMenu.addAction(self.newAct)
2009 self.fileMenu.addAction(self.openAct) 2009 self.fileMenu.addAction(self.openAct)
2010 self.fileMenu.addAction(self.saveAct) 2010 self.fileMenu.addAction(self.saveAct)
2011 self.fileMenu.addAction(self.saveAsAct) 2011 self.fileMenu.addAction(self.saveAsAct)
2012 self.fileMenu.addSeparator() 2012 self.fileMenu.addSeparator()
2013 self.fileMenu.addAction(self.printPreviewAct) 2013 self.fileMenu.addAction(self.printPreviewAct)
2014 self.fileMenu.addAction(self.printAct) 2014 self.fileMenu.addAction(self.printAct)
2015 self.fileMenu.addSeparator() 2015 self.fileMenu.addSeparator()
2016 self.fileMenu.addAction(self.closeAct) 2016 self.fileMenu.addAction(self.closeAct)
2017 2017
2018 self.editMenu = self.menuBar().addMenu(self.trUtf8("&Edit")) 2018 self.editMenu = self.menuBar().addMenu(self.tr("&Edit"))
2019 self.editMenu.addAction(self.undoAct) 2019 self.editMenu.addAction(self.undoAct)
2020 self.editMenu.addAction(self.redoAct) 2020 self.editMenu.addAction(self.redoAct)
2021 self.editMenu.addSeparator() 2021 self.editMenu.addSeparator()
2022 self.editMenu.addAction(self.cutAct) 2022 self.editMenu.addAction(self.cutAct)
2023 self.editMenu.addAction(self.copyAct) 2023 self.editMenu.addAction(self.copyAct)
2030 self.editMenu.addAction(self.searchClearMarkersAct) 2030 self.editMenu.addAction(self.searchClearMarkersAct)
2031 self.editMenu.addAction(self.replaceAct) 2031 self.editMenu.addAction(self.replaceAct)
2032 2032
2033 self.menuBar().addSeparator() 2033 self.menuBar().addSeparator()
2034 2034
2035 self.helpMenu = self.menuBar().addMenu(self.trUtf8("&Help")) 2035 self.helpMenu = self.menuBar().addMenu(self.tr("&Help"))
2036 self.helpMenu.addAction(self.aboutAct) 2036 self.helpMenu.addAction(self.aboutAct)
2037 self.helpMenu.addAction(self.aboutQtAct) 2037 self.helpMenu.addAction(self.aboutQtAct)
2038 self.helpMenu.addSeparator() 2038 self.helpMenu.addSeparator()
2039 self.helpMenu.addAction(self.whatsThisAct) 2039 self.helpMenu.addAction(self.whatsThisAct)
2040 2040
2042 2042
2043 def __createToolBars(self): 2043 def __createToolBars(self):
2044 """ 2044 """
2045 Private method to create the various toolbars. 2045 Private method to create the various toolbars.
2046 """ 2046 """
2047 filetb = self.addToolBar(self.trUtf8("File")) 2047 filetb = self.addToolBar(self.tr("File"))
2048 filetb.setIconSize(UI.Config.ToolBarIconSize) 2048 filetb.setIconSize(UI.Config.ToolBarIconSize)
2049 filetb.addAction(self.newAct) 2049 filetb.addAction(self.newAct)
2050 filetb.addAction(self.openAct) 2050 filetb.addAction(self.openAct)
2051 filetb.addAction(self.saveAct) 2051 filetb.addAction(self.saveAct)
2052 filetb.addAction(self.saveAsAct) 2052 filetb.addAction(self.saveAsAct)
2054 filetb.addAction(self.printPreviewAct) 2054 filetb.addAction(self.printPreviewAct)
2055 filetb.addAction(self.printAct) 2055 filetb.addAction(self.printAct)
2056 filetb.addSeparator() 2056 filetb.addSeparator()
2057 filetb.addAction(self.closeAct) 2057 filetb.addAction(self.closeAct)
2058 2058
2059 edittb = self.addToolBar(self.trUtf8("Edit")) 2059 edittb = self.addToolBar(self.tr("Edit"))
2060 edittb.setIconSize(UI.Config.ToolBarIconSize) 2060 edittb.setIconSize(UI.Config.ToolBarIconSize)
2061 edittb.addAction(self.undoAct) 2061 edittb.addAction(self.undoAct)
2062 edittb.addAction(self.redoAct) 2062 edittb.addAction(self.redoAct)
2063 edittb.addSeparator() 2063 edittb.addSeparator()
2064 edittb.addAction(self.cutAct) 2064 edittb.addAction(self.cutAct)
2065 edittb.addAction(self.copyAct) 2065 edittb.addAction(self.copyAct)
2066 edittb.addAction(self.pasteAct) 2066 edittb.addAction(self.pasteAct)
2067 edittb.addAction(self.deleteAct) 2067 edittb.addAction(self.deleteAct)
2068 2068
2069 findtb = self.addToolBar(self.trUtf8("Find")) 2069 findtb = self.addToolBar(self.tr("Find"))
2070 findtb.setIconSize(UI.Config.ToolBarIconSize) 2070 findtb.setIconSize(UI.Config.ToolBarIconSize)
2071 findtb.addAction(self.searchAct) 2071 findtb.addAction(self.searchAct)
2072 findtb.addAction(self.searchNextAct) 2072 findtb.addAction(self.searchNextAct)
2073 findtb.addAction(self.searchPrevAct) 2073 findtb.addAction(self.searchPrevAct)
2074 findtb.addAction(self.searchClearMarkersAct) 2074 findtb.addAction(self.searchClearMarkersAct)
2075 2075
2076 helptb = self.addToolBar(self.trUtf8("Help")) 2076 helptb = self.addToolBar(self.tr("Help"))
2077 helptb.setIconSize(UI.Config.ToolBarIconSize) 2077 helptb.setIconSize(UI.Config.ToolBarIconSize)
2078 helptb.addAction(self.whatsThisAct) 2078 helptb.addAction(self.whatsThisAct)
2079 2079
2080 def __createStatusBar(self): 2080 def __createStatusBar(self):
2081 """ 2081 """
2084 self.__statusBar = self.statusBar() 2084 self.__statusBar = self.statusBar()
2085 self.__statusBar.setSizeGripEnabled(True) 2085 self.__statusBar.setSizeGripEnabled(True)
2086 2086
2087 self.sbWritable = QLabel(self.__statusBar) 2087 self.sbWritable = QLabel(self.__statusBar)
2088 self.__statusBar.addPermanentWidget(self.sbWritable) 2088 self.__statusBar.addPermanentWidget(self.sbWritable)
2089 self.sbWritable.setWhatsThis(self.trUtf8( 2089 self.sbWritable.setWhatsThis(self.tr(
2090 """<p>This part of the status bar displays an indication of the""" 2090 """<p>This part of the status bar displays an indication of the"""
2091 """ editors files writability.</p>""" 2091 """ editors files writability.</p>"""
2092 )) 2092 ))
2093 2093
2094 self.sbLine = QLabel(self.__statusBar) 2094 self.sbLine = QLabel(self.__statusBar)
2095 self.__statusBar.addPermanentWidget(self.sbLine) 2095 self.__statusBar.addPermanentWidget(self.sbLine)
2096 self.sbLine.setWhatsThis(self.trUtf8( 2096 self.sbLine.setWhatsThis(self.tr(
2097 """<p>This part of the status bar displays the line number of""" 2097 """<p>This part of the status bar displays the line number of"""
2098 """ the editor.</p>""" 2098 """ the editor.</p>"""
2099 )) 2099 ))
2100 2100
2101 self.sbPos = QLabel(self.__statusBar) 2101 self.sbPos = QLabel(self.__statusBar)
2102 self.__statusBar.addPermanentWidget(self.sbPos) 2102 self.__statusBar.addPermanentWidget(self.sbPos)
2103 self.sbPos.setWhatsThis(self.trUtf8( 2103 self.sbPos.setWhatsThis(self.tr(
2104 """<p>This part of the status bar displays the cursor position""" 2104 """<p>This part of the status bar displays the cursor position"""
2105 """ of the editor.</p>""" 2105 """ of the editor.</p>"""
2106 )) 2106 ))
2107 2107
2108 self.__statusBar.showMessage(self.trUtf8("Ready")) 2108 self.__statusBar.showMessage(self.tr("Ready"))
2109 2109
2110 def __readSettings(self): 2110 def __readSettings(self):
2111 """ 2111 """
2112 Private method to read the settings remembered last time. 2112 Private method to read the settings remembered last time.
2113 """ 2113 """
2132 @return flag indicating, if it is ok to continue (boolean) 2132 @return flag indicating, if it is ok to continue (boolean)
2133 """ 2133 """
2134 if self.__textEdit.isModified(): 2134 if self.__textEdit.isModified():
2135 ret = E5MessageBox.okToClearData( 2135 ret = E5MessageBox.okToClearData(
2136 self, 2136 self,
2137 self.trUtf8("eric5 Mini Editor"), 2137 self.tr("eric5 Mini Editor"),
2138 self.trUtf8("The document has unsaved changes."), 2138 self.tr("The document has unsaved changes."),
2139 self.__save) 2139 self.__save)
2140 return ret 2140 return ret
2141 return True 2141 return True
2142 2142
2143 def __loadFile(self, fileName, filetype=None): 2143 def __loadFile(self, fileName, filetype=None):
2152 try: 2152 try:
2153 txt, self.encoding = Utilities.readEncodedFile(fileName) 2153 txt, self.encoding = Utilities.readEncodedFile(fileName)
2154 except (UnicodeDecodeError, IOError) as why: 2154 except (UnicodeDecodeError, IOError) as why:
2155 QApplication.restoreOverrideCursor() 2155 QApplication.restoreOverrideCursor()
2156 E5MessageBox.critical( 2156 E5MessageBox.critical(
2157 self, self.trUtf8('Open File'), 2157 self, self.tr('Open File'),
2158 self.trUtf8('<p>The file <b>{0}</b> could not be opened.</p>' 2158 self.tr('<p>The file <b>{0}</b> could not be opened.</p>'
2159 '<p>Reason: {1}</p>') 2159 '<p>Reason: {1}</p>')
2160 .format(fileName, str(why))) 2160 .format(fileName, str(why)))
2161 QApplication.restoreOverrideCursor() 2161 QApplication.restoreOverrideCursor()
2162 return 2162 return
2163 2163
2164 self.__textEdit.setText(txt) 2164 self.__textEdit.setText(txt)
2171 self.__setCurrentFile(fileName) 2171 self.__setCurrentFile(fileName)
2172 2172
2173 fileEol = self.__textEdit.detectEolString(txt) 2173 fileEol = self.__textEdit.detectEolString(txt)
2174 self.__textEdit.setEolModeByEolString(fileEol) 2174 self.__textEdit.setEolModeByEolString(fileEol)
2175 2175
2176 self.__statusBar.showMessage(self.trUtf8("File loaded"), 2000) 2176 self.__statusBar.showMessage(self.tr("File loaded"), 2000)
2177 2177
2178 def __saveFile(self, fileName): 2178 def __saveFile(self, fileName):
2179 """ 2179 """
2180 Private method to save to the given file. 2180 Private method to save to the given file.
2181 2181
2187 try: 2187 try:
2188 self.encoding = Utilities.writeEncodedFile( 2188 self.encoding = Utilities.writeEncodedFile(
2189 fileName, txt, self.encoding) 2189 fileName, txt, self.encoding)
2190 except (IOError, Utilities.CodingError, UnicodeError) as why: 2190 except (IOError, Utilities.CodingError, UnicodeError) as why:
2191 E5MessageBox.critical( 2191 E5MessageBox.critical(
2192 self, self.trUtf8('Save File'), 2192 self, self.tr('Save File'),
2193 self.trUtf8('<p>The file <b>{0}</b> could not be saved.<br/>' 2193 self.tr('<p>The file <b>{0}</b> could not be saved.<br/>'
2194 'Reason: {1}</p>') 2194 'Reason: {1}</p>')
2195 .format(fileName, str(why))) 2195 .format(fileName, str(why)))
2196 QApplication.restoreOverrideCursor() 2196 QApplication.restoreOverrideCursor()
2197 2197
2198 self.__checkActions() 2198 self.__checkActions()
2199 2199
2201 2201
2202 QApplication.restoreOverrideCursor() 2202 QApplication.restoreOverrideCursor()
2203 self.editorSaved.emit() 2203 self.editorSaved.emit()
2204 2204
2205 self.__setCurrentFile(fileName) 2205 self.__setCurrentFile(fileName)
2206 self.__statusBar.showMessage(self.trUtf8("File saved"), 2000) 2206 self.__statusBar.showMessage(self.tr("File saved"), 2000)
2207 2207
2208 self.__checkActions() 2208 self.__checkActions()
2209 2209
2210 return True 2210 return True
2211 2211
2216 @param fileName name of the file to register (string) 2216 @param fileName name of the file to register (string)
2217 """ 2217 """
2218 self.__curFile = fileName 2218 self.__curFile = fileName
2219 2219
2220 if not self.__curFile: 2220 if not self.__curFile:
2221 shownName = self.trUtf8("Untitled") 2221 shownName = self.tr("Untitled")
2222 else: 2222 else:
2223 shownName = self.__strippedName(self.__curFile) 2223 shownName = self.__strippedName(self.__curFile)
2224 2224
2225 self.setWindowTitle(self.trUtf8("{0}[*] - {1}") 2225 self.setWindowTitle(self.tr("{0}[*] - {1}")
2226 .format(shownName, self.trUtf8("Mini Editor"))) 2226 .format(shownName, self.tr("Mini Editor")))
2227 2227
2228 self.__textEdit.setModified(False) 2228 self.__textEdit.setModified(False)
2229 self.setWindowModified(False) 2229 self.setWindowModified(False)
2230 2230
2231 self.setLanguage(self.__bindName(self.__textEdit.text(0))) 2231 self.setLanguage(self.__bindName(self.__textEdit.text(0)))
2481 sb = self.statusBar() 2481 sb = self.statusBar()
2482 printDialog = QPrintDialog(printer, self) 2482 printDialog = QPrintDialog(printer, self)
2483 if self.__textEdit.hasSelectedText(): 2483 if self.__textEdit.hasSelectedText():
2484 printDialog.addEnabledOption(QAbstractPrintDialog.PrintSelection) 2484 printDialog.addEnabledOption(QAbstractPrintDialog.PrintSelection)
2485 if printDialog.exec_() == QDialog.Accepted: 2485 if printDialog.exec_() == QDialog.Accepted:
2486 sb.showMessage(self.trUtf8('Printing...')) 2486 sb.showMessage(self.tr('Printing...'))
2487 QApplication.processEvents() 2487 QApplication.processEvents()
2488 if self.__curFile: 2488 if self.__curFile:
2489 printer.setDocName(QFileInfo(self.__curFile).fileName()) 2489 printer.setDocName(QFileInfo(self.__curFile).fileName())
2490 else: 2490 else:
2491 printer.setDocName(self.trUtf8("Untitled")) 2491 printer.setDocName(self.tr("Untitled"))
2492 if printDialog.printRange() == QAbstractPrintDialog.Selection: 2492 if printDialog.printRange() == QAbstractPrintDialog.Selection:
2493 # get the selection 2493 # get the selection
2494 fromLine, fromIndex, toLine, toIndex = \ 2494 fromLine, fromIndex, toLine, toIndex = \
2495 self.__textEdit.getSelection() 2495 self.__textEdit.getSelection()
2496 if toIndex == 0: 2496 if toIndex == 0:
2498 # Qscintilla seems to print one line more than told 2498 # Qscintilla seems to print one line more than told
2499 res = printer.printRange(self.__textEdit, fromLine, toLine - 1) 2499 res = printer.printRange(self.__textEdit, fromLine, toLine - 1)
2500 else: 2500 else:
2501 res = printer.printRange(self.__textEdit) 2501 res = printer.printRange(self.__textEdit)
2502 if res: 2502 if res:
2503 sb.showMessage(self.trUtf8('Printing completed'), 2000) 2503 sb.showMessage(self.tr('Printing completed'), 2000)
2504 else: 2504 else:
2505 sb.showMessage(self.trUtf8('Error while printing'), 2000) 2505 sb.showMessage(self.tr('Error while printing'), 2000)
2506 QApplication.processEvents() 2506 QApplication.processEvents()
2507 else: 2507 else:
2508 sb.showMessage(self.trUtf8('Printing aborted'), 2000) 2508 sb.showMessage(self.tr('Printing aborted'), 2000)
2509 QApplication.processEvents() 2509 QApplication.processEvents()
2510 2510
2511 def __printPreviewFile(self): 2511 def __printPreviewFile(self):
2512 """ 2512 """
2513 Private slot to show a print preview of the text. 2513 Private slot to show a print preview of the text.
2517 2517
2518 printer = Printer(mode=QPrinter.HighResolution) 2518 printer = Printer(mode=QPrinter.HighResolution)
2519 if self.__curFile: 2519 if self.__curFile:
2520 printer.setDocName(QFileInfo(self.__curFile).fileName()) 2520 printer.setDocName(QFileInfo(self.__curFile).fileName())
2521 else: 2521 else:
2522 printer.setDocName(self.trUtf8("Untitled")) 2522 printer.setDocName(self.tr("Untitled"))
2523 preview = QPrintPreviewDialog(printer, self) 2523 preview = QPrintPreviewDialog(printer, self)
2524 preview.paintRequested.connect(self.__printPreview) 2524 preview.paintRequested.connect(self.__printPreview)
2525 preview.exec_() 2525 preview.exec_()
2526 2526
2527 def __printPreview(self, printer): 2527 def __printPreview(self, printer):
2558 self.contextMenu.addSeparator() 2558 self.contextMenu.addSeparator()
2559 self.contextMenu.addAction(self.cutAct) 2559 self.contextMenu.addAction(self.cutAct)
2560 self.contextMenu.addAction(self.copyAct) 2560 self.contextMenu.addAction(self.copyAct)
2561 self.contextMenu.addAction(self.pasteAct) 2561 self.contextMenu.addAction(self.pasteAct)
2562 self.contextMenu.addSeparator() 2562 self.contextMenu.addSeparator()
2563 self.contextMenu.addAction(self.trUtf8('Select all'), self.__selectAll) 2563 self.contextMenu.addAction(self.tr('Select all'), self.__selectAll)
2564 self.contextMenu.addAction( 2564 self.contextMenu.addAction(
2565 self.trUtf8('Deselect all'), self.__deselectAll) 2565 self.tr('Deselect all'), self.__deselectAll)
2566 self.contextMenu.addSeparator() 2566 self.contextMenu.addSeparator()
2567 self.languagesMenuAct = self.contextMenu.addMenu(self.languagesMenu) 2567 self.languagesMenuAct = self.contextMenu.addMenu(self.languagesMenu)
2568 self.contextMenu.addSeparator() 2568 self.contextMenu.addSeparator()
2569 self.contextMenu.addAction(self.printPreviewAct) 2569 self.contextMenu.addAction(self.printPreviewAct)
2570 self.contextMenu.addAction(self.printAct) 2570 self.contextMenu.addAction(self.printAct)
2573 """ 2573 """
2574 Private method used to setup the Languages context sub menu. 2574 Private method used to setup the Languages context sub menu.
2575 2575
2576 @return reference to the generated menu (QMenu) 2576 @return reference to the generated menu (QMenu)
2577 """ 2577 """
2578 menu = QMenu(self.trUtf8("Languages")) 2578 menu = QMenu(self.tr("Languages"))
2579 2579
2580 self.languagesActGrp = QActionGroup(self) 2580 self.languagesActGrp = QActionGroup(self)
2581 self.noLanguageAct = menu.addAction(self.trUtf8("No Language")) 2581 self.noLanguageAct = menu.addAction(self.tr("No Language"))
2582 self.noLanguageAct.setCheckable(True) 2582 self.noLanguageAct.setCheckable(True)
2583 self.noLanguageAct.setData("None") 2583 self.noLanguageAct.setData("None")
2584 self.languagesActGrp.addAction(self.noLanguageAct) 2584 self.languagesActGrp.addAction(self.noLanguageAct)
2585 menu.addSeparator() 2585 menu.addSeparator()
2586 2586
2599 act.setData(language) 2599 act.setData(language)
2600 self.supportedLanguages[language].append(act) 2600 self.supportedLanguages[language].append(act)
2601 self.languagesActGrp.addAction(act) 2601 self.languagesActGrp.addAction(act)
2602 2602
2603 menu.addSeparator() 2603 menu.addSeparator()
2604 self.pygmentsAct = menu.addAction(self.trUtf8("Guessed")) 2604 self.pygmentsAct = menu.addAction(self.tr("Guessed"))
2605 self.pygmentsAct.setCheckable(True) 2605 self.pygmentsAct.setCheckable(True)
2606 self.pygmentsAct.setData("Guessed") 2606 self.pygmentsAct.setData("Guessed")
2607 self.languagesActGrp.addAction(self.pygmentsAct) 2607 self.languagesActGrp.addAction(self.pygmentsAct)
2608 self.pygmentsSelAct = menu.addAction(self.trUtf8("Alternatives")) 2608 self.pygmentsSelAct = menu.addAction(self.tr("Alternatives"))
2609 self.pygmentsSelAct.setData("Alternatives") 2609 self.pygmentsSelAct.setData("Alternatives")
2610 2610
2611 menu.triggered.connect(self.__languageMenuTriggered) 2611 menu.triggered.connect(self.__languageMenuTriggered)
2612 menu.aboutToShow.connect(self.__showContextMenuLanguages) 2612 menu.aboutToShow.connect(self.__showContextMenuLanguages)
2613 2613
2618 Private slot handling the aboutToShow signal of the languages context 2618 Private slot handling the aboutToShow signal of the languages context
2619 menu. 2619 menu.
2620 """ 2620 """
2621 if self.apiLanguage.startswith("Pygments|"): 2621 if self.apiLanguage.startswith("Pygments|"):
2622 self.pygmentsSelAct.setText( 2622 self.pygmentsSelAct.setText(
2623 self.trUtf8("Alternatives ({0})").format(self.getLanguage())) 2623 self.tr("Alternatives ({0})").format(self.getLanguage()))
2624 else: 2624 else:
2625 self.pygmentsSelAct.setText(self.trUtf8("Alternatives")) 2625 self.pygmentsSelAct.setText(self.tr("Alternatives"))
2626 2626
2627 def __selectPygmentsLexer(self): 2627 def __selectPygmentsLexer(self):
2628 """ 2628 """
2629 Private method to select a specific pygments lexer. 2629 Private method to select a specific pygments lexer.
2630 2630
2636 lexerSel = lexerList.index(self.getLanguage()) 2636 lexerSel = lexerList.index(self.getLanguage())
2637 except ValueError: 2637 except ValueError:
2638 lexerSel = 0 2638 lexerSel = 0
2639 lexerName, ok = QInputDialog.getItem( 2639 lexerName, ok = QInputDialog.getItem(
2640 self, 2640 self,
2641 self.trUtf8("Pygments Lexer"), 2641 self.tr("Pygments Lexer"),
2642 self.trUtf8("Select the Pygments lexer to apply."), 2642 self.tr("Select the Pygments lexer to apply."),
2643 lexerList, 2643 lexerList,
2644 lexerSel, 2644 lexerSel,
2645 False) 2645 False)
2646 if ok and lexerName: 2646 if ok and lexerName:
2647 return lexerName 2647 return lexerName

eric ide

mercurial