1#!/usr/bin/env python 2""" 3This example illustrates embedding a visvis figure in an FLTK application. 4""" 5 6import fltk 7import visvis as vv 8 9# Create a visvis app instance, which wraps an fltk application object. 10# This needs to be done *before* instantiating the main window. 11app = vv.use('fltk') 12 13 14class MainWindow(fltk.Fl_Window): 15 def __init__(self): 16 fltk.Fl_Window.__init__(self, 560, 420, "Embedding in FLTK") 17 18 # Make a panel with a button 19 but = fltk.Fl_Button(10,10,70,30, 'Click me') 20 but.callback(self._Plot) 21 22 # Make figure to draw stuff in 23 Figure = app.GetFigureClass() 24 self.fig = Figure(100,10,560-110,420-20, "") 25 26 # Make box for resizing 27 box = fltk.Fl_Box(fltk.FL_NO_BOX,100,50, 560-110,420-60,"") 28 self.resizable(box) 29 box.hide() 30 31 # Finish 32 self.end() 33 self.show() 34 self.fig._widget.show() 35 36 37 def _Plot(self, event): 38 39 # Make sure our figure is the active one 40 # If only one figure, this is not necessary. 41 #vv.figure(self.fig.nr) 42 43 # Clear it 44 vv.clf() 45 46 # Plot 47 vv.plot([1,2,3,1,6]) 48 vv.legend(['this is a line']) 49 50 51# Two ways to create the application and start the main loop 52if True: 53 # The visvis way. Will run in interactive mode when used in IEP or IPython. 54 app.Create() 55 m = MainWindow() 56 app.Run() 57 58else: 59 # The native way. 60 m = MainWindow() 61 fltk.Fl.run() 62