23
23
from idlelib .config import idleConf
24
24
from idlelib .textview import view_text
25
25
from idlelib .tooltip import Hovertip
26
+ from idlelib import macosx
26
27
27
28
28
29
def _add_to_rmenu (editwin , specs ):
@@ -122,15 +123,17 @@ def __init__(self, s, tags, numoflines, squeezer):
122
123
123
124
if self .squeezer .should_show_tooltip :
124
125
button_tooltip_text = (
125
- "Double-click to expand, middle-click to copy, " +
126
- "right-click to preview."
126
+ "Double-click to expand, right-click for more options."
127
127
)
128
128
Hovertip (self , button_tooltip_text ,
129
129
hover_delay = self .squeezer .tooltip_delay )
130
130
131
131
self .bind ("<Double-Button-1>" , self .expand )
132
- self .bind ("<Button-2>" , self .copy )
133
- self .bind ("<Button-3>" , self .preview )
132
+ if macosx .isAquaTk ():
133
+ # AquaTk defines <2> as the right button, not <3>.
134
+ self .bind ("<Button-2>" , self .context_menu_event )
135
+ else :
136
+ self .bind ("<Button-3>" , self .context_menu_event )
134
137
self .selection_handle (
135
138
lambda offset , length : s [int (offset ):int (offset ) + int (length )])
136
139
@@ -148,7 +151,7 @@ def set_is_dangerous(self):
148
151
)
149
152
)
150
153
151
- def expand (self , event ):
154
+ def expand (self , event = None ):
152
155
"""expand event handler
153
156
154
157
This inserts the original text in place of the button in the Text
@@ -177,21 +180,35 @@ def expand(self, event):
177
180
self .base_text .delete (self )
178
181
self .squeezer .expandingbuttons .remove (self )
179
182
180
- def copy (self , event ):
183
+ def copy (self , event = None ):
181
184
"""copy event handler
182
185
183
186
Copy the original text to the clipboard.
184
187
"""
185
188
self .clipboard_clear ()
186
189
self .clipboard_append (self .s )
187
190
188
- def preview (self , event ):
191
+ def preview (self , event = None ):
189
192
"""preview event handler
190
193
191
194
View the original text in a separate text viewer window.
192
195
"""
193
196
view_text (self .text , "Squeezed Output Viewer" , self .s , wrap = 'none' )
194
197
198
+ rmenu_specs = (
199
+ # item structure: (label, method_name)
200
+ ('copy' , 'copy' ),
201
+ ('preview' , 'preview' ),
202
+ )
203
+
204
+ def context_menu_event (self , event ):
205
+ self .text .mark_set ("insert" , "@%d,%d" % (event .x , event .y ))
206
+ rmenu = tk .Menu (self .text , tearoff = 0 )
207
+ for label , method_name in self .rmenu_specs :
208
+ rmenu .add_command (label = label , command = getattr (self , method_name ))
209
+ rmenu .tk_popup (event .x_root , event .y_root )
210
+ return "break"
211
+
195
212
196
213
class Squeezer :
197
214
"""Replace long outputs in the shell with a simple button.
0 commit comments