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

Sat, 11 Aug 2007 04:17:15 +0000

author
Sadrul Habib Chowdhury <sadrul@pidgin.im>
date
Sat, 11 Aug 2007 04:17:15 +0000
changeset 19233
50476028f83f
parent 19196
3477f5db57e1
child 19859
71d37b57eff2
permissions
-rwxr-xr-x

Fix a few small bugs in the example code.

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
19196
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
56 __gntbindings__ = {
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
57 'jump-next-unread' : ('jump_next_unread', 'J')
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
58 }
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
59
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
60 def jump_next_unread(self, null):
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
61 first = None
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
62 next = None
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
63 all = self.get_rows()
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
64 for item in all:
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
65 if item.unread:
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
66 if next:
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
67 first = item
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
68 break
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
69 elif not first and self.active != item:
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
70 first = item
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
71 if self.active == item:
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
72 next = item
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
73 if first:
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
74 self.set_active(first)
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
75 self.set_selected(first)
19233
50476028f83f Fix a few small bugs in the example code.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19196
diff changeset
76 return True
19196
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
77
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
78 def __init__(self):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
79 self.active = None
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
80 gnt.Tree.__init__(self)
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
81 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
82 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
83
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
84 def set_active(self, active):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
85 if self.active == active:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
86 return
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
87 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
88 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
89 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
90 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
91 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
92 old = self.active
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
93 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
94 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
95 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
96 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
97 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
98 self.emit('active_changed', old)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
99
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
100 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
101 if text == '\r':
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
102 now = self.get_selection_data()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
103 self.set_active(now)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
104 return True
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
105 return False
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
106
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
107 gobject.type_register(RssTree)
19196
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
108 gnt.register_bindings(RssTree)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
109
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
110 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
111 win.set_toplevel(True)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
112 win.set_title("GntRss")
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
113 win.set_pad(0)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
114
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
115 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
116 # [[[ Generic feed/item callbacks
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
117 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
118 def feed_item_added(feed, item):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
119 add_feed_item(item)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
120
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
121 def add_feed(feed):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
122 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
123 feed.connect('added', feed_item_added)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
124 feed.connect('notify', update_feed_title)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
125 feed.set_data('gntrss-connected', True)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
126 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
127
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
128 def remove_item(item, feed):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
129 items.remove(item)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
130
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
131 def update_feed_item(item, property):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
132 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
133 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
134 flag = 0
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
135 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
136 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
137 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
138 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
139 else:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
140 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
141 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
142
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
143 unread = item.parent.unread
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
144 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
145 unread = unread + 1
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
146 else:
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
147 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
148 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
149
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
150 def add_feed_item(item):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
151 currentfeed = feeds.active
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
152 if item.parent != currentfeed:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
153 return
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
154 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
155 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
156 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
157 if item.unread:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
158 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
159 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
160 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
161 # 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
162 item.connect('notify', update_feed_item)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
163 item.connect('delete', remove_item)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
164
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
165 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
166 # ]]] Generic feed/item callbacks
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
167 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
168
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
169
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
170 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
171 # [[[ The list of feeds
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
172 ###
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
173
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
174 # 'Add Feed' dialog
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
175 add_feed_win = None
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
176 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
177 global add_feed_win
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
178 add_feed_win = None
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
179
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
180 def add_new_feed():
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
181 global add_feed_win
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
182
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
183 if add_feed_win:
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
184 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
185 return
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
186 win = gnt.Window()
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
187 win.set_title("New Feed")
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
188
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
189 box = gnt.Box(False, False)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
190 label = gnt.Label("Link")
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
191 box.add_widget(label)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
192 entry = gnt.Entry("")
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
193 entry.set_size(40, 1)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
194 box.add_widget(entry)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
195
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
196 win.add_widget(box)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
197 win.show()
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
198 add_feed_win = win
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
199 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
200
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
201 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
202 # 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
203 def feed_active_changed(tree, old):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
204 items.remove_all()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
205 if not tree.active:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
206 return
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
207 update_items_title()
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
208 for item in tree.active.items:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
209 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
210 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
211
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
212 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
213 # 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
214 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
215 if tree.is_searching():
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
216 return
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
217 if text == 'r':
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
218 feed = tree.get_selection_data()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
219 tree.perform_action_key('j')
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
220 #tree.perform_action('move-down')
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
221 feed.refresh()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
222 elif text == 'R':
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
223 feeds = tree.get_rows()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
224 for feed in feeds:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
225 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
226 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
227 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
228 if feed:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
229 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
230 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
231 elif text == 'a':
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
232 add_new_feed()
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
233 else:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
234 return False
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
235 return True
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 feeds = RssTree()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
238 feeds.set_property('columns', 2)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
239 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
240 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
241 feeds.set_column_resizable(0, False)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
242 feeds.set_column_resizable(1, False)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
243 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
244 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
245 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
246 feeds.set_show_title(True)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
247
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
248 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
249 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
250 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
251
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
252 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
253 # ]]] The list of feeds
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
254 ###
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
255
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 # [[[ 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
258 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
259
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
260 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
261 # 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
262 # summary content.
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
263 def item_active_changed(tree, old):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
264 details.clear()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
265 if not tree.active:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
266 return
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
267 item = tree.active
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
268 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
269 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
270 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
271 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
272 details.append_text_with_flags(str(item.date) + "\n", gnt.TEXT_FLAG_NORMAL)
19196
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
273 details.append_text_with_flags("\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
274 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
275 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
276 item.mark_unread(False)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
277
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
278 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
279 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
280
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
281 #
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
282 # 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
283 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
284 if tree.is_searching():
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
285 return
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
286 current = tree.get_selection_data()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
287 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
288 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
289 if feed:
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
290 feed.mark_read()
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
291 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
292 current.mark_unread(False)
19178
952bf9cb471d A few updates to the rss reader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19176
diff changeset
293 tree.perform_action_key('j')
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
294 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
295 current.mark_unread(True)
19178
952bf9cb471d A few updates to the rss reader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19176
diff changeset
296 elif text == 'd':
952bf9cb471d A few updates to the rss reader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19176
diff changeset
297 current.remove()
952bf9cb471d A few updates to the rss reader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19176
diff changeset
298 tree.perform_action_key('j')
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
299 else:
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
300 return False
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
301 return True
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
302
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
303 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
304 items.set_property('columns', 2)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
305 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
306 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
307 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
308 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
309 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
310 items.set_show_title(True)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
311 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
312 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
313
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
314 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
315 # ]]] 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
316 ####
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
317
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
318 #
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
319 # 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
320 def update_items_title():
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
321 feed = feeds.active
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
322 if feed:
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
323 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
324 else:
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
325 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
326 items.draw()
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
327
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
328 # The container on the top
19176
487103c2e783 The promised cleanups.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19175
diff changeset
329 line = gnt.Line(vertical = False)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
330
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
331 # 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
332 details = gnt.TextView()
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
333 details.set_take_focus(True)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
334 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
335 details.attach_scroll_widget(details)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
336
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
337 # 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
338 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
339 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
340 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
341 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
342 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
343
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
344 # Category tree
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
345 cat = gnt.Tree()
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
346 cat.set_property('columns', 1)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
347 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
348 cat.set_show_title(True)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
349 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
350
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
351 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
352 box.set_pad(0)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
353
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
354 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
355 vbox.set_pad(0)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
356 vbox.add_widget(feeds)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
357 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
358 vbox.add_widget(cat)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
359 box.add_widget(vbox)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
360
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
361 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
362
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
363 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
364 vbox.set_pad(0)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
365 vbox.add_widget(items)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
366 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
367 vbox.add_widget(details)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
368 box.add_widget(vbox)
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
369
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
370 win.add_widget(box)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
371 win.show()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
372
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
373 def update_feed_title(feed, property):
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
374 if property.name == 'title':
19196
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
375 if feed.customtitle:
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
376 title = feed.customtitle
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
377 else:
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
378 title = feed.title
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
379 feeds.change_text(feed, 0, title)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
380 elif property.name == 'unread':
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
381 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
382 flag = 0
19186
6426c0906fc8 Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19179
diff changeset
383 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
384 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
385 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
386 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
387 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
388 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
389
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
390 # populate everything
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
391 for feed in gntrss.feeds:
19176
487103c2e783 The promised cleanups.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19175
diff changeset
392 feed.refresh()
19196
3477f5db57e1 Use __gntbindings__ to specify a 'jump-next-unread' action bound to 'J'. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19191
diff changeset
393 feed.set_auto_refresh(True)
19175
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
394 add_feed(feed)
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
395
19189
d72a994ca5ac Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19186
diff changeset
396 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
397 gnt.gnt_main()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
398
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
399 gnt.gnt_quit()
d6cea4e8560f A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
400

mercurial