File: hig_alert.py

package info (click to toggle)
gnome-blog 0.9.1-8
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,116 kB
  • ctags: 178
  • sloc: python: 1,341; sh: 632; makefile: 136; xml: 8
file content (73 lines) | stat: -rw-r--r-- 2,770 bytes parent folder | download | duplicates (4)
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
import gtk

from gettext import gettext as _

import xml.sax.saxutils

def italic(s):
    return "<span style=\"italic\">%s</span>" % xml.sax.saxutils.escape(str(s))

def bold(s):
    return "<span weight=\"bold\">%s</span>" % xml.sax.saxutils.escape(str(s))

def handleBloggerAPIFault(e, primary, username, blog_id, url):
    if e.faultCode == 'Method Error':
        reportError(primary, _('URL \'%s\' may not be a valid bloggerAPI. XML-RPC Server reported: %s.') % (url, italic(e.faultString)))
    elif e.faultCode == 'PasswordError':
        reportError(primary, _('Unknown username %s or password trying to post blog entry to XML-RPC server %s.') % (bold(username), italic(url)))
    elif e.faultCode == 'PostError':
        reportError(primary, _('Could not post to blog \'%s\' at bloggerAPI XML-RPC server \'%s\'. Server reported: %s.') % (blog_id, url, italic(e.faultString)))
    else:
        reportError(primary, _('The bloggerAPI server (%s) reported an error I don\'t understand: \'%s, %s\'. \n\nPlease email this error message to seth@gnome.org so I can address it.') % (url, italic(e.faultCode), e.faultString))

def reportError(primaryText, secondaryText):
    alert = HIGAlert(primaryText, secondaryText,
                     buttons = (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
    alert.run()
    alert.hide()

class HIGAlert(gtk.Dialog):
    def __init__(self, primaryText, secondaryText, parent=None, flags=0, buttons=None):
        gtk.Dialog.__init__(self, primaryText, parent, flags, buttons)

        self.set_border_width(6)
        self.set_has_separator(False)
        self.set_resizable(False)

        self.vbox.set_spacing(12)

        hbox = gtk.HBox()
        hbox.set_spacing(12)
        hbox.set_border_width(6)
        
        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG)
        alignment = gtk.Alignment(yalign=0.0)
        alignment.add(image)
        hbox.pack_start(alignment, expand=False)

        
        vbox = gtk.VBox()

        primaryLabel = gtk.Label("")
        primaryLabel.set_use_markup(True)
        primaryLabel.set_markup('<span weight="bold" size="larger">%s</span>\n' % (primaryText))
        primaryLabel.set_line_wrap(True)
        primaryLabel.set_alignment(0.0, 0.0)
        primaryLabel.set_selectable(True)
        
        secondaryLabel = gtk.Label("")
        secondaryLabel.set_use_markup(True)
        secondaryLabel.set_markup(secondaryText)
        secondaryLabel.set_line_wrap(True)
        secondaryLabel.set_alignment(0.0, 0.0)
        secondaryLabel.set_selectable(True)
        
        vbox.pack_start(primaryLabel)
        vbox.pack_end(secondaryLabel)
        hbox.pack_end(vbox)

        hbox.show_all()

        self.vbox.add(hbox)