OSDN Git Service

Format lists properly.
authorSimon Forman <sforman@hushmail.com>
Sun, 10 May 2020 19:46:33 +0000 (12:46 -0700)
committerSimon Forman <sforman@hushmail.com>
Sun, 10 May 2020 19:46:33 +0000 (12:46 -0700)
joy/gui/controllerlistbox.py
joy/utils/stack.py

index 745f8c0..e1b1a67 100644 (file)
@@ -20,7 +20,7 @@
 '''
 from Tkinter import Listbox, SINGLE
 from Tkdnd import dnd_start
-from joy.utils.stack import iter_stack, list_to_stack
+from joy.utils.stack import iter_stack, list_to_stack, expression_to_string
 
 
 class SourceWrapper:
@@ -135,7 +135,7 @@ class StackListbox(ControllerListbox):
 
     def _update(self):
         self.delete(0, 'end')
-        self.insert(0, *self.stack)
+        self.insert(0, *map(self.format, self.stack))
 
     def update_stack(self, stack):
         self.stack = list(iter_stack(stack))
@@ -145,3 +145,9 @@ class StackListbox(ControllerListbox):
         ControllerListbox.dnd_commit(self, source, event)
         self._update()
         self.world.stack = list_to_stack(self.stack)
+
+    @staticmethod
+    def format(item):
+        if isinstance(item, tuple):
+            return '[%s]' % expression_to_string(item)
+        return str(item)
index 34e4066..c04af32 100644 (file)
@@ -25,8 +25,8 @@ values from (at least) one end.
 
 There is no "Stack" Python class, instead we use the  `cons list`_, a 
 venerable two-tuple recursive sequence datastructure, where the
-empty tuple ``()`` is the empty stack and ``(head, rest)`` gives the recursive
-form of a stack with one or more items on it::
+empty tuple ``()`` is the empty stack and ``(head, rest)`` gives the
+recursive form of a stack with one or more items on it::
 
     stack := () | (item, stack)