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