'Setup main window'

def setup(self):

    self.debug_print('***    Start    of    MainWindow    setup    ***')
    self.debug_print('        ..core    actions')
    self.close_dockwidget_action = create_action(self, icon=ima.icon('DialogCloseButton'), text=_('Close    current    pane'), triggered=self.close_current_dockwidget, context=Qt.ApplicationShortcut)
    self.register_shortcut(self.close_dockwidget_action, '_', 'Close    pane')
    self.lock_dockwidgets_action = create_action(self, _('Lock    panes'), toggled=self.toggle_lock_dockwidgets, context=Qt.ApplicationShortcut)
    self.register_shortcut(self.lock_dockwidgets_action, '_', 'Lock    unlock    panes')
    self.toggle_next_layout_action = create_action(self, _('Use    next    layout'), triggered=self.toggle_next_layout, context=Qt.ApplicationShortcut)
    self.toggle_previous_layout_action = create_action(self, _('Use    previous    layout'), triggered=self.toggle_previous_layout, context=Qt.ApplicationShortcut)
    self.register_shortcut(self.toggle_next_layout_action, '_', 'Use    next    layout')
    self.register_shortcut(self.toggle_previous_layout_action, '_', 'Use    previous    layout')
    self.file_switcher_action = create_action(self, _('File    switcher...'), icon=ima.icon('filelist'), tip=_('Fast    switch    between    files'), triggered=self.open_fileswitcher, context=Qt.ApplicationShortcut)
    self.register_shortcut(self.file_switcher_action, context='_', name='File    switcher')
    self.symbol_finder_action = create_action(self, _('Symbol    finder...'), icon=ima.icon('symbol_find'), tip=_('Fast    symbol    search    in    file'), triggered=self.open_symbolfinder, context=Qt.ApplicationShortcut)
    self.register_shortcut(self.symbol_finder_action, context='_', name='symbol    finder', add_sc_to_tip=True)
    self.file_toolbar_actions = [self.file_switcher_action, self.symbol_finder_action]
    def create_edit_action(text, tr_text, icon):
        textseq = text.split('    ')
        method_name = (textseq[0].lower() + ''.join(textseq[1:]))
        action = create_action(self, tr_text, icon=icon, triggered=self.global_callback, data=method_name, context=Qt.WidgetShortcut)
        self.register_shortcut(action, 'Editor', text)
        return action
    self.undo_action = create_edit_action('Undo', _('Undo'), ima.icon('undo'))
    self.redo_action = create_edit_action('Redo', _('Redo'), ima.icon('redo'))
    self.copy_action = create_edit_action('Copy', _('Copy'), ima.icon('editcopy'))
    self.cut_action = create_edit_action('Cut', _('Cut'), ima.icon('editcut'))
    self.paste_action = create_edit_action('Paste', _('Paste'), ima.icon('editpaste'))
    self.selectall_action = create_edit_action('Select    All', _('Select    All'), ima.icon('selectall'))
    self.edit_menu_actions = [self.undo_action, self.redo_action, None, self.cut_action, self.copy_action, self.paste_action, self.selectall_action]
    namespace = None
    self.debug_print('        ..toolbars')
    self.file_menu = self.menuBar().addMenu(_('&File'))
    self.file_toolbar = self.create_toolbar(_('File    toolbar'), 'file_toolbar')
    self.edit_menu = self.menuBar().addMenu(_('&Edit'))
    self.edit_toolbar = self.create_toolbar(_('Edit    toolbar'), 'edit_toolbar')
    self.search_menu = self.menuBar().addMenu(_('&Search'))
    self.search_toolbar = self.create_toolbar(_('Search    toolbar'), 'search_toolbar')
    self.source_menu = self.menuBar().addMenu(_('Sour&ce'))
    self.source_toolbar = self.create_toolbar(_('Source    toolbar'), 'source_toolbar')
    self.run_menu = self.menuBar().addMenu(_('&Run'))
    self.run_toolbar = self.create_toolbar(_('Run    toolbar'), 'run_toolbar')
    self.debug_menu = self.menuBar().addMenu(_('&Debug'))
    self.debug_toolbar = self.create_toolbar(_('Debug    toolbar'), 'debug_toolbar')
    self.consoles_menu = self.menuBar().addMenu(_('C&onsoles'))
    self.projects_menu = self.menuBar().addMenu(_('&Projects'))
    self.tools_menu = self.menuBar().addMenu(_('&Tools'))
    self.view_menu = self.menuBar().addMenu(_('&View'))
    self.help_menu = self.menuBar().addMenu(_('&Help'))
    status = self.statusBar()
    status.setObjectName('StatusBar')
    status.showMessage(_('Welcome    to    Spyder!'), 5000)
    self.debug_print('        ..tools')
    prefs_action = create_action(self, _('Pre&ferences'), icon=ima.icon('configure'), triggered=self.edit_preferences, context=Qt.ApplicationShortcut)
    self.register_shortcut(prefs_action, '_', 'Preferences', add_sc_to_tip=True)
    spyder_path_action = create_action(self, _('PYTHONPATH    manager'), None, icon=ima.icon('pythonpath'), triggered=self.path_manager_callback, tip=_('Python    Path    Manager'), menurole=QAction.ApplicationSpecificRole)
    update_modules_action = create_action(self, _('Update    module    names    list'), triggered=(lambda : module_completion.reset()), tip=_('Refresh    list    of    module    names    available    in    PYTHONPATH'))
    reset_spyder_action = create_action(self, _('Reset    Spyder    to    factory    defaults'), triggered=self.reset_spyder)
    self.tools_menu_actions = [prefs_action, spyder_path_action]
    if (WinUserEnvDialog is not None):
        winenv_action = create_action(self, _('Current    user    environment    variables...'), icon='win_env.png', tip=_('Show    and    edit    current    user    environment    variables    in    Windows    registry    (i.e.    for    all    sessions)'), triggered=self.win_env)
        self.tools_menu_actions.append(winenv_action)
    self.tools_menu_actions += [reset_spyder_action, MENU_SEPARATOR, update_modules_action]
    self.external_tools_menu = QMenu(_('External    Tools'))
    self.external_tools_menu_actions = []
    self.wp_action = create_action(self, _('WinPython    control    panel'), icon=get_icon('winpython.svg'), triggered=(lambda : programs.run_python_script('winpython', 'controlpanel')))
    if ((os.name == 'nt') and is_module_installed('winpython')):
        self.external_tools_menu_actions.append(self.wp_action)
    additact = []
    for name in ('designer-qt4', 'designer'):
        qtdact = create_program_action(self, _('Qt    Designer'), name, 'qtdesigner.png')
        if qtdact:
            break
    for name in ('linguist-qt4', 'linguist'):
        qtlact = create_program_action(self, _('Qt    Linguist'), 'linguist', 'qtlinguist.png')
        if qtlact:
            break
    args = (['-no-opengl'] if (os.name == 'nt') else [])
    qteact = create_python_script_action(self, _('Qt    examples'), 'qt.png', 'PyQt4', osp.join('examples', 'demos', 'qtdemo', 'qtdemo'), args)
    for act in (qtdact, qtlact, qteact):
        if act:
            additact.append(act)
    if (additact and is_module_installed('winpython')):
        self.external_tools_menu_actions += ([None] + additact)
    self.debug_print('        ..sift?')
    gdgq_act = []
    try:
        from guidata import configtools
        from guidata import config
        guidata_icon = configtools.get_icon('guidata.svg')
        guidata_act = create_python_script_action(self, _('guidata    examples'), guidata_icon, 'guidata', osp.join('tests', '__init__'))
        gdgq_act += [guidata_act]
    except (ImportError, AssertionError):
        pass
    try:
        from guidata import configtools
        from guiqwt import config
        guiqwt_icon = configtools.get_icon('guiqwt.svg')
        guiqwt_act = create_python_script_action(self, _('guiqwt    examples'), guiqwt_icon, 'guiqwt', osp.join('tests', '__init__'))
        if guiqwt_act:
            gdgq_act += [guiqwt_act]
        sift_icon = configtools.get_icon('sift.svg')
        sift_act = create_python_script_action(self, _('Sift'), sift_icon, 'guiqwt', osp.join('tests', 'sift'))
        if sift_act:
            gdgq_act += [sift_act]
    except (ImportError, AssertionError):
        pass
    if gdgq_act:
        self.external_tools_menu_actions += ([None] + gdgq_act)
    vitables_act = create_program_action(self, _('ViTables'), 'vitables', 'vitables.png')
    if vitables_act:
        self.external_tools_menu_actions += [None, vitables_act]
    self.maximize_action = create_action(self, '', triggered=self.maximize_dockwidget, context=Qt.ApplicationShortcut)
    self.register_shortcut(self.maximize_action, '_', 'Maximize    pane')
    self.__update_maximize_action()
    self.fullscreen_action = create_action(self, _('Fullscreen    mode'), triggered=self.toggle_fullscreen, context=Qt.ApplicationShortcut)
    self.register_shortcut(self.fullscreen_action, '_', 'Fullscreen    mode', add_sc_to_tip=True)
    self.main_toolbar_actions = [self.maximize_action, self.fullscreen_action, None, prefs_action, spyder_path_action]
    self.main_toolbar = self.create_toolbar(_('Main    toolbar'), 'main_toolbar')
    self.debug_print('        ..plugin:    internal    console')
    from spyder.plugins.console import Console
    self.console = Console(self, namespace, exitfunc=self.closing, profile=self.profile, multithreaded=self.multithreaded, message=_("Spyder    Internal    Console\n\nThis    console    is    used    to    report    application\ninternal    errors    and    to    inspect    Spyder\ninternals    with    the    following    commands:\n        spy.app,    spy.window,    dir(spy)\n\nPlease    don't    use    it    to    run    your    code\n\n"))
    self.console.register_plugin()
    self.debug_print('        ..plugin:    working    directory')
    from spyder.plugins.workingdirectory import WorkingDirectory
    self.workingdirectory = WorkingDirectory(self, self.init_workdir, main=self)
    self.workingdirectory.register_plugin()
    self.toolbarslist.append(self.workingdirectory.toolbar)
    if CONF.get('help', 'enable'):
        self.set_splash(_('Loading    help...'))
        from spyder.plugins.help import Help
        self.help = Help(self)
        self.help.register_plugin()
    if CONF.get('outline_explorer', 'enable'):
        self.set_splash(_('Loading    outline    explorer...'))
        from spyder.plugins.outlineexplorer import OutlineExplorer
        fullpath_sorting = CONF.get('editor', 'fullpath_sorting', True)
        self.outlineexplorer = OutlineExplorer(self, fullpath_sorting=fullpath_sorting)
        self.outlineexplorer.register_plugin()
    self.set_splash(_('Loading    editor...'))
    from spyder.plugins.editor import Editor
    self.editor = Editor(self)
    self.editor.register_plugin()
    quit_action = create_action(self, _('&Quit'), icon=ima.icon('exit'), tip=_('Quit'), triggered=self.console.quit, context=Qt.ApplicationShortcut)
    self.register_shortcut(quit_action, '_', 'Quit')
    restart_action = create_action(self, _('&Restart'), icon=ima.icon('restart'), tip=_('Restart'), triggered=self.restart, context=Qt.ApplicationShortcut)
    self.register_shortcut(restart_action, '_', 'Restart')
    self.file_menu_actions += [self.file_switcher_action, self.symbol_finder_action, None, restart_action, quit_action]
    self.set_splash('')
    self.debug_print('        ..widgets')
    self.set_splash(_('Loading    namespace    browser...'))
    from spyder.plugins.variableexplorer import VariableExplorer
    self.variableexplorer = VariableExplorer(self)
    self.variableexplorer.register_plugin()
    if CONF.get('historylog', 'enable'):
        self.set_splash(_('Loading    history    plugin...'))
        from spyder.plugins.history import HistoryLog
        self.historylog = HistoryLog(self)
        self.historylog.register_plugin()
    self.set_splash(_('Loading    IPython    console...'))
    from spyder.plugins.ipythonconsole import IPythonConsole
    self.ipyconsole = IPythonConsole(self)
    self.ipyconsole.register_plugin()
    if CONF.get('explorer', 'enable'):
        self.set_splash(_('Loading    file    explorer...'))
        from spyder.plugins.explorer import Explorer
        self.explorer = Explorer(self)
        self.explorer.register_plugin()
    try:
        from spyder.plugins.onlinehelp import OnlineHelp
    except ImportError:
        OnlineHelp = None
    if (CONF.get('onlinehelp', 'enable') and (OnlineHelp is not None)):
        self.set_splash(_('Loading    online    help...'))
        self.onlinehelp = OnlineHelp(self)
        self.onlinehelp.register_plugin()
    self.set_splash(_('Loading    project    explorer...'))
    from spyder.plugins.projects import Projects
    self.projects = Projects(self)
    self.projects.register_plugin()
    self.project_path = self.projects.get_pythonpath(at_start=True)
    if CONF.get('find_in_files', 'enable'):
        from spyder.plugins.findinfiles import FindInFiles
        self.findinfiles = FindInFiles(self)
        self.findinfiles.register_plugin()
    self.set_splash(_('Loading    third-party    plugins...'))
    for mod in get_spyderplugins_mods():
        try:
            plugin = mod.PLUGIN_CLASS(self)
            if plugin.check_compatibility()[0]:
                self.thirdparty_plugins.append(plugin)
                plugin.register_plugin()
        except Exception as error:
            print(('%s:    %s' % (mod, str(error))), file=STDERR)
            traceback.print_exc(file=STDERR)
    self.set_splash(_('Setting    up    main    window...'))
    dep_action = create_action(self, _('Dependencies...'), triggered=self.show_dependencies, icon=ima.icon('advanced'))
    report_action = create_action(self, _('Report    issue...'), icon=ima.icon('bug'), triggered=self.report_issue)
    support_action = create_action(self, _('Spyder    support...'), triggered=self.google_group)
    self.check_updates_action = create_action(self, _('Check    for    updates...'), triggered=self.check_updates)
    doc_path = get_module_data_path('spyder', relpath='doc', attr_name='DOCPATH')
    spyder_doc = osp.join(doc_path, 'Spyderdoc.chm')
    if (not osp.isfile(spyder_doc)):
        spyder_doc = osp.join(doc_path, os.pardir, 'Spyderdoc.chm')
    if (not osp.isfile(spyder_doc)):
        spyder_doc = osp.join(doc_path, 'index.html')
    if (not osp.isfile(spyder_doc)):
        spyder_doc = osp.join(get_module_source_path('spyder'), os.pardir, 'build', 'lib', 'spyder', 'doc', 'index.html')
    if (not osp.isfile(spyder_doc)):
        spyder_doc = 'http://pythonhosted.org/spyder'
    else:
        spyder_doc = file_uri(spyder_doc)
    doc_action = create_action(self, _('Spyder    documentation'), icon=ima.icon('DialogHelpButton'), triggered=(lambda : programs.start_file(spyder_doc)))
    self.register_shortcut(doc_action, '_', 'spyder    documentation')
    if (self.help is not None):
        tut_action = create_action(self, _('Spyder    tutorial'), triggered=self.help.show_tutorial)
    else:
        tut_action = None
    shortcuts_action = create_action(self, _('Shortcuts    Summary'), shortcut='Meta+F1', triggered=self.show_shortcuts_dialog)
    self.tour = tour.AnimatedTour(self)
    self.tours_menu = QMenu(_('Interactive    tours'))
    self.tour_menu_actions = []
    self.tours_available = tour.get_tours(0)
    for (i, tour_available) in enumerate(self.tours_available):
        self.tours_available[i]['last'] = 0
        tour_name = tour_available['name']
        def trigger(i=i, self=self):
            return (lambda : self.show_tour(i))
        temp_action = create_action(self, tour_name, tip='', triggered=trigger())
        self.tour_menu_actions += [temp_action]
    self.tours_menu.addActions(self.tour_menu_actions)
    self.help_menu_actions = [doc_action, tut_action, shortcuts_action, self.tours_menu, MENU_SEPARATOR, report_action, dep_action, self.check_updates_action, support_action, MENU_SEPARATOR]
    if (get_python_doc_path() is not None):
        pydoc_act = create_action(self, _('Python    documentation'), triggered=(lambda : programs.start_file(get_python_doc_path())))
        self.help_menu_actions.append(pydoc_act)
    if (self.help is not None):
        ipython_menu = QMenu(_('IPython    documentation'), self)
        intro_action = create_action(self, _('Intro    to    IPython'), triggered=self.ipyconsole.show_intro)
        quickref_action = create_action(self, _('Quick    reference'), triggered=self.ipyconsole.show_quickref)
        guiref_action = create_action(self, _('Console    help'), triggered=self.ipyconsole.show_guiref)
        add_actions(ipython_menu, (intro_action, guiref_action, quickref_action))
        self.help_menu_actions.append(ipython_menu)
    ipm_actions = []
    def add_ipm_action(text, path):
        'Add    installed    Python    module    doc    action    to    help    submenu'
        path = file_uri(path)
        if (not (API == 'pyside')):
            slot = (lambda _checked, path=path: programs.start_file(path))
        else:
            slot = (lambda path=path: programs.start_file(path))
        action = create_action(self, text, icon=('%s.png' % osp.splitext(path)[1][1:]), triggered=slot)
        ipm_actions.append(action)
    sysdocpth = osp.join(sys.prefix, 'Doc')
    if osp.isdir(sysdocpth):
        for docfn in os.listdir(sysdocpth):
            pt = '([a-zA-Z\\_]*)(doc)?(-dev)?(-ref)?(-user)?.(chm|pdf)'
            match = re.match(pt, docfn)
            if (match is not None):
                pname = match.groups()[0]
                if (pname not in ('Python',)):
                    add_ipm_action(pname, osp.join(sysdocpth, docfn))
    if ipm_actions:
        pymods_menu = QMenu(_('Installed    Python    modules'), self)
        add_actions(pymods_menu, ipm_actions)
        self.help_menu_actions.append(pymods_menu)
    web_resources = QMenu(_('Online    documentation'))
    webres_actions = create_module_bookmark_actions(self, self.BOOKMARKS)
    webres_actions.insert(2, None)
    webres_actions.insert(5, None)
    add_actions(web_resources, webres_actions)
    self.help_menu_actions.append(web_resources)
    if (sys.platform.startswith('linux') and (not PYQT5)):
        qta_exe = 'assistant-qt4'
    else:
        qta_exe = 'assistant'
    qta_act = create_program_action(self, _('Qt    documentation'), qta_exe)
    if qta_act:
        self.help_menu_actions += [qta_act, None]
    about_action = create_action(self, (_('About    %s...') % 'Spyder'), icon=ima.icon('MessageBoxInformation'), triggered=self.about)
    self.help_menu_actions += [MENU_SEPARATOR, about_action]
    from spyder.widgets.status import MemoryStatus, CPUStatus
    self.mem_status = MemoryStatus(self, status)
    self.cpu_status = CPUStatus(self, status)
    self.apply_statusbar_settings()
    self.plugins_menu = QMenu(_('Panes'), self)
    self.toolbars_menu = QMenu(_('Toolbars'), self)
    self.quick_layout_menu = QMenu(_('Window    layouts'), self)
    self.quick_layout_set_menu()
    self.view_menu.addMenu(self.plugins_menu)
    add_actions(self.view_menu, (self.lock_dockwidgets_action, self.close_dockwidget_action, self.maximize_action, MENU_SEPARATOR))
    self.show_toolbars_action = create_action(self, _('Show    toolbars'), triggered=self.show_toolbars, context=Qt.ApplicationShortcut)
    self.register_shortcut(self.show_toolbars_action, '_', 'Show    toolbars')
    self.view_menu.addMenu(self.toolbars_menu)
    self.view_menu.addAction(self.show_toolbars_action)
    add_actions(self.view_menu, (MENU_SEPARATOR, self.quick_layout_menu, self.toggle_previous_layout_action, self.toggle_next_layout_action, MENU_SEPARATOR, self.fullscreen_action))
    if (set_attached_console_visible is not None):
        cmd_act = create_action(self, _('Attached    console    window    (debugging)'), toggled=set_attached_console_visible)
        cmd_act.setChecked(is_attached_console_visible())
        add_actions(self.view_menu, (MENU_SEPARATOR, cmd_act))
    if self.external_tools_menu_actions:
        external_tools_act = create_action(self, _('External    Tools'))
        external_tools_act.setMenu(self.external_tools_menu)
        self.tools_menu_actions += [None, external_tools_act]
    add_actions(self.file_menu, self.file_menu_actions)
    add_actions(self.edit_menu, self.edit_menu_actions)
    add_actions(self.search_menu, self.search_menu_actions)
    add_actions(self.source_menu, self.source_menu_actions)
    add_actions(self.run_menu, self.run_menu_actions)
    add_actions(self.debug_menu, self.debug_menu_actions)
    add_actions(self.consoles_menu, self.consoles_menu_actions)
    add_actions(self.projects_menu, self.projects_menu_actions)
    add_actions(self.tools_menu, self.tools_menu_actions)
    add_actions(self.external_tools_menu, self.external_tools_menu_actions)
    add_actions(self.help_menu, self.help_menu_actions)
    add_actions(self.main_toolbar, self.main_toolbar_actions)
    add_actions(self.file_toolbar, self.file_toolbar_actions)
    add_actions(self.edit_toolbar, self.edit_toolbar_actions)
    add_actions(self.search_toolbar, self.search_toolbar_actions)
    add_actions(self.source_toolbar, self.source_toolbar_actions)
    add_actions(self.debug_toolbar, self.debug_toolbar_actions)
    add_actions(self.run_toolbar, self.run_toolbar_actions)
    self.apply_shortcuts()
    self.all_actions_defined.emit()
    self.debug_print('Setting    up    window...')
    self.setup_layout(default=False)
    if (sys.platform == 'darwin'):
        for name in ['file', 'edit', 'search', 'source', 'run', 'debug', 'projects', 'tools', 'plugins']:
            menu_object = getattr(self, (name + '_menu'))
            menu_object.aboutToShow.connect((lambda name=name: self.show_shortcuts(name)))
            menu_object.aboutToHide.connect((lambda name=name: self.hide_shortcuts(name)))
    if (self.splash is not None):
        self.splash.hide()
    if CONF.get('main', 'tear_off_menus'):
        for child in self.menuBar().children():
            if (isinstance(child, QMenu) and (child != self.help_menu)):
                child.setTearOffEnabled(True)
    for child in self.menuBar().children():
        if isinstance(child, QMenu):
            try:
                child.aboutToShow.connect(self.update_edit_menu)
            except TypeError:
                pass
    self.debug_print('***    End    of    MainWindow    setup    ***')
    self.is_starting_up = False
