@@ -257,6 +257,40 @@ def __init__(self, index, parent=None):
257
257
layout .addWidget (self .advanced_button )
258
258
self .setLayout (layout )
259
259
260
+ def show_context_menu (self , position ):
261
+ menu = QMenu (self )
262
+
263
+ # Only show the "Add to list" UI element if the current node does not have children
264
+ index = self .tree .currentIndex ()
265
+ node = index .internalPointer ()
266
+ if not node .children :
267
+ add_to_list_action = QAction ("Add to list" , self )
268
+ add_to_list_action .triggered .connect (self .add_to_list )
269
+ menu .addAction (add_to_list_action )
270
+
271
+ # Display the context menu at the position of the mouse click
272
+ global_position = self .tree .viewport ().mapToGlobal (position )
273
+ menu .exec_ (global_position )
274
+
275
+
276
+ def add_to_list (self ):
277
+ from larray_eurostat import eurostat_get
278
+ index = self .tree .currentIndex ()
279
+ node = index .internalPointer ()
280
+
281
+ if not node .children : # should only work on leaf nodes
282
+ # custom tree model where each node was represented by tuple (name, code,...) => data[1] = code
283
+ code = self .tree .currentIndex ().internalPointer ().data [1 ]
284
+ arr = eurostat_get (code , cache_dir = '__array_cache__' )
285
+
286
+ # Add indicator to the list
287
+ editor = self .parent ()
288
+ new_data = editor .data .copy ()
289
+ new_data [code ] = arr
290
+ editor .update_mapping (new_data )
291
+ editor .kernel .shell .user_ns [code ] = arr
292
+
293
+
260
294
def view_eurostat_indicator (self , index ):
261
295
from larray_eurostat import eurostat_get
262
296
0 commit comments