Skip to content

Commit a13ec8b

Browse files
author
Tony Crisci
committed
Initial commit
0 parents  commit a13ec8b

File tree

7 files changed

+242
-0
lines changed

7 files changed

+242
-0
lines changed

.gitignore

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
bin/
12+
build/
13+
develop-eggs/
14+
dist/
15+
eggs/
16+
lib/
17+
lib64/
18+
parts/
19+
sdist/
20+
var/
21+
*.egg-info/
22+
.installed.cfg
23+
*.egg
24+
25+
# Installer logs
26+
pip-log.txt
27+
pip-delete-this-directory.txt
28+
29+
# Unit test / coverage reports
30+
htmlcov/
31+
.tox/
32+
.coverage
33+
.cache
34+
nosetests.xml
35+
coverage.xml
36+
37+
# Translations
38+
*.mo
39+
40+
# Mr Developer
41+
.mr.developer.cfg
42+
.project
43+
.pydevproject
44+
45+
# Rope
46+
.ropeproject
47+
48+
# Django stuff:
49+
*.log
50+
*.pot
51+
52+
# Sphinx documentation
53+
docs/_build/
54+
55+
# Editor
56+
.clang_complete
57+
tags
58+
*.swp

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SUBDIRS=overrides

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# i3ipc-python
2+
3+
An improved Python library to control [i3wm](http://i3wm.org).
4+
5+
## About
6+
7+
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.
8+
9+
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.
10+
11+
## Documentation
12+
13+
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/)).
14+
15+
## Installation
16+
17+
i3ipc-python requires [i3ipc-GLib](https://github.com/acrisci/i3ipc-glib) and [PyGObject](https://wiki.gnome.org/action/show/Projects/PyGObject).
18+
19+
Then simply do:
20+
21+
```shell
22+
./autogen.sh
23+
sudo make install
24+
```
25+
26+
Or get someone to host a package for your distro.
27+
28+
## Example
29+
30+
```python
31+
#!/usr/bin/env python3
32+
33+
from gi.repository import i3ipc
34+
35+
# Create the Connection object that can be used to send commands and subscribe
36+
# to events.
37+
conn = i3ipc.Connection()
38+
39+
# Query the ipc for outputs. The result is a list that represents the parsed
40+
# reply of a command like `i3-msg -t get_outputs`.
41+
outputs = conn.get_outputs()
42+
43+
print('Active outputs:')
44+
45+
for output in filter(lambda o: o.active, outputs):
46+
print(output.name)
47+
48+
# Send a command to be executed synchronously.
49+
conn.command('focus left')
50+
51+
# Define a callback to be called when you switch workspaces.
52+
def on_workspace(self, e):
53+
# The first parameter is the connection to the ipc and the second is an object
54+
# with the data of the event sent from i3.
55+
if e.current:
56+
print('Windows on this workspace:')
57+
for w in e.current.descendents():
58+
print(w.name)
59+
60+
# Subscribe to the workspace event
61+
conn.on('workspace', on_workspace)
62+
63+
# Start the main loop and wait for events to come in.
64+
conn.main()
65+
```
66+
67+
## Contributing
68+
69+
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).
70+
71+
## License
72+
73+
This work is available under the GNU General Public License (See COPYING).
74+
75+
Copyright © 2014, Tony Crisci
76+
77+
All rights reserved.

autogen.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
# Run this to generate all the initial makefiles, etc.
3+
4+
test -n "$srcdir" || srcdir=`dirname "$0"`
5+
test -n "$srcdir" || srcdir=.
6+
7+
olddir=`pwd`
8+
9+
cd $srcdir
10+
PROJECT=i3ipc-python
11+
TEST_TYPE=-f
12+
FILE=overrides/i3ipc.py
13+
14+
test $TEST_TYPE $FILE || {
15+
echo "You must run this script in the top-level $PROJECT directory"
16+
exit 1
17+
}
18+
19+
AUTORECONF=`which autoreconf`
20+
if test -z $AUTORECONF; then
21+
echo "*** No autoreconf found, please install it ***"
22+
exit 1
23+
fi
24+
25+
# NOCONFIGURE is used by gnome-common
26+
if test -z "$NOCONFIGURE"; then
27+
if test -z "$*"; then
28+
echo "I am going to run ./configure with no arguments - if you wish "
29+
echo "to pass any to it, please specify them on the $0 command line."
30+
fi
31+
fi
32+
33+
rm -rf autom4te.cache
34+
35+
autoreconf --force --install --verbose || exit $?
36+
37+
cd "$olddir"
38+
test -n "$NOCONFIGURE" || "$srcdir/configure" "$@"

configure.ac

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
AC_PREREQ(2.69)
2+
3+
AC_INIT([i3ipc-python], [0.0.1], [tony@dubstepdish.com])
4+
5+
AM_INIT_AUTOMAKE([-Wall -Werror foreign -Wno-portability])
6+
7+
AM_PATH_PYTHON([3],, [:])
8+
9+
PKG_CHECK_MODULES([PYGOBJECT], [pygobject-3.0])
10+
PKG_CHECK_MODULES([I3IPC], [i3ipc-glib-1.0])
11+
12+
AC_ARG_WITH([pygi_overrides_dir],
13+
AC_HELP_STRING([--with-pygi-overrides-dir], [Path to pygobject overrides directory]))
14+
15+
AC_MSG_CHECKING(for pygobject overrides directory)
16+
if test "x$with_pygi_overrides_dir" = "x" ; then
17+
overrides_dir="`$PYTHON -c 'import gi; print(gi._overridesdir)' 2>/dev/null`"
18+
# fallback if the previous failed
19+
if test "x$overrides_dir" = "x" ; then
20+
overrides_dir="${pyexecdir}/gi/overrides"
21+
fi
22+
else
23+
overrides_dir="$with_pygi_overrides_dir"
24+
fi
25+
26+
PYGI_OVERRIDES_DIR="$overrides_dir"
27+
AC_SUBST(PYGI_OVERRIDES_DIR)
28+
AC_MSG_RESULT($PYGI_OVERRIDES_DIR)
29+
30+
AM_SILENT_RULES([yes])
31+
32+
AC_CONFIG_FILES([
33+
Makefile
34+
overrides/Makefile
35+
])
36+
37+
AC_OUTPUT

overrides/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# We install everything in the gi/overrides folder
2+
pygioverridesdir = $(PYGI_OVERRIDES_DIR)
3+
pygioverrides_PYTHON = i3ipc.py
4+
pygioverridesexecdir = $(PYGI_OVERRIDES_DIR)

overrides/i3ipc.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from gi.repository.GLib import MainLoop
2+
from ..module import get_introspection_module
3+
from ..overrides import override
4+
5+
i3ipc = get_introspection_module('i3ipc')
6+
7+
__all__ = []
8+
9+
class Connection(i3ipc.Connection):
10+
def main(self):
11+
MainLoop().run()
12+
13+
Connection = override(Connection)
14+
__all__.append('Connection')
15+
16+
class Con(i3ipc.Con):
17+
def __getattr__(self, name):
18+
if name == 'nodes':
19+
return self.get_nodes()
20+
try:
21+
return self.get_property(name)
22+
except TypeError:
23+
raise AttributeError
24+
25+
26+
Con = override(Con)
27+
__all__.append('Con')

0 commit comments

Comments
 (0)