~flimm/epidermis/icon-theme-bugfix

« back to all changes in this revision

Viewing changes to epidermis/gtkcrashhandler.py

  • Committer: David D Lowe
  • Date: 2011-01-04 22:50:19 UTC
  • Revision ID: daviddlowe.flimm@gmail.com-20110104225019-uo31kb54cbxjt5vt
Tidy up code with better comments.
Deleted unused functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    import pango
25
25
    import gobject
26
26
    _gtk_initialized = True
27
 
except Exception:
 
27
except ImportError, AssertionError:
28
28
    print >> sys.stderr, "gtkcrashhandler could not load GTK 2.0"
29
29
    _gtk_initialized = False
30
30
import traceback
32
32
import threading
33
33
 
34
34
APP_NAME = None
35
 
MESSAGE = _("We're terribly sorry. Could you help us fix the problem by " \
36
 
                  "reporting the crash?")
 
35
MESSAGE = None
37
36
USE_APPORT = False
38
37
 
39
 
_old_sys_excepthook = None # None means that initialize() has not been called
40
 
                                                   # yet.
 
38
_old_sys_excepthook = None # None means that initialize() has not been called yet.
41
39
 
42
40
def initialize(app_name=None, message=None, use_apport=False):
43
41
    """Initialize the except hook built on GTK.
56
54
 
57
55
    """
58
56
    global APP_NAME, MESSAGE, USE_APPORT, _gtk_initialized, _old_sys_excepthook
59
 
    if app_name:
60
 
        APP_NAME = _(app_name)
61
 
    if not message is None:
62
 
        MESSAGE = _(message)
63
 
    if use_apport:
64
 
        USE_APPORT = use_apport
 
57
    APP_NAME = app_name
 
58
    MESSAGE = message
 
59
    USE_APPORT = use_apport
65
60
    if _gtk_initialized == True and _old_sys_excepthook is None:
66
61
        # save sys.excepthook first, as it may not be sys.__excepthook__
67
62
        # (for example, it might be Apport's python hook)
83
78
    add_apport_button = False
84
79
    global USE_APPORT
85
80
    if USE_APPORT:
86
 
        # see if this file is from a properly installed distribution package
 
81
        # see if this file is from a properly installed distribution package
87
82
        try:
88
83
            from apport.fileutils import likely_packaged
 
84
            # this bit borrowed from apport_python_hook.py
 
85
            # apport will look up the package from the executable path.
89
86
            try:
90
87
                filename = os.path.realpath(os.path.join(os.getcwdu(),
91
 
                        sys.argv[0]))
92
 
            except:
93
 
                filename = os.path.realpath("/proc/%i/exe" % os.getpid())
94
 
            if not os.path.isfile(filename) or not os.access(filename, os.X_OK):
95
 
                raise Exception()
 
88
                       sys.argv[0]))
 
89
            except (TypeError, AttributeError, IndexError):
 
90
                filename = os.readlink('/proc/%i/exe' % os.getpid())
 
91
            if not os.access(filename, os.X_OK) or not os.path.isfile(filename):
 
92
                raise
96
93
            add_apport_button = likely_packaged(filename)
97
94
        except:
98
95
            add_apport_button = False
102
99
    if res == 3: # report button clicked
103
100
        # enable apport, overriding preferences
104
101
        try:
 
102
            # This method works for old versions of Apport
105
103
            # create new temporary configuration file, where enabled=1
106
104
            import re
107
105
            from apport.packaging_impl import impl as apport_packaging
120
118
 
121
119
            # set apport to use this configuration file, temporarily
122
120
            apport_packaging.configuration = tempfilename
 
121
            
 
122
            # This method works for newer versions of Apport, tested with
 
123
            # Apport version 1.13.3
 
124
            import apport_python_hook
 
125
            apport_python_hook.enabled = lambda: True
 
126
            
 
127
            
123
128
            # override Apport's ignore settings for this app
124
129
            from apport.report import Report
125
130
            Report.check_ignored = lambda self: False
126
 
 
127
 
            # Apport 1.12.2 introduced new function for checking whether
128
 
            # apport is enabled or not, we need to override it
129
 
            import apport_python_hook
130
 
            apport_python_hook.enabled = lambda: True
131
131
        except:
132
132
            pass
133
133
 
151
151
    title = _("An error has occurred")
152
152
    global APP_NAME
153
153
    if APP_NAME:
154
 
        title = APP_NAME
 
154
        title = _(APP_NAME)
155
155
    dialog = gtk.Dialog(title)
156
156
 
157
157
    # title Label
162
162
 
163
163
    # message Label
164
164
    global MESSAGE
165
 
    text_label = gtk.Label(MESSAGE)
 
165
    if MESSAGE:
 
166
        text_label = gtk.Label(MESSAGE)
 
167
    else:
 
168
        text_label = gtk.Label(_("Unfortunately, we haven't yet found and "
 
169
                            "corrected this problem. You might want to "
 
170
                            "report the crash to the developers."))
166
171
    text_label.set_alignment(0, 0.5)
167
 
    
168
172
    text_label.set_line_wrap(True)
169
173
    def text_label_size_allocate(widget, rect):
170
174
        """Lets label resize correctly while wrapping text."""
211
215
 
212
216
    # show the dialog and act on it
213
217
    dialog.show_all()
214
 
    gtk_main_level = gtk.main_level()
215
 
    if gtk_main_level > 0:
216
 
        gtk.gdk.threads_enter()
217
218
    res = dialog.run()
218
 
    if gtk_main_level > 0:
219
 
        gtk.gdk.threads_leave()
220
219
    dialog.destroy()
221
 
    if gtk_main_level <= 0:
222
 
        while gtk.events_pending():
223
 
            gtk.main_iteration(False)
224
220
    if res < 0:
225
221
        res = 2
226
222
    return res