annotate finch/libgnt/pygnt/example/rss/gntrss-ui.py @ 18715:64a7b13d3b8d

Update the license info.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 29 Jul 2007 10:48:45 +0000
parents 121d1560346c
children 8b5082d54c1d
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
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
26 """
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 import gntrss
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 import gnt
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 import gobject
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 import sys
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33 __version__ = "0.0.1alpha"
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 __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
35 __copyright__ = "Copyright 2007, Sadrul Habib Chowdhury"
18715
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
36 __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
37
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
38 gnt.gnt_init()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
39
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
40 class RssTree(gnt.Tree):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
41 __gsignals__ = {
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
42 'active_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT,)),
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43 'key_pressed' : 'override'
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44 }
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
46 def __init__(self):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47 self.active = None
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
48 gnt.Tree.__init__(self)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
49
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
50 def set_active(self, active):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51 if self.active == active:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
52 return
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
53 if self.active:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
54 self.set_row_flags(self.active, gnt.TEXT_FLAG_NORMAL)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
55 old = self.active
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
56 self.active = active
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57 self.set_row_flags(self.active, gnt.TEXT_FLAG_UNDERLINE)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 self.emit('active_changed', old)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
59
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
60 def do_key_pressed(self, text):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
61 if text == '\r':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
62 now = self.get_selection_data()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
63 self.set_active(now)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
64 return True
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
65 return False
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
66
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
67 gobject.type_register(RssTree)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
68
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
69 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
70 win.set_toplevel(True)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
71 win.set_title("GntRss")
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
72 win.set_pad(0)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
73
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
74 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
75 # [[[ Generic feed/item callbacks
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
76 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
77 def feed_item_added(feed, item):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
78 add_feed_item(item)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
79
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
80 def add_feed(feed):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
81 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
82 feed.connect('added', feed_item_added)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
83 feed.connect('notify', update_feed_title)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
84 feed.set_data('gntrss-connected', True)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
85 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
86
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
87 def remove_item(item, feed):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
88 items.remove(item)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
89
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
90 def update_feed_item(item, property):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
91 if property.name == 'unread':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
92 if feeds.active != item.parent:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
93 return
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
94 flag = 0
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
95 if item == items.active:
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
96 flag = gnt.TEXT_FLAG_UNDERLINE
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
97 if item.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
98 item.parent.unread = item.parent.unread + 1
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
99 items.set_row_flags(item, flag | gnt.TEXT_FLAG_BOLD)
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
100 else:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
101 item.parent.unread = item.parent.unread - 1
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
102 items.set_row_flags(item, flag | gnt.TEXT_FLAG_NORMAL)
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
103 item.parent.notify('unread')
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 add_feed_item(item):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
106 currentfeed = feeds.active
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
107 if item.parent != currentfeed:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
108 return
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
109 items.add_row_after(item, [str(item.title)], None, None)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
110 if item.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
111 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
112 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
113 item.set_data('gntrss-connected', True)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
114 item.connect('notify', update_feed_item)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
115 item.connect('delete', remove_item)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
116
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
117 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
118 # ]]] Generic feed/item callbacks
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
119 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
120
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
121
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
122 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
123 # [[[ The list of feeds
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
124 ###
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
125
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 # 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
128 def feed_active_changed(tree, old):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
129 items.remove_all()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
130 if not tree.active:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
131 return
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
132 for item in tree.active.items:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
133 add_feed_item(item)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
134
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
135 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
136 # 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
137 def feed_key_pressed(tree, text):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
138 if text == 'r':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
139 feed = tree.get_selection_data()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
140 tree.perform_action_key('j')
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
141 #tree.perform_action('move-down')
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
142 feed.refresh()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
143 elif text == 'R':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
144 feeds = tree.get_rows()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
145 for feed in feeds:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
146 feed.refresh()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
147 else:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
148 return False
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
149 return True
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
150
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
151 feeds = RssTree()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
152 feeds.set_property('columns', 2)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
153 feeds.set_col_width(0, 20)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
154 feeds.set_col_width(1, 4)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
155 feeds.set_column_resizable(0, False)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
156 feeds.set_column_resizable(1, False)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
157 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
158 feeds.set_show_separator(False)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
159
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
160 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
161 feeds.connect('key_pressed', feed_key_pressed)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
162
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
163 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
164 # ]]] The list of feeds
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
165 ###
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
166
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
167 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
168 # [[[ 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
169 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
170
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
171 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
172 # 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
173 # summary content.
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
174 def item_active_changed(tree, old):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
175 details.clear()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
176 if not tree.active:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
177 return
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
178 item = tree.active
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
179 details.append_text_with_flags(str(item.title) + "\n", gnt.TEXT_FLAG_BOLD)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
180 details.append_text_with_flags(str(item.summary), gnt.TEXT_FLAG_NORMAL)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
181 details.scroll(0)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
182 if item.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
183 item.set_property('unread', False)
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
184 if old and old.unread:
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
185 old.set_property('unread', True)
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
186
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
187 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
188 # 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
189 def item_key_pressed(tree, text):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
190 current = tree.get_selection_data()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
191 if text == 'M': # Mark all of the items 'read'
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
192 all = tree.get_rows()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
193 for item in all:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
194 item.unread = False
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
195 elif text == 'm': # Mark the current item 'read'
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
196 if current.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
197 current.set_property('unread', False)
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
198 tree.perform_action_key('j')
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
199 elif text == 'U': # Mark the current item 'unread'
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
200 if not current.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
201 current.set_property('unread', True)
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
202 elif text == 'd':
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
203 current.remove()
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
204 tree.perform_action_key('j')
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
205 else:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
206 return False
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
207 return True
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
208
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
209 items = RssTree()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
210 items.set_property('columns', 1)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
211 items.set_col_width(0, 40)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
212 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
213 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
214
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
215 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
216 # ]]] 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
217 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
218
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
219 # The container on the top
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
220 box = gnt.Box(homo = False, vert = False)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
221 box.set_pad(0)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
222 box.add_widget(feeds)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
223 box.add_widget(items)
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 win.add_widget(box)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
226
18682
254823d66aa5 The promised cleanups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18681
diff changeset
227 line = gnt.Line(vertical = False)
254823d66aa5 The promised cleanups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18681
diff changeset
228 win.add_widget(line)
18681
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 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
231 details = gnt.TextView()
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 win.add_widget(details)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
234
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
235 browser = gnt.Button("Open in Browser")
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
236 win.add_widget(browser)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
237 details.attach_scroll_widget(browser)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
238
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
239 win.show()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
240
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
241 def update_feed_title(feed, property):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
242 if property.name == 'title':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
243 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
244 elif property.name == 'unread':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
245 feeds.change_text(feed, 1, str(feed.unread))
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
246
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
247 # populate everything
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
248 for feed in gntrss.feeds:
18682
254823d66aa5 The promised cleanups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18681
diff changeset
249 feed.refresh()
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
250 add_feed(feed)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
251
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
252 gnt.gnt_main()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
253
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
254 gnt.gnt_quit()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
255