Implement setting the journal entry title from the toolbar.
This commit is contained in:
parent
309ddec8b7
commit
f3289d2e59
@ -84,7 +84,7 @@ class ClipboardBox(hippo.CanvasBox):
|
||||
if len(uris) > 1:
|
||||
raise NotImplementedError('Multiple uris in text/uri-list still not supported.')
|
||||
uri = urlparse.urlparse(uris[0])
|
||||
path, file_name = os.path.split(uri.path)
|
||||
path, file_name = os.path.split(uri[2])
|
||||
|
||||
# Copy the file, as it will be deleted when the dnd operation finishes.
|
||||
new_file_path = os.path.join(path, 'cb' + file_name)
|
||||
|
@ -59,7 +59,7 @@ class ActivityToolbar(gtk.Toolbar):
|
||||
if activity.jobject:
|
||||
self.title = gtk.Entry()
|
||||
self.title.set_text(activity.jobject['title'])
|
||||
self.title.connect('activate', self._title_activate_cb)
|
||||
self.title.connect('focus-out-event', self._title_focus_out_event_cb)
|
||||
self._add_widget(self.title, expand=True)
|
||||
|
||||
activity.jobject.connect('updated', self._jobject_updated_cb)
|
||||
@ -67,9 +67,10 @@ class ActivityToolbar(gtk.Toolbar):
|
||||
def _jobject_updated_cb(self, jobject):
|
||||
self.title.set_text(jobject['title'])
|
||||
|
||||
def _title_activate_cb(self, entry):
|
||||
self._activity.jobject['title'] = self.title.get_text()
|
||||
self._activity.save()
|
||||
def _title_focus_out_event_cb(self, entry, event):
|
||||
if self._activity.jobject['title'] != self.title.get_text():
|
||||
self._activity.jobject['title'] = self.title.get_text()
|
||||
self._activity.save()
|
||||
|
||||
def _add_widget(self, widget, expand=False):
|
||||
tool_item = gtk.ToolItem()
|
||||
@ -181,34 +182,27 @@ class Activity(Window, gtk.Container):
|
||||
elif create_jobject:
|
||||
logging.debug('Creating a jobject.')
|
||||
self.jobject = datastore.create()
|
||||
self.jobject['title'] = 'New entry'
|
||||
self.jobject['title'] = ''
|
||||
self.jobject['activity'] = self.get_service_name()
|
||||
self.jobject['date'] = str(time.time())
|
||||
self.jobject['icon'] = 'theme:object-text'
|
||||
self.jobject['icon'] = ''
|
||||
self.jobject['keep'] = '0'
|
||||
self.jobject['buddies'] = ''
|
||||
self.jobject['preview'] = ''
|
||||
self.jobject['icon-color'] = profile.get_color().to_string()
|
||||
from sugar import env
|
||||
self.jobject.file_path = os.path.join(env.get_profile_path(), 'test.txt')
|
||||
f = open(self.jobject.file_path, 'w')
|
||||
f.write('mec')
|
||||
f.close()
|
||||
self.jobject.file_path = ''
|
||||
try:
|
||||
datastore.write(self.jobject)
|
||||
except Exception, e:
|
||||
logging.error(e)
|
||||
else:
|
||||
self.jobject = None
|
||||
|
||||
self.connect('realize', self._realize_cb)
|
||||
|
||||
def _realize_cb(self, activity):
|
||||
try:
|
||||
self.read_file()
|
||||
except NotImplementedError:
|
||||
logging.debug('read_file() not implemented.')
|
||||
pass
|
||||
self.connect('focus-out-event', self._focus_out_event_cb)
|
||||
|
||||
def _focus_out_event_cb(self, widget, event):
|
||||
if self.jobject:
|
||||
self.save()
|
||||
|
||||
def read_file(self):
|
||||
"""
|
||||
@ -221,20 +215,18 @@ class Activity(Window, gtk.Container):
|
||||
"""
|
||||
Subclasses implement this method if they support saving data to objects
|
||||
in the journal. Can access the object through the jobject attribute.
|
||||
Must return the file path the data was saved to.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def save(self):
|
||||
"""Request that the activity is saved to the Journal."""
|
||||
try:
|
||||
file_path = self.write_file()
|
||||
self.jobject.file_path = file_path
|
||||
self.jobject.file_path = os.path.join('/tmp', '%i.txt' % time.time())
|
||||
self.write_file()
|
||||
except NotImplementedError:
|
||||
pass
|
||||
self.jobject.file_path = ''
|
||||
datastore.write(self.jobject)
|
||||
|
||||
|
||||
def _internal_joined_cb(self, activity, success, err):
|
||||
"""Callback when join has finished"""
|
||||
self._shared_activity.disconnect(self._join_id)
|
||||
|
@ -22,26 +22,48 @@ from sugar.datastore import dbus_helpers
|
||||
class DSObject(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
'updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||
([gobject.TYPE_PYOBJECT]))
|
||||
([]))
|
||||
}
|
||||
|
||||
def __init__(self, object_id, metadata, file_path):
|
||||
gobject.GObject.__init__(self)
|
||||
self.object_id = object_id
|
||||
self.metadata = metadata
|
||||
self.file_path = file_path
|
||||
self._metadata = metadata
|
||||
self._file_path = file_path
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.metadata[key]
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
self.metadata[key] = value
|
||||
if not self.metadata.has_key(key) or self.metadata[key] != value:
|
||||
self.metadata[key] = value
|
||||
self.emit('updated')
|
||||
|
||||
def get_metadata(self):
|
||||
return self._metadata
|
||||
|
||||
def set_metadata(self, metadata):
|
||||
if self._metadata != metadata:
|
||||
self._metadata = metadata
|
||||
self.emit('updated')
|
||||
|
||||
metadata = property(get_metadata, set_metadata)
|
||||
|
||||
def get_file_path(self):
|
||||
return self._file_path
|
||||
|
||||
def set_file_path(self, file_path):
|
||||
if self._file_path != file_path:
|
||||
self._file_path = file_path
|
||||
self.emit('updated')
|
||||
|
||||
file_path = property(get_file_path, set_file_path)
|
||||
|
||||
def get(object_id):
|
||||
logging.debug('datastore.get')
|
||||
metadata = dbus_helpers.get_properties(object_id)
|
||||
file_path = dbus_helpers.get_filename(object_id)
|
||||
logging.debug('filepath: ' + file_path)
|
||||
|
||||
ds_object = DSObject(object_id, metadata, file_path)
|
||||
# TODO: register the object for updates
|
||||
return ds_object
|
||||
|
@ -34,20 +34,47 @@ except Exception, e:
|
||||
_data_store = None
|
||||
logging.error(e)
|
||||
|
||||
def get_contents(filename):
|
||||
if not filename:
|
||||
return ''
|
||||
f = open(filename, "r")
|
||||
try:
|
||||
contents = f.read()
|
||||
finally:
|
||||
f.close()
|
||||
return contents
|
||||
|
||||
def create(properties, filename):
|
||||
logging.debug('dbus_helpers.create: %s, %s' % (properties, filename))
|
||||
try:
|
||||
logging.debug(get_contents(filename))
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
object_id = _data_store.create(dbus.Dictionary(properties), filename)
|
||||
logging.debug('dbus_helpers.create: ' + object_id)
|
||||
return object_id
|
||||
|
||||
def update(uid, properties, filename):
|
||||
logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, properties, filename))
|
||||
try:
|
||||
logging.debug(get_contents(filename))
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
_data_store.update(uid, dbus.Dictionary(properties), filename)
|
||||
|
||||
def get_properties(uid):
|
||||
return _data_store.get_properties(uid)
|
||||
props = _data_store.get_properties(uid)
|
||||
logging.debug('dbus_helpers.get_properties: %s, %s' % (uid, props))
|
||||
return props
|
||||
|
||||
def get_filename(uid):
|
||||
return _data_store.get_filename(uid)
|
||||
filename = _data_store.get_filename(uid)
|
||||
logging.debug('dbus_helpers.get_filename: %s, %s' % (uid, filename))
|
||||
try:
|
||||
logging.debug(get_contents(filename))
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
return filename
|
||||
|
||||
def find(query):
|
||||
return _data_store.find(query)
|
||||
|
Loading…
Reference in New Issue
Block a user