本文整理汇总了Python中sugar3.datastore.datastore.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_from_journal
def load_from_journal(self, journal_data):
for card in self._card_data:
alphabet = card[0]
if alphabet in journal_data:
for images in journal_data[alphabet]:
imagedataobject = datastore.get(images[0])
audiodataobject = datastore.get(images[1])
if imagedataobject and audiodataobject:
imagepath = imagedataobject.get_file_path()
pixbuf = image_file_to_pixbuf(imagepath, self._card_width,
self._card_height)
audiopath = audiodataobject.get_file_path()
s = Sprite(self._sprites, 0, 0, pixbuf)
self._image_data[alphabet].append((s, audiopath))
self._pictures.append(s)
示例2: _process_tags
def _process_tags(self, text_buffer, text):
""" process tag data from textview """
self._reflection.data["tags"] = []
label = ""
tags = text.split()
for tag in tags:
if len(label) > 0:
label += ", "
tag = tag.rstrip(",")
tag = tag.rstrip(";")
if tag[0] == "#":
self._reflection.data["tags"].append(tag)
label += tag
else:
self._reflection.data["tags"].append("#" + tag)
label += "#" + tag
text_buffer.set_text(label.replace("\12", ""))
if self._reflection.activity.sharing:
data = json.dumps(self._reflection.data["tags"])
self._reflection.activity.send_event("%s|%s|%s" % (TAG_CMD, self._reflection.data["obj_id"], data))
self._reflection.set_modification_time()
# Update journal entry
dsobj = datastore.get(self._reflection.data["obj_id"])
logging.error("setting tags to %s" % label)
dsobj.metadata["tags"] = label
datastore.write(
dsobj,
update_mtime=False,
reply_handler=self.datastore_write_cb,
error_handler=self.datastore_write_error_cb,
)
示例3: create_preview
def create_preview(self, object_id):
jobject = datastore.get(object_id)
if 'preview' in jobject.metadata:
preview = jobject.metadata['preview']
if preview is None or preview == '' or preview == 'None':
if jobject.metadata['mime_type'] .startswith('image/') and \
jobject.metadata['mime_type'] != 'image/vnd.djvu':
filename = jobject.get_file_path()
self.show_image(filename)
return
if jobject.metadata['mime_type'] == 'application/x-cbz':
filename = jobject.get_file_path()
fname = self.extract_image(filename)
self.show_image(fname)
os.remove(fname)
return
self.show_image('xoimage.jpg')
return
if 'preview' in jobject.metadata and \
len(jobject.metadata['preview']) > 4:
preview_data = jobject.metadata['preview']
loader = GdkPixbuf.PixbufLoader()
loader.write(preview_data)
scaled_buf = loader.get_pixbuf()
loader.close()
self.image.set_from_pixbuf(scaled_buf)
self.image.show()
else:
self.image.clear()
self.image.show()
示例4: update_entry
def update_entry(self):
needs_update = False
if self.selected_journal_entry is None:
return
object_id = self.selected_journal_entry.object_id
jobject = datastore.get(object_id)
old_title = jobject.metadata.get('title', None)
if old_title != self.title_entry.props.text:
jobject.metadata['title'] = self.title_entry.props.text
jobject.metadata['title_set_by_user'] = '1'
self.update_log_entries += '\n' + _('Entry title changed to %s') % self.title_entry.props.text
needs_update = True
old_tags = jobject.metadata.get('tags', None)
new_tags = self.tags_textview.props.buffer.props.text
if old_tags != new_tags:
jobject.metadata['tags'] = new_tags
self.update_log_entries += '\n' + _('Entry %s tags updated.') % self.title_entry.props.text
needs_update = True
old_description = jobject.metadata.get('description', None)
new_description = self.description_textview.props.buffer.props.text
if old_description != new_description:
jobject.metadata['description'] = new_description
self.update_log_entries += '\n' + _('Entry %s description updated.') % self.title_entry.props.text
needs_update = True
if needs_update:
datastore.write(jobject, update_mtime=False,
reply_handler=self.datastore_write_cb,
error_handler=self.datastore_write_error_cb)
self.btn_save.props.sensitive = False
示例5: selection_journal_cb
def selection_journal_cb(self, selection):
self.btn_delete.props.sensitive = True
tv = selection.get_tree_view()
model = tv.get_model()
sel = selection.get_selected()
if sel:
model, iter = sel
jobject = model.get_value(iter,COLUMN_JOBJECT)
jobject = datastore.get(jobject.object_id)
self.selected_journal_entry = jobject
self.set_form_fields(jobject)
if jobject.metadata['mime_type'] .startswith('image/') \
and jobject.metadata['mime_type'] != 'image/vnd.djvu':
self.btn_resize.show()
self.resize_width_entry.show()
filename = jobject.get_file_path()
im = pygame.image.load(filename)
image_width, image_height = im.get_size()
self.dimension_label.set_text(str(image_width) + "x" + str(image_height))
self.dimension_label.show()
else:
self.btn_resize.hide()
self.resize_width_entry.hide()
self.dimension_label.hide()
self.selected_path = model.get_path(iter)
示例6: _process_tags
def _process_tags(self, text_buffer, text):
''' process tag data from textview '''
self._reflection.data['tags'] = []
label = ''
tags = text.split()
for tag in tags:
if len(label) > 0:
label += ', '
tag = tag.rstrip(',')
tag = tag.rstrip(';')
if tag[0] == '#':
self._reflection.data['tags'].append(tag)
label += tag
else:
self._reflection.data['tags'].append('#' + tag)
label += '#' + tag
text_buffer.set_text(label.replace('\12', ''))
if self._reflection.activity.sharing:
data = json.dumps(self._reflection.data['tags'])
self._reflection.activity.send_event(TAG_CMD,
{"obj_id": self._refelection.data["ob_id"],
"reflection": data})
self._reflection.set_modification_time()
# Update journal entry
dsobj = datastore.get(self._reflection.data['obj_id'])
logging.error('setting tags to %s' % label)
dsobj.metadata['tags'] = label
datastore.write(dsobj,
update_mtime=False,
reply_handler=self.datastore_write_cb,
error_handler=self.datastore_write_error_cb)
示例7: insert_comment
def insert_comment(self, obj_id, comment):
for item in self._reflections:
if item.obj_id == obj_id:
item.graphics.add_new_comment(comment)
item.graphics.notify_button.show()
# Update journal entry
if obj_id[0:4] == 'obj-':
break
try:
dsobj = datastore.get(obj_id)
except Exception as e:
logging.error('Could not open %s: %e' % (obj_id, e))
break
if 'comments' in dsobj.metadata:
data = json.loads(dsobj.metadata['comments'])
else:
data = []
data.append({'from': comment['nick'],
'message': comment['comment'],
'icon-color': '%s,%s' % (
comment['color'], comment['color'])
})
dsobj.metadata['comments'] = json.dumps(data)
datastore.write(dsobj,
update_mtime=False,
reply_handler=self.datastore_write_cb,
error_handler=self.datastore_write_error_cb)
break
示例8: _comment_activate_cb
def _comment_activate_cb(self, entry):
text = entry.props.text
if not 'comments' in self._reflection.data:
self._reflection.data['comments'] = []
data = {'nick': profile.get_nick_name(),
'color': self._reflection.activity.fg_color.get_html(),
'comment': text}
self._reflection.data['comments'].append(data)
self.add_new_comment(data)
# Send the comment
if self._reflection.activity.sharing:
send_data = data.copy()
send_data["obj_id"] = self._reflection.data["obj_id"]
self._reflection.activity.send_event(COMMENT_CMD, send_data)
entry.set_text('')
# Update journal entry
dsobj = datastore.get(self._reflection.data['obj_id'])
if 'comments' in dsobj.metadata:
data = json.loads(dsobj.metadata['comments'])
else:
data = []
data.append({'from': profile.get_nick_name(),
'message': text,
'icon-color': profile.get_color().to_string()})
dsobj.metadata['comments'] = json.dumps(data)
datastore.write(dsobj,
update_mtime=False,
reply_handler=self.datastore_write_cb,
error_handler=self.datastore_write_error_cb)
示例9: get_bundle
def get_bundle(bundle_id=None, object_id=None):
if bundle_id is None and object_id is None:
logging.error('At least one parameter has to be passed')
return None
if bundle_id is None:
obj = datastore.get(object_id)
if obj.metadata['mime_type'] is None:
return None
mime_type = str(obj.metadata['mime_type'])
activities = get_activities_for_mime(mime_type)
if not activities:
logging.warning('No activity can start object with type, %s.',
mime_type)
return None
return activities[0]
else:
bundle = bundleregistry.get_registry().get_bundle(bundle_id)
if bundle is None:
logging.warning('Activity with the bundle_id %s was not found',
mime_type)
return None
return bundle
示例10: _image_file_from_metadata
def _image_file_from_metadata(self, image_path):
""" Load a pixbuf from a Journal object. """
try:
metadata = self._get_metadata()
if 'mime_type' in metadata and 'image' in metadata['mime_type']:
ds_object = datastore.get(metadata['uid'])
pixbuf = GdkPixbuf.Pixbuf.new_from_file(ds_object.file_path)
else:
pixbufloader = \
GdkPixbuf.PixbufLoader.new_with_mime_type('image/png')
pixbufloader.set_size(300, 225)
pixbufloader.write(metadata['preview'])
pixbuf = pixbufloader.get_pixbuf()
pixbufloader.close()
except Exception as ex:
logging.error("_image_file_from_metadata: %s" % (str(ex)))
return False
try:
pixbuf.savev(image_path, 'png', [], [])
logging.debug('_image_file_from_metadata: success %s' %
(image_path))
return True
except Exception as ex:
logging.error("_image_file_from_metadata: %s" % (str(ex)))
return False
示例11: _fb_comments_downloaded_cb
def _fb_comments_downloaded_cb(self, fb_photo, comments):
logging.debug('_fb_comments_downloaded_cb')
ds_object = datastore.get(self._metadata['uid'])
if not COMMENTS in ds_object.metadata:
ds_comments = []
else:
ds_comments = json.loads(ds_object.metadata[COMMENTS])
if not COMMENT_IDS in ds_object.metadata:
ds_comment_ids = []
else:
ds_comment_ids = json.loads(ds_object.metadata[COMMENT_IDS])
new_comment = False
for comment in comments:
if comment['id'] not in ds_comment_ids:
# TODO: get avatar icon and add it to icon_theme
ds_comments.append({'from': comment['from'],
'message': comment['message'],
'icon': 'facebook-share'})
ds_comment_ids.append(comment['id'])
new_comment = True
if new_comment:
ds_object.metadata[COMMENTS] = json.dumps(ds_comments)
ds_object.metadata[COMMENT_IDS] = json.dumps(ds_comment_ids)
self.emit('comments-changed', ds_object.metadata[COMMENTS])
datastore.write(ds_object, update_mtime=False)
示例12: _photo_created_cb
def _photo_created_cb(self, fb_photo, fb_object_id, tmp_file):
logging.debug("_photo_created_cb")
if os.path.exists(tmp_file):
os.unlink(tmp_file)
metadata = self._get_metadata()
comment = ''
if 'title' in metadata:
comment += '%s:' % str(metadata['title'])
if 'description' in metadata:
comment += str(metadata['description'])
fb_photo.connect('comment-added', self._comment_added_cb)
fb_photo.connect('comment-add-failed', self._comment_add_failed_cb)
fb_photo.add_comment(comment)
try:
ds_object = datastore.get(metadata['uid'])
ds_object.metadata['fb_object_id'] = fb_object_id
datastore.write(ds_object, update_mtime=False)
except Exception as ex:
logging.debug("_photo_created_cb failed to write to datastore: " %
str(ex))
示例13: load_file
def load_file(self, jobject, title=None):
if isinstance(jobject, datastore.RawObject):
logging.debug('Loading a datastore.RawObject')
file_path = mime_path = jobject.file_path
title = jobject.metadata['title']
elif isinstance(jobject, datastore.DSObject):
# This file is stored in the Journal (datastore)
logging.debug('Loading a datastore.DSObject')
file_path = 'journal://' + jobject.object_id
mime_path = datastore.get(jobject.object_id).file_path
title = jobject.metadata['title']
else:
logging.debug('Loading a %s', type(jobject))
file_path = mime_path = jobject
mimetype = mime.get_for_file('file://' + mime_path)
logging.info('read_file mime %s', mimetype)
if mimetype == 'audio/x-mpegurl':
# is a M3U playlist:
self._load_m3u_playlist(file_path)
else:
# is not a M3U playlist
self._load_stream(file_path, title)
missing_tracks = self._get_missing_tracks()
if len(missing_tracks) > 0:
logging.info('%s tracks not found', len(missing_tracks))
self.emit('missing-tracks', missing_tracks)
# set the focus in the first row
self._set_cursor(0)
示例14: _comment_activate_cb
def _comment_activate_cb(self, entry):
text = entry.props.text
if not "comments" in self._reflection.data:
self._reflection.data["comments"] = []
data = {
"nick": profile.get_nick_name(),
"color": self._reflection.activity.fg_color.get_html(),
"comment": text,
}
self._reflection.data["comments"].append(data)
self.add_new_comment(data)
# Send the comment
if self._reflection.activity.sharing:
self._reflection.activity.send_event(
"%s|%s|%s|%s|%s"
% (COMMENT_CMD, self._reflection.data["obj_id"], data["nick"], data["color"], data["comment"])
)
entry.set_text("")
# Update journal entry
dsobj = datastore.get(self._reflection.data["obj_id"])
if "comments" in dsobj.metadata:
data = json.loads(dsobj.metadata["comments"])
else:
data = []
data.append({"from": profile.get_nick_name(), "message": text, "icon-color": profile.get_color().to_string()})
dsobj.metadata["comments"] = json.dumps(data)
datastore.write(
dsobj,
update_mtime=False,
reply_handler=self.datastore_write_cb,
error_handler=self.datastore_write_error_cb,
)
示例15: _get_data
def _get_data(self, metadata=None):
if not metadata:
metadata = self._get_metadata()
jobject = datastore.get(metadata['uid'])
path = str(jobject.file_path)
return path