GNOME Bugzilla – Bug 691878
Convert to Python 3
Last modified: 2014-02-24 17:10:26 UTC
GNOME 3.8 is Python 3 based. Mousetrap is not.
I have started working on this in my fork on GitHub [1], but there are a few roadblocks that I've hit and had to adjust for. For the most part, the code base is ready for use in Python 3, with a few important exceptions. Much of the pain points within the conversion (print statements, unicode, etc) have been reduced to a small area, which made it easy to migrate. A few dependencies needed to be updated for Python 3, namely OpenCV and Xlib. Xlib was supported through the python-xlib library, which hasn't seen an update since 2009. Luckily a few people have made Python 3 forks [2] of the original library, and one person pushed it up to PyPi under the name "python3-xlib" [3]. OpenCV is actively developed, and a patch for Python 3 support has already landed. Unfortunately it landed for OpenCV 3, which is set for a release on 2014-05-30 [4] and it doesn't appear that it will be backported to the 2.4 releases. OpenCV can be compiled and installed under Python 3 relatively easily [5]. The biggest problem we will face when upgrading to OpenCV 3 is our dependency on the old OpenCV bindings (available under `cv` and `cv2.cv`). Once I can confirm that I have fixed most of the problems, I will squash my commits [6] into a single patch and submit it. [1]: https://github.com/kevin-brown/mousetrap/tree/issue_691878 [2]: https://github.com/LiuLang/python3-xlib [3]: https://pypi.python.org/pypi/python3-xlib [4]: http://code.opencv.org/projects/opencv/versions/3 [5]: http://stackoverflow.com/a/21212023/359284 [6]: https://github.com/kevin-brown/mousetrap/compare/gnome3-wip...issue_691878
Created attachment 268542 [details] [review] Patch to add Python 3.3 support This is a squashed version of the original commit set [1] for adding in Python 3.3 support to MouseTrap. As an update to my last comment [2], a few things were cleared up during the last meeting. The code that relied on `python-xlib` is not actively used within the code base, but some references still exist, which was noted in 4664728 [3] and bug 71802 [4]. [1]: https://github.com/kevin-brown/mousetrap/compare/gnome3-wip...issue_691878 [2]: https://bugzilla.gnome.org/show_bug.cgi?id=691878#c1 [3]: https://git.gnome.org/browse/mousetrap/commit/?h=gnome3-wip&id=466472819c6f995ca7005a5bffa82af4d688b2b7 [4]: https://bugzilla.gnome.org/show_bug.cgi?id=710802
Review of attachment 268542 [details] [review]: We applied the patch and it applied fine. When we ran MouseTrap it did not behave as expected. On some runs, it started and displayed a headshot with a red rectangle that tracked for a second or two. On other executions the window opens with no camera image shown, just a small gray rectangle within the MouseTrap window. Traceback (most recent call last):
+ Trace 233171
self.itf.update_frame(self.idm.get_capture(), self.idm.get_pointer())
self.get_forehead()
self.cap.add( Point("point", "forehead", (X,Y), parent=self.cap, follow=True) )
Camera.set_lkpoint(graphic)
(cv2.TERM_CRITERIA_MAX_ITER | cv.TERM_CRITERIA_EPS, 20, 0.03))
Alos, please comment lines as you go. We don't need a line-by-line and we don't need complete explanations of changes, but the code is completely uncommented so any help towards making the code more understandable is helpful.
Created attachment 270013 [details] [review] Patch to add Python 3.3 support This is a squashed version of the original commit set [1] that adds Python 3.3 support and also documents sections of the code that were touched while adding the support. The problem that was introduced in the last patch [2] has been fixed, and now both Python 2.7 and Python 3.3 produce the same output consistently. [1]: https://github.com/kevin-brown/mousetrap/compare/79f3165...c66b1c8 [2]: https://bugzilla.gnome.org/page.cgi?id=trace.html&trace_id=233171
Review of attachment 270013 [details] [review]: Solid. I recommend commit.
Review of attachment 270013 [details] [review]: Done.
Fixed: https://git.gnome.org/browse/mousetrap/commit/?h=gnome3-wip&id=cb21fd556064391dcf54e8a44b234741a167da3f