Browse Source

add shell gui

nico 8 years ago
parent
commit
223ba413bc
7 changed files with 140 additions and 10 deletions
  1. 1 0
      Docs/dev_env_install.md
  2. 10 0
      core/ConfigurationManager/ConfigurationManager.py
  3. 88 0
      core/ShellGui.py
  4. 1 1
      core/__init__.py
  5. 28 2
      jarvis.py
  6. 2 7
      test.py
  7. 10 0
      test_arg_parser.py

+ 1 - 0
Docs/dev_env_install.md

@@ -31,4 +31,5 @@ pip install SpeechRecognition
 pip install pyaudio
 pip install ansible
 pip install pygame
+pip install python2-pythondialog
 ```

+ 10 - 0
core/ConfigurationManager/ConfigurationManager.py

@@ -133,3 +133,13 @@ class ConfigurationManager:
         args = find(texts_to_speech, tts_name)
         logging.debug("Args for %s STT: %s" % (tts_name, args))
         return args
+
+    @classmethod
+    def get_tts_list(cls):
+        settings = cls.get_settings()
+        try:
+            texts_to_speech = settings["text_to_speech"]
+        except KeyError:
+            raise NoSpeechToTextConfiguration("No text_to_speech in settings")
+
+        return texts_to_speech

+ 88 - 0
core/ShellGui.py

@@ -0,0 +1,88 @@
+from dialog import Dialog
+import locale
+
+from core import ConfigurationManager
+from neurons import Say
+
+
+class ShellGui:
+    def __init__(self):
+        # get settings
+        self.conf = ConfigurationManager().get_settings()
+        locale.setlocale(locale.LC_ALL, '')
+
+        self.d = Dialog(dialog="dialog")
+
+        self.d.set_background_title("Jarvis shell UI")
+
+        self.show_main_menu()
+
+    def show_main_menu(self):
+        """
+        Main menu of the shell UI.
+        Provide a list of action the user can select to test his settings
+        :return:
+        """
+
+        code, tag = self.d.menu("Test your JARVIS settings from this menu",
+                                choices=[("TTS", "Text to Speech"),
+                                         ("STT", "Speech to text")])
+
+        if code == self.d.OK:
+            if tag == "STT":
+                self.show_stt_test_menu()
+            if tag == "TTS":
+                self.show_tts_test_menu()
+
+    def show_stt_test_menu(self):
+        pass
+
+    def show_tts_test_menu(self, sentence_to_test=None):
+        """
+         A menu for testing text to speech
+        :return:
+        """
+        continue_bool = True
+        # if we don't have yet a sentence to test, we ask the user to type one
+        if sentence_to_test is None:
+            # First, we ask the user to type a sentence that will be passed in the TTS
+            code, sentence_to_test = self.d.inputbox("Please type the sentence you want to test", height=20, width=50)
+
+            if code == self.d.CANCEL:
+                self.show_main_menu()
+                continue_bool = False
+            if code == self.d.OK:
+                continue_bool = True
+
+        if continue_bool:
+            # we get TTS from settings
+            tts_list = ConfigurationManager.get_tts_list()
+
+            # create a list of tuple that can be used by the dialog menu
+            choices = list()
+            for tts in tts_list:
+                for name, settings in tts.iteritems():
+                    print name
+                    print settings
+                    tup = (str(name), str(settings))
+                    choices.append(tup)
+
+            code, tag = self.d.menu("Sentence to test: %s" % sentence_to_test,
+                                    choices=choices)
+
+            if code == self.d.CANCEL:
+                self.show_tts_test_menu()
+            if code == self.d.OK:
+                self._run_tts_test(tag, sentence_to_test)
+                # then go back to this menu with the same sentence
+                self.show_tts_test_menu(sentence_to_test=sentence_to_test)
+
+    def _run_tts_test(self, tag, sentence_to_test):
+        """
+        Call the TTS
+        :param tag:
+        :param sentence_to_test:
+        :return:
+        """
+        Say(message=sentence_to_test, tts=tag)
+

+ 1 - 1
core/__init__.py

@@ -3,4 +3,4 @@ from core.JarvisTrigger import JarvisTrigger
 from core.OrderAnalyser import OrderAnalyser
 from core.OrderListener import OrderListener
 from core.AudioPlayer import AudioPlayer
-
+from core.ShellGui import ShellGui

+ 28 - 2
jarvis.py

@@ -1,12 +1,38 @@
+#!/usr/bin/env python
+import argparse
 from core.MainController import MainController
+import signal
+import sys
+
+
+def signal_handler(signal, frame):
+        print "\n"
+        print('Ctrl+C pressed. Killing Jarvis')
+        sys.exit(0)
 
 
 def main():
     """
     Entry point of jarvis program
     """
-    main_controller = MainController()
-    main_controller.start()
+    # create arguments
+    parser = argparse.ArgumentParser(description='JARVIS')
+    parser.add_argument("--start", action='store_true', help="Start Jarvis in the current shell")
+    parser.add_argument("--gui", action='store_true', help="Run Jarvis with shell GUI to test components")
+
+    # parse arguments from script parameters
+    args = parser.parse_args()
+
+    if args.start:
+        print "Starting JARVIS. Press Ctrl+C for stopping"
+        # catch signal for killing on Ctrl+C pressed
+        signal.signal(signal.SIGINT, signal_handler)
+        # start the main controller
+        main_controller = MainController()
+        main_controller.start()
+
+    if args.gui:
+        pass
 
 if __name__ == '__main__':
     main()

+ 2 - 7
test.py

@@ -7,13 +7,8 @@ from neurons import Say
 from neurons.ansible_tasks.ansible_tasks import Ansible_tasks
 import logging
 
-logger = logging.getLogger()
-logger.setLevel(logging.DEBUG)
-
-
-order = OrderAnalyser("dis bonjour")
-
-order.start()
+from core import ShellGui
 
 
 
+shelgui = ShellGui()

+ 10 - 0
test_arg_parser.py

@@ -0,0 +1,10 @@
+import os
+
+# print help
+# cmd = "python jarvis.py -h"
+
+# start jarvis
+cmd = "python jarvis.py --start"
+
+
+os.system(cmd)