utils.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. # removes the last character from the argument string
  2. def remove_last_char(inp: str) -> str:
  3. return inp[:-1]
  4. # if the argument string represents an integer, returns its integer value
  5. def stoi(inp: str) -> int:
  6. return int(inp)
  7. # returns true if the argument string represents an integer, else false
  8. def is_numerical(inp: str) -> bool:
  9. try:
  10. int(inp)
  11. return True
  12. except ValueError:
  13. print("could not turn into int:", inp)
  14. return False
  15. def is_backspace(char):
  16. return char == "\b"
  17. def is_enter(char):
  18. return char == "\r" # Tkinter uses this symbol for 'enter' key press
  19. from sccd.action_lang.static.types import *
  20. SCCD_EXPORTS = {
  21. "remove_last_char": (remove_last_char, SCCDFunction([SCCDString], SCCDString)),
  22. "stoi": (stoi, SCCDFunction([SCCDString], SCCDInt)),
  23. "is_numerical": (is_numerical, SCCDFunction([SCCDString], SCCDBool)),
  24. "is_backspace": (is_backspace, SCCDFunction([SCCDString], SCCDBool)),
  25. "is_enter": (is_enter, SCCDFunction([SCCDString], SCCDBool)),
  26. }