Пример #1
0
    def enable_pylab(self, gui=None):
        """Activate pylab support at runtime.

        This turns on support for matplotlib, preloads into the interactive
        namespace all of numpy and pylab, and configures IPython to correcdtly
        interact with the GUI event loop.  The GUI backend to be used can be
        optionally selected with the optional :param:`gui` argument.

        Parameters
        ----------
        gui : optional, string

          If given, dictates the choice of matplotlib GUI backend to use
          (should be one of IPython's supported backends, 'tk', 'qt', 'wx' or
          'gtk'), otherwise we use the default chosen by matplotlib (as
          dictated by the matplotlib build-time options plus the user's
          matplotlibrc configuration file).
        """
        # We want to prevent the loading of pylab to pollute the user's
        # namespace as shown by the %who* magics, so we execute the activation
        # code in an empty namespace, and we update *both* user_ns and
        # user_ns_hidden with this information.
        ns = {}
        gui = pylab_activate(ns, gui)
        self.user_ns.update(ns)
        self.user_ns_hidden.update(ns)
        # Now we must activate the gui pylab wants to use, and fix %run to take
        # plot updates into account
        enable_gui(gui)
        self.magic_run = self._pylab_magic_run
Пример #2
0
    def enable_pylab(self, gui=None, import_all=True):
        """Activate pylab support at runtime.

        This turns on support for matplotlib, preloads into the interactive
        namespace all of numpy and pylab, and configures IPython to correcdtly
        interact with the GUI event loop.  The GUI backend to be used can be
        optionally selected with the optional :param:`gui` argument.

        Parameters
        ----------
        gui : optional, string

          If given, dictates the choice of matplotlib GUI backend to use
          (should be one of IPython's supported backends, 'tk', 'qt', 'wx' or
          'gtk'), otherwise we use the default chosen by matplotlib (as
          dictated by the matplotlib build-time options plus the user's
          matplotlibrc configuration file).
        """
        # We want to prevent the loading of pylab to pollute the user's
        # namespace as shown by the %who* magics, so we execute the activation
        # code in an empty namespace, and we update *both* user_ns and
        # user_ns_hidden with this information.
        ns = {}
        try:
            gui = pylab_activate(ns, gui, import_all)
        except KeyError:
            error("Backend %r not supported" % gui)
            return
        self.user_ns.update(ns)
        self.user_ns_hidden.update(ns)
        # Now we must activate the gui pylab wants to use, and fix %run to take
        # plot updates into account
        enable_gui(gui)
        self.magic_run = self._pylab_magic_run
Пример #3
0
In [5]: %gui tk

In [6]: %run gui-tk.py
"""

from tkinter import *


class MyApp:
    def __init__(self, root):
        frame = Frame(root)
        frame.pack()

        self.button = Button(frame, text="Hello", command=self.hello_world)
        self.button.pack(side=LEFT)

    def hello_world(self):
        print("Hello World!")


root = Tk()

app = MyApp(root)

try:
    from IPython.lib.inputhook import enable_gui
    enable_gui('tk', root)
except ImportError:
    root.mainloop()
Пример #4
0
# schedule a gui update every half second
pyglet.clock.schedule_interval(update_gui, 0.5)

# make the window visible
window.set_visible(True)

# setup shaders etc
setup()
setup_gui()

window.push_handlers(frame)
window.push_handlers(on_key_press)


sys.path = sys.path + [os.curdir + os.sep + "fbx2020_1"]
import FbxCommon
try:
    from fbx import *
    # Prepare the FBX SDK.
    (lSdkManager, lScene) = FbxCommon.InitializeSdkObjects()
    try:
        print("Ipython import")
        from IPython.lib.inputhook import enable_gui
        enable_gui('pyglet')
    except ImportError:
         print("Ipython import failed")
    pyglet.app.run()
    lSdkManager.Destroy()
except ImportError:
    print("You need to build the python bindings for fbx 2020.1")
Пример #5
0
import pygtk
pygtk.require('2.0')
import gtk


def hello_world(wigdet, data=None):
    print("Hello World")

def delete_event(widget, event, data=None):
    return False

def destroy(widget, data=None):
    gtk.main_quit()

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("delete_event", delete_event)
window.connect("destroy", destroy)
button = gtk.Button("Hello World")
button.connect("clicked", hello_world, None)

window.add(button)
button.show()
window.show()

try:
    from IPython.lib.inputhook import enable_gui
    enable_gui('gtk')
except ImportError:
    gtk.main()
Пример #6
0

def hello_world(wigdet, data=None):
    print("Hello World")


def delete_event(widget, event, data=None):
    return False


def destroy(widget, data=None):
    Gtk.main_quit()


window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
window.connect("delete_event", delete_event)
window.connect("destroy", destroy)
button = Gtk.Button(label="Hello World")
button.connect("clicked", hello_world, None)

window.add(button)
button.show()
window.show()

try:
    from IPython.lib.inputhook import enable_gui

    enable_gui("gtk3")
except ImportError:
    Gtk.main()
Пример #7
0

def hello_world(wigdet, data=None):
    print("Hello World")


def delete_event(widget, event, data=None):
    return False


def destroy(widget, data=None):
    gtk.main_quit()


window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("delete_event", delete_event)
window.connect("destroy", destroy)
button = gtk.Button("Hello World")
button.connect("clicked", hello_world, None)

window.add(button)
button.show()
window.show()

try:
    from IPython.lib.inputhook import enable_gui

    enable_gui("gtk")
except ImportError:
    gtk.main()
Пример #8
0

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, "Simple wxPython App")
        self.SetTopWindow(frame)

        print("Print statements go to this stdout window by default.")

        frame.Show(True)
        return True


if __name__ == "__main__":

    app = wx.GetApp()
    if app is None:
        app = MyApp(redirect=False, clearSigInt=False)
    else:
        frame = MyFrame(None, "Simple wxPython App")
        app.SetTopWindow(frame)
        print("Print statements go to this stdout window by default.")
        frame.Show(True)

    try:
        from IPython.lib.inputhook import enable_gui

        enable_gui("wx", app)
    except ImportError:
        app.MainLoop()
Пример #9
0
"""

try:
    from tkinter import *  # Python 3
except ImportError:
    from Tkinter import *  # Python 2


class MyApp:
    def __init__(self, root):
        frame = Frame(root)
        frame.pack()

        self.button = Button(frame, text="Hello", command=self.hello_world)
        self.button.pack(side=LEFT)

    def hello_world(self):
        print("Hello World!")


root = Tk()

app = MyApp(root)

try:
    from IPython.lib.inputhook import enable_gui

    enable_gui("tk", root)
except ImportError:
    root.mainloop()
from gi.repository import Gtk


def hello_world(wigdet, data=None):
    print("Hello World")


def delete_event(widget, event, data=None):
    return False


def destroy(widget, data=None):
    Gtk.main_quit()


window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
window.connect("delete_event", delete_event)
window.connect("destroy", destroy)
button = Gtk.Button("Hello World")
button.connect("clicked", hello_world, None)

window.add(button)
button.show()
window.show()

try:
    from IPython.lib.inputhook import enable_gui
    enable_gui('gtk3')
except ImportError:
    Gtk.main()
Пример #11
0

def hello_world(wigdet, data=None):
    print("Hello World")


def delete_event(widget, event, data=None):
    return False


def destroy(widget, data=None):
    Gtk.main_quit()


window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
window.connect("delete_event", delete_event)
window.connect("destroy", destroy)
button = Gtk.Button("Hello World")
button.connect("clicked", hello_world, None)

window.add(button)
button.show()
window.show()

try:
    from IPython.lib.inputhook import enable_gui

    enable_gui("gtk3")
except ImportError:
    Gtk.main()
Пример #12
0
 def gtk_catchup(self):
     if ENABLE_GTK:
         from IPython.lib.inputhook import enable_gui
         enable_gui(gui='gtk')
Пример #13
0
In [2]: %run gui-gtk3.py
"""

from gi.repository import Gtk


def hello_world(wigdet, data=None):
    print("Hello World")

def delete_event(widget, event, data=None):
    return False

def destroy(widget, data=None):
    Gtk.main_quit()

window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
window.connect("delete_event", delete_event)
window.connect("destroy", destroy)
button = Gtk.Button(label="Hello World")
button.connect("clicked", hello_world, None)

window.add(button)
button.show()
window.show()

try:
    from IPython.lib.inputhook import enable_gui
    enable_gui('gtk3')
except ImportError:
    Gtk.main()
Пример #14
0
In [5]: %gui tk

In [6]: %run gui-tk.py
"""

from tkinter import * 


class MyApp:

    def __init__(self, root):
        frame = Frame(root)
        frame.pack()

        self.button = Button(frame, text="Hello", command=self.hello_world)
        self.button.pack(side=LEFT)

    def hello_world(self):
        print("Hello World!")

root = Tk()

app = MyApp(root)

try:
    from IPython.lib.inputhook import enable_gui
    enable_gui('tk', root)
except ImportError:
    root.mainloop()
Пример #15
0
In [5]: %gui tk

In [6]: %run gui-tk.py
"""

from tkinter import *


class MyApp:
    def __init__(self, root):
        frame = Frame(root)
        frame.pack()

        self.button = Button(frame, text="Hello", command=self.hello_world)
        self.button.pack(side=LEFT)

    def hello_world(self):
        print("Hello World!")


root = Tk()

app = MyApp(root)

try:
    from IPython.lib.inputhook import enable_gui

    enable_gui("tk", root)
except ImportError:
    root.mainloop()
Пример #16
0
window = pyglet.window.Window()
label = pyglet.text.Label(
    "Hello, world",
    font_name="Times New Roman",
    font_size=36,
    x=window.width // 2,
    y=window.height // 2,
    anchor_x="center",
    anchor_y="center",
)


@window.event
def on_close():
    window.close()


@window.event
def on_draw():
    window.clear()
    label.draw()


try:
    from IPython.lib.inputhook import enable_gui

    enable_gui("pyglet")
except ImportError:
    pyglet.app.run()
Пример #17
0
    mainShader = shaderSystem.createShader("main")
    grid_image = pyglet.image.load('images/grid.png')
    grid_texture = grid_image.get_texture()
    planet = sphere.Sphere(1.0)
    cam = camera.Camera(position=Vector3(0.0, 0.0, -10.0))
    mainShader.unbind()

# schedule an empty update function, at 60 frames/second
pyglet.clock.schedule_interval(lambda dt: None, 1.0/60.0)

# schedule a gui update every half second
pyglet.clock.schedule_interval(update_gui, 0.5)

# make the window visible
window.set_visible(True)

# setup shaders etc
setup()
setup_gui()

window.push_handlers(frame)
window.push_handlers(on_key_press)

try:
    print "Ipython import"
    from IPython.lib.inputhook import enable_gui
    enable_gui('pyglet')
except ImportError:
    print "Ipython import failed"
    pyglet.app.run()
Пример #18
0
        print("Having fun yet?")


class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, "Simple wxPython App")
        self.SetTopWindow(frame)

        print("Print statements go to this stdout window by default.")

        frame.Show(True)
        return True


if __name__ == '__main__':

    app = wx.GetApp()
    if app is None:
        app = MyApp(redirect=False, clearSigInt=False)
    else:
        frame = MyFrame(None, "Simple wxPython App")
        app.SetTopWindow(frame)
        print("Print statements go to this stdout window by default.")
        frame.Show(True)

    try:
        from IPython.lib.inputhook import enable_gui
        enable_gui('wx', app)
    except ImportError:
        app.MainLoop()