diff --git a/_mathfly_main.py b/_mathfly_main.py index 84b724b..1317210 100644 --- a/_mathfly_main.py +++ b/_mathfly_main.py @@ -1,45 +1,48 @@ -from dragonfly import (Function, Grammar, Text, Dictation, Choice, Pause) +import os +os.environ['BREATHE_REBUILD_COMMAND'] = "rebuild mathfly" + -import os, sys import logging -import natlink logging.basicConfig() -from mathfly.lib import control, utilities -from mathfly.lib.merge.mergerule import MergeRule -from mathfly.lib.merge.mergepair import MergeInf +from mathfly.imports import * BASE_PATH = os.path.realpath(__file__).split("\\_mathfly_main.py")[0].replace("\\", "/") sys.path.append(BASE_PATH) -CORE = utilities.load_toml_relative("config/core.toml") +CORE = utilities.load_config("core.toml") +SETTINGS = utilities.load_toml_relative("config/settings.toml") -MF_NEXUS = control.nexus() -MF_NEXUS.build(True) -class MainRule(MergeRule): +def delete_words(words): + for word in words: + try: + natlink.deleteWord(word) + except: + pass - mapping = { - "configure math fly [settings]": - Function(utilities.load_config, config_name="settings.toml"), +def add_words(words): + for word in words: + try: + natlink.addWord(word) + except: + pass - " ": Function(MF_NEXUS.rule_changer), +delete_words(SETTINGS["delete_words"]) +add_words(SETTINGS["add_words"]) - "reboot dragon": Function(utilities.reboot), +Breathe.load_modules( + { + "mathfly.ccr": "global_extras" + } +) - "rebuild math fly": Function(MF_NEXUS.build), +Breathe.load_modules( + { + "mathfly": SETTINGS["modules"] + } +) - "math fly help": Function(utilities.help), - } - extras=[ - MF_NEXUS.generate_ccr_choices("name"), - Choice("enable", { - "enable": True, - "disable": False - }), - ] +print("*- Starting Mathfly -*") -grammar = Grammar('general') -main_rule = MainRule() -grammar.add_rule(main_rule) -grammar.load() \ No newline at end of file +del os.environ['BREATHE_REBUILD_COMMAND'] \ No newline at end of file diff --git a/mathfly/apps/app_template.py b/mathfly/apps/app_template.py index 573f3c4..d5dba3c 100644 --- a/mathfly/apps/app_template.py +++ b/mathfly/apps/app_template.py @@ -1,9 +1,7 @@ from mathfly.imports import * -class RuleNameRule(MergeRule): - pronunciation = "AppName" - mcontext = AppContext(title="AppName") - +Breathe.add_commands( + context = AppContext(title="AppName"), mapping = { "new file" : Key("c-n"), "open file" : Key("c-o"), @@ -20,10 +18,9 @@ class RuleNameRule(MergeRule): "zoom in" : Key("c-equals"), "zoom out" : Key("c-minus"), - } - + }, extras = [ - IntegerRef("n", 1, 1000), + IntegerRefMF("n", 1, 1000), Choice("nth", { "first" : "1", "second" : "2", @@ -35,10 +32,9 @@ class RuleNameRule(MergeRule): "eighth" : "8", "(last | final)": "9", }) - ] - + ], defaults = { "n": 1, - } - -control.nexus().merger.add_non_ccr_app_rule(RuleNameRule()) + }, + ccr=False +) diff --git a/mathfly/apps/sublime.py b/mathfly/apps/sublime.py index a42a8e8..3934c94 100644 --- a/mathfly/apps/sublime.py +++ b/mathfly/apps/sublime.py @@ -1,9 +1,7 @@ from mathfly.imports import * -class SublimeRule(MergeRule): - pronunciation = "sublime" - mcontext = AppContext(executable="sublime_text", title="Sublime Text") - +Breathe.add_commands( + context = AppContext(executable="sublime_text", title="Sublime Text"), mapping = { "new (file | pane)": Key("c-n"), # {"keys": ["ctrl+alt+n"], "command": "new_window"}, @@ -86,13 +84,12 @@ class SublimeRule(MergeRule): "zoom in []": Key("c-equal")*Repeat(extra="n2"), "zoom out []": Key("c-minus")*Repeat(extra="n2"), - - } + }, extras = [ - IntegerRef("n11", 1, 100), - IntegerRef("n12", 0, 100), - IntegerRef("n2", 1, 9), - IntegerRef("n3", 1, 21), + IntegerRefMF("n11", 1, 100), + IntegerRefMF("n12", 0, 100), + IntegerRefMF("n2", 1, 9), + IntegerRefMF("n3", 1, 21), Choice("nth", { "first": "1", "second": "2", @@ -117,14 +114,11 @@ class SublimeRule(MergeRule): "two": "2", "right": "2", }), - ] + ], defaults = { "n12": "", "n2": 1, "n3": 1, - } - - -#--------------------------------------------------------------------------- - -control.nexus().merger.add_non_ccr_app_rule(SublimeRule()) \ No newline at end of file + }, + ccr=False +) \ No newline at end of file diff --git a/mathfly/apps/sumatrapdf.py b/mathfly/apps/sumatrapdf.py index d896b9d..1d5f42c 100644 --- a/mathfly/apps/sumatrapdf.py +++ b/mathfly/apps/sumatrapdf.py @@ -1,9 +1,7 @@ from mathfly.imports import * -class SumatraPDFRule(MergeRule): - pronunciation = "SumatraPDF" - mcontext = AppContext(title="SumatraPDF") - +Breathe.add_commands( + AppContext(title="SumatraPDF"), mapping = { # https://www.sumatrapdfreader.org/manual.html "open file" : Key("c-o"), @@ -18,7 +16,7 @@ class SumatraPDFRule(MergeRule): "find" : Key("c-f"), "find next" : Key("f3"), "find previous" : Key("s-f3"), - "page " : Key("c-g") + Text("%(n)s") + Key("enter"), + "page " : Key("c-g") + Text("%(n1000)s") + Key("enter"), "table of contents" : Key("f12"), "zoom in" : Key("c-equals"), @@ -34,10 +32,9 @@ class SumatraPDFRule(MergeRule): "rotate left" : Key("c-minus"), "presentation [mode]" : Key("f11"), "full screen" : Key("s-f11"), - } - + }, extras = [ - IntegerRef("n", 1, 1000), + IntegerRef("n1000", 1, 1000), Choice("nth", { "first" : "1", "second" : "2", @@ -49,10 +46,6 @@ class SumatraPDFRule(MergeRule): "eighth" : "8", "(last | final)": "9", }) - ] - - defaults = { - "n": 1, - } - -control.nexus().merger.add_non_ccr_app_rule(SumatraPDFRule()) + ], + ccr=False +) \ No newline at end of file diff --git a/mathfly/apps/wordpad.py b/mathfly/apps/wordpad.py index e964df1..830bb76 100644 --- a/mathfly/apps/wordpad.py +++ b/mathfly/apps/wordpad.py @@ -1,9 +1,7 @@ from mathfly.imports import * -class WordPadRule(MergeRule): - pronunciation = "WordPad" - mcontext = AppContext(title="WordPad") - +Breathe.add_commands( + AppContext(title="WordPad"), mapping = { "new file" : Key("c-n"), "open file" : Key("c-o"), @@ -11,14 +9,6 @@ class WordPadRule(MergeRule): "page down []" : Key("c-pagedown:%(n)s"), "page up []" : Key("c-pageup:%(n)s"), - } - - extras = [ - IntegerRef("n", 1, 1000), - ] - - defaults = { - "n": 1, - } - -control.nexus().merger.add_non_ccr_app_rule(WordPadRule()) + }, + ccr=False +) diff --git a/mathfly/ccr/LyX.py b/mathfly/ccr/LyX.py index 85db365..8c586b4 100644 --- a/mathfly/ccr/LyX.py +++ b/mathfly/ccr/LyX.py @@ -5,8 +5,8 @@ ''' from mathfly.imports import * -BINDINGS = utilities.load_toml_relative("config/lyx.toml") -CORE = utilities.load_toml_relative("config/core.toml") +BINDINGS = utilities.load_config("lyx.toml") +CORE = utilities.load_config("core.toml") def greek(big, greek_letter): if big: @@ -17,125 +17,104 @@ def matrix(rows, cols): Text("\\" + BINDINGS["matrix_style"] + " ").execute() Key("a-m, w, i, "*(rows-1) + "a-m, c, i, "*(cols-1)).execute() -class lyx_nested(NestedRule): - mapping = { +Breathe.add_commands( + AppContext(executable="lyx.exe"), + { + "": Key("%(control)s"), + " []": Key("%(control_repeat)s") * Repeat("n"), + }, + [ + Choice("control", BINDINGS["control"]), + Choice("control_repeat", BINDINGS["control_repeat"]), + ], + ccr=False, +) + +Breathe.add_commands( + AppContext(executable="lyx.exe"), + { + "": Text("%(numbers)s"), + BINDINGS["symbol1_prefix"] + " ": Text("\\%(symbol1)s "), + BINDINGS["symbol2_prefix"] + " ": Text("\\%(symbol2)s "), + BINDINGS["accent_prefix"] + " ": Key("a-m, %(accent)s"), + BINDINGS["text_prefix"] + " ": Text("\\%(text_modes)s "), + BINDINGS["greek_prefix"] + " [] ": Function(greek), + "": Key("%(misc_lyx_keys)s"), + "": Alternating("command"), + "matrix by ": Function(matrix), + " ": Key( + "a-m, f, %(numbers)s, down, %(denominator)s, right" + ), + }, + [ + IntegerRef("rows", 1, BINDINGS["max_matrix_size"]), + IntegerRef("cols", 1, BINDINGS["max_matrix_size"]), + IntegerRefMF("numbers", 0, CORE["numbers_max"]), + Choice("big", {CORE["capitals_prefix"]: True}, default=False), + Choice("greek_letter", BINDINGS["greek_letters"]), + Choice("symbol1", BINDINGS["tex_symbols1"]), + Choice("symbol2", BINDINGS["tex_symbols2"]), + Choice("accent", BINDINGS["accents"]), + Choice("text_modes", BINDINGS["text_modes"]), + Choice("misc_lyx_keys", BINDINGS["misc_lyx_keys"]), + Choice("command", BINDINGS["misc_lyx_commands"]), + Choice("denominator", BINDINGS["denominators"]), + ], +) + + +Breathe.add_commands( + AppContext(executable="lyx.exe"), + { "[] integral from to ": - [Text("\\int _"), Key("right, caret"), Key("right")], + Exec("before") + Text("\\int _") + Exec("sequence1") + + Key("right, caret") + Exec("sequence2") + Key("right"), "[] definite from to ": - [Key("a-m, lbracket, right, underscore"), - Key("right, caret"), Key("right, left:2")], + Exec("before") + Key("a-m, lbracket, right, underscore") + + Exec("sequence1") + Key("right, caret") + Exec("sequence2") + Key("right, left:2"), "[] differential by ": - [Key("a-m, f, d"), Key("down, d"), Key("right")], + Exec("before") + Key("a-m, f, d") + Exec("sequence1") + + Key("down, d") + Exec("sequence2") + Key("right"), "[] sum from to ": - [Text("\\stackrelthree ") + Key("down") + Text("\\sum ") + Key("down"), - Key("up:2"), Key("right")], + Exec("before") + Text("\\stackrelthree ") + Key("down") + + Text("\\sum ") + Key("down") + Exec("sequence1") + Key("up:2") + + Exec("sequence2") + Key("right"), "[] limit from to ": - [Text("\\underset \\lim ") + Key("down"), - Text("\\rightarrow "), Key("right")], + Exec("before") + Text("\\underset \\lim ") + Key("down") + + Exec("sequence1") + Text("\\rightarrow ") + Exec("sequence2") + Key("right"), "[] argument that ": - [Text("\\underset \\arg \\%(minmax)s ") + Key("down"), - Key("right"), None], + Exec("before") + Text("\\underset \\arg \\%(minmax)s ") + + Key("down") + Exec("sequence1") + Key("right"), "[] by ": - [Text("\\underset \\%(minmax)s ") + Key("down"), - Key("right"), None], + Exec("before") + Text("\\underset \\%(minmax)s ") + + Key("down") + Exec("sequence1") + Key("right"), "[] []": - [Key("%(script1)s"), Key("right"), None], + Exec("before") + Key("%(script1)s") + Exec("singleton1") + Key("right") + Exec("after"), "[] []": - [Key("%(script1)s"), Key("right, %(script2)s"), Key("right")], - } - extras = [ - Choice("minmax", { - "(minimum | minimises)": "min", - "(maximum | maximises)": "max", - }), - Choice("script1", { - "sub": "_", - "super": "^", - }), - Choice("script2", { - "sub": "_", - "super": "^", - }), - ] - -class lyx_mathematicsNon(MergeRule): - mapping = { - "": - Key("%(control)s"), - " []": - Key("%(control_repeat)s")*Repeat(extra="n"), - } - extras = [ - IntegerRef("n", 1, 10), - Choice("control", BINDINGS["control"]), - Choice("control_repeat", BINDINGS["control_repeat"]), - ] - defaults = { - "n": 1, - } - -class lyx_mathematics(MergeRule): - non = lyx_mathematicsNon - nested = lyx_nested - mwith = CORE["pronunciation"] - mcontext = AppContext(executable="lyx") - pronunciation = BINDINGS["pronunciation"] - - mapping = { - BINDINGS["symbol1_prefix"] + " ": - Text("\\%(symbol1)s "), - - BINDINGS["symbol2_prefix"] + " ": - Text("\\%(symbol2)s "), - - BINDINGS["accent_prefix"] + " ": - Key("a-m, %(accent)s"), - - BINDINGS["text_prefix"] + " ": - Text("\\%(text_modes)s "), - - BINDINGS["greek_prefix"] + " [] ": - Function(greek), - - "": - Key("%(misc_lyx_keys)s"), - - "": - Alternating("command"), - - "matrix by ": - Function(matrix), - - " ": - Key("a-m, f") + Text("%(numbers)s") + Key("down") + Text("%(denominator)s") + Key("right"), - - } - - extras = [ - IntegerRef("rows", 1, BINDINGS["max_matrix_size"]), - IntegerRef("cols", 1, BINDINGS["max_matrix_size"]), - IntegerRef("numbers", 0, CORE["numbers_max"]), - Choice("big", {CORE["capitals_prefix"]: True}), - Choice("greek_letter", BINDINGS["greek_letters"]), - Choice("symbol1", BINDINGS["tex_symbols1"]), - Choice("symbol2", BINDINGS["tex_symbols2"]), - Choice("accent", BINDINGS["accents"]), - Choice("text_modes", BINDINGS["text_modes"]), - Choice("misc_lyx_keys", BINDINGS["misc_lyx_keys"]), - Choice("command", BINDINGS["misc_lyx_commands"]), - Choice("denominator", BINDINGS["denominators"]), - ] - - defaults = { - "big": False, - } - -control.nexus().merger.add_app_rule(lyx_mathematics()) + Exec("before") + Key("%(script1)s") + Exec("singleton1") + + Key("right, %(script2)s") + Exec("singleton2") + Key("right") + Exec("after"), + }, + extras=[ + Choice( + "minmax", {"(minimum | minimises)": "min", "(maximum | maximises)": "max"} + ), + Choice("script1", {"sub": "_", "super": "^"}), + Choice("script2", {"sub": "_", "super": "^"}), + CommandsRef("before", 8), + CommandsRef("after", 8), + CommandsRef("singleton1", 1), + CommandsRef("singleton2", 1), + CommandsRef("sequence1", 4), + CommandsRef("sequence2", 4), + ], + top_level=True, +) + diff --git a/mathfly/ccr/ScientificNotebook55.py b/mathfly/ccr/ScientificNotebook55.py index dc1062c..1a76e65 100644 --- a/mathfly/ccr/ScientificNotebook55.py +++ b/mathfly/ccr/ScientificNotebook55.py @@ -5,141 +5,127 @@ ''' from mathfly.imports import * -BINDINGS = utilities.load_toml_relative("config/ScientificNotebook55.toml") -CORE = utilities.load_toml_relative("config/core.toml") +BINDINGS = utilities.load_config("ScientificNotebook55.toml") +CORE = utilities.load_config("core.toml") -#--------------------------------------------------------------------------- +#------------------------------------------------ + +def TeX(symbol): + return Key("ctrl:down") + Text(symbol) + Key("ctrl:up") -def texchar(symbol): - keychain = "ctrl:down, " - for character in symbol: - keychain = keychain + character + ", " - keychain=keychain + "ctrl:up" - Key(keychain).execute() def greek(big, greek_letter): if big: greek_letter = greek_letter.upper() Key("c-g, " + greek_letter).execute() + def matrix(rows, cols): Key("f10/5, i/5, down:8, enter/50").execute() Key(str(rows) + "/50, tab, " + str(cols) + "/50, enter").execute() -class sn_nested(NestedRule): - mapping = { + +#------------------------------------------------ + + +Breathe.add_commands( + AppContext(executable="scientific notebook"), + { + "text ": Key("c-t") + + Function(lambda text: Text(text.capitalize()).execute()), + "": Key("%(control)s"), + }, + [ + Choice("control", BINDINGS["control"]), + ], + ccr=False, +) + +Breathe.add_commands( + AppContext(executable="scientific notebook"), + { + BINDINGS["symbol_prefix"] + " ": TeX("%(symbol)s"), + # + BINDINGS["greek_prefix"] + " [] ": Function(greek), + BINDINGS["accent_prefix"] + " ": Key("%(accent)s"), + BINDINGS["unit_prefix"] + " ": Alternating("units"), + "": Key("%(misc_sn_keys)s"), + "": Text("%(misc_sn_text)s"), + "matrix by ": Function(matrix), + "": Text("%(numbers)s"), + " ": Key("c-f") + + Text("%(numbers)s") + + Key("down") + + Text("%(denominator)s") + + Key("right"), + }, + [ + IntegerRef("rows", 1, BINDINGS["max_matrix_size"]), + IntegerRef("cols", 1, BINDINGS["max_matrix_size"]), + IntegerRefMF("numbers", 0, CORE["numbers_max"]), + Choice("big", {CORE["capitals_prefix"]: True}, default=False), + Choice("greek_letter", BINDINGS["greek_letters"]), + Choice("units", BINDINGS["units"]), + Choice("symbol", BINDINGS["tex_symbols"]), + Choice("accent", BINDINGS["accents"]), + Choice("misc_sn_keys", BINDINGS["misc_sn_keys"]), + Choice("misc_sn_text", BINDINGS["misc_sn_text"]), + Choice("denominator", BINDINGS["denominators"]), + ], +) + + +Breathe.add_commands( + AppContext(executable="scientific notebook"), + { "[] integral from to ": - [Function(lambda: texchar("int")) + Key("c-l"), - Key("right, c-h"), Key("right")], + Exec("before") + TeX("int") + Key("c-l") + Exec("sequence1") + + Key("right, c-h") + Exec("sequence2") + Key("right"), "[] definite from to ": - [Key("c-6, right, c-l"), - Key("right, c-h"), Key("right, c-left, left")], + Exec("before") + Key("c-6, right, c-l") + Exec("sequence1") + + Key("right, c-h") + Exec("sequence2") + Key("right, c-left, left"), "[] differential by ": - [Key("c-f, d"), Key("down, d"), Key("right")], + Exec("before") + Key("c-f") + TeX("partial") + Exec("sequence1") + + Key("down") + TeX("partial") + Exec("sequence2") + Key("right"), "[] sum from to ": - [Key("f10, i, down:11, enter/25, a, enter, f10, i, down:11, enter/25, b, enter") + Function(lambda: texchar("sum")) + Key("down"), - Key("up:2"), Key("right")], + Exec("before") + Key("f10, i, down:11, enter/25, a, enter, f10, i, down:11, enter/25, b, enter") + + TeX("sum") + Key("down") + Exec("sequence1") + Key("up:2") + Exec("sequence2") + Key("right"), "[] limit from to ": - [Key("f10, i, down:11, enter/25, b, enter") + Function(lambda: texchar("lim")) + Key("down"), - Function(lambda: texchar("rightarrow")), - Key("right")], + Exec("before") + Key("f10, i, down:11, enter/25, b, enter") + + TeX("lim") + Key("down") + Exec("sequence1") + TeX("rightarrow") + + Exec("sequence2") + Key("right"), "[] argument that ": - [Key("f10, i, down:11, enter/25, b, enter") + Text("arg%(minmax)s") + Key("down"), - Key("right"), None], + Exec("before") + Key("f10, i, down:11, enter/25, b, enter") + + Text("arg%(minmax)s") + Key("down") + Exec("sequence1") + Key("right"), "[] by ": - [Key("f10, i, down:11, enter/25, b, enter") + Text("%(minmax)s") + Key("down"), - Key("right"), None], + Exec("before") + Key("f10, i, down:11, enter/25, b, enter") + + Text("%(minmax)s") + Key("down") + Exec("sequence1") + Key("right"), "[] []": - [Key("%(script1)s"), Key("right"), None], + Exec("before") + Key("%(script1)s") + Exec("singleton1") + Key("right") + Exec("after"), "[] []": - [Key("%(script1)s"), Key("right, %(script2)s"), Key("right")], - - } - extras = [ - Choice("minmax", { - "(minimum | minimises)": "min", - "(maximum | maximises)": "max", - }), - Choice("script1", { - "sub": "c-l", - "super": "c-h", - }), - Choice("script2", { - "sub": "c-l", - "super": "c-h", - }), - ] - -class sn_mathematicsNon(MergeRule): - mapping = { - "text ": - Key("c-t") + Function(lambda dict: Text(str(dict).capitalize()).execute()), - "": - Key("%(control)s"), - } - extras = [ - Dictation("dict"), - IntegerRef("n", 1, 10), - Choice("control", BINDINGS["control"]), - ] - - -class sn_mathematics(MergeRule): - non = sn_mathematicsNon - mwith = CORE["pronunciation"] - mcontext = AppContext(executable="scientific notebook") - pronunciation = BINDINGS["pronunciation"] - - nested = sn_nested - - mapping = { - BINDINGS["symbol_prefix"] + " ": - Function(texchar), - # - BINDINGS["greek_prefix"] + " [] ": - Function(greek), - BINDINGS["accent_prefix"] + " ": - Key("%(accent)s"), - - BINDINGS["unit_prefix"] + " ": - Alternating("units"), - - "": - Key("%(misc_sn_keys)s"), - "": - Text("%(misc_sn_text)s"), - - "matrix by ": - Function(matrix), - - " ": - Key("c-f") + Text("%(numbers)s") + Key("down") + Text("%(denominator)s") + Key("right"), - } - - extras = [ - IntegerRef("rows", 1, BINDINGS["max_matrix_size"]), - IntegerRef("cols", 1, BINDINGS["max_matrix_size"]), - IntegerRef("numbers", 0, CORE["numbers_max"]), - Choice("big", {CORE["capitals_prefix"]: True}), - Choice("greek_letter", BINDINGS["greek_letters"]), - Choice("units", BINDINGS["units"]), - Choice("symbol", BINDINGS["tex_symbols"]), - Choice("accent", BINDINGS["accents"]), - Choice("misc_sn_keys", BINDINGS["misc_sn_keys"]), - Choice("misc_sn_text", BINDINGS["misc_sn_text"]), - Choice("denominator", BINDINGS["denominators"]), - ] - - defaults = { - "big": False, - } - -control.nexus().merger.add_app_rule(sn_mathematics()) + Exec("before") + Key("%(script1)s") + Exec("singleton1") + + Key("right, %(script2)s") + Exec("singleton2") + Key("right") + Exec("after"), + }, + [ + Choice( + "minmax", {"(minimum | minimises)": "min", "(maximum | maximises)": "max"} + ), + Choice("script1", {"sub": "c-l", "super": "c-h"}), + Choice("script2", {"sub": "c-l", "super": "c-h"}), + CommandsRef("before", 8), + CommandsRef("after", 8), + CommandsRef("singleton1", 1), + CommandsRef("singleton2", 1), + CommandsRef("sequence1", 4), + CommandsRef("sequence2", 4), + ], + top_level=True, +) diff --git a/mathfly/ccr/alias.py b/mathfly/ccr/alias.py index cfb9ceb..031ef62 100644 --- a/mathfly/ccr/alias.py +++ b/mathfly/ccr/alias.py @@ -1,36 +1,40 @@ from mathfly.imports import * -MF_NEXUS = control.nexus() +aliases = DictList("aliases", utilities.load_toml_relative("config/aliases.toml")) -class Alias(SelfModifyingRule): - mapping = {"default command": ""} - key = "aliases" - pronunciation = "alias" +def add_alias(spec): + _, text = utilities.read_selected(True) + if text and spec: + aliases[str(spec)] = text + utilities.save_toml_relative(dict(aliases), "config/aliases.toml") - def delete_all(self, key): - utilities.save_toml_relative({}, "config/aliases.toml") - self.refresh() +def delete_aliases(): + aliases.clear() + utilities.save_toml_relative(dict(aliases), "config/aliases.toml") - def alias(self, spec): - spec = str(spec) - e, text = utilities.read_selected(True) - if spec and text: - self.refresh(spec, str(text)) +def delete_alias(alias): + for k, v in dict(aliases).items(): + if v == alias: + del aliases[k] + utilities.save_toml_relative(dict(aliases), "config/aliases.toml") + break - def refresh(self, *args): - '''args: spec, text''' - aliases = utilities.load_toml_relative("config/aliases.toml") - if not Alias.key in aliases: - aliases[Alias.key] = {} - if len(args) > 0: - aliases[Alias.key][args[0]] = args[1] - utilities.save_toml_relative(aliases, "config/aliases.toml") - mapping = {} - for spec in aliases[Alias.key]: - mapping[spec] = Function(utilities.paste_string, - content=str(aliases[Alias.key][spec])) - mapping["alias "] = Function(lambda s: self.alias(s)) - mapping["delete aliases"] = Function(self.delete_all, key=Alias.key) - self.reset(mapping) +Breathe.add_commands( + None, + { + "alias ": lambda text: add_alias(text), + "delete all aliases": delete_aliases, + }, + ccr=False +) -control.nexus().merger.add_selfmodrule(Alias()) +Breathe.add_commands( + None, + { + "delete alias ": delete_alias, + "": Text("%(alias)s") + }, + [ + DictListRef("alias", aliases), + ] +) \ No newline at end of file diff --git a/mathfly/ccr/core.py b/mathfly/ccr/core.py index 14a7e20..712ecce 100644 --- a/mathfly/ccr/core.py +++ b/mathfly/ccr/core.py @@ -5,8 +5,8 @@ ''' from mathfly.imports import * -SETTINGS = utilities.load_toml_relative("config/settings.toml") -CORE = utilities.load_toml_relative("config/core.toml") +SETTINGS = utilities.load_settings() +CORE = utilities.load_config("core.toml") _LETTERS, _DIRECTIONS = "letters", "directions" if SETTINGS["alternative_letters"]: @@ -15,38 +15,39 @@ _DIRECTIONS += "_alt" def alphabet(big, letter): - if big: - letter = letter.upper() - Key(letter).execute() + Key(letter.upper() if big else letter).execute() -class coreNon(MergeRule): +Breathe.add_commands( + context=None, mapping = { "configure " + CORE["pronunciation"]: - Function(utilities.load_config, config_name="core.toml"), + Function(utilities.edit_config, fname="core.toml"), "configure scientific notebook": - Function(utilities.load_config, config_name="ScientificNotebook55.toml"), + Function(utilities.edit_config, fname="ScientificNotebook55.toml"), "configure (LyX | licks)": - Function(utilities.load_config, config_name="lyx.toml"), + Function(utilities.edit_config, fname="lyx.toml"), + + "configure math fly [settings]": + Function(utilities.load_config, config_name="settings.toml"), + + "reboot dragon": Function(utilities.reboot), + + "math fly help": Function(utilities.help), " []": Key("%(noCCR_repeatable_key)s")*Repeat(extra="n"), "": Key("%(noCCR_non_repeatable_key)s"), - } + }, extras = [ - IntegerRef("n", 1, 10), Choice("noCCR_repeatable_key", CORE["noCCR_repeatable_keys"]), Choice("noCCR_non_repeatable_key", CORE["noCCR_non_repeatable_keys"]), - ] - defaults = { - "n": 1, - } - -class core(MergeRule): - non = coreNon - - pronunciation = CORE["pronunciation"] + ], + ccr=False +) +Breathe.add_commands( + context=None, mapping = { "[] ": Function(alphabet), @@ -67,31 +68,17 @@ class core(MergeRule): "shift click": Key("shift:down") + Mouse("left") + Key("shift:up"), - } - + }, extras = [ - Dictation("text"), - IntegerRef("n", 1, 10), - IntegerRef("n50", 1, 50), + IntegerRef("n50", 1, 50, 1), IntegerRefMF("numbers", 0, CORE["numbers_max"]), - Choice("big", {CORE["capitals_prefix"]: True}), + Choice("big", {CORE["capitals_prefix"]: True}, default=False), + Choice("extreme", {CORE["extreme"]: True}, default=False), Choice("letter", CORE[_LETTERS]), Choice("punctuation", CORE["punctuation"]), Choice("repeatable_key", CORE["repeatable_keys"]), Choice("non_repeatable_key", CORE["non_repeatable_keys"]), - Choice("direction", CORE[_DIRECTIONS]), - Choice("modifier", CORE["modifiers"]), - Choice("extreme", {CORE["extreme"]: True}), - ] - - defaults = { - "big" : False, - "extreme" : False, - "n" : 1, - "n50" : 1, - "direction": "left", - "modifier" : "", - } - - -control.nexus().merger.add_global_rule(core()) \ No newline at end of file + Choice("direction", CORE[_DIRECTIONS], default="left"), + Choice("modifier", CORE["modifiers"], default=""), + ], +) diff --git a/mathfly/ccr/global_extras.py b/mathfly/ccr/global_extras.py new file mode 100644 index 0000000..a8d84a1 --- /dev/null +++ b/mathfly/ccr/global_extras.py @@ -0,0 +1,6 @@ +from mathfly.imports import * + +Breathe.add_global_extras( + Dictation("text", default=""), + IntegerRef("n", 1, 20, 1) +) diff --git a/mathfly/ccr/latex.py b/mathfly/ccr/latex.py index 5e16a98..83032ca 100644 --- a/mathfly/ccr/latex.py +++ b/mathfly/ccr/latex.py @@ -4,10 +4,11 @@ ''' from mathfly.imports import * -BINDINGS = utilities.load_toml_relative("config/latex.toml") -CORE = utilities.load_toml_relative("config/core.toml") +BINDINGS = utilities.load_config("latex.toml") +CORE = utilities.load_config("core.toml") -class LaTeXNon(MergeRule): +Breathe.add_commands( + AppContext(title=BINDINGS["title_contexts"]) | CommandContext(BINDINGS["pronunciation"]), mapping = { "configure " + BINDINGS["pronunciation"]: Function(utilities.load_config, config_name="latex.toml"), @@ -16,11 +17,11 @@ class LaTeXNon(MergeRule): Function(tex_funcs.selection_to_bib, bib_path=BINDINGS["bibliography_path"]), "(open | edit) bibliography": - Function(utilities.load_text_file, path=BINDINGS["bibliography_path"]), + Function(utilities.edit_text_file, path=BINDINGS["bibliography_path"]), BINDINGS["template_prefix"] + "