def open_editor(self): """Open an external editor with the currently selected form field. The editor which should be launched can be configured via the `general -> editor` config option. // We use QProcess rather than subprocess here because it makes it a lot easier to execute some code as soon as the process has been finished and do everything async. """ frame = self._current_widget().page().currentFrame() try: elem = webelem.focus_elem(frame) except webelem.IsNullError: raise cmdexc.CommandError("No element focused!") if not elem.is_editable(strict=True): raise cmdexc.CommandError("Focused element is not editable!") if elem.is_content_editable(): text = str(elem) else: text = elem.evaluateJavaScript('this.value') self._editor = editor.ExternalEditor( self._win_id, self._tabbed_browser()) self._editor.editing_finished.connect( functools.partial(self.on_editing_finished, elem)) self._editor.edit(text)
def open_editor(self): """Open an external editor with the currently selected form field. The editor which should be launched can be configured via the `general -> editor` config option. // We use QProcess rather than subprocess here because it makes it a lot easier to execute some code as soon as the process has been finished and do everything async. """ frame = self._current_widget().page().currentFrame() try: elem = webelem.focus_elem(frame) except webelem.IsNullError: raise cmdexc.CommandError("No element focused!") if not elem.is_editable(strict=True): raise cmdexc.CommandError("Focused element is not editable!") if elem.is_content_editable(): text = str(elem) else: text = elem.evaluateJavaScript('this.value') self._editor = editor.ExternalEditor(self._win_id, self._tabbed_browser()) self._editor.editing_finished.connect( functools.partial(self.on_editing_finished, elem)) self._editor.edit(text)
def test_focus_element(stubs): """Test getting focus element with a fake frame/element. Testing this with a real webpage is almost impossible because the window and the element would have focus, which is hard to achieve consistently in a test. """ frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100)) elem = get_webelem() frame.focus_elem = elem._elem assert webelem.focus_elem(frame)._elem is elem._elem
def mouserelease_insertmode(self): """If we have an insertmode check scheduled, handle it.""" if not self._check_insertmode: return self._check_insertmode = False try: elem = webelem.focus_elem(self.page().currentFrame()) except webelem.IsNullError: log.mouse.warning("Element vanished!") return if elem.is_editable(): log.mouse.debug("Clicked editable element (delayed)!") modeman.maybe_enter(usertypes.KeyMode.insert, 'click-delayed') else: log.mouse.debug("Clicked non-editable element (delayed)!") if config.get('input', 'auto-leave-insert-mode'): modeman.maybe_leave(usertypes.KeyMode.insert, 'click-delayed')
def mouserelease_insertmode(self): """If we have an insertmode check scheduled, handle it.""" if not self._check_insertmode: return self._check_insertmode = False try: elem = webelem.focus_elem(self.page().currentFrame()) except (webelem.IsNullError, RuntimeError): log.mouse.debug("Element/page vanished!") return if elem.is_editable(): log.mouse.debug("Clicked editable element (delayed)!") modeman.enter(self.win_id, usertypes.KeyMode.insert, 'click-delayed', only_if_normal=True) else: log.mouse.debug("Clicked non-editable element (delayed)!") if config.get('input', 'auto-leave-insert-mode'): modeman.maybe_leave(self.win_id, usertypes.KeyMode.insert, 'click-delayed')