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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4.  
  5. try:
  6.     import wx
  7. except ImportError:
  8.     e = None
  9.     e.message = '%s\n________________________________________________________________________________\nYou need wxPython to run this application.\n' % e.message
  10.     e.args = (e.message,) + e.args[1:]
  11.     raise e
  12.  
  13. from wx_frontend import WxController
  14. import __builtin__
  15.  
  16. class IPythonXController(WxController):
  17.     debug = False
  18.     
  19.     def __init__(self, *args, **kwargs):
  20.         WxController.__init__(self, *args, **kwargs)
  21.         self.ipython0.ask_exit = self.do_exit
  22.         maxrange = self.GetScrollRange(wx.VERTICAL)
  23.         self.ScrollLines(-maxrange)
  24.  
  25.     
  26.     def _on_key_down(self, event, skip = True):
  27.         if event.KeyCode == ord('D') and event.ControlDown() and self.input_buffer == '' and self._input_state == 'readline':
  28.             wx.CallAfter(self.ask_exit)
  29.         else:
  30.             WxController._on_key_down(self, event, skip = skip)
  31.  
  32.     
  33.     def ask_exit(self):
  34.         self._input_state = 'subprocess'
  35.         self.write('\n', refresh = False)
  36.         self.capture_output()
  37.         self.ipython0.shell.exit()
  38.         self.release_output()
  39.         if not self.ipython0.exit_now:
  40.             wx.CallAfter(self.new_prompt, self.input_prompt_template.substitute(number = self.last_result['number'] + 1))
  41.         else:
  42.             wx.CallAfter(wx.GetApp().Exit)
  43.         self.write('Exiting ...', refresh = False)
  44.  
  45.     
  46.     def do_exit(self):
  47.         WxController.do_exit(self)
  48.         self.release_output()
  49.         wx.CallAfter(wx.Exit)
  50.  
  51.  
  52.  
  53. class IPythonX(wx.Frame):
  54.     
  55.     def __init__(self, parent, id, title, debug = False):
  56.         wx.Frame.__init__(self, parent, id, title, size = (300, 250))
  57.         self._sizer = wx.BoxSizer(wx.VERTICAL)
  58.         self.shell = IPythonXController(self, debug = debug)
  59.         self._sizer.Add(self.shell, 1, wx.EXPAND)
  60.         self.SetSizer(self._sizer)
  61.         self.SetAutoLayout(1)
  62.         self.Show(True)
  63.         wx.EVT_CLOSE(self, self.on_close)
  64.  
  65.     
  66.     def on_close(self, event):
  67.         wx.CallAfter(wx.Exit)
  68.  
  69.  
  70.  
  71. def main():
  72.     OptionParser = OptionParser
  73.     import optparse
  74.     usage = 'usage: %prog [options]\n\nSimple graphical frontend to IPython, using WxWidgets.'
  75.     parser = OptionParser(usage = usage)
  76.     parser.add_option('-d', '--debug', action = 'store_true', dest = 'debug', default = False, help = 'Enable debug message for the wx frontend.')
  77.     (options, args) = parser.parse_args()
  78.     import sys
  79.     sys.argv = sys.argv[:1]
  80.     app = wx.PySimpleApp()
  81.     frame = IPythonX(None, wx.ID_ANY, 'IPythonX', debug = options.debug)
  82.     frame.shell.SetFocus()
  83.     frame.shell.app = app
  84.     frame.SetSize((680, 460))
  85.     app.MainLoop()
  86.  
  87. if __name__ == '__main__':
  88.     main()
  89.  
  90.