• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revision99fec6433bb1fa0c3518685e1d01ef721cb92a43 (tree)
Time2018-07-23 02:14:45
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

TEXT_BINDINGS stay in textwidget.py.

Change Summary

Incremental Difference

diff -r 1b71bc8986c4 -r 99fec6433bb1 joy/gui/main.py
--- a/joy/gui/main.py Sat Jul 21 20:19:38 2018 -0700
+++ b/joy/gui/main.py Sun Jul 22 10:14:45 2018 -0700
@@ -24,9 +24,10 @@
2424 filename=os.path.join(JOY_HOME, 'thun.log'),
2525 level=logging.INFO,
2626 )
27+_log.info('Starting with JOY_HOME=%s', JOY_HOME)
2728
2829
29-from joy.gui.textwidget import TextViewerWidget, tk, get_font, TEXT_BINDINGS
30+from joy.gui.textwidget import TextViewerWidget, tk, get_font
3031 from joy.gui.world import StackDisplayWorld
3132 from joy.library import initialize
3233 from joy.utils.stack import stack_to_string
@@ -41,16 +42,6 @@
4142 GLOBAL_COMMANDS = dict(cp.items('key bindings'))
4243
4344
44-tb = TEXT_BINDINGS.copy()
45-tb.update({
46- '<F3>': lambda tv: tv.copy_selection_to_stack,
47- '<Shift-F3>': lambda tv: tv.cut,
48- '<F4>': lambda tv: tv.copyto,
49- '<Shift-F4>': lambda tv: tv.pastecut,
50- })
51-defaults = dict(text_bindings=tb, width=80, height=25)
52-
53-
5445 def repo_relative_path(path):
5546 return os.path.relpath(
5647 path,
@@ -58,73 +49,71 @@
5849 )
5950
6051
61-def key_bindings(*args):
62- commands = [
63- 'Control-Enter - Run the selection as Joy code.',
64- 'F3 - Copy selection to stack.',
65- 'Shift-F3 - Cut selection to stack.',
66- 'F4 - Paste item on top of stack to insertion cursor.',
67- 'Shift-F4 - Pop and paste top of stack to insertion cursor.',
68- ]
69- for key, command in GLOBAL_COMMANDS.iteritems():
70- commands.append('%s - %s' % (key.strip('<>'), command))
71- print '\n'.join([''] + sorted(commands))
72- return args
52+def commands():
53+ # pylint: disable=unused-variable
54+
55+ def key_bindings(*args):
56+ commands = [ # These are bound in the TextViewerWidget.
57+ 'Control-Enter - Run the selection as Joy code, or if there\'s no selection the line containing the cursor.',
58+ 'F3 - Copy selection to stack.',
59+ 'Shift-F3 - Cut selection to stack.',
60+ 'F4 - Paste item on top of stack to insertion cursor.',
61+ 'Shift-F4 - Pop and paste top of stack to insertion cursor.',
62+ ]
63+ for key, command in GLOBAL_COMMANDS.iteritems():
64+ commands.append('%s - %s' % (key.lstrip('<').rstrip('>'), command))
65+ print '\n'.join([''] + sorted(commands))
66+ return args
7367
7468
75-def mouse_bindings(*args):
76- print dedent('''
77- Mouse button chords (to cancel a chord, click the third mouse button.)
78-
79- Left - Point, sweep selection
80- Left-Middle - Copy the selection, place text on stack
81- Left-Right - Run the selection as Joy code
69+ def mouse_bindings(*args):
70+ print dedent('''
71+ Mouse button chords (to cancel a chord, click the third mouse button.)
8272
83- Middle - Paste selection (bypass stack); click and drag to scroll.
84- Middle-Left - Paste from top of stack, preserve
85- Middle-Right - Paste from top of stack, pop
73+ Left - Point, sweep selection
74+ Left-Middle - Copy the selection, place text on stack
75+ Left-Right - Run the selection as Joy code
8676
87- Right - Execute command word under mouse cursor
88- Right-Left - Print docs of command word under mouse cursor
89- Right-Middle - Lookup word (kinda useless now)
90- ''')
91- return args
77+ Middle - Paste selection (bypass stack); click and drag to scroll.
78+ Middle-Left - Paste from top of stack, preserve
79+ Middle-Right - Paste from top of stack, pop
80+
81+ Right - Execute command word under mouse cursor
82+ Right-Left - Print docs of command word under mouse cursor
83+ Right-Middle - Lookup word (kinda useless now)
84+ ''')
85+ return args
9286
9387
94-def reset_log(*args):
95- log.delete('0.0', tk.END)
96- print __doc__
97- return args
88+ def reset_log(*args):
89+ log.delete('0.0', tk.END)
90+ print __doc__
91+ return args
9892
9993
100-def show_log(*args):
101- log_window.wm_deiconify()
102- log_window.update()
103- return args
94+ def show_log(*args):
95+ log_window.wm_deiconify()
96+ log_window.update()
97+ return args
10498
10599
106-def grand_reset(s, e, d):
107- stack = world.load_stack() or ()
108- log.reset()
109- t.reset()
110- return stack, e, d
100+ def grand_reset(s, e, d):
101+ stack = world.load_stack() or ()
102+ log.reset()
103+ t.reset()
104+ return stack, e, d
105+
106+ return locals()
111107
112108
113-_log.info('Starting.')
114109 STACK_FN = os.path.join(JOY_HOME, 'stack.pickle')
115110 REL_STACK_FN = repo_relative_path(STACK_FN)
116111 JOY_FN = os.path.join(JOY_HOME, 'scratch.txt')
117112 LOG_FN = os.path.join(JOY_HOME, 'log.txt')
118113 D = initialize()
119-for func in (
120- reset_log,
121- show_log,
122- grand_reset,
123- key_bindings,
124- mouse_bindings,
125- ):
126- D[func.__name__] = func
114+D.update(commands())
127115 world = StackDisplayWorld(repo, STACK_FN, REL_STACK_FN, dictionary=D)
116+defaults = dict(width=80, height=25)
128117 t = TextViewerWidget(world, **defaults)
129118 log_window = tk.Toplevel()
130119 log_window.protocol("WM_DELETE_WINDOW", log_window.withdraw)
@@ -133,8 +122,9 @@
133122 log.init('Log', LOG_FN, repo_relative_path(LOG_FN), repo, FONT)
134123 t.init('Joy - ' + JOY_HOME, JOY_FN, repo_relative_path(JOY_FN), repo, FONT)
135124 for event, command in GLOBAL_COMMANDS.items():
136- t.bind(event, lambda _, _command=command: world.interpret(_command))
137- log.bind(event, lambda _, _command=command: world.interpret(_command))
125+ callback = lambda _, _command=command: world.interpret(_command)
126+ t.bind(event, callback)
127+ log.bind(event, callback)
138128
139129
140130 def main():
diff -r 1b71bc8986c4 -r 99fec6433bb1 joy/gui/textwidget.py
--- a/joy/gui/textwidget.py Sat Jul 21 20:19:38 2018 -0700
+++ b/joy/gui/textwidget.py Sun Jul 22 10:14:45 2018 -0700
@@ -73,10 +73,14 @@
7373 TEXT_BINDINGS = {
7474
7575 #I want to ensure that these keyboard shortcuts work.
76+ '<Control-Return>': lambda tv: tv._control_enter,
7677 '<Control-v>': lambda tv: tv._paste,
7778 '<Control-V>': lambda tv: tv._paste,
79+ '<F3>': lambda tv: tv.copy_selection_to_stack,
80+ '<F4>': lambda tv: tv.copyto,
81+ '<Shift-F3>': lambda tv: tv.cut,
82+ '<Shift-F4>': lambda tv: tv.pastecut,
7883 '<Shift-Insert>': lambda tv: tv._paste,
79- '<Control-Return>': lambda tv: tv._control_enter,
8084 }
8185
8286
Show on old repository browser