summaryrefslogtreecommitdiff
path: root/grc/gui/Dialogs.py
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2013-11-07 12:14:46 +0100
committerJohnathan Corgan <johnathan@corganlabs.com>2013-11-07 16:21:47 -0800
commit43398a55d959b12fb34a6cc9a7b2f14a0ecc9979 (patch)
treee5ad55bd51c5b4af60425eb8478c895564c2b194 /grc/gui/Dialogs.py
parent59ab46d521d11b9ad14da5221cb7fa269ab9dea7 (diff)
grc: make backspace chars work in TextDisplay
Diffstat (limited to 'grc/gui/Dialogs.py')
-rw-r--r--grc/gui/Dialogs.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py
index 5b3b420d3b..04e4f0a862 100644
--- a/grc/gui/Dialogs.py
+++ b/grc/gui/Dialogs.py
@@ -35,12 +35,32 @@ class TextDisplay(gtk.TextView):
text_buffer = gtk.TextBuffer()
text_buffer.set_text(text)
self.set_text = text_buffer.set_text
- self.insert = lambda line: text_buffer.insert(text_buffer.get_end_iter(), line)
gtk.TextView.__init__(self, text_buffer)
self.set_editable(False)
self.set_cursor_visible(False)
self.set_wrap_mode(gtk.WRAP_WORD_CHAR)
+ def insert(self, line):
+ # make backspaces work
+ line = self._consume_backspaces(line)
+ # add the remaining text to buffer
+ self.get_buffer().insert(self.get_buffer().get_end_iter(), line)
+
+ def _consume_backspaces(self, line):
+ """removes text from the buffer if line starts with \b*"""
+ if not line: return
+ # for each \b delete one char from the buffer
+ back_count = 0
+ start_iter = self.get_buffer().get_end_iter()
+ while line[back_count] == '\b':
+ # stop at the beginning of a line
+ if not start_iter.starts_line(): start_iter.backward_char()
+ back_count += 1
+ # remove chars
+ self.get_buffer().delete(start_iter, self.get_buffer().get_end_iter())
+ # return remaining text
+ return line[back_count:]
+
def MessageDialogHelper(type, buttons, title=None, markup=None):
"""
Create a modal message dialog and run it.