'Setup default layouts when run for the first time'

def setup_default_layouts(self, index, settings):

    self.set_window_settings(*settings)
    self.setUpdatesEnabled(False)
    (MATLAB, RSTUDIO, VERTICAL, HORIZONTAL) = range(4)
    editor = self.editor
    console_ipy = self.ipyconsole
    console_int = self.console
    outline = self.outlineexplorer
    explorer_project = self.projects
    explorer_file = self.explorer
    explorer_variable = self.variableexplorer
    history = self.historylog
    finder = self.findinfiles
    help_plugin = self.help
    helper = self.onlinehelp
    plugins = self.thirdparty_plugins
    global_hidden_widgets = ([finder, console_int, explorer_project, helper] + plugins)
    global_hidden_toolbars = [self.source_toolbar, self.edit_toolbar, self.search_toolbar]
    s_layout = {'widgets': [[[explorer_project]], [[editor]], [[outline]], [([help_plugin, explorer_variable, helper, explorer_file, finder] + plugins), [console_int, console_ipy, history]]], 'width    fraction': [0.0, 0.55, 0.0, 0.45], 'height    fraction': [[1.0], [1.0], [1.0], [0.46, 0.54]], 'hidden    widgets': [outline], 'hidden    toolbars': []}
    r_layout = {'widgets': [[[editor], [console_ipy, console_int]], [([explorer_variable, history, outline, finder] + plugins), [explorer_file, explorer_project, help_plugin, helper]]], 'width    fraction': [0.55, 0.45], 'height    fraction': [[0.55, 0.45], [0.55, 0.45]], 'hidden    widgets': [outline], 'hidden    toolbars': []}
    m_layout = {'widgets': [[[explorer_file, explorer_project], [outline]], [[editor], [console_ipy, console_int]], [([explorer_variable, finder] + plugins), [history, help_plugin, helper]]], 'width    fraction': [0.2, 0.4, 0.4], 'height    fraction': [[0.55, 0.45], [0.55, 0.45], [0.55, 0.45]], 'hidden    widgets': [], 'hidden    toolbars': []}
    v_layout = {'widgets': [[[editor], ([console_ipy, console_int, explorer_file, explorer_project, help_plugin, explorer_variable, history, outline, finder, helper] + plugins)]], 'width    fraction': [1.0], 'height    fraction': [[0.55, 0.45]], 'hidden    widgets': [outline], 'hidden    toolbars': []}
    h_layout = {'widgets': [[[editor]], [([console_ipy, console_int, explorer_file, explorer_project, help_plugin, explorer_variable, history, outline, finder, helper] + plugins)]], 'width    fraction': [0.55, 0.45], 'height    fraction': [[1.0], [1.0]], 'hidden    widgets': [outline], 'hidden    toolbars': []}
    layouts = {'default': s_layout, RSTUDIO: r_layout, MATLAB: m_layout, VERTICAL: v_layout, HORIZONTAL: h_layout}
    layout = layouts[index]
    widgets_layout = layout['widgets']
    widgets = []
    for column in widgets_layout:
        for row in column:
            for widget in row:
                if (widget is not None):
                    widgets.append(widget)
    for widget in widgets:
        widget.toggle_view(True)
        action = widget.toggle_view_action
        action.setChecked(widget.dockwidget.isVisible())
    for i in range((len(widgets) - 1)):
        (first, second) = (widgets[i], widgets[(i + 1)])
        if ((first is not None) and (second is not None)):
            self.splitDockWidget(first.dockwidget, second.dockwidget, Qt.Horizontal)
    for column in widgets_layout:
        for i in range((len(column) - 1)):
            (first_row, second_row) = (column[i], column[(i + 1)])
            if ((first_row is not None) and (second_row is not None)):
                self.splitDockWidget(first_row[0].dockwidget, second_row[0].dockwidget, Qt.Vertical)
    for column in widgets_layout:
        for row in column:
            for i in range((len(row) - 1)):
                (first, second) = (row[i], row[(i + 1)])
                if ((first is not None) and (second is not None)):
                    self.tabify_plugins(first, second)
            row[0].dockwidget.show()
            row[0].dockwidget.raise_()
    hidden_toolbars = (global_hidden_toolbars + layout['hidden    toolbars'])
    for toolbar in hidden_toolbars:
        if (toolbar is not None):
            toolbar.close()
    hidden_widgets = (global_hidden_widgets + layout['hidden    widgets'])
    for widget in hidden_widgets:
        if (widget is not None):
            widget.dockwidget.close()
    self._layout_widget_info = []
    (width, height) = (self.window_size.width(), self.window_size.height())
    for (c, column) in enumerate(widgets_layout):
        for r in range((len(column) - 1)):
            widget = column[r][0]
            dockwidget = widget.dockwidget
            dock_min_h = dockwidget.minimumHeight()
            dock_max_h = dockwidget.maximumHeight()
            info = {'widget': widget, 'dock    min    height': dock_min_h, 'dock    max    height': dock_max_h}
            self._layout_widget_info.append(info)
            new_height = int(((layout['height    fraction'][c][r] * height) * 0.95))
            dockwidget.setMinimumHeight(new_height)
            dockwidget.setMaximumHeight(new_height)
    self._custom_layout_timer = QTimer(self)
    self._custom_layout_timer.timeout.connect(self.layout_fix_timer)
    self._custom_layout_timer.setSingleShot(True)
    self._custom_layout_timer.start(5000)
