Skip to content

Commit

Permalink
ok displayText now uses python to locale conversion instead of C++
Browse files Browse the repository at this point in the history
  • Loading branch information
dougransom committed Aug 19, 2022
1 parent 77a0e06 commit 3cd7797
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 40 deletions.
35 changes: 7 additions & 28 deletions NatlinkSource/DragonCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,40 +2003,19 @@ BOOL CDragonCode::playString( const char * pszKeys, DWORD dwFlags )

// OutputDebugStringA("ignoring input, just sending out `naïve'");

int const inputCodePage = CP_UTF8;
int const outputCodePage = 1252;


//get a wide unicode string from the unicode string. Be better to change pytwrap to just give us
//unicode strings.
int size_needed = 10+ ::MultiByteToWideChar( inputCodePage, 0, pszKeys, -1, NULL, 0 );
BSTR pszKeysW = new TCHAR[ size_needed ];
memset(pszKeysW,0,(sizeof pszKeysW[0]*size_needed));

std::unique_ptr<TCHAR> pdzKesWMem(pszKeysW);

::MultiByteToWideChar( inputCodePage, MB_PRECOMPOSED, pszKeys, -1, pszKeysW, size_needed );

//now convert to to single byte code page for windows
int mbSizeNeeded = 10+WideCharToMultiByte(outputCodePage,0,pszKeysW,-1,0,0,0,0);
char * mbString = new char[mbSizeNeeded];
memset(mbString,0,sizeof mbString[0]*mbSizeNeeded);
std::unique_ptr<char> mbPtr(mbString);
WideCharToMultiByte(outputCodePage,0,pszKeysW,-1,mbString,mbSizeNeeded,0,0);

std::string msg1("Windows String: ");
msg1.append(mbString);
OutputDebugStringA(msg1.c_str());

// use the interface that takes char strings, not wide strings.

rc = m_pIDgnSSvcOutputEventA->PlayString(
mbString, // string to send
pszKeys, // string to send
dwFlags, // flags
0xFFFFFFFF, // delay (-1 for app specific delay)
dwClientCode, // to identify which WM_PLAYBACK is ours
&dwNumUndo );

int const inputCodePage = CP_UTF8;
int const outputCodePage = 1252;




#else
rc = m_pIDgnSSvcOutputEvent->PlayString(
pszKeys, // string to send
Expand Down
10 changes: 2 additions & 8 deletions NatlinkSource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ def lmap(fn,iter):
return list(map(fn,iter))

def playString(a):
print(f"wrapped playString {a}")
_playString(a)
print("returned from playString")
return _playString(toWindowsEncoding(a))

def execScript(script,args=[]):
#only encode the script. can't find a single case of anyone using the args

script_w=toWindowsEncoding(script)

print(f"Exec Scripts {script} args {args} windows encodings script {script_w} ")
_execScript(script_w,args)
print(f"returned from exec ")
return _execScript(script_w,args)

def toWindowsEncoding(str_to_encode):
return str_to_encode.encode('Windows-1252')
5 changes: 3 additions & 2 deletions NatlinkSource/pythwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ natlink_waitForSpeech( PyObject *self, PyObject *args )
extern "C" static PyObject *
natlink_playString( PyObject *self, PyObject *args )
{
char *pKeys;
char *pKeys=0;
int pkeysLen=0;
DWORD dwFlags = 0;
if( !PyArg_ParseTuple( args, "s|i:playString", &pKeys, &dwFlags ) )
if( !PyArg_ParseTuple( args, "s#|i:playString", &pKeys, &pkeysLen, &dwFlags ) )
{
return NULL;
}
Expand Down
11 changes: 11 additions & 0 deletions NatlinkSource/samples_for_interactive_debugging/displayText.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import natlink as n

n.natConnect()
dis=n.natDisconnect
def bye():
n.natDisconnect()
quit()

d=n.displayText

d("naïve brachialis",True,True)
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ def bye():
quit()

e=n.execScript

e('SendKeys "naïve brachialis"')
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import natlink as n
n.natConnect()
dis=n.natDisconnect
dis=n.natDisconnect
def bye():
n.natDisconnect()
quit()
p=n.playString

n.playString("naïve brachialis")

0 comments on commit 3cd7797

Please sign in to comment.