Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAneesh Dogra <lionaneesh@gmail.com>2012-12-17 17:58:51 (GMT)
committer Aneesh Dogra <lionaneesh@gmail.com>2012-12-17 17:58:51 (GMT)
commit3a09ae6c3249a3151488d947e3d8052f551f633d (patch)
tree2c2768ef91dde19d8788302a9142bfb8e83ec358
parent16581dda4e4a43bdebb9c8c0665918fef93752a4 (diff)
Use ObjectChooser to add images to Journal Gallery View.
-rw-r--r--edit.py18
-rw-r--r--infoslicer/processing/Journal_Getter.py29
-rw-r--r--infoslicer/widgets/Journal_Gallery_View.py10
-rw-r--r--infoslicer/widgets/Journal_Image_Pane.py2
4 files changed, 27 insertions, 32 deletions
diff --git a/edit.py b/edit.py
index adada7d..9a6e2cf 100644
--- a/edit.py
+++ b/edit.py
@@ -19,6 +19,9 @@ from gettext import gettext as _
from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.toggletoolbutton import ToggleToolButton
+from sugar3 import mime
+from sugar3.graphics.objectchooser import ObjectChooser
+
from infoslicer.widgets.Edit_Pane import Edit_Pane
from infoslicer.widgets.Format_Pane import Format_Pane
from infoslicer.widgets.Image_Pane import Image_Pane
@@ -57,6 +60,7 @@ class ToolbarBuilder():
self.txt_toggle = ToggleToolButton('ascii')
self.img_toggle = ToggleToolButton('image')
+ self.jimg_chooser_toggle = ToolButton('image')
self.jimg_toggle = ToggleToolButton('image')
self.txt_toggle.set_tooltip(_('Text'))
@@ -69,6 +73,10 @@ class ToolbarBuilder():
[self.txt_toggle, self.img_toggle, self.jimg_toggle])
toolbar.insert(self.img_toggle, -1)
+ self.jimg_chooser_toggle.set_tooltip(_('Choose Journal Images'))
+ self.jimg_chooser_toggle.connect('clicked', self._toggle_image_chooser)
+ toolbar.insert(self.jimg_chooser_toggle, -1)
+
self.jimg_toggle.set_tooltip(_('Journal Images'))
self.jimg_toggle.connect('toggled', self._toggle_cb,
[self.txt_toggle, self.img_toggle, self.jimg_toggle])
@@ -91,6 +99,16 @@ class ToolbarBuilder():
self.img_toggle.set_sensitive(False)
self.jimg_toggle.set_sensitive(False)
+ def _toggle_image_chooser(self, widget):
+ chooser = ObjectChooser(what_filter=mime.GENERIC_TYPE_IMAGE)
+ result = chooser.run()
+ if result == Gtk.ResponseType.ACCEPT:
+ jobject = chooser.get_selected_object()
+ if jobject and jobject.file_path:
+ title = str(jobject.metadata['title'])
+ path = str(jobject.file_path)
+ TABS[2].gallery.add_image(path, title)
+
def _toggle_cb(self, widget, toggles):
for tab in TABS:
for i in tab.toolitems:
diff --git a/infoslicer/processing/Journal_Getter.py b/infoslicer/processing/Journal_Getter.py
deleted file mode 100644
index a4cb4f3..0000000
--- a/infoslicer/processing/Journal_Getter.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (C) Aneesh Dogra <lionaneesh@gmail.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# You should have received a copy of the GNU General Public License
-# along with this library; if not, write to the Free Software
-# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
-
-from sugar3.datastore import datastore
-
-def get_starred_images():
- ''' Find all the Starred images in journal. '''
- images = []
- dsobjects, nobjects = datastore.find({'keep': '1'})
- print "Found %d starred images" % (nobjects,)
- for dsobj in dsobjects:
- if hasattr(dsobj, 'metadata') and 'mime_type' in dsobj.metadata and \
- dsobj.metadata['mime_type'][0:5] == 'image':
- if 'title' in dsobj.metadata:
- title = dsobj.metadata['title']
- else:
- title = ''
- images.append((str(dsobj.file_path), str(title)))
-
- return images
diff --git a/infoslicer/widgets/Journal_Gallery_View.py b/infoslicer/widgets/Journal_Gallery_View.py
index 078cba6..e18cf11 100644
--- a/infoslicer/widgets/Journal_Gallery_View.py
+++ b/infoslicer/widgets/Journal_Gallery_View.py
@@ -47,7 +47,7 @@ class Journal_Gallery_View( Gtk.HBox ):
"""
def __init__(self):
- self.image_list = journal.get_starred_images()
+ self.image_list = []
GObject.GObject.__init__(self)
self.current_index = -1
self.source_article_id = -1
@@ -133,7 +133,7 @@ class Journal_Gallery_View( Gtk.HBox ):
if self.image_list == []:
self.caption.set_text("No images were found in the journal.")
self.image.clear()
- return
+ return
self.current_index = 0
self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0])
self.imagebuf = self.imagebuf.scale_simple(IMG_WIDTH, IMG_HEIGHT,
@@ -160,3 +160,9 @@ class Journal_Gallery_View( Gtk.HBox ):
sectionsdata = [Section_Data(0, self.source_article_id, 0, [paragraph1data, paragraph2data])]
string = cPickle.dumps(sectionsdata)
selection_data.set(atom, 8, string)
+
+ def add_image(self, image_path, title):
+ logger.debug('############# Journal_Journal_Gallery_View.add_image')
+ self.image_list.append((image_path, title))
+ logger.debug(self.image_list)
+ self.get_first_item()
diff --git a/infoslicer/widgets/Journal_Image_Pane.py b/infoslicer/widgets/Journal_Image_Pane.py
index 2666bf5..38c1c23 100644
--- a/infoslicer/widgets/Journal_Image_Pane.py
+++ b/infoslicer/widgets/Journal_Image_Pane.py
@@ -8,7 +8,7 @@ import logging
from gettext import gettext as _
from Editing_View import Editing_View
-from Journal_Gallery_View import Journal_Gallery_View
+from infoslicer.widgets.Journal_Gallery_View import Journal_Gallery_View
from infoslicer.processing.Article import Article
logger = logging.getLogger('infoslicer')