Repository: biolab/orange3

Issue:
Unexpected autorun in the Python script widget
<!--
This is an issue template. Please fill in the relevant details in the
sections below.

Wrap code and verbatim terminal window output into triple backticks, see:
https://help.github.com/articles/basic-writing-and-formatting-syntax/#quoting-code

If you're raising an issue about an add-on (e.g. installed via
Options > Add-ons), raise an issue on the relevant add-on's issue
tracker instead. See: https://github.com/biolab?q=orange3
-->

##### Orange version
3.16


##### Expected behaviour
Python script in a Py script widget is run only when Run button is pushed 
since 'Autorun on new data' is unchecked


##### Actual behaviour
Python script (in a Py script widget) is run automatically after every modification in the wf


##### Steps to reproduce the behaviour
Make a wf with a File widget + Python script widget


##### Additional info (worksheets, data, screenshots, ...)





Discussion:

Resolving patch:
diff --git a/Orange/widgets/data/owpythonscript.py b/Orange/widgets/data/owpythonscript.py
--- a/Orange/widgets/data/owpythonscript.py
+++ b/Orange/widgets/data/owpythonscript.py
@@ -111,11 +111,10 @@ def lastLine(self):
         return text
 
     def keyPressEvent(self, event):
-        self.widget.enable_execute()
         if event.key() == Qt.Key_Return:
             if event.modifiers() & (
                     Qt.ShiftModifier | Qt.ControlModifier | Qt.MetaModifier):
-                self.widget.unconditional_commit()
+                self.widget.commit()
                 return
             text = self.lastLine()
             indent = len(text) - len(text.lstrip())
@@ -199,6 +198,7 @@ def raw_input(self, prompt):
     def new_prompt(self, prompt):
         self.write(prompt)
         self.newPromptPos = self.textCursor().position()
+        self.repaint()
 
     def write(self, data):
         cursor = QTextCursor(self.document())
@@ -393,7 +393,6 @@ class Outputs:
         Setting([Script("Hello world", "print('Hello world')\n")])
     currentScriptIndex = Setting(0)
     splitterState = Setting(None)
-    auto_execute = Setting(True)
 
     class Error(OWWidget.Error):
         pass
@@ -480,9 +479,7 @@ def __init__(self):
 
         self.controlBox.layout().addWidget(w)
 
-        auto = gui.auto_commit(self.controlArea, self, "auto_execute", "Run",
-                               checkbox_label="Autorun on new data")
-        self.execute_button, self.autobox = auto.button, auto.checkbox
+        self.execute_button = gui.button(self.controlArea, self, 'Run', callback=self.commit)
 
         self.splitCanvas = QSplitter(Qt.Vertical, self.mainArea)
         self.mainArea.layout().addWidget(self.splitCanvas)
@@ -524,9 +521,6 @@ def __init__(self):
         self.controlArea.layout().addStretch(1)
         self.resize(800, 600)
 
-    def enable_execute(self):
-        self.execute_button.setEnabled(True)
-
     def handle_input(self, obj, id, signal):
         id = id[0]
         dic = getattr(self, signal)
@@ -553,12 +547,12 @@ def set_object(self, data, id):
         self.handle_input(data, id, "object")
 
     def handleNewSignals(self):
-        self.unconditional_commit()
+        self.commit()
 
     def selectedScriptIndex(self):
         rows = self.libraryView.selectionModel().selectedRows()
         if rows:
-            return  [i.row() for i in rows][0]
+            return [i.row() for i in rows][0]
         else:
             return None
 
@@ -681,8 +675,6 @@ def initial_locals_state(self):
         return d
 
     def commit(self):
-        if self.auto_execute:
-            self.execute_button.setEnabled(False)
         self.Error.clear()
         self._script = str(self.text.toPlainText())
         lcls = self.initial_locals_state()


Test patch:
diff --git a/Orange/widgets/data/tests/test_owpythonscript.py b/Orange/widgets/data/tests/test_owpythonscript.py
--- a/Orange/widgets/data/tests/test_owpythonscript.py
+++ b/Orange/widgets/data/tests/test_owpythonscript.py
@@ -43,7 +43,6 @@ def test_outputs(self):
 
     def test_local_variable(self):
         """Check if variable remains in locals after removed from script"""
-        self.widget.autobox.setCheckState(False)
         self.widget.text.setPlainText("temp = 42\nprint(temp)")
         self.widget.execute_button.click()
         self.assertIn("42", self.widget.console.toPlainText())
@@ -57,7 +56,6 @@ def test_wrong_outputs(self):
         Error is shown when output variables are filled with wrong variable
         types and also output variable is set to None. (GH-2308)
         """
-        self.widget.autobox.setCheckState(False)
         self.assertEqual(len(self.widget.Error.active), 0)
         for signal, data in (
                 ("Data", self.iris),
@@ -80,7 +78,6 @@ def test_owns_errors(self):
         self.assertIsNot(self.widget.Error, OWWidget.Error)
 
     def test_multiple_signals(self):
-        self.widget.autobox.setCheckState(False)
         click = self.widget.execute_button.click
         console_locals = self.widget.console.locals