Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 and other fixes #11

Merged
merged 21 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[flake8]

# E402 module level import not at top of file
# gi.require_version() is required before later imports

ignore = E402, E501

#E501 line too long
#readers.py definition of TACAT, TAPAL, TASCORE can't be shortened

JuiP marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# AnalyzeJournal Activity #
AnalyzeJournal Activity
===============
This Activity charts data from the Sugar Journal and gives you a visual representation of Disk usage, Activity usage and Turtle data usage using a vertical bar chart, a horizontal bar chart or a pie chart.
JuiP marked this conversation as resolved.
Show resolved Hide resolved

This Activity charts data from the Sugar Journal:

1. free space
2. activity usage
3. turtle block usage

This activity gives you the possibility to graphically, the journal usage.

### To Know more about AnalyzeJournal and Sugar, Please refer to ###
JuiP marked this conversation as resolved.
Show resolved Hide resolved
How to use?
===============
AnalyzeJournal Activity is not a part of Sugar Desktop but can be added. Refer to the following links-

* [How to Get Sugar on sugarlabs.org](https://sugarlabs.org/)
* [How to use Sugar](https://help.sugarlabs.org/)
* [Download AnalyzeJournal](https://activities.sugarlabs.org/en-US/sugar/addon/4545)

<img src="Screenshots/2.png" width="75%" title="AnalyzeJournal Activity">

First select Disk usage, Activity usage or Turtle data (the one you wish to see the graphical represenation of) and then click on the type of chart you wish to see. You can also save the chart dispayed as an image by clicking on 'save as image'.
JuiP marked this conversation as resolved.
Show resolved Hide resolved

How to upgrade?
===============
On Sugar Desktop systems;

* [Use My Settings,](https://help.sugarlabs.org/my_settings.html) [Software Update](https://help.sugarlabs.org/my_settings.html#software-update)
* Use Browse to open [activities.sugarlabs.org](https://activities.sugarlabs.org/) Search for Paths, then download
JuiP marked this conversation as resolved.
Show resolved Hide resolved

Binary file added Screenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 40 additions & 37 deletions activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@
import logging
import utils

from StringIO import StringIO
from io import StringIO
from gettext import gettext as _

from sugar3.activity import activity
from sugar3.activity.widgets import ActivityToolbarButton
from sugar3.activity.widgets import StopButton
from sugar3.activity.widgets import ToolbarButton
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.radiotoolbutton import RadioToolButton
from sugar3.graphics.colorbutton import ColorToolButton
from sugar3.graphics.objectchooser import ObjectChooser
from sugar3.graphics.icon import Icon
from sugar3.graphics.alert import Alert
Expand All @@ -63,19 +61,23 @@

# Logging
_logger = logging.getLogger('analyze-journal-activity')
_logger.setLevel(logging.DEBUG)
logging.basicConfig()

DRAG_ACTION = Gdk.DragAction.COPY


class ChartArea(Gtk.DrawingArea):

def __init__(self, parent):
"""A class for Draw the chart"""
super(ChartArea, self).__init__()
self._parent = parent
self.add_events(Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.VISIBILITY_NOTIFY_MASK)
self.exposure = Gdk.EventMask.EXPOSURE_MASK
self.visibility = Gdk.EventMask.VISIBILITY_NOTIFY_MASK
self.add_events(self.exposure | self.visibility)
self.connect("draw", self._draw_cb)

self.drag_dest_set(Gtk.DestDefaults.ALL, [], DRAG_ACTION)
self.drag_dest_set_target_list(Gtk.TargetList.new([]))
self.drag_dest_add_text_targets()
self.connect('drag_data_received', self._drag_data_received)
Expand Down Expand Up @@ -182,6 +184,13 @@ def __init__(self, handle):
add_hbar_chart.props.group = charts_group
toolbarbox.toolbar.insert(add_hbar_chart, -1)

add_line_chart = RadioToolButton()
add_line_chart.connect("clicked", self._add_chart_cb, "line")
add_line_chart.set_tooltip(_("Line Bar Chart"))
add_line_chart.props.icon_name = "line"
add_line_chart.props.group = charts_group
toolbarbox.toolbar.insert(add_line_chart, -1)

add_pie_chart = RadioToolButton()
add_pie_chart.connect("clicked", self._add_chart_cb, "pie")
add_pie_chart.set_tooltip(_("Pie Chart"))
Expand All @@ -192,6 +201,7 @@ def __init__(self, handle):

self.chart_type_buttons = [add_vbar_chart,
add_hbar_chart,
add_line_chart,
add_pie_chart]

separator = Gtk.SeparatorToolItem()
Expand Down Expand Up @@ -228,8 +238,7 @@ def size_allocate_cb(widget, allocation):
box_width = allocation.width / 3
box.set_size_request(box_width, -1)

self._setup_handle = paned.connect('size_allocate',
size_allocate_cb)
self._setup_handle = paned.connect('size_allocate', size_allocate_cb)

scroll = Gtk.ScrolledWindow()
scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
Expand Down Expand Up @@ -373,7 +382,8 @@ def _set_chart_line_color(self, widget, pspec):
self._render_chart()

def _object_chooser(self, mime_type, type_name):
chooser = ObjectChooser()
chooser = None
JuiP marked this conversation as resolved.
Show resolved Hide resolved
chooser = ObjectChooser(parent=self, what_filter=mime_type)
matches_mime_type = False

response = chooser.run()
Expand All @@ -389,8 +399,7 @@ def _object_chooser(self, mime_type, type_name):
alert = Alert()

alert.props.title = _('Invalid object')
alert.props.msg = \
_('The selected object must be a %s file' % (type_name))
alert.props.msg = _('The selected object must be a %s file' % (type_name))

ok_icon = Icon(icon_name='dialog-ok')
alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
Expand All @@ -402,7 +411,7 @@ def _object_chooser(self, mime_type, type_name):

alert.show()

return matches_mime_type, file_path, metadata['title']
return matches_mime_type, file_path, metadata['title']

def _graph_from_reader(self, reader):
self.labels_and_values.model.clear()
Expand All @@ -412,39 +421,39 @@ def _graph_from_reader(self, reader):
horizontal, vertical = reader.get_labels_name()

# Load the data
for row in chart_data:
self._add_value(None,
label=row[0], value=float(row[1]))
for row in chart_data:
self._add_value(None, label=row[0], value=float(row[1]))

self.update_chart()

def _add_value(self, widget, label="", value="0.0"):
data = (label, float(value))
if not data in self.chart_data:
if data not in self.chart_data:
pos = self.labels_and_values.add_value(label, value)
self.chart_data.insert(pos, data)
self._update_chart_data()


def _remove_value(self, widget):
value = self.labels_and_values.remove_selected_value()
self.chart_data.remove(value)
self._update_chart_data()

def __import_freespace_cb(self, widget):
reader = FreeSpaceReader()
self._graph_from_reader(reader)
reader = FreeSpaceReader()
self._graph_from_reader(reader)

def __import_journal_cb(self, widget):
reader = JournalReader()
self._graph_from_reader(reader)

def __import_turtle_cb(self, widget):
matches_mime_type, file_path, title = self._object_chooser(
'application/x-turtle-art', _('Turtle'))
if matches_mime_type:
reader = TurtleReader(file_path)
self._graph_from_reader(reader)
try:
matches_mime_type, file_path, title = self._object_chooser('application/x-turtle-art', _('Turtle'))
JuiP marked this conversation as resolved.
Show resolved Hide resolved
if matches_mime_type:
reader = TurtleReader(file_path)
self._graph_from_reader(reader)
except TypeError:
return

def _save_as_image(self, widget):
if self.current_chart:
Expand Down Expand Up @@ -486,11 +495,10 @@ def load_from_file(self, f):
elif _type == "pie":
self.chart_type_buttons[3].set_active(True)

#load the data
for row in chart_data:
# load the data
for row in chart_data:
self._add_value(None, label=row[0], value=float(row[1]))


self.update_chart()

def write_file(self, file_path):
Expand Down Expand Up @@ -519,15 +527,12 @@ def read_file(self, file_path):

class ChartData(Gtk.TreeView):

__gsignals__ = {
'label-changed': (GObject.SignalFlags.RUN_FIRST, None, [str, str], ),
'value-changed': (GObject.SignalFlags.RUN_FIRST, None, [str, str], ), }
__gsignals__ = {'label-changed': (GObject.SignalFlags.RUN_FIRST, None, [str, str], ), 'value-changed': (GObject.SignalFlags.RUN_FIRST, None, [str, str], ), }
JuiP marked this conversation as resolved.
Show resolved Hide resolved

def __init__(self, activity):

GObject.GObject.__init__(self)


self.model = Gtk.ListStore(str, str)
self.set_model(self.model)

Expand Down Expand Up @@ -572,31 +577,30 @@ def add_value(self, label, value):
except ValueError:
_iter = self.model.append([label, str(value)])


self.set_cursor(self.model.get_path(_iter),
self.get_column(1),
True)

_logger.info("Added: %s, Value: %s" % (label, value))
logging.debug("Added: %s, Value: %s" % (label, value))
JuiP marked this conversation as resolved.
Show resolved Hide resolved

return path

def remove_selected_value(self):
model, iter = self._selection.get_selected()
value = (self.model.get(iter, 0)[0], float(self.model.get(iter, 1)[0]))
_logger.info('VALUE: ' + str(value))
logging.debug('VALUE: ' + str(value))
self.model.remove(iter)

return value

def _label_changed(self, cell, path, new_text, model):
_logger.info("Change '%s' to '%s'" % (model[path][0], new_text))
logging.debug("Change '%s' to '%s'" % (model[path][0], new_text))
model[path][0] = new_text

self.emit("label-changed", str(path), new_text)

def _value_changed(self, cell, path, new_text, model, activity):
_logger.info("Change '%s' to '%s'" % (model[path][1], new_text))
logging.debug("Change '%s' to '%s'" % (model[path][1], new_text))
is_number = True
number = new_text.replace(",", ".")
try:
Expand All @@ -615,8 +619,7 @@ def _value_changed(self, cell, path, new_text, model, activity):
alert = Alert()

alert.props.title = _('Invalid Value')
alert.props.msg = \
_('The value must be a number (integer or decimal)')
alert.props.msg = _('The value must be a number (integer or decimal)')

ok_icon = Icon(icon_name='dialog-ok')
alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
Expand Down
2 changes: 1 addition & 1 deletion activity/activity.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = Analyze Journal
activity_version = 4
bundle_id = org.sugarlabs.AnalyzeJournal
exec = sugar-activity activity.AnalyzeJournal
exec = sugar-activity3 activity.AnalyzeJournal
icon = analyzejournal
license = GPLv3+
summary = chart of Sugar Journal activity
Expand Down
12 changes: 4 additions & 8 deletions charthelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ def create_help(toolbar):
helpitem.show()
helpitem.add_section(_('Basic usage'))
helpitem.add_paragraph(_('First select data type:'))
helpitem.add_paragraph(_('The free space in the Journal;'),
'import-freespace')
helpitem.add_paragraph(_('The types of Sugar Activities you have used;'),
'import-journal')
helpitem.add_paragraph(_('The types of blocks used in Turtle Art.'),
'import-turtle')
helpitem.add_paragraph(_('The free space in the Journal;'), 'import-freespace')
helpitem.add_paragraph(_('The types of Sugar Activities you have used;'), 'import-journal')
helpitem.add_paragraph(_('The types of blocks used in Turtle Art.'), 'import-turtle')
helpitem.add_paragraph(_('The graph title is the same as the Activity title'))
JuiP marked this conversation as resolved.
Show resolved Hide resolved

helpitem.add_paragraph(_('You can change the type of graph:'))
Expand All @@ -26,5 +23,4 @@ def create_help(toolbar):
helpitem.add_paragraph(_('Pie'), 'pie')

helpitem.add_section(_('Saving as an image'))
helpitem.add_paragraph(_('In the activity toolbar you have button to save the graph as an image'),
'save-as-image')
helpitem.add_paragraph(_('In the activity toolbar you have button to save the graph as an image'), 'save-as-image')
21 changes: 6 additions & 15 deletions charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import sugarpycha.line
import sugarpycha.pie

import gi
from gi.repository import GObject
import cairo

Expand All @@ -44,9 +43,7 @@ def __init__(self, type="vertical", width=600, height=460):
def data_set(self, data):
"""Set chart data (dataSet)"""

self.dataSet = (
('Puntos', [(i, l[1]) for i, l in enumerate(data)]),
)
self.dataSet = (('Puntos', [(i, l[1]) for i, l in enumerate(data)]), )

self.options = {
'legend': {'hide': True},
Expand All @@ -56,14 +53,11 @@ def data_set(self, data):
'labelFontSize': 14,
'lineColor': '#b3b3b3',
'x': {
'ticks': [dict(v=i, label=l[0]) for i,
l in enumerate(data)],
'label': 'X',
},
'ticks': [dict(v=i, label=l[0]) for i, l in enumerate(data)],
'label': 'X', },
'y': {
'tickCount': 5,
'label': 'Y',
}
'label': 'Y', }
},
'stroke': {
'width': 3
Expand Down Expand Up @@ -107,9 +101,7 @@ def set_title(self, title="Chart"):
def render(self, sg=None):
"""Draw the chart
Use the self.surface variable for show the chart"""
self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
self.width,
self.height)
self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.width, self.height)

if self.type == "vbar":
chart = sugarpycha.bar.VerticalBarChart(self.surface, self.options)
Expand All @@ -124,8 +116,7 @@ def render(self, sg=None):
elif self.type == "pie":
self.options["legend"] = {"hide": "False"}
chart = sugarpycha.pie.PieChart(self.surface, self.options)
self.dataSet = [(data[0],
[[0, data[1]]]) for data in sg.chart_data]
self.dataSet = [(data[0], [[0, data[1]]]) for data in sg.chart_data]

else:
chart = sugarpycha.bar.HorizontalBarChart(self.surface,
Expand Down
3 changes: 1 addition & 2 deletions helpbutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def __init__(self, **kwargs):
self._palette = help_button.get_palette()

sw = Gtk.ScrolledWindow()
sw.set_size_request(int(Gdk.Screen.width() / 2.8),
Gdk.Screen.height() - style.GRID_CELL_SIZE * 3)
sw.set_size_request(int(Gdk.Screen.width() / 2.8), Gdk.Screen.height() - style.GRID_CELL_SIZE * 3)
sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)

self._max_text_width = int(Gdk.Screen.width() / 3) - 20
Expand Down
Loading