From 756ea88db2e6ab21a88f38478e3b344d0819d00e Mon Sep 17 00:00:00 2001 From: Quintijn Hoogenboom Date: Thu, 8 Aug 2024 11:20:20 +0200 Subject: [PATCH] adding rememberdialog.py (in a mixture of things) --- .../UnimacroGrammars/rememberdialog.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/unimacro/UnimacroGrammars/rememberdialog.py diff --git a/src/unimacro/UnimacroGrammars/rememberdialog.py b/src/unimacro/UnimacroGrammars/rememberdialog.py new file mode 100644 index 0000000..2f7c7b6 --- /dev/null +++ b/src/unimacro/UnimacroGrammars/rememberdialog.py @@ -0,0 +1,51 @@ +"""template for _folders grammar, remember function. +This template is filled with the actual values and fired. It asks for a spoken form to "remember a given file", this value +is put in the _folders.ini config file. +""" +#pylint:disable=W0621 +import time +import PySimpleGUI as sg +from dtactions.unimacro import inivars + +prompt = """Remember in Unimacro _folders grammar""" # readable text +text = """Remember folder "C:/Users/Gebruiker/Music" for future calling? + +Please give a spoken form for this folder and choose OK; or Cancel...""" # input text, the key of the +inifile = "C:/Users/Gebruiker/Documents/unimacro_clean_start/enx_inifiles/_folders.ini" +section = "folders" +value = "C:/Users/Gebruiker/Music" +title = "test" +default = "Music" +pausetime = 3 # should be replaced by 0 or a positive int value + + + +def InputBox(text, prompt, title, default): + """the dialog, which returns the wanted spoken form""" + layout = [[sg.Text(prompt)], + [sg.InputText(default)], + [sg.OK(), sg.Cancel()]] + + window = sg.Window(title, layout) + + _event, values = window.read() + window.close() + + return values[0] + +if __name__ == "__main__": + result = InputBox(text, prompt, title, default) + if result: + key = result + ini = inivars.IniVars(inifile) + ini.set(section, key, value) + ini.write() + print(f'Wrote "{key} = {value}" to inifile') + print('Call "edit folders" to edit or delete') + else: + print("Action canceled, no change of ini file") + # if pausetime is given, launch as .py, otherwise launch as .pyw: + if pausetime: + # print "sleep: %s"% pausetime + time.sleep(pausetime) + \ No newline at end of file