annotate finch/libgnt/pygnt/example/rss/gntrss-ui.py @ 18727:778f4fc8cbcc

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