Show 'No book' message when Read starts from scratch
When the user starts a new instance of Read the 'No book' message is
shown with a button to 'Choose something to read' that opens the Object Chooser.
Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
Manuel Kaufmann authored 11 years ago
Gonzalo Odiard committed 11 years ago
0 | import logging | |
1 | ||
2 | from gi.repository import Gtk | |
3 | ||
4 | from sugar3.graphics import style | |
5 | from sugar3.graphics.icon import Icon | |
6 | ||
7 | ||
8 | def show(activity, icon_name, message, btn_label, btn_callback): | |
9 | empty_widgets = Gtk.EventBox() | |
10 | empty_widgets.modify_bg(Gtk.StateType.NORMAL, | |
11 | style.COLOR_WHITE.get_gdk_color()) | |
12 | ||
13 | vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) | |
14 | mvbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) | |
15 | vbox.pack_start(mvbox, True, False, 0) | |
16 | ||
17 | image_icon = Icon(pixel_size=style.LARGE_ICON_SIZE, | |
18 | icon_name=icon_name, | |
19 | stroke_color=style.COLOR_BUTTON_GREY.get_svg(), | |
20 | fill_color=style.COLOR_TRANSPARENT.get_svg()) | |
21 | mvbox.pack_start(image_icon, False, False, style.DEFAULT_PADDING) | |
22 | ||
23 | label = Gtk.Label('<span foreground="%s"><b>%s</b></span>' % | |
24 | (style.COLOR_BUTTON_GREY.get_html(), | |
25 | message)) | |
26 | label.set_use_markup(True) | |
27 | mvbox.pack_start(label, False, False, style.DEFAULT_PADDING) | |
28 | ||
29 | hbox = Gtk.Box() | |
30 | open_image_btn = Gtk.Button() | |
31 | open_image_btn.connect('clicked', btn_callback) | |
32 | add_image = Gtk.Image.new_from_stock(Gtk.STOCK_ADD, | |
33 | Gtk.IconSize.BUTTON) | |
34 | buttonbox = Gtk.Box() | |
35 | buttonbox.pack_start(add_image, False, True, 0) | |
36 | buttonbox.pack_end(Gtk.Label(btn_label), True, True, 5) | |
37 | open_image_btn.add(buttonbox) | |
38 | hbox.pack_start(open_image_btn, True, False, 0) | |
39 | mvbox.pack_start(hbox, False, False, style.DEFAULT_PADDING) | |
40 | ||
41 | empty_widgets.add(vbox) | |
42 | empty_widgets.show_all() | |
43 | logging.error('Showing empty Panel') | |
44 | activity.set_canvas(empty_widgets) |
0 | <?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [ | |
1 | <!ENTITY stroke_color "#010101"> | |
2 | <!ENTITY fill_color "#FFFFFF"> | |
3 | ]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="activity-read"> | |
4 | <path d="M27.904,11.023h-0.002 c0-0.002-1.71-2.053-9.376-2.504C10.86,8.07,6.843,10.121,6.84,10.122c-1.898,0.619-3.495,1.735-3.495,3.494v27.702 c0,2.025,1.235,3.494,3.495,3.494c0.003,0,4.41-1.35,10.004-1.35c5.589-0.001,11.061,2.253,11.061,2.253" display="inline" fill="&fill_color;" stroke="&stroke_color;" stroke-linejoin="round" stroke-width="3.5"/> | |
5 | <path d="M27.898,11.023 L27.898,11.023c0-0.002,1.715-2.053,9.377-2.504c7.668-0.449,11.686,1.602,11.688,1.603c1.897,0.619,3.494,1.735,3.494,3.494 v27.702c0,2.025-1.233,3.494-3.494,3.494c-0.003,0-4.409-1.35-10.004-1.35c-5.589-0.001-11.062,2.253-11.062,2.253" display="inline" fill="&fill_color;" stroke="&stroke_color;" stroke-linejoin="round" stroke-width="3.5"/> | |
6 | ||
7 | <line display="inline" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5" x1="27.898" x2="27.9" y1="11.023" y2="45.717"/> | |
8 | <path d=" M32.566,44.275c0,0-0.031,2.906-4.666,2.906c-4.632,0-4.663-2.906-4.663-2.906" display="inline" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5"/> | |
9 | </g></svg> |
24 | 24 | import md5 |
25 | 25 | import StringIO |
26 | 26 | import cairo |
27 | import emptypanel | |
27 | 28 | |
28 | 29 | import dbus |
29 | 30 | from gi.repository import GObject |
335 | 336 | self.connect("joined", self._joined_cb) |
336 | 337 | elif self._object_id is None: |
337 | 338 | # Not joining, not resuming |
338 | self._show_journal_object_picker() | |
339 | emptypanel.show(self, 'activity-read', | |
340 | _('No book'), _('Choose something to read'), | |
341 | self._show_journal_object_picker_cb) | |
339 | 342 | |
340 | 343 | def _create_back_button(self): |
341 | 344 | back = ToolButton('go-previous-paired') |
626 | 629 | else: |
627 | 630 | logging.debug('link "%s" not found in the toc model', current_link) |
628 | 631 | |
629 | def _show_journal_object_picker(self): | |
632 | def _show_journal_object_picker_cb(self, button): | |
630 | 633 | """Show the journal object picker to load a document. |
631 | 634 | |
632 | 635 | This is for if Read is launched without a document. |
642 | 645 | jobject = chooser.get_selected_object() |
643 | 646 | if jobject and jobject.file_path: |
644 | 647 | self.read_file(jobject.file_path) |
648 | self.set_canvas(self._vbox) | |
645 | 649 | finally: |
646 | 650 | chooser.destroy() |
647 | 651 | del chooser |