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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import wx.aui as wx
  5. import sys
  6. from wx.lib.wordwrap import wordwrap
  7. from IPython.gui.wx.ipython_view import IPShellWidget
  8. from IPython.gui.wx.ipython_history import IPythonHistoryPanel
  9. is_sync_frontend_ok = False
  10.  
  11. try:
  12.     from IPython.frontend.wx.ipythonx import IPythonXController
  13. except ImportError:
  14.     is_sync_frontend_ok = False
  15.  
  16. from IPython.ipapi import get
  17. __version__ = 0.91
  18. __author__ = 'Laurent Dufrechou'
  19. __email__ = 'laurent.dufrechou _at_ gmail.com'
  20. __license__ = 'BSD'
  21.  
  22. class MyFrame(wx.Frame):
  23.     
  24.     def __init__(self, parent = None, id = -1, title = 'WxIPython', pos = wx.DefaultPosition, size = (800, 600), style = wx.DEFAULT_FRAME_STYLE, sync_ok = False):
  25.         wx.Frame.__init__(self, parent, id, title, pos, size, style)
  26.         self._mgr = wx.aui.AuiManager()
  27.         self._mgr.SetManagedWindow(self)
  28.         self.history_panel = IPythonHistoryPanel(self)
  29.         self.history_panel.setOptionTrackerHook(self.optionSave)
  30.         self.ipython_panel = IPShellWidget(self, background_color = 'BLACK')
  31.         if sync_ok:
  32.             self.ipython_panel2 = IPythonXController(self)
  33.         else:
  34.             self.ipython_panel2 = None
  35.         self.ipython_panel.setHistoryTrackerHook(self.history_panel.write)
  36.         self.ipython_panel.setStatusTrackerHook(self.updateStatus)
  37.         self.ipython_panel.setAskExitHandler(self.OnExitDlg)
  38.         self.ipython_panel.setOptionTrackerHook(self.optionSave)
  39.         self.nb = wx.aui.AuiNotebook(self)
  40.         self.optionLoad()
  41.         self.statusbar = self.createStatus()
  42.         self.createMenu()
  43.         self._mgr.AddPane(self.nb, wx.CENTER, 'IPython Shells')
  44.         self.nb.AddPage(self.ipython_panel, 'IPython0 Shell')
  45.         if sync_ok:
  46.             self.nb.AddPage(self.ipython_panel2, 'IPython1 Synchroneous Shell')
  47.         
  48.         self._mgr.AddPane(self.history_panel, wx.RIGHT, 'IPython history')
  49.         self._mgr.GetPane(self.ipython_panel).CaptionVisible(True)
  50.         self._mgr.GetPane(self.history_panel).CaptionVisible(True)
  51.         self._mgr.GetPane(self.history_panel).MinSize((200, 400))
  52.         self._mgr.Update()
  53.         self.Bind(wx.EVT_CLOSE, self.OnClose)
  54.         self.Bind(wx.EVT_MENU, self.OnClose, id = wx.ID_EXIT)
  55.         self.Bind(wx.EVT_MENU, self.OnShowIPythonPanel, id = wx.ID_HIGHEST + 1)
  56.         self.Bind(wx.EVT_MENU, self.OnShowHistoryPanel, id = wx.ID_HIGHEST + 2)
  57.         self.Bind(wx.EVT_MENU, self.OnShowAbout, id = wx.ID_HIGHEST + 3)
  58.         self.Bind(wx.EVT_MENU, self.OnShowAllPanel, id = wx.ID_HIGHEST + 6)
  59.         warn_text = 'Hello from IPython and wxPython.\n'
  60.         warn_text += 'Please Note that this work is still EXPERIMENTAL\n'
  61.         warn_text += 'It does NOT emulate currently all the IPython functions.\n'
  62.         warn_text += "\nIf you use MATPLOTLIB with show() you'll need to deactivate the THREADING option.\n"
  63.         if not sync_ok:
  64.             warn_text += '\n->No twisted package detected, IPython1 example deactivated.'
  65.         
  66.         dlg = wx.MessageDialog(self, warn_text, 'Warning Box', wx.OK | wx.ICON_INFORMATION)
  67.         dlg.ShowModal()
  68.         dlg.Destroy()
  69.  
  70.     
  71.     def optionSave(self, name, value):
  72.         ip = get()
  73.         path = ip.IP.rc.ipythondir
  74.         opt = open(path + '/options.conf', 'w')
  75.         
  76.         try:
  77.             options_ipython_panel = self.ipython_panel.getOptions()
  78.             options_history_panel = self.history_panel.getOptions()
  79.             for key in options_ipython_panel.keys():
  80.                 opt.write(key + '=' + options_ipython_panel[key]['value'] + '\n')
  81.             
  82.             for key in options_history_panel.keys():
  83.                 opt.write(key + '=' + options_history_panel[key]['value'] + '\n')
  84.         finally:
  85.             opt.close()
  86.  
  87.  
  88.     
  89.     def optionLoad(self):
  90.         
  91.         try:
  92.             ip = get()
  93.             path = ip.IP.rc.ipythondir
  94.             opt = open(path + '/options.conf', 'r')
  95.             lines = opt.readlines()
  96.             opt.close()
  97.             options_ipython_panel = self.ipython_panel.getOptions()
  98.             options_history_panel = self.history_panel.getOptions()
  99.             for line in lines:
  100.                 key = line.split('=')[0]
  101.                 value = line.split('=')[1].replace('\n', '').replace('\r', '')
  102.                 if key in options_ipython_panel.keys():
  103.                     options_ipython_panel[key]['value'] = value
  104.                     continue
  105.                 if key in options_history_panel.keys():
  106.                     options_history_panel[key]['value'] = value
  107.                     continue
  108.                 print >>sys.__stdout__, 'Warning: key ', key, 'not found in widget options. Check Options.conf'
  109.             
  110.             self.ipython_panel.reloadOptions(options_ipython_panel)
  111.             self.history_panel.reloadOptions(options_history_panel)
  112.         except IOError:
  113.             print >>sys.__stdout__, 'Could not open Options.conf, defaulting to default values.'
  114.  
  115.  
  116.     
  117.     def createMenu(self):
  118.         mb = wx.MenuBar()
  119.         file_menu = wx.Menu()
  120.         file_menu.Append(wx.ID_EXIT, 'Exit')
  121.         view_menu = wx.Menu()
  122.         view_menu.Append(wx.ID_HIGHEST + 1, 'Show IPython Panel')
  123.         view_menu.Append(wx.ID_HIGHEST + 2, 'Show History Panel')
  124.         view_menu.AppendSeparator()
  125.         view_menu.Append(wx.ID_HIGHEST + 6, 'Show All')
  126.         about_menu = wx.Menu()
  127.         about_menu.Append(wx.ID_HIGHEST + 3, 'About')
  128.         mb.Append(file_menu, 'File')
  129.         mb.Append(view_menu, 'View')
  130.         mb.Append(about_menu, 'About')
  131.         self.SetMenuBar(mb)
  132.  
  133.     
  134.     def createStatus(self):
  135.         statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
  136.         statusbar.SetStatusWidths([
  137.             -2,
  138.             -3])
  139.         statusbar.SetStatusText('Ready', 0)
  140.         statusbar.SetStatusText('WxIPython ' + str(__version__), 1)
  141.         return statusbar
  142.  
  143.     
  144.     def updateStatus(self, text):
  145.         states = {
  146.             'IDLE': 'Idle',
  147.             'DO_EXECUTE_LINE': 'Send command',
  148.             'WAIT_END_OF_EXECUTION': 'Running command',
  149.             'WAITING_USER_INPUT': 'Waiting user input',
  150.             'SHOW_DOC': 'Showing doc',
  151.             'SHOW_PROMPT': 'Showing prompt' }
  152.         self.statusbar.SetStatusText(states[text], 0)
  153.  
  154.     
  155.     def OnClose(self, event):
  156.         self._mgr.UnInit()
  157.         self.Destroy()
  158.         event.Skip()
  159.  
  160.     
  161.     def OnExitDlg(self, event):
  162.         dlg = wx.MessageDialog(self, 'Are you sure you want to quit WxIPython', 'WxIPython exit', wx.ICON_QUESTION | wx.YES_NO | wx.NO_DEFAULT)
  163.         if dlg.ShowModal() == wx.ID_YES:
  164.             dlg.Destroy()
  165.             self._mgr.UnInit()
  166.             self.Destroy()
  167.         
  168.         dlg.Destroy()
  169.  
  170.     
  171.     def OnShowIPythonPanel(self, event):
  172.         self._mgr.GetPane(self.ipython_panel).Show(True)
  173.         self._mgr.Update()
  174.  
  175.     
  176.     def OnShowHistoryPanel(self, event):
  177.         self._mgr.GetPane(self.history_panel).Show(True)
  178.         self._mgr.Update()
  179.  
  180.     
  181.     def OnShowAllPanel(self, event):
  182.         self._mgr.GetPane(self.ipython_panel).Show(True)
  183.         self._mgr.GetPane(self.history_panel).Show(True)
  184.         self._mgr.Update()
  185.  
  186.     
  187.     def OnShowAbout(self, event):
  188.         info = wx.AboutDialogInfo()
  189.         info.Name = 'WxIPython'
  190.         info.Version = str(__version__)
  191.         info.Copyright = '(C) 2007 Laurent Dufrechou'
  192.         info.Description = wordwrap('A Gui that embbed a multithreaded IPython Shell', 350, wx.ClientDC(self))
  193.         info.WebSite = ('http://ipython.scipy.org/', 'IPython home page')
  194.         info.Developers = [
  195.             'Laurent Dufrechou']
  196.         licenseText = 'BSD License.\nAll rights reserved. This program and the accompanying materials are made available under the terms of the BSD which accompanies this distribution, and is available at http://www.opensource.org/licenses/bsd-license.php'
  197.         info.License = wordwrap(licenseText, 500, wx.ClientDC(self))
  198.         wx.AboutBox(info)
  199.  
  200.  
  201.  
  202. class MyApp(wx.PySimpleApp):
  203.     
  204.     def __init__(self, sync_ok = False):
  205.         wx.PySimpleApp.__init__(self)
  206.         self.frame = MyFrame(sync_ok = sync_ok)
  207.         self.frame.Show()
  208.  
  209.  
  210.  
  211. def main():
  212.     app = MyApp(is_sync_frontend_ok)
  213.     app.SetTopWindow(app.frame)
  214.     app.MainLoop()
  215.  
  216. if __name__ == '__main__':
  217.     main()
  218.  
  219.