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 4 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: 4 additions & 6 deletions activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import logging
import utils

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

from sugar3.activity import activity
Expand Down Expand Up @@ -66,6 +66,8 @@
_logger.setLevel(logging.DEBUG)
logging.basicConfig()

#Dragging
DRAG_ACTION = Gdk.DragAction.COPY

class ChartArea(Gtk.DrawingArea):

Expand All @@ -76,6 +78,7 @@ def __init__(self, parent):
self.add_events(Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.VISIBILITY_NOTIFY_MASK)
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 @@ -577,26 +580,21 @@ def add_value(self, label, value):
self.get_column(1),
True)

_logger.info("Added: %s, Value: %s" % (label, value))

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))
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))
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))
is_number = True
number = new_text.replace(",", ".")
try:
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
10 changes: 5 additions & 5 deletions readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import os
import glob
import statvfs
import shutil

from gettext import gettext as _

Expand Down Expand Up @@ -63,9 +63,9 @@ def get_chart_data(self):
return chart_data

def _get_space(self):
stat = os.statvfs(env.get_profile_path())
free_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL]
total_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BLOCKS]
total_space, used_space, free_space = shutil.disk_usage(env.get_profile_path())
#free_space = stat[statvfs.f_bsize] * stat[statvfs.f_bavail]
#total_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BLOCKS]

free_space = self._get_MBs(free_space)
total_space = self._get_MBs(total_space)
Expand Down Expand Up @@ -239,7 +239,7 @@ def __init__(self):
self._dsdict[os.path.basename(path)][-1][
'activity'] = activity

for k, v in self._dsdict.iteritems():
for k, v in self._dsdict.items():
for a in v:
if 'activity' in a:
if a['activity'] in self._activity_name:
Expand Down
13 changes: 7 additions & 6 deletions sugarpycha/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from sugarpycha.color import ColorScheme, hex2rgb, DEFAULT_COLOR
from sugarpycha.utils import safe_unicode
from functools import reduce


class Chart(object):
Expand Down Expand Up @@ -139,7 +140,7 @@ def _setColorscheme(self):
# Remove invalid args before calling the constructor
kwargs = dict(self.options.colorScheme.args)
validArgs = inspect.getargspec(colorSchemeClass.__init__)[0]
kwargs = dict([(k, v) for k, v in kwargs.items() if k in validArgs])
kwargs = dict([(k, v) for k, v in list(kwargs.items()) if k in validArgs])
self.colorScheme = colorSchemeClass(keys, **kwargs)

def _initSurface(self, surface):
Expand Down Expand Up @@ -242,7 +243,7 @@ def _updateTicks(self):
pos = self.xscale * (label - self.minxval)

elif self.options.axis.x.tickCount > 0:
uniqx = range(len(uniqueIndices(stores)) + 1)
uniqx = list(range(len(uniqueIndices(stores)) + 1))
roughSeparation = self.xrange / self.options.axis.x.tickCount
i = j = 0
while i < len(uniqx) and j < self.options.axis.x.tickCount:
Expand Down Expand Up @@ -613,7 +614,7 @@ def drawKey(key, x, y, text_height):

def uniqueIndices(arr):
"""Return a list with the indexes of the biggest element of arr"""
return range(max([len(a) for a in arr]))
return list(range(max([len(a) for a in arr])))


class Area(object):
Expand Down Expand Up @@ -764,7 +765,7 @@ def _getAxisTickLabelsSize(self, cx, options, axis, ticks):
))[2:4] # get width and height as a tuple
for tick in ticks]
if extents:
widths, heights = zip(*extents)
widths, heights = list(zip(*extents))
max_width, max_height = max(widths), max(heights)
if axis.rotate:
radians = math.radians(axis.rotate)
Expand All @@ -782,14 +783,14 @@ class Option(dict):
"""Useful dict that allow attribute-like access to its keys"""

def __getattr__(self, name):
if name in self.keys():
if name in list(self.keys()):
return self[name]
else:
raise AttributeError(name)

def merge(self, other):
"""Recursive merge with other Option or dict object"""
for key, value in other.items():
for key, value in list(other.items()):
if key in self:
if isinstance(self[key], Option):
self[key].merge(other[key])
Expand Down
4 changes: 1 addition & 3 deletions sugarpycha/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,9 @@ def __new__(mcs, name, bases, dict):
return klass


class ColorScheme(dict):
class ColorScheme(dict, metaclass=ColorSchemeMetaclass):
"""A color scheme is a dictionary where the keys match the keys
constructor argument and the values are colors"""

__metaclass__ = ColorSchemeMetaclass
__registry__ = {}

def __init__(self, keys):
Expand Down
3 changes: 2 additions & 1 deletion sugarpycha/stackedbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from sugarpycha.bar import BarChart, VerticalBarChart, HorizontalBarChart, Rect
from sugarpycha.chart import uniqueIndices
from functools import reduce


class StackedBarChart(BarChart):
Expand All @@ -37,7 +38,7 @@ def _updateXY(self):
n_stores = len(stores)
flat_y = [pair[1] for pair in reduce(lambda a, b: a + b, stores)]
store_size = len(flat_y) / n_stores
accum = [sum(flat_y[j]for j in xrange(i,
accum = [sum(flat_y[j]for j in range(i,
i + store_size * n_stores,
store_size))
for i in range(len(flat_y) / n_stores)]
Expand Down
8 changes: 4 additions & 4 deletions sugarpycha/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def clamp(minValue, maxValue, value):

def safe_unicode(obj, encoding=None):
"""Return a unicode value from the argument"""
if isinstance(obj, unicode):
if isinstance(obj, str):
return obj
elif isinstance(obj, str):
if encoding is None:
return unicode(obj)
return str(obj)
else:
return unicode(obj, encoding)
return str(obj, encoding)
else:
# it may be an int or a float
return unicode(obj)
return str(obj)