diff --git a/appJar/appjar.py b/appJar/appjar.py index 4a188f8..7b920b4 100755 --- a/appJar/appjar.py +++ b/appJar/appjar.py @@ -178,6 +178,7 @@ def CENTER(win): PIECHART = 15 PROPERTIES = 16 GRID = 17 + PLOTS = 18 RB = 60 CB = 40 @@ -562,6 +563,7 @@ def __initArrays(self): self.n_tbButts = {} self.n_spins = {} self.n_props = {} + self.n_plots = {} self.n_options = {} self.n_frameLabs = {} self.n_textAreas = {} @@ -1377,6 +1379,8 @@ def __getItems(self, kind): return self.n_pieCharts elif kind == self.PROPERTIES: return self.n_props + elif kind == self.PLOTS: + return self.n_plots elif kind == self.GRID: return self.n_grids @@ -3409,6 +3413,47 @@ def setOptionBox(self, title, index, value=True): var.set("") self.warn("No items to select from: " + title) +##################################### +# FUNCTION for matplotlib +##################################### + def addPlot( + self, + title, + t, s, + row=None, + column=0, + colspan=0, + rowspan=0): + self.__verifyItem(self.n_plots, title, True) + + from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg + from matplotlib.figure import Figure + + fig = Figure() + + axes = fig.add_subplot(111) + axes.plot(t,s) + + canvas = FigureCanvasTkAgg(fig, self.__getContainer()) + canvas.fig = fig + canvas.axes = axes + canvas.show() +# canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1) + canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1) + + self.__positionWidget(canvas.get_tk_widget(), row, column, colspan, rowspan) + self.n_plots[title] = canvas + return axes + + def updatePlot(self, title, t, s): + canvas = self.__verifyItem(self.n_plots, title) + + axes = canvas.axes + axes.clear() + axes.plot(t, s) +# canvas.draw() + + ##################################### # FUNCTION to manage Properties Widgets ##################################### diff --git a/examples/plot.py b/examples/plot.py new file mode 100644 index 0000000..09c3b48 --- /dev/null +++ b/examples/plot.py @@ -0,0 +1,23 @@ +#import matplotlib +#matplotlib.use('TkAgg') +from numpy import arange, sin, pi +import sys +sys.path.append("../") +from appJar import gui + +def press(btn): + t = arange(0.2, 12.0, 0.01) + s = sin(4*pi*t) + app.updatePlot("p1", t, s) + +t = arange(0.0, 3.0, 0.01) +s = sin(2*pi*t) + +app = gui() +app.startLabelFrame("MatPlotLib") +app.addLabel("l1", "Welcome to MatPlotLib") +axes = app.addPlot("p1", t, s) +axes.legend(['some stuff']) +app.addButtons(["Quit", "Open", "Close"], press) +app.stopLabelFrame() +app.go()