Improve ExceptionDialog
- Add OS/System info to report text - Use ApplicationWindow - Supply all the infos directly to gitlab via url params
This commit is contained in:
		
							parent
							
								
									513bffd483
								
							
						
					
					
						commit
						67a008ea80
					
				
					 2 changed files with 117 additions and 69 deletions
				
			
		|  | @ -1,65 +1,21 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!-- Generated with glade 3.19.0 --> | ||||
| <!-- Generated with glade 3.20.2 --> | ||||
| <interface> | ||||
|   <requires lib="gtk+" version="3.12"/> | ||||
|   <object class="GtkDialog" id="ExceptionDialog"> | ||||
|   <object class="GtkApplicationWindow" id="ExceptionDialog"> | ||||
|     <property name="can_focus">False</property> | ||||
|     <property name="title" translatable="yes">Exception</property> | ||||
|     <property name="window_position">center</property> | ||||
|     <property name="icon_name">dialog-error</property> | ||||
|     <property name="type_hint">dialog</property> | ||||
|     <property name="gravity">center</property> | ||||
|     <child internal-child="vbox"> | ||||
|       <object class="GtkBox" id="dialog-vbox"> | ||||
|     <child> | ||||
|       <object class="GtkBox"> | ||||
|         <property name="visible">True</property> | ||||
|         <property name="can_focus">False</property> | ||||
|         <property name="margin_left">12</property> | ||||
|         <property name="margin_right">12</property> | ||||
|         <property name="margin_top">12</property> | ||||
|         <property name="margin_bottom">13</property> | ||||
|         <property name="margin_bottom">12</property> | ||||
|         <property name="orientation">vertical</property> | ||||
|         <property name="spacing">2</property> | ||||
|         <child internal-child="action_area"> | ||||
|           <object class="GtkButtonBox" id="dialog-action_area"> | ||||
|             <property name="can_focus">False</property> | ||||
|             <property name="margin_top">5</property> | ||||
|             <property name="layout_style">end</property> | ||||
|             <child> | ||||
|               <object class="GtkButton" id="close_btn"> | ||||
|                 <property name="label">gtk-close</property> | ||||
|                 <property name="visible">True</property> | ||||
|                 <property name="can_focus">True</property> | ||||
|                 <property name="receives_default">True</property> | ||||
|                 <property name="use_stock">True</property> | ||||
|                 <property name="always_show_image">True</property> | ||||
|                 <signal name="clicked" handler="on_close_clicked" swapped="no"/> | ||||
|               </object> | ||||
|               <packing> | ||||
|                 <property name="expand">True</property> | ||||
|                 <property name="fill">True</property> | ||||
|                 <property name="position">0</property> | ||||
|               </packing> | ||||
|             </child> | ||||
|             <child> | ||||
|               <object class="GtkButton" id="report_btn"> | ||||
|                 <property name="label" translatable="yes">Report Bug</property> | ||||
|                 <property name="visible">True</property> | ||||
|                 <property name="can_focus">True</property> | ||||
|                 <property name="receives_default">True</property> | ||||
|                 <signal name="clicked" handler="on_report_clicked" swapped="no"/> | ||||
|               </object> | ||||
|               <packing> | ||||
|                 <property name="expand">True</property> | ||||
|                 <property name="fill">True</property> | ||||
|                 <property name="position">1</property> | ||||
|               </packing> | ||||
|             </child> | ||||
|           </object> | ||||
|           <packing> | ||||
|             <property name="expand">False</property> | ||||
|             <property name="fill">False</property> | ||||
|             <property name="position">0</property> | ||||
|           </packing> | ||||
|         </child> | ||||
|         <property name="spacing">6</property> | ||||
|         <child> | ||||
|           <object class="GtkGrid" id="grid"> | ||||
|             <property name="visible">True</property> | ||||
|  | @ -86,9 +42,8 @@ | |||
|                 <property name="halign">start</property> | ||||
|                 <property name="valign">center</property> | ||||
|                 <property name="hexpand">True</property> | ||||
|                 <property name="label" translatable="yes">A programming error has been detected. | ||||
| It probably is not fatal, but should be reported | ||||
| to the developers nonetheless.</property> | ||||
|                 <property name="label" translatable="yes">A programming error has been detected. It probably is not fatal, but should be reported to the developers nonetheless.</property> | ||||
|                 <property name="wrap">True</property> | ||||
|                 <property name="max_width_chars">60</property> | ||||
|                 <property name="lines">3</property> | ||||
|                 <attributes> | ||||
|  | @ -130,10 +85,57 @@ to the developers nonetheless.</property> | |||
|           <packing> | ||||
|             <property name="expand">True</property> | ||||
|             <property name="fill">True</property> | ||||
|             <property name="position">0</property> | ||||
|           </packing> | ||||
|         </child> | ||||
|         <child> | ||||
|           <object class="GtkButtonBox"> | ||||
|             <property name="visible">True</property> | ||||
|             <property name="can_focus">False</property> | ||||
|             <property name="spacing">6</property> | ||||
|             <property name="layout_style">end</property> | ||||
|             <child> | ||||
|               <object class="GtkButton" id="close_btn"> | ||||
|                 <property name="label">gtk-close</property> | ||||
|                 <property name="visible">True</property> | ||||
|                 <property name="can_focus">True</property> | ||||
|                 <property name="receives_default">True</property> | ||||
|                 <property name="use_stock">True</property> | ||||
|                 <property name="always_show_image">True</property> | ||||
|                 <signal name="clicked" handler="on_close_clicked" swapped="no"/> | ||||
|               </object> | ||||
|               <packing> | ||||
|                 <property name="expand">True</property> | ||||
|                 <property name="fill">True</property> | ||||
|                 <property name="position">0</property> | ||||
|               </packing> | ||||
|             </child> | ||||
|             <child> | ||||
|               <object class="GtkButton" id="report_btn"> | ||||
|                 <property name="label" translatable="yes">Report Bug</property> | ||||
|                 <property name="visible">True</property> | ||||
|                 <property name="can_focus">True</property> | ||||
|                 <property name="receives_default">True</property> | ||||
|                 <signal name="clicked" handler="on_report_clicked" swapped="no"/> | ||||
|               </object> | ||||
|               <packing> | ||||
|                 <property name="expand">True</property> | ||||
|                 <property name="fill">True</property> | ||||
|                 <property name="position">1</property> | ||||
|               </packing> | ||||
|             </child> | ||||
|           </object> | ||||
|           <packing> | ||||
|             <property name="expand">False</property> | ||||
|             <property name="fill">True</property> | ||||
|             <property name="pack_type">end</property> | ||||
|             <property name="position">1</property> | ||||
|           </packing> | ||||
|         </child> | ||||
|       </object> | ||||
|     </child> | ||||
|     <child> | ||||
|       <placeholder/> | ||||
|     </child> | ||||
|   </object> | ||||
| </interface> | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| # -*- coding:utf-8 -*- | ||||
| ## src/gtkexcepthook.py | ||||
| ## gajim/gtkexcepthook.py | ||||
| ## | ||||
| ## Copyright (C) 2016 Philipp Hörist <philipp AT hoerist.com> | ||||
| ## Copyright (C) 2016-2018 Philipp Hörist <philipp AT hoerist.com> | ||||
| ## Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com> | ||||
| ## Copyright (C) 2005-2014 Yann Leboulanger <asterix AT lagaule.org> | ||||
| ## Copyright (C) 2008 Stephan Erb <steve-e AT h3c.de> | ||||
|  | @ -26,17 +26,36 @@ import os | |||
| import traceback | ||||
| import threading | ||||
| import webbrowser | ||||
| import gi | ||||
| 
 | ||||
| gi.require_version('Gtk', '3.0') | ||||
| from gi.repository import Gtk | ||||
| import platform | ||||
| from io import StringIO | ||||
| from gajim.common import configpaths | ||||
| from urllib.parse import urlencode | ||||
| 
 | ||||
| import nbxmpp | ||||
| import gi | ||||
| gi.require_version('Gtk', '3.0') | ||||
| from gi.repository import Gtk, GObject | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     glade_file = os.path.join('data', 'gui', 'exception_dialog.ui') | ||||
| else: | ||||
|     from gajim.common import configpaths | ||||
|     glade_file = os.path.join(configpaths.get('GUI'), 'exception_dialog.ui') | ||||
| 
 | ||||
| glade_file = os.path.join(configpaths.get('GUI'), 'exception_dialog.ui') | ||||
| 
 | ||||
| _exception_in_progress = threading.Lock() | ||||
| 
 | ||||
| ISSUE_TEXT = '''## Versions | ||||
| - OS: {} | ||||
| - GTK+ Version: {} | ||||
| - PyGObject Version: {} | ||||
| - python-nbxmpp Version: {} | ||||
| 
 | ||||
| ## Traceback | ||||
| ``` | ||||
| {} | ||||
| ``` | ||||
| ## Steps to reproduce the problem | ||||
| ...''' | ||||
| 
 | ||||
| def _hook(type_, value, tb): | ||||
|     if not _exception_in_progress.acquire(False): | ||||
|  | @ -60,26 +79,53 @@ class ExceptionDialog(): | |||
|         buffer_ = self.exception_view.get_buffer() | ||||
|         trace = StringIO() | ||||
|         traceback.print_exception(type_, value, tb, None, trace) | ||||
|         buffer_.set_text(trace.getvalue()) | ||||
|         self.text = self.get_issue_text(trace.getvalue()) | ||||
|         buffer_.set_text(self.text) | ||||
|         self.exception_view.set_editable(False) | ||||
|         self.dialog.run() | ||||
|         self.dialog.show() | ||||
| 
 | ||||
|     def on_report_clicked(self, *args): | ||||
|         url = 'https://dev.gajim.org/gajim/gajim/issues' | ||||
|         issue_url = 'https://dev.gajim.org/gajim/gajim/issues/new' | ||||
|         params = {'issue[description]': self.text} | ||||
|         url = '{}?{}'.format(issue_url, urlencode(params)) | ||||
|         webbrowser.open(url, new=2) | ||||
| 
 | ||||
|     def on_close_clicked(self, *args): | ||||
|         self.dialog.destroy() | ||||
| 
 | ||||
|     def get_issue_text(self, traceback_text): | ||||
|         gtk_ver = '%i.%i.%i' % ( | ||||
|             Gtk.get_major_version(), | ||||
|             Gtk.get_minor_version(), | ||||
|             Gtk.get_micro_version()) | ||||
|         gobject_ver = '.'.join(map(str, GObject.pygobject_version)) | ||||
| 
 | ||||
|         return ISSUE_TEXT.format(get_os_info(), | ||||
|                                  gtk_ver, | ||||
|                                  gobject_ver, | ||||
|                                  nbxmpp.__version__, | ||||
|                                  traceback_text) | ||||
| 
 | ||||
| 
 | ||||
| def init(): | ||||
|     # gdb/kdm etc if we use startx this is not True | ||||
|     if os.name == 'nt' or not sys.stderr.isatty(): | ||||
|         # FIXME: maybe always show dialog? | ||||
|         sys.excepthook = _hook | ||||
| 
 | ||||
| # this is just to assist testing (python gtkexcepthook.py) | ||||
| 
 | ||||
| def get_os_info(): | ||||
|     if os.name == 'nt' or sys.platform == 'darwin': | ||||
|         return platform.system() + " " + platform.release() | ||||
|     elif os.name == 'posix': | ||||
|         try: | ||||
|             import distro | ||||
|             return distro.name(pretty=True) | ||||
|         except ImportError: | ||||
|             return platform.system() | ||||
|     return '' | ||||
| 
 | ||||
| # this is just to assist testing (python3 gtkexcepthook.py) | ||||
| if __name__ == '__main__': | ||||
|     init() | ||||
|     print(sys.version) | ||||
|     raise Exception() | ||||
|     ExceptionDialog(None, None, None) | ||||
|     Gtk.main() | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue