Default is the sys.stdout.isatty function which causes the debug option is not present when there is no terminal/tty to display the debugger.
---
meh/ui/__init__.py | 3 ++-
meh/ui/gui.py | 10 ++++++++--
meh/ui/text.py | 9 ++++++---
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/meh/ui/__init__.py b/meh/ui/__init__.py
index 8c174e1..053025f 100644
--- a/meh/ui/__init__.py
+++ b/meh/ui/__init__.py
@@ -47,12 +47,13 @@ class AbstractIntf(object):
"""
raise NotImplementedError
- def mainExceptionWindow(self, text, exnFile, *args, **kwargs):
+ def mainExceptionWindow(self, text, exnFile, allowDebug, *args, **kwargs):
"""Create and return an instance of the initial execption handling
dialog. This method must be provided by all subclasses.
text -- The short traceback (usually, just the stack trace).
exnFile -- A file containing the output of ExceptionDump.write().
+ allowDebug -- A function to decide whether allow using of debug option.
"""
raise NotImplementedError
diff --git a/meh/ui/gui.py b/meh/ui/gui.py
index ab6f56a..5e8c95a 100644
--- a/meh/ui/gui.py
+++ b/meh/ui/gui.py
@@ -19,6 +19,7 @@
from meh import *
from meh.ui import *
import os
+import sys
import report
from gi.repository import Gtk
@@ -47,8 +48,8 @@ class GraphicalIntf(AbstractIntf):
win.run()
win.destroy()
- def mainExceptionWindow(self, text, exnFile, *args, **kwargs):
- win = MainExceptionWindow(text, exnFile, *args, **kwargs)
+ def mainExceptionWindow(self, text, exnFile, allowDebug=sys.stdout.isatty, *args, **kwargs):
+ win = MainExceptionWindow(text, exnFile, allowDebug=allowDebug, *args, **kwargs)
return win
def messageWindow(self, title, message, *args, **kwargs):
@@ -86,6 +87,11 @@ class MainExceptionWindow(AbstractMainExceptionWindow):
self._traceback_buffer.set_text(longTraceback)
self._response = MAIN_RESPONSE_QUIT
+ self._debug_button = builder.get_object("debugButton")
+
+ if not kwargs["allowDebug"]():
+ self._debug_button.set_sensitive(False)
+
@property
def main_window(self):
return self._main_window
diff --git a/meh/ui/text.py b/meh/ui/text.py
index 7a28b3e..8a4bbd2 100644
--- a/meh/ui/text.py
+++ b/meh/ui/text.py
@@ -26,6 +26,7 @@ import report.io.TextIO
from report import LIBREPORT_WAIT, LIBREPORT_RUN_CLI
import os
+import sys
import gettext
_ = lambda x: gettext.ldgettext("python-meh", x)
@@ -116,9 +117,9 @@ class TextIntf(AbstractIntf):
win.run()
win.destroy()
- def mainExceptionWindow(self, text, exnFile, *args, **kwargs):
+ def mainExceptionWindow(self, text, exnFile, allowDebug=sys.stdout.isatty, *args, **kwargs):
kwargs["io_handler"] = self._io
- win = MainExceptionWindow(text, exnFile, *args, **kwargs)
+ win = MainExceptionWindow(text, exnFile, allowDebug=allowDebug, *args, **kwargs)
return win
def messageWindow(self, title, message, *args, **kwargs):
@@ -154,10 +155,12 @@ class MainExceptionWindow(TextWindow, AbstractMainExceptionWindow):
*args, **kwargs)
self._short_traceback = shortTraceback
self._menu_items = [(_("Report Bug"), MAIN_RESPONSE_SAVE),
- (_("Debug"), MAIN_RESPONSE_DEBUG),
(_("Run shell"), MAIN_RESPONSE_SHELL),
(_("Quit"), MAIN_RESPONSE_QUIT)]
+ if kwargs["allowDebug"]():
+ self._menu_items.append((_("Debug"), MAIN_RESPONSE_DEBUG))
+
def run(self, *args, **kwargs):
self.print_header()
self._io.print(self._short_traceback)
--
2.1.0