示例#1
0
def quote():
    e, text = utilities.read_selected(False)
    if text:
        Text("``" + text + "\'\'").execute()
    else:
        Text("``\'\'").execute()
        Key("left:2").execute()
示例#2
0
def symbol(symbol):
    if type(symbol) in [str, unicode, int]:
        Text("\\" + symbol + " ").execute()
    else:
        Text("\\" + str(symbol[0])).execute()
        Text("{}"*int(symbol[1])).execute()
        Key("left:" + str(2*int(symbol[1])-1)).execute()
示例#3
0
class sn_nested(NestedRule):
    mapping = {
        "[<before>] integral from <sequence1> to <sequence2>": [
            Function(lambda: texchar("int")) + Key("c-l"),
            Key("right, c-h"),
            Key("right")
        ],
        "[<before>] definite from <sequence1> to <sequence2>": [
            Key("c-6, right, c-l"),
            Key("right, c-h"),
            Key("right, c-left, left")
        ],
        "[<before>] differential <sequence1> by <sequence2>":
        [Key("c-f, d"), Key("down, d"),
         Key("right")],
        "[<before>] sum from <sequence1> to <sequence2>": [
            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")
        ],
        "[<before>] limit from <sequence1> to <sequence2>": [
            Key("f10, i, down:11, enter/25, b, enter") +
            Function(lambda: texchar("lim")) + Key("down"),
            Function(lambda: texchar("rightarrow")),
            Key("right")
        ],
        "[<before>] argument that <minmax> <sequence1>": [
            Key("f10, i, down:11, enter/25, b, enter") +
            Text("arg%(minmax)s") + Key("down"),
            Key("right"), None
        ],
        "[<before>] <minmax> by <sequence1>": [
            Key("f10, i, down:11, enter/25, b, enter") + Text("%(minmax)s") +
            Key("down"),
            Key("right"), None
        ],
        "[<before>] <script1> <singleton1> [<after>]":
        [Key("%(script1)s"), Key("right"), None],
        "[<before>] <script1> <singleton1> <script2> <singleton2> [<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",
        }),
    ]
示例#4
0
def paren_function(name, dl1="(", dl2=")"):
    e, text = utilities.read_selected(False)
    Text(name + dl1).execute()
    if text:
        utilities.paste_string(text)
        Text(dl2).execute()
    else:
        Text(dl2).execute()
        Key("left:" + str(len(dl2))).execute()
示例#5
0
def alternating_command(command):
    if type(command) in [str, int, unicode]:
        Text(str(command)).execute()
    elif type(command) in [list, tuple]:
        for i in range(len(command)):
            if i % 2 == 0:
                Text(command[i]).execute()
            else:
                Key(command[i]).execute()
示例#6
0
class TexmakerRule(MergeRule):
    pronunciation = "texmaker"

    mapping = {
        # file
        "new [file]": Key("c-n"),
        "open": Key("c-o"),
        "open recent": Key("a-f, down:3, right"),
        "close": Key("c-w"),
        "exit": Key("c-q"),
        "restore previous session": Key("cs-f8"),

        # edit
        "[go to] line <m>": Key("c-g") + Text("%(m)s") + Key("enter"),
        "comment": Key("c-t"),
        "uncomment": Key("c-u"),
        "indent": Key("c-rangle"),
        "(outdent | unindent)": Key("c-langle"),
        "find [<text>]": Key("c-f/5") + Text("%(text)s"),
        "find next [<n>]": Key("c-m") * Repeat(extra="n"),
        "replace": Key("c-r"),
        "check spelling": Key("cs-f7"),
        "refresh structure": Key("cs-f1"),

        # tools
        # if you have f1 set to turn on/off microphone, you will need to reset the Texmaker shortcut
        "quick build": Key("f1"),
        # "LaTeX": Key("f2"), # not sure what this does so I'm going to comment it out
        "view DVI": Key("f3"),
        "DVI to postscript": Key("f4"),
        "view postscript": Key("f5"),
        "PDF latex": Key("f6"),
        "view PDF": Key("f7"),
        "postscript to PDF": Key("f8"),
        "DVI to PDF": Key("f9"),
        "view log": Key("f10"),
        "bibtech": Key("f11"),
        "make index": Key("f12"),

        # view
        # Texmaker doesn't seem to have tabs unless I'm missing something
        "next (document | dock) [<n>]": Key("a-pgdown") * Repeat(extra='n'),
        "(previous | prior)  (document | dock)":
        Key("a-pgup") * Repeat(extra='n'),
        "full-screen": Key("cs-f11"),
        "switch pane":
        Key("c-space"),  # switch between editor and embedded viewer
    }

    extras = [
        Dictation("text"),
        IntegerRef("n", 1, 10),
        IntegerRef("m", 1, 1000),
    ]

    defaults = {}
示例#7
0
 def _execute(self, data=None):
     command = data[self.command]
     if type(command) in [str, int, unicode]:
         Text(str(command)).execute()
     elif type(command) in [list, tuple]:
         for i in range(len(command)):
             if i % 2 == 0:
                 Text(command[i]).execute()
             else:
                 Key(command[i]).execute()
示例#8
0
文件: core.py 项目: alexboche/mathfly
class core(MergeRule):
    non = coreNon

    pronunciation = CORE["pronunciation"]

    mapping = {
        "[<big>] <letter>":
        Function(alphabet),
        CORE["numbers_prefix"] + " <numbers>":
        Text("%(numbers)s"),
        "<punctuation>":
        Key("%(punctuation)s"),
        "(<direction> | <modifier> [<direction>]) [(<n50> | <extreme>)]":
        Function(navigation.text_nav),
        "<repeatable_key> [<n>]":
        Key("%(repeatable_key)s") * Repeat(extra="n"),
        "<non_repeatable_key>":
        Key("%(non_repeatable_key)s"),
        CORE["dictation_prefix"] + " <text>":
        Function(lambda text: Text(str(text).lower()).execute()),
        "shift click":
        Key("shift:down") + Mouse("left") + Key("shift:up"),
    }

    extras = [
        Dictation("text"),
        IntegerRef("n", 1, 10),
        IntegerRef("n50", 1, 50),
        IntegerRefMF("numbers", 0, CORE["numbers_max"]),
        Choice("big", {CORE["capitals_prefix"]: True}),
        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": "",
    }
示例#9
0
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"] + " <symbol>":
        Function(texchar),
        #
        BINDINGS["greek_prefix"] + " [<big>] <greek_letter>":
        Function(greek),
        BINDINGS["accent_prefix"] + " <accent>":
        Key("%(accent)s"),
        BINDINGS["unit_prefix"] + " <units>":
        Function(lambda units: execution.alternating_command(units)),
        "<misc_sn_keys>":
        Key("%(misc_sn_keys)s"),
        "<misc_sn_text>":
        Text("%(misc_sn_text)s"),
        "matrix <rows> by <cols>":
        Function(matrix),
        "<numbers> <denominator>":
        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,
    }
示例#10
0
class sn_mathematicsNon(MergeRule):
    mapping = {
        "text <dict>":
        Key("c-t") +
        Function(lambda dict: Text(str(dict).capitalize()).execute()),
        "<control>":
        Key("%(control)s"),
    }
    extras = [
        Dictation("dict"),
        IntegerRef("n", 1, 10),
        Choice("control", BINDINGS["control"]),
    ]
示例#11
0
def begin_end(environment):
    e, text = utilities.read_selected(False)
    if type(environment) in [str, unicode]:
        env, arg = environment, ""
    elif type(environment) in [tuple, list]:
        env, arg = environment[0], environment[1]
    back_curl("begin", env)
    Text(arg + "\n").execute()
    if text:
        utilities.paste_string(text)
    Key("enter").execute()
    back_curl("end", env)
    if not text:
        Key("up").execute()
示例#12
0
class LaTeX(MergeRule):
    non = LaTeXNon

    pronunciation = BINDINGS["pronunciation"]

    mapping = {
        "insert comment":
        Text("% "),
        BINDINGS["class_prefix"] + " [<doc_class>]":
        Function(
            lambda doc_class: tex_funcs.back_curl("documentclass", doc_class)),
        BINDINGS["environment_prefix"] + " <environment>":
        Function(tex_funcs.begin_end),
        "end <environment>":
        Function(lambda environment: tex_funcs.back_curl("end", environment)),
        #
        BINDINGS["package_prefix"] + " [<packopts>]":
        Function(tex_funcs.packages),
        #
        BINDINGS["symbol_prefix"] + " <symbol>":
        Function(tex_funcs.symbol),
        BINDINGS["symbol_prefix"] + " <misc_symbol>":
        Function(
            lambda misc_symbol: execution.alternating_command(misc_symbol)),
        "<latex_misc>":
        Function(lambda latex_misc: execution.alternating_command(latex_misc)),
        BINDINGS["accent_prefix"] + " <accent>":
        Function(
            lambda accent: execution.paren_function("\\" + accent, "{", "}")),
        BINDINGS["greek_prefix"] + " [<big>] <greek_letter>":
        Function(tex_funcs.greek_letters),
        #
        BINDINGS["command_prefix"] + " <command>":
        Function(lambda command: execution.paren_function(
            "\\" + command, "{", "}")),
        BINDINGS["command_prefix"] + " <commandnoarg>":
        Text("\\%(commandnoarg)s "),
        BINDINGS["command_prefix"] + " my (bib resource | bibliography)":
        Function(lambda: tex_funcs.back_curl("addbibresource", BINDINGS[
            "bibliography_path"])),
        BINDINGS["command_prefix"] + " quote":
        Function(tex_funcs.quote),
        #
    }

    extras = [
        Choice("big", {CORE["capitals_prefix"]: True}),
        Choice("packopts", BINDINGS["packages"]),
        Choice("doc_class", BINDINGS["document_classes"]),
        Choice("greek_letter", BINDINGS["greek_letters"]),
        Choice("symbol", BINDINGS["symbols"]),
        Choice("misc_symbol", BINDINGS["misc_symbols"]),
        Choice("latex_misc", BINDINGS["latex_misc"]),
        Choice("accent", BINDINGS["accents"]),
        Choice("commandnoarg", BINDINGS["commandnoarg"]),
        Choice("command", BINDINGS["command"]),
        Choice("environment", BINDINGS["environments"]),
    ]
    defaults = {
        "big": False,
        "packopts": "",
        "doc_class": "",
    }
示例#13
0
class SublimeRule(MergeRule):
    pronunciation = "sublime"

    mapping = {
        "new (file | pane)":
        Key("c-n"),
        # {"keys": ["ctrl+alt+n"], "command": "new_window"},
        "new window":
        Key("ca-n"),
        "open file":
        Key("c-o"),
        # {"keys": ["ctrl+shift+o"], "command": "prompt_add_folder"},
        "open folder":
        Key("cs-o"),
        "save as":
        Key("cs-s"),
        #
        "comment line":
        Key("c-slash"),
        "comment (block | lines)":
        Key("cs-slash"),
        "outdent lines":
        Key("c-lbracket"),
        "join lines [<n3>]":
        Key("c-j"),
        "match bracket":
        Key("c-m"),
        #
        # "(select | sell) all":  Key("c-a"),
        "(select | sell) scope [<n2>]":
        Key("cs-space"),
        "(select | sell) brackets [<n2>]":
        Key("cs-m"),
        "(select | sell) line [<n2>]":
        Key("c-l"),
        "(select | sell) indent":
        Key("cs-j"),
        # {"keys": ["ctrl+alt+p"], "command": "expand_selection_to_paragraph"},
        "(select | sell) paragraph":
        Key("ca-p"),
        # SelectUntil
        "(select | sell) until":
        Key("as-s"),
        "toggle side bar":
        Key("c-k, c-b"),

        #
        "find":
        Key("c-f"),
        "get all":
        Key("a-enter"),
        "replace":
        Key("c-h"),
        "edit lines":
        Key("cs-l"),
        "edit next [<n3>]":
        Key("c-d"),
        "edit skip next [<n3>]":
        Key("c-k, c-d"),
        "edit all":
        Key("c-d, a-f3"),
        #
        "transform upper":
        Key("c-k, c-u"),
        "transform lower":
        Key("c-k, c-l"),
        # {"keys": ["ctrl+k", "ctrl+t"], "command": "title_case"},
        "transform title":
        Key("c-k, c-t"),
        #
        "line <n11> [<n12>]":
        Key("c-g") + Text("%(n11)s" + "%(n12)s") + Key("enter"),
        "go to file":
        Key("c-p"),
        "go to word":
        Key("c-semicolon"),
        "go to symbol":
        Key("c-r"),
        "go to [symbol in] project":
        Key("cs-r"),
        "command pallette":
        Key("cs-p"),
        "(find | search) in (project | folder | directory)":
        Key("cs-f"),
        #
        "fold":
        Key("cs-lbracket"),
        "unfold":
        Key("cs-rbracket"),
        "unfold all":
        Key("c-k, c-j"),
        "fold [level] <n2>":
        Key("c-k, c-%(n2)s"),
        #
        "full screen":
        Key("f11"),
        "(set | add) bookmark":
        Key("c-f2"),
        "next bookmark":
        Key("f2"),
        "previous bookmark":
        Key("s-f2"),
        "clear bookmarks":
        Key("cs-f2"),
        #
        "build it":
        Key("c-b"),
        # "cancel build": Key("c-break")),
        #
        "record macro":
        Key("c-q"),
        "play [back] macro [<n3>]":
        Key("cs-q"),
        "(new | create) snippet":
        Key("a-n"),
        #
        "close tab":
        Key("c-w"),
        "next tab":
        Key("c-pgdown"),
        "previous tab":
        Key("c-pgup"),
        "<nth> tab":
        Key("a-%(n2)s"),
        #
        "column <cols>":
        Key("as-%(cols)s"),
        "focus <panel>":
        Key("c-%(panel)s"),
        "move <panel>":
        Key("cs-%(panel)s"),
        # {"keys": ["ctrl+alt+v"], "command": "clone_file"}
        "split right":
        Key("as-2, c-1, ca-v, cs-2"),
        #
        "open terminal":
        Key("cs-t"),
        "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),
        Choice(
            "nth", {
                "first": "1",
                "second": "2",
                "third": "3",
                "fourth": "4",
                "fifth": "5",
                "sixth": "6",
                "seventh": "7",
                "eighth": "8",
                "ninth": "9",
                "tenth": "10",
            }),
        Choice("cols", {
            "one": "1",
            "two": "2",
            "three": "3",
            "grid": "5",
        }),
        Choice("panel", {
            "one": "1",
            "left": "1",
            "two": "2",
            "right": "2",
        }),
    ]
    defaults = {
        "n12": "",
        "n2": 1,
        "n3": 1,
    }
示例#14
0
def back_curl(first, second):
    (Text("\\" + str(first)) + Key("lbrace, rbrace, left") + Text(
            str(second))).execute()
    if str(second) != "":
        Key("right").execute()
示例#15
0
def greek_letters(big, greek_letter):
    if big:
        greek_letter = greek_letter.title()
    Text("\\" + str(greek_letter) + " ").execute()