<commit_before>from __future__ import absolute_import, division, print_function, unicode_literals
import logging
import os

from PySide import QtGui, QtCore
from PySide.QtCore import Qt

from mcedit2 import editortools
from mcedit2.command import SimpleRevisionCommand
from mcedit2.rendering.blockmodels import BlockModels
from mcedit2.panels.player import PlayerPanel
from mcedit2.util.dialogs import NotImplementedYet
from mcedit2.util.resources import resourcePath
from mcedit2.util.showprogress import showProgress
from mcedit2.util.undostack import MCEUndoStack
from mcedit2.worldview.worldview import UseToolMouseAction, TrackingMouseAction
from mceditlib import util
from mcedit2.rendering import chunkloader, blockmeshes, scenegraph
from mcedit2.rendering.geometrycache import GeometryCache
from mcedit2.rendering.textureatlas import TextureAtlas
from mcedit2.widgets.layout import Column, Row
from mcedit2.util.settings import Settings
from mcedit2.worldview.camera import CameraWorldViewFrame
from mcedit2.worldview.cutaway import CutawayWorldViewFrame
from mcedit2.worldview.minimap import MinimapWorldView
from mcedit2.worldview.overhead import OverheadWorldViewFrame
from mceditlib.geometry import Vector
from mceditlib.selection import BoundingBox
from mceditlib.exceptions import PlayerNotFound
from mceditlib.revisionhistory import UndoFolderExists
from mceditlib.worldeditor import WorldEditor


log = logging.getLogger(__name__)
"""
An EditorSession is a world currently opened for editing, the state of the editor including the current
selection box, the editor tab containing its viewports, its command history, a separate instance of each editor
tool (why?), and the ChunkLoader that coordinates loading chunks into its viewports.
"""

class EditorSession(QtCore.QObject):
    def __init__(self, filename, versionInfo, readonly=False):
        QtCore.QObject.__init__(self)
        self.undoStack = MCEUndoStack()

        self.filename = filename
        self.dockWidgets = []
        self.undoBlock = None
        self.currentTool = None
        self.dirty = False

        self.copiedSchematic = None
        """:type : WorldEditor"""
        self.versionInfo = versionInfo

        # --- Open world editor ---
        try:
            self.worldEditor = WorldEditor(filename, readonly=readonly)
        except UndoFolderExists:
            msgBox = QtGui.QMessageBox()
            msgBox.setIcon(QtGui.QMessageBox.Warning)
            msgBox.setWindowTitle(self.tr("MCEdit tech demo"))
            msgBox.setText(self.tr("This world was not properly closed by MCEdit."))
            msgBox.setInformativeText(self.tr(
                "MCEdit may have crashed. An undo history was found for this world. You may try to resume editing "
                "with the saved undo history, or start over with the current state of the world."))
            resumeBtn = msgBox.addButton("Resume Editing", QtGui.QMessageBox.ApplyRole)
            msgBox.addButton("Discard History", QtGui.QMessageBox.DestructiveRole)
            # msgBox.exec_()
            # clicked = msgBox.clickedButton()
            clicked = None  # xxxxx
            resume = clicked is resumeBtn
            try:
                self.worldEditor = WorldEditor(filename, readonly=readonly, resume=resume)
            except NotImplementedError:
                NotImplementedYet()
                raise IOError("Uh-oh")

        self.worldEditor.requireRevisions()
        self.currentDimension = self.worldEditor.getDimension()
        self.loader = chunkloader.ChunkLoader(self.currentDimension)

        self.loader.chunkCompleted.connect(self.chunkDidComplete)
        self.loader.allChunksDone.connect(lambda: self.editorTab.currentView().update())

        # --- Menus ---

        self.menus = []

        self.menuEdit = QtGui.QMenu(self.tr("Edit"))
        self.menuEdit.setObjectName("menuEdit")
        self.actionCut = QtGui.QAction(self.tr("Cut"), self, triggered=self.cut, enabled=False)
        self.actionCut.setObjectName("actionCut")
        self.actionCopy = QtGui.QAction(self.tr("Copy"), self, triggered=self.copy, enabled=False)
        self.actionCopy.setObjectName("actionCopy")
        self.actionPaste = QtGui.QAction(self.tr("Paste"), self, triggered=self.paste, enabled=False)
        self.actionPaste.setObjectName("actionPaste")
        self.actionPaste_Blocks = QtGui.QAction(self.tr("Paste Blocks"), self, triggered=self.pasteBlocks, enabled=False)
        self.actionPaste_Blocks.setObjectName("actionPaste_Blocks")
        self.actionPaste_Entities = QtGui.QAction(self.tr("Paste Entities"), self, triggered=self.pasteEntities, enabled=False)
        self.actionPaste_Entities.setObjectName("actionPaste_Entities")
        self.actionClear = QtGui.QAction(self.tr("Clear"), self, triggered=self.clear, enabled=False)
        self.actionClear.setObjectName("actionClear")

        undoAction = self.undoStack.createUndoAction(self.menuEdit)
        undoAction.setShortcut(QtGui.QKeySequence.Undo)
        redoAction = self.undoStack.createRedoAction(self.menuEdit)
        redoAction.setShortcut(QtGui.QKeySequence.Redo)
        self.menuEdit.addAction(undoAction)
        self.menuEdit.addAction(redoAction)
        self.menuEdit.addSeparator()
        self.menuEdit.addAction(self.actionCut)
        self.menuEdit.addAction(self.actionCopy)
        self.menuEdit.addAction(self.actionPaste)
        self.menuEdit.addAction(self.actionPaste_Blocks)
        self.menuEdit.addAction(self.actionPaste_Entities)
        self.menuEdit.addAction(self.actionClear)

        self.actionCut.setShortcut(QtGui.QKeySequence.Cut)
        self.actionCopy.setShortcut(QtGui.QKeySequence.Copy)
        self.actionPaste.setShortcut(QtGui.QKeySequence.Paste)
        self.actionPaste_Blocks.setShortcut(QtGui.QKeySequence("Ctrl+Shift+V"))
        self.actionPaste_Entities.setShortcut(QtGui.QKeySequence("Ctrl+Alt+V"))
        self.actionClear.setShortcut(QtGui.QKeySequence.Quit)

        self.menus.append(self.menuEdit)

        # --- Resources ---

        i, v, p = self.versionInfo
        self.resourceLoader = i.getResourceLoader(v, p)
        self.geometryCache = GeometryCache()
        self.blockModels = BlockModels(self.worldEditor.blocktypes, self.resourceLoader)
        self.textureAtlas = TextureAtlas(self.worldEditor, self.resourceLoader, self.blockModels)

        self.editorOverlay = scenegraph.Node()

        # --- Panels ---

        self.playerPanel = PlayerPanel(self)
        self.panels = [self.playerPanel]

        # --- Tools ---
        def PickToolAction(tool):
            name = tool.name
            iconName = tool.iconName
            if iconName:
                iconPath = resourcePath("mcedit2/assets/mcedit2/toolicons/%s.png" % iconName)
                if not os.path.exists(iconPath):
                    log.error("Tool icon %s not found", iconPath)
                    icon = None
                else:
                    icon = QtGui.QIcon(iconPath)
            else:
                icon = None

            def _triggered():
                self.chooseTool(name)

            action = QtGui.QAction(
                self.tr(name),
                self,
                shortcut=self.toolShortcut(name),
                triggered=_triggered,<commit_msg>Disable tool shortcuts. Find out why they override view controls.<commit_after>from __future__ import absolute_import, division, print_function, unicode_literals
import logging
import os

from PySide import QtGui, QtCore
from PySide.QtCore import Qt

from mcedit2 import editortools
from mcedit2.command import SimpleRevisionCommand
from mcedit2.rendering.blockmodels import BlockModels
from mcedit2.panels.player import PlayerPanel
from mcedit2.util.dialogs import NotImplementedYet
from mcedit2.util.resources import resourcePath
from mcedit2.util.showprogress import showProgress
from mcedit2.util.undostack import MCEUndoStack
from mcedit2.worldview.worldview import UseToolMouseAction, TrackingMouseAction
from mceditlib import util
from mcedit2.rendering import chunkloader, blockmeshes, scenegraph
from mcedit2.rendering.geometrycache import GeometryCache
from mcedit2.rendering.textureatlas import TextureAtlas
from mcedit2.widgets.layout import Column, Row
from mcedit2.util.settings import Settings
from mcedit2.worldview.camera import CameraWorldViewFrame
from mcedit2.worldview.cutaway import CutawayWorldViewFrame
from mcedit2.worldview.minimap import MinimapWorldView
from mcedit2.worldview.overhead import OverheadWorldViewFrame
from mceditlib.geometry import Vector
from mceditlib.selection import BoundingBox
from mceditlib.exceptions import PlayerNotFound
from mceditlib.revisionhistory import UndoFolderExists
from mceditlib.worldeditor import WorldEditor


log = logging.getLogger(__name__)
"""
An EditorSession is a world currently opened for editing, the state of the editor including the current
selection box, the editor tab containing its viewports, its command history, a separate instance of each editor
tool (why?), and the ChunkLoader that coordinates loading chunks into its viewports.
"""

class EditorSession(QtCore.QObject):
    def __init__(self, filename, versionInfo, readonly=False):
        QtCore.QObject.__init__(self)
        self.undoStack = MCEUndoStack()

        self.filename = filename
        self.dockWidgets = []
        self.undoBlock = None
        self.currentTool = None
        self.dirty = False

        self.copiedSchematic = None
        """:type : WorldEditor"""
        self.versionInfo = versionInfo

        # --- Open world editor ---
        try:
            self.worldEditor = WorldEditor(filename, readonly=readonly)
        except UndoFolderExists:
            msgBox = QtGui.QMessageBox()
            msgBox.setIcon(QtGui.QMessageBox.Warning)
            msgBox.setWindowTitle(self.tr("MCEdit tech demo"))
            msgBox.setText(self.tr("This world was not properly closed by MCEdit."))
            msgBox.setInformativeText(self.tr(
                "MCEdit may have crashed. An undo history was found for this world. You may try to resume editing "
                "with the saved undo history, or start over with the current state of the world."))
            resumeBtn = msgBox.addButton("Resume Editing", QtGui.QMessageBox.ApplyRole)
            msgBox.addButton("Discard History", QtGui.QMessageBox.DestructiveRole)
            # msgBox.exec_()
            # clicked = msgBox.clickedButton()
            clicked = None  # xxxxx
            resume = clicked is resumeBtn
            try:
                self.worldEditor = WorldEditor(filename, readonly=readonly, resume=resume)
            except NotImplementedError:
                NotImplementedYet()
                raise IOError("Uh-oh")

        self.worldEditor.requireRevisions()
        self.currentDimension = self.worldEditor.getDimension()
        self.loader = chunkloader.ChunkLoader(self.currentDimension)

        self.loader.chunkCompleted.connect(self.chunkDidComplete)
        self.loader.allChunksDone.connect(lambda: self.editorTab.currentView().update())

        # --- Menus ---

        self.menus = []

        self.menuEdit = QtGui.QMenu(self.tr("Edit"))
        self.menuEdit.setObjectName("menuEdit")
        self.actionCut = QtGui.QAction(self.tr("Cut"), self, triggered=self.cut, enabled=False)
        self.actionCut.setObjectName("actionCut")
        self.actionCopy = QtGui.QAction(self.tr("Copy"), self, triggered=self.copy, enabled=False)
        self.actionCopy.setObjectName("actionCopy")
        self.actionPaste = QtGui.QAction(self.tr("Paste"), self, triggered=self.paste, enabled=False)
        self.actionPaste.setObjectName("actionPaste")
        self.actionPaste_Blocks = QtGui.QAction(self.tr("Paste Blocks"), self, triggered=self.pasteBlocks, enabled=False)
        self.actionPaste_Blocks.setObjectName("actionPaste_Blocks")
        self.actionPaste_Entities = QtGui.QAction(self.tr("Paste Entities"), self, triggered=self.pasteEntities, enabled=False)
        self.actionPaste_Entities.setObjectName("actionPaste_Entities")
        self.actionClear = QtGui.QAction(self.tr("Clear"), self, triggered=self.clear, enabled=False)
        self.actionClear.setObjectName("actionClear")

        undoAction = self.undoStack.createUndoAction(self.menuEdit)
        undoAction.setShortcut(QtGui.QKeySequence.Undo)
        redoAction = self.undoStack.createRedoAction(self.menuEdit)
        redoAction.setShortcut(QtGui.QKeySequence.Redo)
        self.menuEdit.addAction(undoAction)
        self.menuEdit.addAction(redoAction)
        self.menuEdit.addSeparator()
        self.menuEdit.addAction(self.actionCut)
        self.menuEdit.addAction(self.actionCopy)
        self.menuEdit.addAction(self.actionPaste)
        self.menuEdit.addAction(self.actionPaste_Blocks)
        self.menuEdit.addAction(self.actionPaste_Entities)
        self.menuEdit.addAction(self.actionClear)

        self.actionCut.setShortcut(QtGui.QKeySequence.Cut)
        self.actionCopy.setShortcut(QtGui.QKeySequence.Copy)
        self.actionPaste.setShortcut(QtGui.QKeySequence.Paste)
        self.actionPaste_Blocks.setShortcut(QtGui.QKeySequence("Ctrl+Shift+V"))
        self.actionPaste_Entities.setShortcut(QtGui.QKeySequence("Ctrl+Alt+V"))
        self.actionClear.setShortcut(QtGui.QKeySequence.Quit)

        self.menus.append(self.menuEdit)

        # --- Resources ---

        i, v, p = self.versionInfo
        self.resourceLoader = i.getResourceLoader(v, p)
        self.geometryCache = GeometryCache()
        self.blockModels = BlockModels(self.worldEditor.blocktypes, self.resourceLoader)
        self.textureAtlas = TextureAtlas(self.worldEditor, self.resourceLoader, self.blockModels)

        self.editorOverlay = scenegraph.Node()

        # --- Panels ---

        self.playerPanel = PlayerPanel(self)
        self.panels = [self.playerPanel]

        # --- Tools ---
        def PickToolAction(tool):
            name = tool.name
            iconName = tool.iconName
            if iconName:
                iconPath = resourcePath("mcedit2/assets/mcedit2/toolicons/%s.png" % iconName)
                if not os.path.exists(iconPath):
                    log.error("Tool icon %s not found", iconPath)
                    icon = None
                else:
                    icon = QtGui.QIcon(iconPath)
            else:
                icon = None

            def _triggered():
                self.chooseTool(name)

            action = QtGui.QAction(
                self.tr(name),
                self,
                #shortcut=self.toolShortcut(name),  # xxxx coordinate with view movement keys
                triggered=_triggered,
{'fraction_non_alphanumeric': 0.08837525492861999, 'fraction_numerical': 0.002719238613188307, 'mean_word_length': 3.02159650082012, 'pattern_counts': {'":': 2, '<': 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': '1755644', 'n_tokens_mistral': 4211, 'n_tokens_neox': 4125, 'n_words': 838}