Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions _mathfly_main.py
Original file line number Diff line number Diff line change
@@ -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

"<enable> <name>": 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()
del os.environ['BREATHE_REBUILD_COMMAND']
20 changes: 8 additions & 12 deletions mathfly/apps/app_template.py
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -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",
Expand All @@ -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
)
28 changes: 11 additions & 17 deletions mathfly/apps/sublime.py
Original file line number Diff line number Diff line change
@@ -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"},
Expand Down Expand Up @@ -86,13 +84,12 @@ class SublimeRule(MergeRule):

"zoom in [<n2>]": Key("c-equal")*Repeat(extra="n2"),
"zoom out [<n2>]": 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",
Expand All @@ -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())
},
ccr=False
)
23 changes: 8 additions & 15 deletions mathfly/apps/sumatrapdf.py
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -18,7 +16,7 @@ class SumatraPDFRule(MergeRule):
"find" : Key("c-f"),
"find next" : Key("f3"),
"find previous" : Key("s-f3"),
"page <n>" : Key("c-g") + Text("%(n)s") + Key("enter"),
"page <n1000>" : Key("c-g") + Text("%(n1000)s") + Key("enter"),
"table of contents" : Key("f12"),

"zoom in" : Key("c-equals"),
Expand All @@ -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",
Expand All @@ -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
)
20 changes: 5 additions & 15 deletions mathfly/apps/wordpad.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
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"),
"print file" : Key("c-p"),

"page down [<n>]" : Key("c-pagedown:%(n)s"),
"page up [<n>]" : Key("c-pageup:%(n)s"),
}

extras = [
IntegerRef("n", 1, 1000),
]

defaults = {
"n": 1,
}

control.nexus().merger.add_non_ccr_app_rule(WordPadRule())
},
ccr=False
)
Loading