3

How would I go about installing a handler of touchscreen gestures in Tkinter?

I need to something particularly simple: to increase the font size whenever an 'expand' gesture is detected.

Is this even possible to do in Tkinter if Tcl/Tk doesn't specifically implement it? I suppose that either the window manager sends the client window some event that I could listen for and handle, or the client must register to the window manager a handler for a specific kind of event, but if it isn't possible to register these handlers from Tkinter and if Tcl doesn't provide an interface to them, I'm don't see a way I could do this.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
ealfonso
  • 6,622
  • 5
  • 39
  • 67
  • I _really_ have no idea what touchscreen-related events look like. What platform are you on? – Donal Fellows Aug 19 '14 at 14:01
  • This would be a windows 8 tablet, but I guess it would apply to any touchscreen-enabled device. Maybe I could create a dummy window and print all the event Tkinter receives from it, and see if anything is output for the 'pinch' event I'm looking for. – ealfonso Aug 19 '14 at 20:13
  • Yes, that sounds like it would be interesting. – This isn't my real name Aug 19 '14 at 21:33
  • I haven't tried that because I currently don't have access to the device. When I do, I will update the post if I find something interesting – ealfonso Aug 20 '14 at 01:44

1 Answers1

2

Tk doesn't support the complex touch events at the moment, and MSDN is very thin on what they actually look like when they come in over the event loop. (It's not something that you're supposed to look at, it seems.) Because Tk intercepts that data at a very low level, it's going to be tricky to integrate.

I can't chase this further. I can see how some of the code works, but way that the samples on MSDN function doesn't match up at all to what Tk's doing. There's a whole framework's worth of mismatch between the two. (I also don't have a device which would support these features; my touch devices don't run Windows and my Windows devices don't support touch input.)

What we would need is someone with a touch-input Win 8 system to run a Tk app that has been hacked (Tk_TranslateWinEvent() in win/tkWinX.c would be the right spot) to print out unrecognised events. We could then see what actually comes over the wire (well, through the master message pump) with touch events; we might hope that they correspond to things involved in the ManipulationStarted, ManipulationUpdated and ManipulationCompleted events, but hope is not always enough. (We might also hope that the events aren't squirrelled in via another route.)

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • And before you ask, there's nothing in there to intercept unrecognised Win events so there's very little that could be done at the Tkinter level. We could do it on X11, which _does_ have a general interceptor, but the Win side doesn't. [Feature Request](http://core.tcl.tk/tk/tktnew) time, methinks… (anon login is OK) – Donal Fellows Aug 20 '14 at 08:34
  • I submitted the request. Thanks for your answer – ealfonso Aug 22 '14 at 01:48
  • @erjoalgo Thanks! It's tracked now at http://core.tcl.tk/tk/tktview/9c2f8da611 and I've filled it out with more info glommed from MSDN. I so wish I could help more; I've just not got the right kit. – Donal Fellows Aug 22 '14 at 21:17
  • erjoalgo and @DonalFellows it seems like you both know how to change the Tcl/Tk code in order to pinpoint the event generated by touch events, but don't have a device for testing it out. Adding touch support for Tkinter applications is something I would really love to have as well (either officially in future Python versions or via custom patches), and it just so happens that I have a Windows 8 device with a touch screen. I know my way around Python and Tkinter but not Tk/Tcl, so if you guys can give me very specific instructions on what to do I would love to test this out for you guys? – Karim Bahgat Apr 14 '15 at 20:30