annotate finch/libgnt/pygnt/example/rss/gntrss-ui.py @ 18714:121d1560346c

A few updates to the rss reader.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 29 Jul 2007 10:37:10 +0000
parents 254823d66aa5
children 64a7b13d3b8d
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
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 # A very simple and stupid RSS reader
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
4 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
5 # Uses the Universal Feed Parser
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
6 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8 import gntrss
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9 import gnt
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10 import gobject
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
11 import sys
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
13 __version__ = "0.0.1alpha"
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14 __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
15 __copyright__ = "Copyright 2007, Sadrul Habib Chowdhury"
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
16 __license__ = "GPL" # see full license statement below
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
17
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
18 gnt.gnt_init()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
19
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
20 class RssTree(gnt.Tree):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
21 __gsignals__ = {
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
22 '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
23 'key_pressed' : 'override'
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 }
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
25
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
26 def __init__(self):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27 self.active = None
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 gnt.Tree.__init__(self)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 def set_active(self, active):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 if self.active == active:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 return
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33 if self.active:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 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
35 old = self.active
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36 self.active = active
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
37 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
38 self.emit('active_changed', old)
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 def do_key_pressed(self, text):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
41 if text == '\r':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
42 now = self.get_selection_data()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43 self.set_active(now)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44 return True
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45 return False
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
46
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47 gobject.type_register(RssTree)
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 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
50 win.set_toplevel(True)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51 win.set_title("GntRss")
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
52 win.set_pad(0)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
53
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 # [[[ Generic feed/item callbacks
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
56 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57 def feed_item_added(feed, item):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 add_feed_item(item)
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 add_feed(feed):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
61 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
62 feed.connect('added', feed_item_added)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
63 feed.connect('notify', update_feed_title)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
64 feed.set_data('gntrss-connected', True)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
65 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
66
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
67 def remove_item(item, feed):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
68 items.remove(item)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
69
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
70 def update_feed_item(item, property):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
71 if property.name == 'unread':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
72 if feeds.active != item.parent:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
73 return
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
74 flag = 0
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
75 if item == items.active:
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
76 flag = gnt.TEXT_FLAG_UNDERLINE
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
77 if item.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
78 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
79 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
80 else:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
81 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
82 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
83 item.parent.notify('unread')
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 def add_feed_item(item):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
86 currentfeed = feeds.active
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
87 if item.parent != currentfeed:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
88 return
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
89 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
90 if item.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
91 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
92 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
93 item.set_data('gntrss-connected', True)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
94 item.connect('notify', update_feed_item)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
95 item.connect('delete', remove_item)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
96
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 # ]]] Generic feed/item callbacks
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
99 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
100
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
101
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
102 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
103 # [[[ The list of feeds
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
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
106 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
107 # 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
108 def feed_active_changed(tree, old):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
109 items.remove_all()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
110 if not tree.active:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
111 return
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
112 for item in tree.active.items:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
113 add_feed_item(item)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
114
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
115 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
116 # 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
117 def feed_key_pressed(tree, text):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
118 if text == 'r':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
119 feed = tree.get_selection_data()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
120 tree.perform_action_key('j')
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
121 #tree.perform_action('move-down')
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
122 feed.refresh()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
123 elif text == 'R':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
124 feeds = tree.get_rows()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
125 for feed in feeds:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
126 feed.refresh()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
127 else:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
128 return False
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
129 return True
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
130
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
131 feeds = RssTree()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
132 feeds.set_property('columns', 2)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
133 feeds.set_col_width(0, 20)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
134 feeds.set_col_width(1, 4)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
135 feeds.set_column_resizable(0, False)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
136 feeds.set_column_resizable(1, False)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
137 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
138 feeds.set_show_separator(False)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
139
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
140 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
141 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
142
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
143 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
144 # ]]] The list of feeds
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 items in the feed
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
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
151 #
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
152 # 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
153 # summary content.
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
154 def item_active_changed(tree, old):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
155 details.clear()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
156 if not tree.active:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
157 return
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
158 item = tree.active
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
159 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
160 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
161 details.scroll(0)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
162 if item.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
163 item.set_property('unread', False)
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
164 if old and old.unread:
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
165 old.set_property('unread', True)
18681
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 # 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
169 def item_key_pressed(tree, text):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
170 current = tree.get_selection_data()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
171 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
172 all = tree.get_rows()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
173 for item in all:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
174 item.unread = False
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
175 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
176 if current.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
177 current.set_property('unread', False)
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
178 tree.perform_action_key('j')
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
179 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
180 if not current.unread:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
181 current.set_property('unread', True)
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
182 elif text == 'd':
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
183 current.remove()
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
184 tree.perform_action_key('j')
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
185 else:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
186 return False
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
187 return True
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 items = RssTree()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
190 items.set_property('columns', 1)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
191 items.set_col_width(0, 40)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
192 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
193 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
194
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
195 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
196 # ]]] 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
197 ####
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
198
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
199 # The container on the top
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
200 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
201 box.set_pad(0)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
202 box.add_widget(feeds)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
203 box.add_widget(items)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
204
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
205 win.add_widget(box)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
206
18682
254823d66aa5 The promised cleanups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18681
diff changeset
207 line = gnt.Line(vertical = False)
254823d66aa5 The promised cleanups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18681
diff changeset
208 win.add_widget(line)
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
209
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
210 # 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
211 details = gnt.TextView()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
212
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
213 win.add_widget(details)
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 browser = gnt.Button("Open in Browser")
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
216 win.add_widget(browser)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
217 details.attach_scroll_widget(browser)
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 win.show()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
220
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
221 def update_feed_title(feed, property):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
222 if property.name == 'title':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
223 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
224 elif property.name == 'unread':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
225 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
226
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
227 # populate everything
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
228 for feed in gntrss.feeds:
18682
254823d66aa5 The promised cleanups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18681
diff changeset
229 feed.refresh()
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
230 add_feed(feed)
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 gnt.gnt_main()
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 gnt.gnt_quit()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
235