Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 3a09ae6c3249a3151488d947e3d8052f551f633d

Use ObjectChooser to add images to Journal Gallery View.
edit.py
(18 / 0)
  
1919from sugar3.graphics.toolbutton import ToolButton
2020from sugar3.graphics.toggletoolbutton import ToggleToolButton
2121
22from sugar3 import mime
23from sugar3.graphics.objectchooser import ObjectChooser
24
2225from infoslicer.widgets.Edit_Pane import Edit_Pane
2326from infoslicer.widgets.Format_Pane import Format_Pane
2427from infoslicer.widgets.Image_Pane import Image_Pane
6060
6161 self.txt_toggle = ToggleToolButton('ascii')
6262 self.img_toggle = ToggleToolButton('image')
63 self.jimg_chooser_toggle = ToolButton('image')
6364 self.jimg_toggle = ToggleToolButton('image')
6465
6566 self.txt_toggle.set_tooltip(_('Text'))
7373 [self.txt_toggle, self.img_toggle, self.jimg_toggle])
7474 toolbar.insert(self.img_toggle, -1)
7575
76 self.jimg_chooser_toggle.set_tooltip(_('Choose Journal Images'))
77 self.jimg_chooser_toggle.connect('clicked', self._toggle_image_chooser)
78 toolbar.insert(self.jimg_chooser_toggle, -1)
79
7680 self.jimg_toggle.set_tooltip(_('Journal Images'))
7781 self.jimg_toggle.connect('toggled', self._toggle_cb,
7882 [self.txt_toggle, self.img_toggle, self.jimg_toggle])
9898 self.txt_toggle.set_sensitive(False)
9999 self.img_toggle.set_sensitive(False)
100100 self.jimg_toggle.set_sensitive(False)
101
102 def _toggle_image_chooser(self, widget):
103 chooser = ObjectChooser(what_filter=mime.GENERIC_TYPE_IMAGE)
104 result = chooser.run()
105 if result == Gtk.ResponseType.ACCEPT:
106 jobject = chooser.get_selected_object()
107 if jobject and jobject.file_path:
108 title = str(jobject.metadata['title'])
109 path = str(jobject.file_path)
110 TABS[2].gallery.add_image(path, title)
101111
102112 def _toggle_cb(self, widget, toggles):
103113 for tab in TABS:
  
1# -*- coding: utf-8 -*-
2# Copyright (C) Aneesh Dogra <lionaneesh@gmail.com>
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8#
9# You should have received a copy of the GNU General Public License
10# along with this library; if not, write to the Free Software
11# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
12
13from sugar3.datastore import datastore
14
15def get_starred_images():
16 ''' Find all the Starred images in journal. '''
17 images = []
18 dsobjects, nobjects = datastore.find({'keep': '1'})
19 print "Found %d starred images" % (nobjects,)
20 for dsobj in dsobjects:
21 if hasattr(dsobj, 'metadata') and 'mime_type' in dsobj.metadata and \
22 dsobj.metadata['mime_type'][0:5] == 'image':
23 if 'title' in dsobj.metadata:
24 title = dsobj.metadata['title']
25 else:
26 title = ''
27 images.append((str(dsobj.file_path), str(title)))
28
29 return images
  
4747 """
4848
4949 def __init__(self):
50 self.image_list = journal.get_starred_images()
50 self.image_list = []
5151 GObject.GObject.__init__(self)
5252 self.current_index = -1
5353 self.source_article_id = -1
133133 if self.image_list == []:
134134 self.caption.set_text("No images were found in the journal.")
135135 self.image.clear()
136 return
136 return
137137 self.current_index = 0
138138 self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0])
139139 self.imagebuf = self.imagebuf.scale_simple(IMG_WIDTH, IMG_HEIGHT,
160160 sectionsdata = [Section_Data(0, self.source_article_id, 0, [paragraph1data, paragraph2data])]
161161 string = cPickle.dumps(sectionsdata)
162162 selection_data.set(atom, 8, string)
163
164 def add_image(self, image_path, title):
165 logger.debug('############# Journal_Journal_Gallery_View.add_image')
166 self.image_list.append((image_path, title))
167 logger.debug(self.image_list)
168 self.get_first_item()
  
88
99from gettext import gettext as _
1010from Editing_View import Editing_View
11from Journal_Gallery_View import Journal_Gallery_View
11from infoslicer.widgets.Journal_Gallery_View import Journal_Gallery_View
1212from infoslicer.processing.Article import Article
1313
1414logger = logging.getLogger('infoslicer')