<s> import wx <EOL> from robotide . action import ActionInfoCollection , ActionFactory , SeparatorInfo <EOL> from robotide . context import ABOUT_RIDE , SHORTCUT_KEYS <EOL> from robotide . controller . commands import SaveFile , SaveAll <EOL> from robotide . publish import RideSaveAll , RideClosing , RideSaved , PUBLISHER , RideInputValidationError , RideTreeSelection , RideModificationPrevented <EOL> from robotide . ui . tagdialogs import ViewAllTagsDialog <EOL> from robotide . ui . filedialogs import RobotFilePathDialog <EOL> from robotide . utils import RideEventHandler <EOL> from robotide . widgets import Dialog , ImageProvider , HtmlWindow <EOL> from robotide . preferences import PreferenceEditor <EOL> from . actiontriggers import MenuBar , ToolBar , ShortcutRegistry <EOL> from . filedialogs import ( NewProjectDialog , InitFileFormatDialog ) <EOL> from . review import ReviewDialog <EOL> from . pluginmanager import PluginManager <EOL> from robotide . action . shortcut import localize_shortcuts <EOL> from . tree import Tree <EOL> from . notebook import NoteBook <EOL> from . progress import LoadProgressObserver <EOL> _menudata = """<STR_LIT>""" <EOL> class RideFrame ( wx . Frame , RideEventHandler ) : <EOL> def __init__ ( self , application , controller ) : <EOL> wx . Frame . __init__ ( self , parent = None , title = '<STR_LIT>' , <EOL> pos = application . settings [ '<STR_LIT>' ] , <EOL> size = application . settings [ '<STR_LIT>' ] ) <EOL> self . ensure_on_screen ( ) <EOL> if application . settings [ '<STR_LIT>' ] : <EOL> self . Maximize ( ) <EOL> self . _application = application <EOL> self . _controller = controller <EOL> self . _init_ui ( ) <EOL> self . _plugin_manager = PluginManager ( self . notebook ) <EOL> self . _review_dialog = None <EOL> self . _view_all_tags_dialog = None <EOL> self . Bind ( wx . EVT_CLOSE , self . OnClose ) <EOL> self . Bind ( wx . EVT_SIZE , self . OnSize ) <EOL> self . Bind ( wx . EVT_MOVE , self . OnMove ) <EOL> self . Bind ( wx . EVT_MAXIMIZE , self . OnMaximize ) <EOL> self . _subscribe_messages ( ) <EOL> self . Show ( ) <EOL> wx . CallLater ( <NUM_LIT:100> , self . actions . register_tools ) <EOL> def _subscribe_messages ( self ) : <EOL> for listener , topic in [ <EOL> ( lambda msg : self . SetStatusText ( '<STR_LIT>' % msg . path ) , RideSaved ) , <EOL> ( lambda msg : self . SetStatusText ( '<STR_LIT>' ) , RideSaveAll ) , <EOL> ( self . _set_label , RideTreeSelection ) , <EOL> ( self . _show_validation_error , RideInputValidationError ) , <EOL> ( self . _show_modification_prevented_error , RideModificationPrevented ) <EOL> ] : <EOL> PUBLISHER . subscribe ( listener , topic ) <EOL> def _set_label ( self , message ) : <EOL> self . SetTitle ( self . _create_title ( message ) ) <EOL> def _create_title ( self , message ) : <EOL> title = '<STR_LIT>' <EOL> if message : <EOL> item = message . item <EOL> title += '<STR_LIT>' + item . datafile . name <EOL> if not item . is_modifiable ( ) : <EOL> title += '<STR_LIT>' <EOL> return title <EOL> def _show_validation_error ( self , message ) : <EOL> wx . MessageBox ( message . message , '<STR_LIT>' , style = wx . ICON_ERROR ) <EOL> def _show_modification_prevented_error ( self , message ) : <EOL> wx . MessageBox ( '<STR_LIT>' % message . controller . datafile_controller . filename , <EOL> '<STR_LIT>' , <EOL> style = wx . ICON_ERROR ) <EOL> def _init_ui ( self ) : <EOL> splitter = wx . SplitterWindow ( self , style = wx . SP_LIVE_UPDATE ) <EOL> self . notebook = NoteBook ( splitter , self . _application ) <EOL> mb = MenuBar ( self ) <EOL> self . toolbar = ToolBar ( self ) <EOL> self . actions = ActionRegisterer ( mb , self . toolbar , <EOL> ShortcutRegistry ( self ) ) <EOL> self . tree = Tree ( splitter , self . actions , self . _application . settings ) <EOL> self . actions . register_actions ( <EOL> ActionInfoCollection ( _menudata , self , self . tree ) ) <EOL> mb . take_menu_bar_into_use ( ) <EOL> splitter . SetMinimumPaneSize ( <NUM_LIT:100> ) <EOL> splitter . SplitVertically ( self . tree , self . notebook , <NUM_LIT> ) <EOL> self . CreateStatusBar ( ) <EOL> self . SetIcons ( ImageProvider ( ) . PROGICONS ) <EOL> def get_selected_datafile ( self ) : <EOL> return self . tree . get_selected_datafile ( ) <EOL> def get_selected_datafile_controller ( self ) : <EOL> return self . tree . get_selected_datafile_controller ( ) <EOL> def OnClose ( self , event ) : <EOL> if self . _allowed_to_exit ( ) : <EOL> PUBLISHER . unsubscribe ( self . _set_label , RideTreeSelection ) <EOL> RideClosing ( ) . publish ( ) <EOL> self . Destroy ( ) <EOL> else : <EOL> wx . CloseEvent . Veto ( event ) <EOL> def OnSize ( self , event ) : <EOL> if not self . IsMaximized ( ) : <EOL> self . _application . settings [ '<STR_LIT>' ] = False <EOL> self . _application . settings [ '<STR_LIT>' ] = self . GetSizeTuple ( ) <EOL> event . Skip ( ) <EOL> def OnMove ( self , event ) : <EOL> if not self . IsIconized ( ) and not self . IsMaximized ( ) : <EOL> self . _application . settings [ '<STR_LIT>' ] = self . GetPositionTuple ( ) <EOL> event . Skip ( ) <EOL> def OnMaximize ( self , event ) : <EOL> self . _application . settings [ '<STR_LIT>' ] = True <EOL> event . Skip ( ) <EOL> def OnReleasenotes ( self , event ) : <EOL> pass <EOL> def _allowed_to_exit ( self ) : <EOL> if self . has_unsaved_changes ( ) : <EOL> ret = wx . MessageBox ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , wx . ICON_WARNING | wx . CANCEL | wx . YES_NO ) <EOL> if ret == wx . CANCEL : <EOL> return False <EOL> if ret == wx . YES : <EOL> self . save ( ) <EOL> return True <EOL> def has_unsaved_changes ( self ) : <EOL> return self . _controller . is_dirty ( ) <EOL> def OnNewProject ( self , event ) : <EOL> if not self . check_unsaved_modifications ( ) : <EOL> return <EOL> NewProjectDialog ( self . _controller ) . execute ( ) <EOL> self . _populate_tree ( ) <EOL> def _populate_tree ( self ) : <EOL> self . tree . populate ( self . _controller ) <EOL> def OnOpenTestSuite ( self , event ) : <EOL> if not self . check_unsaved_modifications ( ) : <EOL> return <EOL> path = RobotFilePathDialog ( <EOL> self , self . _controller , self . _application . settings ) . execute ( ) <EOL> if path : <EOL> self . open_suite ( path ) <EOL> def check_unsaved_modifications ( self ) : <EOL> if self . has_unsaved_changes ( ) : <EOL> ret = wx . MessageBox ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , wx . ICON_WARNING | wx . YES_NO ) <EOL> return ret == wx . YES <EOL> return True <EOL> def open_suite ( self , path ) : <EOL> self . _controller . update_default_dir ( path ) <EOL> self . _controller . load_datafile ( path , LoadProgressObserver ( self ) ) <EOL> self . _populate_tree ( ) <EOL> def refresh_datafile ( self , item , event ) : <EOL> self . tree . refresh_datafile ( item , event ) <EOL> def OnOpenDirectory ( self , event ) : <EOL> if self . check_unsaved_modifications ( ) : <EOL> path = wx . DirSelector ( message = '<STR_LIT>' , <EOL> defaultPath = self . _controller . default_dir ) <EOL> if path : <EOL> self . open_suite ( path ) <EOL> def OnSave ( self , event ) : <EOL> self . save ( ) <EOL> def OnSaveAll ( self , event ) : <EOL> self . save_all ( ) <EOL> def save_all ( self ) : <EOL> self . _show_dialog_for_files_without_format ( ) <EOL> self . _controller . execute ( SaveAll ( ) ) <EOL> def save ( self , controller = None ) : <EOL> if controller is None : <EOL> controller = self . get_selected_datafile_controller ( ) <EOL> if controller is not None : <EOL> if not controller . has_format ( ) : <EOL> self . _show_dialog_for_files_without_format ( controller ) <EOL> else : <EOL> controller . execute ( SaveFile ( ) ) <EOL> def _show_dialog_for_files_without_format ( self , controller = None ) : <EOL> files_without_format = self . _controller . get_files_without_format ( controller ) <EOL> for f in files_without_format : <EOL> self . _show_format_dialog_for ( f ) <EOL> def _show_format_dialog_for ( self , file_controller_without_format ) : <EOL> InitFileFormatDialog ( file_controller_without_format ) . execute ( ) <EOL> def OnExit ( self , event ) : <EOL> self . Close ( ) <EOL> def OnManagePlugins ( self , event ) : <EOL> self . _plugin_manager . show ( self . _application . get_plugins ( ) ) <EOL> def OnViewAllTags ( self , event ) : <EOL> if self . _view_all_tags_dialog is None : <EOL> self . _view_all_tags_dialog = ViewAllTagsDialog ( self . _controller , self ) <EOL> self . _view_all_tags_dialog . show_dialog ( ) <EOL> def OnSearchUnusedKeywords ( self , event ) : <EOL> if self . _review_dialog is None : <EOL> self . _review_dialog = ReviewDialog ( self . _controller , self ) <EOL> self . _review_dialog . show_dialog ( ) <EOL> def OnPreferences ( self , event ) : <EOL> dlg = PreferenceEditor ( self , "<STR_LIT>" , <EOL> self . _application . preferences , style = '<STR_LIT>' ) <EOL> dlg . ShowModal ( ) <EOL> dlg . Destroy ( ) <EOL> def OnAbout ( self , event ) : <EOL> dlg = AboutDialog ( ) <EOL> dlg . ShowModal ( ) <EOL> dlg . Destroy ( ) <EOL> def OnShortcutkeys ( self , event ) : <EOL> dialog = ShortcutKeysDialog ( ) <EOL> dialog . Show ( ) <EOL> def OnReportaProblem ( self , event ) : <EOL> wx . LaunchDefaultBrowser ( '<STR_LIT>' ) <EOL> def OnUserGuide ( self , event ) : <EOL> wx . LaunchDefaultBrowser ( '<STR_LIT>' ) <EOL> def _has_data ( self ) : <EOL> return self . _controller . data is not None <EOL> def _refresh ( self ) : <EOL> self . _controller . update_namespace ( ) <EOL> def ensure_on_screen ( self ) : <EOL> try : <EOL> display_id = wx . Display . GetFromWindow ( self ) <EOL> except NotImplementedError : <EOL> display_id = <NUM_LIT:0> <EOL> if display_id == - <NUM_LIT:1> : <EOL> display_id = <NUM_LIT:0> <EOL> geometry = wx . Display ( display_id ) . GetGeometry ( ) <EOL> position = self . GetPosition ( ) <EOL> if position . x < geometry . x : <EOL> position . x = geometry . x <EOL> if position . y < geometry . y : <EOL> position . y = geometry . y <EOL> size = self . GetSize ( ) <EOL> if size . width > geometry . width : <EOL> size . width = geometry . width <EOL> position . x = geometry . x <EOL> elif position . x + size . width > geometry . x + geometry . width : <EOL> position . x = geometry . x + geometry . width - size . width <EOL> if size . height > geometry . height : <EOL> size . height = geometry . height <EOL> position . y = geometry . y <EOL> elif position . y + size . height > geometry . y + geometry . height : <EOL> position . y = geometry . y + geometry . height - size . height <EOL> self . SetPosition ( position ) <EOL> self . SetSize ( size ) <EOL> class ActionRegisterer ( object ) : <EOL> def __init__ ( self , menubar , toolbar , shortcut_registry ) : <EOL> self . _menubar = menubar <EOL> self . _toolbar = toolbar <EOL> self . _shortcut_registry = shortcut_registry <EOL> self . _tools_items = { } <EOL> def register_action ( self , action_info ) : <EOL> menubar_can_be_registered = True <EOL> action = ActionFactory ( action_info ) <EOL> self . _shortcut_registry . register ( action ) <EOL> if hasattr ( action_info , "<STR_LIT>" ) : <EOL> if action_info . menu_name == "<STR_LIT>" : <EOL> self . _tools_items [ action_info . position ] = action <EOL> menubar_can_be_registered = False <EOL> if menubar_can_be_registered : <EOL> self . _menubar . register ( action ) <EOL> self . _toolbar . register ( action ) <EOL> return action <EOL> def register_tools ( self ) : <EOL> separator_action = ActionFactory ( SeparatorInfo ( "<STR_LIT>" ) ) <EOL> add_separator_after = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> for key in sorted ( self . _tools_items . iterkeys ( ) ) : <EOL> self . _menubar . register ( self . _tools_items [ key ] ) <EOL> if self . _tools_items [ key ] . name . lower ( ) in add_separator_after : <EOL> self . _menubar . register ( separator_action ) <EOL> def register_actions ( self , actions ) : <EOL> for action in actions : <EOL> self . register_action ( action ) <EOL> def register_shortcut ( self , action_info ) : <EOL> action = ActionFactory ( action_info ) <EOL> self . _shortcut_registry . register ( action ) <EOL> return action <EOL> class AboutDialog ( Dialog ) : <EOL> def __init__ ( self ) : <EOL> Dialog . __init__ ( self , title = '<STR_LIT>' ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> sizer . Add ( HtmlWindow ( self , ( <NUM_LIT> , <NUM_LIT:200> ) , ABOUT_RIDE ) , <NUM_LIT:1> , flag = wx . EXPAND ) <EOL> self . SetSizerAndFit ( sizer ) <EOL> def OnKey ( self , * args ) : <EOL> pass <EOL> class ShortcutKeysDialog ( Dialog ) : <EOL> def __init__ ( self ) : <EOL> Dialog . __init__ ( self , title = '<STR_LIT>' ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> sizer . Add ( HtmlWindow ( self , ( <NUM_LIT> , <NUM_LIT> ) , self . _get_platform_specific_shortcut_keys ( ) ) , <NUM_LIT:1> , flag = wx . EXPAND ) <EOL> self . SetSizerAndFit ( sizer ) <EOL> def OnKey ( self , * args ) : <EOL> pass <EOL> def _get_platform_specific_shortcut_keys ( self ) : <EOL> return localize_shortcuts ( SHORTCUT_KEYS ) </s>
