<commit_before>"""
This module contains the definition of the QCodeEdit
"""
import logging
import sys
import pcef
from pcef.qt import QtGui, QtCore
from pcef.core import constants
from pcef.core.constants import PanelPosition, CODE_EDIT_STYLESHEET
from pcef.core.properties import PropertyRegistry


class QCodeEdit(QtGui.QPlainTextEdit):
    """
    This is the core code editor widget which inherits from a QPlainTextEdit

    The code editor provides a series of additional slots specifically suited
    for code edition:
        - keyboard events
        - mouse events
        - save / dirty events

    The widget appearance and behaviour can be customised by adding modes and
    panels (editor extensions).

    Panels are drawn in the document margin by the panel manager.

    The widget also provides a series of convenience methods to:
        - open/save a file
        - manipulate the text cursor / getting text informations (line, col,...)

    The widget exposes a style property which is a dictionary of properties
    (more about this topic in the style section)
    """
    #: Paint hook
    painted = QtCore.Signal(QtGui.QPaintEvent)
    #: Signal emitted when a new text is set on the widget
    newTextSet = QtCore.Signal()
    #: Signal emitted when the text is saved
    textSaved = QtCore.Signal(str)
    #: Signal emitted when the dirty state changed
    dirtyChanged = QtCore.Signal(bool)
    #: Signal emitted when a key is pressed
    keyPressed = QtCore.Signal(QtGui.QKeyEvent)
    #: Signal emitted when a key is released
    keyReleased = QtCore.Signal(QtGui.QKeyEvent)
    #: Signal emitted when a mouse button is pressed
    mousePressed = QtCore.Signal(QtGui.QMouseEvent)
    #: Signal emitted when a mouse button is released
    mouseReleased = QtCore.Signal(QtGui.QMouseEvent)
    #: Signal emitted on a wheel event
    mouseWheelActivated = QtCore.Signal(QtGui.QWheelEvent)
    #: Signal emitted at the end of the keyPressed event
    postKeyPressed = QtCore.Signal(QtGui.QKeyEvent)
    #: Signal emitted when focusInEvent is is called
    focusedIn = QtCore.Signal(QtGui.QFocusEvent)
    #: Signal emitted when the mouseMoved
    mouseMoved = QtCore.Signal(QtGui.QMouseEvent)

    @property
    def dirty(self):
        """
        Gets the dirty flag
        """
        return self.__dirty

    @dirty.setter
    def dirty(self, value):
        """
        Sets the dirty flag,

        .. note: The dirtyChanged signal is emitted if the new value is
                 different from the current value

        :param value: The new value
        """
        if self.__dirty != value:
            self.__dirty = value
            self.dirtyChanged.emit(value)

    @property
    def cursorPosition(self):
        """
        Returns the text cursor position (line, column)

        :return: The cursor position (line, column)
        :rtype: tuple(int, int)
        """
        return (self.textCursor().blockNumber() + 1,
                self.textCursor().columnNumber())

    @property
    def fileName(self):
        """
        Returns the file name (see QFileInfo.fileName)
        """
        return QtCore.QFileInfo(self.filePath).fileName()

    @property
    def filePath(self):
        """
        Returns the file path
        """
        return self.__filePath

    @property
    def fileEncoding(self):
        """
        Returns last encoding used to open the file
        """
        return self.__fileEncoding

    @property
    def visibleBlocks(self):
        """
        Returns the list of visible blocks/lines

        Each block is a tuple made up of the line top position and the line
        number (already 1 based)

        :return: A list of tuple(top position, line number)
        :rtype List of tuple(int, int)
        """
        return self.__blocks

    def __init__(self, parent=None):
        """
        :param parent: QWidget
        """
        QtGui.QPlainTextEdit.__init__(self, parent)
        #: The list of visible blocks, update every paintEvent
        self.__blocks = []

        #: The custom context menu
        self.contextMenu = QtGui.QMenu()
        # a.setIconVisibleInMenu(True)

        a = QtGui.QAction(QtGui.QIcon(constants.ICON_UNDO[0]), "Undo", self)
        a.setShortcut(constants.ICON_UNDO[1])
        a.setIconVisibleInMenu(True)
        a.triggered.connect(self.undo)
        self.undoAvailable.connect(a.setEnabled)
        self.contextMenu.addAction(a)

        a = QtGui.QAction(QtGui.QIcon(constants.ICON_REDO[0]), "Redo", self)
        a.setShortcut(constants.ICON_REDO[1])
        a.setIconVisibleInMenu(True)
        a.triggered.connect(self.redo)
        self.redoAvailable.connect(a.setEnabled)
        self.contextMenu.addAction(a)
<commit_msg>Set editor context menu title to "Edit"<commit_after>"""
This module contains the definition of the QCodeEdit
"""
import logging
import sys
import pcef
from pcef.qt import QtGui, QtCore
from pcef.core import constants
from pcef.core.constants import PanelPosition, CODE_EDIT_STYLESHEET
from pcef.core.properties import PropertyRegistry


class QCodeEdit(QtGui.QPlainTextEdit):
    """
    This is the core code editor widget which inherits from a QPlainTextEdit

    The code editor provides a series of additional slots specifically suited
    for code edition:
        - keyboard events
        - mouse events
        - save / dirty events

    The widget appearance and behaviour can be customised by adding modes and
    panels (editor extensions).

    Panels are drawn in the document margin by the panel manager.

    The widget also provides a series of convenience methods to:
        - open/save a file
        - manipulate the text cursor / getting text informations (line, col,...)

    The widget exposes a style property which is a dictionary of properties
    (more about this topic in the style section)
    """
    #: Paint hook
    painted = QtCore.Signal(QtGui.QPaintEvent)
    #: Signal emitted when a new text is set on the widget
    newTextSet = QtCore.Signal()
    #: Signal emitted when the text is saved
    textSaved = QtCore.Signal(str)
    #: Signal emitted when the dirty state changed
    dirtyChanged = QtCore.Signal(bool)
    #: Signal emitted when a key is pressed
    keyPressed = QtCore.Signal(QtGui.QKeyEvent)
    #: Signal emitted when a key is released
    keyReleased = QtCore.Signal(QtGui.QKeyEvent)
    #: Signal emitted when a mouse button is pressed
    mousePressed = QtCore.Signal(QtGui.QMouseEvent)
    #: Signal emitted when a mouse button is released
    mouseReleased = QtCore.Signal(QtGui.QMouseEvent)
    #: Signal emitted on a wheel event
    mouseWheelActivated = QtCore.Signal(QtGui.QWheelEvent)
    #: Signal emitted at the end of the keyPressed event
    postKeyPressed = QtCore.Signal(QtGui.QKeyEvent)
    #: Signal emitted when focusInEvent is is called
    focusedIn = QtCore.Signal(QtGui.QFocusEvent)
    #: Signal emitted when the mouseMoved
    mouseMoved = QtCore.Signal(QtGui.QMouseEvent)

    @property
    def dirty(self):
        """
        Gets the dirty flag
        """
        return self.__dirty

    @dirty.setter
    def dirty(self, value):
        """
        Sets the dirty flag,

        .. note: The dirtyChanged signal is emitted if the new value is
                 different from the current value

        :param value: The new value
        """
        if self.__dirty != value:
            self.__dirty = value
            self.dirtyChanged.emit(value)

    @property
    def cursorPosition(self):
        """
        Returns the text cursor position (line, column)

        :return: The cursor position (line, column)
        :rtype: tuple(int, int)
        """
        return (self.textCursor().blockNumber() + 1,
                self.textCursor().columnNumber())

    @property
    def fileName(self):
        """
        Returns the file name (see QFileInfo.fileName)
        """
        return QtCore.QFileInfo(self.filePath).fileName()

    @property
    def filePath(self):
        """
        Returns the file path
        """
        return self.__filePath

    @property
    def fileEncoding(self):
        """
        Returns last encoding used to open the file
        """
        return self.__fileEncoding

    @property
    def visibleBlocks(self):
        """
        Returns the list of visible blocks/lines

        Each block is a tuple made up of the line top position and the line
        number (already 1 based)

        :return: A list of tuple(top position, line number)
        :rtype List of tuple(int, int)
        """
        return self.__blocks

    def __init__(self, parent=None):
        """
        :param parent: QWidget
        """
        QtGui.QPlainTextEdit.__init__(self, parent)
        #: The list of visible blocks, update every paintEvent
        self.__blocks = []

        #: The custom context menu
        self.contextMenu = QtGui.QMenu()
        self.contextMenu.setTitle("Edit")

        a = QtGui.QAction(QtGui.QIcon(constants.ICON_UNDO[0]), "Undo", self)
        a.setShortcut(constants.ICON_UNDO[1])
        a.setIconVisibleInMenu(True)
        a.triggered.connect(self.undo)
        self.undoAvailable.connect(a.setEnabled)
        self.contextMenu.addAction(a)

        a = QtGui.QAction(QtGui.QIcon(constants.ICON_REDO[0]), "Redo", self)
        a.setShortcut(constants.ICON_REDO[1])
        a.setIconVisibleInMenu(True)
        a.triggered.connect(self.redo)
        self.redoAvailable.connect(a.setEnabled)
        self.contextMenu.addAction(a)

{'fraction_non_alphanumeric': 0.08082923254109517, 'fraction_numerical': 0.001256412941053293, 'mean_word_length': 2.4976199194434274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6231557', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2615, 'n_words': 864}