--- a/eric6/QScintilla/MiniEditor.py Tue Oct 06 18:16:00 2020 +0200 +++ b/eric6/QScintilla/MiniEditor.py Tue Oct 06 19:10:28 2020 +0200 @@ -111,7 +111,6 @@ self.endUndoAction() -# TODO: add zoom actions and view menu class MiniEditor(E5MainWindow): """ Class implementing a minimalistic editor for simple editing tasks. @@ -158,6 +157,8 @@ self.text = self.__textEdit.text self.getZoom = self.__textEdit.getZoom self.zoomTo = self.__textEdit.zoomTo + self.zoomIn = self.__textEdit.zoomIn + self.zoomOut = self.__textEdit.zoomOut self.__curFile = filename self.__lastLine = 0 @@ -456,11 +457,13 @@ self.editActions = [] self.helpActions = [] self.searchActions = [] + self.viewActions = [] self.__createFileActions() self.__createEditActions() self.__createHelpActions() self.__createSearchActions() + self.__createViewActions() # read the keyboard shortcuts and make them identical to the main # eric6 shortcuts @@ -472,6 +475,8 @@ self.__readShortcut(act, "File") for act in self.searchActions: self.__readShortcut(act, "Search") + for act in self.viewActions: + self.__readShortcut(act, "View") def __createFileActions(self): """ @@ -2201,6 +2206,86 @@ self.__replaceWidget.replaceAll) self.searchActions.append(self.replaceAllAct) + def __createViewActions(self): + """ + Private method to create the View actions. + """ + self.zoomInAct = E5Action( + QCoreApplication.translate('ViewManager', 'Zoom in'), + UI.PixmapCache.getIcon("zoomIn"), + QCoreApplication.translate('ViewManager', 'Zoom &in'), + QKeySequence(QCoreApplication.translate( + 'ViewManager', "Ctrl++", "View|Zoom in")), + QKeySequence(QCoreApplication.translate( + 'ViewManager', "Zoom In", "View|Zoom in")), + self, 'vm_view_zoom_in') + self.zoomInAct.setStatusTip(QCoreApplication.translate( + 'ViewManager', 'Zoom in on the text')) + self.zoomInAct.setWhatsThis(QCoreApplication.translate( + 'ViewManager', + """<b>Zoom in</b>""" + """<p>Zoom in on the text. This makes the text bigger.</p>""" + )) + self.zoomInAct.triggered.connect(self.__zoomIn) + self.viewActions.append(self.zoomInAct) + + self.zoomOutAct = E5Action( + QCoreApplication.translate('ViewManager', 'Zoom out'), + UI.PixmapCache.getIcon("zoomOut"), + QCoreApplication.translate('ViewManager', 'Zoom &out'), + QKeySequence(QCoreApplication.translate( + 'ViewManager', "Ctrl+-", "View|Zoom out")), + QKeySequence(QCoreApplication.translate( + 'ViewManager', "Zoom Out", "View|Zoom out")), + self, 'vm_view_zoom_out') + self.zoomOutAct.setStatusTip(QCoreApplication.translate( + 'ViewManager', 'Zoom out on the text')) + self.zoomOutAct.setWhatsThis(QCoreApplication.translate( + 'ViewManager', + """<b>Zoom out</b>""" + """<p>Zoom out on the text. This makes the text smaller.</p>""" + )) + self.zoomOutAct.triggered.connect(self.__zoomOut) + self.viewActions.append(self.zoomOutAct) + + self.zoomResetAct = E5Action( + QCoreApplication.translate('ViewManager', 'Zoom reset'), + UI.PixmapCache.getIcon("zoomReset"), + QCoreApplication.translate('ViewManager', 'Zoom &reset'), + QKeySequence(QCoreApplication.translate( + 'ViewManager', "Ctrl+0", "View|Zoom reset")), + 0, + self, 'vm_view_zoom_reset') + self.zoomResetAct.setStatusTip(QCoreApplication.translate( + 'ViewManager', 'Reset the zoom of the text')) + self.zoomResetAct.setWhatsThis(QCoreApplication.translate( + 'ViewManager', + """<b>Zoom reset</b>""" + """<p>Reset the zoom of the text. """ + """This sets the zoom factor to 100%.</p>""" + )) + self.zoomResetAct.triggered.connect(self.__zoomReset) + self.viewActions.append(self.zoomResetAct) + + self.zoomToAct = E5Action( + QCoreApplication.translate('ViewManager', 'Zoom'), + UI.PixmapCache.getIcon("zoomTo"), + QCoreApplication.translate('ViewManager', '&Zoom'), + QKeySequence(QCoreApplication.translate( + 'ViewManager', "Ctrl+#", "View|Zoom")), + 0, + self, 'vm_view_zoom') + self.zoomToAct.setStatusTip(QCoreApplication.translate( + 'ViewManager', 'Zoom the text')) + self.zoomToAct.setWhatsThis(QCoreApplication.translate( + 'ViewManager', + """<b>Zoom</b>""" + """<p>Zoom the text. This opens a dialog where the""" + """ desired size can be entered.</p>""" + )) + self.zoomToAct.triggered.connect(self.__zoom) + self.viewActions.append(self.zoomToAct) + def __createHelpActions(self): """ Private method to create the Help actions. @@ -2283,6 +2368,12 @@ self.editMenu.addAction(self.replaceSelectionAct) self.editMenu.addAction(self.replaceAllAct) + self.viewMenu = self.menuBar().addMenu(self.tr("&View")) + self.viewMenu.addAction(self.zoomInAct) + self.viewMenu.addAction(self.zoomOutAct) + self.viewMenu.addAction(self.zoomResetAct) + self.viewMenu.addAction(self.zoomToAct) + self.menuBar().addSeparator() self.helpMenu = self.menuBar().addMenu(self.tr("&Help")) @@ -2327,6 +2418,13 @@ findtb.addAction(self.searchPrevAct) findtb.addAction(self.searchClearMarkersAct) + viewtb = self.addToolBar(self.tr("View")) + viewtb.setIconSize(UI.Config.ToolBarIconSize) + viewtb.addAction(self.zoomInAct) + viewtb.addAction(self.zoomOutAct) + viewtb.addAction(self.zoomResetAct) + viewtb.addAction(self.zoomToAct) + helptb = self.addToolBar(self.tr("Help")) helptb.setIconSize(UI.Config.ToolBarIconSize) helptb.addAction(self.whatsThisAct) @@ -2374,8 +2472,8 @@ self.__statusBar) self.__statusBar.addPermanentWidget(self.sbZoom) self.sbZoom.setWhatsThis(self.tr( - """<p>This part of the status bar allows zooming the current""" - """ editor or shell.</p>""" + """<p>This part of the status bar allows zooming the editor.""" + """</p>""" )) self.sbZoom.valueChanged.connect(self.__zoomTo) @@ -3675,6 +3773,36 @@ ####################################################################### ## Methods supporting zooming ####################################################################### + + def __zoomIn(self): + """ + Private method to handle the zoom in action. + """ + self.zoomIn() + self.sbZoom.setValue(self.getZoom()) + + def __zoomOut(self): + """ + Private method to handle the zoom out action. + """ + self.zoomOut() + self.sbZoom.setValue(self.getZoom()) + + def __zoomReset(self): + """ + Private method to reset the zoom factor. + """ + self.__zoomTo(0) + + def __zoom(self): + """ + Private method to handle the zoom action. + """ + from QScintilla.ZoomDialog import ZoomDialog + dlg = ZoomDialog(self.getZoom(), self, None, True) + if dlg.exec_() == QDialog.Accepted: + value = dlg.getZoomSize() + self.__zoomTo(value) def __zoomTo(self, value): """