Skip to content

Commit 64aebe1

Browse files
author
Tony Crisci
committed
break it up into packages
1 parent e91738c commit 64aebe1

13 files changed

+1318
-1261
lines changed

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include README.rst LICENSE CHANGELOG.md pytest.ini requirements.txt .flake8 .style.yapf
2+
recursive-include test *.py

i3ipc/__init__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from .i3ipc import (BarConfigReply, BarconfigUpdateEvent, BindingEvent, BindingInfo, CommandReply,
2-
Con, ConfigReply, Connection, Event, Gaps, GenericEvent, MessageType,
3-
OutputReply, Rect, TickEvent, TickReply, VersionReply, WindowEvent,
4-
WorkspaceEvent, WorkspaceReply)
1+
from .model import (BarConfigReply, BarconfigUpdateEvent, BindingEvent, BindingInfo, CommandReply,
2+
ConfigReply, Event, Gaps, GenericEvent, MessageType, OutputReply, Rect,
3+
TickEvent, TickReply, VersionReply, WindowEvent, WorkspaceEvent, WorkspaceReply)
4+
from .con import Con
5+
from .connection import Connection

i3ipc/_private/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .pubsub import PubSub
2+
from .props_object import PropsObject

i3ipc/_private/props_object.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# this is for compatability with i3ipc-glib
2+
3+
4+
class PropsObject(object):
5+
def __init__(self, obj):
6+
object.__setattr__(self, "_obj", obj)
7+
8+
def __getattribute__(self, name):
9+
return getattr(object.__getattribute__(self, "_obj"), name)
10+
11+
def __delattr__(self, name):
12+
delattr(object.__getattribute__(self, "_obj"), name)
13+
14+
def __setattr__(self, name, value):
15+
setattr(object.__getattribute__(self, "_obj"), name, value)

i3ipc/_private/pubsub.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class PubSub(object):
2+
def __init__(self, conn):
3+
self.conn = conn
4+
self._subscriptions = []
5+
6+
def subscribe(self, detailed_event, handler):
7+
event = detailed_event.replace('-', '_')
8+
detail = ''
9+
10+
if detailed_event.count('::') > 0:
11+
[event, detail] = detailed_event.split('::')
12+
13+
self._subscriptions.append({'event': event, 'detail': detail, 'handler': handler})
14+
15+
def unsubscribe(self, handler):
16+
self._subscriptions = list(filter(lambda s: s['handler'] != handler, self._subscriptions))
17+
18+
def emit(self, event, data):
19+
detail = ''
20+
21+
if data and hasattr(data, 'change'):
22+
detail = data.change
23+
24+
for s in self._subscriptions:
25+
if s['event'] == event:
26+
if not s['detail'] or s['detail'] == detail:
27+
if data:
28+
s['handler'](self.conn, data)
29+
else:
30+
s['handler'](self.conn)

0 commit comments

Comments
 (0)