本文整理汇总了Python中sugar3.datastore.datastore.create函数的典型用法代码示例。如果您正苦于以下问题:Python create函数的具体用法?Python create怎么用?Python create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __export_pdf_cb
def __export_pdf_cb(self, event):
maxx, maxy = self._main_area.get_max_area()
true_width = int(maxx)
true_height = int(maxy)
# Create the new journal entry
fileObject = datastore.create()
act_meta = self.metadata
fileObject.metadata['title'] = act_meta['title'] + ' (PDF)'
fileObject.metadata['title_set_by_user'] = \
act_meta['title_set_by_user']
fileObject.metadata['mime_type'] = 'application/pdf'
# TODO: add text thoughts into fulltext metadata
# fileObject.metadata['fulltext'] = ...
fileObject.metadata['icon-color'] = act_meta['icon-color']
fileObject.file_path = os.path.join(self.get_activity_root(),
'instance', '%i' % time.time())
filename = fileObject.file_path
surface = cairo.PDFSurface(filename, true_width, true_height)
cairo_context = cairo.Context(surface)
context = Pango.create_context(cairo_context)
self._main_area.export(context, true_width, true_height, False)
surface.finish()
datastore.write(fileObject, transfer_ownership=True)
fileObject.destroy()
del fileObject
示例2: create_journal_entry
def create_journal_entry(self, tempfile):
journal_entry = datastore.create()
journal_title = self.selected_title
if self.selected_volume != '':
journal_title += ' ' + _('Volume') + ' ' + self.selected_volume
if self.selected_author != '':
journal_title = journal_title + ', by ' + self.selected_author
journal_entry.metadata['title'] = journal_title
journal_entry.metadata['title_set_by_user'] = '1'
journal_entry.metadata['keep'] = '0'
if _NEW_TOOLBAR_SUPPORT:
format = self.format_combo.props.value
else:
format = self._books_toolbar.format_combo.props.value
if format == '.epub':
journal_entry.metadata['mime_type'] = 'application/epub+zip'
if format == '.djvu':
journal_entry.metadata['mime_type'] = 'image/vnd.djvu'
if format == '.pdf' or format == '_bw.pdf':
journal_entry.metadata['mime_type'] = 'application/pdf'
journal_entry.metadata['buddies'] = ''
journal_entry.metadata['preview'] = ''
journal_entry.metadata['icon-color'] = profile.get_color().to_string()
textbuffer = self.textview.get_buffer()
journal_entry.metadata['description'] = textbuffer.get_text(textbuffer.get_start_iter(), textbuffer.get_end_iter(), True)
journal_entry.file_path = tempfile
datastore.write(journal_entry)
os.remove(tempfile)
self.progressbar.hide()
self._alert(_('Success'), self.selected_title + _(' added to Journal.'))
示例3: __export_png_cb
def __export_png_cb(self, event):
x, y, w, h, bitdepth = self._main_area.window.get_geometry()
cmap = self._main_area.window.get_colormap()
maxx, maxy = self._main_area.get_max_area()
true_width = int(maxx)
true_height = int(maxy)
# Create the new journal entry
fileObject = datastore.create()
act_meta = self.metadata
fileObject.metadata['title'] = act_meta['title'] + ' (PNG)'
fileObject.metadata['title_set_by_user'] = \
act_meta['title_set_by_user']
fileObject.metadata['mime_type'] = 'image/png'
fileObject.metadata['icon-color'] = act_meta['icon-color']
fileObject.file_path = os.path.join(self.get_activity_root(),
'instance', '%i' % time.time())
filename = fileObject.file_path
#pixmap = gtk.gdk.Pixmap(None, true_width, true_height, bitdepth)
#pixmap.set_colormap(cmap)
#self._main_area.export(pixmap.cairo_create(), true_width, true_height,
# False)
#pb = gtk.gdk.Pixbuf.get_from_drawable(
# gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, true_width,
# true_height),
# pixmap, gtk.gdk.colormap_get_system(), 0, 0, 0, 0, true_width,
# true_height)
pb.save(filename, 'png')
datastore.write(fileObject, transfer_ownership=True)
fileObject.destroy()
del fileObject
示例4: save
def save(self):
"""
Save the current font loaded in globals.FONT as a .ufo.zip file.
The file will be saved in the activity data folder
"""
ufo_path = self._create_font_instance()
title = self.get_title()
zip_path =\
os.path.join(self.get_activity_root(),
'data', '%s_ufo.zip' % (title))
if globals.FONT.save_zip(ufo_path, zip_path) is True:
# create a journal entry
jobject = datastore.create()
# FIXME: This method of setting the metadata is not working
# set the title to the output of self.get_title()
jobject.metadata['icon-color'] = profile.get_color().to_string()
jobject.metadata['mime_type'] = 'application/zip'
jobject.metadata['title'] = title
jobject.file_path = zip_path
datastore.write(jobject, transfer_ownership=True)
self._object_id = jobject.object_id
# create an alert
success_title = 'Success'
success_msg = 'A UFO Font zip file was created in the Journal'
self._show_journal_alert(_(success_title), _(success_msg))
else:
# create an alert
failure_title = 'Error'
failure_msg = 'Could not create the Zip file'
self._show_journal_alert(_(failure_title), _(failure_msg))
示例5: __export_as_html_cb
def __export_as_html_cb(self, button):
jobject = datastore.create()
jobject.metadata['title'] = \
_('{} as HTML').format(self.metadata['title'])
jobject.metadata['mime_type'] = 'text/html'
preview = self.get_preview()
if preview is not None:
jobject.metadata['preview'] = dbus.ByteArray(preview)
# write out the document contents in the requested format
path = os.path.join(self.get_activity_root(),
'instance', str(time.time()))
with open(path, 'w') as f:
f.write('''<html>
<head>
<title>{title}</title>
</head>
<body>
<h1>{title}</h1>
'''.format(title=jobject.metadata['title']))
for item in self._main_list.all():
f.write('<p>{}</p>'.format(
item[self._main_list.COLUMN_TEXT]))
f.write('''
</body>
</html>
''')
jobject.file_path = path
datastore.write(jobject, transfer_ownership=True)
self._journal_alert(jobject.object_id, _('Success'), _('Your'
' Bibliography was saved to the journal as HTML'))
jobject.destroy()
del jobject
示例6: export_font
def export_font(self):
"""
Export the current font loaded in globals.FONT as a .otf file.
The file will be saved in the activity data folder
"""
# create the file path
file_path =\
os.path.join(self.get_activity_root(),
'data', '%s.otf' % self.get_title)
# save the otf
globals.FONT.export_binary(file_path)
# create a journal entry
jobject = datastore.create()
jobject.metadata['icon-color'] = profile.get_color().to_string()
jobject.metadata['mime_type'] = 'application/x-font-opentype'
jobject.metadata['title'] = '%s.otf' % self.get_title
jobject.file_path = file_path
datastore.write(jobject, transfer_ownership=True)
self._object_id = jobject.object_id
success_title = 'Success'
success_msg = 'A OTF Font file was created in the Journal'
self._show_journal_alert(_(success_title), _(success_msg))
示例7: _install_update
def _install_update(self, bundle_update, local_file_path):
total = self._total_bundles_to_update
current = total - len(self._bundles_to_update) - 0.5
self.emit('progress', UpdateModel.ACTION_UPDATING,
bundle_update.bundle.get_name(),
current, total)
# TODO: Should we first expand the zip async so we can provide progress
# and only then copy to the journal?
jobject = datastore.create()
try:
title = '%s-%s' % (bundle_update.bundle.get_name(),
bundle_update.version)
jobject.metadata['title'] = title
jobject.metadata['mime_type'] = ActivityBundle.MIME_TYPE
jobject.file_path = local_file_path
datastore.write(jobject, transfer_ownership=True)
finally:
jobject.destroy()
self.emit('progress', UpdateModel.ACTION_UPDATING,
bundle_update.bundle.get_name(),
current + 0.5, total)
if self._bundles_to_update:
# do it in idle so the UI has a chance to refresh
GLib.idle_add(self._download_next_update)
示例8: generate_bundle
def generate_bundle(nick, new_basename):
"""Generate a new .xo bundle for the activity and copy it into the
Journal.
"""
new_activity_name = _customize_activity_info(
nick, new_basename)
user_activities_path = get_user_activities_path()
if os.path.exists(os.path.join(user_activities_path, new_basename,
'dist')):
for path in glob.glob(os.path.join(user_activities_path, new_basename,
'dist', '*')):
os.remove(path)
config = bundlebuilder.Config(source_dir=os.path.join(
user_activities_path, new_basename),
dist_name='%s-1.xo' % (new_activity_name))
bundlebuilder.cmd_dist_xo(config, None)
dsobject = datastore.create()
dsobject.metadata['title'] = '%s-1.xo' % (new_activity_name)
dsobject.metadata['mime_type'] = 'application/vnd.olpc-sugar'
dsobject.set_file_path(os.path.join(
user_activities_path, new_basename, 'dist',
'%s-1.xo' % (new_activity_name)))
datastore.write(dsobject)
dsobject.destroy()
示例9: do_drag_data_get
def do_drag_data_get(self, path, selection):
data = self.get_iter(path)
mime_type = self.get_value(data, 13)
fileid = self.get_value(data, 14)
title = self.get_value(data, 15)
data = self._account.download_file(fileid, self._display_alert)
fd, file_path = tempfile.mkstemp(dir="/tmp/")
os.close(fd)
if data[0]:
f = open(file_path, 'w')
f.write(data[0])
f.close()
jobject = datastore.create()
jobject.metadata['title'] = title
jobject.metadata['icon-color'] = profile.get_color().to_string()
jobject.metadata['mime_type'] = mime_type
if data[1]:
jobject.metadata['activity'] = data[1]
if data[0]:
jobject.file_path = file_path
datastore.write(jobject)
self._load_files()
self._journal_button.set_active(True)
self._listview.refresh()
示例10: __init__
def __init__(self, file_transfer):
BaseTransferButton.__init__(self, file_transfer)
self._ds_object = datastore.create()
file_transfer.connect('notify::state', self.__notify_state_cb)
file_transfer.connect('notify::transferred-bytes',
self.__notify_transferred_bytes_cb)
icons = Gio.content_type_get_icon(file_transfer.mime_type).props.names
icons.append('application-octet-stream')
for icon_name in icons:
icon_name = 'transfer-from-%s' % icon_name
file_name = get_icon_file_name(icon_name)
if file_name is not None:
self.props.icon_widget.props.icon_name = icon_name
self.notif_icon.props.icon_name = icon_name
break
icon_color = file_transfer.buddy.props.color
self.props.icon_widget.props.xo_color = icon_color
self.notif_icon.props.xo_color = icon_color
frame = jarabe.frame.get_view()
frame.add_notification(self.notif_icon,
Gtk.CornerType.TOP_LEFT)
示例11: initialize_journal_object
def initialize_journal_object(title=None, bundle_id=None,
activity_id=None, project_metadata=None,
icon_color=None, invited=False):
if not icon_color:
settings = Gio.Settings('org.sugarlabs.user')
icon_color = settings.get_string('color')
if not activity_id:
activity_id = activityfactory.create_activity_id()
jobject = datastore.create()
jobject.metadata['title'] = title
jobject.metadata['title_set_by_user'] = '0'
jobject.metadata['activity_id'] = activity_id
jobject.metadata['keep'] = '0'
jobject.metadata['preview'] = ''
jobject.metadata['icon-color'] = icon_color
jobject.file_path = ''
if bundle_id == PROJECT_BUNDLE_ID:
jobject.metadata['activity'] = PROJECT_BUNDLE_ID
elif project_metadata is not None:
jobject.metadata['mountpoints'] = ['/']
jobject.metadata['activity'] = bundle_id
jobject.metadata['share-scope'] = SCOPE_PRIVATE
jobject.metadata['launch-times'] = str(int(time.time()))
jobject.metadata['spent-times'] = '0'
jobject.metadata['project_id'] = project_metadata['uid']
# FIXME: We should be able to get an ID synchronously from the DS,
# then call async the actual create.
# http://bugs.sugarlabs.org/ticket/2169
datastore.write(jobject)
return jobject
示例12: create_journal_entry
def create_journal_entry(self, widget, data=None):
filename = self._filechooser.get_filename()
journal_entry = datastore.create()
journal_entry.metadata['title'] = self.make_new_filename(filename)
journal_entry.metadata['title_set_by_user'] = '1'
journal_entry.metadata['keep'] = '0'
file_mimetype = mime.get_for_file(filename)
if not file_mimetype is None:
journal_entry.metadata['mime_type'] = file_mimetype
journal_entry.metadata['buddies'] = ''
if file_mimetype.startswith('image/') and file_mimetype != 'image/vnd.djvu':
preview = self.create_preview_metadata(filename)
elif file_mimetype == 'application/x-cbz':
fname = self.extract_image(filename)
preview = self.create_preview_metadata(fname)
os.remove(fname)
else:
preview = ''
if not preview == '':
journal_entry.metadata['preview'] = dbus.ByteArray(preview)
else:
journal_entry.metadata['preview'] = ''
journal_entry.file_path = filename
datastore.write(journal_entry)
self.update_log_entries += '\n' + _('File %s copied to the Journal.') % filename
self.alert(_('Success'), _('%s added to Journal.')
% self.make_new_filename(filename))
示例13: _file_part_receiver
def _file_part_receiver(self, target, filename, part, numparts,
bytes, title=None, color=None, sender=None):
# ignore my own signal
if sender == self._tube.get_unique_name():
return
if target != self._tube.get_unique_name() and target != 'all':
return
# first chunk
if part == 1:
tmp_root = join(environ['SUGAR_ACTIVITY_ROOT'], 'instance')
temp_dir = tempfile.mkdtemp(dir=tmp_root)
chmod(temp_dir, 0777)
self.temp_file = join(temp_dir, 'game.zip')
self.files[filename] = self.temp_file
self.f = open(self.temp_file, 'a+b')
self.f.write(bytes)
percentage = int(float(part) / float(numparts) * 100.0)
self.game.set_load_mode(_('Receiving game') + ': '
+ str(percentage) + '% ' + _('done') + '.')
# last chunk
if part == numparts:
self.f.close()
# file = self.files[filename]
# Saves the zip in datastore
gameObject = datastore.create()
gameObject.metadata['title'] = title
gameObject.metadata['mime_type'] = 'application/x-memorize-project'
gameObject.metadata['icon-color'] = color
gameObject.file_path = self.temp_file
datastore.write(gameObject)
示例14: take_screenshot
def take_screenshot(self, capture_count=1):
''' Take a screenshot and save to the Journal '''
tmp_file_path = os.path.join(
os.environ['SUGAR_ACTIVITY_ROOT'], 'instance',
'screen_capture_' + str(capture_count) + '.png')
window = self.activity.wave.get_window()
width, height = window.get_width(), window.get_height()
surface = Gdk.Window.create_similar_surface(window,
cairo.CONTENT_COLOR,
width, height)
cr = cairo.Context(surface)
Gdk.cairo_set_source_window(cr, window, 0, 0)
cr.paint()
surface.write_to_png(tmp_file_path)
if os.path.exists(tmp_file_path):
dsobject = datastore.create()
try:
dsobject.metadata['title'] = '%s %d' % (_('Waveform'),
capture_count)
dsobject.metadata['keep'] = '0'
dsobject.metadata['buddies'] = ''
dsobject.metadata['preview'] = self._get_preview_data(surface)
dsobject.metadata['icon-color'] = self.activity.icon_colors
dsobject.metadata['mime_type'] = 'image/png'
dsobject.set_file_path(tmp_file_path)
datastore.write(dsobject)
finally:
dsobject.destroy()
del dsobject
os.remove(tmp_file_path)
return True
return False
示例15: __export_as_abiword_cb
def __export_as_abiword_cb(self, button):
jobject = datastore.create()
jobject.metadata['title'] = \
_('{} as Write document').format(self.metadata['title'])
jobject.metadata['mime_type'] = 'application/x-abiword'
preview = self.get_preview()
if preview is not None:
jobject.metadata['preview'] = dbus.ByteArray(preview)
path = os.path.join(self.get_activity_root(),
'instance', str(time.time()))
with open(path, 'w') as f:
f.write('<?xml version="1.0" encoding="UTF-8"?>\n<abiword>\n'
'<section>')
entries = []
for item in self._main_list.all():
markup = item[self._main_list.COLUMN_TEXT]
abiword = '<p><c>{}</c></p>'.format(markup) \
.replace('<b>', '<c props="font-weight:bold">') \
.replace('<i>', '<c props="font-style:italic;'
' font-weight:normal">') \
.replace('</b>', '</c>').replace('</i>', '</c>')
entries.append(abiword)
f.write('\n<p><c></c></p>\n'.join(entries))
f.write('</section>\n</abiword>')
jobject.file_path = path
datastore.write(jobject, transfer_ownership=True)
self._journal_alert(jobject.object_id, _('Success'), _('Your'
' Bibliography was saved to the journal as a Write'
' document'))
jobject.destroy()
del jobject