├── resources ├── error.png ├── icons.png ├── sound.wav ├── command.png ├── process.png ├── success.png ├── icons │ ├── add.png │ ├── edit.png │ ├── help.png │ ├── setup.png │ ├── try.png │ └── remove.png └── Waiting │ ├── wait-0.png │ ├── wait-1.png │ ├── wait-10.png │ ├── wait-11.png │ ├── wait-12.png │ ├── wait-13.png │ ├── wait-14.png │ ├── wait-15.png │ ├── wait-16.png │ ├── wait-17.png │ ├── wait-2.png │ ├── wait-3.png │ ├── wait-4.png │ ├── wait-5.png │ ├── wait-6.png │ ├── wait-7.png │ ├── wait-8.png │ └── wait-9.png ├── mama.desktop ├── modules ├── goto.py ├── google.py ├── weather.py ├── wikipedia.py └── youtube.py ├── mama-manager.desktop ├── mama-manager.py ├── library ├── ModuleSelection.py ├── WorkWithModule.py ├── Listener.py ├── MessageDialogWindow.py ├── MainWindow.py ├── HelpWindow.py ├── StringParser.py ├── BingTextToSpeech.py ├── BasicCommands.py ├── ExternalWindow.py ├── Interface.py ├── InternalWindow.py ├── ArgsWindow.py ├── SetupWindow.py └── AddWindow.py ├── .gitignore ├── mama.py ├── notifier.py ├── install.py ├── config └── en_EN │ └── default.xml ├── updater.py ├── README.md └── LICENSE /resources/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/error.png -------------------------------------------------------------------------------- /resources/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/icons.png -------------------------------------------------------------------------------- /resources/sound.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/sound.wav -------------------------------------------------------------------------------- /resources/command.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/command.png -------------------------------------------------------------------------------- /resources/process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/process.png -------------------------------------------------------------------------------- /resources/success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/success.png -------------------------------------------------------------------------------- /resources/icons/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/icons/add.png -------------------------------------------------------------------------------- /resources/icons/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/icons/edit.png -------------------------------------------------------------------------------- /resources/icons/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/icons/help.png -------------------------------------------------------------------------------- /resources/icons/setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/icons/setup.png -------------------------------------------------------------------------------- /resources/icons/try.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/icons/try.png -------------------------------------------------------------------------------- /resources/icons/remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/icons/remove.png -------------------------------------------------------------------------------- /resources/Waiting/wait-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-0.png -------------------------------------------------------------------------------- /resources/Waiting/wait-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-1.png -------------------------------------------------------------------------------- /resources/Waiting/wait-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-10.png -------------------------------------------------------------------------------- /resources/Waiting/wait-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-11.png -------------------------------------------------------------------------------- /resources/Waiting/wait-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-12.png -------------------------------------------------------------------------------- /resources/Waiting/wait-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-13.png -------------------------------------------------------------------------------- /resources/Waiting/wait-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-14.png -------------------------------------------------------------------------------- /resources/Waiting/wait-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-15.png -------------------------------------------------------------------------------- /resources/Waiting/wait-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-16.png -------------------------------------------------------------------------------- /resources/Waiting/wait-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-17.png -------------------------------------------------------------------------------- /resources/Waiting/wait-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-2.png -------------------------------------------------------------------------------- /resources/Waiting/wait-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-3.png -------------------------------------------------------------------------------- /resources/Waiting/wait-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-4.png -------------------------------------------------------------------------------- /resources/Waiting/wait-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-5.png -------------------------------------------------------------------------------- /resources/Waiting/wait-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-6.png -------------------------------------------------------------------------------- /resources/Waiting/wait-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-7.png -------------------------------------------------------------------------------- /resources/Waiting/wait-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-8.png -------------------------------------------------------------------------------- /resources/Waiting/wait-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maateen/mama/HEAD/resources/Waiting/wait-9.png -------------------------------------------------------------------------------- /mama.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Mama 3 | Comment=Voice driven Linux OS controller 4 | Exec=python3 /usr/share/mama/mama.py 5 | Icon=/usr/share/mama/resources/icons.png 6 | Terminal=false 7 | Type=Application 8 | Categories=Utility;Application; -------------------------------------------------------------------------------- /modules/goto.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import re 4 | 5 | if len(sys.argv) >= 2: 6 | web = sys.argv[1] 7 | web = web.replace(' ', '+') 8 | web = web.lower() 9 | 10 | url = 'www.' + web 11 | os.system('xdg-open ' + url + ' &') 12 | -------------------------------------------------------------------------------- /mama-manager.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Mama Manager 3 | Comment=Manage and control Mama from this GUI 4 | Exec=python3 /usr/share/mama/mama-manager.py 5 | Icon=/usr/share/mama/resources/icons.png 6 | Terminal=false 7 | Type=Application 8 | Categories=Utility;Application; -------------------------------------------------------------------------------- /modules/google.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | # Parsing arguments 5 | try: 6 | if sys.argv[1]: 7 | param = sys.argv[1] 8 | execute = "xdg-open https://www.google.com/search?q=" + param + "&gws_rd=ssl" 9 | os.system(execute) 10 | else: 11 | print("Not enough parameters to search on google.") 12 | except: 13 | print("Not enough parameters to search on google.") 14 | -------------------------------------------------------------------------------- /modules/weather.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | # Parsing arguments 5 | try: 6 | if sys.argv[1]: 7 | param = sys.argv[1] 8 | execute = "xdg-open https://www.google.com/search?q=weather+in+" + param + "&gws_rd=ssl" 9 | os.system(execute) 10 | else: 11 | print("Not enough parameters to search weather.") 12 | except: 13 | print("Not enough parameters to search weather.") 14 | -------------------------------------------------------------------------------- /modules/wikipedia.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | # Parsing arguments 5 | try: 6 | if sys.argv[1]: 7 | param = sys.argv[1] 8 | execute = "xdg-open https://en.wikipedia.org/wiki/" + param + "" 9 | print(execute) 10 | os.system(execute) 11 | else: 12 | print("Not enough parameters to search on wikipedia.") 13 | except: 14 | print("Not enough parameters to search on wikipedia.") 15 | -------------------------------------------------------------------------------- /modules/youtube.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | # Parsing arguments 5 | try: 6 | if sys.argv[1]: 7 | param = sys.argv[1] 8 | execute = "xdg-open https://www.youtube.com/results?search_query" \ 9 | "=" + param + "" 10 | print(execute) 11 | os.system(execute) 12 | else: 13 | print("Not enough parameters to search on youtube.") 14 | except: 15 | print("Not enough parameters to search on youtube.") 16 | -------------------------------------------------------------------------------- /mama-manager.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version('Gtk', '3.0') 4 | from gi.repository import Gtk 5 | import os 6 | import sys 7 | 8 | sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/library') 9 | from MainWindow import MainWindow 10 | 11 | 12 | class MyApplication(Gtk.Application): 13 | """ 14 | @description: Initializing the main window for Mama Manager 15 | """ 16 | def __init__(self): 17 | Gtk.Application.__init__(self) 18 | 19 | def do_activate(self): 20 | win = MainWindow(self) 21 | win.show_all() 22 | 23 | def do_startup(self): 24 | Gtk.Application.do_startup(self) 25 | 26 | 27 | app = MyApplication() 28 | exit_status = app.run(sys.argv) 29 | sys.exit(exit_status) 30 | -------------------------------------------------------------------------------- /library/ModuleSelection.py: -------------------------------------------------------------------------------- 1 | import gi 2 | gi.require_version('Gtk', '3.0') 3 | from gi.repository import Gtk 4 | import os 5 | 6 | # manage the development of the module selection window 7 | class ModuleSelection(): 8 | """ 9 | @description: This class display an fileChooserDialog when the user 10 | wants to add a new module from the menu of the main window 11 | """ 12 | def __init__(self): 13 | w=Gtk.Window() 14 | dialog = Gtk.FileChooserDialog(_("Choose a file"), w,Gtk.FileChooserAction.OPEN,(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) 15 | dialog.set_default_size(800, 400) 16 | 17 | response = dialog.run() 18 | self.module = '-1' 19 | if response == Gtk.ResponseType.OK: 20 | self.module=dialog.get_filename() 21 | elif response == Gtk.ResponseType.CANCEL: 22 | print("Cancel clicked") 23 | 24 | dialog.destroy() 25 | 26 | def getModule(self): 27 | """ 28 | @description: return the module selected 29 | 30 | @return: return the path to the executable of the module 31 | """ 32 | return self.module 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | 91 | #Custom -------------------------------------------------------------------------------- /library/WorkWithModule.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | class WorkWithModule(): 5 | 6 | """ 7 | @description: This class allows you to call external modules. If a call 8 | for an external module is detected by the parser then this class check 9 | the module's config file before extracting modules's parameter from the 10 | text you have pronounced 11 | """ 12 | 13 | def __init__(self, module_name, text, linker, plus, PID): 14 | self.pid = PID 15 | 16 | try: 17 | sentence = text.lower() 18 | 19 | if sentence.count(linker) > 0: 20 | param = (sentence.split(linker, 1)[1]) 21 | 22 | # we check whether the user wants to turn '' into + 23 | if plus == '1': 24 | param = param.replace(' ', '+') 25 | # command that will be executed 26 | parent_dir = os.path.dirname(os.path.abspath(__file__)).strip( 27 | 'library') 28 | module_dir = os.path.join(parent_dir, 'modules') 29 | execute = 'python3 ' + module_dir + '/' + module_name + ' ' + param 30 | os.system(execute) 31 | else: 32 | message = "you didn't say the linking word" 33 | os.system( 34 | 'echo "' + message + '" > /tmp/mama/mama_error_' + self.pid) 35 | 36 | except IOError: 37 | message = 'args file missing' 38 | os.system('echo "'+message+'" > /tmp/mama/mama_error_'+self.pid) 39 | sys.exit(1) 40 | -------------------------------------------------------------------------------- /library/Listener.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import wave 4 | 5 | import pyaudio 6 | 7 | 8 | class Listener(): 9 | """ 10 | @description: This class will record the voice as wav. 11 | """ 12 | 13 | def __init__(self, config, pid): 14 | audio_chunk = config['audio_chunk'] 15 | audio_format = pyaudio.paInt16 # paInt8 16 | audio_channels = config['audio_channels'] 17 | audio_rate = config['audio_rate'] 18 | recording_time = config['recording_time'] 19 | wav_file_path = "/tmp/mama/output.wav" 20 | 21 | p = pyaudio.PyAudio() 22 | 23 | stream = p.open(format=audio_format, 24 | channels=audio_channels, 25 | rate=audio_rate, 26 | input=True, 27 | frames_per_buffer=audio_chunk) # buffer 28 | 29 | # we play a sound to signal the start 30 | parent_dir = os.path.dirname(os.path.abspath(__file__)).strip('librairy') 31 | os.system('play ' + parent_dir + 'resources/sound.wav') 32 | print("* recording") 33 | os.system('touch /tmp/mama/mama_start_' + pid) 34 | 35 | frames = [] 36 | 37 | for i in range(0, int(audio_rate / audio_chunk * recording_time)): 38 | data = stream.read(audio_chunk) 39 | frames.append(data) # 2 bytes(16 bits) per channel 40 | 41 | print("* done recording") 42 | os.system('touch /tmp/mama/mama_record_complete_' + pid) 43 | 44 | stream.stop_stream() 45 | stream.close() 46 | p.terminate() 47 | 48 | wf = wave.open(wav_file_path, 'wb') 49 | wf.setnchannels(audio_channels) 50 | wf.setsampwidth(p.get_sample_size(audio_format)) 51 | wf.setframerate(audio_rate) 52 | wf.writeframes(b''.join(frames)) 53 | wf.close() 54 | -------------------------------------------------------------------------------- /library/MessageDialogWindow.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version('Gtk', '3.0') 4 | from gi.repository import Gtk 5 | 6 | 7 | class MessageDialogWindow(Gtk.Window): 8 | """ 9 | @description: This class show info, warning and error message dialog 10 | To show it on nay page just import the class and then 11 | win = MessageDialogWindow() 12 | win.show_warn_message() 13 | win.show_all() 14 | @param: text 15 | text will show in the dialog 16 | """ 17 | 18 | def __init__(self, text): 19 | Gtk.Window.__init__(self) 20 | self.text = text 21 | 22 | def show_info_message(self): 23 | dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO, 24 | Gtk.ButtonsType.OK, 25 | "Info") 26 | dialog.format_secondary_text(self.text) 27 | dialog.run() 28 | print("Info dialog closed") 29 | 30 | dialog.destroy() 31 | 32 | def show_error_message(self): 33 | dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR, 34 | Gtk.ButtonsType.CANCEL, 35 | "Error") 36 | dialog.format_secondary_text(self.text) 37 | dialog.run() 38 | print("Error dialog closed") 39 | 40 | dialog.destroy() 41 | 42 | def show_warn_message(self): 43 | dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.WARNING, 44 | Gtk.ButtonsType.OK_CANCEL, 45 | "Warning") 46 | dialog.format_secondary_text(self.text) 47 | response = dialog.run() 48 | if response == Gtk.ResponseType.OK: 49 | print("Warning dialog closed by clicking OK button") 50 | elif response == Gtk.ResponseType.CANCEL: 51 | print("Warning dialog closed by clicking CANCEL button") 52 | 53 | dialog.destroy() 54 | -------------------------------------------------------------------------------- /mama.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from os import system 3 | from os.path import abspath 4 | from os.path import dirname 5 | from os.path import exists 6 | from os.path import expanduser 7 | 8 | sys.path.append(dirname(abspath(__file__)) + '/library') 9 | from Interface import Interface 10 | from MessageDialogWindow import MessageDialogWindow 11 | 12 | # Declaring some variables, config{} dict will contain all config info 13 | config = {} 14 | config_file = expanduser('~') + '/.config/mama/mama.conf' 15 | temp_dir = '/tmp/mama/' 16 | has_key = False 17 | has_id = False 18 | 19 | # Lets check the existence of temp_dir, create if not 20 | if not exists(temp_dir): 21 | system("mkdir -p '" + temp_dir + "'") 22 | 23 | try: 24 | with open(config_file, "r") as f: 25 | for line in f.readlines(): 26 | line = line.strip('\n') 27 | field = line.split('=') 28 | if field[0] == 'locale': 29 | config['locale'] = field[1].replace('"', '') 30 | elif field[0] == 'audio_chunk': 31 | config['audio_chunk'] = int(field[1]) 32 | elif field[0] == 'audio_channels': 33 | config['audio_channels'] = int(field[1]) 34 | elif field[0] == 'audio_rate': 35 | config['audio_rate'] = int(field[1]) 36 | elif field[0] == 'recording_time': 37 | config['recording_time'] = int(field[1]) 38 | elif field[0] == 'client_id': 39 | config['client_id'] = field[1].replace('"', '') 40 | has_id = True 41 | elif field[0] == 'api_key': 42 | config['api_key'] = field[1].replace('"', '') 43 | has_key = True 44 | elif field[0] == 'speaker': 45 | speaker = field[1].replace('"', '') 46 | speaker = speaker.split(' ') 47 | config['speaker'] = speaker[1].strip('()') 48 | 49 | except Exception: 50 | # Show error message with dialog 51 | error_dialog = MessageDialogWindow("Error reading mama.conf file") 52 | error_dialog.show_error_message() 53 | error_dialog.show_all() 54 | 55 | if has_id and has_key: 56 | # launch the recognition 57 | Interface(config) 58 | -------------------------------------------------------------------------------- /library/MainWindow.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version('Gtk', '3.0') 4 | from gi.repository import Gtk 5 | from AddWindow import AddWindow 6 | from SetupWindow import SetupWindow 7 | import os 8 | 9 | 10 | class MainWindow(Gtk.ApplicationWindow): 11 | """ 12 | @description: This class display the main window that the user will 13 | see when he wants to manage his commands 14 | """ 15 | 16 | def __init__(self, app): 17 | Gtk.Window.__init__(self, title="Mama Manager", application=app) 18 | self.set_default_size(800, 400) 19 | self.set_resizable(True) 20 | self.set_border_width(0) 21 | self.get_focus() 22 | self.set_position(Gtk.WindowPosition.CENTER) 23 | path = os.path.dirname(os.path.abspath(__file__)).strip('librairy') 24 | self.icon_path = path + 'resources/icons/' 25 | self.set_default_icon_from_file(path + '/resources/icons.png') 26 | 27 | # get two button to switch between view 28 | setup_icon = Gtk.Image() 29 | setup_icon.set_from_file(self.icon_path + 'setup.png') 30 | button_config = Gtk.ToolButton(icon_widget=setup_icon) 31 | button_config.set_label("Setup") 32 | button_config.set_is_important(True) 33 | button_config.set_tooltip_text('Open setup window') 34 | button_config.show() 35 | button_config.connect("clicked", self.change_page, 1) 36 | 37 | button_back = Gtk.Button.new_from_stock(Gtk.STOCK_OK) 38 | button_back.connect("clicked", self.change_page, 0) 39 | button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL) 40 | button_cancel.connect("clicked", self.change_page, 0) 41 | 42 | # get the main view 43 | content = AddWindow(button_config) 44 | label_main = Gtk.Label("main") 45 | config = SetupWindow(button_back, button_cancel) 46 | label_config = Gtk.Label("config") 47 | 48 | # create a Gtk.Notebook to store both page 49 | self.notebook = Gtk.Notebook.new() 50 | self.notebook.set_show_tabs(False) 51 | self.notebook.append_page(content.get_grid(), label_main) 52 | self.notebook.append_page(config.getGrid(), label_config) 53 | 54 | # show 55 | self.add(self.notebook) 56 | self.show_all() 57 | 58 | def change_page(self, button, page): 59 | self.notebook.set_current_page(page) 60 | -------------------------------------------------------------------------------- /library/HelpWindow.py: -------------------------------------------------------------------------------- 1 | import gi 2 | gi.require_version('Gtk', '3.0') 3 | from gi.repository import Gtk 4 | 5 | # manage the appearance of the Help window 6 | class HelpWindow(): 7 | """ 8 | @description: Diaplay an help window 9 | """ 10 | def __init__(self): 11 | #a Gtk.AboutDialog 12 | self.aboutdialog = Gtk.AboutDialog() 13 | 14 | # lists of authors and documenters (will be used later) 15 | authors = ["Maksudur Rahman Maateen "] 16 | documenters = ["Maksudur Rahman Maateen "] 17 | 18 | # we fill in the aboutdialog 19 | self.aboutdialog.set_program_name("About Mama") 20 | self.aboutdialog.set_version("Version 0.1") 21 | self.aboutdialog.set_copyright("Maksudur Rahman Maateen \xa9 2016") 22 | self.aboutdialog.set_comments("The aim of this project is to let you " 23 | "use Microsoft powered Bing Speech " 24 | "Recognition API to control your Linux " 25 | "computer. The project is developed in " 26 | "Python3. For note, this is a fork of " 27 | "project google2ubuntu - <" 28 | "https://github.com/benoitfragit/google2ubuntu/>." 29 | " Thanks Franquet Benoit for your google2ubuntu.") 30 | self.aboutdialog.set_license_type (Gtk.License.GPL_3_0,) 31 | self.aboutdialog.set_website("https://maateen.github.io/mama/") 32 | self.aboutdialog.set_website_label("https://maateen.github.io/mama/") 33 | self.aboutdialog.set_authors(authors) 34 | self.aboutdialog.set_documenters(documenters) 35 | 36 | # Resetting the window title 37 | self.aboutdialog.set_title("About Mama") 38 | 39 | # to close the aboutdialog when "close" is clicked we connect the 40 | # "response" signal to on_close 41 | self.aboutdialog.connect("response", self.on_close) 42 | # show the aboutdialog 43 | self.aboutdialog.show() 44 | 45 | # destroy the aboutdialog 46 | def on_close(self, action, parameter): 47 | """ 48 | @description: function called when the user wants to close the window 49 | 50 | @param: action 51 | the window to close 52 | """ 53 | action.destroy() 54 | -------------------------------------------------------------------------------- /library/StringParser.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import xml.etree.ElementTree as ET 4 | 5 | from BasicCommands import BasicCommands 6 | from WorkWithModule import WorkWithModule 7 | 8 | 9 | class StringParser(): 10 | """ 11 | @description: This class parses the text retrieve by Microsoft in order 12 | to distinguish external commands, internal commands and modules 13 | """ 14 | 15 | def __init__(self, config, text, File, PID): 16 | # read configuration files 17 | self.pid = PID 18 | try: 19 | max_size = 0 20 | text = text.lower() 21 | tree = ET.parse(File) 22 | root = tree.getroot() 23 | tp = '' 24 | 25 | for entry in root.findall('entry'): 26 | score = 0 27 | entry_name = entry.get('name') 28 | voice_key = entry.find('key').text 29 | command_to_apply = entry.find('command').text 30 | the_linker = entry.find('linker').text 31 | space_by_plus = entry.find('spacebyplus').text 32 | 33 | key = voice_key.split(' ') 34 | for j in range(len(key)): 35 | score += text.count(key[j]) 36 | 37 | if max_size < score: 38 | max_size = score 39 | do = command_to_apply 40 | tp = entry_name 41 | linker = the_linker 42 | spacebyplus = space_by_plus 43 | 44 | os.system('echo "' + do + '" > /tmp/mama/mama_cmd_' + self.pid) 45 | if 'modules' in tp: 46 | # if we find the word "modules", a WorkWithModule class and we pass it we instantiate 47 | # the folder ie weather, search, ...; the module name weather.sh ie, search.sh and against delivery 48 | WorkWithModule(do, text, linker, spacebyplus, self.pid) 49 | elif 'internal' in tp: 50 | # we execute an internal command, the command is configured 51 | # and internal / battery, battery is sent to the function 52 | BasicCommands(config, do, self.pid) 53 | elif 'external' in tp: 54 | os.system(do + ' &') 55 | else: 56 | os.system('xdotool type "' + do + '"') 57 | 58 | os.system('touch /tmp/mama/mama_stop_' + self.pid) 59 | 60 | 61 | except Exception as e: 62 | message = 'Setup file missing' 63 | os.system( 64 | 'echo "' + message + '" > /tmp/mama/mama_error_' + self.pid) 65 | sys.exit(1) 66 | -------------------------------------------------------------------------------- /notifier.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version('Notify', '0.7') 4 | import os 5 | import sys 6 | import time 7 | from gi.repository import Notify 8 | 9 | RESULT = False 10 | path = os.path.dirname(os.path.abspath(__file__)) 11 | path += '/resources' 12 | 13 | if len(sys.argv) >= 2: 14 | PID = sys.argv[1] 15 | # name of files 16 | start = '/tmp/mama/mama_start_' + PID 17 | stop = '/tmp/mama/mama_stop_' + PID 18 | result = '/tmp/mama/mama_result_' + PID 19 | cmd = '/tmp/mama/mama_cmd_' + PID 20 | error = '/tmp/mama/mama_error_' + PID 21 | display = '/tmp/mama/mama_display_' + PID 22 | record_complete = '/tmp/mama/mama_record_complete_' + PID 23 | 24 | # initialization 25 | Notify.init("Mama") 26 | n = Notify.Notification.new('Mama', 'Ready', path + "/icons.png") 27 | n.set_urgency(Notify.Urgency.CRITICAL) 28 | n.show() 29 | 30 | while not os.path.exists(start): 31 | n.update('mama', 'Ready', path + "/icons.png") 32 | n.show() 33 | 34 | i = 0 35 | while not os.path.exists(stop): 36 | if os.path.exists(error): 37 | f = open(error, "r") 38 | title = 'Error' 39 | body = f.readline().rstrip('\n') 40 | f.close 41 | n.update(title, body, icon=path + "/error.png") 42 | n.show() 43 | n.close() 44 | Notify.uninit() 45 | os.system('rm /tmp/mama/mama_*_' + PID + ' 2>/dev/null') 46 | sys.exit(1) 47 | 48 | if os.path.exists(result) and not RESULT: 49 | f = open(result, "r") 50 | title = 'Recognition result' 51 | body = f.readline().rstrip('\n') 52 | icon = path + "/success.png" 53 | f.close() 54 | RESULT = True 55 | elif os.path.exists(cmd) and RESULT: 56 | f = open(cmd, "r") 57 | title = 'Calling command' 58 | body = f.readline().rstrip('\n') 59 | icon = path + "/command.png" 60 | f.close() 61 | elif os.path.exists(display): 62 | f = open(display, "r") 63 | title = 'Information' 64 | body = f.readline().rstrip('\n') 65 | f.close 66 | icon = path + "/icons.png" 67 | elif os.path.exists(record_complete): 68 | title = 'Great! Got it.' 69 | body = 'Processing ...' 70 | icon = path + "/process.png" 71 | else: 72 | title = 'Hearing ...' 73 | body = 'Please speak' 74 | icon = path + "/Waiting/wait-" + str(i) + ".png" 75 | time.sleep(0.1) 76 | 77 | n.update(title, body, icon) 78 | n.show() 79 | i += 1 80 | if i > 17: 81 | i = 0 82 | 83 | n.update("Mama", 'Task completed!', path + "/icons.png") 84 | n.show() 85 | n.close() 86 | Notify.uninit() 87 | os.system('rm /tmp/mama/* 2>/dev/null') 88 | -------------------------------------------------------------------------------- /library/BingTextToSpeech.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | import json 3 | import os 4 | import sys 5 | import urllib.parse 6 | 7 | 8 | class TextToSpeech(): 9 | """ 10 | @description: Let mama to use the Microsoft Bing Text-to-Speech API 11 | 12 | @param config 13 | A dictionary containing Microsoft Bing Speech API Key and Azure 14 | client ID, also some other info 15 | 16 | @param text 17 | the text to read to the user 18 | """ 19 | 20 | def __init__(self, config, text, pid): 21 | client_id = config['client_id'] 22 | api_key = config['api_key'] 23 | host = "https://speech.platform.bing.com" 24 | 25 | params = urllib.parse.urlencode( 26 | {'grant_type': 'client_credentials', 'client_id': client_id, 27 | 'client_secret': api_key, 'scope': host}) 28 | 29 | headers = {"Content-type": "application/x-www-form-urlencoded"} 30 | 31 | access_token_host = "oxford-speech.cloudapp.net" 32 | token_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 33 | "/token/issueToken") 34 | 35 | # Connecting to server to get the Microsoft Bing Speech API Access Token 36 | conn = http.client.HTTPSConnection(access_token_host, timeout=10) 37 | conn.request("POST", token_path, params, headers) 38 | response = conn.getresponse() 39 | 40 | if response.status == 200: 41 | data = response.read() 42 | conn.close() 43 | access_token = data.decode("UTF-8") 44 | 45 | # Decoding the object from json 46 | decoded_data = json.loads(access_token) 47 | access_token = decoded_data['access_token'] 48 | 49 | body = "" + text + "" 53 | 54 | headers = {"Content-type": "application/ssml+xml", 55 | "X-Microsoft-OutputFormat": "riff-16khz-16bit-mono-pcm", 56 | "Authorization": "Bearer " + access_token, 57 | "X-Search-AppId": "07D3234E49CE426DAA29772419F436CA", 58 | "X-Search-ClientID": "1ECFAE91408841A480F00935DC390960", 59 | "User-Agent": "Mama"} 60 | 61 | # Connect to server to synthesize the wave 62 | conn = http.client.HTTPSConnection("speech.platform.bing.com") 63 | conn.request("POST", "/synthesize", body, headers) 64 | response = conn.getresponse() 65 | print(response.status, response.reason) 66 | 67 | data = response.read() 68 | conn.close() 69 | wf = open('/tmp/mama/tts.wav', 'wb') 70 | wf.write(data) 71 | wf.close() 72 | os.system('play /tmp/mama/tts.wav') 73 | os.system('touch /tmp/mama/mama_stop_' + pid) 74 | sys.exit(1) 75 | else: 76 | os.system( 77 | 'echo "' + response.reason + '" > /tmp/mama/mama_error_' + pid) 78 | sys.exit(1) 79 | -------------------------------------------------------------------------------- /install.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import gi 4 | 5 | gi.require_version('Gtk', '3.0') 6 | from gi.repository import Gtk 7 | 8 | 9 | class MessageDialogWindow(Gtk.Window): 10 | """ 11 | @description: This class show info, warning and error message dialog 12 | To show it on nay page just import the class and then 13 | win = MessageDialogWindow() 14 | win.show_warn_message() 15 | win.show_all() 16 | @param: text 17 | text will show in the dialog 18 | """ 19 | 20 | def __init__(self): 21 | Gtk.Window.__init__(self) 22 | dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO, 23 | Gtk.ButtonsType.OK, 24 | "Mama! New version Installed Successfully") 25 | dialog.run() 26 | print("Info dialog closed") 27 | 28 | dialog.destroy() 29 | 30 | # Initializing the parent and directory 31 | parent_dir = os.path.dirname(os.path.abspath(__file__)) 32 | print('Parent directory: ' + parent_dir) 33 | target_dir = '/usr/share/mama' 34 | print('Target directory: ' + target_dir) 35 | # Checking target directory existence 36 | if os.path.exists(target_dir): 37 | print('Target directory exists, so making it empty.') 38 | os.system("gksu \"rm -rf " + target_dir + "\"") 39 | os.system("gksu \"mkdir -p " + target_dir + "\"") 40 | else: 41 | os.system("gksu \"mkdir -p " + target_dir + "\"") 42 | print('Target directory does not exist, so created.') 43 | 44 | # Now copying files and folders 45 | config_dir = parent_dir + '/config' 46 | os.system("gksu \"cp -vr " + config_dir + " " + target_dir + "\"") 47 | library_dir = parent_dir + '/library' 48 | os.system("gksu \"cp -vr " + library_dir + " " + target_dir + "\"") 49 | modules_dir = parent_dir + '/modules' 50 | os.system("gksu \"cp -vr " + modules_dir + " " + target_dir + "\"") 51 | resources_dir = parent_dir + '/resources' 52 | os.system("gksu \"cp -vr " + resources_dir + " " + target_dir + "\"") 53 | os.system("gksu \"cp -v " + parent_dir + "/mama.py" + " " + target_dir + "\"") 54 | os.system( 55 | "gksu \"cp -v " + parent_dir + "/mama-manager.py" + " " + target_dir + "\"") 56 | os.system( 57 | "gksu \"cp -v " + parent_dir + "/notifier.py" + " " + target_dir + "\"") 58 | os.system( 59 | "gksu \"cp -v " + parent_dir + "/updater.py" + " " + target_dir + "\"") 60 | 61 | # Now copying desktop launcher 62 | print('Now making desktop launcher.') 63 | if os.path.exists('/usr/share/applications/mama.desktop'): 64 | os.system("gksu \"rm /usr/share/applications/mama.desktop\"") 65 | os.system( 66 | "gksu \"cp -v " + parent_dir + "/mama.desktop" + " /usr/share/applications\"") 67 | else: 68 | os.system( 69 | "gksu \"cp -v " + parent_dir + "/mama.desktop" + " /usr/share/applications\"") 70 | 71 | if os.path.exists('/usr/share/applications/mama-manager.desktop'): 72 | os.system("gksu \"rm /usr/share/applications/mama-manager.desktop\"") 73 | os.system("gksu \"cp -v " + parent_dir + "/mama-manager.desktop" + " " 74 | "/usr/share/applications") 75 | 76 | print('\n\nInstalled Successfully.\n\n') 77 | win = MessageDialogWindow() 78 | win.show_all() 79 | sys.exit(0) 80 | -------------------------------------------------------------------------------- /library/BasicCommands.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version('Gtk', '3.0') 4 | from gi.repository import Gtk 5 | from gi.repository import Gdk 6 | from BingTextToSpeech import TextToSpeech 7 | from MessageDialogWindow import MessageDialogWindow 8 | import os, time, subprocess 9 | 10 | 11 | class BasicCommands(): 12 | """ 13 | @description: Called when the user wants to start an internal command 14 | for the moment there is 3 internal commands: 15 | 16 | * time 17 | * clipboard 18 | * power 19 | 20 | @param config 21 | A dictionary containing Microsoft Bing Speech API Key and Azure 22 | client ID, also some other info 23 | 24 | @param text 25 | name of the function to launch 26 | 27 | @param PID 28 | the program's pid to synchronize osd notification 29 | """ 30 | 31 | def __init__(self, config, text, PID): 32 | # according to the received parameter, performs an action 33 | self.config = config 34 | self.pid = PID 35 | if text == 'time': 36 | self.get_time() 37 | elif text == 'power': 38 | self.get_power() 39 | elif text == 'clipboard': 40 | self.read_clipboard() 41 | else: 42 | error_dialog = MessageDialogWindow("No action found!") 43 | error_dialog.show_error_message() 44 | error_dialog.show_all() 45 | 46 | def read_clipboard(self): 47 | """ 48 | @description: A function to make mama reads the selected 49 | text 50 | """ 51 | clipboard = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY) 52 | 53 | text = clipboard.wait_for_text() 54 | if text: 55 | text = text.replace("'", ' ') 56 | TextToSpeech(self.config, text) 57 | else: 58 | TextToSpeech('Nothing in the clipboard') 59 | 60 | def get_time(self): 61 | """ 62 | @description: a function that let mama read and display 63 | the current time 64 | """ 65 | var = time.strftime('%H:%M', time.localtime()) 66 | hour = var.split(':')[0] 67 | minute = var.split(':')[1] 68 | 69 | message = 'it is' + ' ' + hour + ' ' + 'hour' + ' ' + minute + ' ' + 'minute' 70 | os.system('echo "' + var + '" > /tmp/mama/mama_display_' + self.pid) 71 | TextToSpeech(self.config, message, self.pid) 72 | 73 | def get_power(self): 74 | """ 75 | @description: a function that let mama read and display 76 | the current power state 77 | """ 78 | command = "acpi -b" 79 | process = subprocess.Popen(command, stdout=subprocess.PIPE, 80 | stderr=subprocess.PIPE, shell=True) 81 | output, error = process.communicate() 82 | if output: 83 | output = output.decode("utf-8", "strict")[:-1] 84 | output = output.replace(',', '') 85 | output = output.split(' ') 86 | else: 87 | error_dialog = MessageDialogWindow(error) 88 | error_dialog.show_error_message() 89 | error_dialog.show_all() 90 | # parsing output 91 | if 'Battery' in output: 92 | battery_percentage = output[3] 93 | if len(output) > 4: 94 | remaining_time = output[4] 95 | 96 | if 'Charging' in output: 97 | message = 'Charging' + ', now ' + battery_percentage + ', ' + \ 98 | remaining_time + ' ' + 'until charged' 99 | else: 100 | message = 'Discharging' + ', now ' + battery_percentage + ', ' \ 101 | '' + \ 102 | remaining_time + ' ' + 'remaining' 103 | else: 104 | message = 'Not charging, ' + battery_percentage + ' remaining' 105 | else: 106 | message = 'battery is not plugged' 107 | 108 | os.system('echo "' + message + '" > /tmp/mama/mama_display_' + self.pid) 109 | TextToSpeech(self.config, message, self.pid) 110 | -------------------------------------------------------------------------------- /library/ExternalWindow.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version('Gtk', '3.0') 4 | from gi.repository import Gtk 5 | from os.path import expanduser 6 | import os 7 | import xml.etree.ElementTree as ET 8 | 9 | 10 | class ExternalWindow(): 11 | def __init__(self, store, iter=None): 12 | self.grid = Gtk.Grid() 13 | self.grid.set_border_width(5) 14 | self.grid.set_row_spacing(5) 15 | self.grid.set_vexpand(True) 16 | self.grid.set_hexpand(True) 17 | self.grid.set_column_spacing(2) 18 | self.grid.set_column_homogeneous(False) 19 | label1 = Gtk.Label('key sentence') 20 | label1.set_hexpand(True) 21 | label1.set_justify(Gtk.Justification.LEFT) 22 | label1.set_halign(Gtk.Align.START) 23 | label2 = Gtk.Label('your command') 24 | label2.set_justify(Gtk.Justification.LEFT) 25 | label2.set_halign(Gtk.Align.START) 26 | ll = Gtk.Label() 27 | ll.set_vexpand(True) 28 | self.entry1 = Gtk.Entry() 29 | self.entry2 = Gtk.Entry() 30 | 31 | if iter is not None: 32 | self.entry1.set_text(store[iter][0]) 33 | self.entry2.set_text(store[iter][1]) 34 | 35 | button = Gtk.Button.new_from_stock(Gtk.STOCK_OK) 36 | button.connect("clicked", self.button_clicked, store, iter) 37 | button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL) 38 | button_cancel.connect("clicked", self.do_destroy) 39 | 40 | self.grid.attach(label1, 0, 0, 11, 1) 41 | self.grid.attach(self.entry1, 11, 0, 4, 1) 42 | self.grid.attach(label2, 0, 1, 11, 1) 43 | self.grid.attach(self.entry2, 11, 1, 4, 1) 44 | self.grid.attach(ll, 0, 2, 15, 1) 45 | self.grid.attach(button_cancel, 13, 3, 1, 1) 46 | self.grid.attach(button, 14, 3, 1, 1) 47 | self.grid.show_all() 48 | 49 | def do_destroy(self, button): 50 | self.grid.destroy() 51 | 52 | def get_grid(self): 53 | return self.grid 54 | 55 | def button_clicked(self, button, store, iter): 56 | if iter is None: 57 | if self.entry1.get_text() is not '' and self.entry2.get_text() is not '': 58 | store.append([self.entry1.get_text(), self.entry2.get_text(), 59 | 'external', ' ', ' ']) 60 | self.saveTree(store) 61 | elif iter is not None: 62 | store[iter][0] = str(self.entry1.get_text()) 63 | store[iter][1] = str(self.entry2.get_text()) 64 | self.saveTree(store) 65 | 66 | self.grid.destroy() 67 | 68 | def saveTree(self, store): 69 | """ 70 | @description: save the treeview in the mama.xml file 71 | 72 | @param: store 73 | the listStore attach to the treeview 74 | """ 75 | # if there is still an entry in the model 76 | config = expanduser('~') + '/.config/mama/mama.xml' 77 | try: 78 | if not os.path.exists(os.path.dirname(config)): 79 | os.makedirs(os.path.dirname(config)) 80 | 81 | root = ET.Element("data") 82 | if len(store) != 0: 83 | for i in range(len(store)): 84 | iter = store.get_iter(i) 85 | if store[iter][0] != '' and store[iter][1] != '': 86 | for s in store[iter][0].split('|'): 87 | s = s.lower() 88 | s = s.replace('*', ' ') 89 | Type = ET.SubElement(root, "entry") 90 | Type.set("name", unicode(store[iter][2], "utf-8")) 91 | Key = ET.SubElement(Type, "key") 92 | Key.text = unicode(s, "utf-8") 93 | Command = ET.SubElement(Type, "command") 94 | Command.text = unicode(store[iter][1], "utf-8") 95 | Linker = ET.SubElement(Type, "linker") 96 | Spacebyplus = ET.SubElement(Type, "spacebyplus") 97 | if store[iter][3] is not None and store[iter][ 98 | 4] is not None: 99 | Linker.text = unicode(store[iter][3], "utf-8") 100 | Spacebyplus.text = unicode(store[iter][4], 101 | "utf-8") 102 | 103 | ET.ElementTree(root).write(config, encoding="utf-8", 104 | xml_declaration=True) 105 | 106 | except IOError: 107 | print("Unable to write the file") 108 | -------------------------------------------------------------------------------- /library/Interface.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | import json 3 | import os 4 | import sys 5 | import urllib.parse 6 | from os.path import expanduser 7 | 8 | import xmltodict 9 | from Listener import Listener 10 | from StringParser import StringParser 11 | from MessageDialogWindow import MessageDialogWindow 12 | 13 | 14 | class Interface(): 15 | """ 16 | @description: This class start the notifier, then start recording your voice before 17 | asking Microsoft for the speech-to-text. Then, the result is parsing in order to 18 | execute the associated action 19 | """ 20 | 21 | def __init__(self, config): 22 | self.p = os.path.dirname(os.path.abspath(__file__)).strip('librairy') 23 | self.PID = str(os.getpid()) 24 | 25 | # Initialization notifications 26 | os.system( 27 | 'python3 ' + self.p + 'notifier.py ' + self.PID + ' &') 28 | 29 | # We launch the recorder 30 | Listener(config, self.PID) 31 | self.sendto(config) 32 | 33 | def sendto(self, config): 34 | """ 35 | @function: Send the wav file to Microsoft and start the parser 36 | """ 37 | 38 | # configuration file 39 | config_file = expanduser('~') + '/.config/mama/mama.xml' 40 | default = self.p + 'config/' + 'en_EN' + '/default.xml' 41 | 42 | if os.path.exists(config_file): 43 | config_file = config_file 44 | else: 45 | if not os.path.exists(expanduser('~') + '/.config/mama'): 46 | os.makedirs(expanduser('~') + '/.config/mama') 47 | if not os.path.exists( 48 | expanduser('~') + '/.config/mama/modules'): 49 | os.system('cp -r ' + self.p + '/modules ' + expanduser( 50 | '~') + '/.config/mama') 51 | if not os.path.exists(default): 52 | default = self.p + 'config/en_EN/default.xml' 53 | 54 | config_file = default 55 | 56 | host = "https://speech.platform.bing.com" 57 | 58 | params = urllib.parse.urlencode( 59 | {'grant_type': 'client_credentials', 60 | 'client_id': config['client_id'], 61 | 'client_secret': config['api_key'], 'scope': host}) 62 | 63 | headers = {"Content-type": "application/x-www-form-urlencoded"} 64 | 65 | access_token_host = "oxford-speech.cloudapp.net" 66 | token_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 67 | "/token/issueToken") 68 | 69 | # Connecting to server to get the Microsoft Bing Speech API Access Token 70 | conn = http.client.HTTPSConnection(access_token_host, timeout=10) 71 | conn.request("POST", token_path, params, headers) 72 | response = conn.getresponse() 73 | 74 | if response.status == 200: 75 | 76 | data = response.read() 77 | conn.close() 78 | access_token = data.decode("UTF-8") 79 | 80 | # Decoding the object from json 81 | decoded_data = json.loads(access_token) 82 | access_token = decoded_data['access_token'] 83 | 84 | # Reading the binary from wave file 85 | f = open('/tmp/mama/output.wav', 'rb') 86 | try: 87 | body = f.read(); 88 | finally: 89 | f.close() 90 | 91 | headers = {"Content-type": "audio/wav; samplerate=" + str(config[ 92 | 'audio_rate']) + "; sourcerate=" + str( 93 | config['audio_rate']), 94 | "Authorization": "Bearer " + access_token} 95 | 96 | # Connect to server to recognize the wave binary 97 | conn = http.client.HTTPSConnection("speech.platform.bing.com", 98 | timeout=30) 99 | conn.request("POST", 100 | "/recognize/query?scenarios=ulm&appid=D4D52672-91D7-4C74-8AD8-42B1D98141A5&locale=en-US&device.os=wp7&version=3.0&format=xml&requestid=1d4b6030-9099-11e0-91e4-0800200c9a66&instanceid=1d4b6030-9099-11e0-91e4-0800200c9a66", 101 | body, headers) 102 | response = conn.getresponse() 103 | 104 | if response.status == 200: 105 | 106 | data = response.read() 107 | conn.close() 108 | result = json.loads( 109 | json.dumps(xmltodict.parse(data.decode("UTF-8")))) 110 | try: 111 | text = result['speechbox-root']['results']['result']['name'] 112 | except: 113 | text = '' 114 | os.system("echo '" + text + "' > /tmp/mama/mama_result_" + 115 | str(self.PID)) 116 | 117 | # Calling updater 118 | os.system( 119 | 'python3 ' + self.p + 'updater.py ' + self.PID + ' &') 120 | # parsing the results to find the action 121 | StringParser(config, text, 122 | config_file, self.PID) 123 | 124 | else: 125 | os.system( 126 | 'echo "' + response.reason + '" > /tmp/mama/mama_error_' + self.PID) 127 | sys.exit(1) 128 | else: 129 | os.system( 130 | 'echo "' + response.reason + '" > /tmp/mama/mama_error_' + self.PID) 131 | error_dialog = MessageDialogWindow(response.reason) 132 | error_dialog.show_error_message() 133 | error_dialog.show_all() 134 | sys.exit(1) 135 | -------------------------------------------------------------------------------- /config/en_EN/default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | what time 5 | time 6 | 7 | 8 | 9 | 10 | power level 11 | power 12 | 13 | 14 | 15 | 16 | how many battery 17 | power 18 | 19 | 20 | 21 | 22 | close window 23 | xdotool key "Alt+F4" 24 | 25 | 26 | 27 | 28 | hide window 29 | xdotool key "Alt+F9" 30 | 31 | 32 | 33 | 34 | switch window 35 | xdotool key "Alt+Tab" 36 | 37 | 38 | 39 | 40 | other window 41 | xdotool key "Alt+Tab" 42 | 43 | 44 | 45 | 46 | return 47 | xdotool key "Return" 48 | 49 | 50 | 51 | 52 | return 53 | xdotool key "Return" 54 | 55 | 56 | 57 | 58 | tabulation 59 | xdotool key "Tab" 60 | 61 | 62 | 63 | 64 | menu 65 | xdotool key "Alt+F1" 66 | 67 | 68 | 69 | 70 | pyow menu 71 | xdotool key "Alt+F1" 72 | 73 | 74 | 75 | 76 | open web browser 77 | exo-open --launch WebBrowser 78 | 79 | 80 | 81 | 82 | open web browser 83 | exo-open --launch WebBrowser 84 | 85 | 86 | 87 | 88 | open file manager 89 | exo-open --launch FileManager 90 | 91 | 92 | 93 | 94 | open terminal 95 | exo-open --launch TerminalEmulator 96 | 97 | 98 | 99 | 100 | open pictures 101 | xdg-open ~/Images 102 | 103 | 104 | 105 | 106 | open musics 107 | xdg-open ~/Music 108 | 109 | 110 | 111 | 112 | open documents 113 | xdg-open ~/Documents 114 | 115 | 116 | 117 | 118 | open downloads 119 | xdg-open ~/Downloads 120 | 121 | 122 | 123 | 124 | copy 125 | xdotool key "Ctrl+c" 126 | 127 | 128 | 129 | 130 | paste 131 | xdotool key "Ctrl+v" 132 | 133 | 134 | 135 | 136 | cut 137 | xdotool key "Ctrl+x" 138 | 139 | 140 | 141 | 142 | google 143 | google.py 144 | google 145 | 1 146 | 147 | 148 | meaning 149 | meaning.py 150 | meaning 151 | 1 152 | 153 | 154 | weather in 155 | weather.py 156 | in 157 | 1 158 | 159 | 160 | wikipedia 161 | wikipedia.py 162 | wikipedia 163 | 1 164 | 165 | 166 | youtube 167 | youtube.py 168 | youtube 169 | 1 170 | 171 | 172 | -------------------------------------------------------------------------------- /updater.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version('Gtk', '3.0') 4 | from gi.repository import Gtk 5 | import os 6 | import sys 7 | import json 8 | import urllib.request 9 | 10 | # Declaring variables 11 | current_version = 0.1 12 | new_version_info = {} 13 | 14 | # This is the github api url of mama release page 15 | host = 'https://api.github.com/repos/maateen/mama/releases' 16 | 17 | 18 | class MessageDialogWindow(Gtk.Window): 19 | """ 20 | @description: This class show new stable and pre release message dialog 21 | To show it on nay page just import the class and then 22 | win = MessageDialogWindow() 23 | win.show_stable_release_message() 24 | win.show_all() 25 | @param: text 26 | text will show in the dialog 27 | """ 28 | 29 | def __init__(self, text, url): 30 | Gtk.Window.__init__(self) 31 | self.text = text 32 | self.url = url 33 | 34 | def __install_latest_version(self): 35 | os.system("unzip /tmp/mama/latest.zip") 36 | os.system("gksu python3 /tmp/mama/mama/install.py &") 37 | sys.exit(0) 38 | 39 | def __download_latest_version(self): 40 | if not os.path.exists("/tmp/mama"): 41 | os.system("mkdir -p /tmp/mama") 42 | os.system("wget -O /tmp/mama/latest.zip " + self.url) 43 | print("Latest version downloaded successfully.") 44 | self.__install_latest_version() 45 | 46 | def show_pre_release_message(self): 47 | dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO, 48 | Gtk.ButtonsType.OK, 49 | "Mama! New beta version available!") 50 | dialog.format_secondary_text(self.text) 51 | dialog.run() 52 | if response == Gtk.ResponseType.OK: 53 | print("Pre release dialog closed by clicking OK button") 54 | dialog.destroy() 55 | self.__download_latest_version() 56 | elif response == Gtk.ResponseType.CANCEL: 57 | print("Pre release dialog closed by clicking CANCEL button") 58 | dialog.destroy() 59 | 60 | def show_stable_release_message(self): 61 | dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.WARNING, 62 | Gtk.ButtonsType.OK_CANCEL, 63 | "Mama! New stable version available!") 64 | dialog.format_secondary_text(self.text) 65 | response = dialog.run() 66 | if response == Gtk.ResponseType.OK: 67 | print("Stable release dialog closed by clicking OK button") 68 | dialog.destroy() 69 | self.__download_latest_version() 70 | elif response == Gtk.ResponseType.CANCEL: 71 | print("Stable release dialog closed by clicking CANCEL button") 72 | dialog.destroy() 73 | 74 | 75 | # Getting data from github API 76 | try: 77 | conn = urllib.request.urlopen(host) 78 | response = conn.read().decode('utf-8') 79 | info = json.loads(response) 80 | 81 | # Parsing data from info in new_version_info dict 82 | for key, data in info[0].items(): 83 | if 'assets' == key: 84 | for new_list in data: 85 | for x, y in new_list.items(): 86 | if 'api' in str(y): 87 | pass 88 | else: 89 | new_version_info[x] = y 90 | elif 'author' in key: 91 | pass 92 | elif 'upload' in key: 93 | pass 94 | else: 95 | if 'api' in str(data): 96 | pass 97 | else: 98 | new_version_info[key] = data 99 | 100 | new_version_info['tag_name'] = new_version_info['tag_name'].strip('v') 101 | published_at = new_version_info['published_at'].split('T') 102 | new_version_info['published_at'] = published_at[0] 103 | size = new_version_info['size'] / 1024 104 | size = str(size).split('.') 105 | new_version_info['size'] = size[0] 106 | except: 107 | sys.exit(0) 108 | 109 | print(new_version_info) 110 | 111 | # Checking first whether any new release is available or not. 112 | if float(new_version_info['tag_name']) > current_version: 113 | 114 | # If the release isn't drafted, then we will proceed 115 | if not new_version_info['draft']: 116 | # If the release is stable, then we will show a stable message dialog 117 | 118 | text = "Latest stable version : " + new_version_info[ 119 | 'tag_name'] + "\nPublished at : " + new_version_info[ 120 | 'published_at'] + "\n" 121 | release_notes = "Release notes:\n" + new_version_info['body'] + "\n" 122 | text2 = "\nAlready " + str( 123 | new_version_info['download_count']) + " people " \ 124 | "updated " \ 125 | "to this " \ 126 | "version. " \ 127 | "Do you " \ 128 | "want to update? (" \ 129 | "" + new_version_info[ 130 | 'size'] + " KB will be downloaded)" 131 | if not new_version_info['prerelease']: 132 | stable_message_dialog = MessageDialogWindow(text + release_notes + 133 | text2, new_version_info[ 134 | 'browser_download_url']) 135 | stable_message_dialog.show_stable_release_message() 136 | stable_message_dialog.show_all() 137 | else: 138 | pre_message_dialog = MessageDialogWindow(text + release_notes + 139 | text2, new_version_info[ 140 | 'browser_download_url']) 141 | pre_message_dialog.show_pre_release_message() 142 | pre_message_dialog.show_all() 143 | sys.exit(0) 144 | else: 145 | print("No update available.") 146 | -------------------------------------------------------------------------------- /library/InternalWindow.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version('Gtk', '3.0') 4 | from gi.repository import Gtk 5 | from os.path import expanduser 6 | import os 7 | import xml.etree.ElementTree as ET 8 | 9 | 10 | class InternalWindow(): 11 | def __init__(self, store, iter=None): 12 | self.grid = Gtk.Grid() 13 | self.grid.set_border_width(5) 14 | self.grid.set_row_spacing(5) 15 | self.grid.set_vexpand(True) 16 | self.grid.set_hexpand(True) 17 | self.grid.set_column_spacing(2) 18 | self.grid.set_column_homogeneous(False) 19 | self.grid.set_row_homogeneous(False) 20 | 21 | label1 = Gtk.Label('key sentence') 22 | label1.set_justify(Gtk.Justification.LEFT) 23 | label1.set_halign(Gtk.Align.START) 24 | label1.set_hexpand(True) 25 | label2 = Gtk.Label('your command') 26 | label2.set_justify(Gtk.Justification.LEFT) 27 | label2.set_halign(Gtk.Align.START) 28 | ll = Gtk.Label() 29 | ll.set_vexpand(True) 30 | self.entry1 = Gtk.Entry() 31 | if iter is not None: 32 | self.entry1.set_text(store[iter][0]) 33 | 34 | self.combo = self.__get_combobox(store, iter) 35 | button = Gtk.Button.new_from_stock(Gtk.STOCK_OK) 36 | button.connect("clicked", self.button_clicked, store, iter) 37 | button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL) 38 | button_cancel.connect("clicked", self.do_destroy) 39 | 40 | self.grid.attach(label1, 0, 0, 11, 1) 41 | self.grid.attach(self.entry1, 11, 0, 4, 1) 42 | self.grid.attach(label2, 0, 1, 11, 1) 43 | self.grid.attach(self.combo, 11, 1, 4, 1) 44 | self.grid.attach(ll, 0, 2, 15, 1) 45 | self.grid.attach(button_cancel, 13, 3, 1, 1) 46 | self.grid.attach(button, 14, 3, 1, 1) 47 | self.grid.show_all() 48 | 49 | def do_destroy(self, button): 50 | self.grid.destroy() 51 | 52 | def get_grid(self): 53 | return self.grid 54 | 55 | def button_clicked(self, button, store, iter): 56 | if iter is None: 57 | if self.entry1.get_text() is not '': 58 | store.append([self.entry1.get_text(), 59 | str(self.dic[self.combo.get_active()]), 60 | 'internal', ' ', ' ']) 61 | self.saveTree(store) 62 | else: 63 | store[iter][0] = str(self.entry1.get_text()) 64 | store[iter][1] = str(self.dic[self.combo.get_active()]) 65 | self.saveTree(store) 66 | 67 | self.grid.destroy() 68 | 69 | # return a combobox to add to the toolbar 70 | def __get_combobox(self, store, iter): 71 | """ 72 | @description: get the combobox of the toolbar 73 | 74 | @return: a Gtk.Combobox 75 | """ 76 | # the data in the model, of type string 77 | listmodel = Gtk.ListStore(str) 78 | # append the data in the model 79 | self.dic = {} 80 | self.dic[0] = 'time' 81 | listmodel.append(['time']) 82 | self.dic[1] = 'power' 83 | listmodel.append(['power']) 84 | self.dic[2] = 'clipboard' 85 | listmodel.append(['clipboard']) 86 | 87 | selected = 0 88 | if iter is not None: 89 | for i in range(len(self.dic)): 90 | if self.dic[i] == store[iter][1]: 91 | selected = i 92 | 93 | # a combobox to see the data stored in the model 94 | combobox = Gtk.ComboBox(model=listmodel) 95 | combobox.set_tooltip_text("Which internal command to choose" + '?') 96 | 97 | # a cellrenderer to render the text 98 | cell = Gtk.CellRendererText() 99 | 100 | # pack the cell into the beginning of the combobox, allocating 101 | # no more space than needed 102 | combobox.pack_start(cell, False) 103 | # associate a property ("text") of the cellrenderer (cell) to a column (column 0) 104 | # in the model used by the combobox 105 | combobox.add_attribute(cell, "text", 0) 106 | 107 | # the first row is the active one by default at the beginning 108 | combobox.set_active(selected) 109 | 110 | return combobox 111 | 112 | def saveTree(self, store): 113 | """ 114 | @description: save the treeview in the mama.xml file 115 | 116 | @param: store 117 | the listStore attach to the treeview 118 | """ 119 | # if there is still an entry in the model 120 | config = expanduser('~') + '/.config/mama/mama.xml' 121 | try: 122 | if not os.path.exists(os.path.dirname(config)): 123 | os.makedirs(os.path.dirname(config)) 124 | 125 | root = ET.Element("data") 126 | if len(store) != 0: 127 | for i in range(len(store)): 128 | iter = store.get_iter(i) 129 | if store[iter][0] != '' and store[iter][1] != '': 130 | for s in store[iter][0].split('|'): 131 | s = s.lower() 132 | s = s.replace('*', ' ') 133 | Type = ET.SubElement(root, "entry") 134 | Type.set("name", unicode(store[iter][2], "utf-8")) 135 | Key = ET.SubElement(Type, "key") 136 | Key.text = unicode(s, "utf-8") 137 | Command = ET.SubElement(Type, "command") 138 | Command.text = unicode(store[iter][1], "utf-8") 139 | Linker = ET.SubElement(Type, "linker") 140 | Spacebyplus = ET.SubElement(Type, "spacebyplus") 141 | if store[iter][3] is not None and store[iter][ 142 | 4] is not None: 143 | Linker.text = unicode(store[iter][3], "utf-8") 144 | Spacebyplus.text = unicode(store[iter][4], 145 | "utf-8") 146 | 147 | tree = ET.ElementTree(root).write(config, encoding="utf-8", 148 | xml_declaration=True) 149 | 150 | except IOError: 151 | print("Unable to write the file") 152 | -------------------------------------------------------------------------------- /library/ArgsWindow.py: -------------------------------------------------------------------------------- 1 | import gi 2 | gi.require_version('Gtk', '3.0') 3 | from gi.repository import Gtk 4 | from os.path import expanduser 5 | import os 6 | import xml.etree.ElementTree as ET 7 | 8 | # manage the development of the module creation assistance window 9 | class ArgsWindow(): 10 | """ 11 | @description: Display a window to help the user create a config for a 12 | module 13 | 14 | @param module 15 | module's folder 16 | 17 | @param name 18 | module's name 19 | 20 | @param store 21 | a Gtk.Listore in which we will append a new line for this module 22 | """ 23 | def __init__(self,module,name,store,iter=None): 24 | self.grid = Gtk.Grid() 25 | self.grid.set_border_width(5) 26 | self.grid.set_row_spacing(5) 27 | self.grid.set_vexpand(True) 28 | self.grid.set_hexpand(True) 29 | self.grid.set_column_spacing(2) 30 | self.grid.set_column_homogeneous(False) 31 | 32 | label1 = Gtk.Label('key sentence') 33 | label1.set_justify(Gtk.Justification.LEFT) 34 | label1.set_halign(Gtk.Align.START) 35 | label1.set_hexpand(True) 36 | 37 | label2 = Gtk.Label("Linking word") 38 | label2.set_justify(Gtk.Justification.LEFT) 39 | label2.set_halign(Gtk.Align.START) 40 | 41 | label3 = Gtk.Label("Replace space by plus") 42 | label3.set_justify(Gtk.Justification.LEFT) 43 | label3.set_halign(Gtk.Align.START) 44 | 45 | ll = Gtk.Label() 46 | ll.set_vexpand(True) 47 | 48 | self.entry1 = Gtk.Entry() 49 | self.entry1.set_tooltip_text('key sentence') 50 | 51 | self.entry2 = Gtk.Entry() 52 | self.entry2.set_tooltip_text("Word to separate call and parameter") 53 | self.checkbutton = Gtk.Switch() 54 | self.checkbutton.set_tooltip_text("Replace space by plus") 55 | self.checkbutton.set_active(False) 56 | 57 | button = Gtk.Button() 58 | button.set_label("Go") 59 | button.set_tooltip_text("Go") 60 | image = Gtk.Image() 61 | image.set_from_stock(Gtk.STOCK_APPLY, Gtk.IconSize.BUTTON) 62 | button.set_image(image) 63 | 64 | button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL) 65 | button_cancel.connect("clicked",self.do_destroy) 66 | 67 | print(module, name) 68 | if iter is None: 69 | button.connect("clicked",self.do_clicked,module,name,store) 70 | else: 71 | self.entry1.set_text(store[iter][0]) 72 | linker = store[iter][3] 73 | spacebyplus = store[iter][4] 74 | self.entry2.set_text(linker) 75 | 76 | if spacebyplus == '1': 77 | self.checkbutton.set_active(True) 78 | button.connect("clicked",self.do_modify,store[iter][3],store,iter) 79 | 80 | self.grid.attach(label1,0,0,11,1) 81 | self.grid.attach(self.entry1,11,0,4,1) 82 | self.grid.attach(label2,0,1,11,1) 83 | self.grid.attach(self.entry2,11,1,4,1) 84 | self.grid.attach(label3,0,2,14,1) 85 | self.grid.attach(self.checkbutton,14,2,1,1) 86 | self.grid.attach(ll,0,3,15,1) 87 | self.grid.attach(button_cancel,13,4,1,1) 88 | self.grid.attach(button,14,4,1,1) 89 | self.grid.show_all() 90 | 91 | def do_destroy(self,button): 92 | self.grid.destroy() 93 | 94 | def get_grid(self): 95 | return self.grid 96 | 97 | def do_clicked(self,button,module,name,store): 98 | """ 99 | @description: callback function called when the user want to finish 100 | the configuration of the module. If everything is ok then the config 101 | file is written at the right place 102 | """ 103 | key = self.entry1.get_text() 104 | linker = self.entry2.get_text() 105 | if self.checkbutton.get_active(): 106 | spacebyplus='1' 107 | else: 108 | spacebyplus='0' 109 | 110 | if linker is not '': 111 | try: 112 | # folder = name.split('.')[0] 113 | module_path=expanduser('~')+'/.config/mama/modules/' 114 | 115 | os.system('cp '+module+' '+module_path) 116 | print("key", key) 117 | print("name", name) 118 | print("module", module_path+name) 119 | print("linker", linker) 120 | print("spacebyplus", spacebyplus) 121 | store.append([key,name,'modules',linker,spacebyplus]) 122 | #save the store 123 | self.saveTree(store) 124 | except IOError: 125 | "Unable to open the file" 126 | 127 | self.grid.destroy() 128 | 129 | def do_modify(self,button,argsfile,store,iter): 130 | if self.checkbutton.get_active(): 131 | spacebyplus = 1 132 | else: 133 | spacebyplus = 0 134 | 135 | # modifying the store 136 | store[iter][0] = self.entry1.get_text() 137 | store[iter][3] = self.entry2.get_text() 138 | store[iter][4] = str(spacebyplus) 139 | 140 | #save the store 141 | self.saveTree(store) 142 | self.grid.destroy() 143 | 144 | def saveTree(self,store): 145 | """ 146 | @description: save the treeview in the mama.xml file 147 | 148 | @param: store 149 | the listStore attach to the treeview 150 | """ 151 | # if there is still an entry in the model 152 | config = expanduser('~') +'/.config/mama/mama.xml' 153 | try: 154 | if not os.path.exists(os.path.dirname(config)): 155 | os.makedirs(os.path.dirname(config)) 156 | 157 | root = ET.Element("data") 158 | if len(store) != 0: 159 | for i in range(len(store)): 160 | iter = store.get_iter(i) 161 | if store[iter][0] != '' and store[iter][1] != '': 162 | for s in store[iter][0].split('|'): 163 | s = s.lower() 164 | s = s.replace('*',' ') 165 | Type = ET.SubElement(root, "entry") 166 | Type.set("name",unicode(store[iter][2],"utf-8")) 167 | Key = ET.SubElement(Type, "key") 168 | Key.text = unicode(s,"utf-8") 169 | Command = ET.SubElement(Type, "command") 170 | Command.text = unicode(store[iter][1],"utf-8") 171 | Linker = ET.SubElement(Type, "linker") 172 | Spacebyplus = ET.SubElement(Type, "spacebyplus") 173 | if store[iter][3] is not None or store[iter][4] is not None: 174 | Linker.text = unicode(store[iter][3],"utf-8") 175 | Spacebyplus.text = unicode(store[iter][4],"utf-8") 176 | 177 | tree = ET.ElementTree(root).write(config,encoding="utf-8",xml_declaration=True) 178 | 179 | except IOError: 180 | print("Unable to write the file") 181 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Mama 2 | The aim of this project is to let you use [Microsoft powered Bing Speech Recognition API](https://www.microsoft.com/cognitive-services/en-us/speech-api) to control your Linux computer. The project is developed in Python3. For note, this is a fork of project [google2ubuntu](https://github.com/benoitfragit/google2ubuntu). 3 | 4 | The mother project, [google2ubuntu](https://github.com/benoitfragit/google2ubuntu), is a tool that **Franquet Benoit** started 2 years ago, written in Python2. Unfortunately, he was not able to do what he wanted because of a lack of time. Perhaps, he used Google Web Speech API which isn't free anymore. 5 | 6 | So I am moving the project to the next level using [Microsoft powered Bing Speech Recognition API](https://www.microsoft.com/cognitive-services/en-us/speech-api) by renaming it to **Mama**. 7 | 8 | ###Why is it renamed Mama? 9 | In **Bangladesh**, the term **Mama** is similar to maternal uncle. But now-a-days, it has become a common calling name of people, known/unknown. Actually we call someone **mama** with love. That's the matter! 10 | 11 | The project consists in 2 principal Python3 scripts: 12 | 13 | * mama.py 14 | * mama-manager.py 15 | 16 | The first one lets you send commands to Microsoft and then execute some actions. The second one lets you manage all the commands with a nice GUI, powered by `PyGtk3`. 17 | 18 | #Installation 19 | ### Dependencies 20 | 21 | For the moment, dependencies are: 22 | 23 | * python3 24 | * python3-gi 25 | * python3-xmltodict 26 | * python3-pyaudio 27 | * libnotify-dev 28 | * xdotool 29 | * acpi 30 | * gksu 31 | * unzip 32 | 33 | If you are using Ubuntu/Debian, type this to install all dependencies: 34 | ``` 35 | sudo apt-get install python3 python3-gi python3-xmltodict python3-pyaudio libnotify-dev acpi xdotool gksu unzip 36 | ``` 37 | Now we will install the main things. 38 | ``` 39 | wget "https://github.com/maateen/mama/releases/download/v0.1/mama-v0.1.zip" 40 | 41 | unzip mama-v0.1.zip 42 | cd mama 43 | sudo python3 install.py 44 | ``` 45 | That's all. Now you should get the success message. 46 | ####Note: Mama should run like a king on every Linux distribution. Just install the above dependencies with relevant command. 47 | 48 | ##Configuration 49 | ###Main programs 50 | Once you have installed Mama, you can attribute a shortcut to those two of Python scripts: 51 | 52 | ``` 53 | python3 /usr/share/mama/mama.py 54 | python3 /usr/share/mama/mama-manager.py 55 | ``` 56 | 57 | Moreover, if you search in the application's menu you will find two launchers, one for each of those programs. 58 | 59 | After that, you can launch `mama-manager.py` in order to manage all commands. 60 | ![Mama-manager](https://raw.githubusercontent.com/maateen/mama/gh-pages/Screenshot_from_2016_07_20_21_32_22.png) 61 | 62 | 63 | As you can see, Mama comes with several default commands. I will explain you how to manage and add commands. 64 | 65 | ###Basic configs 66 | Then you can configure Mama by clicking on the **Setup** button, that will open a window 67 | ![setup](https://raw.githubusercontent.com/maateen/mama/gh-pages/Screenshot_from_2016_07_20_21_37_12.png) 68 | 69 | In this window you can: 70 | 71 | 1. Set you locale, the language in which the speaker will talk. 72 | 2. Set audio chunk 73 | 3. Set number of channels 74 | 4. Set sampling sate 75 | 5. Set recording time 76 | 6. Set Microsoft Azure Client ID, please visit: [https://portal.azure.com/](https://portal.azure.com/) for your client ID. It is required. 77 | 7. Set Microsoft Bing Speech API Key, please visit [https://www.microsoft.com/cognitive-services/en-us/speech-api](https://www.microsoft.com/cognitive-services/en-us/speech-api) for our API key. It is required. 78 | 79 | For the last two parameters, please visit our wiki for details. 80 | 81 | #Manage commands 82 | 83 | ##Commands' storage 84 | By default, Mama comes with several commands stored in a default xml file: 85 | ``` 86 | /usr/share/mama/config//default.xml 87 | ``` 88 | For the moment, there is a default file for French, English, Spanish, Deutch and Italian users, if your language is not currently supported the default voice will be English. 89 | 90 | At the first, launch, a module folder is created in: 91 | ``` 92 | ~/.config/mama 93 | ``` 94 | The first time you add, modify or remove a command, your commands' configuration will be also stored in this folder in the file: 95 | ``` 96 | ~/.config/mama/mama.xml 97 | ``` 98 | 99 | 100 | ##Commands' description 101 | A command is a pair of `key` and `action`. Each `key` referes to an `action`. Many `key` can leads to the same `action`. 102 | To define a command, you do not need to make explicitaly all the word you will tell, I mean, if I want to create the command: 103 | ``` 104 | key: open my documents 105 | action: xdg-open ~/Documents 106 | ``` 107 | The word `my` is not usefull so, I will put: 108 | ``` 109 | key: open documents 110 | action: xdg-open ~/Documents 111 | ``` 112 | Don't care about capital letter, because the program automatically put the text in lowercase. 113 | 114 | 115 | I've implemented different types of command: 116 | 117 | * **external commands** 118 | * **internal commands** 119 | * **modules** 120 | 121 | ###External commands 122 | 123 | External commands are basically commands that you can run in your terminal: 124 | ``` 125 | exo-open --launch MailReader 126 | ``` 127 | If you want to add an external command, just click on the "Add" button. Then find the newline and replace "your key" by the key you want to associate to the command and replace "your command" by the action. 128 | 129 | ###Internal commands 130 | ####What are they ? 131 | Internal commands are commands that I've implemented in Mama, for the moment there is 3 internal commands: 132 | 133 | | Name | Function | 134 | | --- | --- | 135 | | time | Tell the current time | 136 | | power | Tell the battery state | 137 | | clipboard | Read the text selected by the cursor | 138 | 139 | If you want to add an internal command, open the little menu near the "Add" button and select "internal". Then replace "your key" by the "key" you will pronounce to call this command and replace "word" by one of those 5 actions' name. 140 | 141 | ###Modules 142 | In order to extend Mama very easily I've implemented a system of modules that let developers add their own scripts in Mama. Besides, all modules will receive the text that you pronounce in parameter 143 | 144 | ####Module's description 145 | A module is basically, an executable file that will receive some text in argument. each module embed its configuration in your configuration file. Two fields are recorded for each module: 146 | 147 | * linker 148 | a word that let us distinguish the call to the module and the parameter we have to send to this module. For example, if I want to configure the module google, I can choose the linker "google " because when I make a research I say: 149 | ``` 150 | google who is barack obama 151 | ``` 152 | So, the google module will be call with `who is barack obama` in parameter. 153 | * spacebyplus 154 | If spacebyplus=1 then space are replace py +. 155 | 156 | ####How to add a module 157 | If you want to add a script, the gui will help you to create one and will place the module in : 158 | ``` 159 | ~/.config/mama/modules 160 | ``` 161 | 162 | You can add a module by opening the menu near to the "Add" button then selecting the executable files of the module. 163 | Yu can also simply drag&drop this executable on the treeview and the module will be automatically added. When you add a new module you don't have to modify the `action` field in the newline. You just have to modify the `key` field in the gui. 164 | 165 | 166 | ####Already available 167 | Mama already comes with 6 modules: 168 | 169 | * **google** 170 | This plugin allows you to make search on Google and open the web browser on the search page you ask for. 171 | * **wikipedia** 172 | This plugin allows you to make search on Wikipedia 173 | * **youtube** 174 | This plugin allows you to make search on YouTube 175 | So your locations need to be between the word "between" and "and" 176 | * **weather** 177 | This plugin allows you to ask Google to show you the weather for a city 178 | * **goto** 179 | This plugin allows you to open a new web page with the web page you want. For example if you have configurated the plugin liker this: 180 | ``` 181 | your sentence = go to 182 | linker = to 183 | ``` 184 | Then if you say "go to gmail.com", a new web page is going to be open with gmail.com 185 | 186 | ####Note for the user 187 | Perhaps, you will have to modify the linker field of those module by selecting the module and clicking on the edit button 188 | 189 | #Go Linux automation 190 | Once you have personalized and take care about the commands already included in Mama, you can launch the recognition by launching `mama.py` 191 | 192 | A little sound is played and a notification tell you to speak. Then the notification show the result and the action associated to the text you have pronounced is played. 193 | -------------------------------------------------------------------------------- /library/SetupWindow.py: -------------------------------------------------------------------------------- 1 | import gi 2 | gi.require_version('Gtk', '3.0') 3 | gi.require_version('Notify', '0.7') 4 | from gi.repository import Gtk 5 | from os.path import expanduser 6 | import os 7 | 8 | class SetupWindow(): 9 | def __init__(self,button_back, button_cancel): 10 | # class variables 11 | self.config_file = expanduser('~') + '/.config/mama/mama.conf' 12 | self.locale = 'en-US' 13 | self.audio_chunk = 1024 14 | self.audio_channels = 2 15 | self.audio_rate = 8000 # sample rate 16 | self.recording_time = 3 # in second 17 | self.client_id = '' 18 | self.api_key = '' 19 | self.speaker = 'Mama (Male)' 20 | 21 | # looking for the configuration file 22 | self.__loadconfig() 23 | 24 | label0 = Gtk.Label('Set Your Locale') 25 | label0.set_justify(Gtk.Justification.LEFT) 26 | label0.set_halign(Gtk.Align.START) 27 | label0.set_hexpand(True) 28 | label1 = Gtk.Label('Set Audio Chunk') 29 | label1.set_justify(Gtk.Justification.LEFT) 30 | label1.set_halign(Gtk.Align.START) 31 | label2 = Gtk.Label('Set Number of Channels') 32 | label2.set_justify(Gtk.Justification.LEFT) 33 | label2.set_halign(Gtk.Align.START) 34 | label3 = Gtk.Label('Set Sampling Rate') 35 | label3.set_justify(Gtk.Justification.LEFT) 36 | label3.set_halign(Gtk.Align.START) 37 | label4 = Gtk.Label('Set the Recording Time (in second)') 38 | label4.set_justify(Gtk.Justification.LEFT) 39 | label4.set_halign(Gtk.Align.START) 40 | label5 = Gtk.Label('Set Microsoft Azure Client ID') 41 | label5.set_justify(Gtk.Justification.LEFT) 42 | label5.set_halign(Gtk.Align.START) 43 | label6 = Gtk.Label('Set Microsoft Bing Speech Api Key') 44 | label6.set_justify(Gtk.Justification.LEFT) 45 | label6.set_halign(Gtk.Align.START) 46 | label7 = Gtk.Label('Set Speaker (who will talk to you?)') 47 | label7.set_justify(Gtk.Justification.LEFT) 48 | label7.set_halign(Gtk.Align.START) 49 | label7.set_hexpand(True) 50 | 51 | combo = self.__get_combobox() 52 | 53 | self.entry1 = Gtk.Entry() 54 | self.entry1.set_text(str(self.audio_chunk)) 55 | self.entry1.set_tooltip_text('Set the audio chunk') 56 | 57 | self.entry2 = Gtk.Entry() 58 | self.entry2.set_text(str(self.audio_channels)) 59 | self.entry2.set_tooltip_text('Set audio channels') 60 | 61 | rate_combo = self.__get_rate_combobox() 62 | 63 | self.scale = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 1, 10, 64 | 1) 65 | self.scale.set_value(self.recording_time) 66 | self.scale.connect("value-changed", self.scale_moved) 67 | self.scale.set_tooltip_text('Change the recording time') 68 | 69 | self.entry5 = Gtk.Entry() 70 | self.entry5.set_text(self.client_id) 71 | self.entry5.set_tooltip_text('Set Microsoft Azure Client ID') 72 | 73 | self.entry6 = Gtk.Entry() 74 | self.entry6.set_text(self.api_key) 75 | self.entry6.set_tooltip_text('Set Microsoft Bing Speech Api Key') 76 | 77 | speaker_combo = self.__get_speaker_combobox() 78 | 79 | button_back.connect("clicked",self.on_clicked) 80 | 81 | # an invisble widget to fill the window 82 | ll = Gtk.Label() 83 | ll.set_vexpand(True) 84 | 85 | self.grid = Gtk.Grid() 86 | self.grid.set_border_width(10) 87 | self.grid.set_row_spacing(15) 88 | self.grid.set_vexpand(True) 89 | self.grid.set_hexpand(True) 90 | self.grid.set_column_spacing(2) 91 | self.grid.set_column_homogeneous(False) 92 | self.grid.attach(label0, 0, 0, 14, 1) 93 | self.grid.attach(combo, 14, 0, 1, 1) 94 | self.grid.attach(label1, 0, 1, 14, 1) 95 | self.grid.attach(self.entry1, 11, 1, 4, 1) 96 | self.grid.attach(label2, 0, 2, 14, 1) 97 | self.grid.attach(self.entry2, 11, 2, 4, 1) 98 | self.grid.attach(label3, 0, 3, 11, 1) 99 | self.grid.attach(rate_combo, 14, 3, 1, 1) 100 | self.grid.attach(label4, 0, 4, 11, 1) 101 | self.grid.attach(self.scale, 11, 4, 4, 1) 102 | self.grid.attach(label5, 0, 5, 11, 1) 103 | self.grid.attach(self.entry5, 11, 5, 4, 1) 104 | self.grid.attach(label6, 0, 6, 11, 1) 105 | self.grid.attach(self.entry6, 11, 6, 4, 1) 106 | self.grid.attach(label7, 0, 7, 14, 1) 107 | self.grid.attach(speaker_combo, 14, 7, 1, 1) 108 | self.grid.attach(ll, 0, 8, 15, 1) 109 | self.grid.attach(button_cancel, 13, 9, 1, 1) 110 | self.grid.attach(button_back, 14, 9, 1, 1) 111 | 112 | # load the config_file 113 | def __loadconfig(self): 114 | # if a config_file file is available 115 | if os.path.exists(self.config_file): 116 | try: 117 | # here we load 118 | with open(self.config_file, "r") as f: 119 | for line in f.readlines(): 120 | line = line.strip('\n') 121 | #get the field 122 | field = line.split('=') 123 | if len(field) >= 2: 124 | if field[0] == 'locale': 125 | self.locale = field[1].replace('"', '') 126 | elif field[0] == 'audio_chunk': 127 | self.audio_chunk = int(field[1]) 128 | elif field[0] == 'audio_channels': 129 | self.audio_channels = int(field[1]) 130 | elif field[0] == 'audio_rate': 131 | self.audio_rate = int(field[1]) 132 | elif field[0] == 'recording_time': 133 | self.recording_time = int(field[1]) 134 | elif field[0] == 'client_id': 135 | self.client_id = field[1].replace('"','') 136 | elif field[0] == 'api_key': 137 | self.api_key = field[1].replace('"', '') 138 | elif field[0] == 'speaker': 139 | self.speaker = field[1].replace('"', '') 140 | 141 | except Exception: 142 | print("Config file", self.config_file) 143 | print("missing...") 144 | 145 | # record the config_file 146 | def __recordconfig(self): 147 | try: 148 | with open(self.config_file, "w") as f: 149 | f.write('locale="' + self.locale + '"\n') 150 | f.write( 151 | 'audio_chunk=' + self.entry1.get_text().strip(' ') + '\n') 152 | f.write('audio_channels=' + self.entry2.get_text().strip( 153 | ' ') + '\n') 154 | f.write('audio_rate=' + str(self.audio_rate) + '\n') 155 | f.write('recording_time=' + str(self.recording_time).strip( 156 | ' ') + '\n') 157 | f.write( 158 | 'client_id="' + self.entry5.get_text().strip(' ') + '"\n') 159 | f.write('api_key="' + self.entry6.get_text().strip(' ') + '"\n') 160 | f.write('speaker="' + self.speaker + '"\n') 161 | f.close() 162 | except Exception: 163 | print("Config file", self.config_file) 164 | print("Unable to write") 165 | 166 | # get the grid 167 | def getGrid(self): 168 | return self.grid 169 | 170 | def scale_moved(self,event): 171 | self.recording_time = int(self.scale.get_value()) 172 | self.__recordconfig() 173 | 174 | def on_clicked(self,button): 175 | self.__recordconfig() 176 | 177 | # return a combobox to add to the toolbar 178 | def __get_combobox(self): 179 | """ 180 | @description: get the combobox of the toolbar 181 | 182 | @return: a Gtk.Combobox 183 | """ 184 | # the data in the model, of type string 185 | listmodel = Gtk.ListStore(str) 186 | # append the data in the model 187 | selected = 4 188 | i = 0 189 | self.language_list = ['en-AU', 'en-CA', 'en-GB', 'en-IN', 'en-US'] 190 | for language_name in self.language_list: 191 | listmodel.append([language_name]) 192 | if language_name == self.locale: 193 | selected = i 194 | i += 1 195 | 196 | # a combobox to see the data stored in the model 197 | combobox = Gtk.ComboBox(model=listmodel) 198 | combobox.set_tooltip_text("What format to choose?") 199 | 200 | # a cellrenderer to render the text 201 | cell = Gtk.CellRendererText() 202 | 203 | # pack the cell into the beginning of the combobox, allocating 204 | # no more space than needed 205 | combobox.pack_start(cell, False) 206 | # associate a property ("text") of the cellrenderer (cell) to a column (column 0) 207 | # in the model used by the combobox 208 | combobox.add_attribute(cell, "text", 0) 209 | 210 | # the first row is the active one by default at the beginning 211 | combobox.set_active(selected) 212 | 213 | # connect the signal emitted when a row is selected to the callback function 214 | combobox.connect("changed", self.on_combochanged) 215 | return combobox 216 | 217 | def on_combochanged(self, combo): 218 | self.locale = str(self.language_list[combo.get_active()]) 219 | self.__recordconfig() 220 | 221 | # return a sample rate combobox to add to the toolbar 222 | def __get_rate_combobox(self): 223 | """ 224 | @description: get the sample rate combobox of the toolbar 225 | 226 | @return: a Gtk.Combobox 227 | """ 228 | # the data in the model, of type string 229 | listmodel = Gtk.ListStore(int) 230 | # append the data in the model 231 | selected = 0 232 | i = 0 233 | self.rate_list = [8000, 16000] 234 | for rate_name in self.rate_list: 235 | listmodel.append([rate_name]) 236 | if rate_name == self.audio_rate: 237 | selected = i 238 | i += 1 239 | 240 | # a combobox to see the data stored in the model 241 | rate_combobox = Gtk.ComboBox(model=listmodel) 242 | rate_combobox.set_tooltip_text("Set Sampling Rate") 243 | 244 | # a cellrenderer to render the text 245 | rate_cell = Gtk.CellRendererText() 246 | 247 | # pack the cell into the beginning of the combobox, allocating 248 | # no more space than needed 249 | rate_combobox.pack_start(rate_cell, False) 250 | # associate a property ("text") of the cellrenderer (cell) to a column (column 0) 251 | # in the model used by the combobox 252 | rate_combobox.add_attribute(rate_cell, "text", 0) 253 | 254 | # the first row is the active one by default at the beginning 255 | rate_combobox.set_active(selected) 256 | 257 | # connect the signal emitted when a row is selected to the callback function 258 | rate_combobox.connect("changed", self.on_rate_combochanged) 259 | return rate_combobox 260 | 261 | def on_rate_combochanged(self, combo): 262 | self.audio_rate = self.rate_list[combo.get_active()] 263 | print(self.audio_rate) 264 | print(type(self.audio_rate)) 265 | self.__recordconfig() 266 | 267 | # return a speaker combobox to add to the toolbar 268 | def __get_speaker_combobox(self): 269 | """ 270 | @description: get the speaker combobox of the toolbar 271 | 272 | @return: a Gtk.Combobox 273 | """ 274 | # the data in the model, of type string 275 | listmodel = Gtk.ListStore(str) 276 | # append the data in the model 277 | selected = 0 278 | i = 0 279 | self.speaker_list = ['Mama (Male)', 'His Wife (Female)'] 280 | for speaker_name in self.speaker_list: 281 | listmodel.append([speaker_name]) 282 | if speaker_name == self.speaker: 283 | selected = i 284 | i += 1 285 | 286 | # a combobox to see the data stored in the model 287 | speaker_combobox = Gtk.ComboBox(model=listmodel) 288 | speaker_combobox.set_tooltip_text("Whose speaker to choose?") 289 | 290 | # a cellrenderer to render the text 291 | speaker_cell = Gtk.CellRendererText() 292 | 293 | # pack the cell into the beginning of the combobox, allocating 294 | # no more space than needed 295 | speaker_combobox.pack_start(speaker_cell, False) 296 | # associate a property ("text") of the cellrenderer (cell) to a column (column 0) 297 | # in the model used by the combobox 298 | speaker_combobox.add_attribute(speaker_cell, "text", 0) 299 | 300 | # the first row is the active one by default at the beginning 301 | speaker_combobox.set_active(selected) 302 | 303 | # connect the signal emitted when a row is selected to the callback function 304 | speaker_combobox.connect("changed", self.on_speaker_combochanged) 305 | return speaker_combobox 306 | 307 | def on_speaker_combochanged(self, combo): 308 | self.speaker = str(self.speaker_list[combo.get_active()]) 309 | self.__recordconfig() 310 | -------------------------------------------------------------------------------- /library/AddWindow.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version('Gtk', '3.0') 4 | from gi.repository import Gtk 5 | from gi.repository import Gdk 6 | from os.path import expanduser 7 | from ArgsWindow import ArgsWindow 8 | from ModuleSelection import ModuleSelection 9 | from HelpWindow import HelpWindow 10 | from SetupWindow import SetupWindow 11 | from ExternalWindow import ExternalWindow 12 | from InternalWindow import InternalWindow 13 | from MessageDialogWindow import MessageDialogWindow 14 | import os 15 | import subprocess 16 | import xml.etree.ElementTree as ET 17 | 18 | TARGET_TYPE_URI_LIST = 80 19 | dnd_list = [Gtk.TargetEntry.new('text/uri-list', 0, TARGET_TYPE_URI_LIST)] 20 | 21 | 22 | class AddWindow(): 23 | """ 24 | @description: This class allow the user to manage all his commands thanks 25 | to a treeview. The grid generated will be added to the window 26 | """ 27 | 28 | def __init__(self, button_config): 29 | self.Button = button_config 30 | # Gtk.ListStore will hold data for the TreeView 31 | # Only the first two columns will be displayed 32 | # The third one is for sorting file sizes as numbers 33 | store = Gtk.ListStore(str, str, str, str, str) 34 | # Get the data - see below 35 | self.populate_store(store) 36 | 37 | # use a filter in order to filtering the data 38 | self.tree_filter = store.filter_new() 39 | 40 | # getting parent directory and icon directory 41 | self.path = os.path.dirname(os.path.abspath(__file__)).strip('librairy') 42 | self.icon_path = self.path + 'resources/icons/' 43 | 44 | # create the treeview 45 | treeview = Gtk.TreeView.new_with_model(self.tree_filter) 46 | treeview.set_tooltip_text('list of commands') 47 | treeview.set_headers_visible(False) 48 | treeview.set_enable_search(True) 49 | treeview.set_search_column(1) 50 | treeview.set_hexpand(True) 51 | treeview.set_vexpand(True) 52 | 53 | # The first TreeView column displays the data from 54 | # the first ListStore column (text=0), which contains 55 | # file names 56 | renderer_1 = Gtk.CellRendererText() 57 | renderer_1.set_property("editable", True) 58 | renderer_1.connect("edited", self.key_edited, store) 59 | column_1 = Gtk.TreeViewColumn('Keys', renderer_1, text=0) 60 | column_1.set_min_width(200) 61 | # Calling set_sort_column_id makes the treeViewColumn sortable 62 | # by clicking on its header. The column is sorted by 63 | # the ListStore column index passed to it 64 | # (in this case 0 - the first ListStore column) 65 | column_1.set_sort_column_id(0) 66 | treeview.append_column(column_1) 67 | 68 | # xalign=1 right-aligns the file sizes in the second column 69 | renderer_2 = Gtk.CellRendererText(xalign=1) 70 | renderer_2.set_property("editable", True) 71 | renderer_2.connect("edited", self.command_edited, store) 72 | # text=1 pulls the data from the second ListStore column 73 | # which contains filesizes in bytes formatted as strings 74 | # with thousand separators 75 | column_2 = Gtk.TreeViewColumn('Commands', renderer_2, text=1) 76 | # Mak the Treeview column sortable by the third ListStore column 77 | # which contains the actual file sizes 78 | column_2.set_sort_column_id(1) 79 | treeview.append_column(column_2) 80 | 81 | # the label we use to show the selection 82 | self.labelState = Gtk.Label() 83 | self.labelState.set_text("Ready") 84 | self.labelState.set_justify(Gtk.Justification.LEFT) 85 | self.labelState.set_halign(Gtk.Align.START) 86 | 87 | # Use ScrolledWindow to make the TreeView scrollable 88 | # Otherwise the TreeView would expand to show all items 89 | # Only allow vertical scrollbar 90 | self.scrolled_window = Gtk.ScrolledWindow() 91 | self.scrolled_window.set_policy(Gtk.PolicyType.NEVER, 92 | Gtk.PolicyType.AUTOMATIC) 93 | self.scrolled_window.add(treeview) 94 | self.scrolled_window.set_min_content_width(200) 95 | self.scrolled_window.set_min_content_height(200) 96 | self.scrolled_window.connect('drag_data_received', 97 | self.on_drag_data_received, store) 98 | self.scrolled_window.drag_dest_set( 99 | Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, 100 | dnd_list, Gdk.DragAction.COPY) 101 | 102 | # a toolbar created in the method create_toolbar (see below) 103 | self.toolbar = self.create_toolbar(store) 104 | self.toolbar.set_hexpand(True) 105 | self.toolbar.show() 106 | 107 | # when a row of the treeview is selected, it emits a signal 108 | self.selection = treeview.get_selection() 109 | self.selection.connect("changed", self.on_changed, store) 110 | 111 | # define the visible func toolbar should be create 112 | self.tree_filter.set_visible_func(self.match_func) 113 | 114 | # Use a grid to add all item 115 | self.grid = Gtk.Grid() 116 | self.grid.set_border_width(0) 117 | self.grid.set_vexpand(True) 118 | self.grid.set_hexpand(True) 119 | self.grid.set_column_spacing(2) 120 | self.grid.set_column_homogeneous(False) 121 | self.grid.set_row_homogeneous(False) 122 | self.grid.set_row_spacing(2); 123 | self.grid.attach(self.toolbar, 0, 0, 1, 1) 124 | self.grid.attach(self.scrolled_window, 0, 1, 1, 1) 125 | self.grid.attach(self.labelState, 0, 2, 1, 1) 126 | 127 | # a grid for setup 128 | self.setup_grid = Gtk.Grid() 129 | 130 | def get_grid(self): 131 | """ 132 | @description: get the grid 133 | 134 | @return a Gtk.Grid 135 | """ 136 | return self.grid 137 | 138 | def on_drag_data_received(self, widget, context, x, y, Selection, 139 | target_type, timestamp, store): 140 | """ 141 | @description: The treeview allows dnd so, if the user select a file then the process to 142 | add a module start and finally a new line is added to the treeview. If the user select a 143 | folder then a new line is added to the treeview with a command to open this folder 144 | 145 | @param: widget 146 | the widget that support dnd 147 | 148 | @param: Selection 149 | the item selected 150 | 151 | @param: store 152 | the listStore to append the new entry 153 | """ 154 | if target_type == TARGET_TYPE_URI_LIST: 155 | uri = Selection.get_uris()[0] 156 | uri = uri.strip('\r\n\x00') 157 | uris = uri.split('://') 158 | if len(uris) >= 1: 159 | path = uris[1] 160 | print("path", path) 161 | if os.path.isfile(path): 162 | self.addModule(store, path) 163 | elif os.path.isdir(path): 164 | store.append(['key sentence', 'xdg-open ' + path, 165 | 'external', ' ', ' ']) 166 | self.scroll_to_bottom(store) 167 | 168 | def show_label(self, action): 169 | """ 170 | @description: Show or hide the bottom label 171 | 172 | @param: action 173 | a string 'show' or 'hide' 174 | """ 175 | etat = self.labelState.get_parent() 176 | if action == 'show' and etat == None: 177 | self.grid.attach(self.labelState, 0, 2, 2, 1) 178 | elif action == 'hide' and etat != None: 179 | self.grid.remove(self.labelState) 180 | 181 | def command_edited(self, widget, path, text, store): 182 | """ 183 | @description: callback function called when the user edited the command 184 | field of the treeview, we need to modify the liststore 185 | 186 | @param: widget 187 | a Gtk.Widget 188 | 189 | @param: path 190 | the way to find the modifiyed item 191 | 192 | @param: text 193 | the new text 194 | 195 | @param: store 196 | the listStore to modify 197 | """ 198 | iters = self.tree_filter.get_iter(path) 199 | path = self.tree_filter.convert_iter_to_child_iter(iters) 200 | store[path][1] = text 201 | self.saveTree(store) 202 | 203 | def key_edited(self, widget, path, text, store): 204 | """ 205 | @description: same thing that the previous function 206 | """ 207 | iters = self.tree_filter.get_iter(path) 208 | path = self.tree_filter.convert_iter_to_child_iter(iters) 209 | store[path][0] = text 210 | self.saveTree(store) 211 | 212 | def on_changed(self, selection, store): 213 | """ 214 | @description: hide the bottom label when the selection change 215 | 216 | @param: selection 217 | the selection from the treeview 218 | 219 | @return: a boolean 220 | """ 221 | # get the model and the iterator that points at the data in the model 222 | (model, iter) = selection.get_selected() 223 | if iter is not None: 224 | if self.setup_grid.get_parent is not None: 225 | self.setup_grid.destroy() 226 | 227 | self.show_label('hide') 228 | path = self.tree_filter.convert_iter_to_child_iter(iter) 229 | if store[path][2] == 'external': 230 | if self.try_button.get_parent() is None: 231 | self.toolbar.insert(self.try_button, 2) 232 | else: 233 | if self.try_button.get_parent() is not None: 234 | self.toolbar.remove(self.try_button) 235 | 236 | return True 237 | 238 | # a method to create the toolbar 239 | def create_toolbar(self, store): 240 | """ 241 | @description: create the toolbar of the main window 242 | 243 | @param: store 244 | the listStore to connect to some buttons 245 | 246 | @return: a Gtk.toolbar 247 | """ 248 | # a toolbar 249 | toolbar = Gtk.Toolbar() 250 | # which is the primary toolbar of the application 251 | toolbar.set_icon_size(Gtk.IconSize.LARGE_TOOLBAR) 252 | toolbar.set_style(Gtk.ToolbarStyle.BOTH_HORIZ) 253 | toolbar.set_show_arrow(True) 254 | 255 | # create a menu 256 | menu = Gtk.Menu() 257 | external = Gtk.MenuItem(label="External commands") 258 | external.connect("activate", self.add_clicked, store, 'external') 259 | external.show() 260 | menu.append(external) 261 | internal = Gtk.MenuItem(label="Internal commands") 262 | internal.connect("activate", self.add_clicked, store, 'internal') 263 | internal.show() 264 | menu.append(internal) 265 | module = Gtk.MenuItem(label="Module") 266 | module.connect("activate", self.add_clicked, store, 'module') 267 | module.show() 268 | menu.append(module) 269 | 270 | # create a button for the "add" action, with a stock image 271 | add_icon = Gtk.Image() 272 | add_icon.set_from_file(self.icon_path+'add.png') 273 | add_button = Gtk.MenuToolButton(icon_widget = add_icon) 274 | add_button.set_label("Add") 275 | add_button.set_menu(menu) 276 | # label is shown 277 | add_button.set_is_important(True) 278 | # insert the button at position in the toolbar 279 | toolbar.insert(add_button, 0) 280 | # show the button 281 | add_button.connect("clicked", self.add_clicked, store, 'external') 282 | add_button.set_tooltip_text('Add a new command') 283 | add_button.show() 284 | 285 | # create a menu to store remove action 286 | delete_menu = Gtk.Menu() 287 | one_item = Gtk.MenuItem(label="Remove") 288 | one_item.connect("activate", self.remove_clicked, store) 289 | one_item.set_tooltip_text('Remove this command') 290 | one_item.show() 291 | delete_menu.append(one_item) 292 | all_item = Gtk.MenuItem(label="Clean up") 293 | all_item.connect("activate", self.removeall_clicked, store) 294 | all_item.set_tooltip_text('Remove all commands') 295 | all_item.show() 296 | delete_menu.append(all_item) 297 | 298 | remove_icon = Gtk.Image() 299 | remove_icon.set_from_file(self.icon_path+'remove.png') 300 | remove_button = Gtk.MenuToolButton(icon_widget = remove_icon) 301 | remove_button.set_label("Remove") 302 | remove_button.set_menu(delete_menu) 303 | image = Gtk.Image() 304 | image.set_from_stock(Gtk.STOCK_REMOVE, Gtk.IconSize.BUTTON) 305 | # label is shown 306 | remove_button.set_is_important(True) 307 | # insert the button at position in the toolbar 308 | toolbar.insert(remove_button, 1) 309 | # show the button 310 | remove_button.connect("clicked", self.remove_clicked, store) 311 | remove_button.set_tooltip_text('Remove this command') 312 | remove_button.show() 313 | 314 | # create a button for the "try" action 315 | self.try_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_MEDIA_PLAY) 316 | self.try_button.set_label("Try") 317 | self.try_button.set_is_important(True) 318 | self.try_button.connect("clicked", self.try_command, store) 319 | self.try_button.set_tooltip_text('Try this command') 320 | self.try_button.show() 321 | # toolbar.insert(self.try_button,2) 322 | 323 | 324 | # create a button to edit a module 325 | edit_icon = Gtk.Image() 326 | edit_icon.set_from_file(self.icon_path + 'edit.png') 327 | self.module_button = Gtk.ToolButton(icon_widget = edit_icon) 328 | self.module_button.set_label('Edit') 329 | self.module_button.set_is_important(True) 330 | self.module_button.connect("clicked", self.edit_clicked, store) 331 | self.module_button.set_tooltip_text('Edit this command') 332 | self.module_button.show() 333 | toolbar.insert(self.module_button, 2) 334 | 335 | # create a button to setup the application 336 | toolbar.insert(self.Button, 3) 337 | 338 | # create a combobox to store user choice 339 | self.combo = self.get_combobox() 340 | toolcombo = Gtk.ToolItem() 341 | toolcombo.add(self.combo) 342 | toolcombo.show() 343 | toolbar.insert(toolcombo, 4) 344 | 345 | # add a separator 346 | separator = Gtk.ToolItem() 347 | separator.set_expand(True) 348 | toolbar.insert(separator, 5) 349 | 350 | # create a button for the "Help" action 351 | about_icon = Gtk.Image() 352 | about_icon.set_from_file(self.icon_path+'help.png') 353 | about_button = Gtk.ToolButton(icon_widget = about_icon) 354 | about_button.set_label("About") 355 | about_button.set_is_important(True) 356 | toolbar.insert(about_button, 6) 357 | about_button.connect("clicked", self.help_clicked) 358 | about_button.set_tooltip_text("Display who are behind Mama!") 359 | about_button.show() 360 | 361 | # return the complete toolbar 362 | return toolbar 363 | 364 | # open a setup window 365 | def setup_clicked(self, button): 366 | s = SetupWindow() 367 | 368 | # return a combobox to add to the toolbar 369 | def get_combobox(self): 370 | """ 371 | @description: get the combobox of the toolbar 372 | 373 | @return: a Gtk.Combobox 374 | """ 375 | # the data in the model, of type string 376 | listmodel = Gtk.ListStore(str) 377 | # append the data in the model 378 | listmodel.append(['All']) 379 | listmodel.append(['External']) 380 | listmodel.append(['Internal']) 381 | listmodel.append(['Modules']) 382 | 383 | # a combobox to see the data stored in the model 384 | combobox = Gtk.ComboBox(model=listmodel) 385 | combobox.set_tooltip_text("What type of command to add?") 386 | 387 | # a cellrenderer to render the text 388 | cell = Gtk.CellRendererText() 389 | 390 | # pack the cell into the beginning of the combobox, allocating 391 | # no more space than needed 392 | combobox.pack_start(cell, False) 393 | # associate a property ("text") of the cellrenderer (cell) to a column (column 0) 394 | # in the model used by the combobox 395 | combobox.add_attribute(cell, "text", 0) 396 | 397 | # the first row is the active one by default at the beginning 398 | combobox.set_active(0) 399 | 400 | # connect the signal emitted when a row is selected to the callback function 401 | combobox.connect("changed", self.on_combochanged) 402 | return combobox 403 | 404 | # callback function attach to the combobox 405 | def on_combochanged(self, combo): 406 | """ 407 | @description: the combobox is used to filter the treeview and switch 408 | between different commands types 409 | """ 410 | self.tree_filter.refilter() 411 | 412 | # filter function 413 | def match_func(self, model, iterr, data=None): 414 | """ 415 | @description: we get the combobox selection and filter the treeview 416 | data thanks to this selection. 417 | 418 | @return: a boolean 419 | """ 420 | query = self.combo.get_active() 421 | value = model.get_value(iterr, 1) 422 | field = model.get_value(iterr, 2) 423 | 424 | if query == 0: 425 | return True 426 | elif query == 1 and 'modules' not in field and 'internal' not in field: 427 | return True 428 | elif query == 2 and 'internal' in field: 429 | return True 430 | elif query == 3 and 'modules' in field: 431 | return True 432 | else: 433 | return False 434 | 435 | def edit_clicked(self, button, store): 436 | # get the selected line, if it is module then we can open the window 437 | (model, iters) = self.selection.get_selected() 438 | 439 | if len(store) != 0: 440 | if iters is not None: 441 | iter = self.tree_filter.convert_iter_to_child_iter(iters) 442 | w = None 443 | if store[iter][2] == 'modules': 444 | w = ArgsWindow(store[iter][3], store[iter][1], store, iter) 445 | elif store[iter][2] == 'external': 446 | w = ExternalWindow(store, iter) 447 | elif store[iter][2] == 'internal': 448 | w = InternalWindow(store, iter) 449 | 450 | if self.setup_grid.get_parent() is None and w is not None: 451 | self.setup_grid = w.get_grid() 452 | self.grid.attach_next_to(self.setup_grid, 453 | self.scrolled_window, 454 | Gtk.PositionType.BOTTOM, 1, 1) 455 | 456 | def add_clicked(self, button, store, add_type): 457 | """ 458 | @description: callback function called when the user want to add 459 | command 460 | 461 | @param: button 462 | the button that has to be clicked 463 | 464 | @param: store 465 | the listStore that will contain a new entry 466 | 467 | @param: add_type 468 | the type of the new command to add 469 | """ 470 | if self.setup_grid.get_parent() is None: 471 | if add_type == 'external': 472 | win = ExternalWindow(store, None) 473 | self.setup_grid = win.get_grid() 474 | self.grid.attach_next_to(self.setup_grid, self.scrolled_window, 475 | Gtk.PositionType.BOTTOM, 1, 1) 476 | self.grid.show_all() 477 | 478 | elif add_type == 'internal': 479 | win = InternalWindow(store, None) 480 | self.setup_grid = win.get_grid() 481 | self.grid.attach_next_to(self.setup_grid, self.scrolled_window, 482 | Gtk.PositionType.BOTTOM, 1, 1) 483 | 484 | elif add_type == 'module': 485 | mo = ModuleSelection() 486 | module = mo.getModule() 487 | if module != '-1': 488 | self.addModule(store, module) 489 | else: 490 | self.show_label('show') 491 | self.labelState.set_text("Error, you must choose a file") 492 | 493 | def scroll_to_bottom(self, store): 494 | # autoscroll to the bottom 495 | adj = self.scrolled_window.get_vadjustment() 496 | adj.set_value(adj.get_upper() - adj.get_page_size()) 497 | 498 | # select the bottom one 499 | iter = store.get_iter(len(store) - 1) 500 | st, iters = self.tree_filter.convert_child_iter_to_iter(iter) 501 | 502 | self.selection.select_iter(iters) 503 | 504 | def addModule(self, store, module): 505 | """ 506 | @description: function that adds a module 507 | 508 | @param: store 509 | the listStore that will receive a new entry 510 | 511 | @param: module 512 | the path of the executable file of the module 513 | """ 514 | # ex: recup de weather.sh 515 | name = module.split('/')[-1] 516 | iter = None 517 | 518 | if self.setup_grid.get_parent() is None: 519 | win = ArgsWindow(module, name, store, iter) 520 | self.setup_grid = win.get_grid() 521 | self.grid.attach_next_to(self.setup_grid, self.scrolled_window, 522 | Gtk.PositionType.BOTTOM, 1, 1) 523 | 524 | def remove_clicked(self, button, store): 525 | """ 526 | @description: callback function called wnen the user want to remove 527 | a line of the treeview 528 | 529 | @param: button 530 | the button that will be clicked 531 | 532 | @param: store 533 | the listStore that is going to be modify 534 | """ 535 | if len(store) != 0: 536 | (model, iters) = self.selection.get_selected() 537 | if iters is not None: 538 | iter = self.tree_filter.convert_iter_to_child_iter(iters) 539 | if iter is not None: 540 | self.show_label('show') 541 | self.labelState.set_text( 542 | 'Remove' + ': ' + store[iter][0] + ' ' + store[iter][1]) 543 | store.remove(iter) 544 | self.saveTree(store) 545 | else: 546 | print("Select a title to remove") 547 | else: 548 | print("Empty list") 549 | 550 | def removeall_clicked(self, button, store): 551 | """ 552 | @description: Same as the past function but remove all lines of the 553 | treeview 554 | """ 555 | # if there is still an entry in the model 556 | old = expanduser('~') + '/.config/mama/mama.xml' 557 | new = expanduser('~') + '/.config/mama/.mama.bak' 558 | if os.path.exists(old): 559 | os.rename(old, new) 560 | 561 | if len(store) != 0: 562 | # remove all the entries in the model 563 | self.labelState.set_text('Remove all commands') 564 | for i in range(len(store)): 565 | iter = store.get_iter(0) 566 | store.remove(iter) 567 | 568 | self.saveTree(store) 569 | print("Empty list") 570 | 571 | def try_command(self, button, store): 572 | """ 573 | @description: try a command (bash) 574 | 575 | @param: button 576 | the button that has to be clicked 577 | 578 | @param: store 579 | the listStore 580 | """ 581 | (model, iter) = self.selection.get_selected() 582 | if iter is not None: 583 | command = model[iter][1] 584 | Type = model[iter][2] 585 | if 'internal' != Type and 'modules' != Type: 586 | process = subprocess.Popen(command, stdout=subprocess.PIPE, 587 | stderr=subprocess.PIPE, shell=True) 588 | output, error = process.communicate() 589 | output = output.decode("utf-8") 590 | error = error.decode("utf-8") 591 | self.show_label('show') 592 | self.labelState.set_text('Output and error on dialog box.') 593 | if output and error: 594 | info_dialog = MessageDialogWindow(output) 595 | info_dialog.show_info_message() 596 | info_dialog.show_all() 597 | error_dialog = MessageDialogWindow(error) 598 | error_dialog.show_error_message() 599 | error_dialog.show_all() 600 | elif output and not error: 601 | info_dialog = MessageDialogWindow(output) 602 | info_dialog.show_info_message() 603 | info_dialog.show_all() 604 | else: 605 | error_dialog = MessageDialogWindow(error) 606 | error_dialog.show_error_message() 607 | error_dialog.show_all() 608 | 609 | def help_clicked(self, button): 610 | """ 611 | @description: show the help window 612 | 613 | @param: button 614 | the button that has to be clicked 615 | """ 616 | HelpWindow() 617 | 618 | def populate_store(self, store): 619 | """ 620 | @description: load the treeview from the mama.xml file or 621 | from the default.xml file 622 | 623 | @param: store 624 | the listStore that will be modify 625 | """ 626 | # user ocnfig file 627 | config = expanduser('~') + '/.config/mama/mama.xml' 628 | 629 | # default config file for the selected language 630 | path = os.path.dirname(os.path.abspath(__file__)).strip('librairy') 631 | default = path + 'config/en_EN/default.xml' 632 | 633 | try: 634 | if os.path.isfile(config): 635 | # here the program refuses to load the xml file 636 | tree = ET.parse(config) 637 | else: 638 | if os.path.exists(expanduser('~') + '/.config/mama') == False: 639 | os.makedirs(expanduser('~') + '/.config/mama') 640 | tree = ET.parse(default) 641 | if os.path.exists( 642 | expanduser('~') + '/.config/mama/modules') == False: 643 | os.system('cp -r ' + path + '/modules ' + expanduser( 644 | '~') + '/.config/mama') 645 | 646 | root = tree.getroot() 647 | for entry in root.findall('entry'): 648 | Type = entry.get('name') 649 | Key = entry.find('key').text 650 | Command = entry.find('command').text 651 | linker = entry.find('linker').text 652 | spacebyplus = entry.find('spacebyplus').text 653 | store.append([Key, Command, Type, linker, spacebyplus]) 654 | except Exception as e: 655 | error = "Error while reading config file.\n"+type( 656 | e)+"\n"+e.args+"\n"+e 657 | error_dialog = MessageDialogWindow(error) 658 | error_dialog.show_error_message() 659 | error_dialog.show_all() 660 | 661 | def saveTree(self, store): 662 | """ 663 | @description: save the treeview in the mama.xml file 664 | 665 | @param: store 666 | the listStore attach to the treeview 667 | """ 668 | # if there is still an entry in the model 669 | model = self.tree_filter.get_model() 670 | config = expanduser('~') + '/.config/mama/mama.xml' 671 | try: 672 | if not os.path.exists(os.path.dirname(config)): 673 | os.makedirs(os.path.dirname(config)) 674 | 675 | root = ET.Element("data") 676 | if len(store) != 0: 677 | for i in range(len(store)): 678 | iter = store.get_iter(i) 679 | if model[iter][0] != '' and model[iter][1] != '': 680 | for s in model[iter][0].split('|'): 681 | s = s.lower() 682 | s = s.replace('*', ' ') 683 | Type = ET.SubElement(root, "entry") 684 | Type.set("name", unicode(model[iter][2], "utf-8")) 685 | Key = ET.SubElement(Type, "key") 686 | Key.text = unicode(s, "utf-8") 687 | Command = ET.SubElement(Type, "command") 688 | Command.text = unicode(model[iter][1], "utf-8") 689 | Linker = ET.SubElement(Type, "linker") 690 | Spacebyplus = ET.SubElement(Type, "spacebyplus") 691 | if store[iter][3] is not None or store[iter][ 692 | 4] is not None: 693 | Linker.text = unicode(store[iter][3], "utf-8") 694 | Spacebyplus.text = unicode(store[iter][4], 695 | "utf-8") 696 | 697 | ET.ElementTree(root).write(config, encoding="utf-8", 698 | xml_declaration=True) 699 | 700 | self.show_label('show') 701 | self.labelState.set_text('Save commands') 702 | except IOError: 703 | error_dialog = MessageDialogWindow("Unable to write the file.") 704 | error_dialog.show_error_message() 705 | error_dialog.show_all() 706 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------