示例#1
0
    def rule_changer(self, enable, name):
        CORE = utilities.load_toml_relative("config/core.toml")

        self.merger.global_rule_changer(name=name, enable=enable, save=True)
        if name == CORE["pronunciation"]:
            self.merger.selfmod_rule_changer(name2="alias",
                                             enable=enable,
                                             save=True)
示例#2
0
def build(startup=False):
    SETTINGS = utilities.load_toml_relative("config/settings.toml")
    for word in SETTINGS["delete_words"]:
        try:
            natlink.deleteWord(word)
        except:
            pass
    MF_NEXUS.merger.wipe()
    MF_NEXUS.merger._global_rules = {}
    MF_NEXUS.merger._app_rules = {}
    MF_NEXUS.merger._self_modifying_rules = {}
    if startup:
        apploaded = []
        for module_name in SETTINGS["app_modules"]:
            try:
                lib = __import__("mathfly.apps." + module_name)
                apploaded.append(module_name)
            except Exception as e:
                print("Ignoring rule '{}'. Failed to load with: ".format(
                    module_name))
                print(e)
        if apploaded:
            print("App modules loaded: " + ", ".join(apploaded))
    ccrloaded = []
    ccrrebuilt = []
    for module_name in SETTINGS["ccr_modules"]:
        if "mathfly.ccr." + module_name in sys.modules:
            try:
                want_reload_module = sys.modules["mathfly.ccr." + module_name]
                reload(want_reload_module)
                ccrrebuilt.append(module_name)
            except Exception as e:
                print("Ignoring rule '{}'. Failed to load with: ".format(
                    module_name))
                print(e)
        else:
            try:
                lib = __import__("mathfly.ccr." + module_name)
                ccrloaded.append(module_name)
            except Exception as e:
                print("Ignoring rule '{}'. Failed to load with: ".format(
                    module_name))
                print(e)
    if ccrloaded:
        print("CCR modules loaded: " + ", ".join(ccrloaded))
    if ccrrebuilt:
        print("CCR modules rebuilt: " + ", ".join(ccrrebuilt))
    MF_NEXUS.merger.update_config()
    MF_NEXUS.merger.merge(MergeInf.BOOT)
    print("*- Starting mathfly -*")
    print("Modules available:")
    MF_NEXUS.merger.display_rules()
    print(
        "Say \"enable <module name>\" to begin, \n\"configure <module name>\" to make changes, \nand \"mathfly help\" to open the documentation"
    )
示例#3
0
 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 <s>"] = Function(lambda s: self.alias(s))
     mapping["delete aliases"] = Function(self.delete_all, key=Alias.key)
     self.reset(mapping)
示例#4
0
文件: core.py 项目: alexboche/mathfly
'''
Created on Sep 4, 2018

@author: Mike Roberts
'''
from dragonfly import Function, Choice, IntegerRef, Dictation, Repeat

from mathfly.lib.actions import Text, Key, Mouse
from mathfly.lib import control, utilities, navigation
from mathfly.lib.integers import IntegerRefMF
from mathfly.lib.merge.mergerule import MergeRule

SETTINGS = utilities.load_toml_relative("config/settings.toml")
CORE = utilities.load_toml_relative("config/core.toml")

_LETTERS, _DIRECTIONS = "letters", "directions"
if SETTINGS["alternative_letters"]:
    _LETTERS += "_alt"
if SETTINGS["alternative_directions"]:
    _DIRECTIONS += "_alt"


def alphabet(big, letter):
    if big:
        letter = letter.upper()
    Key(letter).execute()


class coreNon(MergeRule):
    mapping = {
        "configure " + CORE["pronunciation"]:
示例#5
0
'''
Created on Sep 4, 2018

@author: Mike Roberts
'''
from dragonfly import Function, Choice, Repeat, Clipboard

from mathfly.lib.actions import Text, Key, Mouse, AppContext
from mathfly.lib import control, utilities, execution
from mathfly.lib.merge.mergerule import MergeRule
from mathfly.lib.latex import tex_funcs

BINDINGS = utilities.load_toml_relative("config/latex.toml")
CORE = utilities.load_toml_relative("config/core.toml")


class LaTeXNon(MergeRule):
    mapping = {
        "configure " + BINDINGS["pronunciation"]:
        Function(utilities.load_config, config_name="latex.toml"),
        "add <ref_type> to bibliography":
        Function(tex_funcs.selection_to_bib,
                 bib_path=BINDINGS["bibliography_path"]),
        "(open | edit) bibliography":
        Function(utilities.load_text_file, path=BINDINGS["bibliography_path"]),
        BINDINGS["template_prefix"] + " <template>":
        Function(execution.template),
    }
    extras = [
        Choice("ref_type", {
            "book": "book",
示例#6
0
'''
Created on Sep 4, 2018

@author: Mike Roberts
'''
from dragonfly import Function, Choice, IntegerRef, Dictation, Repeat

from mathfly.lib.actions import Text, Key, Mouse, AppContext
from mathfly.lib import control, utilities, execution
from mathfly.lib.merge.mergerule import MergeRule
from mathfly.lib.merge.nestedrule import NestedRule

BINDINGS = utilities.load_toml_relative("config/ScientificNotebook55.toml")
CORE = utilities.load_toml_relative("config/core.toml")

#---------------------------------------------------------------------------


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()
示例#7
0
from dragonfly import (Function, Grammar, Text, Dictation, Choice, Pause)

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

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")

MF_NEXUS = control.nexus()
MF_NEXUS.build(True)


class MainRule(MergeRule):

    mapping = {
        "configure math fly [settings]":
        Function(utilities.load_config, config_name="settings.toml"),
        "<enable> <name>":
        Function(MF_NEXUS.rule_changer),
        "reboot dragon":
        Function(utilities.reboot),
        "rebuild math fly":
示例#8
0
'''
Created on Sep 4, 2018

@author: Mike Roberts
'''
from dragonfly import Function, Choice, Key, Text, Mouse, IntegerRef
from dragonfly import AppContext, Grammar, Repeat

from mathfly.lib import control, utilities
from mathfly.lib.merge.mergerule import MergeRule

BINDINGS = utilities.load_toml_relative("config/scientific_notebook.toml")
CORE = utilities.load_toml_relative("config/core.toml")


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()
示例#9
0
 def reload_settings(self):
     self.settings = utilities.load_toml_relative("config/settings.toml")