File: Dialogs.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 (237 lines) | stat: -rw-r--r-- 9,510 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
import gtk
import gobject 
import ConfigParser
import os
from xpn_src.UserDir import get_wdir


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

    def destroy(self,widget,event):
        self.dialog.destroy()

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

    def __init__(self,NUMBER):
        self.dialog=gtk.Dialog(_("About"),None,0,(gtk.STOCK_OK,gtk.RESPONSE_OK))
        self.dialog.set_default_size(300,280)
        self.dialog.connect("delete_event",self.delete_event)
        self.dialog.connect("response",self.destroy)
        self.dialog.set_has_separator(True)
        self.dialog.set_position(gtk.WIN_POS_CENTER)
        self.image=gtk.Image()
        self.image.set_from_file("pixmaps/xpn-logo-small.png")
        self.dialog.vbox.pack_start(self.image,True,True)
        string="<span size='x-large' weight='heavy'>X Python Newsreader %s</span>\n<span weight='heavy' style='italic'>Italian Style</span>\n\nWritten by Antonio 'Nemesis' Caputo\nxpn@altervista.org\n\nhttp://xpn.altervista.org" % (NUMBER,)
        self.label=gtk.Label()
        self.label.set_markup(string)
        self.label.set_justify(gtk.JUSTIFY_CENTER)
        self.dialog.vbox.pack_start(self.label,True,True,8)

class Dialog_YES_NO:

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

    def __init__(self,message):
        self.resp=""
        self.dialog=gtk.MessageDialog(None,0,gtk.MESSAGE_QUESTION,gtk.BUTTONS_YES_NO)
        self.dialog.connect("delete_event",self.delete_event)
        self.dialog.set_position(gtk.WIN_POS_CENTER)
        self.dialog.label.set_markup(message)
        resp=self.dialog.run()
        if resp==gtk.RESPONSE_YES:
            self.resp=True
        else:
            self.resp=False
        self.dialog.destroy()

class Dialog_OK:

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

    def __init__(self,message):
        self.resp=""
        self.dialog=gtk.MessageDialog(None,0,gtk.MESSAGE_INFO,gtk.BUTTONS_OK)
        self.dialog.connect("delete_event",self.delete_event)
        self.dialog.set_position(gtk.WIN_POS_CENTER)
        self.dialog.label.set_markup(message)
        self.resp=self.dialog.run()
        self.dialog.destroy()

class Dialog_Import_Newsrc(gtk.Dialog):
    def __init__(self,message,server_name):
        gtk.Dialog.__init__(self,_("Choose the Server"),None,0,(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OK,gtk.RESPONSE_OK))
        self.label=gtk.Label()
        self.label.set_markup(message)
        self.set_position(gtk.WIN_POS_CENTER)
        self.server_combo=gtk.combo_box_new_text()
        cp=ConfigParser.ConfigParser()
        cp.read(os.path.join(get_wdir(),"dats","servers.txt"))
        positions=dict()
        i=0
        for server in cp.sections(): 
            self.server_combo.append_text(cp.get(server,"server"))
            positions[server]=i
            i=i+1
        
        if server_name: self.server_combo.set_active(positions.get(server_name,0))
        else: self.server_combo.set_active(0)
        
        self.vbox.pack_start(self.label,True,True,8)
        self.vbox.pack_start(self.server_combo,False,False,8)
        self.server_combo.show()
        self.label.show()
        self.label.set_line_wrap(True)
        if len(positions)== 0:
            Dialog_OK(_("First you have to configure at least one Server"))
            self.resp=gtk.RESPONSE_CLOSE
            self.destroy()
        else:
            self.resp=self.run()
            self.server_name=self.server_combo.get_active_text()
            self.destroy()

class Error_Dialog(gtk.Dialog):
    def __init__(self,string,log):
        gtk.Dialog.__init__(self,_("Error Dialog"),None,0,(gtk.STOCK_OK,gtk.RESPONSE_OK))
        self.set_default_size(350,350)
        self.set_icon(gtk.gdk.pixbuf_new_from_file("pixmaps/dialog-error.xpm"))
        self.set_has_separator(True)
        self.set_position(gtk.WIN_POS_CENTER)
        self.buffer=gtk.TextBuffer()
        self.buffer.set_text(string)
        self.view=gtk.TextView(self.buffer)
        self.view.set_wrap_mode(gtk.WRAP_WORD)
        self.view.set_cursor_visible(False)
        self.view.set_border_width(5)
        self.view.set_editable(False)
        self.scrolled_win=gtk.ScrolledWindow()
        self.scrolled_win.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.scrolled_win.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.scrolled_win.add(self.view)
        self.buffer_log=gtk.TextBuffer()
        self.buffer_log.set_text(log)
        self.view_log=gtk.TextView(self.buffer_log)
        self.view_log.set_wrap_mode(gtk.WRAP_WORD)
        self.view_log.set_cursor_visible(False)
        self.view_log.set_border_width(5)
        self.view_log.set_editable(False)
        self.scrolled_win_log=gtk.ScrolledWindow()
        self.scrolled_win_log.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.scrolled_win_log.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.scrolled_win_log.add(self.view_log)
        self.notebook=gtk.Notebook()
        self.label_error=gtk.Label()
        self.label_error.set_markup("<b>"+_("Last Error")+"</b>")
        self.label_error_log=gtk.Label()
        self.label_error_log.set_markup("<b>"+_("Errors Log")+"</b>")
        self.notebook.append_page(self.scrolled_win,self.label_error)
        self.notebook.append_page(self.scrolled_win_log,self.label_error_log)
        self.notebook.show_all()

        self.vbox.pack_start(self.notebook,True,True,0)

class MidDialog(gtk.Dialog):
    def __init__(self,mid):
        gtk.Dialog.__init__(self,_("Message-ID Search Dialog"),None,0,(gtk.STOCK_CLOSE,gtk.RESPONSE_CLOSE,gtk.STOCK_OK,gtk.RESPONSE_OK))

        self.label=gtk.Label()
        self.label.set_markup("<b>"+_("Message-ID to search")+"</b>")
        self.entry=gtk.Entry()
        self.entry.set_text(mid)
        self.entry.show()
        self.label.show()
        self.vbox.pack_start(self.label,True,True)
        self.vbox.pack_start(self.entry,True,True)
        self.r1=gtk.RadioButton(None,_("Search in current group"))
        self.r2=gtk.RadioButton(self.r1,_("Search in subscribed groups"))
        self.r3=gtk.RadioButton(self.r1,_("Search on Google"))
        self.r1.show()
        self.r2.show()
        self.r3.show()
        self.vbox.pack_start(self.r1,True,True)
        self.vbox.pack_start(self.r2,True,True)
        self.vbox.pack_start(self.r3,True,True)
        self.set_size_request(350,200)

        self.resp=self.run()
        self.sel=self.r1.get_active(),self.r2.get_active(),self.r3.get_active()
        self.destroy()

class Shortcut_Dialog(gtk.Dialog):
    def grab_shortcut(self,obj,event):
        comb=""
        name=gtk.gdk.keyval_name(event.keyval)
        string_name=event.string
        if event.state & gtk.gdk.CONTROL_MASK:
            comb=comb+"<Control>"
        if event.state & gtk.gdk.MOD1_MASK:
            comb=comb+"<Alt>"
        if event.state & gtk.gdk.SHIFT_MASK:
            comb=comb+"<Shift>"
        comb=comb+name
        admitted=["delete",]+["f"+str(i) for i in range(1,13)]
        if string_name or comb.lower() in admitted:
            self.entry.set_text(comb)
            self.shortcut=comb
        else:
            self.entry.set_text("")
            self.shortcut=""

    def __init__(self):
        gtk.Dialog.__init__(self,_("Shortcut Dialog"),None,0,(gtk.STOCK_OK,gtk.RESPONSE_OK,gtk.STOCK_CLOSE,gtk.RESPONSE_CLOSE))
        self.label1=gtk.Label()
        self.label1.set_markup("<b>"+_("Type your Shortcut")+"</b>")
        self.label2=gtk.Label()
        self.label2.set_markup("<b>"+_("Press OK to confirm it")+"</b>")
        self.entry=gtk.Entry()
        self.entry.set_sensitive(False)
        self.entry.show()
        self.label1.show()
        self.label2.show()
        self.vbox.pack_start(self.label1,True,True,4)
        self.vbox.pack_start(self.label2,True,True,4)
        self.vbox.pack_start(self.entry,True,True,4)
        self.shortcut=""        
        self.connect("key-press-event",self.grab_shortcut)
        self.resp=self.run()
        self.destroy()

class Shortcut_Error_Warning_Dialog(gtk.MessageDialog):
    def __init__(self,warning,list,message):
        if warning:
            type=gtk.MESSAGE_WARNING
        else:
            type=gtk.MESSAGE_ERROR
        gtk.MessageDialog.__init__(self,None,0,type,gtk.BUTTONS_OK)
        self.set_size_request(500,400)
        self.set_resizable(True)
        self.label.set_markup(message)
        scrolledwin=gtk.ScrolledWindow()
        self.treeview=gtk.TreeView()
        self.treeview.set_border_width(4)
        scrolledwin.add(self.treeview)
        self.model=gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING)
        self.treeview.set_model(self.model)
        text_renderer=gtk.CellRendererText()
        column1=gtk.TreeViewColumn(_("Window"),text_renderer,text=0)
        column1.set_resizable(True)
        column2=gtk.TreeViewColumn(_("Shortcut"),text_renderer,text=1)
        column2.set_resizable(True)
        column3=gtk.TreeViewColumn(_("Action"),text_renderer,text=2)
        self.treeview.append_column(column1)
        self.treeview.append_column(column2)
        self.treeview.append_column(column3)
        self.treeview.set_rules_hint(True)
        for line in list: self.model.append(line)
        self.vbox.add(scrolledwin)
        self.vbox.show_all()
        self.resp=self.run()
        self.destroy()