Improve ExceptionDialog
- Move to gtk module - Use get_builder() so translation works - Add GLib version - Remove standalone testing code
This commit is contained in:
parent
79a37f6992
commit
0e2a9c724f
3 changed files with 28 additions and 44 deletions
|
@ -2,7 +2,7 @@
|
||||||
<!-- Generated with glade 3.22.1 -->
|
<!-- Generated with glade 3.22.1 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
<object class="GtkApplicationWindow" id="ExceptionDialog">
|
<object class="GtkApplicationWindow" id="exception_dialog">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="window_position">center</property>
|
<property name="window_position">center</property>
|
||||||
<property name="type_hint">dialog</property>
|
<property name="type_hint">dialog</property>
|
||||||
|
|
|
@ -67,8 +67,8 @@ def _init_gtk():
|
||||||
'Quitting...' % _MIN_GTK_VER)
|
'Quitting...' % _MIN_GTK_VER)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
from gajim import gtkexcepthook
|
from gajim.gtk import exception
|
||||||
gtkexcepthook.init()
|
exception.init()
|
||||||
|
|
||||||
i18n.initialize_direction_mark()
|
i18n.initialize_direction_mark()
|
||||||
|
|
||||||
|
|
|
@ -23,25 +23,19 @@ import traceback
|
||||||
import threading
|
import threading
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import platform
|
import platform
|
||||||
|
from pathlib import Path
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
from gi.repository import Gtk
|
||||||
|
from gi.repository import GObject
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
import nbxmpp
|
import nbxmpp
|
||||||
from gi.repository import Gtk, GObject
|
|
||||||
|
|
||||||
try:
|
import gajim
|
||||||
import gajim
|
from gajim.common import configpaths
|
||||||
gajim_version = gajim.__version__
|
from gajim.gtk.util import get_builder
|
||||||
except ImportError:
|
|
||||||
# For standalone testing
|
|
||||||
gajim_version = 'Package not installed'
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
glade_file = os.path.join('data', 'gui', 'exception_dialog.ui')
|
|
||||||
else:
|
|
||||||
from gajim.common import configpaths
|
|
||||||
gui_path = configpaths.get('GUI')
|
|
||||||
glade_file = os.path.join(gui_path, 'exception_dialog.ui')
|
|
||||||
|
|
||||||
|
|
||||||
_exception_in_progress = threading.Lock()
|
_exception_in_progress = threading.Lock()
|
||||||
|
@ -50,6 +44,7 @@ ISSUE_TEXT = '''## Versions
|
||||||
- OS: {}
|
- OS: {}
|
||||||
- GTK+ Version: {}
|
- GTK+ Version: {}
|
||||||
- PyGObject Version: {}
|
- PyGObject Version: {}
|
||||||
|
- GLib Version : {}
|
||||||
- python-nbxmpp Version: {}
|
- python-nbxmpp Version: {}
|
||||||
- Gajim Version: {}
|
- Gajim Version: {}
|
||||||
|
|
||||||
|
@ -74,22 +69,21 @@ def _hook(type_, value, tb):
|
||||||
|
|
||||||
class ExceptionDialog():
|
class ExceptionDialog():
|
||||||
def __init__(self, type_, value, tb):
|
def __init__(self, type_, value, tb):
|
||||||
builder = Gtk.Builder()
|
path = Path(configpaths.get('GUI')) / 'exception_dialog.ui'
|
||||||
builder.add_from_file(glade_file)
|
self._ui = get_builder(path.resolve())
|
||||||
self.dialog = builder.get_object("ExceptionDialog")
|
self._ui.connect_signals(self)
|
||||||
builder.connect_signals(self)
|
|
||||||
builder.get_object("report_btn").grab_focus()
|
self._ui.report_btn.grab_focus()
|
||||||
self.exception_view = builder.get_object("exception_view")
|
|
||||||
buffer_ = self.exception_view.get_buffer()
|
buffer_ = self._ui.exception_view.get_buffer()
|
||||||
trace = StringIO()
|
trace = StringIO()
|
||||||
traceback.print_exception(type_, value, tb, None, trace)
|
traceback.print_exception(type_, value, tb, None, trace)
|
||||||
self.text = self.get_issue_text(trace.getvalue())
|
self.text = self.get_issue_text(trace.getvalue())
|
||||||
buffer_.set_text(self.text)
|
buffer_.set_text(self.text)
|
||||||
print(self.text)
|
print(self.text)
|
||||||
self.exception_view.set_editable(False)
|
|
||||||
self.dialog.show()
|
self._ui.exception_view.set_editable(False)
|
||||||
if __name__ == '__main__':
|
self._ui.exception_dialog.show()
|
||||||
self.dialog.connect('delete-event', self._on_delete_event)
|
|
||||||
|
|
||||||
def on_report_clicked(self, *args):
|
def on_report_clicked(self, *args):
|
||||||
issue_url = 'https://dev.gajim.org/gajim/gajim/issues/new'
|
issue_url = 'https://dev.gajim.org/gajim/gajim/issues/new'
|
||||||
|
@ -98,25 +92,23 @@ class ExceptionDialog():
|
||||||
webbrowser.open(url, new=2)
|
webbrowser.open(url, new=2)
|
||||||
|
|
||||||
def on_close_clicked(self, *args):
|
def on_close_clicked(self, *args):
|
||||||
self.dialog.destroy()
|
self._ui.exception_dialog.destroy()
|
||||||
if __name__ == '__main__':
|
|
||||||
Gtk.main_quit()
|
|
||||||
|
|
||||||
def _on_delete_event(self, *args):
|
@staticmethod
|
||||||
Gtk.main_quit()
|
def get_issue_text(traceback_text):
|
||||||
|
|
||||||
def get_issue_text(self, traceback_text):
|
|
||||||
gtk_ver = '%i.%i.%i' % (
|
gtk_ver = '%i.%i.%i' % (
|
||||||
Gtk.get_major_version(),
|
Gtk.get_major_version(),
|
||||||
Gtk.get_minor_version(),
|
Gtk.get_minor_version(),
|
||||||
Gtk.get_micro_version())
|
Gtk.get_micro_version())
|
||||||
gobject_ver = '.'.join(map(str, GObject.pygobject_version))
|
gobject_ver = '.'.join(map(str, GObject.pygobject_version))
|
||||||
|
glib_ver = '.'.join(map(str, GLib.glib_version))
|
||||||
|
|
||||||
return ISSUE_TEXT.format(get_os_info(),
|
return ISSUE_TEXT.format(get_os_info(),
|
||||||
gtk_ver,
|
gtk_ver,
|
||||||
gobject_ver,
|
gobject_ver,
|
||||||
|
glib_ver,
|
||||||
nbxmpp.__version__,
|
nbxmpp.__version__,
|
||||||
gajim_version,
|
gajim.__version__,
|
||||||
traceback_text)
|
traceback_text)
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,11 +127,3 @@ def get_os_info():
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return platform.system()
|
return platform.system()
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
# this is just to assist testing (python3 gtkexcepthook.py)
|
|
||||||
if __name__ == '__main__':
|
|
||||||
init()
|
|
||||||
print(sys.version)
|
|
||||||
ExceptionDialog(None, None, None)
|
|
||||||
Gtk.main()
|
|
Loading…
Add table
Reference in a new issue