<s> import os <EOL> import wx <EOL> from contextlib import contextmanager <EOL> from robotide . namespace import Namespace <EOL> from robotide . controller import Project <EOL> from robotide . spec import librarydatabase <EOL> from robotide . ui import LoadProgressObserver <EOL> from robotide . ui . mainframe import RideFrame <EOL> from robotide import publish <EOL> from robotide import context , contrib <EOL> from robotide . context import coreplugins <EOL> from robotide . preferences import Preferences , RideSettings <EOL> from robotide . application . pluginloader import PluginLoader <EOL> from robotide . application . editorprovider import EditorProvider <EOL> from robotide . application . releasenotes import ReleaseNotes <EOL> from robotide . application . updatenotifier import UpdateNotifierController , UpdateDialog <EOL> from robotide import utils <EOL> class RIDE ( wx . App ) : <EOL> def __init__ ( self , path = None , updatecheck = True ) : <EOL> self . _initial_path = path <EOL> self . _updatecheck = updatecheck <EOL> context . APP = self <EOL> wx . App . __init__ ( self , redirect = False ) <EOL> def OnInit ( self ) : <EOL> wx . HelpProvider_Set ( wx . SimpleHelpProvider ( ) ) <EOL> self . settings = RideSettings ( ) <EOL> librarydatabase . initialize_database ( ) <EOL> self . preferences = Preferences ( self . settings ) <EOL> self . namespace = Namespace ( self . settings ) <EOL> self . _controller = Project ( self . namespace , self . settings ) <EOL> self . frame = RideFrame ( self , self . _controller ) <EOL> self . _editor_provider = EditorProvider ( ) <EOL> self . _plugin_loader = PluginLoader ( self , self . _get_plugin_dirs ( ) , <EOL> coreplugins . get_core_plugins ( ) ) <EOL> self . _plugin_loader . enable_plugins ( ) <EOL> self . editor = self . _get_editor ( ) <EOL> self . _load_data ( ) <EOL> self . frame . tree . populate ( self . model ) <EOL> self . frame . tree . set_editor ( self . editor ) <EOL> self . _find_robot_installation ( ) <EOL> self . _publish_system_info ( ) <EOL> if self . _updatecheck : <EOL> UpdateNotifierController ( <EOL> self . settings ) . notify_update_if_needed ( UpdateDialog ) <EOL> wx . CallLater ( <NUM_LIT:200> , ReleaseNotes ( self ) . bring_to_front ) <EOL> return True <EOL> def _publish_system_info ( self ) : <EOL> publish . RideLogMessage ( context . SYSTEM_INFO ) . publish ( ) <EOL> @ property <EOL> def model ( self ) : <EOL> return self . _controller <EOL> def _get_plugin_dirs ( self ) : <EOL> return [ self . settings . get_path ( '<STR_LIT>' ) , <EOL> os . path . join ( self . settings [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> contrib . CONTRIB_PATH ] <EOL> def _get_editor ( self ) : <EOL> from robotide . editor import EditorPlugin <EOL> for pl in self . _plugin_loader . plugins : <EOL> maybe_editor = pl . _plugin <EOL> if isinstance ( maybe_editor , EditorPlugin ) : <EOL> maybe_editor . show ( ) <EOL> return maybe_editor <EOL> def _load_data ( self ) : <EOL> path = self . _initial_path or self . _get_latest_path ( ) <EOL> if path : <EOL> with self . active_event_loop ( ) : <EOL> observer = LoadProgressObserver ( self . frame ) <EOL> self . _controller . load_data ( path , observer ) <EOL> def _find_robot_installation ( self ) : <EOL> output = utils . run_python_command ( <EOL> [ '<STR_LIT>' ] ) <EOL> robot_found = '<STR_LIT>' not in output <EOL> if robot_found : <EOL> rf_file , rf_version = output . strip ( ) . split ( '<STR_LIT:U+002CU+0020>' ) <EOL> publish . RideLogMessage ( <EOL> "<STR_LIT>" . format ( <EOL> rf_version , os . path . dirname ( rf_file ) ) ) . publish ( ) <EOL> return rf_version <EOL> else : <EOL> publish . RideLogMessage ( <EOL> publish . get_html_message ( '<STR_LIT>' ) , notify_user = True <EOL> ) . publish ( ) <EOL> def _get_latest_path ( self ) : <EOL> recent = self . _get_recentfiles_plugin ( ) <EOL> if not recent or not recent . recent_files : <EOL> return None <EOL> return recent . recent_files [ <NUM_LIT:0> ] <EOL> def _get_recentfiles_plugin ( self ) : <EOL> from robotide . recentfiles import RecentFilesPlugin <EOL> for pl in self . get_plugins ( ) : <EOL> if isinstance ( pl . _plugin , RecentFilesPlugin ) : <EOL> return pl . _plugin <EOL> def get_plugins ( self ) : <EOL> return self . _plugin_loader . plugins <EOL> def register_preference_panel ( self , panel_class ) : <EOL> '''<STR_LIT>''' <EOL> self . preferences . add ( panel_class ) <EOL> def unregister_preference_panel ( self , panel_class ) : <EOL> '''<STR_LIT>''' <EOL> self . preferences . remove ( panel_class ) <EOL> def register_editor ( self , object_class , editor_class , activate ) : <EOL> self . _editor_provider . register_editor ( object_class , editor_class , <EOL> activate ) <EOL> def unregister_editor ( self , object_class , editor_class ) : <EOL> self . _editor_provider . unregister_editor ( object_class , editor_class ) <EOL> def activate_editor ( self , object_class , editor_class ) : <EOL> self . _editor_provider . set_active_editor ( object_class , editor_class ) <EOL> def get_editors ( self , object_class ) : <EOL> return self . _editor_provider . get_editors ( object_class ) <EOL> def get_editor ( self , object_class ) : <EOL> return self . _editor_provider . get_editor ( object_class ) <EOL> @ contextmanager <EOL> def active_event_loop ( self ) : <EOL> loop = wx . EventLoop ( ) <EOL> wx . EventLoop . SetActive ( loop ) <EOL> yield <EOL> del loop </s>
