##// END OF EJS Templates
Added GTK support to ZeroMQ kernel....
Added GTK support to ZeroMQ kernel. We use an approach which is a combination of an gtk timer callback into our execution loop, like we do for Qt and Wx, I've run as tests several GTK examples found on the net, as well as multiple matplotlib scripts, and so far everything works as expected. The only catch is that we silently trap gtk.main_quit(), so examples that call it with a 'close' button or similar seem to not do anything. But their windows close normally and no other problems have been found. This solution uses code taken from an old bug report of ours: https://bugs.launchpad.net/ipython/+bug/270856 specifically the attachment in this comment: https://bugs.launchpad.net/ipython/+bug/270856/comments/6 along with the changes suggested by Michiel de Hoon there. Thanks to Ville and Michiel for that old discussion, which put me on the right track to figure out the details of the logic needed for GTK.

File last commit:

r1234:52b55407
r2949:13751b1c
Show More
magic.py
147 lines | 4.3 KiB | text/x-python | PythonLexer
# encoding: utf-8
__docformat__ = "restructuredtext en"
#-------------------------------------------------------------------------------
# Copyright (C) 2008 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Imports
#-------------------------------------------------------------------------------
import os
import __builtin__
# Local imports.
from util import Bunch
# fixme: RTK thinks magics should be implemented as separate classes rather than
# methods on a single class. This would give us the ability to plug new magics
# in and configure them separately.
class Magic(object):
""" An object that maintains magic functions.
"""
def __init__(self, interpreter, config=None):
# A reference to the interpreter.
self.interpreter = interpreter
# A reference to the configuration object.
if config is None:
# fixme: we need a better place to store this information.
config = Bunch(ESC_MAGIC='%')
self.config = config
def has_magic(self, name):
""" Return True if this object provides a given magic.
Parameters
----------
name : str
"""
return hasattr(self, 'magic_' + name)
def object_find(self, name):
""" Find an object in the available namespaces.
fixme: this should probably be moved elsewhere. The interpreter?
"""
name = name.strip()
# Namespaces to search.
# fixme: implement internal and alias namespaces.
user_ns = self.interpreter.user_ns
internal_ns = {}
builtin_ns = __builtin__.__dict__
alias_ns = {}
# Order the namespaces.
namespaces = [
('Interactive', user_ns),
('IPython internal', internal_ns),
('Python builtin', builtin_ns),
('Alias', alias_ns),
]
# Initialize all results.
found = False
obj = None
space = None
ds = None
ismagic = False
isalias = False
# Look for the given name by splitting it in parts. If the head is
# found, then we look for all the remaining parts as members, and only
# declare success if we can find them all.
parts = name.split('.')
head, rest = parts[0], parts[1:]
for nsname, ns in namespaces:
try:
obj = ns[head]
except KeyError:
continue
else:
for part in rest:
try:
obj = getattr(obj, part)
except:
# Blanket except b/c some badly implemented objects
# allow __getattr__ to raise exceptions other than
# AttributeError, which then crashes us.
break
else:
# If we finish the for loop (no break), we got all members
found = True
space = nsname
isalias = (ns == alias_ns)
break # namespace loop
# Try to see if it is a magic.
if not found:
if name.startswith(self.config.ESC_MAGIC):
name = name[1:]
obj = getattr(self, 'magic_' + name, None)
if obj is not None:
found = True
space = 'IPython internal'
ismagic = True
# Last try: special-case some literals like '', [], {}, etc:
if not found and head in ["''", '""', '[]', '{}', '()']:
obj = eval(head)
found = True
space = 'Interactive'
return dict(
found=found,
obj=obj,
namespace=space,
ismagic=ismagic,
isalias=isalias,
)
def magic_pwd(self, parameter_s=''):
""" Return the current working directory path.
"""
return os.getcwd()
def magic_env(self, parameter_s=''):
""" List environment variables.
"""
return os.environ.data