12 import contextlib |
12 import contextlib |
13 |
13 |
14 import editorconfig |
14 import editorconfig |
15 |
15 |
16 from PyQt6.QtCore import ( |
16 from PyQt6.QtCore import ( |
17 pyqtSignal, Qt, QSignalMapper, QPoint, QTimer, QFileInfo, QSize, |
17 pyqtSignal, pyqtSlot, Qt, QSignalMapper, QPoint, QTimer, QFileInfo, QSize, |
18 QCoreApplication |
18 QCoreApplication |
19 ) |
19 ) |
20 from PyQt6.QtGui import QKeySequence, QPalette, QFont, QPixmap, QActionGroup |
20 from PyQt6.QtGui import ( |
|
21 QKeySequence, QPalette, QFont, QPixmap, QActionGroup, QAction |
|
22 ) |
21 from PyQt6.QtWidgets import ( |
23 from PyQt6.QtWidgets import ( |
22 QWidget, QWhatsThis, QDialog, QInputDialog, QApplication, |
24 QWidget, QWhatsThis, QDialog, QInputDialog, QApplication, |
23 QMenu, QVBoxLayout, QHBoxLayout, QLabel |
25 QMenu, QVBoxLayout, QHBoxLayout, QLabel |
24 ) |
26 ) |
25 from PyQt6.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog |
27 from PyQt6.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog |
304 self.__createActions() |
306 self.__createActions() |
305 self.__createMenus() |
307 self.__createMenus() |
306 self.__createToolBars() |
308 self.__createToolBars() |
307 self.__createStatusBar() |
309 self.__createStatusBar() |
308 |
310 |
309 self.__setTextDisplay() |
311 self.__loadConfiguration() |
310 self.__setMargins() |
|
311 self.__setEolMode() |
|
312 |
|
313 self.__readSettings() |
312 self.__readSettings() |
314 |
313 |
315 # clear QScintilla defined keyboard commands |
314 # clear QScintilla defined keyboard commands |
316 # we do our own handling through the view manager |
315 # we do our own handling through the view manager |
317 self.__textEdit.clearAlternateKeys() |
316 self.__textEdit.clearAlternateKeys() |
559 self.fileActions = [] |
558 self.fileActions = [] |
560 self.editActions = [] |
559 self.editActions = [] |
561 self.helpActions = [] |
560 self.helpActions = [] |
562 self.searchActions = [] |
561 self.searchActions = [] |
563 self.viewActions = [] |
562 self.viewActions = [] |
|
563 self.configActions = [] |
564 |
564 |
565 self.__createFileActions() |
565 self.__createFileActions() |
566 self.__createEditActions() |
566 self.__createEditActions() |
567 self.__createHelpActions() |
567 self.__createHelpActions() |
568 self.__createSearchActions() |
568 self.__createSearchActions() |
569 self.__createViewActions() |
569 self.__createViewActions() |
|
570 self.__createConfigActions() |
570 |
571 |
571 # read the keyboard shortcuts and make them identical to the main |
572 # read the keyboard shortcuts and make them identical to the main |
572 # eric shortcuts |
573 # eric shortcuts |
573 for act in self.helpActions: |
574 for act in self.helpActions + self.configActions: |
574 self.__readShortcut(act, "General") |
575 self.__readShortcut(act, "General") |
575 for act in self.editActions: |
576 for act in self.editActions: |
576 self.__readShortcut(act, "Edit") |
577 self.__readShortcut(act, "Edit") |
577 for act in self.fileActions: |
578 for act in self.fileActions: |
578 self.__readShortcut(act, "File") |
579 self.__readShortcut(act, "File") |
2437 """</p>""" |
2438 """</p>""" |
2438 )) |
2439 )) |
2439 self.whatsThisAct.triggered.connect(self.__whatsThis) |
2440 self.whatsThisAct.triggered.connect(self.__whatsThis) |
2440 self.helpActions.append(self.whatsThisAct) |
2441 self.helpActions.append(self.whatsThisAct) |
2441 |
2442 |
|
2443 def __createConfigActions(self): |
|
2444 """ |
|
2445 Private method to create the Settings actions. |
|
2446 """ |
|
2447 self.prefAct = EricAction( |
|
2448 self.tr('Preferences'), |
|
2449 UI.PixmapCache.getIcon("configure"), |
|
2450 self.tr('&Preferences...'), |
|
2451 0, 0, self, 'hexEditor_settings_preferences') |
|
2452 self.prefAct.setStatusTip(self.tr( |
|
2453 'Set the prefered configuration')) |
|
2454 self.prefAct.setWhatsThis(self.tr( |
|
2455 """<b>Preferences</b>""" |
|
2456 """<p>Set the configuration items of the application""" |
|
2457 """ with your prefered values.</p>""" |
|
2458 )) |
|
2459 self.prefAct.triggered.connect(self.__showPreferences) |
|
2460 self.prefAct.setMenuRole(QAction.MenuRole.PreferencesRole) |
|
2461 self.configActions.append(self.prefAct) |
|
2462 |
2442 def __createMenus(self): |
2463 def __createMenus(self): |
2443 """ |
2464 """ |
2444 Private method to create the menus of the menu bar. |
2465 Private method to create the menus of the menu bar. |
2445 """ |
2466 """ |
2446 self.fileMenu = self.menuBar().addMenu(self.tr("&File")) |
2467 self.fileMenu = self.menuBar().addMenu(self.tr("&File")) |
2462 self.editMenu.addAction(self.cutAct) |
2483 self.editMenu.addAction(self.cutAct) |
2463 self.editMenu.addAction(self.copyAct) |
2484 self.editMenu.addAction(self.copyAct) |
2464 self.editMenu.addAction(self.pasteAct) |
2485 self.editMenu.addAction(self.pasteAct) |
2465 self.editMenu.addAction(self.deleteAct) |
2486 self.editMenu.addAction(self.deleteAct) |
2466 self.editMenu.addSeparator() |
2487 self.editMenu.addSeparator() |
2467 self.editMenu.addAction(self.searchAct) |
2488 |
2468 self.editMenu.addAction(self.searchNextAct) |
2489 self.searchMenu = self.menuBar().addMenu(self.tr("&Search")) |
2469 self.editMenu.addAction(self.searchPrevAct) |
2490 self.searchMenu.addAction(self.searchAct) |
2470 self.editMenu.addAction(self.searchClearMarkersAct) |
2491 self.searchMenu.addAction(self.searchNextAct) |
2471 self.editMenu.addAction(self.replaceAct) |
2492 self.searchMenu.addAction(self.searchPrevAct) |
2472 self.editMenu.addAction(self.replaceAndSearchAct) |
2493 self.searchMenu.addAction(self.searchClearMarkersAct) |
2473 self.editMenu.addAction(self.replaceSelectionAct) |
2494 self.searchMenu.addAction(self.replaceAct) |
2474 self.editMenu.addAction(self.replaceAllAct) |
2495 self.searchMenu.addAction(self.replaceAndSearchAct) |
|
2496 self.searchMenu.addAction(self.replaceSelectionAct) |
|
2497 self.searchMenu.addAction(self.replaceAllAct) |
2475 |
2498 |
2476 self.viewMenu = self.menuBar().addMenu(self.tr("&View")) |
2499 self.viewMenu = self.menuBar().addMenu(self.tr("&View")) |
2477 self.viewMenu.addAction(self.zoomInAct) |
2500 self.viewMenu.addAction(self.zoomInAct) |
2478 self.viewMenu.addAction(self.zoomOutAct) |
2501 self.viewMenu.addAction(self.zoomOutAct) |
2479 self.viewMenu.addAction(self.zoomResetAct) |
2502 self.viewMenu.addAction(self.zoomResetAct) |
2480 self.viewMenu.addAction(self.zoomToAct) |
2503 self.viewMenu.addAction(self.zoomToAct) |
2481 |
2504 |
|
2505 self.settingsMenu = self.menuBar().addMenu(self.tr("Se&ttings")) |
|
2506 self.settingsMenu.addAction(self.prefAct) |
|
2507 |
2482 self.menuBar().addSeparator() |
2508 self.menuBar().addSeparator() |
2483 |
2509 |
2484 self.helpMenu = self.menuBar().addMenu(self.tr("&Help")) |
2510 self.helpMenu = self.menuBar().addMenu(self.tr("&Help")) |
2485 self.helpMenu.addAction(self.aboutAct) |
2511 self.helpMenu.addAction(self.aboutAct) |
2486 self.helpMenu.addAction(self.aboutQtAct) |
2512 self.helpMenu.addAction(self.aboutQtAct) |
2514 edittb.addAction(self.cutAct) |
2540 edittb.addAction(self.cutAct) |
2515 edittb.addAction(self.copyAct) |
2541 edittb.addAction(self.copyAct) |
2516 edittb.addAction(self.pasteAct) |
2542 edittb.addAction(self.pasteAct) |
2517 edittb.addAction(self.deleteAct) |
2543 edittb.addAction(self.deleteAct) |
2518 |
2544 |
2519 findtb = self.addToolBar(self.tr("Find")) |
2545 findtb = self.addToolBar(self.tr("Search")) |
2520 findtb.setIconSize(UI.Config.ToolBarIconSize) |
2546 findtb.setIconSize(UI.Config.ToolBarIconSize) |
2521 findtb.addAction(self.searchAct) |
2547 findtb.addAction(self.searchAct) |
2522 findtb.addAction(self.searchNextAct) |
2548 findtb.addAction(self.searchNextAct) |
2523 findtb.addAction(self.searchPrevAct) |
2549 findtb.addAction(self.searchPrevAct) |
2524 findtb.addAction(self.searchClearMarkersAct) |
2550 findtb.addAction(self.searchClearMarkersAct) |
2527 viewtb.setIconSize(UI.Config.ToolBarIconSize) |
2553 viewtb.setIconSize(UI.Config.ToolBarIconSize) |
2528 viewtb.addAction(self.zoomInAct) |
2554 viewtb.addAction(self.zoomInAct) |
2529 viewtb.addAction(self.zoomOutAct) |
2555 viewtb.addAction(self.zoomOutAct) |
2530 viewtb.addAction(self.zoomResetAct) |
2556 viewtb.addAction(self.zoomResetAct) |
2531 viewtb.addAction(self.zoomToAct) |
2557 viewtb.addAction(self.zoomToAct) |
|
2558 |
|
2559 settingstb = self.addToolBar(self.tr("Settings")) |
|
2560 settingstb.setIconSize(UI.Config.ToolBarIconSize) |
|
2561 settingstb.addAction(self.prefAct) |
2532 |
2562 |
2533 helptb = self.addToolBar(self.tr("Help")) |
2563 helptb = self.addToolBar(self.tr("Help")) |
2534 helptb.setIconSize(UI.Config.ToolBarIconSize) |
2564 helptb.setIconSize(UI.Config.ToolBarIconSize) |
2535 helptb.addAction(self.whatsThisAct) |
2565 helptb.addAction(self.whatsThisAct) |
2536 |
2566 |
2581 """</p>""" |
2611 """</p>""" |
2582 )) |
2612 )) |
2583 self.sbZoom.valueChanged.connect(self.__zoomTo) |
2613 self.sbZoom.valueChanged.connect(self.__zoomTo) |
2584 |
2614 |
2585 self.__statusBar.showMessage(self.tr("Ready")) |
2615 self.__statusBar.showMessage(self.tr("Ready")) |
|
2616 |
|
2617 def __showPreferences(self): |
|
2618 """ |
|
2619 Private slot to set the preferences. |
|
2620 """ |
|
2621 from Preferences.ConfigurationDialog import ( |
|
2622 ConfigurationDialog, ConfigurationMode |
|
2623 ) |
|
2624 dlg = ConfigurationDialog( |
|
2625 None, 'Configuration', True, fromEric=True, |
|
2626 displayMode=ConfigurationMode.EDITORMODE) |
|
2627 dlg.preferencesChanged.connect(self.__preferencesChanged) |
|
2628 dlg.show() |
|
2629 dlg.showConfigurationPageByName("interfacePage") |
|
2630 dlg.exec() |
|
2631 QCoreApplication.processEvents() |
|
2632 if dlg.result() == QDialog.DialogCode.Accepted: |
|
2633 dlg.setPreferences() |
|
2634 Preferences.syncPreferences() |
|
2635 self.__preferencesChanged() |
|
2636 |
|
2637 @pyqtSlot() |
|
2638 def __preferencesChanged(self): |
|
2639 """ |
|
2640 Private slot to handle a configuration change. |
|
2641 """ |
|
2642 self.__loadConfiguration() |
|
2643 |
|
2644 self.__markOccurrencesTimer.setInterval( |
|
2645 Preferences.getEditor("MarkOccurrencesTimeout")) |
|
2646 |
|
2647 @pyqtSlot() |
|
2648 def __loadConfiguration(self): |
|
2649 """ |
|
2650 Private slot to load the configuration. |
|
2651 """ |
|
2652 self.__setTextDisplay() |
|
2653 self.__setMargins() |
|
2654 self.__setEolMode() |
2586 |
2655 |
2587 def __readSettings(self): |
2656 def __readSettings(self): |
2588 """ |
2657 """ |
2589 Private method to read the settings remembered last time. |
2658 Private method to read the settings remembered last time. |
2590 """ |
2659 """ |