home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1762 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  8.3 KB  |  214 lines

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