<commit_before>""" Defines commands for the Chaco shell.
"""
import wx

from enthought.chaco.api import Plot, color_map_name_dict
from enthought.chaco.scales.api import ScaleSystem
from enthought.chaco.tools.api import PanTool, RectZoomTool

# Note: these are imported to be exposed in the namespace.
from enthought.chaco.scales.api import (FixedScale, Pow10Scale, LogScale,
    CalendarScaleSystem)
from enthought.chaco.default_colormaps import *

import plot_maker
from session import PlotSession

session = PlotSession()


#------------------------------------------------------------------------
# General help commands
#------------------------------------------------------------------------

def chaco_commands():
    """
    Prints the current list of all shell commands.  Information
    on each command is available in that command's docstring (__doc__).

    Window/Plot Management
    ----------------------
    figure
        creates a new figure window
    activate
        activates an existing window or plot
    close
        closes a window
    curplot
        returns a reference to the active window's Plot object
    show
        starts the GUI and displays windows (should only be used in scripts)

    Plotting
    --------
    plot 
        plots some data
    imread 
        creates an array from an image file on disk
    imshow 
        creates an image plot from a file on disk
    pcolor 
        plots some scalar data as a pseudocolor image
    contour 
        creates a contour line plot of some scalar data
    contourf 
        creates a contour poly plot of some scalar data
    loglog 
        plots an x-y line or scatter plot on log-log scale
    semilogx 
        plots an x-y line or scatter plot with a log x-scale
    semilogy 
        plots an x-y line or scatter plot with a log y-scale
    hold 
        turns "hold" on or off
    show 
        shows plot on screen; used when running from script
    

    Axes, Annotations, Legends
    --------------------------
    xaxis 
        toggles the horizontal axis, sets the interval
    yaxis 
        toggles the vertical axis, sets the interval
    xgrid 
        toggles the grid running along the X axis
    ygrid 
        toggles the grid running along the Y axis
    xtitle 
        sets the title of a horizontal axis
    ytitle 
        sets the title of a vertical axis
    xscale
        sets the tick scale system of the X axis
    yscale
        sets the tick scale system of the Y axis
    title 
        sets the title of the plot


    Tools
    -----
    colormap 
        sets the current colormap    

    IO
    --
    save
        saves the current plot to a file (png, bmp, jpg, pdf)
    """
    print chaco_commands.__doc__

    # The following are not implemented yet
    """
    tool -- toggles certain tools on or off
    load -- loads a saved plot from file into the active plot area
    scatter -- plots some data as a scatterplot (unordered X/Y data)
    line -- plots some data as an ordered set of of X,Y points
    label -- adds a label at a data point
    legend -- creates a legend and adds it to the plot

    Layout
    ------
    names -- temporarily overlays plot areas with their names
    hidenames -- force remove the name overlays from show_names
    happend -- create a new plot area horizontally after the active plot
    vappend -- create a new plot area vertically after the active plot
    hsplit -- splits the current plot into two horizontal subplots
    vsplit -- splits the current plot into two vertical subplots
    save_layout -- saves the current layout of plots and plots areas
    load_layout -- loads a saved layout of plot areas and applies it to the
                   current set of plots

    Sessions
    --------
    save_session -- saves the current "workspace", defined as the set of
                    active windows and plots
    load_session -- restores a previously-saved session
    save_prefs -- saves the current session's preferences, either in a
                  separate file or as the chaco.shell defaults
    load_prefs -- loads a previously-saved set of preferences
    """

#------------------------------------------------------------------------
# Window management commands
#------------------------------------------------------------------------

def figure(name=None, title=None):
    """ Creates a new figure window and returns its index.
    
    Parameters
    ----------
    name : string 
        The name to use for this window. If this parameter is provided, then
        this name can be used instead of the window's integer index in other
        window-related functions.
    title : string
        The title of the plot window. If this is blank but *name* is provided,
        then that is used. If neither *name* nor *title* is provided, then the
        method uses the value of default_window_name in the Preferences.
    """
    win = session.new_window(name, title)
    activate(win)
    return win


def activate(ident=None):
    """ Activates and raises a figure window.
    
    Parameters
    ----------
    ident : integer or string 
        Index or name of the window.  If neither is specified,
        then the function raises the currently active window.
    """
    if ident is not None:
        win = session.get_window(ident)
    else:
        win = session.active_window
    
    if win is not None:
        session.active_window = win
        win.raise_window()
    return

def show():
    """ Shows all the figure windows that have been created thus far, and
    creates a GUI main loop.  This function is useful in scripts to show plots and
    keep their windows open, and has no effect when used from the interpreter
    prompt.
    """

    app = wx.GetApp()
    if not(app.IsMainLoopRunning()):
        frame = session.active_window
        app.SetTopWindow(frame)
        app.MainLoop()
    return


def close(ident=None):
    """ Closes a figure window<commit_msg>wrapping import of wx in chaco.shell<commit_after>""" Defines commands for the Chaco shell.
"""

try:
    from wx import GetApp
except ImportError:
    GetApp = lambda: None

from enthought.chaco.api import Plot, color_map_name_dict
from enthought.chaco.scales.api import ScaleSystem
from enthought.chaco.tools.api import PanTool, RectZoomTool

# Note: these are imported to be exposed in the namespace.
from enthought.chaco.scales.api import (FixedScale, Pow10Scale, LogScale,
    CalendarScaleSystem)
from enthought.chaco.default_colormaps import *

import plot_maker
from session import PlotSession

session = PlotSession()


#------------------------------------------------------------------------
# General help commands
#------------------------------------------------------------------------

def chaco_commands():
    """
    Prints the current list of all shell commands.  Information
    on each command is available in that command's docstring (__doc__).

    Window/Plot Management
    ----------------------
    figure
        creates a new figure window
    activate
        activates an existing window or plot
    close
        closes a window
    curplot
        returns a reference to the active window's Plot object
    show
        starts the GUI and displays windows (should only be used in scripts)

    Plotting
    --------
    plot 
        plots some data
    imread 
        creates an array from an image file on disk
    imshow 
        creates an image plot from a file on disk
    pcolor 
        plots some scalar data as a pseudocolor image
    contour 
        creates a contour line plot of some scalar data
    contourf 
        creates a contour poly plot of some scalar data
    loglog 
        plots an x-y line or scatter plot on log-log scale
    semilogx 
        plots an x-y line or scatter plot with a log x-scale
    semilogy 
        plots an x-y line or scatter plot with a log y-scale
    hold 
        turns "hold" on or off
    show 
        shows plot on screen; used when running from script
    

    Axes, Annotations, Legends
    --------------------------
    xaxis 
        toggles the horizontal axis, sets the interval
    yaxis 
        toggles the vertical axis, sets the interval
    xgrid 
        toggles the grid running along the X axis
    ygrid 
        toggles the grid running along the Y axis
    xtitle 
        sets the title of a horizontal axis
    ytitle 
        sets the title of a vertical axis
    xscale
        sets the tick scale system of the X axis
    yscale
        sets the tick scale system of the Y axis
    title 
        sets the title of the plot


    Tools
    -----
    colormap 
        sets the current colormap    

    IO
    --
    save
        saves the current plot to a file (png, bmp, jpg, pdf)
    """
    print chaco_commands.__doc__

    # The following are not implemented yet
    """
    tool -- toggles certain tools on or off
    load -- loads a saved plot from file into the active plot area
    scatter -- plots some data as a scatterplot (unordered X/Y data)
    line -- plots some data as an ordered set of of X,Y points
    label -- adds a label at a data point
    legend -- creates a legend and adds it to the plot

    Layout
    ------
    names -- temporarily overlays plot areas with their names
    hidenames -- force remove the name overlays from show_names
    happend -- create a new plot area horizontally after the active plot
    vappend -- create a new plot area vertically after the active plot
    hsplit -- splits the current plot into two horizontal subplots
    vsplit -- splits the current plot into two vertical subplots
    save_layout -- saves the current layout of plots and plots areas
    load_layout -- loads a saved layout of plot areas and applies it to the
                   current set of plots

    Sessions
    --------
    save_session -- saves the current "workspace", defined as the set of
                    active windows and plots
    load_session -- restores a previously-saved session
    save_prefs -- saves the current session's preferences, either in a
                  separate file or as the chaco.shell defaults
    load_prefs -- loads a previously-saved set of preferences
    """

#------------------------------------------------------------------------
# Window management commands
#------------------------------------------------------------------------

def figure(name=None, title=None):
    """ Creates a new figure window and returns its index.
    
    Parameters
    ----------
    name : string 
        The name to use for this window. If this parameter is provided, then
        this name can be used instead of the window's integer index in other
        window-related functions.
    title : string
        The title of the plot window. If this is blank but *name* is provided,
        then that is used. If neither *name* nor *title* is provided, then the
        method uses the value of default_window_name in the Preferences.
    """
    win = session.new_window(name, title)
    activate(win)
    return win


def activate(ident=None):
    """ Activates and raises a figure window.
    
    Parameters
    ----------
    ident : integer or string 
        Index or name of the window.  If neither is specified,
        then the function raises the currently active window.
    """
    if ident is not None:
        win = session.get_window(ident)
    else:
        win = session.active_window
    
    if win is not None:
        session.active_window = win
        win.raise_window()
    return

def show():
    """ Shows all the figure windows that have been created thus far, and
    creates a GUI main loop.  This function is useful in scripts to show plots and
    keep their windows open, and has no effect when used from the interpreter
    prompt.
    """

    app = GetApp()
    if not app:
        return

    if not(app.IsMainLoopRunning()):
        frame = session.active_window
        app.SetTopWindow(frame)
        app.MainLoop()
    return


def close(ident=None):
    """ Closes a figure window
{'fraction_non_alphanumeric': 0.10382197220383851, 'fraction_numerical': 0.00033090668431502316, 'mean_word_length': 1.8680901542111505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5543332', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2940, 'n_words': 1442}