finch/libgnt/pygnt/example/rss/gntrss-ui.py

Tue, 31 Jul 2007 12:03:46 +0000

author
Sadrul Habib Chowdhury <sadrul@pidgin.im>
date
Tue, 31 Jul 2007 12:03:46 +0000
changeset 19195
f1aaa37a842a
parent 19191
1596abb76093
child 19196
3477f5db57e1
permissions
-rwxr-xr-x

Add support for auto-refreshing. There should be some way to change the
refresh timeout for each feed, though.

19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1 #!/usr/bin/env python
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
2
19179
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
3 """
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
4 gr - An RSS-reader built using libgnt and feedparser.
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
5
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
6 Copyright (C) 2007 Sadrul Habib Chowdhury <sadrul@pidgin.im>
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
7
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
8 This application is free software; you can redistribute it and/or
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
9 modify it under the terms of the GNU Lesser General Public
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
10 License as published by the Free Software Foundation; either
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
11 version 2.1 of the License, or (at your option) any later version.
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
12
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
13 This application is distributed in the hope that it will be useful,
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
16 Lesser General Public License for more details.
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
17
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
18 You should have received a copy of the GNU Lesser General Public
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
19 License along with this application; if not, write to the Free Software
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
21 USA
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
22 """
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
23
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
24 """
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
25 This file deals with the UI part (gnt) of the application
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
26
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
27 TODO:
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
28 - Allow showing feeds of only selected 'category' and/or 'priority'. A different
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
29 window should be used to change such filtering.
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
30 - Display details of each item in its own window.
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
31 - Add search capability, and allow searching only in title/body. Also allow
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
32 filtering in the search results.
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
33 - Show the data and time for feed items (probably in a separate column .. perhaps not)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
34 - Have a simple way to add a feed.
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
35 - Allow renaming a feed.
19179
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
36 """
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
37
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
38 import gntrss
19191
1596abb76093 Parse HTML and show bold, italic etc. in the textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19189
diff changeset
39 import gnthtml
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
40 import gnt
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
41 import gobject
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
42 import sys
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
43
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
44 __version__ = "0.0.1alpha"
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
45 __author__ = "Sadrul Habib Chowdhury (sadrul@pidgin.im)"
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
46 __copyright__ = "Copyright 2007, Sadrul Habib Chowdhury"
19179
b3e5a04d839f Update the license info.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19178
diff changeset
47 __license__ = "GPL" # see full license statement above
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
48
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
49 gnt.gnt_init()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
50
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
51 class RssTree(gnt.Tree):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
52 __gsignals__ = {
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
53 'active_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT,))
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
54 }
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
55
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
56 def __init__(self):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
57 self.active = None
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
58 gnt.Tree.__init__(self)
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
59 gnt.set_flag(self, 8) # remove borders
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
60 self.connect('key_pressed', self.do_key_pressed)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
61
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
62 def set_active(self, active):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
63 if self.active == active:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
64 return
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
65 if self.active:
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
66 flag = gnt.TEXT_FLAG_NORMAL
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
67 if self.active.unread:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
68 flag = flag | gnt.TEXT_FLAG_BOLD
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
69 self.set_row_flags(self.active, flag)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
70 old = self.active
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
71 self.active = active
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
72 flag = gnt.TEXT_FLAG_UNDERLINE
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
73 if self.active.unread:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
74 flag = flag | gnt.TEXT_FLAG_BOLD
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
75 self.set_row_flags(self.active, flag)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
76 self.emit('active_changed', old)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
77
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
78 def do_key_pressed(self, null, text):
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
79 if text == '\r':
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
80 now = self.get_selection_data()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
81 self.set_active(now)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
82 return True
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
83 return False
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
84
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
85 gobject.type_register(RssTree)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
86
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
87 win = gnt.Box(homo = False, vert = True)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
88 win.set_toplevel(True)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
89 win.set_title("GntRss")
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
90 win.set_pad(0)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
91
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
92 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
93 # [[[ Generic feed/item callbacks
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
94 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
95 def feed_item_added(feed, item):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
96 add_feed_item(item)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
97
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
98 def add_feed(feed):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
99 if not feed.get_data('gntrss-connected'):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
100 feed.connect('added', feed_item_added)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
101 feed.connect('notify', update_feed_title)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
102 feed.set_data('gntrss-connected', True)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
103 feeds.add_row_after(feed, [feed.title, str(feed.unread)], None, None)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
104
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
105 def remove_item(item, feed):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
106 items.remove(item)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
107
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
108 def update_feed_item(item, property):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
109 if property.name == 'unread':
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
110 if feeds.active == item.parent:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
111 flag = 0
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
112 if item == items.active:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
113 flag = gnt.TEXT_FLAG_UNDERLINE
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
114 if item.unread:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
115 flag = flag | gnt.TEXT_FLAG_BOLD
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
116 else:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
117 flag = flag | gnt.TEXT_FLAG_NORMAL
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
118 items.set_row_flags(item, flag)
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
119
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
120 unread = item.parent.unread
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
121 if item.unread:
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
122 unread = unread + 1
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
123 else:
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
124 unread = unread - 1
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
125 item.parent.set_property('unread', unread)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
126
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
127 def add_feed_item(item):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
128 currentfeed = feeds.active
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
129 if item.parent != currentfeed:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
130 return
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
131 months = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
132 dt = str(item.date_parsed[2]) + "." + months[item.date_parsed[1]] + "." + str(item.date_parsed[0])
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
133 items.add_row_after(item, [str(item.title), dt], None, None)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
134 if item.unread:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
135 items.set_row_flags(item, gnt.TEXT_FLAG_BOLD)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
136 if not item.get_data('gntrss-connected'):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
137 item.set_data('gntrss-connected', True)
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
138 # this needs to happen *without* having to add the item in the tree
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
139 item.connect('notify', update_feed_item)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
140 item.connect('delete', remove_item)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
141
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
142 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
143 # ]]] Generic feed/item callbacks
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
144 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
145
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
146
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
147 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
148 # [[[ The list of feeds
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
149 ###
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
150
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
151 # 'Add Feed' dialog
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
152 add_feed_win = None
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
153 def add_feed_win_closed(win):
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
154 global add_feed_win
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
155 add_feed_win = None
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
156
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
157 def add_new_feed():
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
158 global add_feed_win
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
159
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
160 if add_feed_win:
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
161 gnt.gnt_window_present(add_feed_win)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
162 return
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
163 win = gnt.Window()
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
164 win.set_title("New Feed")
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
165
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
166 box = gnt.Box(False, False)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
167 label = gnt.Label("Link")
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
168 box.add_widget(label)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
169 entry = gnt.Entry("")
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
170 entry.set_size(40, 1)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
171 box.add_widget(entry)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
172
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
173 win.add_widget(box)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
174 win.show()
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
175 add_feed_win = win
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
176 add_feed_win.connect("destroy", add_feed_win_closed)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
177
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
178 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
179 # The active row in the feed-list has changed. Update the feed-item table.
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
180 def feed_active_changed(tree, old):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
181 items.remove_all()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
182 if not tree.active:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
183 return
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
184 update_items_title()
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
185 for item in tree.active.items:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
186 add_feed_item(item)
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
187 win.give_focus_to_child(items)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
188
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
189 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
190 # Check for the action keys and decide how to deal with them.
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
191 def feed_key_pressed(tree, text):
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
192 if tree.is_searching():
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
193 return
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
194 if text == 'r':
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
195 feed = tree.get_selection_data()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
196 tree.perform_action_key('j')
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
197 #tree.perform_action('move-down')
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
198 feed.refresh()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
199 elif text == 'R':
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
200 feeds = tree.get_rows()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
201 for feed in feeds:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
202 feed.refresh()
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
203 elif text == 'm':
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
204 feed = tree.get_selection_data()
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
205 if feed:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
206 feed.mark_read()
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
207 feed.set_property('unread', 0)
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
208 elif text == 'a':
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
209 add_new_feed()
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
210 else:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
211 return False
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
212 return True
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
213
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
214 feeds = RssTree()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
215 feeds.set_property('columns', 2)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
216 feeds.set_col_width(0, 20)
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
217 feeds.set_col_width(1, 6)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
218 feeds.set_column_resizable(0, False)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
219 feeds.set_column_resizable(1, False)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
220 feeds.set_column_is_right_aligned(1, True)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
221 feeds.set_show_separator(False)
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
222 feeds.set_column_title(0, "Feeds")
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
223 feeds.set_show_title(True)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
224
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
225 feeds.connect('active_changed', feed_active_changed)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
226 feeds.connect('key_pressed', feed_key_pressed)
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
227 gnt.unset_flag(feeds, 256) # Fix the width
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
228
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
229 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
230 # ]]] The list of feeds
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
231 ###
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
232
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
233 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
234 # [[[ The list of items in the feed
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
235 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
236
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
237 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
238 # The active item in the feed-item list has changed. Update the
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
239 # summary content.
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
240 def item_active_changed(tree, old):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
241 details.clear()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
242 if not tree.active:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
243 return
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
244 item = tree.active
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
245 details.append_text_with_flags(str(item.title) + "\n", gnt.TEXT_FLAG_BOLD)
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
246 details.append_text_with_flags("Link: ", gnt.TEXT_FLAG_BOLD)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
247 details.append_text_with_flags(str(item.link) + "\n", gnt.TEXT_FLAG_UNDERLINE)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
248 details.append_text_with_flags("Date: ", gnt.TEXT_FLAG_BOLD)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
249 details.append_text_with_flags(str(item.date) + "\n", gnt.TEXT_FLAG_NORMAL)
19191
1596abb76093 Parse HTML and show bold, italic etc. in the textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19189
diff changeset
250 parser = gnthtml.GParser(details)
1596abb76093 Parse HTML and show bold, italic etc. in the textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19189
diff changeset
251 parser.parse(str(item.summary))
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
252 item.mark_unread(False)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
253
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
254 if old and old.unread: # If the last selected item is marked 'unread', then make sure it's bold
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
255 items.set_row_flags(old, gnt.TEXT_FLAG_BOLD)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
256
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
257 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
258 # Look for action keys in the feed-item list.
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
259 def item_key_pressed(tree, text):
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
260 if tree.is_searching():
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
261 return
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
262 current = tree.get_selection_data()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
263 if text == 'M': # Mark all of the items 'read'
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
264 feed = feeds.active
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
265 if feed:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
266 feed.mark_read()
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
267 elif text == 'm': # Mark the current item 'read'
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
268 current.mark_unread(False)
19178
952bf9cb471d A few updates to the rss reader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19176
diff changeset
269 tree.perform_action_key('j')
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
270 elif text == 'U': # Mark the current item 'unread'
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
271 current.mark_unread(True)
19178
952bf9cb471d A few updates to the rss reader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19176
diff changeset
272 elif text == 'd':
952bf9cb471d A few updates to the rss reader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19176
diff changeset
273 current.remove()
952bf9cb471d A few updates to the rss reader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19176
diff changeset
274 tree.perform_action_key('j')
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
275 else:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
276 return False
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
277 return True
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
278
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
279 items = RssTree()
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
280 items.set_property('columns', 2)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
281 items.set_col_width(0, 40)
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
282 items.set_col_width(1, 11)
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
283 items.set_column_resizable(1, False)
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
284 items.set_column_title(0, "Items")
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
285 items.set_column_title(1, "Date")
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
286 items.set_show_title(True)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
287 items.connect('key_pressed', item_key_pressed)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
288 items.connect('active_changed', item_active_changed)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
289
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
290 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
291 # ]]] The list of items in the feed
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
292 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
293
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
294 #
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
295 # Update the title of the items list depending on the selection in the feed list
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
296 def update_items_title():
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
297 feed = feeds.active
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
298 if feed:
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
299 items.set_column_title(0, str(feed.title) + ": " + str(feed.unread) + "(" + str(len(feed.items)) + ")")
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
300 else:
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
301 items.set_column_title(0, "Items")
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
302 items.draw()
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
303
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
304 # The container on the top
19176
487103c2e783 The promised cleanups.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19175
diff changeset
305 line = gnt.Line(vertical = False)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
306
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
307 # The textview to show the details of a feed
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
308 details = gnt.TextView()
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
309 details.set_take_focus(True)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
310 details.set_flag(gnt.TEXT_VIEW_TOP_ALIGN)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
311 details.attach_scroll_widget(details)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
312
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
313 # Make it look nice
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
314 s = feeds.get_size()
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
315 size = gnt.screen_size()
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
316 size[0] = size[0] - s[0]
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
317 items.set_size(size[0], size[1] / 2)
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
318 details.set_size(size[0], size[1] / 2)
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
319
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
320 # Category tree
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
321 cat = gnt.Tree()
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
322 cat.set_property('columns', 1)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
323 cat.set_column_title(0, 'Category')
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
324 cat.set_show_title(True)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
325 gnt.set_flag(cat, 8) # remove borders
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
326
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
327 box = gnt.Box(homo = False, vert = False)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
328 box.set_pad(0)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
329
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
330 vbox = gnt.Box(homo = False, vert = True)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
331 vbox.set_pad(0)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
332 vbox.add_widget(feeds)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
333 vbox.add_widget(gnt.Line(False))
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
334 vbox.add_widget(cat)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
335 box.add_widget(vbox)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
336
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
337 box.add_widget(gnt.Line(True))
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
338
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
339 vbox = gnt.Box(homo = False, vert = True)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
340 vbox.set_pad(0)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
341 vbox.add_widget(items)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
342 vbox.add_widget(gnt.Line(False))
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
343 vbox.add_widget(details)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
344 box.add_widget(vbox)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
345
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
346 win.add_widget(box)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
347 win.show()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
348
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
349 def update_feed_title(feed, property):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
350 if property.name == 'title':
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
351 feeds.change_text(feed, 0, feed.title)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
352 elif property.name == 'unread':
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
353 feeds.change_text(feed, 1, str(feed.unread) + "(" + str(len(feed.items)) + ")")
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
354 flag = 0
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
355 if feeds.active == feed:
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
356 flag = gnt.TEXT_FLAG_UNDERLINE
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
357 update_items_title()
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
358 if feed.unread > 0:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
359 flag = flag | gnt.TEXT_FLAG_BOLD
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
360 feeds.set_row_flags(feed, flag)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
361
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
362 # populate everything
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
363 for feed in gntrss.feeds:
19176
487103c2e783 The promised cleanups.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19175
diff changeset
364 feed.refresh()
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
365 add_feed(feed)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
366
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
367 gnt.gnt_register_action("Stuff", add_new_feed)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
368 gnt.gnt_main()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
369
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
370 gnt.gnt_quit()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
371

mercurial