File: Threads_Pane.py

package info (click to toggle)
xpn 1.2.6-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 2,500 kB
  • ctags: 1,685
  • sloc: python: 12,693; xml: 206; makefile: 16; sh: 1
file content (320 lines) | stat: -rw-r--r-- 14,375 bytes parent folder | download | duplicates (2)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import gtk
import gobject
import pango
import cPickle
import os
from xpn_src.UserDir import get_wdir


class Threads_Pane:
    def get_widget(self):
        return self.scrolledwin

    def unparent(self):
        self.scrolledwin.unparent()

    def show(self):
        self.scrolledwin.show_all()

    def hide(self):
        self.scrolledwin.hide_all()

    def clear(self):
        model=self.threads_tree.get_model()
        model.clear()

    def set_background(self,color):
        color=gtk.gdk.color_parse(color)
        self.threads_tree.modify_base(gtk.STATE_NORMAL,color)

    def set_foreground(self,color):
        color=gtk.gdk.color_parse(color)
        self.threads_tree.modify_text(gtk.STATE_NORMAL,color)
        self.threads_tree.modify_fg(gtk.STATE_NORMAL,color)

    def delete_row(self,model,iter):
        model.remove(iter)

    def insert(self,model,iter_parent,iter_sibling,values):
        iter=model.insert_before(iter_parent,iter_sibling)
        if values[5]: values[5]=pango.WEIGHT_BOLD
        else :values[5]= pango.WEIGHT_NORMAL
        if len(values)==19: #quando cerco l'articolo padre non passo tutte le info
            if values[18]: values[18]=pango.UNDERLINE_SINGLE
            else :values[18]= pango.UNDERLINE_NONE
        
        for i in range(len(values)):
            if i==1 or i==2 or i==3:
                value=values[i].encode("utf-8")
            else:
                value=values[i]
            model.set_value(iter,i,value)
        return iter

    def get_subject(self,model,article_iter):
        return model.get_value(article_iter,1)

    def get_article(self,model,article_iter):
        return model.get_value(article_iter,4)
    
    def set_article(self,model,article_iter,article):
        model.set_value(article_iter,4,article)
        
    def get_unread_in_thread(self,model,article_iter):
        return model.get_value(article_iter,12)
    
    def get_watched_in_thread(self,model,article_iter):
        return model.get_value(article_iter,19)
    
    def get_watched_unread_in_thread(self,model,article_iter):
        return model.get_value(article_iter,20)

    def set_unread_in_thread(self,model,article_iter,unread_in_thread):
        model.set_value(article_iter,12,unread_in_thread)

    def set_watched_in_thread(self,model,article_iter,watched_in_thread):
        model.set_value(article_iter,19,watched_in_thread)
        
    def set_watched_unread_in_thread(self,model,article_iter,watched_unread_in_thread):
        model.set_value(article_iter,20,watched_unread_in_thread)
        model.set_value(article_iter,18,watched_unread_in_thread!=0)

    def set_unread_in_thread_visible(self,model,article_iter,unread_in_thread_visible):
        model.set_value(article_iter,13,unread_in_thread_visible)

    def update_unread_in_thread(self,is_read,show_threads,insert):
        if show_threads and ((is_read and insert) or (not is_read and not insert)):
            model,iter_selected=self.threads_tree.get_selection().get_selected()
            parent_path=tuple([model.get_path(iter_selected)[0],])
            parent_iter=model.get_iter(parent_path)
            unread_in_thread=self.get_unread_in_thread(model,parent_iter)
            if insert:  unread_in_thread=unread_in_thread+1
            else:       unread_in_thread=unread_in_thread-1
            self.set_unread_in_thread(model,parent_iter,unread_in_thread)
            self.set_unread_in_thread_visible(model,parent_iter,unread_in_thread!=0)
    
    def update_watched_in_thread(self,is_watched,show_threads,insert):
        if show_threads and ((is_watched and insert) or (not is_watched and not insert)):
            model,iter_selected=self.threads_tree.get_selection().get_selected()
            parent_path=tuple([model.get_path(iter_selected)[0],])
            parent_iter=model.get_iter(parent_path)
            watched_in_thread=self.get_watched_in_thread(model,parent_iter)
            if insert:  watched_in_thread=watched_in_thread+1
            else:       watched_in_thread=watched_in_thread-1
            self.set_watched_in_thread(model,parent_iter,watched_in_thread)
    
    def update_watched_unread_in_thread(self,is_read,is_watched,show_threads,insert_in_unreads,insert_in_watched,updating_unreads):
        print is_read,is_watched,show_threads,insert_in_unreads,insert_in_watched,updating_unreads
        inserting=((is_read and insert_in_unreads) and is_watched) or ((is_watched and insert_in_watched) and not is_read and not updating_unreads)
        removing=((not is_read and not insert_in_unreads) and is_watched) or ((not is_watched and not insert_in_watched) and not is_read and not updating_unreads)
        
        if show_threads and (inserting or removing):
            model,iter_selected=self.threads_tree.get_selection().get_selected()
            parent_path=tuple([model.get_path(iter_selected)[0],])
            parent_iter=model.get_iter(parent_path)
            watched_unread_in_thread=self.get_watched_unread_in_thread(model,parent_iter)
            print "BEFORE:",watched_unread_in_thread
            if inserting:  watched_unread_in_thread=watched_unread_in_thread+1
            else:          watched_unread_in_thread=watched_unread_in_thread-1
            print "AFTER:",watched_unread_in_thread
            self.set_watched_unread_in_thread(model,parent_iter,watched_unread_in_thread)

    def get_is_unread(self,model,article_iter):
        return model.get_value(article_iter,5)==pango.WEIGHT_BOLD

    def set_is_unread(self,model,article_iter,is_unread):
        if is_unread: weight=pango.WEIGHT_BOLD
        else: weight=pango.WEIGHT_NORMAL
        model.set_value(article_iter,5,weight)
    
    def new_model(self):
        #MODEL: 0 Icon, 1 Subject, 2 From, 3 Date, 4 XPN_article, 5 Use_Bold, 6 Seconds, 7 Score, 8 Score_Foreground,
        #       9 Score_Visible, 10 Icon2, 11 Icon3, 12 Unread_In_Thread, 13 Unread_Visible, 14 Article_FG_Set, 15 Article_FG
        #      16 Article_BG_Set,17 Article_BG, 18 Use_Underline, 19 Watched_In_Thread, Watched_Unread_in_Thread
        model=gtk.TreeStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT,gobject.TYPE_INT,gobject.TYPE_INT,gobject.TYPE_INT,gobject.TYPE_STRING, 
                            gobject.TYPE_BOOLEAN, gtk.gdk.Pixbuf, gtk.gdk.Pixbuf,gobject.TYPE_INT,gobject.TYPE_BOOLEAN, gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, 
                            gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,gobject.TYPE_BOOLEAN,gobject.TYPE_INT,gobject.TYPE_INT)
        return model

    def set_model(self,model):
        self.threads_tree.set_model(model)

    def find_next_row(self,model,current_iter):
        if model.iter_has_child(current_iter):
            next_iter = model.iter_children(current_iter)
        else:
            next_iter=model.iter_next(current_iter)
            while not next_iter:
                prev_iter=model.iter_parent(current_iter)
                current_iter=prev_iter
                if not prev_iter:
                    break
                next_iter=model.iter_next(current_iter)
        return next_iter

    def find_previous_row(self,model,current_iter):
        path=model.get_path(current_iter)
        new_path=[path[i] for i in xrange(len(path)-1)]
        if path[len(path)-1]>0:
            new_path.append(path[len(path)-1]-1)
        new_path=tuple(new_path)
        if new_path:
            prev_iter = model.get_iter(new_path)
            return prev_iter
        else:
            return current_iter

    def update_article_icon(self,name,iter_row=None):
        model,iter_selected=self.threads_tree.get_selection().get_selected()
        if iter_row:
            iter_selected=iter_row
        current_icon=model.get_value(iter_selected,0)
        current_icon2=model.get_value(iter_selected,10)
        current_icon3=model.get_value(iter_selected,11)
        icon=current_icon
        icon2=current_icon2
        icon3=current_icon3
        if name=="read":
            if current_icon!=self.art_fup:
                icon=self.art_read
            else:
                icon=self.art_fup
        elif name=="fup":
            icon=self.art_fup
        elif name=="unread":
            icon=self.art_unread
        elif name=="download":
            icon=self.art_mark
        elif name=="body":
            icon=self.art_body
        elif name=="keep":
            icon2=self.art_keep
        elif name=="unkeep":
            icon2=self.art_unkeep
        elif name=="watch":
            icon3=self.art_watch
        elif name=="unwatchignore":
            icon3=self.art_unwatchignore
        elif name=="ignore":
            icon3=self.art_ignore
        model.set_value(iter_selected,0,icon)
        model.set_value(iter_selected,10,icon2)
        model.set_value(iter_selected,11,icon3)


    def get_subthread(self,iter_parent,model,iter_list):
        '''Return the list of iters in the subthread without the father'''
        if model.iter_has_child(iter_parent):
            number=model.iter_n_children(iter_parent)
            for i in xrange(number):
                iter_child=model.iter_nth_child(iter_parent,i)
                self.get_subthread(iter_child,model,iter_list)
                iter_list.append(iter_child)
        return iter_list

   
    def __init__(self,configs):
        self.art_unread=gtk.gdk.pixbuf_new_from_file("pixmaps/art_unread.xpm")
        self.art_read=gtk.gdk.pixbuf_new_from_file("pixmaps/art_read.xpm")
        self.art_fup=gtk.gdk.pixbuf_new_from_file("pixmaps/art_fup.xpm")
        self.art_mark=gtk.gdk.pixbuf_new_from_file("pixmaps/art_mark.xpm")
        self.art_body=gtk.gdk.pixbuf_new_from_file("pixmaps/art_body.xpm")
        self.art_keep=gtk.gdk.pixbuf_new_from_file("pixmaps/art_keep.xpm")
        self.art_unkeep=gtk.gdk.pixbuf_new_from_file("pixmaps/art_unkeep.xpm")
        self.art_watch=gtk.gdk.pixbuf_new_from_file("pixmaps/art_watch.xpm")
        self.art_unwatchignore=gtk.gdk.pixbuf_new_from_file("pixmaps/art_unwatchignore.xpm")
        self.art_ignore=gtk.gdk.pixbuf_new_from_file("pixmaps/art_ignore.xpm")

        #ThreadsScrolledWin
        self.scrolledwin=gtk.ScrolledWindow()
        self.scrolledwin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.scrolledwin.set_shadow_type(gtk.SHADOW_ETCHED_IN)

        try:
            f=open(os.path.join(get_wdir(),"dats/sizes.dat"),"rb")
        except IOError:
            column1_width=41
            column2_width=415
            column3_width=201
            column4_width=95
            column5_width=60
        else:
            sizes=cPickle.load(f)
            f.close()
            column1_width=sizes.get("threads_col_status",41)
            column2_width=sizes.get("threads_col_subject",415)
            column3_width=sizes.get("threads_col_from",201)
            column4_width=sizes.get("threads_col_date",95)
            column5_width=sizes.get("threads_col_score",60)

        #ThreadsTree
        self.threads_tree=gtk.TreeView()
        model=self.new_model()
        self.set_model(model)
        pix_renderer=gtk.CellRendererPixbuf()
        pix_renderer2=gtk.CellRendererPixbuf()
        pix_renderer3=gtk.CellRendererPixbuf()
        text_renderer=gtk.CellRendererText()
        text_renderer_unread=gtk.CellRendererText()
        text_renderer_unread.set_property("xalign",1)
        #text_renderer.set_property("weight",1000)
        text_renderer_score=gtk.CellRendererText()
        text_renderer_score.set_property("xalign",.5)
        self.column1=gtk.TreeViewColumn("Status")
        self.column1.pack_start(pix_renderer,False)
        self.column1.pack_start(pix_renderer2,False)
        self.column1.pack_start(pix_renderer3,False)
        self.column1.pack_start(text_renderer_unread,False)
        self.column1.set_attributes(pix_renderer,pixbuf=0)
        self.column1.set_attributes(pix_renderer2,pixbuf=10)
        self.column1.set_attributes(pix_renderer3,pixbuf=11)
        self.column1.set_attributes(text_renderer_unread,text=12,visible=13)

        self.column2=gtk.TreeViewColumn(_("Subject"),text_renderer,text=1,weight=5,foreground_set=14,foreground=15,background_set=16,background=17,underline=18)
        self.column3=gtk.TreeViewColumn(_("From"),text_renderer,text=2,weight=5,foreground_set=14,foreground=15,background_set=16,background=17)
        self.column4=gtk.TreeViewColumn(_("Date"),text_renderer,text=3,weight=5,foreground_set=14,foreground=15,background_set=16,background=17)
        self.column5=gtk.TreeViewColumn(_("Score"),text_renderer_score,text=7,foreground=8,visible=9)


        self.column2.set_resizable(True)
        self.column2.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
        self.column2.set_fixed_width(column2_width)
        self.column2.set_sort_column_id(1)

        self.column3.set_resizable(True)
        self.column3.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
        self.column3.set_fixed_width(column3_width)
        self.column3.set_sort_column_id(2)

        self.column4.set_resizable(True)
        self.column4.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
        self.column4.set_fixed_width(column4_width)
        self.column4.set_sort_column_id(6)

        self.column5.set_sort_column_id(7)

        self.threads_tree.append_column(self.column1)
        if configs["exp_column"]=="From":
            self.threads_tree.append_column(self.column3)       
            self.threads_tree.append_column(self.column2)
            self.threads_tree.set_expander_column(self.column3)
        else:
            self.threads_tree.append_column(self.column2)
            self.threads_tree.append_column(self.column3)       
            self.threads_tree.set_expander_column(self.column2)

        self.threads_tree.append_column(self.column4)
        self.threads_tree.append_column(self.column5)
        try: self.threads_tree.set_enable_tree_lines(True)
        except: pass
        self.scrolledwin.add(self.threads_tree)

        color=configs["background_color"]
        self.set_background(color)
        color=configs["text_color"]
        self.set_foreground(color)
        if configs["use_system_fonts"]=="True":
            self.threads_tree.modify_font(pango.FontDescription(""))
        else:
            self.threads_tree.modify_font(pango.FontDescription(configs["font_threads_name"]))