|
@@
-0,0
+1,196
b''
|
|
|
|
|
1
|
import IPython.ipapi
|
|
|
|
|
2
|
ip = IPython.ipapi.get()
|
|
|
|
|
3
|
|
|
|
|
|
4
|
import win32api
|
|
|
|
|
5
|
import win32ui
|
|
|
|
|
6
|
import win32console
|
|
|
|
|
7
|
import dde
|
|
|
|
|
8
|
import os
|
|
|
|
|
9
|
import scitedirector
|
|
|
|
|
10
|
|
|
|
|
|
11
|
|
|
|
|
|
12
|
def setHook(synchronize_with_editor):
|
|
|
|
|
13
|
ip.set_hook("synchronize_with_editor", synchronize_with_editor)
|
|
|
|
|
14
|
|
|
|
|
|
15
|
|
|
|
|
|
16
|
def findFilename(filename):
|
|
|
|
|
17
|
if not os.path.isabs(filename):
|
|
|
|
|
18
|
filename = os.path.join(os.getcwd(), filename)
|
|
|
|
|
19
|
|
|
|
|
|
20
|
if os.path.isfile(filename):
|
|
|
|
|
21
|
return filename
|
|
|
|
|
22
|
|
|
|
|
|
23
|
return ""
|
|
|
|
|
24
|
|
|
|
|
|
25
|
|
|
|
|
|
26
|
def restoreConsoleFocus():
|
|
|
|
|
27
|
h = win32console.GetConsoleWindow()
|
|
|
|
|
28
|
console_window = win32ui.CreateWindowFromHandle(h)
|
|
|
|
|
29
|
console_window.SetForegroundWindow()
|
|
|
|
|
30
|
|
|
|
|
|
31
|
|
|
|
|
|
32
|
# This is the most simple example of hook:
|
|
|
|
|
33
|
class GVimHook:
|
|
|
|
|
34
|
def __init__(self, path, wakeup_duration):
|
|
|
|
|
35
|
self.path = path
|
|
|
|
|
36
|
self.wakeup_duration = wakeup_duration
|
|
|
|
|
37
|
|
|
|
|
|
38
|
def __call__(self, ip, filename, lineno, columnno):
|
|
|
|
|
39
|
filename = findFilename(filename)
|
|
|
|
|
40
|
|
|
|
|
|
41
|
if not filename:
|
|
|
|
|
42
|
return
|
|
|
|
|
43
|
|
|
|
|
|
44
|
command = r'start %s --remote-silent +%d "%s"' % (win32api.GetShortPathName(os.path.join(self.path, "gvim.exe")), lineno, filename)
|
|
|
|
|
45
|
os.system(command)
|
|
|
|
|
46
|
|
|
|
|
|
47
|
win32api.Sleep(self.wakeup_duration)
|
|
|
|
|
48
|
|
|
|
|
|
49
|
restoreConsoleFocus()
|
|
|
|
|
50
|
|
|
|
|
|
51
|
|
|
|
|
|
52
|
def gvim(path = r"C:\Program Files\vim\vim71", wakeup_duration = 100):
|
|
|
|
|
53
|
synchronize_with_editor = GVimHook(path, wakeup_duration)
|
|
|
|
|
54
|
setHook(synchronize_with_editor)
|
|
|
|
|
55
|
|
|
|
|
|
56
|
|
|
|
|
|
57
|
class EmacsHook:
|
|
|
|
|
58
|
def __init__(self, path, wakeup_duration, start_duration):
|
|
|
|
|
59
|
self.path = path
|
|
|
|
|
60
|
self.wakeup_duration = wakeup_duration
|
|
|
|
|
61
|
self.start_duration = start_duration
|
|
|
|
|
62
|
|
|
|
|
|
63
|
def __call__(self, ip, filename, lineno, columnno):
|
|
|
|
|
64
|
filename = findFilename(filename)
|
|
|
|
|
65
|
|
|
|
|
|
66
|
if not filename:
|
|
|
|
|
67
|
return
|
|
|
|
|
68
|
|
|
|
|
|
69
|
command = r'%s -n +%d:%d "%s" 2>nul' % (win32api.GetShortPathName(os.path.join(self.path, "emacsclient.exe")), lineno, columnno, filename)
|
|
|
|
|
70
|
r = os.system(command)
|
|
|
|
|
71
|
if r != 0:
|
|
|
|
|
72
|
command = r'start %s --quick -f server-start +%d:%d "%s"' % (win32api.GetShortPathName(os.path.join(self.path, "runemacs.exe")), lineno, columnno, filename)
|
|
|
|
|
73
|
os.system(command)
|
|
|
|
|
74
|
win32api.Sleep(self.start_duration)
|
|
|
|
|
75
|
else:
|
|
|
|
|
76
|
win32api.Sleep(self.wakeup_duration)
|
|
|
|
|
77
|
|
|
|
|
|
78
|
restoreConsoleFocus()
|
|
|
|
|
79
|
|
|
|
|
|
80
|
|
|
|
|
|
81
|
def emacs(path = r"C:\Program Files\emacs\bin", wakeup_duration = 100, start_duration = 2000):
|
|
|
|
|
82
|
synchronize_with_editor = EmacsHook(path, wakeup_duration, start_duration)
|
|
|
|
|
83
|
setHook(synchronize_with_editor)
|
|
|
|
|
84
|
|
|
|
|
|
85
|
|
|
|
|
|
86
|
class SciteHook:
|
|
|
|
|
87
|
def __init__(self, path, wakeup_duration, start_duration):
|
|
|
|
|
88
|
self.path = path
|
|
|
|
|
89
|
self.wakeup_duration = wakeup_duration
|
|
|
|
|
90
|
self.start_duration = start_duration
|
|
|
|
|
91
|
|
|
|
|
|
92
|
def __call__(self, ip, filename, lineno, columnno):
|
|
|
|
|
93
|
filename = findFilename(filename)
|
|
|
|
|
94
|
|
|
|
|
|
95
|
if not filename:
|
|
|
|
|
96
|
return
|
|
|
|
|
97
|
|
|
|
|
|
98
|
scites = scitedirector.findWindows()
|
|
|
|
|
99
|
if not scites:
|
|
|
|
|
100
|
command = r'start %s "-open:%s" -goto:%d' % (win32api.GetShortPathName(os.path.join(self.path, "scite.exe")), filename.replace("\\", "/"), lineno)
|
|
|
|
|
101
|
os.system(command)
|
|
|
|
|
102
|
|
|
|
|
|
103
|
win32api.Sleep(self.start_duration)
|
|
|
|
|
104
|
restoreConsoleFocus()
|
|
|
|
|
105
|
else:
|
|
|
|
|
106
|
scite = scites[0]
|
|
|
|
|
107
|
scitedirector.sendCommand(scite, 'open:%s' % filename.replace("\\", "/"))
|
|
|
|
|
108
|
scitedirector.sendCommand(scite, "goto:%d" % lineno)
|
|
|
|
|
109
|
|
|
|
|
|
110
|
|
|
|
|
|
111
|
def scite(path = r"C:\Program Files\SciTE Source Code Editor", wakeup_duration = 100, start_duration = 500):
|
|
|
|
|
112
|
synchronize_with_editor = SciteHook(path, wakeup_duration, start_duration)
|
|
|
|
|
113
|
setHook(synchronize_with_editor)
|
|
|
|
|
114
|
|
|
|
|
|
115
|
|
|
|
|
|
116
|
class NodePadPlusPlusHook:
|
|
|
|
|
117
|
def __init__(self, path, wakeup_duration):
|
|
|
|
|
118
|
self.path = path
|
|
|
|
|
119
|
self.wakeup_duration = wakeup_duration
|
|
|
|
|
120
|
|
|
|
|
|
121
|
def __call__(self, ip, filename, lineno, columnno):
|
|
|
|
|
122
|
filename = findFilename(filename)
|
|
|
|
|
123
|
|
|
|
|
|
124
|
if not filename:
|
|
|
|
|
125
|
return
|
|
|
|
|
126
|
|
|
|
|
|
127
|
command = r'start %s "%s" -n%d' % (win32api.GetShortPathName(os.path.join(self.path, "notepad++.exe")), filename, lineno)
|
|
|
|
|
128
|
os.system(command)
|
|
|
|
|
129
|
|
|
|
|
|
130
|
win32api.Sleep(self.wakeup_duration)
|
|
|
|
|
131
|
|
|
|
|
|
132
|
restoreConsoleFocus()
|
|
|
|
|
133
|
|
|
|
|
|
134
|
|
|
|
|
|
135
|
def notepadplusplus(path = r"C:\Program Files\Notepad++", wakeup_duration = 100):
|
|
|
|
|
136
|
synchronize_with_editor = NodePadPlusPlusHook(path, wakeup_duration)
|
|
|
|
|
137
|
setHook(synchronize_with_editor)
|
|
|
|
|
138
|
|
|
|
|
|
139
|
|
|
|
|
|
140
|
class PsPadHook:
|
|
|
|
|
141
|
def __init__(self, path, wakeup_duration):
|
|
|
|
|
142
|
self.path = path
|
|
|
|
|
143
|
self.wakeup_duration = wakeup_duration
|
|
|
|
|
144
|
|
|
|
|
|
145
|
def __call__(self, ip, filename, lineno, columnno):
|
|
|
|
|
146
|
filename = findFilename(filename)
|
|
|
|
|
147
|
|
|
|
|
|
148
|
if not filename:
|
|
|
|
|
149
|
return
|
|
|
|
|
150
|
|
|
|
|
|
151
|
command = r'start %s "%s" -%d ' % (win32api.GetShortPathName(os.path.join(self.path, "pspad.exe")), filename, lineno)
|
|
|
|
|
152
|
os.system(command)
|
|
|
|
|
153
|
|
|
|
|
|
154
|
win32api.Sleep(self.wakeup_duration)
|
|
|
|
|
155
|
|
|
|
|
|
156
|
restoreConsoleFocus()
|
|
|
|
|
157
|
|
|
|
|
|
158
|
|
|
|
|
|
159
|
def pspad(path = r"C:\Program Files\PSPad editor", wakeup_duration = 100):
|
|
|
|
|
160
|
synchronize_with_editor = PsPadHook(path, wakeup_duration)
|
|
|
|
|
161
|
setHook(synchronize_with_editor)
|
|
|
|
|
162
|
|
|
|
|
|
163
|
|
|
|
|
|
164
|
# This is an example of DDE hook:
|
|
|
|
|
165
|
class UltraEditHook:
|
|
|
|
|
166
|
def __init__(self, path, wakeup_duration, start_duration):
|
|
|
|
|
167
|
self.path = path
|
|
|
|
|
168
|
self.wakeup_duration = wakeup_duration
|
|
|
|
|
169
|
self.start_duration = start_duration
|
|
|
|
|
170
|
|
|
|
|
|
171
|
def __call__(self, ip, filename, lineno, columnno):
|
|
|
|
|
172
|
filename = findFilename(filename)
|
|
|
|
|
173
|
|
|
|
|
|
174
|
if not filename:
|
|
|
|
|
175
|
return
|
|
|
|
|
176
|
|
|
|
|
|
177
|
server = dde.CreateServer()
|
|
|
|
|
178
|
server.Create("myddeserver")
|
|
|
|
|
179
|
conversation = dde.CreateConversation(server)
|
|
|
|
|
180
|
try:
|
|
|
|
|
181
|
conversation.ConnectTo("uedit32", "System")
|
|
|
|
|
182
|
conversation.Exec(r'[open("%s/%d"])' % (filename, lineno))
|
|
|
|
|
183
|
win32api.Sleep(self.wakeup_duration)
|
|
|
|
|
184
|
except:
|
|
|
|
|
185
|
command = r'start %s "%s/%d"' % (win32api.GetShortPathName(os.path.join(self.path, "uedit32.exe")), filename, lineno)
|
|
|
|
|
186
|
os.system(command)
|
|
|
|
|
187
|
win32api.Sleep(self.start_duration)
|
|
|
|
|
188
|
|
|
|
|
|
189
|
server.Shutdown()
|
|
|
|
|
190
|
|
|
|
|
|
191
|
restoreConsoleFocus()
|
|
|
|
|
192
|
|
|
|
|
|
193
|
|
|
|
|
|
194
|
def ultraedit(path = r"C:\Program Files\IDM Computer Solutions\UltraEdit-32", wakeup_duration = 10, start_duration = 2000):
|
|
|
|
|
195
|
synchronize_with_editor = UltraEditHook(path, wakeup_duration, start_duration)
|
|
|
|
|
196
|
setHook(synchronize_with_editor)
No newline at end of file
|