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-24 14:46:02 +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 12:52:11 +00:00
|
|
|
arabicCombiningRegEx = r'^[\u064B-\u065F\uFE70-\uFE72\uFE74\uFE76-\uFE7F]+$'
|
2019-09-16 12:13:44 +00:00
|
|
|
arabicRegEx = r'^[\u0621-\u063A\u0640-\u064A]+$'
|
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 12:13:44 +00:00
|
|
|
def _checkRtl(self, canvas, brushPos, keyChar):
|
|
|
|
rtlFlag = False
|
|
|
|
if (keyChar != None) and re.match(self.rtlRegEx, keyChar):
|
|
|
|
rtlFlag = True
|
|
|
|
else:
|
|
|
|
lastX, lastY = brushPos[0], brushPos[1]
|
|
|
|
while True:
|
|
|
|
if canvas.map[lastY][lastX][3] == " ":
|
|
|
|
if (lastX + 1) >= canvas.size[0]:
|
|
|
|
if lastY == 0:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
lastX, lastY = 0, lastY - 1
|
|
|
|
else:
|
|
|
|
lastX += 1
|
|
|
|
elif re.match(self.arabicRegEx, canvas.map[lastY][lastX][3]):
|
|
|
|
rtlFlag = True
|
|
|
|
if (lastX + 1) >= canvas.size[0]:
|
|
|
|
if lastY == 0:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
lastX, lastY = 0, lastY - 1
|
|
|
|
else:
|
|
|
|
lastX += 1
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
return rtlFlag
|
Various bugfixes & usability improvements.
1) Add background colour toolbar beneath (foreground) colour toolbar.
2) Add colour flipping command w/ {accelerator,{menu,toolbar} item}.
3) Add {de,in}crease {brush,canvas} size accelerator.
4) Add {hide,show} assets window toolbar item.
5) Circle tool: draw outline with foreground colour.
6) Circle tool: honour transparency.
7) Fill tool: change comprehensive fill modifier key from <Shift> to <Ctrl>.
8) Fill tool: fill with {back,fore}ground colour given <[RL]MB>
9) Fix arrow keys cursor motion when scrolled down.
10 Instantly reflect {brush size,colour,tool} changes in canvas.
11) Object tool: honour transparency w/ non-external objects.
12) Object tool: update selection rectangle during <LMB> whilst dragging, set w/ release of <LMB>.
13) Rectangle tool: draw outline with foreground colour.
14) Rectangle tool: honour transparency.
15) Replace wx.ToolBar() w/ wx.lib.agw.aui.AuiToolBar() & custom wx.lib.agw.aui.AuiDefaultToolBarArt().
16) Restore scrolling position after resizing canvas.
.TODO: deleted.
assets/audio/roar{arab8,spoke11}.wav: added.
assets/text/hotkeys.txt: added to document hotkeys.
assets/text/requirements.txt, requirements.txt: moved.
assets/text/TODO: updated.
{assets/tools,lib{canvas,gui,roar,rtl,tools}}/*.py: remove Vim fold markers.
libroar/RoarCanvasCommandsFile.py:_importFile(): update wx.FileDialog() message.
libroar/RoarCanvasCommandsOperators.py:canvasOperator(): update invert colours {caption,label}.
2019-09-23 16:49:33 +00:00
|
|
|
|
2019-09-26 20:38:28 +00:00
|
|
|
def _processKeyChar(self, brushColours, brushPos, canvas, keyChar, keyModifiers):
|
|
|
|
patches, rc = [], False
|
Various bugfixes & usability improvements.
1) Add background colour toolbar beneath (foreground) colour toolbar.
2) Add colour flipping command w/ {accelerator,{menu,toolbar} item}.
3) Add {de,in}crease {brush,canvas} size accelerator.
4) Add {hide,show} assets window toolbar item.
5) Circle tool: draw outline with foreground colour.
6) Circle tool: honour transparency.
7) Fill tool: change comprehensive fill modifier key from <Shift> to <Ctrl>.
8) Fill tool: fill with {back,fore}ground colour given <[RL]MB>
9) Fix arrow keys cursor motion when scrolled down.
10 Instantly reflect {brush size,colour,tool} changes in canvas.
11) Object tool: honour transparency w/ non-external objects.
12) Object tool: update selection rectangle during <LMB> whilst dragging, set w/ release of <LMB>.
13) Rectangle tool: draw outline with foreground colour.
14) Rectangle tool: honour transparency.
15) Replace wx.ToolBar() w/ wx.lib.agw.aui.AuiToolBar() & custom wx.lib.agw.aui.AuiDefaultToolBarArt().
16) Restore scrolling position after resizing canvas.
.TODO: deleted.
assets/audio/roar{arab8,spoke11}.wav: added.
assets/text/hotkeys.txt: added to document hotkeys.
assets/text/requirements.txt, requirements.txt: moved.
assets/text/TODO: updated.
{assets/tools,lib{canvas,gui,roar,rtl,tools}}/*.py: remove Vim fold markers.
libroar/RoarCanvasCommandsFile.py:_importFile(): update wx.FileDialog() message.
libroar/RoarCanvasCommandsOperators.py:canvasOperator(): update invert colours {caption,label}.
2019-09-23 16:49:33 +00:00
|
|
|
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")) \
|
Various bugfixes & usability improvements.
1) Add background colour toolbar beneath (foreground) colour toolbar.
2) Add colour flipping command w/ {accelerator,{menu,toolbar} item}.
3) Add {de,in}crease {brush,canvas} size accelerator.
4) Add {hide,show} assets window toolbar item.
5) Circle tool: draw outline with foreground colour.
6) Circle tool: honour transparency.
7) Fill tool: change comprehensive fill modifier key from <Shift> to <Ctrl>.
8) Fill tool: fill with {back,fore}ground colour given <[RL]MB>
9) Fix arrow keys cursor motion when scrolled down.
10 Instantly reflect {brush size,colour,tool} changes in canvas.
11) Object tool: honour transparency w/ non-external objects.
12) Object tool: update selection rectangle during <LMB> whilst dragging, set w/ release of <LMB>.
13) Rectangle tool: draw outline with foreground colour.
14) Rectangle tool: honour transparency.
15) Replace wx.ToolBar() w/ wx.lib.agw.aui.AuiToolBar() & custom wx.lib.agw.aui.AuiDefaultToolBarArt().
16) Restore scrolling position after resizing canvas.
.TODO: deleted.
assets/audio/roar{arab8,spoke11}.wav: added.
assets/text/hotkeys.txt: added to document hotkeys.
assets/text/requirements.txt, requirements.txt: moved.
assets/text/TODO: updated.
{assets/tools,lib{canvas,gui,roar,rtl,tools}}/*.py: remove Vim fold markers.
libroar/RoarCanvasCommandsFile.py:_importFile(): update wx.FileDialog() message.
libroar/RoarCanvasCommandsOperators.py:canvasOperator(): update invert colours {caption,label}.
2019-09-23 16:49:33 +00:00
|
|
|
and ((ord(keyChar) >= 32) if ord(keyChar) < 127 else True):
|
2019-09-26 20:38:28 +00:00
|
|
|
patches += [[*brushPos, *brushColours, 0, keyChar]]
|
2019-09-16 12:13:44 +00:00
|
|
|
if not self._checkRtl(canvas, brushPos, keyChar):
|
2019-09-16 08:09:25 +00:00
|
|
|
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
|
2019-09-26 20:38:28 +00:00
|
|
|
rc = True
|
|
|
|
return rc, patches
|
Various bugfixes & usability improvements.
1) Add background colour toolbar beneath (foreground) colour toolbar.
2) Add colour flipping command w/ {accelerator,{menu,toolbar} item}.
3) Add {de,in}crease {brush,canvas} size accelerator.
4) Add {hide,show} assets window toolbar item.
5) Circle tool: draw outline with foreground colour.
6) Circle tool: honour transparency.
7) Fill tool: change comprehensive fill modifier key from <Shift> to <Ctrl>.
8) Fill tool: fill with {back,fore}ground colour given <[RL]MB>
9) Fix arrow keys cursor motion when scrolled down.
10 Instantly reflect {brush size,colour,tool} changes in canvas.
11) Object tool: honour transparency w/ non-external objects.
12) Object tool: update selection rectangle during <LMB> whilst dragging, set w/ release of <LMB>.
13) Rectangle tool: draw outline with foreground colour.
14) Rectangle tool: honour transparency.
15) Replace wx.ToolBar() w/ wx.lib.agw.aui.AuiToolBar() & custom wx.lib.agw.aui.AuiDefaultToolBarArt().
16) Restore scrolling position after resizing canvas.
.TODO: deleted.
assets/audio/roar{arab8,spoke11}.wav: added.
assets/text/hotkeys.txt: added to document hotkeys.
assets/text/requirements.txt, requirements.txt: moved.
assets/text/TODO: updated.
{assets/tools,lib{canvas,gui,roar,rtl,tools}}/*.py: remove Vim fold markers.
libroar/RoarCanvasCommandsFile.py:_importFile(): update wx.FileDialog() message.
libroar/RoarCanvasCommandsOperators.py:canvasOperator(): update invert colours {caption,label}.
2019-09-23 16:49:33 +00:00
|
|
|
|
2019-09-26 20:38:28 +00:00
|
|
|
def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, keyChar, keyCode, keyModifiers, mapPoint):
|
|
|
|
patches, patchesCursor, rc = [], [], False
|
2019-09-16 12:52:11 +00:00
|
|
|
if re.match(self.arabicCombiningRegEx, keyChar):
|
2019-09-26 20:38:28 +00:00
|
|
|
rc = True
|
2019-09-16 12:52:11 +00:00
|
|
|
elif keyCode == wx.WXK_CONTROL_V:
|
2019-09-26 20:38:28 +00:00
|
|
|
rc = True
|
2019-10-24 19:14:00 +00:00
|
|
|
if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)) and wx.TheClipboard.Open():
|
2019-09-16 09:15:23 +00:00
|
|
|
inBuffer = wx.TextDataObject()
|
|
|
|
if wx.TheClipboard.GetData(inBuffer):
|
2019-10-24 19:14:00 +00:00
|
|
|
brushPosOriginX = brushPos[0]
|
2019-09-16 09:15:23 +00:00
|
|
|
for inBufferChar in list(inBuffer.GetText()):
|
2019-10-24 19:14:00 +00:00
|
|
|
if inBufferChar in set("\r\n"):
|
|
|
|
if brushPos[1] < (canvas.size[1] - 1):
|
|
|
|
brushPos[0], brushPos[1] = brushPosOriginX, brushPos[1] + 1
|
|
|
|
else:
|
|
|
|
brushPos[0], brushPos[1] = brushPosOriginX, 0
|
|
|
|
elif not re.match(self.arabicCombiningRegEx, inBufferChar):
|
2019-09-26 20:38:28 +00:00
|
|
|
rc_, patches_ = self._processKeyChar(brushColours, brushPos, canvas, inBufferChar, 0)
|
|
|
|
patches += patches_
|
|
|
|
rc = True if rc_ else rc
|
2019-09-16 09:15:23 +00:00
|
|
|
if rc:
|
2019-09-26 20:38:28 +00:00
|
|
|
patchesCursor += [[*brushPos, *brushColours, 0, "_"]]
|
2019-09-16 09:15:23 +00:00
|
|
|
wx.TheClipboard.Close()
|
|
|
|
else:
|
|
|
|
rc, error = False, "Clipboard does not contain text data and/or cannot be opened"
|
|
|
|
elif keyCode == wx.WXK_BACK:
|
2019-09-16 12:13:44 +00:00
|
|
|
if ((brushPos[0] + 1) >= canvas.size[0]):
|
2019-09-26 20:38:28 +00:00
|
|
|
lastBrushPos = [0, brushPos[1] - 1] if brushPos[1] > 0 else [0, 0]
|
2019-09-16 09:15:23 +00:00
|
|
|
else:
|
2019-09-16 12:13:44 +00:00
|
|
|
lastBrushPos = [brushPos[0] + 1, brushPos[1]]
|
|
|
|
if not self._checkRtl(canvas, lastBrushPos, None):
|
2019-09-26 20:38:28 +00:00
|
|
|
patches += [[*brushPos, *brushColours, 0, " "]]
|
2019-09-16 12:13:44 +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
|
|
|
|
else:
|
|
|
|
if brushPos[0] < (canvas.size[0] - 1):
|
|
|
|
brushPos[0] += 1
|
|
|
|
elif brushPos[1] > 0:
|
|
|
|
brushPos[0], brushPos[1] = 0, brushPos[1] - 1
|
|
|
|
else:
|
|
|
|
brushPos[0], brushPos[1] = canvas.size[0] - 1, 0
|
2019-09-26 20:38:28 +00:00
|
|
|
rc = True; patchesCursor += [[*brushPos, *brushColours, 0, "_"]];
|
2019-09-16 09:15:23 +00:00
|
|
|
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
|
2019-09-26 20:38:28 +00:00
|
|
|
rc = True; patchesCursor += [[*brushPos, *brushColours, 0, "_"]];
|
2019-09-27 18:17:39 +00:00
|
|
|
elif not (keyModifiers in (wx.MOD_ALT, wx.MOD_ALTGR, wx.MOD_CONTROL)):
|
2019-09-26 20:38:28 +00:00
|
|
|
rc, patches_ = self._processKeyChar(brushColours, brushPos, canvas, keyChar, keyModifiers)
|
|
|
|
patches += patches_
|
2019-09-16 09:15:23 +00:00
|
|
|
if rc:
|
2019-09-26 20:38:28 +00:00
|
|
|
patchesCursor += [[*brushPos, *brushColours, 0, "_"]]
|
|
|
|
return rc, patches, patchesCursor
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-26 20:38:28 +00:00
|
|
|
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
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]
|
2019-09-26 20:38:28 +00:00
|
|
|
return True, None, [[*brushPos, *brushColours, 0, "_"]]
|
2019-09-01 14:34:00 +00:00
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|