Notes of the day

• 4 min read

A recent project requirement from a customer for a cross-platform solution prompted me to look into viable frameworks for this. Based on my knowledge of languages (C++, Python & Javascript), I narrowed the potential solutions to wxWidgets & Git Electron. Since I have been spending some time with Python over the last two years and given its ease of use, I through I'll look into wxPython, the Python projection of wxWidgets framework.

Here are my notes from this research today morning:

  • wxPython provides a genuine means to build cross platform GUI apps (installed through PyPi [pip install wxpython]).
  • Python code can be compiled into distributable binaries using cx_Freeze, another cross-platform tool that can generate binaries for Windows, Mac & Linux. cx_Freeze can provide executable files as well as installable binaries such as MSI or DMG files.
  • cx_Freeze source repo has sample code for various deployment scenarios. One of them is wxPython based application.
  • Py2Exe is a popular tool for this, but it can only generate Windows executables. Moreover it does not work with Python 3.6 and supports only up to Python 3.4 (This is reportedly owing to python byte code compatibility issues). So if cross-platform binaries are required, cx_Freeze is probably the answer.

Git's Electron is also a viable option. Especially using Ionic 4, which natively supports desktop apps through its build scripts. However, Ionic 4 is still in beta and the requirement could potentially require interfacing with native components -- either through IPC or some other means. And for this Python is a much simpler technology. Hence my focus on wxPython.

The project involves emulating input devices on a PC and a Mac. The objective is to create a scriptable mechanism where desired input combinations can be emulated on the target computer and then verify that the input is generated using another software. Obviously a candidate for Windows  APIs [SendInput](https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendinput) & [SetWinEventHook](https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwineventhook). The question is how does one go about implementing this on a Mac. Well, it happens that OS X has parallel APIs to the Windows APIS above. Some notes on this: - Event emulation in Windows is performed through the [SendInput](https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendinput) API. Another API which is closely associated with this is [SetWinEventHook](https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwineventhook), which allows an independent app to trap almost all GUI events, along with input events, in the systen. Mac equivalent of these two technologies is [Quartz Event Services](https://developer.apple.com/documentation/coregraphics/quartz_event_services). - Event hooks are referred as 'event taps' in Quartz.