~ubuntu-branches/ubuntu/utopic/python-apptools/utopic

« back to all changes in this revision

Viewing changes to enthought/scripting/util.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-08 23:55:50 UTC
  • mfrom: (2.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110708235550-yz5u79ubeo4dhyfx
Tags: 4.0.0-1
* New upstream release
* Update debian/watch file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Simple utility functions provided by the scripting API.
2
 
"""
3
 
# Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in>
4
 
# Copyright (c) 2008,  Prabhu Ramachandran
5
 
# License: BSD Style.
6
 
 
7
 
from recorder import Recorder
8
 
from recorder_with_ui import RecorderWithUI
9
 
from package_globals import get_recorder, set_recorder
10
 
 
11
 
 
12
 
################################################################################
13
 
# Utility functions. 
14
 
################################################################################
15
 
def start_recording(object, ui=True, **kw):
16
 
    """Convenience function to start recording.  Returns the recorder.
17
 
 
18
 
    Parameters:
19
 
    -----------
20
 
 
21
 
    object :  object to record.
22
 
 
23
 
    ui : bool specifying if a UI is to be shown or not
24
 
 
25
 
    kw : Keyword arguments to pass to the register function of the
26
 
    recorder.
27
 
    """
28
 
    if ui:
29
 
        r = RecorderWithUI(root=object)
30
 
        r.edit_traits(kind='live')
31
 
    else:
32
 
        r = Recorder()
33
 
    # Set the global recorder.
34
 
    set_recorder(r)
35
 
    r.recording = True
36
 
    r.register(object, **kw)
37
 
    return r
38
 
 
39
 
def stop_recording(object, save=True):
40
 
    """Stop recording the object.  If `save` is `True`, this will pop up
41
 
    a UI to ask where to save the script.
42
 
    """
43
 
    recorder = get_recorder()
44
 
    recorder.unregister(object)
45
 
    recorder.recording = False
46
 
    # Set the global recorder back to None
47
 
    set_recorder(None)
48
 
    # Save the script.
49
 
    if save:
50
 
        recorder.ui_save()
51