Source code for mcedit2.editortools

from __future__ import absolute_import, division, print_function, unicode_literals
import logging
import os

from PySide import QtCore, QtGui

from mceditlib.util.lazyprop import weakrefprop
from mcedit2.util.resources import resourcePath

log = logging.getLogger(__name__)

_registered_tools = []

def registerToolClass(cls):
    if issubclass(cls, EditorTool):
        raise ValueError("Class %s must inherit from EditorTool" % cls)
    return cls

def unregisterToolClass(cls):
    _registered_tools[:] = [c for c in _registered_tools if c != cls]

_scanned_modules = None

def ToolClasses():
    from . import brush
    from . import move
    from . import generate
    from . import edit_chunk
    from . import select_entity
    from . import select
    from . import flood_fill
    from . import select_block
    from . import clone
    return (select.SelectionTool,

class EditorTool(QtCore.QObject):
    name = "Unnamed tool"
    iconName = None
    toolWidget = None
    cursorNode = None
    overlayNode = None
    editorSession = weakrefprop()

    modifiesWorld = False

    def __init__(self, editorSession, *args, **kwargs):
        Initialize toolWidget here.


        editorSession: EditorSession
        super(EditorTool, self).__init__(*args, **kwargs)
        self.editorSession = editorSession

[docs] def mousePress(self, event): """ Parameters ---------- event: QMouseEvent event has been augmented with these attributes: point, ray, blockPosition, blockFace """
[docs] def mouseMove(self, event): """ Parameters ---------- event: QMouseEvent event has been augmented """
[docs] def mouseDrag(self, event): """ Parameters ---------- event: QMouseEvent event has been augmented """
[docs] def mouseRelease(self, event): """ Parameters ---------- event: QMouseEvent event has been augmented """
def toolActive(self): """ Called when this tool is selected. """ def toolInactive(self): """ Called when a different tool is selected. """ toolPicked = QtCore.Signal(object) def pick(self): if self.editorSession.readonly and self.modifiesWorld: return self.toolPicked.emit( def pickToolAction(self): name = iconName = self.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 action = QtGui.QAction(, self, #shortcut=self.toolShortcut(name), # xxxx coordinate with view movement keys triggered=self.pick, checkable=True, icon=icon, enabled=not(self.editorSession.readonly and self.modifiesWorld) ) action.toolName = name return action