Inelegant but functional.
'''
from Tkinter import Listbox, SINGLE
from Tkdnd import dnd_start
+from joy.utils.stack import list_to_stack
class SourceWrapper:
'''
def __init__(self, source, widget, index=None):
'''
- source is the object being dragged, widget is the container thats
+ source is the object being dragged, widget is the container that's
initialing the drag operation, and index s thu index of the item
in the widget's model object (which presumably is a ListModel
containing the source object.)
finally:
self.clear()
+
+class StackListbox(ControllerListbox):
+
+ def __init__(self, world, master=None, **kw):
+ ControllerListbox.__init__(self, master, **kw)
+ self.world = world
+
+ def _update(self):
+ self.delete(0, 'end')
+ self.insert(0, *self.stack)
+
+ def dnd_commit(self, source, event):
+ ControllerListbox.dnd_commit(self, source, event)
+ self._update()
+ self.world.stack = list_to_stack(self.stack)
# Now that logging is set up, continue loading the system.
from joy.gui.textwidget import TextViewerWidget, tk, get_font
-from joy.gui.world import StackDisplayWorld
+from joy.gui.world import StackWorld
+from joy.gui.controllerlistbox import StackListbox
from joy.library import initialize, DefinitionWrapper
from joy.utils.stack import stack_to_string
D.update(commands())
DefinitionWrapper.load_definitions(DEFS_FN, D)
-world = StackDisplayWorld(repo, STACK_FN, REL_STACK_FN, dictionary=D)
+world = StackWorld(repo, STACK_FN, REL_STACK_FN, dictionary=D)
t = TextViewerWidget(world, **VIEWER_DEFAULTS)
FONT = get_font('Iosevka', size=14) # Requires Tk root already set up.
+stack_window = tk.Toplevel()
+stack_window.title("Stack")
+stack_window.protocol("WM_DELETE_WINDOW", log_window.withdraw)
+stack_viewer = StackListbox(world, stack_window, items=[])
+stack_viewer.pack(expand=True, fill=tk.BOTH)
+world.set_viewer(stack_viewer)
+
+
log.init('Log', LOG_FN, repo_relative_path(LOG_FN), repo, FONT)
t.init('Joy - ' + JOY_HOME, JOY_FN, repo_relative_path(JOY_FN), repo, FONT)
from joy.joy import run
from joy.library import HELP_TEMPLATE
from joy.parser import Symbol
-from joy.utils.stack import stack_to_string
+from joy.utils.stack import iter_stack, stack_to_string
from joy.utils.types import type_check
from .utils import is_numerical
if os.path.exists(self.filename):
with open(self.filename, 'rb') as f:
return pickle.load(f)
+
+
+class StackWorld(StackDisplayWorld):
+
+ viewer = None
+
+ def set_viewer(self, viewer):
+ self.viewer = viewer
+
+ def print_stack(self):
+ StackDisplayWorld.print_stack(self)
+ if self.viewer:
+ self.viewer.stack = list(iter_stack(self.stack))
+ self.viewer._update()
+