Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get WNCK working with Python 3.5?

I have a project right now and I'm using WNCK to find the location of open windows, as well as focus them. I recently added features that require Python 3.5, but WNCK is only working with Python 2.7 or whatever I have installed. When running python3 stuff.py, I'm getting

ImportError: No module named 'wnck'

Does anyone know how I can get the wnck library for Python 3? I previously got it for python2 with sudo apt-get install python-wnck

I'm using Ubuntu, so if the answer is anything like "Can't get WNCK working, switch to X", please make sure it's not a windows only solution

like image 575
Nerdsie Avatar asked Dec 11 '22 12:12

Nerdsie


1 Answers

From python3 onwards wnck is part of the GObject Introspection API. You can presently get access to wnck3 in python3 on Debian (and therefore I presume identically on Ubuntu) with:

apt-get install python3-gi gir1.2-wnck-3.0

Obviously the gir- and wnck- versions will vary over time (or you may need e.g. an older version of wnck), but:

apt-cache search 'gir.*wnck'

should be enough for finding what you want. I personally prefer to leverage the power of aptitude-search with

aptitude search '?depends(libgirepository) wnck'

Due to the flexibility of the Introspection API, importing is slightly more complex, for example:

>>> import gi
>>> gi.require_version('Wnck', '3.0')
>>> from gi.repository import Wnck

Documentation for python3/wnck3 can be found here.

like image 104
rowanthorpe Avatar answered Dec 22 '22 16:12

rowanthorpe