Skip to content

Commit 39feb83

Browse files
committed
Add Sublime interface to talk to Sublime Text 2 using my sublime_plugin.py
1 parent eb9bc66 commit 39feb83

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

pyzen/ui/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pyzen.ui.base import load_ui
22
from pyzen.ui import osx
33
from pyzen.ui import win32
4-
from pyzen.ui import linux
4+
from pyzen.ui import linux
5+
from pyzen.ui import sublime

pyzen/ui/sublime.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import multiprocessing.connection
2+
import os
3+
import sys
4+
5+
from pyzen.ui.base import PyZenUI
6+
7+
class SublimeUI(PyZenUI):
8+
"""A PyZen UI that talks to Sublime Text 2."""
9+
10+
name = 'sublime'
11+
12+
@classmethod
13+
def _read_pidfile(cls):
14+
if sys.platform == 'darwin':
15+
base_path = os.path.join(os.environ['HOME'], 'Library', 'Application Support', 'Sublime Text 2')
16+
pid_path = os.path.join(base_path, 'sublime2.pid')
17+
if not os.path.exists(pid_path):
18+
return None
19+
pid_file = open(pid_path, 'r')
20+
pid = int(pid_file.read().strip())
21+
pid_file.close()
22+
return pid
23+
24+
@classmethod
25+
def _conn_path(cls):
26+
pid = cls._read_pidfile()
27+
if not pid:
28+
return None
29+
return '/tmp/.sublimepyzen.%s'%pid
30+
31+
@classmethod
32+
def enabled(cls):
33+
path = cls._conn_path()
34+
if not path:
35+
return False
36+
try:
37+
client = multiprocessing.connection.Client(path)
38+
client.send(['PING', None])
39+
client.close()
40+
return True
41+
except Exception:
42+
return False
43+
44+
def notify(self, failure, title, msg, icon):
45+
path = self._conn_path()
46+
if path:
47+
client = multiprocessing.connection.Client(path)
48+
client.send([os.getcwd(), (failure, title, msg)])
49+
client.close()

0 commit comments

Comments
 (0)