(self, buffer: Gtk.TextBuffer)
| 955 | return False |
| 956 | |
| 957 | def _on_src_text_changed(self, buffer: Gtk.TextBuffer): |
| 958 | if not self.provider["trans"]: |
| 959 | return |
| 960 | |
| 961 | char_count = buffer.get_char_count() |
| 962 | |
| 963 | # If the text is over the highest number of characters allowed, it is truncated. |
| 964 | # This is done for avoiding exceeding the limit imposed by translation services. |
| 965 | if self.provider["trans"].chars_limit == -1: # -1 means unlimited |
| 966 | self.char_counter.props.label = "" |
| 967 | else: |
| 968 | self.char_counter.props.label = f"{str(char_count)}/{self.provider['trans'].chars_limit}" |
| 969 | |
| 970 | if char_count >= self.provider["trans"].chars_limit: |
| 971 | self.send_notification(_("{} characters limit reached!").format(self.provider["trans"].chars_limit)) |
| 972 | buffer.delete(buffer.get_iter_at_offset(self.provider["trans"].chars_limit), buffer.get_end_iter()) |
| 973 | |
| 974 | sensitive = char_count != 0 |
| 975 | self.lookup_action("translation").props.enabled = sensitive # type: ignore |
| 976 | self.lookup_action("clear").props.enabled = sensitive # type: ignore |
| 977 | self._check_speech_enabled() |
| 978 | |
| 979 | def _on_dest_text_changed(self, buffer: Gtk.TextBuffer): |
| 980 | if not self.provider["trans"]: |
nothing calls this directly
no test coverage detected