1
# Copyright (c) 2009 Entertainer Developers - See COPYING - GPLv2
2
'''Rss - Screen displays RSS feeds'''
6
from entertainerlib.gui.screens.screen import Screen
7
from entertainerlib.gui.widgets.label import Label
8
from entertainerlib.gui.widgets.texture import Texture
9
from entertainerlib.gui.widgets.text_menu import TextMenu
10
from entertainerlib.gui.widgets.list_indicator import ListIndicator
11
from entertainerlib.backend.components.feeds.feed_utils import FeedEntryParser
14
'''Screen displays RSS-feed titles and number of entries.'''
16
def __init__(self, feed_library, move_to_new_screen_callback):
17
Screen.__init__(self, 'Rss', move_to_new_screen_callback)
19
self.feed_order = 'UNREAD' # Feeds ordered by number of unread entries
20
self.theme = self.config.theme
21
self.library = feed_library
22
self.parser = FeedEntryParser()
24
# Screen Title (Displayed at the bottom left corner)
25
screen_title = Label(0.13, "screentitle", 0, 0.87, _("Headlines"))
26
self.add(screen_title)
29
icon = Texture(self.theme.getImage("rss_icon"), 0.05, 0.07)
33
title = Label(0.0833, "title", 0.13, 0.07, _("RSS Feeds"))
36
#We set the menus to None here so we can check if they exist later on
38
self.context_menu = None
40
# Display information box if there are not feeds available
41
if self.library.is_empty() or len(self.library.get_feeds()) == 0:
42
self._create_no_feeds_information()
45
self._create_context_menu()
46
self.menu = self._create_feed_menu()
49
self._create_feed_menu_indicator()
50
self.menu.active = True
51
self.context_menu.active = False
54
feeds_title = Label(0.04167, "title", 0.3953, 0.2, _("Feeds"))
58
unread_title = Label(0.04167, "title", 0.8053, 0.2, _("Unread"))
59
self.add(unread_title)
61
# Feed description text
62
desc_text = self.parser.strip_tags(
63
self.menu.selected_userdata.description)
65
self.description = Label(0.03646, "text", 0.3953, 0.9, desc_text)
66
self.description.set_ellipsize(pango.ELLIPSIZE_END)
67
self.description.set_use_markup(True)
68
self.description.set_size(0.5088, 0.0651)
69
self.add(self.description)
71
self.menu.connect('selected', self._handle_select)
72
self.menu.connect('moved', self._display_selected_feed)
73
self.menu.connect('activated', self._menu_activation)
74
self.context_menu.connect('selected', self._handle_select)
75
self.context_menu.connect('activated',
76
self._context_menu_activation)
78
def _create_feed_menu(self):
80
Create Feed-menu. This menu contains list of Feeds. It also displays
81
number of unread entries per feed.
83
menu = TextMenu(0.3807, 0.2604, 0.5124, 0.0781)
85
feeds = self.library.get_feeds(self.feed_order)
86
feeds_list = [[self.parser.strip_tags(feed.title), \
87
str(feed.get_number_of_unread()), feed] \
89
menu.async_add(feeds_list)
93
def _create_feed_menu_indicator(self):
94
'''Create a ListIndicator for feed menu.'''
95
self.li = ListIndicator(0.7, 0.9, 0.2, 0.045, ListIndicator.VERTICAL)
96
self.li.set_maximum(len(self.library.get_feeds(self.feed_order)))
99
def _create_context_menu(self):
101
Create RSS-feed context menu and add it to the screen.
102
This menu contains buttons for update and sorting.
104
self.context_menu = TextMenu(0.0732, 0.2604, 0.2196, 0.0781)
106
self.context_menu.add_item(_("Update feeds"))
107
self.context_menu.add_item(_("Mark all as read"))
108
self.context_menu.add_item(_("Sort by name"))
109
self.context_menu.add_item(_("Sort by unread"))
111
self.context_menu.active = False
112
self.add(self.context_menu)
114
def _create_no_feeds_information(self):
116
Create textures and labels for information screen. This is displayed
117
instead of feeds list if there are no feeds available. This screen helps
118
users to add new feeds to the system.
120
# Create warning icon
121
warning_icon = Texture(self.theme.getImage("warning_icon"), 0.28, 0.27)
122
self.add(warning_icon)
124
# Create warning title
125
info_title = Label(0.0625, "title", 0.3367, 0.2709,
126
_("No headlines available!"))
129
# Create warning help text
131
"To use headlines you have to add some RSS feeds with the Content "
132
"management tool. To do this, start the Content management tool, "
133
"open the 'RSS Feeds' tab and click the 'Add' button. Now you can "
134
"write an RSS feed URL in the text entry. You can get RSS feed "
135
"URLs from webpages that support RSS.")
136
info = Label(0.0417, "menuitem_inactive", 0.2804, 0.45, message)
137
info.set_size(0.5, 0.5208)
140
def update(self, event=None):
142
Update screen widgets. This is called always when screen is poped from
145
feeds = self.library.get_feeds(self.feed_order)
146
for idx, item in enumerate(self.menu.items):
149
item.update(self.parser.strip_tags(feed.title),
150
str(feed.get_number_of_unread()))
152
def _handle_up(self):
153
'''Handle UserEvent.NAVIGATE_UP.'''
157
self.context_menu.up()
159
def _handle_down(self):
160
'''Handle UserEvent.NAVIGATE_DOWN.'''
164
self.context_menu.down()
166
def _handle_left(self):
167
'''Handle UserEvent.NAVIGATE_LEFT.'''
169
self._context_menu_activation()
171
def _handle_right(self):
172
'''Handle UserEvent.NAVIGATE_RIGHT.'''
173
if not self.menu.active:
174
self._menu_activation()
176
def _handle_select(self, event=None):
177
'''Handle UserEvent.NAVIGATE_SELECT.'''
178
if not self.menu.active:
179
index = self.context_menu.selected_index
181
# Send message to bus and update screen
182
self.library.request_feed_update()
185
# Tell feedlibrary to mark all as read and then update screen
186
self.library.mark_all_as_read()
189
# Sort feeds by title ASC and update screen
190
self.feed_order = 'TITLE'
193
# Sort feeds by UNREAD DESC and update screen
194
self.feed_order = 'UNREAD'
197
# Feed selected from the menu. Change screen.
198
feed = self.menu.selected_userdata
199
kwargs = { 'feed' : feed }
200
self.callback("feed", kwargs)
202
def handle_user_event(self, event=None):
203
'''Handle screen specific user events unless the library is empty.'''
204
if self.library.is_empty() or len(self.library.get_feeds()) == 0:
207
Screen.handle_user_event(self, event)
209
def _display_selected_feed(self, actor=None):
210
'''Update of the list indicator and the description label'''
211
self.li.set_current(self.menu.selected_index + 1)
212
feed = self.menu.selected_userdata
213
self.description.set_text(self.parser.strip_tags(feed.description))
215
def _menu_activation(self, actor=None):
216
'''Handle the menu activation'''
217
self.menu.active = True
218
self.context_menu.active = False
219
self.li.show_position()
220
self.description.show()
222
def _context_menu_activation(self, actor=None):
223
'''Handle the context menu activation'''
224
self.menu.active = False
225
self.context_menu.active = True
226
self.li.hide_position()
227
self.description.hide()