##// END OF EJS Templates
Put togehter the few win32 call into some functions (sleep, runCommand, restoreConsoleFocus) to ease the port to other platforms.
vds -
Show More
@@ -23,12 +23,33 b' def findFilename(filename):'
23 return ""
23 return ""
24
24
25
25
26 def runCommand(path, command, arguments, asynchronous = True):
27 line = ''
28 if asynchronous:
29 line += 'start '
30
31 try:
32 line += win32api.GetShortPathName(os.path.join(path, command) + ".exe") + " "
33 except:
34 print 'could not find: "%s"' % (os.path.join(path, command) + ".exe")
35 return -1
36
37 line += arguments
38 r = os.system(line)
39 return r
40
41
42 def sleep(milliseconds):
43 win32api.Sleep(milliseconds)
44
45
26 def restoreConsoleFocus():
46 def restoreConsoleFocus():
27 h = win32console.GetConsoleWindow()
47 h = win32console.GetConsoleWindow()
28 console_window = win32ui.CreateWindowFromHandle(h)
48 console_window = win32ui.CreateWindowFromHandle(h)
29 console_window.SetForegroundWindow()
49 console_window.SetForegroundWindow()
30
50
31
51
52
32 # This is the most simple example of hook:
53 # This is the most simple example of hook:
33 class GVimHook:
54 class GVimHook:
34 def __init__(self, path, wakeup_duration):
55 def __init__(self, path, wakeup_duration):
@@ -41,10 +62,9 b' class GVimHook:'
41 if not filename:
62 if not filename:
42 return
63 return
43
64
44 command = r'start %s --remote-silent +%d "%s"' % (win32api.GetShortPathName(os.path.join(self.path, "gvim.exe")), lineno, filename)
65 runCommand(self.path, 'gvim', '--remote-silent +%d "%s"' % (lineno, filename))
45 os.system(command)
46
66
47 win32api.Sleep(self.wakeup_duration)
67 sleep(self.wakeup_duration)
48
68
49 restoreConsoleFocus()
69 restoreConsoleFocus()
50
70
@@ -66,14 +86,12 b' class EmacsHook:'
66 if not filename:
86 if not filename:
67 return
87 return
68
88
69 command = r'%s -n +%d:%d "%s" 2>nul' % (win32api.GetShortPathName(os.path.join(self.path, "emacsclient.exe")), lineno, columnno, filename)
89 r = runCommand(self.path, "emacsclient", '-n +%d:%d "%s" 2>nul' % (lineno, columnno, filename), False)
70 r = os.system(command)
71 if r != 0:
90 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)
91 runCommand(self.path, 'runemacs', '--quick -f server-start +%d:%d "%s"' % (lineno, columnno, filename))
73 os.system(command)
92 sleep(self.start_duration)
74 win32api.Sleep(self.start_duration)
75 else:
93 else:
76 win32api.Sleep(self.wakeup_duration)
94 sleep(self.wakeup_duration)
77
95
78 restoreConsoleFocus()
96 restoreConsoleFocus()
79
97
@@ -97,10 +115,9 b' class SciteHook:'
97
115
98 scites = scitedirector.findWindows()
116 scites = scitedirector.findWindows()
99 if not scites:
117 if not scites:
100 command = r'start %s "-open:%s" -goto:%d' % (win32api.GetShortPathName(os.path.join(self.path, "scite.exe")), filename.replace("\\", "/"), lineno)
118 runCommand(self.path, "scite", '"-open:%s" -goto:%d' % (filename.replace("\\", "/"), lineno))
101 os.system(command)
102
119
103 win32api.Sleep(self.start_duration)
120 sleep(self.start_duration)
104 restoreConsoleFocus()
121 restoreConsoleFocus()
105 else:
122 else:
106 scite = scites[0]
123 scite = scites[0]
@@ -124,10 +141,9 b' class NodePadPlusPlusHook:'
124 if not filename:
141 if not filename:
125 return
142 return
126
143
127 command = r'start %s "%s" -n%d' % (win32api.GetShortPathName(os.path.join(self.path, "notepad++.exe")), filename, lineno)
144 runCommand(self.path, "notepad++", '"%s" -n%d' % (filename, lineno))
128 os.system(command)
129
145
130 win32api.Sleep(self.wakeup_duration)
146 sleep(self.wakeup_duration)
131
147
132 restoreConsoleFocus()
148 restoreConsoleFocus()
133
149
@@ -148,10 +164,9 b' class PsPadHook:'
148 if not filename:
164 if not filename:
149 return
165 return
150
166
151 command = r'start %s "%s" -%d ' % (win32api.GetShortPathName(os.path.join(self.path, "pspad.exe")), filename, lineno)
167 runCommand(self.path, "pspad", '"%s" -%d' % (filename, lineno))
152 os.system(command)
153
168
154 win32api.Sleep(self.wakeup_duration)
169 sleep(self.wakeup_duration)
155
170
156 restoreConsoleFocus()
171 restoreConsoleFocus()
157
172
@@ -180,11 +195,12 b' class UltraEditHook:'
180 try:
195 try:
181 conversation.ConnectTo("uedit32", "System")
196 conversation.ConnectTo("uedit32", "System")
182 conversation.Exec(r'[open("%s/%d"])' % (filename, lineno))
197 conversation.Exec(r'[open("%s/%d"])' % (filename, lineno))
183 win32api.Sleep(self.wakeup_duration)
198
199 sleep(self.wakeup_duration)
184 except:
200 except:
185 command = r'start %s "%s/%d"' % (win32api.GetShortPathName(os.path.join(self.path, "uedit32.exe")), filename, lineno)
201 runCommand(self.path, 'uedit32', '"%s/%d"' % (filename, lineno))
186 os.system(command)
202
187 win32api.Sleep(self.start_duration)
203 sleep(self.start_duration)
188
204
189 server.Shutdown()
205 server.Shutdown()
190
206
@@ -194,3 +210,4 b' class UltraEditHook:'
194 def ultraedit(path = r"C:\Program Files\IDM Computer Solutions\UltraEdit-32", wakeup_duration = 10, start_duration = 2000):
210 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)
211 synchronize_with_editor = UltraEditHook(path, wakeup_duration, start_duration)
196 setHook(synchronize_with_editor)
212 setHook(synchronize_with_editor)
213 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now