From 663753a7709873f8aab05de4979f50c10073a422 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sun, 10 May 2020 08:28:49 -0700 Subject: [PATCH] Connect it up. Inelegant but functional. --- joy/gui/controllerlistbox.py | 18 +++++++++++++++++- joy/gui/main.py | 13 +++++++++++-- joy/gui/world.py | 17 ++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/joy/gui/controllerlistbox.py b/joy/gui/controllerlistbox.py index ded20c2..a4068fd 100644 --- a/joy/gui/controllerlistbox.py +++ b/joy/gui/controllerlistbox.py @@ -20,6 +20,7 @@ ''' from Tkinter import Listbox, SINGLE from Tkdnd import dnd_start +from joy.utils.stack import list_to_stack class SourceWrapper: @@ -28,7 +29,7 @@ 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.) @@ -125,3 +126,18 @@ class ControllerListbox(DraggyListbox): 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) diff --git a/joy/gui/main.py b/joy/gui/main.py index 141bd56..8d5aa1f 100755 --- a/joy/gui/main.py +++ b/joy/gui/main.py @@ -47,7 +47,8 @@ _log.info('Starting with JOY_HOME=%s', JOY_HOME) # 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 @@ -142,7 +143,7 @@ D = initialize() 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) @@ -155,6 +156,14 @@ log = TextViewerWidget(world, log_window, **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) diff --git a/joy/gui/world.py b/joy/gui/world.py index 945bea2..dfc0360 100644 --- a/joy/gui/world.py +++ b/joy/gui/world.py @@ -29,7 +29,7 @@ from inspect import getdoc 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 @@ -152,3 +152,18 @@ class StackDisplayWorld(World): 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() +