After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 691878 - Convert to Python 3
Convert to Python 3
Status: RESOLVED FIXED
Product: mousetrap
Classification: Other
Component: General
unspecified
Other Linux
: Normal normal
: ---
Assigned To: mousetrap-maint
mousetrap-maint
Depends on:
Blocks:
 
 
Reported: 2013-01-16 17:53 UTC by Joanmarie Diggs (IRC: joanie)
Modified: 2014-02-24 17:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to add Python 3.3 support (11.43 KB, patch)
2014-02-09 02:25 UTC, Kevin Brown
needs-work Details | Review
Patch to add Python 3.3 support (15.21 KB, patch)
2014-02-22 20:44 UTC, Kevin Brown
committed Details | Review

Description Joanmarie Diggs (IRC: joanie) 2013-01-16 17:53:45 UTC
GNOME 3.8 is Python 3 based. Mousetrap is not.
Comment 1 Kevin Brown 2014-02-04 01:07:17 UTC
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
Comment 2 Kevin Brown 2014-02-09 02:25:42 UTC
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
Comment 3 Heidi Ellis 2014-02-13 16:37:18 UTC
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):
  • File "/usr/local/lib64/python2.7/site-packages/mousetrap/app/main.py", line 242 in update_frame
    self.itf.update_frame(self.idm.get_capture(), self.idm.get_pointer())
  • File "/usr/local/lib64/python2.7/site-packages/mousetrap/ocvfw/idm/forehead.py", line 126 in get_capture
    self.get_forehead()
  • File "/usr/local/lib64/python2.7/site-packages/mousetrap/ocvfw/idm/forehead.py", line 168 in get_forehead
    self.cap.add( Point("point", "forehead", (X,Y), parent=self.cap, follow=True) )
  • File "/usr/local/lib64/python2.7/site-packages/mousetrap/ocvfw/dev/camera.py", line 348 in add
    Camera.set_lkpoint(graphic)
  • File "/usr/local/lib64/python2.7/site-packages/mousetrap/ocvfw/_ocv.py", line 166 in set_lkpoint
    (cv2.TERM_CRITERIA_MAX_ITER | cv.TERM_CRITERIA_EPS, 20, 0.03))
AttributeError: 'module' object has no attribute 'TERM_CRITERIA_EPS'

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.
Comment 4 Kevin Brown 2014-02-22 20:44:56 UTC
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
Comment 5 Stoney Jackson 2014-02-24 16:48:40 UTC
Review of attachment 270013 [details] [review]:

Solid. I recommend commit.
Comment 6 Stoney Jackson 2014-02-24 17:09:56 UTC
Review of attachment 270013 [details] [review]:

Done.