Kivy Interactive Sandbox Example

Background

The Kivy Interactive Sandbox (aka kivy.interactive.InteractiveLauncher) seems to be a powerful tool to help Kivy developers. “The InteractiveLauncher provides a user-friendly python shell interface to an App so that it can be prototyped and debugged interactively.”

For example, you can take advantage of IPython’s Tab Completion feature to discover Kivy’s class methods and properties.

I first heard about this when I tried to follow Gabriel Pettier’s YouTube Example of Brian Knapp’s Work, but the font was too small for me.

Then I found the documentation for Brian’s work here.

The following are my notes on getting this running. I did this on Windows XP. This article is divided into 2 sections.

Section-1 Preparation of Paths
Prepare & check that the os.getenv(‘path’) and sys.path for IPython work with the Kivy installation. Step-1 Open a Command Window – Prepare Paths. Step-2 In SAME Command Window – Check Paths.
Section-2 Running the Interactive Development Example
Given the preparation is complete, run the Interactive Development Example. Step-3 In SAME Command Window in IPython – Paste the PART_TO_PASTE. Step-4 In SAME Command Window in IPython – Type in the Interactive Commands one at a time.

Section-1 Preparation & Checking of Paths

I am assuming you have already downloaded & installed Kivy, see this link.

For my Windows XP Kivy-1.8.0-py2.7-win32 installation, I am using the “Send-to method” to Start a Kivy Application.

Here’s what I do to prepare & check that the os.getenv(‘path’) and sys.path for IPython work with my Kivy installation.

Step-1 Open a Command Window – Prepare Paths.

Open a cmd window & say something like the following 2 commands to see the listed output.

>cd "PATH_TO_KIVY_INSTALL\kivy\examples"
>..\..kivy.bat
botstrapping Kivy @ C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32
Setting Environment Variables:
#################################
GST_REGISTRY
C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32gstreamerregistry.bin
---------------
GST_PLUGIN_PATH:
C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32gstreamerlibgstreamer-1.0
---------------
PATH:
C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32;C:Documents and SettingsjoeMy Documents
downloadskivyKivy-1.8.0-py2.7-win32Python27;C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-w
in32tools;C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32Python27Scripts;C:Documents an
d SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32gstreamerbin;C:Documents and SettingsjoeMy Documentsd
ownloadskivyKivy-1.8.0-py2.7-win32MinGWbin;C:Program FilesJavajdk1.7.0_10bin;C:WINDOWSsystem32;C:WINDOWS;C:WINDO
WSSystem32Wbem;C:1bat;C:Python27;C:Python27Scripts;C:Program FilesTortoiseHg;C:Program FilesTortoiseSVNbin;C:Pr
ogram FilesNotepad++
----------------------------------
PYTHONPATH:
C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32kivy;
----------------------------------
##################################
done bootstraping kivy...have fun!n

-----------------------------------------------------------------------
- Running a shell, you can browse kivyexamples and launch apps with: -
- python app.py -
-----------------------------------------------------------------------

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

Step-2 In SAME Command Window – Check Paths.

Next, IN THE SAME COMMAND WINDOW, start IPython. Check to see that the os.getenv(‘path’) and sys.path are good.

>ipython
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.13.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: pwd
Out[1]: u'C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32kivyexamples'

In [2]: import sys, os

In [3]: sys.path
Out[3]:
['',
 'C:Python27Scripts',
 'C:Python27libsite-packagesdistribute-0.6.28-py2.7.egg',
 'C:Python27libsite-packagespyreadline-2.0_dev1-py2.7-win32.egg',
 'C:Python27libsite-packagesfeedparser-5.1.2-py2.7.egg',
 'C:Python27libsite-packagesmechanize-0.2.5-py2.7.egg',
 'C:Python27libsite-packagespip-1.2.1-py2.7.egg',
 'C:Python27libsite-packagespytidylib-0.2.1-py2.7.egg',
 'C:Python27libsite-packageseyed3-0.7.1-py2.7.egg',
 'C:Python27libsite-packagesrequests_oauthlib-0.4.0-py2.7.egg',
 'C:Python27libsite-packagesrequests-2.0.1-py2.7.egg',
 'C:Python27libsite-packagesoauthlib-0.6.0-py2.7.egg',
 'C:Python27libsite-packageshttplib2-0.8-py2.7.egg',
 'C:Python27libsite-packagesoauth2-1.5.211-py2.7.egg',
 'C:Python27libsite-packagespython_twitter-1.1-py2.7.egg',
 'C:Python27libsite-packagessphinx-1.2.1-py2.7.egg',
 'C:Python27libsite-packagesjinja2-2.7.2-py2.7.egg',
 'C:Python27libsite-packagesdocutils-0.11-py2.7.egg',
 'C:Python27libsite-packagespygments-1.6-py2.7.egg',
 'C:Python27libsite-packagesmarkupsafe-0.18-py2.7.egg',
 'C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32kivy',
 'C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32kivyexamples',
 'C:WINDOWSsystem32python27.zip',
 'C:Python27DLLs',
 'C:Python27lib',
 'C:Python27libplat-win',
 'C:Python27liblib-tk',
 'C:Python27',
 'C:Python27libsite-packages',
 'C:Python27libsite-packageswin32',
 'C:Python27libsite-packageswin32lib',
 'C:Python27libsite-packagesPythonwin',
 'C:Python27libsite-packageswx-2.8-msw-unicode',
 'C:Python27libsite-packagesIPythonextensions']

In [4]: os.getenv('path').split(';')
Out[4]:
['C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32',
 'C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32Python27',
 'C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32tools',
 'C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32Python27Scripts',
 'C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32gstreamerbin',
 'C:Documents and SettingsjoeMy DocumentsdownloadskivyKivy-1.8.0-py2.7-win32MinGWbin',
 'C:Program FilesJavajdk1.7.0_10bin',
 'C:WINDOWSsystem32',
 'C:WINDOWS',
 'C:WINDOWSSystem32Wbem',
 'C:1bat',
 'C:Python27',
 'C:Python27Scripts',
 'C:Program FilesTortoiseHg',
 'C:Program FilesTortoiseSVNbin',
 'C:Program FilesNotepad++']

In [5]:

Section-2 Running the Interactive Development Example

Step-3 In SAME Command Window in IPython – Paste the PART_TO_PASTE.

Next, in the same Command Window, in IPython, %paste the PART_TO_PASTE (shown below) of the Interactive Development example into IPython.

# PART_TO_PASTE
from kivy.interactive import InteractiveLauncher
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse

class MyPaintWidget(Widget):
    def on_touch_down(self, touch):
        with self.canvas:
            Color(1, 1, 0)
            d = 30.
            Ellipse(pos=(touch.x - d/2, touch.y - d/2), size=(d, d))


class TestApp(App):
    def build(self):
        return Widget()


i = InteractiveLauncher(TestApp())
i.run()
# /PART_TO_PASTE

Step-4 In SAME Command Window in IPython – Type in the Interactive Commands one at a time.

Now, one at a time, even though IPython is not showing an input prompt, type in the Interactive Commands from the Interactive Development example into IPython as shown below.

i.       # press 'tab' to list attributes of the app - results in the ipython window

i.root.  # press 'tab' to list attributes of the root widget - results in the ipython window

# App is boring.  Attach a new widget! - results in the App window
i.root.add_widget(MyPaintWidget())
# click in the app and yellow dots will show up 

i.safeIn()
# The application is now blocked.
# Click on the screen several times. - dots won't show up 
#    N.B. in windows, window turns white & says "Test (Not Responding)"

i.safeOut()
# The clicks will show up now
#    N.B. In Windows XP, dots show up & clicks again produce yellow dots on black background 
#        but the Test taskbar button still says "Test (Not Responding)" even though it is.

# Erase artwork and start over
i.root.canvas.clear()
# On Windows SP, clicks don't work until after, in ipython, you say "i.root.add_widget(MyPaintWidget())" again

i.root.add_widget(MyPaintWidget())
# click in the app and yellow dots will show up 

Here’s a short link http://wp.me/p1zI3Z-bv

I hope this helps you.

Love and peace,
Joe

Python NWC tool to reverse selected notes in a staff

Here’s the python code. Enjoy.

This code needs to import nwctxt.py see https://github.com/nwsw/nwc2ut-python

"""joeSelReverse.py Reverses the Notes that are selected in a NoteWorthy Composer staff

"""

import sys
import nwctxt # see https://github.com/nwsw/nwc2ut-python
import logging
logging.basicConfig(filename='joeNWC_PY.log',level=logging.DEBUG)  # DEBUG => print ALL msgs

clip = nwctxt.NWC2Clip()
PlayContext = nwctxt.NWC2PlayContext()
txtItemL = clip.Items
clipItemL = [nwctxt.NWC2ClipItem(txtItem) for txtItem in txtItemL]
first2 = clipItemL[:2]
reversedClipItemL = first2 + list(reversed(clipItemL[2:]))
reversedTextItemL = [item.ReconstructClipText() for item in reversedClipItemL]

print clip.GetClipHeader()
for textItem in reversedTextItemL[2:]:
    #print "clipItem.GetObjType()= %s, type(clipItem.GetObjType())= %s, "%(clipItem.GetObjType(), type(clipItem.GetObjType()))
    print textItem
print clip.GetClipFooter()


# TO DEBUG uncomment below to report to NWC STDOUT DIALOG & to CAUSE NO STAFF MODIFICATION
# sys.exit(nwctxt.NWC2RC_REPORT) 

Essential Music Links

Music Software

NoteWorthy Composer
A music notation software authoring tool for Windows.
music21
A Python Toolkit for Computer-Aided Musicology and Musical Analysis.
MuseScore
Create, play and print beautiful sheet music.
MusicXML
The standard open format for exchanging digital sheet music.
LilyPond
LilyPond is a music engraving program, devoted to producing the highest-quality sheet music possible.

Ear Training

The Musical Intervals Tutor
A study aid to help you learn the sounds of the basic music intervals from minor second to perfect octave.
Big Ears
The Original Online Ear Trainer!

Musicology

Dolmetsch Online
Music theory & history online.