Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activity.py88
-rw-r--r--activity/activity.info1
-rw-r--r--pycha/__init__.pyobin178 -> 178 bytes
-rw-r--r--pycha/bar.pyobin11625 -> 11625 bytes
-rw-r--r--pycha/chart.pyobin24966 -> 24966 bytes
-rw-r--r--pycha/color.pyobin5806 -> 5806 bytes
-rw-r--r--pycha/pie.pyobin10925 -> 10925 bytes
-rw-r--r--pycha/utils.pyobin704 -> 704 bytes
8 files changed, 78 insertions, 11 deletions
diff --git a/activity.py b/activity.py
index 9a69e34..4299f02 100644
--- a/activity.py
+++ b/activity.py
@@ -175,7 +175,7 @@ class SimpleGraph(activity.Activity):
self.box.pack_start(self.scroll, True, True, 0)
- self.options = Options()
+ self.options = Options(self)
self.options.connect("hlabel-changed", self.set_h_label)
self.options.connect("vlabel-changed", self.set_v_label)
@@ -194,9 +194,9 @@ class SimpleGraph(activity.Activity):
self.show_all()
- def add_value(self, widget):
- self.labels_and_values.add_value("Unknown", "0")
- self.chart_data.append(("Unknown", "0"))
+ def add_value(self, widget, label="Unknown", value="0.0"):
+ self.labels_and_values.add_value(label, value)
+ self.chart_data.append((label, float(value)))
def remove_value(self, widget):
path = self.labels_and_values.remove_selected_value()
@@ -263,7 +263,9 @@ class SimpleGraph(activity.Activity):
datastore.write(jobject)
def write_file(self, file_path):
+ self.metadata['mime_type'] = "activity/x-simplegraph"
if self.current_chart:
+
jfile = open(file_path, "w")
jfile.write(self.metadata["title"] + "\n")
@@ -271,19 +273,74 @@ class SimpleGraph(activity.Activity):
jfile.write(self.y_label + "\n")
jfile.write(self.chart_color + "\n")
jfile.write(self.chart_line_color + "\n")
- jfile.write(self.current_chart.type + "\n")
string = ""
for item in self.chart_data:
- print "Saving: %s : %s" % (item[0], str(item[-1]))
string += item[0] + ":" + str(item[1]) + ","
jfile.write(string)
+ jfile.write("\n" + self.current_chart.type)
jfile.close()
def read_file(self, file_path):
- print file_path
+ jfile = open(file_path, "r")
+
+ num = 0
+ type = None
+
+ for line in jfile.readlines():
+ num += 1
+
+ num2 = 0
+ l = len(line)
+ string = ""
+
+ for char in line:
+ num2 += 1
+
+ if num2 != l:
+ string += char
+
+ line = string
+
+ if num == 1:
+ self.metadata["title"] = line
+
+ elif num == 2:
+ self.options.hlabel_entry.set_text(line)
+ self.x_label = line
+
+ elif num == 3:
+ self.options.vlabel_entry.set_text(line)
+ self.y_label = line
+
+ elif num == 4:
+ self.chart_color = line
+ self.options.chart_color.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(line))
+ self.options.chart_color.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(line))
+
+ elif num == 5:
+ self.chart_line_color = line
+ self.options.lines_color.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(line))
+ self.options.lines_color.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(line))
+
+ elif num == 6:
+ for x in line.split(","):
+ try:
+ data = x.split(":")
+ label = data[0]
+ value = float(data[1])
+ if data != ('',):
+ self.add_value(None, label=label, value=value)
+ except: pass
+
+ elif num == 7:
+ type = line
+
+ self.add_chart_cb(None, type=type)
+
+ jfile.close()
class TreeView(gtk.TreeView):
@@ -376,7 +433,7 @@ class Options(gtk.VBox):
'chart-color-changed': (gobject.SIGNAL_RUN_FIRST, None, [object]),
'line-color-changed': (gobject.SIGNAL_RUN_FIRST, None, [object])}
- def __init__(self):
+ def __init__(self, activity):
gtk.VBox.__init__(self)
hbox = gtk.HBox()
@@ -388,6 +445,8 @@ class Options(gtk.VBox):
w.get_text()))
hbox.pack_end(entry, False, True, 5)
+ self.hlabel_entry = entry
+
self.pack_start(hbox, False, True, 3)
hbox = gtk.HBox()
@@ -401,6 +460,8 @@ class Options(gtk.VBox):
self.pack_start(hbox, False, True, 3)
+ self.vlabel_entry = entry
+
hbox = gtk.HBox()
title = gtk.Label("Chart color:")
hbox.pack_start(title, False, True, 0)
@@ -414,6 +475,8 @@ class Options(gtk.VBox):
self.pack_start(hbox, False, True, 3)
+ self.chart_color = btn
+
hbox = gtk.HBox()
title = gtk.Label("Lines Color:")
hbox.pack_start(title, False, True, 0)
@@ -430,6 +493,10 @@ class Options(gtk.VBox):
self.pack_start(hbox, False, True, 3)
+ self.lines_color = btn
+
+ self.activity = activity
+
self.show_all()
def color_selector(self, widget):
@@ -452,10 +519,9 @@ class Options(gtk.VBox):
box.pack_start(btn, False, True, 1)
selector.vbox.pack_end(box, False, True, 0)
- selector.colorsel.set_current_color(COLOR1)
-
+ selector.colorsel.set_current_color(gtk.gdk.Color(self.activity.chart_color))
elif widget.id == 2:
- selector.colorsel.set_current_color(COLOR2)
+ selector.colorsel.set_current_color(gtk.gdk.Color(self.activity.chart_line_color))
selector.get_color_selection().connect("color-changed",
self.color_changed, widget)
diff --git a/activity/activity.info b/activity/activity.info
index dd799bd..aefd071 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -5,3 +5,4 @@ bundle_id = org.sugarlabs.SimpleGraph
exec = sugar-activity activity.SimpleGraph -s
icon = simplegraph
license = GPLv3+
+mime_types = activity/x-simplegraph
diff --git a/pycha/__init__.pyo b/pycha/__init__.pyo
index 13b2904..6bdfe9a 100644
--- a/pycha/__init__.pyo
+++ b/pycha/__init__.pyo
Binary files differ
diff --git a/pycha/bar.pyo b/pycha/bar.pyo
index 17f639b..3f19e48 100644
--- a/pycha/bar.pyo
+++ b/pycha/bar.pyo
Binary files differ
diff --git a/pycha/chart.pyo b/pycha/chart.pyo
index 2c5f9d6..7488513 100644
--- a/pycha/chart.pyo
+++ b/pycha/chart.pyo
Binary files differ
diff --git a/pycha/color.pyo b/pycha/color.pyo
index 5180355..3f791e7 100644
--- a/pycha/color.pyo
+++ b/pycha/color.pyo
Binary files differ
diff --git a/pycha/pie.pyo b/pycha/pie.pyo
index 82ef04d..b39c552 100644
--- a/pycha/pie.pyo
+++ b/pycha/pie.pyo
Binary files differ
diff --git a/pycha/utils.pyo b/pycha/utils.pyo
index d296291..c64405d 100644
--- a/pycha/utils.pyo
+++ b/pycha/utils.pyo
Binary files differ