| 1 |
from Base.Metadata import constmethod |
| 2 |
from Base.PyObjectBase import PyObjectBase |
| 3 |
from typing import Any, Dict, List, Optional |
| 4 |
|
| 5 |
class Command(PyObjectBase): |
| 6 |
""" |
| 7 |
FreeCAD Python wrapper of Command functions |
| 8 |
|
| 9 |
Author: Werner Mayer (wmayer[at]users.sourceforge.net) |
| 10 |
Licence: LGPL |
| 11 |
""" |
| 12 |
|
| 13 |
@staticmethod |
| 14 |
def get(name: str) -> Optional["Command"]: |
| 15 |
""" |
| 16 |
get(name) -> Gui.Command or None |
| 17 |
|
| 18 |
Get a given command by name or None if it doesn't exist. |
| 19 |
|
| 20 |
name : str |
| 21 |
Command name. |
| 22 |
""" |
| 23 |
... |
| 24 |
|
| 25 |
@staticmethod |
| 26 |
def update() -> None: |
| 27 |
""" |
| 28 |
update() -> None |
| 29 |
|
| 30 |
Update active status of all commands. |
| 31 |
""" |
| 32 |
... |
| 33 |
|
| 34 |
@staticmethod |
| 35 |
def listAll() -> List[str]: |
| 36 |
""" |
| 37 |
listAll() -> list of str |
| 38 |
|
| 39 |
Returns the name of all commands. |
| 40 |
""" |
| 41 |
... |
| 42 |
|
| 43 |
@staticmethod |
| 44 |
def listByShortcut(string: str, useRegExp: bool = False) -> List[str]: |
| 45 |
""" |
| 46 |
listByShortcut(string, useRegExp=False) -> list of str |
| 47 |
|
| 48 |
Returns a list of all commands, filtered by shortcut. |
| 49 |
Shortcuts are converted to uppercase and spaces removed |
| 50 |
prior to comparison. |
| 51 |
|
| 52 |
string : str |
| 53 |
Shortcut to be searched. |
| 54 |
useRegExp : bool |
| 55 |
Filter using regular expression. |
| 56 |
""" |
| 57 |
... |
| 58 |
|
| 59 |
def run(self, item: int = 0) -> None: |
| 60 |
""" |
| 61 |
run(item=0) -> None |
| 62 |
|
| 63 |
Runs the given command. |
| 64 |
|
| 65 |
item : int |
| 66 |
Item to be run. |
| 67 |
""" |
| 68 |
... |
| 69 |
|
| 70 |
@constmethod |
| 71 |
def isActive(self) -> bool: |
| 72 |
""" |
| 73 |
isActive() -> bool |
| 74 |
|
| 75 |
Returns True if the command is active, False otherwise. |
| 76 |
""" |
| 77 |
... |
| 78 |
|
| 79 |
def getShortcut(self) -> str: |
| 80 |
""" |
| 81 |
getShortcut() -> str |
| 82 |
|
| 83 |
Returns string representing shortcut key accelerator for command. |
| 84 |
""" |
| 85 |
... |
| 86 |
|
| 87 |
def setShortcut(self, string: str) -> bool: |
| 88 |
""" |
| 89 |
setShortcut(string) -> bool |
| 90 |
|
| 91 |
Sets shortcut for given command, returns True for success. |
| 92 |
|
| 93 |
string : str |
| 94 |
Shortcut to be set. |
| 95 |
""" |
| 96 |
... |
| 97 |
|
| 98 |
def resetShortcut(self) -> bool: |
| 99 |
""" |
| 100 |
resetShortcut() -> bool |
| 101 |
|
| 102 |
Resets shortcut for given command back to the default, returns True for success. |
| 103 |
""" |
| 104 |
... |
| 105 |
|
| 106 |
def getInfo(self) -> Dict[Any, Any]: |
| 107 |
""" |
| 108 |
getInfo() -> dict |
| 109 |
|
| 110 |
Return information about this command. |
| 111 |
""" |
| 112 |
... |
| 113 |
|
| 114 |
def getAction(self) -> List[Any]: |
| 115 |
""" |
| 116 |
getAction() -> list of QAction |
| 117 |
|
| 118 |
Return the associated QAction object. |
| 119 |
""" |
| 120 |
... |
| 121 |
|
| 122 |
@staticmethod |
| 123 |
def createCustomCommand( |
| 124 |
*, |
| 125 |
macroFile: str, |
| 126 |
menuText: str, |
| 127 |
toolTip: str, |
| 128 |
whatsThis: str, |
| 129 |
statusTip: str, |
| 130 |
pixmap: str, |
| 131 |
shortcut: str |
| 132 |
) -> str: |
| 133 |
""" |
| 134 |
createCustomCommand(macroFile, menuText, toolTip, whatsThis, statusTip, pixmap, shortcut) -> str |
| 135 |
|
| 136 |
Create a custom command for a macro. Returns name of the created command. |
| 137 |
|
| 138 |
macroFile : str |
| 139 |
Macro file. |
| 140 |
menuText : str |
| 141 |
Menu text. Optional. |
| 142 |
toolTip : str |
| 143 |
Tool tip text. Optional. |
| 144 |
whatsThis : str |
| 145 |
`What's this?` text. Optional. |
| 146 |
statusTip : str |
| 147 |
Status tip text. Optional. |
| 148 |
pixmap : str |
| 149 |
Pixmap name. Optional. |
| 150 |
shortcut : str |
| 151 |
Shortcut key sequence. Optional. |
| 152 |
""" |
| 153 |
... |
| 154 |
|
| 155 |
@staticmethod |
| 156 |
def removeCustomCommand(name: str) -> bool: |
| 157 |
""" |
| 158 |
removeCustomCommand(name) -> bool |
| 159 |
|
| 160 |
Remove the custom command if it exists. |
| 161 |
Given the name of a custom command, this removes that command. |
| 162 |
It is not an error to remove a non-existent command, the function |
| 163 |
simply does nothing in that case. |
| 164 |
Returns True if something was removed, or False if not. |
| 165 |
|
| 166 |
name : str |
| 167 |
Command name. |
| 168 |
""" |
| 169 |
... |
| 170 |
|
| 171 |
@staticmethod |
| 172 |
def findCustomCommand(name: str) -> Optional[str]: |
| 173 |
""" |
| 174 |
findCustomCommand(name) -> str or None |
| 175 |
|
| 176 |
Given the name of a macro, return the name of the custom command for that macro |
| 177 |
or None if there is no command matching that macro script name. |
| 178 |
|
| 179 |
name : str |
| 180 |
Macro name. |
| 181 |
""" |
| 182 |
... |