-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tony Crisci
committed
Mar 8, 2014
0 parents
commit a13ec8b
Showing
7 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
bin/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# Rope | ||
.ropeproject | ||
|
||
# Django stuff: | ||
*.log | ||
*.pot | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# Editor | ||
.clang_complete | ||
tags | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SUBDIRS=overrides |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# i3ipc-python | ||
|
||
An improved Python library to control [i3wm](http://i3wm.org). | ||
|
||
## About | ||
|
||
i3's interprocess communication (or [ipc](http://i3wm.org/docs/ipc.html)) is the interface i3wm uses to receive [commands](http://i3wm.org/docs/userguide.html#_list_of_commands) from client applications such as `i3-msg`. It also features a publish/subscribe mechanism for notifying interested parties of window manager events. | ||
|
||
i3ipc-python is a Python library for controlling the window manager. This project is intended to be useful for general scripting, and for applications that interact with the window manager like status line generators, notification daemons, and pagers. | ||
|
||
## Documentation | ||
|
||
The latest documentation can be found [here](http://dubstepdish.com/i3ipc-glib). i3ipc-python is a [GObject introspection](https://developer.gnome.org/gobject/stable/) library (kind of like [gtk](https://developer.gnome.org/)). | ||
|
||
## Installation | ||
|
||
i3ipc-python requires [i3ipc-GLib](https://github.com/acrisci/i3ipc-glib) and [PyGObject](https://wiki.gnome.org/action/show/Projects/PyGObject). | ||
|
||
Then simply do: | ||
|
||
```shell | ||
./autogen.sh | ||
sudo make install | ||
``` | ||
|
||
Or get someone to host a package for your distro. | ||
|
||
## Example | ||
|
||
```python | ||
#!/usr/bin/env python3 | ||
|
||
from gi.repository import i3ipc | ||
|
||
# Create the Connection object that can be used to send commands and subscribe | ||
# to events. | ||
conn = i3ipc.Connection() | ||
|
||
# Query the ipc for outputs. The result is a list that represents the parsed | ||
# reply of a command like `i3-msg -t get_outputs`. | ||
outputs = conn.get_outputs() | ||
|
||
print('Active outputs:') | ||
|
||
for output in filter(lambda o: o.active, outputs): | ||
print(output.name) | ||
|
||
# Send a command to be executed synchronously. | ||
conn.command('focus left') | ||
|
||
# Define a callback to be called when you switch workspaces. | ||
def on_workspace(self, e): | ||
# The first parameter is the connection to the ipc and the second is an object | ||
# with the data of the event sent from i3. | ||
if e.current: | ||
print('Windows on this workspace:') | ||
for w in e.current.descendents(): | ||
print(w.name) | ||
|
||
# Subscribe to the workspace event | ||
conn.on('workspace', on_workspace) | ||
|
||
# Start the main loop and wait for events to come in. | ||
conn.main() | ||
``` | ||
|
||
## Contributing | ||
|
||
We should do what we can to make this library as "Pythonic" as good tastes allows. New features should be implemented on the main project at [i3ipc-GLib](https://github.com/acrisci/i3ipc-glib). | ||
|
||
## License | ||
|
||
This work is available under the GNU General Public License (See COPYING). | ||
|
||
Copyright © 2014, Tony Crisci | ||
|
||
All rights reserved. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/sh | ||
# Run this to generate all the initial makefiles, etc. | ||
|
||
test -n "$srcdir" || srcdir=`dirname "$0"` | ||
test -n "$srcdir" || srcdir=. | ||
|
||
olddir=`pwd` | ||
|
||
cd $srcdir | ||
PROJECT=i3ipc-python | ||
TEST_TYPE=-f | ||
FILE=overrides/i3ipc.py | ||
|
||
test $TEST_TYPE $FILE || { | ||
echo "You must run this script in the top-level $PROJECT directory" | ||
exit 1 | ||
} | ||
|
||
AUTORECONF=`which autoreconf` | ||
if test -z $AUTORECONF; then | ||
echo "*** No autoreconf found, please install it ***" | ||
exit 1 | ||
fi | ||
|
||
# NOCONFIGURE is used by gnome-common | ||
if test -z "$NOCONFIGURE"; then | ||
if test -z "$*"; then | ||
echo "I am going to run ./configure with no arguments - if you wish " | ||
echo "to pass any to it, please specify them on the $0 command line." | ||
fi | ||
fi | ||
|
||
rm -rf autom4te.cache | ||
|
||
autoreconf --force --install --verbose || exit $? | ||
|
||
cd "$olddir" | ||
test -n "$NOCONFIGURE" || "$srcdir/configure" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
AC_PREREQ(2.69) | ||
|
||
AC_INIT([i3ipc-python], [0.0.1], [[email protected]]) | ||
|
||
AM_INIT_AUTOMAKE([-Wall -Werror foreign -Wno-portability]) | ||
|
||
AM_PATH_PYTHON([3],, [:]) | ||
|
||
PKG_CHECK_MODULES([PYGOBJECT], [pygobject-3.0]) | ||
PKG_CHECK_MODULES([I3IPC], [i3ipc-glib-1.0]) | ||
|
||
AC_ARG_WITH([pygi_overrides_dir], | ||
AC_HELP_STRING([--with-pygi-overrides-dir], [Path to pygobject overrides directory])) | ||
|
||
AC_MSG_CHECKING(for pygobject overrides directory) | ||
if test "x$with_pygi_overrides_dir" = "x" ; then | ||
overrides_dir="`$PYTHON -c 'import gi; print(gi._overridesdir)' 2>/dev/null`" | ||
# fallback if the previous failed | ||
if test "x$overrides_dir" = "x" ; then | ||
overrides_dir="${pyexecdir}/gi/overrides" | ||
fi | ||
else | ||
overrides_dir="$with_pygi_overrides_dir" | ||
fi | ||
|
||
PYGI_OVERRIDES_DIR="$overrides_dir" | ||
AC_SUBST(PYGI_OVERRIDES_DIR) | ||
AC_MSG_RESULT($PYGI_OVERRIDES_DIR) | ||
|
||
AM_SILENT_RULES([yes]) | ||
|
||
AC_CONFIG_FILES([ | ||
Makefile | ||
overrides/Makefile | ||
]) | ||
|
||
AC_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# We install everything in the gi/overrides folder | ||
pygioverridesdir = $(PYGI_OVERRIDES_DIR) | ||
pygioverrides_PYTHON = i3ipc.py | ||
pygioverridesexecdir = $(PYGI_OVERRIDES_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from gi.repository.GLib import MainLoop | ||
from ..module import get_introspection_module | ||
from ..overrides import override | ||
|
||
i3ipc = get_introspection_module('i3ipc') | ||
|
||
__all__ = [] | ||
|
||
class Connection(i3ipc.Connection): | ||
def main(self): | ||
MainLoop().run() | ||
|
||
Connection = override(Connection) | ||
__all__.append('Connection') | ||
|
||
class Con(i3ipc.Con): | ||
def __getattr__(self, name): | ||
if name == 'nodes': | ||
return self.get_nodes() | ||
try: | ||
return self.get_property(name) | ||
except TypeError: | ||
raise AttributeError | ||
|
||
|
||
Con = override(Con) | ||
__all__.append('Con') |