From 5f177adca97752eb2fdf641317b3f2fb133447a5 Mon Sep 17 00:00:00 2001
From: Benoit Favre <benoit.favre@lif.univ-mrs.fr>
Date: Mon, 23 Feb 2015 16:25:27 +0100
Subject: [PATCH] add global keybindings

---
 README  |  2 +-
 asr.py  |  6 +++---
 main.py | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/README b/README
index bc0de12..1d72c00 100644
--- a/README
+++ b/README
@@ -46,6 +46,7 @@ DONE click action = perform action
 DONE add thread for slu
 DONE remove section changer UI
 DONE change xml view to reflect already performed actions, already recognized text
+DONE add global keybindings (1-9 for sections, y/n)...
 
 events = click action or words to resynchronize ?
 click line = synchronize to that line
@@ -55,4 +56,3 @@ add logger
 move slu to asr
 make selector a proper window
 allow sequence advance in slu, add UI for that
-add global keybindings (1-9 for sections, y/n)...
diff --git a/asr.py b/asr.py
index 5ec2c60..54166c0 100644
--- a/asr.py
+++ b/asr.py
@@ -167,12 +167,12 @@ class ASR(Gtk.HBox):
 
     def button_clicked(self, button):
         """Handle button presses."""
-        if button.get_label() == "Record":
-            button.set_label("Stop")
+        if self.button.get_label() == "Record":
+            self.button.set_label("Stop")
             self.asr.set_property("silent", False)
             self.hyp = []
             self.buffer.set_text('...')
         else:
-            button.set_label("Record")
+            self.button.set_label("Record")
             self.asr.set_property("silent", True)
             
diff --git a/main.py b/main.py
index f95a2fd..bee5ccb 100644
--- a/main.py
+++ b/main.py
@@ -78,6 +78,38 @@ class ScriptedASR(Gtk.Window):
         self.kept_history = ''
         self.kept_actions = []
 
+        self.connect('key-press-event', self.global_keybindings)
+
+    def global_keybindings(self, widget, event):
+        if event.keyval == Gdk.KEY_1:
+            self.set_section(0)
+        elif event.keyval == Gdk.KEY_2:
+            self.set_section(1)
+        elif event.keyval == Gdk.KEY_3:
+            self.set_section(2)
+        elif event.keyval == Gdk.KEY_4:
+            self.set_section(3)
+        elif event.keyval == Gdk.KEY_5:
+            self.set_section(4)
+        elif event.keyval == Gdk.KEY_6:
+            self.set_section(5)
+        elif event.keyval == Gdk.KEY_7:
+            self.set_section(6)
+        elif event.keyval == Gdk.KEY_8:
+            self.set_section(7)
+        elif event.keyval == Gdk.KEY_9:
+            self.set_section(8)
+        elif event.keyval == Gdk.KEY_y:
+            self.confirmer.click_yes()
+        elif event.keyval == Gdk.KEY_n:
+            self.confirmer.click_no()
+        elif event.keyval == Gdk.KEY_space:
+            if not self.asr.button.has_focus():
+                self.asr.button_clicked(None)
+        else:
+            return True
+        return False
+
     def set_section(self, section_id):
         self.xmlview.set_section(section_id)
 
-- 
GitLab