Allow pasting text when using text tool.

libtools/ToolText.py:{_processKeyChar,onKeyboardEvent}(): split from onKeyboardEvent().
libtools/ToolText.py:onKeyboardEvent(): obtain & iteratively _processKeyChar() clipboard text on <Control> V.
libtools/ToolText.py:onKeyboardEvent(): dispatch cursor patch once after {drawing,pasting}.
assets/text/TODO: updated.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2019-09-16 11:15:23 +02:00
parent e6bdc52af2
commit 2834fe531b
2 changed files with 46 additions and 24 deletions

View File

@ -15,15 +15,15 @@ High-priority list:
3) cleanup & refactor, switch to GTK 3) cleanup & refactor, switch to GTK
4) GUI: 4) GUI:
a) replace logo w/ canvas panel in About dialogue a) replace logo w/ canvas panel in About dialogue
b) Settings/Settings window (e.g. autosave, hide cursor on leaving window, ...) b) purge MRU list menu item, remove files from MRU list if inaccessible
c) replace resize buttons w/ {-,edit box,+} buttons & lock button re: ratio (ty lol3) c) Settings/Settings window (e.g. autosave, hide cursor on leaving window, ...)
d) {copy,cut,delete,insert from,paste}, {edit asset in new canvas,import from {canvas,object}} d) replace resize buttons w/ {-,edit box,+} buttons & lock button re: ratio (ty lol3)
e) {copy,cut,delete,insert from,paste}, {edit asset in new canvas,import from {canvas,object}}
Queue: Queue:
1) scrolling bug: start @ top, down key til cursor below visible canvas, scroll down, cursor gone GRRRR 1) scrolling bug: start @ top, down key til cursor below visible canvas, scroll down, cursor gone GRRRR
2) scrolling bug: scroll down, apply operator to entire canvas, scroll up 2) scrolling bug: scroll down, apply operator to entire canvas, scroll up
3) select-related {re,un}do bugs 3) select-related {re,un}do bugs
4) text tool: pasting text 4) clone selection lag
5) clone selection lag
vim:ff=dos tw=0 vim:ff=dos tw=0

View File

@ -11,24 +11,9 @@ class ToolText(Tool):
name = "Text" name = "Text"
rtlRegEx = r'^[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]+$' rtlRegEx = r'^[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]+$'
# # {{{ _processKeyChar(self, brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers, viewRect)
# onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint, viewRect) def _processKeyChar(self, brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers, viewRect):
def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint, viewRect): if (ord(keyChar) != wx.WXK_NONE) \
if 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);
elif (ord(keyChar) != wx.WXK_NONE) \
and (not keyChar in set("\t\n\v\f\r")) \ and (not keyChar in set("\t\n\v\f\r")) \
and ((ord(keyChar) >= 32) if ord(keyChar) < 127 else True) \ and ((ord(keyChar) >= 32) if ord(keyChar) < 127 else True) \
and (keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT)): and (keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT)):
@ -47,11 +32,48 @@ class ToolText(Tool):
brushPos[0], brushPos[1] = canvas.size[0] - 1, brushPos[1] - 1 brushPos[0], brushPos[1] = canvas.size[0] - 1, brushPos[1] - 1
else: else:
brushPos[0], brushPos[1] = canvas.size[0] - 1, canvas.size[1] - 1 brushPos[0], brushPos[1] = canvas.size[0] - 1, canvas.size[1] - 1
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect)
rc, dirty = True, True rc, dirty = True, True
else: else:
rc, dirty = False, False rc, dirty = False, False
return rc, dirty return rc, dirty
# }}}
#
# 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
# #
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) # onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)