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