Exemplo n.º 1
0
 def add_activity(self, bundle_id):
     """ Add activity from sharer """
     if not "activities" in self._reflection.data:
         self._reflection.data["activities"] = []
     self._reflection.data["activities"].append(utils.bundle_id_to_icon(bundle_id))
     self._reflection.set_modification_time()
     self._activities_align.remove(self._activities_grid)
     self._make_activities_grid()
Exemplo n.º 2
0
 def add_activity(self, bundle_id):
     ''' Add activity from sharer '''
     if 'activities' not in self._reflection.data:
         self._reflection.data['activities'] = []
     self._reflection.data['activities'].append(
         utils.bundle_id_to_icon(bundle_id))
     self._reflection.set_modification_time()
     self._activities_align.remove(self._activities_grid)
     self._make_activities_grid()
Exemplo n.º 3
0
 def add_activity(self, bundle_id):
     ''' Add activity from sharer '''
     if not 'activities' in self._reflection.data:
         self._reflection.data['activities'] = []
     self._reflection.data['activities'].append(
         utils.bundle_id_to_icon(bundle_id))
     self._reflection.set_modification_time()
     self._activities_align.remove(self._activities_grid)
     self._make_activities_grid()
Exemplo n.º 4
0
 def _entry_activate_cb(self, entry):
     text = entry.props.text
     self._activity.reflection_data.insert(0, {"title": text})
     reflection = Reflection(self._activity, self._activity.reflection_data[0])
     reflection.set_title(text)
     reflection.set_creation_time()
     reflection.set_obj_id(generate=True)
     reflection.add_activity(utils.bundle_id_to_icon("org.sugarlabs.Reflect"))
     reflection.set_stars(0)
     self._reflections_grid.insert_row(1)
     self._reflections_grid.attach(reflection.get_graphics(), 0, 1, 1, 1)
     reflection.refresh()
     self._reflections.append(reflection)
     entry.set_text("")
     if self._activity.sharing:
         data = json.dumps(self._activity.reflection_data[0])
         self._activity.send_event("%s|%s" % (NEW_REFLECTION_CMD, data))
Exemplo n.º 5
0
 def _entry_activate_cb(self, entry):
     text = entry.props.text
     self._activity.reflection_data.insert(0, {'title': text})
     reflection = Reflection(self._activity,
                             self._activity.reflection_data[0])
     reflection.set_title(text)
     reflection.set_creation_time()
     reflection.set_obj_id(generate=True)
     reflection.add_activity(
         utils.bundle_id_to_icon('org.sugarlabs.Reflect'))
     reflection.set_stars(0)
     self._reflections_grid.insert_row(1)
     self._reflections_grid.attach(reflection.get_graphics(), 0, 1, 1, 1)
     reflection.refresh()
     self._reflections.append(reflection)
     entry.set_text('')
     if self._activity.sharing:
         data = json.dumps(self._activity.reflection_data[0])
         self._activity.send_event(NEW_REFLECTION_CMD, {"data": data})
Exemplo n.º 6
0
 def _add_new_from_journal(self, dsobj):
     self.reflection_data.append({
         'title': _('Untitled'),
         'obj_id': dsobj.object_id
     })
     if hasattr(dsobj, 'metadata'):
         if 'creation_time' in dsobj.metadata:
             self.reflection_data[-1]['creation_time'] = \
                 dsobj.metadata['creation_time']
         else:
             self.reflection_data[-1]['creation_time'] = \
                 int(time.time())
         if 'timestamp' in dsobj.metadata:
             self.reflection_data[-1]['modification_time'] = \
                 dsobj.metadata['timestamp']
         else:
             self.reflection_data[-1]['modification_time'] = \
                 self.reflection_data[-1]['creation_time']
         if 'activity' in dsobj.metadata:
             self.reflection_data[-1]['activities'] = \
                 [utils.bundle_id_to_icon(dsobj.metadata['activity'])]
         if 'title' in dsobj.metadata:
             self.reflection_data[-1]['title'] = \
                 dsobj.metadata['title']
         if 'description' in dsobj.metadata:
             self.reflection_data[-1]['content'] = \
                 [{'text': dsobj.metadata['description']}]
         else:
             self.reflection_data[-1]['content'] = []
         if 'tags' in dsobj.metadata:
             self.reflection_data[-1]['tags'] = []
             tags = dsobj.metadata['tags'].split()
             for tag in tags:
                 if tag[0] != '#':
                     self.reflection_data[-1]['tags'].append('#' + tag)
                 else:
                     self.reflection_data[-1]['tags'].append(tag)
         if 'comments' in dsobj.metadata:
             try:
                 comments = json.loads(dsobj.metadata['comments'])
             except BaseException:
                 comments = []
             self.reflection_data[-1]['comments'] = []
             for comment in comments:
                 try:
                     data = {
                         'nick': comment['from'],
                         'comment': comment['message']
                     }
                     if 'icon-color' in comment:
                         colors = comment['icon-color'].split(',')
                         darker = 1 - utils.lighter_color(colors)
                         data['color'] = colors[darker]
                     else:
                         data['color'] = '#000000'
                     self.reflection_data[-1]['comments'].append(data)
                 except BaseException:
                     _logger.debug('could not parse comment %s' % comment)
         if 'mime_type' in dsobj.metadata and \
            dsobj.metadata['mime_type'][0:5] == 'image':
             new_path = os.path.join(self.tmp_path, dsobj.object_id)
             try:
                 shutil.copy(dsobj.file_path, new_path)
             except Exception as e:
                 logging.error("Couldn't copy %s to %s: %s" %
                               (dsobj.file_path, new_path, e))
             self.reflection_data[-1]['content'].append({'image': new_path})
         elif 'preview' in dsobj.metadata:
             pixbuf = utils.get_pixbuf_from_journal(dsobj, 300, 225)
             if pixbuf is not None:
                 path = os.path.join(self.tmp_path,
                                     dsobj.object_id + '.png')
                 utils.save_pixbuf_to_file(pixbuf, path)
                 self.reflection_data[-1]['content'].append({'image': path})
         self.reflection_data[-1]['stars'] = 0
Exemplo n.º 7
0
 def _add_new_from_journal(self, dsobj):
     self.reflection_data.append({
         'title': _('Untitled'), 'obj_id': dsobj.object_id})
     if hasattr(dsobj, 'metadata'):
         if 'creation_time' in dsobj.metadata:
             self.reflection_data[-1]['creation_time'] = \
                 dsobj.metadata['creation_time']
         else:
             self.reflection_data[-1]['creation_time'] = \
                 int(time.time())
         if 'timestamp' in dsobj.metadata:
             self.reflection_data[-1]['modification_time'] = \
                 dsobj.metadata['timestamp']
         else:
             self.reflection_data[-1]['modification_time'] = \
                 self.reflection_data[-1]['creation_time']
         if 'activity' in dsobj.metadata:
             self.reflection_data[-1]['activities'] = \
                 [utils.bundle_id_to_icon(dsobj.metadata['activity'])]
         if 'title' in dsobj.metadata:
             self.reflection_data[-1]['title'] = \
                 dsobj.metadata['title']
         if 'description' in dsobj.metadata:
             self.reflection_data[-1]['content'] = \
                 [{'text': dsobj.metadata['description']}]
         else:
             self.reflection_data[-1]['content'] = []
         if 'tags' in dsobj.metadata:
             self.reflection_data[-1]['tags'] = []
             tags = dsobj.metadata['tags'].split()
             for tag in tags:
                 if tag[0] != '#':
                     self.reflection_data[-1]['tags'].append('#' + tag)
                 else:
                     self.reflection_data[-1]['tags'].append(tag)
         if 'comments' in dsobj.metadata:
             try:
                 comments = json.loads(dsobj.metadata['comments'])
             except:
                 comments = []
             self.reflection_data[-1]['comments'] = []
             for comment in comments:
                 try:
                     data = {'nick': comment['from'],
                             'comment': comment['message']}
                     if 'icon-color' in comment:
                         colors = comment['icon-color'].split(',')
                         darker = 1 - utils.lighter_color(colors)
                         data['color'] = colors[darker]
                     else:
                         data['color'] = '#000000'
                     self.reflection_data[-1]['comments'].append(data)
                 except:
                     _logger.debug('could not parse comment %s'
                                   % comment)
         if 'mime_type' in dsobj.metadata and \
            dsobj.metadata['mime_type'][0:5] == 'image':
             new_path = os.path.join(self.tmp_path,
                                     dsobj.object_id)
             try:
                 shutil.copy(dsobj.file_path, new_path)
             except Exception as e:
                 logging.error("Couldn't copy %s to %s: %s" %
                               (dsobj.file_path, new_path, e))
             self.reflection_data[-1]['content'].append(
                 {'image': new_path})
         elif 'preview' in dsobj.metadata:
             pixbuf = utils.get_pixbuf_from_journal(dsobj, 300, 225)
             if pixbuf is not None:
                 path = os.path.join(self.tmp_path,
                                     dsobj.object_id + '.png')
                 utils.save_pixbuf_to_file(pixbuf, path)
                 self.reflection_data[-1]['content'].append(
                     {'image': path})
         self.reflection_data[-1]['stars'] = 0