// komodo tool: Django Setup
// =========================
// is_clean: true
// type: tutorial
// version: 1.1.5
// =========================
# Sample content, edit, delete, do whatever you like
Description: Tutorial to quickly set up a Django project in Komodo.
Author: ActiveState
Version: 1.0
# Placement can be floating or docked
Placement: docked
Callouts:
    placesWidget:
        Element: "#placesViewbox"
        Message: This is the Places widget.
    projectCog:
        Element: "#placesSubpanelProjectsTools_SPV"
        Message: "This is the Project cog menu."
    menuButton:
        Element: "#unifiedMenuButton"
        Message: "This is the Menu button."
        Fail: "Enable the main toolbar using View > Toolbars > Show Toolbars"
    uniMenuButton:
        Element: "#unifiedMenuButton"
        Message: Access Komodo menus in the Unified Menu.
    toolboxWidget:
        Element: "#toolbox2viewbox"
        Message: "This is the Toolbox widget."
        Fail: "Open Toolbox using View > Tabs & Sidebars > Toolbox or Ctrl + Shift + L"
    gotoAnything:
        Element: "#notification-widget"
        Message: This is the Go to Anything tool.
        Fail: "Enable the Notification Box via View > Toolbars > Customize .."
Steps:
    -
        Title: Before you begin
        Summary: >
            If you are new to the **Komodo IDE** you should complete the
            **Getting Started** tutorial before continuing.  It is located
            in the [toolbox][callout:toolboxWidget] in the Tutorials folder.
            It teaches the basics of using Komodo.

            This tutorial is based on the information in the Django documentation, with specific instructions for configuring Komodo.
            For more information about using Django, see the [Django documentation](https://docs.djangoproject.com/en/1.10/intro).

            ## Prerequisites

            You must have the following items installed, and they must be on your system PATH:
             - Python 2.7, or 3.5+ if you're using Django 2.0
             - The `virtualenv` version that corresponds to the Python version you are using

            **NOTE** You need to run `pip` commands in this tutorial.
            When you are asked to enter `pip`, ensure that you use
            the correct command for your Python version.
            You must use `pip` for Python 2 or `pip3` for Python 3
            when you enter commands in **[Go to Anything][callout:gotoAnything]** (also known as **Commando**).

            ### Configuring Python

            We recommend that you use ActiveState's ActivePython distribution to complete this tutorial.
            It includes additional packages and tools that simplify the setup. However, this tutorial
            should work for most, if not all, Python distributions. You need to download and install Python
            if it's not already installed:

             * [Download ActivePython from ActiveState](http://downloads.activestate.com/ActivePython/releases/)
             * [Download Python from Python.org](https://www.python.org/downloads/)

            #### Configuring Komodo

             1. Open the Preferences dialog box:
                - Select <% if (require("sdk/system").platform == "darwin") { %>**Edit menu > <% } else { %> <i class="icon icon-bars"></i>&nbsp;**[Menu button][callout:uniMenuButton] > Edit <% } %>  Preferences > Languages**.
                - Press `Ctrl + ,` (or `Cmd + ,` on Mac OS X)
             1. Expand the **Languages** list in the sidebar, and select Python or Python3.
             1. Click the **Browse** button next to the **Use this interpreter** field,
             select your Python installation directory, and select the Python interpreter binary file.
             1. Click the **Browse** button next to the **Pip Location** field
             and select the Pip binary file installed in the **Scripts**
             folder for your Python installation.

            ### Configuring virtualenv

            1. Press `Ctrl + Shift + O` (or `Cmd + Shift + O` on Mac OS X)
            to open Go to Anything.
            1. Press 8 to select the Shell scope.
            1. Enter **pip > install > virtualenv**.

            **NOTE** **Go to Anything** will autocomplete commands for you.


        #Validate: validPageOne -> isPythonFound && isVirtualenvFound

    -
        Title: Creating a Komodo project
        Summary: >
            Your first task is to create a Komodo project that provides the context for the
            setup commands in this tutorial. All of these steps are completed in Komodo.
        Task: >
            1. Select <% if (require("sdk/system").platform == "darwin") { %>
            **Project menu >
            <% } else { %>
            <i class="icon icon-bars"></i>&nbsp;**[Menu button][callout:uniMenuButton] > Project >
            <% } %>
            New Project**.
            1. Use the dialog box to navigate to your project folder and name the project file,
            and then click *Save*.
            1. Before continuing with the tutorial, you need to verify that
            Python is configured properly in Komodo. Create a new Python
            file in your project to check the version:
                1. Select <% if (require("sdk/system").platform == "darwin") { %> **File** >
                <% } else { %><i class="icon icon-bars"></i>&nbsp;**[Menu button][callout:uniMenuButton]** ><% } %> **New** > **File From Template**.
                1. Select the correct Python template to use for your version.
                1. Enter `test.py` in the filename text box and click **Open**.
                1. Enter the following code in the file:
                ```
                import platform
                print(platform.python_version())
                ```
                1. Press `Ctrl (Cmd) > B` to run the content.  The output should look similar to the following:
                ```
                Python 3.4.3
                ```

            Leave the file open. You will use it again later in the tutorial.

        Tips:
            - You can specify a custom **Project Base URL** in the **Project Preferences** dialog box.  Right click your project and select **Project Preferences** and then enter the custom URL in the **Project Base Directory** text box.
            - Komodo uses your system path to find installed tools.  You can also manually configure the location at the Global, Project, or File level preferences.  Komodo prioritizes preferences in the following hierarchy, File > Project > Global.
            - <% if (require("sdk/system").platform == "winnt") { %>Use `where [exectuableName]` in **Commando** to see what Komodo will find on your path.  Example `where pip`<% } else { %>Use `which [exectuableName]` in **Commando** to see what Komodo will find on your path.  Example `which pip`<% } %>

    -
        Title: Configuring virtualenv
        Summary: >
            You need to complete these steps to set up and activate your **virtualenv**:
             - Use Go to Anything to create a new virtualenv
             - Edit your preferences to have Komodo use a new system PATH

        Task: >
            1. Press `Ctrl + Shift + O` (or `Cmd + Shift + O` on Mac OS X)
            to open Go to Anything.
            1. Press 8 to select the Shell scope.
            1. Enter *virtualenv VENV* to create a new virtualenv.
            ```
            ...
            Installing setuptools, pip...done.
            ```
            1. Open the Preferences dialog box:
                - Select <% if (require("sdk/system").platform == "darwin") { %>**Edit menu > <% } else { %> <i class="icon icon-bars"></i>&nbsp;**[Menu button][callout:uniMenuButton] > Edit <% } %>  Preferences > Languages**.
                - Press `Ctrl + ,` (or `Cmd + ,` on Mac OS X).
            1. Click the **Environment** section.
            1. Locate and double click the **PATH** variable.
                The values are copied into the **User Environmental Variables**.
            1. Click OK to close the Preferences dialog box.
            1. Right click your project in the **Project pane** and select **Project Preferences**.
            1. Click the **Environment** section.  The **PATH** variable should already be populated.
            1. Double click the **PATH** variable to edit it.
            1. Paste the absolute path to your <% if (require("sdk/system").platform == "winnt") { %>
            `VENV\scripts\
            <% } else { %>
            `VENV\bin\
            <% } %>` folder at the beginning of the PATH string.  You must enter the <% if (require("sdk/system").platform == "winnt") { %>
            `;`
            <% } else { %>
            `:`
            <% } %> character to divide the paths.
            1. Click **OK** to save the path.
            1. Click **OK** to close the dialog box.

        Tips:
            - You can assign your `virtualenv` whatever name you like, but you must ensure that you use the same name throughout the tutorial.
            - You can assign a key binding to the Shell Scope in the Key Bindings section in the Preferences dialog box and search for `cmd_scope-shell` to assign a binding.
            - Press Backspace or Esc to back out of Go to Anything (Commando) commands or the Everything Scope of **Commando**.
    -
        Title: Configuring Django
        Summary: >
            You need to complete the following steps to install and configure Django:
             - Configure Komodo to use your virtualenv `pip`
             - Install Django
             - Create your Django project
        Task: >
            1. Right click your project in the Project pane and select **Project Preferences**.
            1. Expand the Languages section and select Python or Python3, as appropriate.
            1. In the **Pip location** field specify the location of the **pip** executable installed
            in your virtualenv (Windows: `VENV\Scripts\pip`, Unix: `VENV\bin\pip`) and click **OK**.
            1. Press `Ctrl + Shift + O` (or `Cmd + Shift + O` on Mac OS X)
            to open Go to Anything.
            1. Press 8 to select the Shell scope.
            1. Enter **pip > install > Django**. The output should look similar to the following:
            ```
            Successfully installed django
            Cleaning up...
            ```
            1. Press `Ctrl + Shift + O` (or `Cmd + Shift + O` on Mac OS X) and then press 8.
            1. Enter `django-admin startproject mysite`.

        Tips:
            - The output of commands in Go to Anything (Commando) tell you which executable was used at the start of the output.  You should verify that the expected executable is displayed.
    -
        Title: Starting Django
        Summary: >
            You need to complete the following steps to start Django:
            - Create a Toolbox Command to start the server.
            - Navigate to your site in your web browser.

            **NOTE**: You will be saving the tool in your Project toolbox.  Locate the red toolbox icon with the same name as your project at the bottom of the [Toolbox][callout:toolboxWidget].
        Task: >
            1. In the [Toolbox][callout:toolboxWidget] right click your project toolbox and select **Add > New Command**.
            1. Name the tool `Start Django Server`.
            1. Enter the following into the command field: `%python manage.py runserver`.
            1. Click the **Advanced Options** tab.
            1. In the **Start in** field, enter `<% if (require("sdk/system").platform == "winnt") { %>
            %i\mysite
            <% } else { %>
            %/mysite
            <% } %>`. (`%i` is the current projects base directory).
            1. From the `Run in` drop down list select `New Console`.
            1. Click `OK`.
            1. Double click the Start Django toolbox command and
            it will open a terminal window with output that looks
            similar to the following:

            ```
            Performing system checks...

            System check identified no issues (0 silenced).
            December 06, 2016 - 15:45:23
            Django version 1.10.4, using settings
            'mysite.settings'
            Starting development server at
            http://127.0.0.1:8000/
            Quit the server with CTRL-BREAK.
            ```

            Open your web browser and navigate to the URL listed in the command output to see the site running.
// =========================
// komodo meta: logic
// =========================
// Sample content, edit, delete, do whatever you like
(function() {
    var {Cc, Ci} = require("chrome");
    var $ = require("ko/dom");
    var w = require("ko/windows").getMain();
    var ko = w.ko;
    
    this.start = function() {};
    this.preStep = function() {};
    this.step = function() {};
    this.preClose = function() {};
    this.close = function() {};

    this.focusPlaces = function()
    {
        ko.uilayout.ensureTabShown('placesViewbox', true);
        w.require("tutorials").logicCallout("placesWidget");
    };
    
}).apply(module.exports);