Skip to content

Callbacks update

Compare
Choose a tag to compare
@Tim-ats-d Tim-ats-d released this 27 Apr 18:20
· 24 commits to main since this release

Callbacks update

Major changes

  • Python 3.8+ is now required to use Visual-dialog (due to improvements in typing hinting).

New features

Callback

Callback support has been completely redesigned.

  • Passing arguments via cargs to the callback is no longer possible.
  • Added the possibility to pass several callbacks to char_by_char and word_by_word.
    callback argument must now be an iterable of callables (argument has been renamed callbacks accordingly).
    It defaults to an empty tuple.
  • Several arguments are now passed to callbacks when they are executed:
    • For char_by_char method:
      • the instance of the class used (self), character written and index of the character in the current word being written.
    • For word_by_word method:
      • the instance of the class used (self) and word written.

See the implementation for more details.

API changes

  • The unit of the duration parameters (delay, downtime_chars_delay, and random_delay) is now milliseconds
    due to the use of curses.napms instead of time.sleep. Therefore, the values passed to these parameters
    must now be of type int and no longer of Union[int, float].
  • The error message of the PanicError exception is now more precise.
  • Import of all of each submodule when importing visualdialog.
  • BaseTextBox.confirm_dialog_keys is now defaults on [" "].
  • BaseTextBox.key_detection now accepts only a string. It can be "getkey", "getch", or "get_wch".
    These strings represent the name of the input capture methods of curses.

Renaming

In BaseTextBox and DialogBox:
  • Instance variable:

    • confirm_dialog_key to confirm_dialog_keys.
    • panic_key to panic_keys.
    • key_detection_mode to key_detection.
  • Method parameters:

    • cut_char parameter to word_delimiter in char_by_char and word_by_word.
    • callback parameter to callback in char_by_char and word_by_word.
  • Method name:

    • BaseTextBox.getkey method to BaseTextBox.get_input.
In submodules:
  • visualdialog.utils

    • TextAttributes context manager to TextAttr.
  • visualdialog.type

    • CursesKeyConstant and CursesKeyConstants to CursesKey and CursesKeys.

Bug fix

  • Fixed the bug that occurred when several key presses were recorded while scrolling the text in a dialog box.
    If n keystrokes had been registered, n text scrolling was passed without waiting for an input.