File: Headers_List.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 (238 lines) | stat: -rw-r--r-- 9,528 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
import gtk
import gobject
import cPickle
import os
from xpn_src.UserDir import get_wdir

default_list=["From","Date","Subject"]

headers_list=["From","Date","Subject","Newsgroups","Reply-To","Sender","Organization","Followup-To","Mail-Copies-To",
              "Archive","Supersedes","Approved","Content-Type","Content-Transfer-Encoding","User-Agent","Xref","Bytes",
              "Lines","Message-ID","References"]

def load_headers_list():
    try:
        f=open(os.path.join(get_wdir(),"dats/headers_list.dat"),"rb")
    except IOError:
        list=default_list
    else:
        list=cPickle.load(f)
        f.close()
        if not list:
            list=headers_list
    return list

class HeadersList:

    def delete_event(self,widget,event,data=None):
        return False  

    def destroy(self,widget):
        self.window.destroy()
        if __name__=="__main__":
            gtk.main_quit()
    
    def close_ok(self,obj): 
        self.dump_tree(self.right_list)
        self.destroy(None)
    
    def close_cancel(self,obj):
        self.destroy(None)
         
    def fill_lists(self):
        for header in headers_list:
            self.left_model.append([header])

        list=load_headers_list()
        for header in list:
            self.right_model.append([header])

    def get_headers_list(self,treeview):
        model=treeview.get_model()
        iter=model.get_iter_first()
        list=[]
        while iter:
            list.append(model.get_value(iter,0))
            iter=model.iter_next(iter)
        return list
    
    def dump_tree(self,treeview):
        list=self.get_headers_list(self.right_list)
        f=open(os.path.join(get_wdir(),"dats/headers_list.dat"),"wb")
        cPickle.dump(list,f,1)
        f.close()
        
    
    def set_default_list(self,obj):
        self.right_model.clear()
        for header in default_list:
            self.right_model.append([header])
    
    def add_manually(self,obj):
        header=self.add_manually_entry.get_text()
        if header and not (header in self.get_headers_list(self.right_list)):
            self.right_model.append([header])


    def add_ordered(self,obj):
        model_left,path_left_list=self.left_list.get_selection().get_selected_rows()
        for path in path_left_list:
            iter_left=model_left.get_iter(path) 
            header=model_left.get_value(iter_left,0)
            if not (header in self.get_headers_list(self.right_list)):
                self.right_model.append([header])

    def remove_ordered(self,obj):
        model_right,path_right_list=self.right_list.get_selection().get_selected_rows()
        for i in range(len(path_right_list)):
            path=path_right_list[i]
            if i!=0:
                path=list(path)
                path[0]=path[0]-i
                path=tuple(path)
            iter_right=model_right.get_iter(path)
            self.right_model.remove(iter_right)
        
    def move_up(self,obj):
        model,path_list=self.right_list.get_selection().get_selected_rows()
        for path in path_list:
            iter_to_move=model.get_iter(path)
            new_path=list(path)
            if new_path[0]>0:
                new_path[0]=new_path[0]-1
            new_path=tuple(new_path)
            iter_previous=model.get_iter(new_path)
            model.swap(iter_to_move,iter_previous)

    def move_down(self,obj):
        model,path_list=self.right_list.get_selection().get_selected_rows()
        path_list.reverse()
        for path in path_list:
            iter_to_move=model.get_iter(path)
            iter_next=model.iter_next(iter_to_move)
            if iter_next!=None:
                model.swap(iter_to_move,iter_next)
   
    def __init__(self):
        self.window=gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event",self.delete_event)
        self.window.connect("destroy",self.destroy)
        self.window.set_title("Headers List")
        self.window.set_position(gtk.WIN_POS_CENTER)
        self.window.set_size_request(500,400)
        self.table=gtk.Table(3,2,False)
        self.table.set_border_width(4)
        label_left=gtk.Label()
        label_left.set_markup("<b>"+_("Standard Headers")+"</b>")
        label_right=gtk.Label()
        label_right.set_markup("<b>"+_("Shown Headers")+"</b>")
        self.left_scrolledwin=gtk.ScrolledWindow()
        self.left_scrolledwin.set_border_width(4)
        self.left_scrolledwin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.left_scrolledwin.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.left_scrolledwin.set_size_request(200,-1)
        
        self.left_list=gtk.TreeView() 
        self.left_list.set_border_width(4)
        self.left_model=gtk.ListStore(gobject.TYPE_STRING)
        self.left_scrolledwin.add(self.left_list)
        self.left_list.set_model(self.left_model)
        text_renderer=gtk.CellRendererText()
        self.left_column=gtk.TreeViewColumn(_("List"),text_renderer,text=0)
        self.left_list.append_column(self.left_column)
        self.left_list.set_rules_hint(True)
        self.left_list.set_headers_visible(False)
        self.left_list.get_selection().set_mode(gtk.SELECTION_MULTIPLE)


        
        self.right_scrolledwin=gtk.ScrolledWindow()
        self.right_scrolledwin.set_border_width(4)
        self.right_scrolledwin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.right_scrolledwin.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.right_scrolledwin.set_size_request(200,-1)
        self.right_list=gtk.TreeView() 
        self.right_list.set_border_width(4)
        self.right_model=gtk.ListStore(gobject.TYPE_STRING)
        self.right_scrolledwin.add(self.right_list)
        self.right_list.set_model(self.right_model)
        text_renderer=gtk.CellRendererText()
        self.right_column=gtk.TreeViewColumn(_("List"),text_renderer,text=0)
        self.right_list.append_column(self.right_column)
        self.right_list.set_rules_hint(True)
        self.right_list.set_headers_visible(False)
        self.right_list.set_tooltip_text(_("XPN will show these headers on the top of the Article Pane"))
        self.right_list.set_reorderable(True)
        self.right_list.get_selection().set_mode(gtk.SELECTION_MULTIPLE)


        self.to_right_button=gtk.Button()
        to_right_button_image=gtk.Image()
        to_right_button_image.set_from_stock(gtk.STOCK_GO_FORWARD,gtk.ICON_SIZE_MENU)
        
        self.to_right_button.add(to_right_button_image)
        self.to_right_button.connect("clicked",self.add_ordered)
        self.to_left_button=gtk.Button()
        to_left_button_image=gtk.Image()
        to_left_button_image.set_from_stock(gtk.STOCK_GO_BACK,gtk.ICON_SIZE_MENU)
        
        self.to_left_button.add(to_left_button_image)
        self.to_left_button.connect("clicked",self.remove_ordered)
        vbox_buttons=gtk.VBox()
        vbox_buttons.pack_start(self.to_right_button,False,True,10)
        vbox_buttons.pack_start(self.to_left_button,False,True,10)
        
        up_button_image=gtk.Image()
        up_button_image.set_from_stock(gtk.STOCK_GO_UP,gtk.ICON_SIZE_MENU)
        self.up_button=gtk.Button()
        self.up_button.add(up_button_image)
        self.up_button.connect("clicked",self.move_up)

        down_button_image=gtk.Image()
        down_button_image.set_from_stock(gtk.STOCK_GO_DOWN,gtk.ICON_SIZE_MENU)
        self.down_button=gtk.Button()
        self.down_button.add(down_button_image)
        self.down_button.connect("clicked",self.move_down)

        vbox_buttons2=gtk.VBox()
        vbox_buttons2.pack_start(self.up_button,False,False,10)
        vbox_buttons2.pack_start(self.down_button,False,False,10)
        

        self.add_manually_entry=gtk.Entry()
        self.add_manually_button=gtk.Button(_("Add Manually"))
        add_manually_hbox=gtk.HBox()
        add_manually_hbox.add(self.add_manually_entry)
        add_manually_hbox.add(self.add_manually_button)
        self.add_manually_button.connect("clicked",self.add_manually)

        self.default_button=gtk.Button(_("Set Default List"))
        self.default_button.connect("clicked",self.set_default_list)

        self.table.attach(label_left,0,1,0,1,gtk.EXPAND|gtk.FILL,gtk.FILL)
        self.table.attach(vbox_buttons,1,2,1,2,gtk.EXPAND|gtk.FILL,gtk.EXPAND)
        self.table.attach(label_right,2,3,0,1,gtk.EXPAND|gtk.FILL,gtk.FILL)
        self.table.attach(self.left_scrolledwin,0,1,1,2,gtk.EXPAND|gtk.FILL,gtk.EXPAND|gtk.FILL)
        self.table.attach(self.right_scrolledwin,2,3,1,2,gtk.EXPAND|gtk.FILL,gtk.EXPAND|gtk.FILL)
        self.table.attach(vbox_buttons2,3,4,1,2,gtk.FILL,gtk.EXPAND)
        self.table.attach(add_manually_hbox,2,3,2,3,gtk.FILL|gtk.EXPAND,gtk.FILL)        
        self.table.attach(self.default_button,2,3,3,4,gtk.FILL|gtk.EXPAND,gtk.FILL)

        vbox=gtk.VBox()
        hbox=gtk.HBox()
        self.ok_button=gtk.Button(None,gtk.STOCK_OK)
        self.ok_button.connect("clicked",self.close_ok)
        self.cancel_button=gtk.Button(None,gtk.STOCK_CANCEL)
        self.cancel_button.connect("clicked",self.close_cancel)
        hbox.pack_start(self.cancel_button,True,True,2)
        hbox.pack_start(self.ok_button,True,True,2)
        vbox.pack_start(self.table,True,True,4)
        vbox.pack_start(hbox,False,True,2)
        self.window.add(vbox)
        self.fill_lists()
        self.window.show_all()

if __name__=="__main__":
    ch_list=HeadersList()
    gtk.main()