dictation-toolbox / dtactions

Common OS action and related code from dictation-toolbox projects
4 stars 1 forks source link

win32clipboard.SetClipboardData sometimes crashes #16

Open quintijn opened 6 months ago

quintijn commented 6 months ago

In dtactions/unimacro/unimacroutils.py I have a function setClipboard:

def setClipboard(t, format=1):
    """set clipboard with text
    format = win32con.CF_UNICODETEXT (13): as unicode

    """
    #pylint:disable=W0622
    try:
        win32clipboard.OpenClipboard()
        win32clipboard.EmptyClipboard()
        win32clipboard.SetClipboardData(format, t)
    except:
        print(f'exception in unimacroutils/setClipboard of "{t}"')
    finally:
        win32clipboard.CloseClipboard()

which works most of the time, but raises an exception (which cannot be caught, but crashes Dragon) with for example the second number: (this is done via a function in dtactions\unimacro\unimacroactions.py, line 1120).

def try_SCLIP():
    ''' try by running this script, ensure cursor is on a safe place (bottom, or here after a #
    '''
    do_SCLIP('hello')
    print('try first number:')
    do_SCLIP('9123454321')
    # now comes the error:
    print('try second number:')
    do_SCLIP('123456789')
    print('ready')

I am puzzled...

quintijn commented 6 months ago

Put the latest code in the master branch of dtactions. Not in pip yet.