From 2955afe45ea6a36c5a242d467d8a93ee850263f4 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Wed, 25 May 2016 12:08:59 +0200 Subject: [PATCH] New multi line editor Supports zooming in and out with ctrl+scroll. It is a bit hacky, since I use sed in make to make it work, but whatever. --- Makefile | 2 ++ relational_gui/editor.py | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 relational_gui/editor.py diff --git a/Makefile b/Makefile index 37bd57c..3d99b8b 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ pyqt: pyuic5 relational_gui/maingui.ui > relational_gui/maingui.py pyuic5 relational_gui/rel_edit.ui > relational_gui/rel_edit.py pyrcc5 relational_gui/resources.qrc > relational_gui/resources.py + sed -i 's/QtWidgets.QPlainTextEdit/editor.Editor/g' relational_gui/maingui.py + echo 'from . import editor' >> relational_gui/maingui.py dist: clean rm -rf /tmp/relational/ diff --git a/relational_gui/editor.py b/relational_gui/editor.py new file mode 100644 index 0000000..f6b1ee3 --- /dev/null +++ b/relational_gui/editor.py @@ -0,0 +1,43 @@ +# Relational +# Copyright (C) 2016 Salvo "LtWorf" Tomaselli +# +# Relational is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# author Salvo "LtWorf" Tomaselli +# +# This module provides a classes to represent relations and to perform +# relational operations on them. + +from PyQt5.QtWidgets import QPlainTextEdit +from PyQt5.QtCore import Qt + + +class Editor(QPlainTextEdit): + + def __init__(self, *args, **kwargs): + super(Editor, self).__init__(*args, **kwargs) + + def wheelEvent(self, event): + if event.modifiers() & Qt.ControlModifier: + event.accept() + self.zoom(1 if event.angleDelta().y()>0 else -1) + else: + super(Editor, self).wheelEvent(event) + + def zoom(self, incr): + font = self.font() + point_size = font.pointSize() + point_size += incr + font.setPointSize(point_size) + self.setFont(font)