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