~bakrss.developers/bakrss/main

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import feedparser
import pygtk
pygtk.require('2.0')
import gtk
import gtk.glade
import gobject
from GuiTools import Add_dialog, About_dialog
from dbaseclass import DbaseFeed
import webbrowser

class Feed:
    #sito="http://feeds.delicious.com/v2/rss/twelvetone"
    #sito="http://feeds.feedburner.com/pollycokenet"
    #sito={"Twelvetone":"http://feeds.delicious.com/v2/rss/twelvetone","PollyCoke":"http://feeds.feedburner.com/pollycokenet"}

    def __init__(self):
        #Signals required for glade widgets
        signals = {"gtk_main_quit" : gtk.main_quit,
                   "on_add_btn_clicked" : self.on_add_btn_clicked,
                   "on_refresh_btn_clicked" : self.on_refresh_btn_clicked,
                   "on_check_screen_toggled" : self.on_check_screen_toggled,
                    "on_aboutmenuitm_activate" : self.on_aboutmenuitm_activate,
                   }
        #Glade file init
        self.glade = gtk.glade.XML("Gui.glade", "main_window")
        self.glade.signal_autoconnect(signals)
        self.window = self.glade.get_widget("main_window")
        self.scrolledwindow = self.glade.get_widget("scrolledwindow")
        self.add_btn = self.glade.get_widget("add_btn")
        self.refresh_btn = self.glade.get_widget("refresh_btn")
        self.check_screen = self.glade.get_widget("check_screen")
        #questa e' la scrolledwindow per gtkmozembed, per aggiugere la finestra
        #bisogna mettere self.scrolledwindow1.add_with_viewport()
        self.scrolledwindow1 = self.glade.get_widget("scrolledwindow1")
        
        #Treeview widget
        self.liststore=gtk.ListStore(int,str,str,str)
        self.treeview=gtk.TreeView(self.liststore)  
        self.colonna_cont=gtk.TreeViewColumn('num')
        self.colonna_nome=gtk.TreeViewColumn('Site')
        self.colonna_date=gtk.TreeViewColumn('Date')
        self.colonna_link=gtk.TreeViewColumn('Link')
        self.treeview.append_column(self.colonna_cont)
        self.treeview.append_column(self.colonna_nome)
        self.treeview.append_column(self.colonna_date)
        self.treeview.append_column(self.colonna_link)
        
        self.treeview.connect('button_press_event',self.ButtonPress)
        #self.treeview.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)

        self.cella_cont=gtk.CellRendererText()
        self.cella_nome=gtk.CellRendererText()
        self.cella_date=gtk.CellRendererText()
        self.cella_link=gtk.CellRendererText()
        self.cella_cont.set_property('cell-background','cyan')
        self.cella_nome.set_property('cell-background','grey')
        self.cella_date.set_property('cell-background','green')
        self.cella_link.set_property('cell-background','grey')
        self.colonna_cont.pack_start(self.cella_cont,True)
        self.colonna_nome.pack_start(self.cella_nome,True)
        self.colonna_date.pack_start(self.cella_date,True)
        self.colonna_link.pack_start(self.cella_link,True)
        self.colonna_cont.set_attributes(self.cella_cont,text=0)
        self.colonna_nome.set_attributes(self.cella_nome,text=1)
        self.colonna_date.set_attributes(self.cella_date,text=2)
        self.colonna_link.set_attributes(self.cella_link,text=3)
        self.colonna_cont.set_sort_column_id(0)
        self.colonna_nome.set_sort_column_id(1)
        self.colonna_date.set_sort_column_id(2)
        self.colonna_link.set_sort_column_id(3)
        # make treeview searchable
        self.treeview.set_search_column(0)
        # Allow sorting on the column
        self.colonna_cont.set_sort_column_id(0)
        # No reordeding drag and drop
        self.treeview.set_reorderable(False)
        #Treeview added in a scrolledwindow
        self.scrolledwindow.add_with_viewport(self.treeview)
        self.window.show_all()

    def ButtonPress(self,widget,event):
        if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
            print 'left double click'
            treeselection = self.treeview.get_selection()
            (model, iter) = treeselection.get_selected()
            name_of_data = self.liststore.get_value(iter, 0)
            print "name_of_data= ",name_of_data
            print self.links[(name_of_data)-1]
            webbrowser.open_new_tab(self.links[(name_of_data)-1])
                                
    def LoadURL(self):
        self.dbase=DbaseFeed()
        self.urls=self.dbase.read()
        #METTERE NOME DA VISUALIZZARE
        print self.urls
        print type(self.urls)
        return self.urls

     
    def parser(self):
            diz = {}
            url=self.LoadURL()
            print "url in parser= ",url
            for sito in url.keys():
                    sit=url[sito]
                    print "sit= ",sit
                    d = feedparser.parse(sit)
                    for i in range(0,len(d['items'])):
                            tmp=[]
                            self.title = d['items'][i].title
                            #self.title=sito
                            self.news_url = d['items'][i].links[0]['href']
                            self.news_data = d['items'][i].updated [:-5]
                            self.news_data = self.news_data[:-5]
                            #tmp.append(sit)
                            tmp.append(sito)
                            tmp.append(self.news_data)
                            tmp.append(self.news_url)
                            diz[self.title] = tmp
            return diz
            
    def on_add_btn_clicked(self, widget):
        self.LoadURL()
        Add_dialog()
        
    def on_refresh_btn_clicked(self, widget):
        self.links=[]
        line=1
        feeds=self.parser()
        print "feeds= ",feeds
        for key in feeds.keys():
            self.liststore.append([line,feeds[key][0],feeds[key][1],key])
            line+=1
            #print "LINK= ",feeds[key][2]
            self.links.append(feeds[key][2])
        
            
    def on_check_screen_toggled(self, widget):
        if self.check_screen.get_active():
            self.window.fullscreen()
        else:
            self.window.unfullscreen()
            
    def on_aboutmenuitm_activate(self, widget):
        About_dialog()
        
    def main(self):
        gtk.main()

#---MAIN---#
if __name__ == "__main__":
    window = Feed()
    window.main()