Philipp Hörist pushed to branch master at gajim / gajim

Commits:

3 changed files:

Changes:

  • data/gui/exception_dialog.ui
    1
    +<?xml version="1.0" encoding="UTF-8"?>
    
    2
    +<!-- Generated with glade 3.19.0 -->
    
    3
    +<interface>
    
    4
    +  <requires lib="gtk+" version="3.12"/>
    
    5
    +  <object class="GtkDialog" id="ExceptionDialog">
    
    6
    +    <property name="can_focus">False</property>
    
    7
    +    <property name="title" translatable="yes">Exception</property>
    
    8
    +    <property name="window_position">center</property>
    
    9
    +    <property name="icon_name">dialog-error</property>
    
    10
    +    <property name="type_hint">dialog</property>
    
    11
    +    <property name="gravity">center</property>
    
    12
    +    <child internal-child="vbox">
    
    13
    +      <object class="GtkBox" id="dialog-vbox">
    
    14
    +        <property name="can_focus">False</property>
    
    15
    +        <property name="margin_left">12</property>
    
    16
    +        <property name="margin_right">12</property>
    
    17
    +        <property name="margin_top">12</property>
    
    18
    +        <property name="margin_bottom">13</property>
    
    19
    +        <property name="orientation">vertical</property>
    
    20
    +        <property name="spacing">2</property>
    
    21
    +        <child internal-child="action_area">
    
    22
    +          <object class="GtkButtonBox" id="dialog-action_area">
    
    23
    +            <property name="can_focus">False</property>
    
    24
    +            <property name="margin_top">5</property>
    
    25
    +            <property name="layout_style">end</property>
    
    26
    +            <child>
    
    27
    +              <object class="GtkButton" id="close_btn">
    
    28
    +                <property name="label">gtk-close</property>
    
    29
    +                <property name="visible">True</property>
    
    30
    +                <property name="can_focus">True</property>
    
    31
    +                <property name="receives_default">True</property>
    
    32
    +                <property name="use_stock">True</property>
    
    33
    +                <property name="always_show_image">True</property>
    
    34
    +                <signal name="clicked" handler="on_close_clicked" swapped="no"/>
    
    35
    +              </object>
    
    36
    +              <packing>
    
    37
    +                <property name="expand">True</property>
    
    38
    +                <property name="fill">True</property>
    
    39
    +                <property name="position">0</property>
    
    40
    +              </packing>
    
    41
    +            </child>
    
    42
    +            <child>
    
    43
    +              <object class="GtkButton" id="report_btn">
    
    44
    +                <property name="label" translatable="yes">Report Bug</property>
    
    45
    +                <property name="visible">True</property>
    
    46
    +                <property name="can_focus">True</property>
    
    47
    +                <property name="receives_default">True</property>
    
    48
    +                <signal name="clicked" handler="on_report_clicked" swapped="no"/>
    
    49
    +              </object>
    
    50
    +              <packing>
    
    51
    +                <property name="expand">True</property>
    
    52
    +                <property name="fill">True</property>
    
    53
    +                <property name="position">1</property>
    
    54
    +              </packing>
    
    55
    +            </child>
    
    56
    +          </object>
    
    57
    +          <packing>
    
    58
    +            <property name="expand">False</property>
    
    59
    +            <property name="fill">False</property>
    
    60
    +            <property name="position">0</property>
    
    61
    +          </packing>
    
    62
    +        </child>
    
    63
    +        <child>
    
    64
    +          <object class="GtkGrid" id="grid">
    
    65
    +            <property name="visible">True</property>
    
    66
    +            <property name="can_focus">False</property>
    
    67
    +            <property name="row_spacing">20</property>
    
    68
    +            <property name="column_spacing">20</property>
    
    69
    +            <child>
    
    70
    +              <object class="GtkImage" id="image">
    
    71
    +                <property name="visible">True</property>
    
    72
    +                <property name="can_focus">False</property>
    
    73
    +                <property name="valign">center</property>
    
    74
    +                <property name="stock">gtk-dialog-error</property>
    
    75
    +                <property name="icon_size">6</property>
    
    76
    +              </object>
    
    77
    +              <packing>
    
    78
    +                <property name="left_attach">0</property>
    
    79
    +                <property name="top_attach">0</property>
    
    80
    +              </packing>
    
    81
    +            </child>
    
    82
    +            <child>
    
    83
    +              <object class="GtkLabel" id="msglabel">
    
    84
    +                <property name="visible">True</property>
    
    85
    +                <property name="can_focus">False</property>
    
    86
    +                <property name="halign">start</property>
    
    87
    +                <property name="valign">center</property>
    
    88
    +                <property name="hexpand">True</property>
    
    89
    +                <property name="label" translatable="yes">A programming error has been detected.
    
    90
    +It probably is not fatal, but should be reported
    
    91
    +to the developers nonetheless.</property>
    
    92
    +                <property name="max_width_chars">60</property>
    
    93
    +                <property name="lines">3</property>
    
    94
    +                <attributes>
    
    95
    +                  <attribute name="font-desc" value="&lt;Geben Sie den Wert ein&gt; 12"/>
    
    96
    +                </attributes>
    
    97
    +              </object>
    
    98
    +              <packing>
    
    99
    +                <property name="left_attach">1</property>
    
    100
    +                <property name="top_attach">0</property>
    
    101
    +              </packing>
    
    102
    +            </child>
    
    103
    +            <child>
    
    104
    +              <object class="GtkScrolledWindow" id="scrolledwindow">
    
    105
    +                <property name="height_request">150</property>
    
    106
    +                <property name="visible">True</property>
    
    107
    +                <property name="can_focus">True</property>
    
    108
    +                <property name="vexpand">True</property>
    
    109
    +                <property name="shadow_type">in</property>
    
    110
    +                <child>
    
    111
    +                  <object class="GtkTextView" id="exception_view">
    
    112
    +                    <property name="visible">True</property>
    
    113
    +                    <property name="can_focus">True</property>
    
    114
    +                    <property name="hexpand">True</property>
    
    115
    +                    <property name="vexpand">True</property>
    
    116
    +                    <property name="editable">False</property>
    
    117
    +                    <property name="left_margin">4</property>
    
    118
    +                    <property name="right_margin">4</property>
    
    119
    +                    <property name="accepts_tab">False</property>
    
    120
    +                  </object>
    
    121
    +                </child>
    
    122
    +              </object>
    
    123
    +              <packing>
    
    124
    +                <property name="left_attach">0</property>
    
    125
    +                <property name="top_attach">1</property>
    
    126
    +                <property name="width">2</property>
    
    127
    +              </packing>
    
    128
    +            </child>
    
    129
    +          </object>
    
    130
    +          <packing>
    
    131
    +            <property name="expand">True</property>
    
    132
    +            <property name="fill">True</property>
    
    133
    +            <property name="position">1</property>
    
    134
    +          </packing>
    
    135
    +        </child>
    
    136
    +      </object>
    
    137
    +    </child>
    
    138
    +  </object>
    
    139
    +</interface>

  • src/application.py
    ... ... @@ -94,6 +94,9 @@ class GajimApplication(Gtk.Application):
    94 94
     
    
    95 95
             Gtk.Application.do_activate(self)
    
    96 96
     
    
    97
    +        import gtkexcepthook
    
    98
    +        gtkexcepthook.init()
    
    99
    +
    
    97 100
             # Create and initialize Application Paths & Databases
    
    98 101
             import common.configpaths
    
    99 102
             common.configpaths.gajimpaths.init(
    

  • src/gtkexcepthook.py
    1 1
     # -*- coding:utf-8 -*-
    
    2 2
     ## src/gtkexcepthook.py
    
    3 3
     ##
    
    4
    +## Copyright (C) 2016 Philipp Hörist <philipp AT hoerist.com>
    
    4 5
     ## Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com>
    
    5 6
     ## Copyright (C) 2005-2014 Yann Leboulanger <asterix AT lagaule.org>
    
    6 7
     ## Copyright (C) 2008 Stephan Erb <steve-e AT h3c.de>
    
    ... ... @@ -24,83 +25,61 @@ import sys
    24 25
     import os
    
    25 26
     import traceback
    
    26 27
     import threading
    
    28
    +import webbrowser
    
    29
    +import gi
    
    27 30
     
    
    31
    +gi.require_version('Gtk', '3.0')
    
    28 32
     from gi.repository import Gtk
    
    29
    -from gi.repository import Gdk
    
    30
    -from gi.repository import Pango
    
    31
    -from common import i18n # installs _() function
    
    32
    -from dialogs import HigDialog
    
    33
    -
    
    34 33
     from io import StringIO
    
    35
    -from common import helpers
    
    34
    +from common import configpaths
    
    35
    +
    
    36
    +glade_file = os.path.join(configpaths.get('GUI'), 'exception_dialog.ui')
    
    36 37
     
    
    37 38
     _exception_in_progress = threading.Lock()
    
    38 39
     
    
    39
    -def _info(type_, value, tb):
    
    40
    +
    
    41
    +def _hook(type_, value, tb):
    
    40 42
         if not _exception_in_progress.acquire(False):
    
    41 43
             # Exceptions have piled up, so we use the default exception
    
    42 44
             # handler for such exceptions
    
    43
    -        _excepthook_save(type_, value, tb)
    
    45
    +        sys.__excepthook__(type_, value, tb)
    
    44 46
             return
    
    45 47
     
    
    46
    -    dialog = HigDialog(None, Gtk.MessageType.WARNING, Gtk.ButtonsType.NONE,
    
    47
    -                            _('A programming error has been detected'),
    
    48
    -                            _('It probably is not fatal, but should be reported '
    
    49
    -                            'to the developers nonetheless.'))
    
    48
    +    ExceptionDialog(type_, value, tb)
    
    49
    +    _exception_in_progress.release()
    
    50 50
     
    
    51
    -    dialog.set_modal(False)
    
    52
    -    #FIXME: add icon to this button
    
    53
    -    RESPONSE_REPORT_BUG = 42
    
    54
    -    dialog.add_buttons(Gtk.STOCK_CLOSE, Gtk.ButtonsType.CLOSE,
    
    55
    -            _('_Report Bug'), RESPONSE_REPORT_BUG)
    
    56
    -    report_button = dialog.action_area.get_children()[0] # right to left
    
    57
    -    report_button.grab_focus()
    
    58 51
     
    
    59
    -    # Details
    
    60
    -    textview = Gtk.TextView()
    
    61
    -    textview.set_editable(False)
    
    62
    -    textview.override_font(Pango.FontDescription('Monospace'))
    
    63
    -    sw = Gtk.ScrolledWindow()
    
    64
    -    sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
    
    65
    -    sw.add(textview)
    
    66
    -    frame = Gtk.Frame()
    
    67
    -    frame.set_shadow_type(Gtk.ShadowType.IN)
    
    68
    -    frame.add(sw)
    
    69
    -    frame.set_border_width(6)
    
    70
    -    textbuffer = textview.get_buffer()
    
    71
    -    trace = StringIO()
    
    72
    -    traceback.print_exception(type_, value, tb, None, trace)
    
    73
    -    textbuffer.set_text(trace.getvalue())
    
    74
    -    textview.set_size_request(
    
    75
    -            Gdk.Screen.width() / 3,
    
    76
    -            Gdk.Screen.height() / 4)
    
    77
    -    expander = Gtk.Expander(label=_('Details'))
    
    78
    -    expander.add(frame)
    
    79
    -    dialog.vbox.pack_start(expander, True, True, 0)
    
    52
    +class ExceptionDialog():
    
    53
    +    def __init__(self, type_, value, tb):
    
    54
    +        builder = Gtk.Builder()
    
    55
    +        builder.add_from_file(glade_file)
    
    56
    +        self.dialog = builder.get_object("ExceptionDialog")
    
    57
    +        builder.connect_signals(self)
    
    58
    +        builder.get_object("report_btn").grab_focus()
    
    59
    +        self.exception_view = builder.get_object("exception_view")
    
    60
    +        buffer_ = self.exception_view.get_buffer()
    
    61
    +        trace = StringIO()
    
    62
    +        traceback.print_exception(type_, value, tb, None, trace)
    
    63
    +        buffer_.set_text(trace.getvalue())
    
    64
    +        self.exception_view.set_editable(False)
    
    65
    +        self.dialog.run()
    
    80 66
     
    
    81
    -    dialog.set_resizable(True)
    
    82
    -    # on expand the details the dialog remains centered on screen
    
    83
    -    dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
    
    67
    +    def on_report_clicked(self, *args):
    
    68
    +        url = 'https://dev.gajim.org/gajim/gajim/issues'
    
    69
    +        webbrowser.open(url, new=2)
    
    84 70
     
    
    85
    -    def on_dialog_response(dialog, response):
    
    86
    -        if response == RESPONSE_REPORT_BUG:
    
    87
    -            url = 'http://trac.gajim.org/wiki/HowToCreateATicket'
    
    88
    -            helpers.launch_browser_mailer('url', url)
    
    89
    -        else:
    
    90
    -            dialog.destroy()
    
    91
    -    dialog.connect('response', on_dialog_response)
    
    92
    -    dialog.show_all()
    
    71
    +    def on_close_clicked(self, *args):
    
    72
    +        self.dialog.destroy()
    
    93 73
     
    
    94
    -    _exception_in_progress.release()
    
    95 74
     
    
    96
    -# gdb/kdm etc if we use startx this is not True
    
    97
    -if os.name == 'nt' or not sys.stderr.isatty():
    
    98
    -    #FIXME: maybe always show dialog?
    
    99
    -    _excepthook_save = sys.excepthook
    
    100
    -    sys.excepthook = _info
    
    75
    +def init():
    
    76
    +    # gdb/kdm etc if we use startx this is not True
    
    77
    +    if os.name == 'nt' or not sys.stderr.isatty():
    
    78
    +        # FIXME: maybe always show dialog?
    
    79
    +        sys.excepthook = _hook
    
    101 80
     
    
    102 81
     # this is just to assist testing (python gtkexcepthook.py)
    
    103 82
     if __name__ == '__main__':
    
    104
    -    _excepthook_save = sys.excepthook
    
    105
    -    sys.excepthook = _info
    
    83
    +    init()
    
    84
    +    print(sys.version)
    
    106 85
         raise Exception()