_pylab_helpers.py :  » Chart-Report » Matplotlib » matplotlib-0.99.1.1 » lib » matplotlib » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Chart Report » Matplotlib 
Matplotlib » matplotlib 0.99.1.1 » lib » matplotlib » _pylab_helpers.py
"""
Manage figures for pyplot interface.
"""

import sys, gc

def error_msg(msg):
    print >>sys.stderr, msgs

class Gcf(object):
    """
    Manage a set of integer-numbered figures.

    This class is never instantiated; it consists of two class
    attributes (a list and a dictionary), and a set of static
    methods that operate on those attributes, accessing them
    directly as class attributes.

    Attributes:

        *figs*:
          dictionary of the form {*num*: *manager*, ...}

        *_activeQue*:
          list of *managers*, with active one at the end

    """
    _activeQue = []
    figs = {}

    @staticmethod
    def get_fig_manager(num):
        """
        If figure manager *num* exists, make it the active
        figure and return the manager; otherwise return *None*.
        """
        figManager = Gcf.figs.get(num, None)
        if figManager is not None:
            Gcf.set_active(figManager)
        return figManager

    @staticmethod
    def destroy(num):
        """
        Try to remove all traces of figure *num*.

        In the interactive backends, this is bound to the
        window "destroy" and "delete" events.
        """
        if not Gcf.has_fignum(num): return
        figManager = Gcf.figs[num]

        # There must be a good reason for the following careful
        # rebuilding of the activeQue; what is it?
        oldQue = Gcf._activeQue[:]
        Gcf._activeQue = []
        for f in oldQue:
            if f != figManager:
                Gcf._activeQue.append(f)

        del Gcf.figs[num]
        #print len(Gcf.figs.keys()), len(Gcf._activeQue)
        figManager.destroy()
        gc.collect()

    @staticmethod
    def has_fignum(num):
        """
        Return *True* if figure *num* exists.
        """
        return num in Gcf.figs

    @staticmethod
    def get_all_fig_managers():
        """
        Return a list of figure managers.
        """
        return Gcf.figs.values()

    @staticmethod
    def get_num_fig_managers():
        """
        Return the number of figures being managed.
        """
        return len(Gcf.figs.values())

    @staticmethod
    def get_active():
        """
        Return the manager of the active figure, or *None*.
        """
        if len(Gcf._activeQue)==0:
            return None
        else: return Gcf._activeQue[-1]

    @staticmethod
    def set_active(manager):
        """
        Make the figure corresponding to *manager* the active one.
        """
        oldQue = Gcf._activeQue[:]
        Gcf._activeQue = []
        for m in oldQue:
            if m != manager: Gcf._activeQue.append(m)
        Gcf._activeQue.append(manager)
        Gcf.figs[manager.num] = manager

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.