Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamie Boisture <jboisture@nevada.gctaa.net>2009-06-08 15:30:22 (GMT)
committer Jamie Boisture <jboisture@nevada.gctaa.net>2009-06-08 15:30:22 (GMT)
commitdc5f3984bd9e739fedf72e68b5123ffd8c7100f3 (patch)
treecc94cdf95e504e26fb5e42c4525434f2ab39042d
This is the initial commit for the Grapher activityHEADmaster
-rwxr-xr-xGrapherActivity-sugarized.py354
-rwxr-xr-xGrapherActivity-sugarized.pycbin0 -> 10987 bytes
-rwxr-xr-xGrapherActivity-sugarized.py~355
-rwxr-xr-xMANIFEST~7
-rwxr-xr-xactivity/activity-grapher.sugar.svg10
-rwxr-xr-xactivity/activity-grapher.svg21
-rwxr-xr-xactivity/activity.info8
-rwxr-xr-xgraphs.py256
-rwxr-xr-xgraphs.pycbin0 -> 11547 bytes
-rwxr-xr-xmanifest5
-rwxr-xr-xsetup.py4
11 files changed, 1020 insertions, 0 deletions
diff --git a/GrapherActivity-sugarized.py b/GrapherActivity-sugarized.py
new file mode 100755
index 0000000..4fa63b6
--- /dev/null
+++ b/GrapherActivity-sugarized.py
@@ -0,0 +1,354 @@
+import logging
+from sugar.activity import activity
+import pygtk
+pygtk.require('2.0')
+import gtk
+import cairo
+import graphs as graph
+import math
+
+
+class GrapherActivity(activity.Activity):
+ def delete_event(self, widget, event, data=None):
+ print "delete event occurred"
+ return False
+
+ def destroy(self, widget, data=None):
+ print "destroy signal occurred"
+ gtk.main_quit()
+
+
+ def __init__(self,handle):
+ activity.Activity.__init__(self,handle)
+ self.set_title('Grapher Activity')
+ self.buildGUI()
+
+ self.graphs = {"Function": [],
+ "Polar": [],
+ "Parametric": []}
+
+ self.Graphs = []
+
+
+
+ self.settings = {"degrees": False,
+ "width": 3*self.X/4,
+ "height": self.Y,
+ "xmin": -10,
+ "xmax": 10,
+ "ymin": -10,
+ "ymax": 10,
+ "thetamin" : 0,
+ "thetamax" : 2*math.pi,
+ "tmin": -10,
+ "tmax": 10,
+ "points": 1000,
+ "mode": "Polar"}
+ self.axis = graph.Axis(self.settings)
+
+ gtk.main()
+
+
+ def buildGUI(self):
+ self.X = self.window.get_screen().get_width()
+ self.Y = self.window.get_screen().get_height()
+
+ self.table = gtk.Table(2,2)
+ self.table.show()
+
+ self.drawing_area = gtk.DrawingArea()
+ self.table.attach(self.drawing_area,0,1,0,2)
+ self.drawing_area.set_size_request(3*self.X/4, self.Y)
+ self.drawing_area.show()
+ self.drawing_area.connect("expose_event", self.expose)
+
+
+ #creat the settings panel
+ frame = gtk.Frame("Settings")
+ self.table.attach(frame,1,2,1,2)
+ frame.show()
+ frame.set_size_request(self.X/4,self.Y/2)
+ settings_table = gtk.Table(2,12,False)
+ frame.add(settings_table)
+ settings_table.show()
+ self.Xminlabel = gtk.Label("X Min")
+ self.Xmaxlabel = gtk.Label("X Max")
+ self.Yminlabel = gtk.Label("Y Min")
+ self.Ymaxlabel = gtk.Label("Y Max")
+ self.Thetaminlabel = gtk.Label("Theta Min")
+ self.Thetamaxlabel = gtk.Label("Theta Max")
+ self.Tminlabel = gtk.Label("T Min")
+ self.Tmaxlabel = gtk.Label("T Max")
+ self.numPointslabel = gtk.Label("Number of Points")
+ settings_table.attach(self.Xminlabel,0,1,0,1)
+ settings_table.attach(self.Xmaxlabel,0,1,1,2)
+ settings_table.attach(self.Yminlabel,0,1,2,3)
+ settings_table.attach(self.Ymaxlabel,0,1,3,4)
+ settings_table.attach(self.Thetaminlabel,0,1,4,5)
+ settings_table.attach(self.Thetamaxlabel,0,1,5,6)
+ settings_table.attach(self.Tminlabel,0,1,6,7)
+ settings_table.attach(self.Tmaxlabel,0,1,7,8)
+ settings_table.attach(self.numPointslabel,0,1,8,9)
+ self.Xminlabel.show()
+ self.Xmaxlabel.show()
+ self.Yminlabel.show()
+ self.Ymaxlabel.show()
+ self.numPointslabel.show()
+
+ self.Xmin = gtk.Entry()
+ self.Xmax = gtk.Entry()
+ self.Ymin = gtk.Entry()
+ self.Ymax = gtk.Entry()
+ self.Thetamin = gtk.Entry()
+ self.Thetamax = gtk.Entry()
+ self.Tmin = gtk.Entry()
+ self.Tmax = gtk.Entry()
+ self.numPoints = gtk.Entry()
+ self.Xmin.set_text("-10")
+ self.Xmax.set_text("10")
+ self.Ymin.set_text("-10")
+ self.Ymax.set_text("10")
+ self.Thetamin.set_text("0")
+ self.Thetamax.set_text("6.283")
+ self.Tmin.set_text("-10")
+ self.Tmax.set_text("10")
+ self.numPoints.set_text("600")
+ settings_table.attach(self.Xmin,1,2,0,1)
+ settings_table.attach(self.Xmax,1,2,1,2)
+ settings_table.attach(self.Ymin,1,2,2,3)
+ settings_table.attach(self.Ymax,1,2,3,4)
+ settings_table.attach(self.Thetamin,1,2,4,5)
+ settings_table.attach(self.Thetamax,1,2,5,6)
+ settings_table.attach(self.Tmin,1,2,6,7)
+ settings_table.attach(self.Tmax,1,2,7,8)
+ settings_table.attach(self.numPoints,1,2,8,9)
+ self.Xmin.show()
+ self.Xmax.show()
+ self.Ymin.show()
+ self.Ymax.show()
+ self.numPoints.show()
+ self.Thetamin.hide()
+ self.Thetamax.hide()
+ self.Thetaminlabel.hide()
+ self.Thetamaxlabel.hide()
+ self.radians = gtk.CheckButton("Radians")
+ self.degrees = gtk.CheckButton("Degrees")
+ settings_table.attach(self.radians,0,1,9,10)
+ settings_table.attach(self.degrees,1,2,9,10)
+ self.radians.show()
+ self.degrees.show()
+ self.degrees.set_active(True)
+ self.radians.connect("toggled",self.radians_clicked)
+ self.degrees.connect("toggled",self.degrees_clicked)
+
+ self.grapherButton = gtk.Button("Graph")
+ settings_table.attach(self.grapherButton,0,2,10,12)
+ self.grapherButton.show()
+ self.grapherButton.connect("clicked", self.expose, None)
+
+ self.notebook = gtk.Notebook()
+ self.table.attach(self.notebook,1,2,0,1)
+ self.notebook.set_size_request(self.X/4,self.Y/2)
+ self.notebook.show()
+ self.notebook.connect("switch-page", self.mode_changed, None)
+
+ #Creat Function Notebook page
+ self.func_table = gtk.Table(2,5,False)
+ label = gtk.Label("Function")
+ self.notebook.append_page(self.func_table,label)
+ label.show()
+ self.func_table.show()
+ self.FunctionTexts = []
+ i = 0
+ while i < 5:
+ label = gtk.Label("Y"+str(i+1)+" = ")
+ self.func_table.attach(label,0,1,i,i+1)
+ label.show()
+ textbox = gtk.Entry()
+ self.FunctionTexts.append(textbox)
+ self.func_table.attach(textbox,1,2,i,i+1)
+ textbox.show()
+ i+= 1
+
+
+ #Creat Polar Notebook page
+ self.polar_table = gtk.Table(2,8,False)
+ label = gtk.Label("Polar")
+ self.notebook.append_page(self.polar_table,label)
+ label.show()
+ self.polar_table.show()
+ self.PolarTexts = []
+ i = 0
+ while i < 5:
+ label = gtk.Label("R"+str(i+1)+" = ")
+ self.polar_table.attach(label,0,1,i,i+1)
+ label.show()
+ textbox = gtk.Entry()
+ self.PolarTexts.append(textbox)
+ self.polar_table.attach(textbox,1,2,i,i+1)
+ textbox.show()
+ i+= 1
+
+
+ #Creat Parametric Notebook page
+ self.parametric_table = gtk.Table(2,8,False)
+ label = gtk.Label("Parametric")
+ self.notebook.append_page(self.parametric_table,label)
+ label.show()
+ self.parametric_table.show()
+ self.ParametricTexts = []
+ i = 0
+ while i < 4:
+ label1 = gtk.Label("X"+str(i+1)+" = ")
+ label2 = gtk.Label("Y"+str(i+1)+" = ")
+ self.parametric_table.attach(label1,0,1,2*i,2*i+1)
+ self.parametric_table.attach(label2,0,1,2*i+1,2*i+2)
+ label1.show()
+ label2.show()
+ textboxX = gtk.Entry()
+ textboxY = gtk.Entry()
+ self.ParametricTexts.append((textboxX,textboxY))
+ self.parametric_table.attach(textboxX,1,2,2*i,2*i+1)
+ self.parametric_table.attach(textboxY,1,2,2*i+1,2*i+2)
+ textboxX.show()
+ textboxY.show()
+ i+= 1
+ self.set_canvas(self.table)
+ self.show_all()
+
+
+
+
+ def graph_clicked(self, widget=None, data=None):
+ self.grapher()
+
+ def grapher(self):
+ self.Graphs = []
+ self.update_settings()
+ self.update_graphs()
+ self.axis = graph.Axis(self.settings)
+ num = 0
+ if self.settings["mode"] == "Function":
+ for g in self.graphs["Function"]:
+ self.Graphs.append(graph.FunctionGraph(g, self.settings, num))
+ num += 1
+ if self.settings["mode"] == "Polar":
+ for g in self.graphs["Polar"]:
+ self.Graphs.append(graph.PolarGraph(g, self.settings, num))
+ num += 1
+ if self.settings["mode"] == "Parametric":
+ for g in self.graphs["Parametric"]:
+ self.Graphs.append(graph.ParametricGraph(g[0],g[1], self.settings, num))
+ num += 1
+ self.axis.draw(self.context)
+ for g in self.Graphs:
+ g.draw(self.context)
+
+
+
+
+ def mode_changed(self, notebook, page, page_num, data):
+ if page_num == 0:
+ self.Thetamin.hide()
+ self.Thetamax.hide()
+ self.Thetaminlabel.hide()
+ self.Thetamaxlabel.hide()
+ self.Tmin.hide()
+ self.Tmax.hide()
+ self.Tminlabel.hide()
+ self.Tmaxlabel.hide()
+ if page_num == 1:
+ self.Thetamin.show()
+ self.Thetamax.show()
+ self.Thetaminlabel.show()
+ self.Thetamaxlabel.show()
+ self.Tmin.hide()
+ self.Tmax.hide()
+ self.Tminlabel.hide()
+ self.Tmaxlabel.hide()
+ if page_num == 2:
+ self.Thetamin.hide()
+ self.Thetamax.hide()
+ self.Thetaminlabel.hide()
+ self.Thetamaxlabel.hide()
+ self.Tmin.show()
+ self.Tmax.show()
+ self.Tminlabel.show()
+ self.Tmaxlabel.show()
+
+ def update_settings(self):
+ self.settings["xmin"] = float(self.Xmin.get_text())
+ self.settings["xmax"] = float(self.Xmax.get_text())
+ self.settings["ymin"] = float(self.Ymin.get_text())
+ self.settings["ymax"] = float(self.Ymax.get_text())
+ self.settings["thetamin"] = float(self.Thetamin.get_text())
+ self.settings["thetamax"] = float(self.Thetamax.get_text())
+ self.settings["tmin"] = float(self.Tmin.get_text())
+ self.settings["tmax"] = float(self.Tmax.get_text())
+ self.settings["points"] = float(self.numPoints.get_text())
+ self.settings["degrees"] = self.degrees.get_active()
+ mode = self.notebook
+ self.settings["mode"] = mode.get_tab_label_text(mode.get_nth_page(mode.get_current_page()))
+ if self.settings["xmin"] > self.settings["xmax"]:
+ self.settings["xmax"] = 10
+ self.settings["xmin"] = -10
+ self.Xmax.set_text("10")
+ self.Xmin.set_text("-10")
+ if self.settings["ymin"] > self.settings["ymax"]:
+ self.settings["ymax"] = 10
+ self.settings["ymin"] = -10
+ self.Ymax.set_text("10")
+ self.Ymin.set_text("-10")
+
+
+ def update_graphs(self):
+ self.graphs = {"Function": [],
+ "Polar": [],
+ "Parametric": []}
+ for textBox in self.FunctionTexts:
+ graph = textBox.get_text()
+ if graph != "":
+ self.graphs["Function"].append(graph)
+ for textBox in self.PolarTexts:
+ graph = textBox.get_text()
+ if graph != "":
+ self.graphs["Polar"].append(graph)
+ for textBoxs in self.ParametricTexts:
+ Xgraph = textBoxs[0].get_text()
+ Ygraph = textBoxs[1].get_text()
+ if Xgraph != "" and Ygraph != "":
+ self.graphs["Parametric"].append([Xgraph, Ygraph])
+
+ def radians_clicked(self, data):
+ value = self.radians.get_active()
+ if value:
+ self.degrees.set_active(False)
+ else:
+ self.degrees.set_active(True)
+
+ def degrees_clicked(self, data):
+ value = self.degrees.get_active()
+ if value:
+ self.radians.set_active(False)
+ else:
+ self.radians.set_active(True)
+
+
+ def expose(self, widget, event):
+ self.context = self.drawing_area.window.cairo_create()
+ # set a clip region for the expose event
+ self.context.rectangle(0, 0,
+ *self.drawing_area.window.get_size())
+ self.context.clip()
+ self.context.set_source_rgb(1, 1, 1)
+ self.context.rectangle(0, 0, *self.drawing_area.window.get_size())
+ self.context.fill()
+ self.context.set_source_rgb(0, 0, 0)
+
+
+ self.grapher()
+
+ return False
+
+
+
diff --git a/GrapherActivity-sugarized.pyc b/GrapherActivity-sugarized.pyc
new file mode 100755
index 0000000..0029663
--- /dev/null
+++ b/GrapherActivity-sugarized.pyc
Binary files differ
diff --git a/GrapherActivity-sugarized.py~ b/GrapherActivity-sugarized.py~
new file mode 100755
index 0000000..c69b721
--- /dev/null
+++ b/GrapherActivity-sugarized.py~
@@ -0,0 +1,355 @@
+import logging
+from sugar.activity import activity
+import pygtk
+pygtk.require('2.0')
+import gtk
+import cairo
+import graphs as graph
+import math
+X = 1200
+Y = 900
+
+
+class GrapherActivity(activity.Activity):
+ def delete_event(self, widget, event, data=None):
+ print "delete event occurred"
+ return False
+
+ def destroy(self, widget, data=None):
+ print "destroy signal occurred"
+ gtk.main_quit()
+
+
+ def __init__(self,handle):
+ activity.Activity.__init__(self,handle)
+ self.set_title('Logic Circuits Activity')
+ self.buildGUI()
+
+ self.graphs = {"Function": [],
+ "Polar": [],
+ "Parametric": []}
+
+ self.Graphs = []
+
+
+
+ self.settings = {"degrees": False,
+ "width": 900,
+ "height": 900,
+ "xmin": -10,
+ "xmax": 10,
+ "ymin": -10,
+ "ymax": 10,
+ "thetamin" : 0,
+ "thetamax" : 2*math.pi,
+ "tmin": -10,
+ "tmax": 10,
+ "points": 1000,
+ "mode": "Polar"}
+ self.axis = graph.Axis(self.settings)
+
+ gtk.main()
+
+
+ def buildGUI(self):
+ self.hpaned = gtk.HPaned()
+
+ self.drawing_area = gtk.DrawingArea()
+ self.hpaned.add1(self.drawing_area)
+ self.drawing_area.set_size_request(3*X/4, Y)
+ self.drawing_area.show()
+ self.drawing_area.connect("expose_event", self.expose)
+
+ self.vpaned = gtk.VPaned()
+ self.hpaned.add2(self.vpaned)
+ self.vpaned.show()
+
+ #creat the settings panel
+ frame = gtk.Frame("Settings")
+ self.vpaned.add2(frame)
+ frame.show()
+ settings_table = gtk.Table(2,12,False)
+ frame.add(settings_table)
+ settings_table.show()
+ self.Xminlabel = gtk.Label("X Min")
+ self.Xmaxlabel = gtk.Label("X Max")
+ self.Yminlabel = gtk.Label("Y Min")
+ self.Ymaxlabel = gtk.Label("Y Max")
+ self.Thetaminlabel = gtk.Label("Theta Min")
+ self.Thetamaxlabel = gtk.Label("Theta Max")
+ self.Tminlabel = gtk.Label("T Min")
+ self.Tmaxlabel = gtk.Label("T Max")
+ self.numPointslabel = gtk.Label("Number of Points")
+ settings_table.attach(self.Xminlabel,0,1,0,1)
+ settings_table.attach(self.Xmaxlabel,0,1,1,2)
+ settings_table.attach(self.Yminlabel,0,1,2,3)
+ settings_table.attach(self.Ymaxlabel,0,1,3,4)
+ settings_table.attach(self.Thetaminlabel,0,1,4,5)
+ settings_table.attach(self.Thetamaxlabel,0,1,5,6)
+ settings_table.attach(self.Tminlabel,0,1,6,7)
+ settings_table.attach(self.Tmaxlabel,0,1,7,8)
+ settings_table.attach(self.numPointslabel,0,1,8,9)
+ self.Xminlabel.show()
+ self.Xmaxlabel.show()
+ self.Yminlabel.show()
+ self.Ymaxlabel.show()
+ self.numPointslabel.show()
+
+ self.Xmin = gtk.Entry()
+ self.Xmax = gtk.Entry()
+ self.Ymin = gtk.Entry()
+ self.Ymax = gtk.Entry()
+ self.Thetamin = gtk.Entry()
+ self.Thetamax = gtk.Entry()
+ self.Tmin = gtk.Entry()
+ self.Tmax = gtk.Entry()
+ self.numPoints = gtk.Entry()
+ self.Xmin.set_text("-10")
+ self.Xmax.set_text("10")
+ self.Ymin.set_text("-10")
+ self.Ymax.set_text("10")
+ self.Thetamin.set_text("0")
+ self.Thetamax.set_text("6.283")
+ self.Tmin.set_text("-10")
+ self.Tmax.set_text("-10")
+ self.numPoints.set_text("600")
+ settings_table.attach(self.Xmin,1,2,0,1)
+ settings_table.attach(self.Xmax,1,2,1,2)
+ settings_table.attach(self.Ymin,1,2,2,3)
+ settings_table.attach(self.Ymax,1,2,3,4)
+ settings_table.attach(self.Thetamin,1,2,4,5)
+ settings_table.attach(self.Thetamax,1,2,5,6)
+ settings_table.attach(self.Tmin,1,2,6,7)
+ settings_table.attach(self.Tmax,1,2,7,8)
+ settings_table.attach(self.numPoints,1,2,8,9)
+ self.Xmin.show()
+ self.Xmax.show()
+ self.Ymin.show()
+ self.Ymax.show()
+ self.numPoints.show()
+ self.Thetamin.hide()
+ self.Thetamax.hide()
+ self.Thetaminlabel.hide()
+ self.Thetamaxlabel.hide()
+ self.radians = gtk.CheckButton("Radians")
+ self.degrees = gtk.CheckButton("Degrees")
+ settings_table.attach(self.radians,0,1,9,10)
+ settings_table.attach(self.degrees,1,2,9,10)
+ self.radians.show()
+ self.degrees.show()
+ self.degrees.set_active(True)
+ self.radians.connect("toggled",self.radians_clicked)
+ self.degrees.connect("toggled",self.degrees_clicked)
+
+ self.grapherButton = gtk.Button("Graph")
+ settings_table.attach(self.grapherButton,0,2,10,12)
+ self.grapherButton.show()
+ self.grapherButton.connect("clicked", self.expose, None)
+
+ self.notebook = gtk.Notebook()
+ self.vpaned.add1(self.notebook)
+ self.notebook.set_size_request(X/4,400)
+ self.notebook.show()
+ self.notebook.connect("switch-page", self.mode_changed, None)
+
+
+ #Creat Function Notebook page
+ self.func_table = gtk.Table(2,5,False)
+ label = gtk.Label("Function")
+ self.notebook.append_page(self.func_table,label)
+ label.show()
+ self.func_table.show()
+ self.FunctionTexts = []
+ i = 0
+ while i < 5:
+ label = gtk.Label("Y"+str(i+1)+" = ")
+ self.func_table.attach(label,0,1,i,i+1)
+ label.show()
+ textbox = gtk.Entry()
+ self.FunctionTexts.append(textbox)
+ self.func_table.attach(textbox,1,2,i,i+1)
+ textbox.show()
+ i+= 1
+
+
+ #Creat Polar Notebook page
+ self.polar_table = gtk.Table(2,8,False)
+ label = gtk.Label("Polar")
+ self.notebook.append_page(self.polar_table,label)
+ label.show()
+ self.polar_table.show()
+ self.PolarTexts = []
+ i = 0
+ while i < 5:
+ label = gtk.Label("R"+str(i+1)+" = ")
+ self.polar_table.attach(label,0,1,i,i+1)
+ label.show()
+ textbox = gtk.Entry()
+ self.PolarTexts.append(textbox)
+ self.polar_table.attach(textbox,1,2,i,i+1)
+ textbox.show()
+ i+= 1
+
+
+ #Creat Parametric Notebook page
+ self.parametric_table = gtk.Table(2,8,False)
+ label = gtk.Label("Parametric")
+ self.notebook.append_page(self.parametric_table,label)
+ label.show()
+ self.parametric_table.show()
+ self.ParametricTexts = []
+ i = 0
+ while i < 4:
+ label1 = gtk.Label("X"+str(i+1)+" = ")
+ label2 = gtk.Label("Y"+str(i+1)+" = ")
+ self.parametric_table.attach(label1,0,1,2*i,2*i+1)
+ self.parametric_table.attach(label2,0,1,2*i+1,2*i+2)
+ label1.show()
+ label2.show()
+ textboxX = gtk.Entry()
+ textboxY = gtk.Entry()
+ self.ParametricTexts.append((textboxX,textboxY))
+ self.parametric_table.attach(textboxX,1,2,2*i,2*i+1)
+ self.parametric_table.attach(textboxY,1,2,2*i+1,2*i+2)
+ textboxX.show()
+ textboxY.show()
+ i+= 1
+ self.x = 10
+ self.set_canvas(self.hpaned)
+ self.show_all()
+
+
+
+
+ def graph_clicked(self, widget=None, data=None):
+ self.grapher()
+
+ def grapher(self):
+ self.Graphs = []
+ self.update_settings()
+ self.update_graphs()
+ self.axis = graph.Axis(self.settings)
+ num = 0
+ if self.settings["mode"] == "Function":
+ for g in self.graphs["Function"]:
+ self.Graphs.append(graph.FunctionGraph(g, self.settings, num))
+ num += 1
+ if self.settings["mode"] == "Polar":
+ for g in self.graphs["Polar"]:
+ self.Graphs.append(graph.PolarGraph(g, self.settings, num))
+ num += 1
+ if self.settings["mode"] == "Parametric":
+ for g in self.graphs["Parametric"]:
+ self.Graphs.append(graph.ParametricGraph(g[0],g[1], self.settings, num))
+ num += 1
+ self.axis.draw(self.context)
+ for g in self.Graphs:
+ g.draw(self.context)
+
+
+
+
+ def mode_changed(self, notebook, page, page_num, data):
+ if page_num == 0:
+ self.Thetamin.hide()
+ self.Thetamax.hide()
+ self.Thetaminlabel.hide()
+ self.Thetamaxlabel.hide()
+ self.Tmin.hide()
+ self.Tmax.hide()
+ self.Tminlabel.hide()
+ self.Tmaxlabel.hide()
+ if page_num == 1:
+ self.Thetamin.show()
+ self.Thetamax.show()
+ self.Thetaminlabel.show()
+ self.Thetamaxlabel.show()
+ self.Tmin.hide()
+ self.Tmax.hide()
+ self.Tminlabel.hide()
+ self.Tmaxlabel.hide()
+ if page_num == 2:
+ self.Thetamin.hide()
+ self.Thetamax.hide()
+ self.Thetaminlabel.hide()
+ self.Thetamaxlabel.hide()
+ self.Tmin.show()
+ self.Tmax.show()
+ self.Tminlabel.show()
+ self.Tmaxlabel.show()
+
+ def update_settings(self):
+ self.settings["xmin"] = float(self.Xmin.get_text())
+ self.settings["xmax"] = float(self.Xmax.get_text())
+ self.settings["ymin"] = float(self.Ymin.get_text())
+ self.settings["ymax"] = float(self.Ymax.get_text())
+ self.settings["thetamin"] = float(self.Thetamin.get_text())
+ self.settings["thetamax"] = float(self.Thetamax.get_text())
+ self.settings["tmin"] = float(self.Tmin.get_text())
+ self.settings["tmax"] = float(self.Tmax.get_text())
+ self.settings["points"] = float(self.numPoints.get_text())
+ self.settings["degrees"] = self.degrees.get_active()
+ mode = self.notebook
+ self.settings["mode"] = mode.get_tab_label_text(mode.get_nth_page(mode.get_current_page()))
+ if self.settings["xmin"] > self.settings["xmax"]:
+ self.settings["xmax"] = 10
+ self.settings["xmin"] = -10
+ self.Xmax.set_text("10")
+ self.Xmin.set_text("-10")
+ if self.settings["ymin"] > self.settings["ymax"]:
+ self.settings["ymax"] = 10
+ self.settings["ymin"] = -10
+ self.Ymax.set_text("10")
+ self.Ymin.set_text("-10")
+
+
+ def update_graphs(self):
+ self.graphs = {"Function": [],
+ "Polar": [],
+ "Parametric": []}
+ for textBox in self.FunctionTexts:
+ graph = textBox.get_text()
+ if graph != "":
+ self.graphs["Function"].append(graph)
+ for textBox in self.PolarTexts:
+ graph = textBox.get_text()
+ if graph != "":
+ self.graphs["Polar"].append(graph)
+ for textBoxs in self.ParametricTexts:
+ Xgraph = textBoxs[0].get_text()
+ Ygraph = textBoxs[1].get_text()
+ if Xgraph != "" and Ygraph != "":
+ self.graphs["Parametric"].append([Xgraph, Ygraph])
+
+ def radians_clicked(self, data):
+ value = self.radians.get_active()
+ if value:
+ self.degrees.set_active(False)
+ else:
+ self.degrees.set_active(True)
+
+ def degrees_clicked(self, data):
+ value = self.degrees.get_active()
+ if value:
+ self.radians.set_active(False)
+ else:
+ self.radians.set_active(True)
+
+ def expose(self, widget, event):
+ self.context = self.drawing_area.window.cairo_create()
+ # set a clip region for the expose event
+ self.context.rectangle(0, 0,
+ *self.drawing_area.window.get_size())
+ self.context.clip()
+ self.context.set_source_rgb(1, 1, 1)
+ self.context.rectangle(0, 0, *self.drawing_area.window.get_size())
+ self.context.fill()
+ self.context.set_source_rgb(0, 0, 0)
+
+
+ self.grapher()
+
+ return False
+
+
+
diff --git a/MANIFEST~ b/MANIFEST~
new file mode 100755
index 0000000..0a0747c
--- /dev/null
+++ b/MANIFEST~
@@ -0,0 +1,7 @@
+GrapherActivity.py
+setup.py
+Grapher.glade
+graphs.py
+main.py
+activity/activity-grapher.svg
+activity/activity.info
diff --git a/activity/activity-grapher.sugar.svg b/activity/activity-grapher.sugar.svg
new file mode 100755
index 0000000..1bcac3b
--- /dev/null
+++ b/activity/activity-grapher.sugar.svg
@@ -0,0 +1,10 @@
+<?xml version="1.0" ?><!-- Created with Inkscape (http://www.inkscape.org/) --><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
+ <!ENTITY stroke_color "#666666">
+ <!ENTITY fill_color "#ffffff">
+]><svg height="6cm" id="svg3231" style="" version="1.0" viewBox="0 0 500 500" width="6cm" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
+ <defs id="defs3237" style=""/>
+ <g style="fill:&fill_color;;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:20px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1">
+ <path d="M 48.921569,270.49019 C 148.92156,470.49019 248.92156,270.49019 248.92156,270.49019 C 348.92156,70.490194 448.92156,270.49019 448.92156,270.49019 M 55.948516,433.07109 C 254.31372,-285.23411 452.67893,433.07109 452.67893,433.07109" id="path3758" style=""/>
+ <path d="M 247.45098,39.34021 L 247.45098,467.22841 M 489.52574,270.98039 L 13.219357,270.98039" id="path2459" style=""/>
+ </g>
+</svg> \ No newline at end of file
diff --git a/activity/activity-grapher.svg b/activity/activity-grapher.svg
new file mode 100755
index 0000000..107eab2
--- /dev/null
+++ b/activity/activity-grapher.svg
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.0"
+ width="6cm"
+ height="6cm"
+ viewBox="0 0 500 500"
+ id="svg3231">
+ <defs
+ id="defs3237" />
+ <g style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:20px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1">
+ <path
+ d="M 48.921569,270.49019 C 148.92156,470.49019 248.92156,270.49019 248.92156,270.49019 C 348.92156,70.490194 448.92156,270.49019 448.92156,270.49019 M 55.948516,433.07109 C 254.31372,-285.23411 452.67893,433.07109 452.67893,433.07109"
+ id="path3758" />
+ <path
+ d="M 247.45098,39.34021 L 247.45098,467.22841 M 489.52574,270.98039 L 13.219357,270.98039"
+ id="path2459" />
+ </g>
+</svg>
diff --git a/activity/activity.info b/activity/activity.info
new file mode 100755
index 0000000..1060da2
--- /dev/null
+++ b/activity/activity.info
@@ -0,0 +1,8 @@
+[Activity]
+name = Grapher-sugarized
+bundle_id = org.laptop.GrapherActivity-sugarized
+class = GrapherActivity-sugarized.GrapherActivity
+icon = activity-grapher.sugar
+activity_version = 1
+host_version = 1
+show_launcher = yes
diff --git a/graphs.py b/graphs.py
new file mode 100755
index 0000000..32acaa7
--- /dev/null
+++ b/graphs.py
@@ -0,0 +1,256 @@
+import cairo, math
+colors = [(1,0,0),(0,1,0),(0,0,1),(.8,.2,0),(0,.8,.3)]
+
+
+
+def ln(x):
+ try:
+ return math.log(x, math.e)
+ except:
+ return None
+def log(x, base = 10):
+ try:
+ return math.log(x, base)
+ except:
+ return None
+def sin(x):
+ if Settings["degrees"]:
+ x = math.radians(x)
+ try:
+ return math.sin(x)
+ except:
+ return None
+def cos(x):
+ if Settings["degrees"]:
+ x = math.radians(x)
+ try:
+ return math.cos(x)
+ except:
+ return None
+def tan(x):
+ if Settings["degrees"]:
+ x = math.radians(x)
+ try:
+ return math.tan(x)
+ except:
+ return None
+def csc(x):
+ if Settings["degrees"]:
+ x = math.radians(x)
+ try:
+ return 1.0/math.sin(x)
+ except:
+ return None
+def sec(x):
+ if Settings["degrees"]:
+ x = math.radians(x)
+ try:
+ return 1.0/math.cos(x)
+ except:
+ return None
+def cot(x):
+ if Settings["degrees"]:
+ x = math.radians(x)
+ try:
+ return 1.0/math.tan(x)
+ except:
+ return None
+def sqrt(x):
+ try:
+ return math.sqrt(x)
+ except:
+ return None
+
+
+
+
+def calcXpos(x, settings):
+ return float(x - settings["xmin"])/float(settings["xmax"] - settings["xmin"]) * settings["width"]
+
+def calcYpos(y, settings):
+ return settings["height"] - float(y - settings["ymin"])/float(settings["ymax"] - settings["ymin"]) * settings["height"]
+
+def calcPosFromPolar(r, theta, settings):
+ if settings["degrees"]:
+ theta = math.radians(theta)
+ x = r*math.cos(theta)
+ y = r*math.sin(theta)
+ return (calcXpos(x,settings),calcYpos(y,settings))
+
+class FunctionGraph:
+ def __init__(self, graph, settings, num):
+ self.num = num +1
+ self.graph = self.formateGraph(graph)
+ self.settings = settings
+ self.color = colors[num]
+ self.points = self.EvaluateGraph()
+
+ def formateGraph(self, graph):
+ formatedGraph = ""
+ acceptedNumbers = ["1","2","3","4","5","6","7","8","9","0"]
+ acceptedSymbols = [".",",","a","b","c","e","g","i","l","n","o","r","s","t","q","x","*","/","+","-","(",")"]
+ for s in graph:
+ if s in acceptedNumbers: formatedGraph += s
+ if s in acceptedSymbols: formatedGraph += s
+ if s == "{" or s == "[": formatedGraph += ("(")
+ if s == "}" or s == "}": formatedGraph += (")")
+ if s == "^": formatedGraph += ("**")
+ i = 0
+ while i < len(formatedGraph)-1:
+ if formatedGraph[i] in acceptedNumbers:
+ if formatedGraph[i+1] == "x":
+ i += 1
+ formatedGraph = formatedGraph[:i] + "*" + formatedGraph[i:]
+ i += 1
+ return formatedGraph
+
+ def EvaluateGraph(self):
+ graphList = []
+ inc = float(self.settings["xmax"]-self.settings["xmin"])/float(self.settings["points"])
+ x = self.settings["xmin"]
+ while x <= self.settings["xmax"] + inc:
+ y = eval(self.graph)
+ if y != None:
+ graphList.append((calcXpos(x,self.settings),calcYpos(y,self.settings)))
+ x += inc
+ return graphList
+
+ def draw(self,context):
+ context.set_source_rgb(*self.color)
+ i = 1
+ context.move_to(*self.points[0])
+ while i < len(self.points):
+ context.line_to(*self.points[i])
+ i+=1
+ context.stroke()
+
+class PolarGraph:
+ def __init__(self, graph, settings, num):
+ self.num = num +1
+ self.graph = self.formateGraph(graph)
+ self.settings = settings
+ self.color = colors[num]
+ self.points = self.EvaluateGraph()
+
+ def formateGraph(self, graph):
+ formatedGraph = ""
+ acceptedNumbers = ["1","2","3","4","5","6","7","8","9","0"]
+ acceptedSymbols = [".",",","a","b","c","e","g","i","l","n","o","r","s","t","q","x","*","/","+","-","(",")"]
+ for s in graph:
+ if s in acceptedNumbers: formatedGraph += s
+ if s in acceptedSymbols: formatedGraph += s
+ if s == "{" or s == "[": formatedGraph += ("(")
+ if s == "}" or s == "}": formatedGraph += (")")
+ if s == "^": formatedGraph += ("**")
+ i = 0
+ while i < len(formatedGraph)-1:
+ if formatedGraph[i] in acceptedNumbers:
+ if formatedGraph[i+1] == "x":
+ i += 1
+ formatedGraph = formatedGraph[:i] + "*" + formatedGraph[i:]
+ i += 1
+ return formatedGraph
+
+ def EvaluateGraph(self):
+ graphList = []
+ inc = float(self.settings["thetamax"]-self.settings["thetamin"])/float(self.settings["points"])
+ x = self.settings["thetamin"]
+ while x <= self.settings["thetamax"] + inc:
+ y = eval(self.graph)
+ if y != None:
+ graphList.append(calcPosFromPolar(y,x,self.settings))
+ x += inc
+ return graphList
+
+ def draw(self,context):
+ context.set_source_rgb(*self.color)
+ i = 1
+ context.move_to(*self.points[0])
+ while i < len(self.points):
+ context.line_to(*self.points[i])
+ i+=1
+ context.stroke()
+
+class ParametricGraph:
+ def __init__(self, graphX, graphY, settings, num):
+ self.num = num +1
+ self.graphX = self.formateGraph(graphX)
+ self.graphY = self.formateGraph(graphY)
+ self.settings = settings
+ self.color = colors[num]
+ self.points = self.EvaluateGraphs()
+
+ def formateGraph(self, graph):
+ formatedGraph = ""
+ acceptedNumbers = ["1","2","3","4","5","6","7","8","9","0"]
+ acceptedSymbols = [".","a","b","c","g","i","l","n","o","r","s","t","q","*","/","+","-","(",")"]
+ for s in graph:
+ if s in acceptedNumbers: formatedGraph += s
+ if s in acceptedSymbols: formatedGraph += s
+ if s == "{" or s == "[": formatedGraph += ("(")
+ if s == "}" or s == "}": formatedGraph += (")")
+ if s == "^": formatedGraph += ("**")
+ i = 0
+ while i < len(formatedGraph)-1:
+ if formatedGraph[i] in acceptedNumbers:
+ if formatedGraph[i+1] == "x":
+ i += 1
+ formatedGraph = formatedGraph[:i] + "*" + formatedGraph[i:]
+ i += 1
+ return formatedGraph
+
+ def EvaluateGraphs(self):
+ graphList = []
+ inc = float(self.settings["tmax"]-self.settings["tmin"])/float(self.settings["points"])
+ t = self.settings["tmin"]
+ while t <= self.settings["tmax"] + inc:
+ y = eval(self.graphY)
+ x = eval(self.graphX)
+ graphList.append((calcXpos(x,self.settings),calcYpos(y,self.settings)))
+ t += inc
+ return graphList
+
+ def draw(self,context):
+ context.set_source_rgb(*self.color)
+ i = 1
+ context.move_to(*self.points[0])
+ while i < len(self.points):
+ context.line_to(*self.points[i])
+ i+=1
+ context.stroke()
+
+class Axis:
+ def __init__(self, settings):
+ global Settings
+ Settings = settings
+ width = settings["width"]
+ height = settings["height"]
+ self.settings = settings
+ self.center = (width - width*(float(settings["xmax"])/(float(settings["xmax"]-settings["xmin"]))),
+ height*(float(settings["ymax"])/(float(settings["ymax"]-settings["ymin"]))))
+ self.x = self.center[0]
+ if self.center[0] < 0:
+ self.x = 0
+ if self.center[0] > width:
+ self.x = width
+ self.y = self.center[1]
+ if self.center[1] < 0:
+ self.y = 0
+ if self.center[1] > height:
+ self.y = height
+
+ def draw(self,context):
+ context.move_to(self.center[0],0)
+ context.line_to(self.center[0],self.settings["height"])
+ context.stroke()
+ context.move_to(0,self.center[1])
+ context.line_to(self.settings["width"],self.center[1])
+ context.stroke()
+ for x in range(int(self.settings["xmin"]), int(self.settings["xmax"])):
+ context.move_to(calcXpos(x, self.settings), self.y-5)
+ context.line_to(calcXpos(x, self.settings), self.y+5)
+ context.stroke()
+ for y in range(int(self.settings["ymin"]), int(self.settings["ymax"])):
+ context.move_to(self.x-5,calcYpos(y, self.settings))
+ context.line_to(self.x+5,calcYpos(y, self.settings))
+ context.stroke()
diff --git a/graphs.pyc b/graphs.pyc
new file mode 100755
index 0000000..aeaf8d4
--- /dev/null
+++ b/graphs.pyc
Binary files differ
diff --git a/manifest b/manifest
new file mode 100755
index 0000000..c0e7947
--- /dev/null
+++ b/manifest
@@ -0,0 +1,5 @@
+GrapherActivity.py
+setup.py
+graphs.py
+activity/activity-grapher.svg
+activity/activity.info
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..6ed89aa
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,4 @@
+#!/usr/bin/env python
+from sugar.activity import bundlebuilder
+bundlebuilder.start()
+