~nmu-sscheel/gtg/rework-task-editor

« back to all changes in this revision

Viewing changes to GTG/gtk/crashhandler.py

  • Committer: Bertrand Rousseau
  • Date: 2012-05-09 22:33:25 UTC
  • mfrom: (1178 trunk)
  • mto: This revision was merged to the branch mainline in revision 1179.
  • Revision ID: bertrand.rousseau@gmail.com-20120509223325-a53d8nwo0x9g93bc
Merge nimit branch and trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
 
64
64
dialog = None
65
65
 
 
66
 
66
67
def initialize(app_name=None, message=None, use_apport=False):
67
68
    """Initialize the except hook built on GTK.
68
69
 
115
116
                    sys.argv[0]))
116
117
            except:
117
118
                filename = os.path.realpath("/proc/%i/exe" % os.getpid())
118
 
            if not os.path.isfile(filename) or not os.access(filename, os.X_OK):
 
119
            if not os.path.isfile(filename) or \
 
120
                    not os.access(filename, os.X_OK):
119
121
                raise Exception()
120
122
            add_apport_button = likely_packaged(filename)
121
123
        except:
157
159
        sys.stderr = sys.__stderr__
158
160
        os._exit(1)
159
161
 
 
162
 
160
163
def show_error_window(error_string, add_apport_button=False):
161
164
    """Displays an error dialog, and returns the response ID.
162
165
 
181
184
 
182
185
    # title Label
183
186
    label = gtk.Label()
184
 
    label.set_markup("<b>" + _("It looks like an error has occurred.") + "</b>")
 
187
    label.set_markup("<b>%s</b>" % _("It looks like an error has occurred."))
185
188
    label.set_alignment(0, 0.5)
186
189
    dialog.get_content_area().pack_start(label, False)
187
190
 
191
194
    text_label.set_markup(MESSAGE)
192
195
    text_label.set_alignment(0, 0.5)
193
196
    text_label.set_line_wrap(True)
 
197
 
194
198
    def text_label_size_allocate(widget, rect):
195
199
        """Lets label resize correctly while wrapping text."""
196
200
        widget.set_size_request(rect.width, -1)
 
201
 
197
202
    text_label.connect("size-allocate", text_label_size_allocate)
198
203
    if not MESSAGE == "":
199
204
        dialog.get_content_area().pack_start(text_label, False)
243
248
        res = 2
244
249
    return res
245
250
 
 
251
 
246
252
def on_expanded(widget):
247
253
    global dialog
248
254
    dialog.set_size_request(600, 600)
264
270
    #Example 2:
265
271
    def function(arg):
266
272
        arg / 0 # this error will be caught by gtkcrashhandler
267
 
    threading.Thread(target=gtkcrashhandler_thread(function), args=(1,)).start()
 
273
    threading.Thread(target=gtkcrashhandler_thread(function),args=(1,)).start()
268
274
    """
 
275
 
269
276
    def gtkcrashhandler_wrapped_run(*args, **kwargs):
270
277
        try:
271
278
            run(*args, **kwargs)
276
283
            if gtk.main_level() > 0:
277
284
                gobject.idle_add(
278
285
                    lambda ee=ee, tb=tb, thread=threading.currentThread():
279
 
                    _replacement_excepthook(ee.__class__, ee, tb, thread=thread))
 
286
                    _replacement_excepthook(ee.__class__, ee, tb,
 
287
                                                            thread=thread))
280
288
            else:
281
289
                time.sleep(0.1) # ugly hack, seems like threads that are
282
290
                                # started before running gtk.main() cause
288
296
                _replacement_excepthook(ee.__class__, ee, tb,
289
297
                                        thread=threading.currentThread())
290
298
            lock.release()
 
299
 
291
300
    # return wrapped run if gtkcrashhandler has been initialized
292
301
    global _gtk_initialized, _old_sys_excepthook
293
302
    if _gtk_initialized and _old_sys_excepthook:
299
308
    # throw test exception
300
309
    initialize(app_name="gtkcrashhandler", message="Don't worry, though. This "
301
310
        "is just a test. To use the code properly, call "
302
 
        "gtkcrashhandler.initialize() in your PyGTK app to automatically catch "
303
 
        " any Python exceptions like this.")
 
311
        "gtkcrashhandler.initialize() in your PyGTK app to automatically "
 
312
        "catch any Python exceptions like this.")
 
313
 
304
314
    class DoNotRunException(Exception):
 
315
 
305
316
        def __str__(self):
306
317
            return "gtkcrashhandler.py should imported, not run"
 
318
 
307
319
    raise DoNotRunException()
308
320
 
309
321
 
310
322
## We handle initialization directly here, since this module will be used as a
311
323
#  singleton
312
 
        #we listen for signals from the system in order to save our configuration
313
 
        # if GTG is forcefully terminated (e.g.: on shutdown).
 
324
# we listen for signals from the system in order to save our configuration
 
325
# if GTG is forcefully terminated (e.g.: on shutdown).
 
326
 
314
327
@contextmanager
315
328
def signal_catcher(callback):
316
329
    #if TERM or ABORT are caught, we execute the callback function
319
332
    yield
320
333
 
321
334
initialize(app_name = "Getting Things GNOME!",
322
 
           message  =  "GTG" + info.VERSION + 
323
 
           _(" has crashed. Please report the bug on <a "\
324
 
             "href=\"http://bugs.edge.launchpad.net/gtg\">our Launchpad page</a>."\
325
 
             " If you have Apport installed, it will be started for you."),       \
 
335
           message  =  "GTG" + info.VERSION +
 
336
           _(" has crashed. Please report the bug on <a href=\""
 
337
           "http://bugs.edge.launchpad.net/gtg\">our Launchpad page</a>."
 
338
             " If you have Apport installed, it will be started for you."),
326
339
          use_apport = True)