2019-09-01 14:34:00 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 10:46:52 +00:00
|
|
|
# ToolText.py
|
2019-09-04 14:23:59 +00:00
|
|
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
2019-09-01 14:34:00 +00:00
|
|
|
#
|
|
|
|
|
2019-09-03 16:58:50 +00:00
|
|
|
from Tool import Tool
|
2019-09-16 08:09:25 +00:00
|
|
|
import re, string, wx
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-03 16:58:50 +00:00
|
|
|
class ToolText(Tool):
|
2019-09-01 14:34:00 +00:00
|
|
|
name = "Text"
|
2019-09-16 08:09:25 +00:00
|
|
|
rtlRegEx = r'^[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]+$'
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-16 09:15:23 +00:00
|
|
|
# {{{ _processKeyChar(self, brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers, viewRect)
|
|
|
|
def _processKeyChar(self, brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers, viewRect):
|
|
|
|
if (ord(keyChar) != wx.WXK_NONE) \
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
and (not keyChar in set("\t\n\v\f\r")) \
|
|
|
|
and ((ord(keyChar) >= 32) if ord(keyChar) < 127 else True) \
|
|
|
|
and (keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT)):
|
|
|
|
dispatchFn(eventDc, False, [*brushPos, *brushColours, 0, keyChar], viewRect);
|
2019-09-16 08:09:25 +00:00
|
|
|
if not re.match(self.rtlRegEx, keyChar):
|
|
|
|
if brushPos[0] < (canvas.size[0] - 1):
|
|
|
|
brushPos[0] += 1
|
|
|
|
elif brushPos[1] < (canvas.size[1] - 1):
|
|
|
|
brushPos[0], brushPos[1] = 0, brushPos[1] + 1
|
|
|
|
else:
|
|
|
|
brushPos[0], brushPos[1] = 0, 0
|
2019-09-10 10:20:23 +00:00
|
|
|
else:
|
2019-09-16 08:09:25 +00:00
|
|
|
if brushPos[0] > 0:
|
|
|
|
brushPos[0] -= 1
|
|
|
|
elif brushPos[1] > 0:
|
|
|
|
brushPos[0], brushPos[1] = canvas.size[0] - 1, brushPos[1] - 1
|
|
|
|
else:
|
|
|
|
brushPos[0], brushPos[1] = canvas.size[0] - 1, canvas.size[1] - 1
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
rc, dirty = True, True
|
2019-09-01 14:34:00 +00:00
|
|
|
else:
|
2019-09-10 10:20:23 +00:00
|
|
|
rc, dirty = False, False
|
|
|
|
return rc, dirty
|
2019-09-16 09:15:23 +00:00
|
|
|
# }}}
|
|
|
|
|
|
|
|
#
|
|
|
|
# onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint, viewRect)
|
|
|
|
def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint, viewRect):
|
|
|
|
if keyCode == wx.WXK_CONTROL_V:
|
|
|
|
rc, dirty = True, False
|
|
|
|
if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)) \
|
|
|
|
and wx.TheClipboard.Open():
|
|
|
|
inBuffer = wx.TextDataObject()
|
|
|
|
if wx.TheClipboard.GetData(inBuffer):
|
|
|
|
for inBufferChar in list(inBuffer.GetText()):
|
|
|
|
rc_, dirty_ = self._processKeyChar(brushColours, brushPos, canvas, dispatchFn, eventDc, inBufferChar, 0, viewRect)
|
|
|
|
rc = True if rc_ else rc; dirty = True if dirty_ else dirty;
|
|
|
|
if rc:
|
|
|
|
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect)
|
|
|
|
wx.TheClipboard.Close()
|
|
|
|
else:
|
|
|
|
rc, error = False, "Clipboard does not contain text data and/or cannot be opened"
|
|
|
|
elif keyCode == wx.WXK_BACK:
|
|
|
|
if brushPos[0] > 0:
|
|
|
|
brushPos[0] -= 1
|
|
|
|
elif brushPos[1] > 0:
|
|
|
|
brushPos[0], brushPos[1] = canvas.size[0] - 1, brushPos[1] - 1
|
|
|
|
else:
|
|
|
|
brushPos[0], brushPos[1] = canvas.size[0] - 1, canvas.size[1] - 1
|
|
|
|
rc, dirty = True, False; dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect);
|
|
|
|
elif keyCode == wx.WXK_RETURN:
|
|
|
|
if brushPos[1] < (canvas.size[1] - 1):
|
|
|
|
brushPos[0], brushPos[1] = 0, brushPos[1] + 1
|
|
|
|
else:
|
|
|
|
brushPos[0], brushPos[1] = 0, 0
|
|
|
|
rc, dirty = True, False; dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect);
|
|
|
|
else:
|
|
|
|
rc, dirty = self._processKeyChar(brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers, viewRect)
|
|
|
|
if rc:
|
|
|
|
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect)
|
|
|
|
return rc, dirty
|
2019-09-01 14:34:00 +00:00
|
|
|
|
|
|
|
#
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
|
|
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
libgui/GuiCanvasInterface.py:canvasTool(): call applyTool() w/ new tool post-selection.
libgui/GuiCanvasPanel.py:{applyTool,onPanelInput}(): split from onPanelInput().
libtools/Tool{,Circle,Fill,Line,Rect,Select,Text}.py:on{Keyboard,Mouse}Event(): updated.
libtools/ToolFill.py:onMouseEvent(): display cursor.
libtools/ToolSelect{,Clone,Move}.py:onSelectEvent(): updated.
2019-09-09 16:18:54 +00:00
|
|
|
if mouseLeftDown or mouseRightDown:
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
brushPos[0], brushPos[1] = atPoint[0], atPoint[1]
|
|
|
|
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect)
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
return True, False
|
2019-09-01 14:34:00 +00:00
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|