diff --git a/docs/FAQ/Makefile b/docs/FAQ/Makefile new file mode 100644 index 000000000..bd037ef73 --- /dev/null +++ b/docs/FAQ/Makefile @@ -0,0 +1,153 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/TraitsUIFAQ.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/TraitsUIFAQ.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/TraitsUIFAQ" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/TraitsUIFAQ" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/FAQ/make.bat b/docs/FAQ/make.bat new file mode 100644 index 000000000..263988df7 --- /dev/null +++ b/docs/FAQ/make.bat @@ -0,0 +1,190 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source +set I18NSPHINXOPTS=%SPHINXOPTS% source +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\TraitsUIFAQ.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\TraitsUIFAQ.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +:end diff --git a/docs/FAQ/source/conf.py b/docs/FAQ/source/conf.py new file mode 100644 index 000000000..a3b4780f4 --- /dev/null +++ b/docs/FAQ/source/conf.py @@ -0,0 +1,242 @@ +# -*- coding: utf-8 -*- +# +# FAQ documentation build configuration file, created by +# sphinx-quickstart on Thu Feb 28 06:48:12 2013. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.todo'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Traits FAQ' +copyright = u'2013, KJM' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.1' +# The full version, including alpha/beta/rc tags. +release = '0.1' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'FAQdoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'FAQ.tex', u'FAQ Documentation', + u'KJM', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'faq', u'FAQ Documentation', + [u'KJM'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------------ + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'FAQ', u'FAQ Documentation', + u'KJM', 'FAQ', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' diff --git a/docs/FAQ/source/index.rst b/docs/FAQ/source/index.rst new file mode 100644 index 000000000..a9b010352 --- /dev/null +++ b/docs/FAQ/source/index.rst @@ -0,0 +1,18 @@ +TraitsUI FAQ +============ + +This is the Frequently Asked Questions list for TraitsUI. There is some overlap +between Traits, TraitsUI and Chaco so take a look at the FAQs under those topics +as well. + +.. toctree:: + :maxdepth: 2 + + manyWindows/manyWindows.rst + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_oneWindow.py b/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_oneWindow.py new file mode 100644 index 000000000..cbdf6d22b --- /dev/null +++ b/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_oneWindow.py @@ -0,0 +1,142 @@ +## ex_traitsUI.colormappedImage_oneWindow.py + +# standard imports +import os +from math import atan2, sqrt + +# numpy imports +from numpy import sin, cos, exp, linspace, meshgrid, pi + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits, Instance, Range, Str, on_trait_change +from traitsui.api import Item, Group, View +from chaco.api import ArrayPlotData, jet, Plot + +# the window size and title. the title is the file name +windowSize = (800,600) +windowTitle = os.path.split(__file__)[1] + +class OneWindow( HasTraits ): + '''an image/scatter plot with graphics and control traits in one window''' + + # range values for the X and Y position of the point + # x position. suffix TR => Traits Range + xPosTR = Range( + value = 0.0, + low = -7.0, + high = 7.0, + label = "X", + desc = "the x position", + ) + + # y position. suffix TR => Traits Range + yPosTR = Range( + value = 0.0, + low = -7.0, + high = 7.0, + label = "Y", + desc = "the y position", + ) + + # the X,Y position in polar coordinates. suffix TS => Traits String + polarXYTS = Str( + value = 'Indeterminate', + default_value = 'Indeterminate', + label = "Polar", + desc = "the x,y point in polar coordinates", + ) + + # create an interesting scalar field for the image plot + twoPi = 2.0 * pi + xA = linspace(-twoPi, twoPi, 600) + yA = linspace(-twoPi, twoPi, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + z1MG = exp(-(xMG**2 + yMG**2)) / 100.0 + zxMG = sin( xMG ) / xMG + zyMG = sin( yMG ) / yMG + zMG = zxMG + zyMG + + # Create an ArrayPlotData object and give it this data + pdAPD = ArrayPlotData() + pdAPD.set_data( "Z", zMG ) + pdAPD.set_data( "X",[xPosTR.default_value] ) + pdAPD.set_data( "Y",[yPosTR.default_value] ) + + # Create the plot + plotP = Plot( pdAPD ) + + # add the image plot to this plot object + plotP.img_plot( + "Z", + xbounds = (-7,7), + ybounds = (-7,7), + colormap = jet, + ) + + # add a scatter plot to this plot object to plot the single (X,Y) point + plotP.plot( + ("X","Y"), + type = 'scatter', + marker = "circle", + color = "white", + marker_size = 5, + ) + + # add the title and padding around the plot + plotP.title = "2D sin(x)/x" + plotP.padding = 50 + + # grids, fonts, etc + plotP.x_grid.visible = True + plotP.y_grid.visible = True + plotP.x_axis.font = "modern 16" + plotP.y_axis.font = "modern 16" + plotP.x_axis.title = "X Phase (rad)" + plotP.y_axis.title = "Y Phase (rad)" + + @on_trait_change( 'xPosTR, yPosTR' ) + def _calculate_polarXY(self, name, new): + '''calculate a new polar coordinate whenever x or y changes. + also, load the new (X,Y) position into the scatter plot''' + + radius = sqrt( self.xPosTR * self.xPosTR + self.yPosTR * self.yPosTR ) + try: + angle = (180.0/pi) * atan2( self.yPosTR, self.xPosTR ) + self.polarXYTS = 'radius: %.2f, theta = %.2f' % (radius,angle) + except: + self.polarXYTS = 'Indeterminate' + + # manually change the scatter plot data + oneWindow.pdAPD.set_data( "X",[self.xPosTR] ) + oneWindow.pdAPD.set_data( "Y",[self.yPosTR] ) + + # set up the view for both the graphics and control + traits_view = View( + Group( + Item( + 'plotP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + Item( 'xPosTR' ), + Item( 'yPosTR' ), + Item( 'polarXYTS', style = 'readonly' ), + orientation = "vertical" + ), + resizable = True, + title = windowTitle + ) + +if __name__ == "__main__": + + # build the object + oneWindow = OneWindow() + + # set the (X,Y) point to form a 3-4-5 triangle. radius should + # calculate to 5 and the angle should be around 53 degrees + oneWindow.xPosTR = 3 + oneWindow.yPosTR = 4 + + # build and edit the window. uses the traits_view view as the object view + oneWindow.configure_traits() diff --git a/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_oneWindow_01.png b/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_oneWindow_01.png new file mode 100644 index 000000000..6d169d5cb Binary files /dev/null and b/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_oneWindow_01.png differ diff --git a/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_twoWindows.py b/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_twoWindows.py new file mode 100644 index 000000000..cd5830fb5 --- /dev/null +++ b/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_twoWindows.py @@ -0,0 +1,151 @@ +## ex_traitsUI.colormappedImage_twoWindows.py + +# standard imports +import os +from math import atan2, sqrt + +# numpy imports +from numpy import sin, cos, exp, linspace, meshgrid, pi + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits, Instance, Range, Str, on_trait_change +from traitsui.api import Item, Group, View +from chaco.api import ArrayPlotData, jet, Plot + +# the window size and title. the title is the file name +windowSize = (800,600) +windowTitle = os.path.split(__file__)[1] + +class TwoWindows( HasTraits ): + '''an image/scatter plot with graphics and control traits in seperate + windows''' + + # range values for the X and Y position of the point + # x position. suffix TR => Traits Range + xPosTR = Range( + value = 0.0, + low = -7.0, + high = 7.0, + label = "X", + desc = "the x position" + ) + + # y position. suffix TR => Traits Range + yPosTR = Range( + value = 0.0, + low = -7.0, + high = 7.0, + label = "Y", + desc = "the y position", + ) + + # the X,Y position in polar coordinates. suffix TS => Traits String + polarXYTS = Str( + value = 'Indeterminate', + default_value = 'Indeterminate', + label = "Polar", + desc = "the x,y point in polar coordinates" + ) + + # create an interesting scalar field for the image plot + twoPi = 2.0 * pi + xA = linspace(-twoPi, twoPi, 600) + yA = linspace(-twoPi, twoPi, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + z1MG = exp(-(xMG**2 + yMG**2)) / 100.0 + zxMG = sin( xMG ) / xMG + zyMG = sin( yMG ) / yMG + zMG = zxMG + zyMG + + # Create an ArrayPlotData object and give it this data + pdAPD = ArrayPlotData() + pdAPD.set_data( "Z", zMG ) + pdAPD.set_data( "X",[xPosTR.default_value] ) + pdAPD.set_data( "Y",[yPosTR.default_value] ) + + # Create the plot + plotP = Plot( pdAPD ) + + # add the image plot to this plot object + plotP.img_plot( + "Z", + xbounds = (-7,7), + ybounds = (-7,7), + colormap = jet, + ) + + # add a scatter plot to this plot object to plot the single (X,Y) point + plotP.plot( + ("X","Y"), + type = 'scatter', + marker = "circle", + color = "white", + marker_size = 5, + ) + + # add the title and padding around the plot + plotP.title = "2D sin(x)/x" + plotP.padding = 50 + + # grids, fonts, etc + plotP.x_grid.visible = True + plotP.y_grid.visible = True + plotP.x_axis.font = "modern 16" + plotP.y_axis.font = "modern 16" + plotP.x_axis.title = "X Phase (rad)" + plotP.y_axis.title = "Y Phase (rad)" + + @on_trait_change( 'xPosTR, yPosTR' ) + def _calculate_polarXY(self, name, new): + '''calculate a new polar coordinate whenever x or y changes. + also, load the new (X,Y) position into the scatter plot''' + + radius = sqrt( self.xPosTR * self.xPosTR + self.yPosTR * self.yPosTR ) + try: + angle = (180.0/pi) * atan2( self.yPosTR, self.xPosTR ) + self.polarXYTS = 'radius: %.2f, theta = %.2f' % (radius,angle) + except: + self.polarXYTS = 'Indeterminate' + + # manually change the scatter plot data + twoWindows.pdAPD.set_data( "X",[self.xPosTR] ) + twoWindows.pdAPD.set_data( "Y",[self.yPosTR] ) + +if __name__ == "__main__": + + # set up the view for the graphics window + graphicsView = View( + Item( + 'plotP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = 'graphics: ' + windowTitle, + ) + + # set up the view for the control window + controlView = View( + Group( + Item( 'xPosTR' ), + Item( 'yPosTR' ), + Item( 'polarXYTS', style = 'readonly' ), + orientation = "vertical", + ), + resizable = True, + title = 'control: ' + windowTitle, + ) + + # build the object + twoWindows = TwoWindows() + + # set the (X,Y) point to form a 3-4-5 triangle. radius should + # calculate to 5 and the angle should be around 53 degrees + twoWindows.xPosTR = 3 + twoWindows.yPosTR = 4 + + # build the two windows + twoWindows.edit_traits( view = graphicsView ) + twoWindows.configure_traits( view = controlView ) + diff --git a/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_twoWindows_01.png b/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_twoWindows_01.png new file mode 100644 index 000000000..1ebc4b355 Binary files /dev/null and b/docs/FAQ/source/manyWindows/ex_traitsui_colormappedImage_twoWindows_01.png differ diff --git a/docs/FAQ/source/manyWindows/ex_traitsui_manyWindows.py b/docs/FAQ/source/manyWindows/ex_traitsui_manyWindows.py new file mode 100644 index 000000000..44d5bd226 --- /dev/null +++ b/docs/FAQ/source/manyWindows/ex_traitsui_manyWindows.py @@ -0,0 +1,112 @@ +# ex_traitsui_manyWindows.py - multiple windowed gui with linked traits +# +# Particularly useful when the user wants one window to be a graphical +# display and the second window to contain the traitsUI controls +# +# Based upon Peter Wang's Interactive Plotting with Chaco talk given +# at the Scipy 2008 Advanced Tutorial Track, August 20, 2008 + +# standard imports +from math import atan2, sqrt, pi + +# Enthought library imports +from traits.api import HasTraits, Str, Range +from traits.api import on_trait_change +from traitsui.api import Item, View, Group + +class ManyWindows( HasTraits ): + '''multiple windows with linked traits''' + + # x position. suffix TR => Traits Range + xPosTR = Range( + value = 0.0, + low = -1000.0, + high = 1000.0, + label = "X", + desc = "the x position" + ) + + # y position. suffix TR => Traits Range + yPosTR = Range( + value = 0.0, + low = -1000.0, + high = 1000.0, + label = "Y", + desc = "the y position", + ) + + # the X,Y position in polar coordinates. suffix TS => Traits String + polarXYTS = Str( + value = 'Indeterminate', + default_value = 'Indeterminate', + label = "Polar", + desc = "the x,y point in polar coordinates" + ) + + # calculate a new polar coordinate whenever x or y changes + @on_trait_change( 'xPosTR, yPosTR' ) + def _calculate_polarXY(self, name, new): + radius = sqrt( self.xPosTR * self.xPosTR + self.yPosTR * self.yPosTR ) + try: + angle = (180.0/pi) * atan2( self.yPosTR, self.xPosTR ) + self.polarXYTS = 'radius: %.2f, theta = %.2f' % (radius,angle) + except: + self.polarXYTS = 'Indeterminate' + +if __name__ == "__main__": + + # create views for each window. Note that these views are not in the + # ManyWindows class but in the main routine. + + # window containing only the x position and output string. + # suffix TV => Traits View + view1TV = View( + Item( 'xPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + title = 'X View', + ) + + # window containing only the y position and output string + view2TV = View( + Item( 'yPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + title = 'Y View', + ) + + # a window with both the x and y positions + view3TV = View( + Group( + Item( 'xPosTR' ), + Item( 'yPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + ), + title = 'X/Y View', + ) + + ## the x and y positions and polar equivalents in multiple windows + view4TV = View( + Group( + Item( 'xPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + label = 'X View', + ), + Group( + Item( 'yPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + label = 'Y View', + ), + title = 'Tabbed X/Y View' + ) + + manyWindows = ManyWindows() + + # Finally, call edit_traits() on the first object(s), but configure_traits() + # the last object. The final configure_traits() will start the wxPython + # main loop, which activates the service loops on all of the proceeding + # edit_traits() calls. The result is many windows, with linked GUI items + # and trias. + manyWindows.edit_traits( view = view1TV ) + manyWindows.edit_traits( view = view2TV ) + manyWindows.edit_traits( view = view3TV ) + manyWindows.configure_traits( view = view4TV ) + diff --git a/docs/FAQ/source/manyWindows/ex_traitsui_manyWindows_01.png b/docs/FAQ/source/manyWindows/ex_traitsui_manyWindows_01.png new file mode 100644 index 000000000..389b47bb9 Binary files /dev/null and b/docs/FAQ/source/manyWindows/ex_traitsui_manyWindows_01.png differ diff --git a/docs/FAQ/source/manyWindows/ex_traitsui_oneWindow.py b/docs/FAQ/source/manyWindows/ex_traitsui_oneWindow.py new file mode 100644 index 000000000..0ac05b1d5 --- /dev/null +++ b/docs/FAQ/source/manyWindows/ex_traitsui_oneWindow.py @@ -0,0 +1,66 @@ +# ex_traitsui_oneWindow.py - simple window demo + +# Based upon Peter Wang's Interactive Plotting with Chaco talk given +# at the Scipy 2008 Advanced Tutorial Track, August 20, 2008 + +# standard imports +from math import atan2, sqrt, pi + +# Enthought library imports +from traits.api import HasTraits, Str, Range, on_trait_change +from traitsui.api import Item, View, Group + +class oneWindow( HasTraits ): + '''one window with linked traits''' + + # x position. suffix TR => Traits Range + xPosTR = Range( + value = 0.0, + low = -1000.0, + high = 1000.0, + label = "X", + desc = "the x position" + ) + + # y position. suffix TR => Traits Range + yPosTR = Range( + value = 0.0, + low = -1000.0, + high = 1000.0, + label = "Y", + desc = "the y position", + ) + + # the X,Y position in polar coordinates. suffix TS => Traits String + polarXYTS = Str( + value = 'Indeterminate', + default_value = 'Indeterminate', + label = "Polar", + desc = "the x,y point in polar coordinates" + ) + + # calculate a new polar coordinate whenever x or y changes + @on_trait_change( 'xPosTR, yPosTR' ) + def _calculate_polarXY(self, name, new): + radius = sqrt( self.xPosTR * self.xPosTR + self.yPosTR * self.yPosTR ) + try: + angle = (180.0/pi) * atan2( self.yPosTR, self.xPosTR ) + self.polarXYTS = 'radius: %.2f, theta = %.2f' % (radius,angle) + except: + self.polarXYTS = 'Indeterminate' + + # a window with both the x and y positions + traits_view = View( + Group( + Item( 'xPosTR' ), + Item( 'yPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + ), + title = 'X/Y View', + ) + +if __name__ == "__main__": + + oneWindow = oneWindow() + oneWindow.configure_traits() + diff --git a/docs/FAQ/source/manyWindows/ex_traitsui_oneWindow_01.png b/docs/FAQ/source/manyWindows/ex_traitsui_oneWindow_01.png new file mode 100644 index 000000000..2f35de3fa Binary files /dev/null and b/docs/FAQ/source/manyWindows/ex_traitsui_oneWindow_01.png differ diff --git a/docs/FAQ/source/manyWindows/manyWindows.rst b/docs/FAQ/source/manyWindows/manyWindows.rst new file mode 100644 index 000000000..d04e169c1 --- /dev/null +++ b/docs/FAQ/source/manyWindows/manyWindows.rst @@ -0,0 +1,556 @@ + +.. index:: Windows; Multiple + +.. highlight:: python + :linenothreshold: 5 + +How to Create Multiple Linked Windows in TraitsUI +================================================= + +Based upon Peter Wang's Interactive Plotting with Chaco talk given +at the Scipy 2008 Advanced Tutorial Track, August 20, 2008 + +It's often useful to generate multiple windows with linked Traits. This +is especially true when displaying graphical data in a Chaco window, where the +graphical display is a large square window but the control panel must be a +differnt shape to accommodate grouping of various controls. + +The figure below shows a single TraitsUI window that converts an XY point +into its polar equivalent and displays the result as a string. + +.. figure:: ex_traitsui_oneWindow_01.png + :scale: 150 % + :align: center + :alt: A single TraitsUI window + + A single TraitsUI window + +The code to generate this window follows:: + + # ex_traitsui_oneWindow.py - simple window demo + + # Based upon Peter Wang's Interactive Plotting with Chaco talk given + # at the Scipy 2008 Advanced Tutorial Track, August 20, 2008 + + # standard imports + from math import atan2, sqrt, pi + + # Enthought library imports + from traits.api import HasTraits, Str, Range, on_trait_change + from traitsui.api import Item, View, Group + + class oneWindow( HasTraits ): + '''one window with linked traits''' + + # x position. suffix TR => Traits Range + xPosTR = Range( + value = 0.0, + low = -1000.0, + high = 1000.0, + label = "X", + desc = "the x position" + ) + + # y position. suffix TR => Traits Range + yPosTR = Range( + value = 0.0, + low = -1000.0, + high = 1000.0, + label = "Y", + desc = "the y position", + ) + + # the X,Y position in polar coordinates. suffix TS => Traits String + polarXYTS = Str( + value = 'Indeterminate', + default_value = 'Indeterminate', + label = "Polar", + desc = "the x,y point in polar coordinates" + ) + + # calculate a new polar coordinate whenever x or y changes + @on_trait_change( 'xPosTR, yPosTR' ) + def _calculate_polarXY(self, name, new): + radius = sqrt( self.xPosTR * self.xPosTR + self.yPosTR * self.yPosTR ) + try: + angle = (180.0/pi) * atan2( self.yPosTR, self.xPosTR ) + self.polarXYTS = 'radius: %.2f, theta = %.2f' % (radius,angle) + except: + self.polarXYTS = 'Indeterminate' + + # a window with both the x and y positions + traits_view = View( + Group( + Item( 'xPosTR' ), + Item( 'yPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + ), + title = 'X/Y View', + ) + + if __name__ == "__main__": + + oneWindow = oneWindow() + oneWindow.configure_traits() + +We can also display the same data in multiple windows, with the Traits linked +together. As we push a slider in one window, data in the other windows updates. + +.. figure:: ex_traitsui_manyWindows_01.png + :scale: 150 % + :align: center + :alt: Linked Traits in multiple windows + + Linked Traits in multiple windows + +The code to generate these windows is:: + + # ex_traitsui_manyWindows.py - multiple windowed gui with linked traits + # + # Particularly useful when the user wants one window to be a graphical + # display and the second window to contain the traitsUI controls + # + # Based upon Peter Wang's Interactive Plotting with Chaco talk given + # at the Scipy 2008 Advanced Tutorial Track, August 20, 2008 + + # standard imports + from math import atan2, sqrt, pi + + # Enthought library imports + from traits.api import HasTraits, Str, Range + from traits.api import on_trait_change + from traitsui.api import Item, View, Group + + class ManyWindows( HasTraits ): + '''multiple windows with linked traits''' + + # x position. suffix TR => Traits Range + xPosTR = Range( + value = 0.0, + low = -1000.0, + high = 1000.0, + label = "X", + desc = "the x position" + ) + + # y position. suffix TR => Traits Range + yPosTR = Range( + value = 0.0, + low = -1000.0, + high = 1000.0, + label = "Y", + desc = "the y position", + ) + + # the X,Y position in polar coordinates. suffix TS => Traits String + polarXYTS = Str( + value = 'Indeterminate', + default_value = 'Indeterminate', + label = "Polar", + desc = "the x,y point in polar coordinates" + ) + + # calculate a new polar coordinate whenever x or y changes + @on_trait_change( 'xPosTR, yPosTR' ) + def _calculate_polarXY(self, name, new): + radius = sqrt( self.xPosTR * self.xPosTR + self.yPosTR * self.yPosTR ) + try: + angle = (180.0/pi) * atan2( self.yPosTR, self.xPosTR ) + self.polarXYTS = 'radius: %.2f, theta = %.2f' % (radius,angle) + except: + self.polarXYTS = 'Indeterminate' + + if __name__ == "__main__": + + # create views for each window. Note that these views are not in the + # ManyWindows class but in the main routine. + + # window containing only the x position and output string. + # suffix TV => Traits View + view1TV = View( + Item( 'xPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + title = 'X View', + ) + + # window containing only the y position and output string + view2TV = View( + Item( 'yPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + title = 'Y View', + ) + + # a window with both the x and y positions + view3TV = View( + Group( + Item( 'xPosTR' ), + Item( 'yPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + ), + title = 'X/Y View', + ) + + ## the x and y positions and polar equivalents in multiple windows + view4TV = View( + Group( + Item( 'xPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + label = 'X View', + ), + Group( + Item( 'yPosTR' ), + Item( 'polarXYTS',style = 'readonly' ), + label = 'Y View', + ), + title = 'Tabbed X/Y View' + ) + + manyWindows = ManyWindows() + + # Finally, call edit_traits() on the first object(s), but configure_traits() + # the last object. The final configure_traits() will start the wxPython + # main loop, which activates the service loops on all of the proceeding + # edit_traits() calls. The result is many windows, with linked GUI items + # and trias. + manyWindows.edit_traits( view = view1TV ) + manyWindows.edit_traits( view = view2TV ) + manyWindows.edit_traits( view = view3TV ) + manyWindows.configure_traits( view = view4TV ) + +We generate multiple windows by calling ``edit_traits()`` on the first three +views. The ``edit_traits()`` method simply sets the stage to build the windows +without actually building them on the screen and activating the service routines +that manage the windows. The final call to ``configure_windows()`` sets the stage +for the final view and calls the GUI handling routines for all of the staged +windows. + +Using multiple windows can really improve the GUI and the user experience. The +figure below shows a simple image plot with sliders. The program uses the X +and Y Traits of the sliders to place a marker on the plot and display the +value of the function at that point. + +.. figure:: ex_traitsui_colormappedImage_oneWindow_01.png + :scale: 100 % + :align: center + :alt: A Chaco plot, with linked Traits, in a single window + + A Chaco plot, with linked Traits, in a single window + +The X and Y sliders, and the polar output text box, are at the bottom of +the screen but the layout is poor. The TraitsUI items are too wide. The code to +generate this GUI is:: + + ## ex_traitsUI.colormappedImage_oneWindow.py + + # standard imports + import os + from math import atan2, sqrt + + # numpy imports + from numpy import sin, cos, exp, linspace, meshgrid, pi + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits, Instance, Range, Str, on_trait_change + from traitsui.api import Item, Group, View + from chaco.api import ArrayPlotData, jet, Plot + + # the window size and title. the title is the file name + windowSize = (800,600) + windowTitle = os.path.split(__file__)[1] + + class OneWindow( HasTraits ): + '''an image/scatter plot with graphics and control traits in one window''' + + # range values for the X and Y position of the point + # x position. suffix TR => Traits Range + xPosTR = Range( + value = 0.0, + low = -7.0, + high = 7.0, + label = "X", + desc = "the x position", + ) + + # y position. suffix TR => Traits Range + yPosTR = Range( + value = 0.0, + low = -7.0, + high = 7.0, + label = "Y", + desc = "the y position", + ) + + # the X,Y position in polar coordinates. suffix TS => Traits String + polarXYTS = Str( + value = 'Indeterminate', + default_value = 'Indeterminate', + label = "Polar", + desc = "the x,y point in polar coordinates", + ) + + # create an interesting scalar field for the image plot + twoPi = 2.0 * pi + xA = linspace(-twoPi, twoPi, 600) + yA = linspace(-twoPi, twoPi, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + z1MG = exp(-(xMG**2 + yMG**2)) / 100.0 + zxMG = sin( xMG ) / xMG + zyMG = sin( yMG ) / yMG + zMG = zxMG + zyMG + + # Create an ArrayPlotData object and give it this data + pdAPD = ArrayPlotData() + pdAPD.set_data( "Z", zMG ) + pdAPD.set_data( "X",[xPosTR.default_value] ) + pdAPD.set_data( "Y",[yPosTR.default_value] ) + + # Create the plot + plotP = Plot( pdAPD ) + + # add the image plot to this plot object + plotP.img_plot( + "Z", + xbounds = (-7,7), + ybounds = (-7,7), + colormap = jet, + ) + + # add a scatter plot to this plot object to plot the single (X,Y) point + plotP.plot( + ("X","Y"), + type = 'scatter', + marker = "circle", + color = "white", + marker_size = 5, + ) + + # add the title and padding around the plot + plotP.title = "2D sin(x)/x" + plotP.padding = 50 + + # grids, fonts, etc + plotP.x_grid.visible = True + plotP.y_grid.visible = True + plotP.x_axis.font = "modern 16" + plotP.y_axis.font = "modern 16" + plotP.x_axis.title = "X Phase (rad)" + plotP.y_axis.title = "Y Phase (rad)" + + @on_trait_change( 'xPosTR, yPosTR' ) + def _calculate_polarXY(self, name, new): + '''calculate a new polar coordinate whenever x or y changes. + also, load the new (X,Y) position into the scatter plot''' + + radius = sqrt( self.xPosTR * self.xPosTR + self.yPosTR * self.yPosTR ) + try: + angle = (180.0/pi) * atan2( self.yPosTR, self.xPosTR ) + self.polarXYTS = 'radius: %.2f, theta = %.2f' % (radius,angle) + except: + self.polarXYTS = 'Indeterminate' + + # manually change the scatter plot data + oneWindow.pdAPD.set_data( "X",[self.xPosTR] ) + oneWindow.pdAPD.set_data( "Y",[self.yPosTR] ) + + # set up the view for both the graphics and control + traits_view = View( + Group( + Item( + 'plotP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + Item( 'xPosTR' ), + Item( 'yPosTR' ), + Item( 'polarXYTS', style = 'readonly' ), + orientation = "vertical" + ), + resizable = True, + title = windowTitle + ) + + if __name__ == "__main__": + + # build the object + oneWindow = OneWindow() + + # set the (X,Y) point to form a 3-4-5 triangle. radius should + # calculate to 5 and the angle should be around 53 degrees + oneWindow.xPosTR = 3 + oneWindow.yPosTR = 4 + + # build and edit the window. uses the traits_view view as the object view + oneWindow.configure_traits() + +Using the techniques described above, we can seperate the Chaco plot and the +control functions into two windows. + +.. figure:: ex_traitsui_colormappedImage_twoWindows_01.png + :scale: 100 % + :align: center + :alt: A Chaco plot, with linked Traits, in two windows + + A Chaco plot, with linked Traits, in two windows + +The layout and screen usage is a lot better. The graphics completely fill up +one window and the controls are appropriately sized in the second window. The +code generating the last figure is:: + + ## ex_traitsUI.colormappedImage_twoWindows.py + + # standard imports + import os + from math import atan2, sqrt + + # numpy imports + from numpy import sin, cos, exp, linspace, meshgrid, pi + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits, Instance, Range, Str, on_trait_change + from traitsui.api import Item, Group, View + from chaco.api import ArrayPlotData, jet, Plot + + # the window size and title. the title is the file name + windowSize = (800,600) + windowTitle = os.path.split(__file__)[1] + + class TwoWindows( HasTraits ): + '''an image/scatter plot with graphics and control traits in seperate + windows''' + + # range values for the X and Y position of the point + # x position. suffix TR => Traits Range + xPosTR = Range( + value = 0.0, + low = -7.0, + high = 7.0, + label = "X", + desc = "the x position" + ) + + # y position. suffix TR => Traits Range + yPosTR = Range( + value = 0.0, + low = -7.0, + high = 7.0, + label = "Y", + desc = "the y position", + ) + + # the X,Y position in polar coordinates. suffix TS => Traits String + polarXYTS = Str( + value = 'Indeterminate', + default_value = 'Indeterminate', + label = "Polar", + desc = "the x,y point in polar coordinates" + ) + + # create an interesting scalar field for the image plot + twoPi = 2.0 * pi + xA = linspace(-twoPi, twoPi, 600) + yA = linspace(-twoPi, twoPi, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + z1MG = exp(-(xMG**2 + yMG**2)) / 100.0 + zxMG = sin( xMG ) / xMG + zyMG = sin( yMG ) / yMG + zMG = zxMG + zyMG + + # Create an ArrayPlotData object and give it this data + pdAPD = ArrayPlotData() + pdAPD.set_data( "Z", zMG ) + pdAPD.set_data( "X",[xPosTR.default_value] ) + pdAPD.set_data( "Y",[yPosTR.default_value] ) + + # Create the plot + plotP = Plot( pdAPD ) + + # add the image plot to this plot object + plotP.img_plot( + "Z", + xbounds = (-7,7), + ybounds = (-7,7), + colormap = jet, + ) + + # add a scatter plot to this plot object to plot the single (X,Y) point + plotP.plot( + ("X","Y"), + type = 'scatter', + marker = "circle", + color = "white", + marker_size = 5, + ) + + # add the title and padding around the plot + plotP.title = "2D sin(x)/x" + plotP.padding = 50 + + # grids, fonts, etc + plotP.x_grid.visible = True + plotP.y_grid.visible = True + plotP.x_axis.font = "modern 16" + plotP.y_axis.font = "modern 16" + plotP.x_axis.title = "X Phase (rad)" + plotP.y_axis.title = "Y Phase (rad)" + + @on_trait_change( 'xPosTR, yPosTR' ) + def _calculate_polarXY(self, name, new): + '''calculate a new polar coordinate whenever x or y changes. + also, load the new (X,Y) position into the scatter plot''' + + radius = sqrt( self.xPosTR * self.xPosTR + self.yPosTR * self.yPosTR ) + try: + angle = (180.0/pi) * atan2( self.yPosTR, self.xPosTR ) + self.polarXYTS = 'radius: %.2f, theta = %.2f' % (radius,angle) + except: + self.polarXYTS = 'Indeterminate' + + # manually change the scatter plot data + twoWindows.pdAPD.set_data( "X",[self.xPosTR] ) + twoWindows.pdAPD.set_data( "Y",[self.yPosTR] ) + + if __name__ == "__main__": + + # set up the view for the graphics window + graphicsView = View( + Item( + 'plotP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = 'graphics: ' + windowTitle, + ) + + # set up the view for the control window + controlView = View( + Group( + Item( 'xPosTR' ), + Item( 'yPosTR' ), + Item( 'polarXYTS', style = 'readonly' ), + orientation = "vertical", + ), + resizable = True, + title = 'control: ' + windowTitle, + ) + + # build the object + twoWindows = TwoWindows() + + # set the (X,Y) point to form a 3-4-5 triangle. radius should + # calculate to 5 and the angle should be around 53 degrees + twoWindows.xPosTR = 3 + twoWindows.yPosTR = 4 + + # build the two windows + twoWindows.edit_traits( view = graphicsView ) + twoWindows.configure_traits( view = controlView ) + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search`