<s> """<STR_LIT>""" <EOL> __author__ = "<STR_LIT>" <EOL> __version__ = "<STR_LIT>" <EOL> import os <EOL> import wx <EOL> from traits . api import Any , Bool <EOL> from envisage . plugins . remote_editor . editor_plugins . editor_plugin import EditorPlugin <EOL> from wx . tools . Editra . src import ed_menu <EOL> from profiler import Profile_Get <EOL> _ = wx . GetTranslation <EOL> ID_RUN_SCRIPT = wx . NewId ( ) <EOL> ID_RUN_TEXT = wx . NewId ( ) <EOL> class EditraEditorPlugin ( EditorPlugin ) : <EOL> ui_dispatch = '<STR_LIT>' <EOL> main_window = Any <EOL> raise_on_command = Bool ( True ) <EOL> def new ( self ) : <EOL> """<STR_LIT>""" <EOL> notebook = self . main_window . GetNotebook ( ) <EOL> current = notebook . GetCurrentCtrl ( ) <EOL> if current . GetFileName ( ) != "<STR_LIT>" or str ( current . GetText ( ) ) != "<STR_LIT>" : <EOL> notebook . NewPage ( ) <EOL> notebook . GoCurrentPage ( ) <EOL> current . FindLexer ( '<STR_LIT>' ) <EOL> current . BackSpaceUnIndents = True <EOL> if self . raise_on_command : <EOL> self . main_window . Raise ( ) <EOL> def open ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> self . main_window . DoOpen ( None , filename ) <EOL> if self . raise_on_command : <EOL> self . main_window . Raise ( ) <EOL> class RemoteEditorPlugin ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , Editra = None ) : <EOL> self . Editra = Editra <EOL> def do_PlugIt ( self ) : <EOL> self . mainWindow = mainWindow = wx . GetApp ( ) . GetMainWindow ( ) <EOL> self . log = wx . GetApp ( ) . GetLog ( ) <EOL> self . log ( "<STR_LIT>" ) <EOL> menuBar = mainWindow . GetMenuBar ( ) <EOL> self . client = EditraEditorPlugin ( main_window = self . mainWindow ) <EOL> self . client . register ( ) <EOL> mainWindow . Bind ( wx . EVT_KEY_DOWN , self . OnKeyDown ) <EOL> toolsMenu = menuBar . GetMenuByName ( "<STR_LIT>" ) <EOL> mnu_run_text = wx . MenuItem ( toolsMenu , ID_RUN_TEXT , <EOL> _ ( '<STR_LIT>' ) , <EOL> _ ( '<STR_LIT>' ) , <EOL> wx . ITEM_NORMAL ) <EOL> mnu_run_text . SetBitmap ( wx . Bitmap ( os . path . join ( <EOL> os . path . dirname ( __file__ ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> toolsMenu . AppendItem ( mnu_run_text , use_bmp = False ) <EOL> mnu_run_script = wx . MenuItem ( toolsMenu , ID_RUN_SCRIPT , <EOL> _ ( '<STR_LIT>' ) , <EOL> _ ( '<STR_LIT>' ) ) <EOL> mnu_run_script . SetBitmap ( wx . Bitmap ( os . path . join ( <EOL> os . path . dirname ( __file__ ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> toolsMenu . AppendItem ( mnu_run_script , use_bmp = False ) <EOL> self . mainWindow . _handlers [ '<STR_LIT>' ] . extend ( <EOL> [ ( ID_RUN_SCRIPT , self . OnRunScript ) , <EOL> ( ID_RUN_TEXT , self . OnRunText ) ] ) <EOL> self . mainWindow . _handlers [ '<STR_LIT>' ] . insert ( <NUM_LIT:0> , <EOL> ( ID_RUN_TEXT , self . EnableSelection ) , ) <EOL> toolBar = mainWindow . GetToolBar ( ) <EOL> self . run_sel_tb = toolBar . AddLabelTool ( <EOL> ID_RUN_TEXT , '<STR_LIT>' , <EOL> wx . Bitmap ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> shortHelp = '<STR_LIT>' , <EOL> longHelp = '<STR_LIT>' ) <EOL> self . run_file_tb = toolBar . AddLabelTool ( <EOL> ID_RUN_SCRIPT , '<STR_LIT>' , <EOL> wx . Bitmap ( os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> shortHelp = '<STR_LIT>' , <EOL> longHelp = '<STR_LIT>' ) <EOL> toolBar . Realize ( ) <EOL> def OnRunScript ( self , event ) : <EOL> """<STR_LIT>""" <EOL> notebook = self . mainWindow . GetNotebook ( ) <EOL> currentTab = notebook . GetCurrentCtrl ( ) <EOL> filename = currentTab . GetFileName ( ) <EOL> if filename == "<STR_LIT>" : <EOL> if self . mainWindow . OnSaveAs ( None , page = currentTab ) : <EOL> filename = currentTab . GetFileName ( ) <EOL> else : <EOL> return <EOL> else : <EOL> if currentTab . GetModify ( ) : <EOL> result = notebook . frame . ModifySave ( ) <EOL> if result == wx . ID_CANCEL : <EOL> return <EOL> self . client . send_command ( '<STR_LIT>' , filename ) <EOL> def OnRunText ( self , event ) : <EOL> """<STR_LIT>""" <EOL> currentTab = self . mainWindow . GetNotebook ( ) . GetCurrentCtrl ( ) <EOL> text = str ( currentTab . GetSelectedText ( ) ) <EOL> if text == "<STR_LIT>" : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> self . mainWindow . PushStatusText ( msg ) <EOL> else : <EOL> self . client . send_command ( '<STR_LIT>' , text ) <EOL> def OnKeyDown ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . GetKeyCode ( ) == wx . WXK_RETURN : <EOL> if event . ShiftDown ( ) : <EOL> self . OnRunText ( event ) <EOL> elif event . ControlDown ( ) : <EOL> self . OnRunScript ( event ) <EOL> else : <EOL> event . Skip ( ) <EOL> def EnableSelection ( self , evt ) : <EOL> if not self . mainWindow . IsActive ( ) : <EOL> return <EOL> e_id = evt . GetId ( ) <EOL> evt . SetMode ( wx . UPDATE_UI_PROCESS_SPECIFIED ) <EOL> evt . SetUpdateInterval ( <NUM_LIT:200> ) <EOL> ctrl = self . mainWindow . nb . GetCurrentCtrl ( ) <EOL> if e_id == ID_RUN_TEXT : <EOL> evt . Enable ( ctrl . GetSelectionStart ( ) != ctrl . GetSelectionEnd ( ) ) <EOL> else : <EOL> evt . Skip ( ) </s>
