Package: sagemath / 8.6-6

u1-ipywidgets-repr.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Description: Money-patch ipywidgets in the way that Sage upstream expects
 Sage upstream patches ipywidgets, but this is still being discussed
 upstream (see Bug below). In the meantime, we can have Sage monkey-patch
 ipywidgets at runtime, to prevent other users of ipywidgets being affected.
Author: Ximin Luo <infinity0@debian.org>
Author: Jeroen Demeyer <jdemeyer@cage.ugent.be>
Bug: https://github.com/jupyter-widgets/ipywidgets/pull/1031
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/sage/src/sage/repl/ipython_kernel/widgets.py
+++ b/sage/src/sage/repl/ipython_kernel/widgets.py
@@ -27,13 +27,42 @@
 from ipywidgets.widgets import (IntSlider, IntRangeSlider,
                                 FloatSlider, FloatRangeSlider, Text,
                                 Textarea, ColorPicker, HTML, Label,
-                                HBox, VBox, ValueWidget)
+                                HBox, VBox, ValueWidget, Widget)
 from traitlets import List, Unicode, link
 
 from sage.misc.sage_eval import sage_eval
 from sage.repl.user_globals import get_globals
 from sage.plot.colors import Color
 
+def __widgets__repr__(self):
+    """
+    Textual representation of this widget, mainly used for testing
+    and debugging.
+    """
+    # List of attributes to show with default values. The attribute
+    # is printed if it exists and its value is not equal to this
+    # default value.
+    attributes = [("value", None),
+                  ("min", None),
+                  ("max", None),
+                  ("step", None),
+                  ("options", None),
+                  ("description", ""),
+                  ("children", [])]
+    r = ""
+    for (attr, default) in attributes:
+        try:
+            v = getattr(self, attr)
+        except AttributeError:
+            continue
+        if default == v:
+            continue
+        if r:
+            r += ", "
+        r += attr + "=" + repr(v)
+    return "%s(%s)" % (type(self).__name__, r)
+Widget.__repr__ = __widgets__repr__
+del __widgets__repr__
 
 class HTMLText(HTML):
     """