Guest User

Untitled

a guest
May 30th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.39 KB | None | 0 0
  1. #
  2. # This file is part of Dragonfly.
  3. # (c) Copyright 2007, 2008 by Christo Butcher
  4. # Licensed under the LGPL.
  5. #
  6. #   Dragonfly is free software: you can redistribute it and/or modify it
  7. #   under the terms of the GNU Lesser General Public License as published
  8. #   by the Free Software Foundation, either version 3 of the License, or
  9. #   (at your option) any later version.
  10. #
  11. #   Dragonfly is distributed in the hope that it will be useful, but
  12. #   WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. #   Lesser General Public License for more details.
  15. #
  16. #   You should have received a copy of the GNU Lesser General Public
  17. #   License along with Dragonfly.  If not, see
  18. #   <http://www.gnu.org/licenses/>.
  19. #
  20. # file based on modified https://github.com/t4ngo/dragonfly-modules/blob/master/command-modules/notepad_example.py
  21.  
  22. """
  23.    This module is a simple example of Dragonfly use.
  24.  
  25.    It shows how to use Dragonfly's Grammar, AppContext, and MappingRule
  26.    classes.  This module can be activated in the same way as other
  27.    Natlink macros by placing it in the "My Documents\Natlink folder" or
  28.    "Program Files\NetLink/MacroSystem".
  29.  
  30. """
  31. print("vscode grammar loaded")
  32. from dragonfly import (Grammar, AppContext, MappingRule, Dictation,
  33.                        Key, Text, IntegerRef, Integer)
  34.  
  35.  
  36. grammar_context = AppContext(executable="code")
  37. grammar = Grammar("vscode", context=grammar_context)
  38.  
  39. #----------------------------------------------------------
  40. # general
  41. #----------------------------------------------------------
  42. general = MappingRule(
  43.     name="general",
  44.     mapping={
  45.              "palette":            Key("cs-p"),
  46.              "quick open":         Key("c-p"),
  47.              "open file":          Key("c-o"),
  48.              "new window":         Key("cs-n"),
  49.              "close window":       Key("cs-w"),
  50.              "open settings":      Key("c-comma"),
  51.             },
  52.     extras=[
  53.             Dictation("text"),
  54.            ],
  55.     )
  56. #----------------------------------------------------------
  57. # editing
  58. #----------------------------------------------------------
  59. editing = MappingRule(
  60.     name="editing",
  61.     mapping={
  62.              "cut":                 Key("c-x"),
  63.              "copy":                Key("c-c"),
  64.              "paste":               Key("c-v"),
  65.              "move line up":        Key("a-up"),
  66.              "move line down":      Key("a-down"),
  67.              "copy line up":        Key("sa-up"),
  68.              "copy line down":      Key("sa-down"),
  69.              "delete line":         Key("cs-k"),
  70.              "insert below":        Key("c-enter"),
  71.              "insert above":        Key("cs-enter"),
  72.              "jump bracket":        Key("cs-backslash"),
  73.              "indent":              Key("c-]"),
  74.              "outdent":             Key("c-["),
  75.              "home":                Key("home"),
  76.              "end":                 Key("end"),
  77.              "top":                 Key("c-home"),
  78.              "bottom":              Key("c-end"),
  79.              "line up":             Key("c-up"),
  80.              "line down":           Key("c-down"),
  81.              "scroll up":           Key("a-pgup"),
  82.              "scroll down":         Key("a-pgdown"),
  83.              "fold":                Key("cs-["),
  84.              "unfold":              Key("cs-]"),
  85.              "comment":             Key("c-slash"),
  86.              "block comment":       Key("sa-a"),
  87.             },
  88.     extras=[
  89.             Dictation("text"),
  90.            ],
  91.     )
  92. #----------------------------------------------------------
  93. # navigation
  94. #----------------------------------------------------------
  95. navigation = MappingRule(
  96.     name="navigation",
  97.     mapping={
  98.              "jump to <n>":       Key("c-g") + Text("%(n)d") + Key("enter"),
  99.              "go to <text>":      Key("c-p") + Text("%(text)s") + Key("enter"),
  100.             },
  101.     extras=[
  102.             IntegerRef("n", 1, 9999),
  103.             Integer("n", 1, 9999),
  104.             Dictation("text"),
  105.            ]
  106.     )
  107. #----------------------------------------------------------
  108. # search and replace
  109. #----------------------------------------------------------
  110. search = MappingRule(
  111.     name="search",
  112.     mapping={
  113.              "cut loop":            Key("c-x"),
  114.             },
  115.     extras=[
  116.             Dictation("text"),
  117.            ],
  118.     )
  119. #----------------------------------------------------------
  120. # multi-cursor and selection
  121. #----------------------------------------------------------
  122. cursor = MappingRule(
  123.     name="cursor-selection",
  124.     mapping={
  125.              "cut loop":            Key("c-x"),
  126.             },
  127.     extras=[
  128.             Dictation("text"),
  129.            ],
  130.     )
  131. #----------------------------------------------------------
  132. # Rich languages editing
  133. #----------------------------------------------------------
  134. richediting = MappingRule(
  135.     name="rich-editing",
  136.     mapping={
  137.              "cut loop":            Key("c-x"),
  138.             },
  139.     extras=[
  140.             Dictation("text"),
  141.            ],
  142.     )
  143. #----------------------------------------------------------
  144. # editor management
  145. #----------------------------------------------------------
  146. editor_management = MappingRule(
  147.     name="editor-management",
  148.     mapping={
  149.              "cut loop":            Key("c-x"),
  150.             },
  151.     extras=[
  152.             Dictation("text"),
  153.            ],
  154.     )
  155. #----------------------------------------------------------
  156. # file management
  157. #----------------------------------------------------------
  158. file_management = MappingRule(
  159.     name="file-management",
  160.     mapping={
  161.              "cut loop":            Key("c-x"),
  162.             },
  163.     extras=[
  164.             Dictation("text"),
  165.            ],
  166.     )
  167. #----------------------------------------------------------
  168. # display
  169. #----------------------------------------------------------
  170. display = MappingRule(
  171.     name="display",
  172.     mapping={
  173.              "cut loop":            Key("c-x"),
  174.             },
  175.     extras=[
  176.             Dictation("text"),
  177.            ],
  178.     )
  179. #----------------------------------------------------------
  180. # debug
  181. #----------------------------------------------------------
  182. debug = MappingRule(
  183.     name="debug",
  184.     mapping={
  185.              "cut loop":            Key("c-x"),
  186.             },
  187.     extras=[
  188.             Dictation("text"),
  189.            ],
  190.     )
  191. #----------------------------------------------------------
  192. # terminal
  193. #----------------------------------------------------------
  194. terminal = MappingRule(
  195.     name="terminal",
  196.     mapping={
  197.              "cut loop":            Key("c-x"),
  198.             },
  199.     extras=[
  200.             Dictation("text"),
  201.            ],
  202.     )
  203.  
  204. # Add the action rule to the grammar instance.
  205. grammar.add_rule(general)
  206. grammar.add_rule(editing)
  207. grammar.add_rule(navigation)
  208. grammar.add_rule(search)
  209. grammar.add_rule(cursor)
  210. grammar.add_rule(editing)
  211. grammar.add_rule(editor_management)
  212. grammar.add_rule(file_management)
  213. grammar.add_rule(display)
  214. grammar.add_rule(debug)
  215. grammar.add_rule(terminal)
  216.  
  217. #---------------------------------------------------------------------------
  218. # Load the grammar instance and define how to unload it.
  219.  
  220. grammar.load()
  221.  
  222. # Unload function which will be called by natlink at unload time.
  223. def unload():
  224.     global grammar
  225.     if grammar: grammar.unload()
  226.     grammar = None
Advertisement
Add Comment
Please, Sign In to add comment