code: def on_state_changed(self, state):
          
          if state:
              self.editor.painted.connect(self._paint_margins)
              self.editor.key_pressed.connect(self._on_key_pressed)
              self.editor.repaint()
          else:
              self.editor.painted.disconnect(self._paint_margins)
              self.editor.key_pressed.disconnect(self._on_key_pressed)
              self.editor.repaint()
docs: Connects/Disconnects to the painted event of the editor.
  
          :param state: Enable state