Skip to content

Commit bd7db81

Browse files
committed
add method to get the plots_item
of a given variable in the ds_tree
1 parent 3649289 commit bd7db81

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

‎psyplot_gui/content_widget.py‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,22 @@ def add_variables(self, ds=None):
413413
self.add_attrs(variable.encoding, encoding_item)
414414
item.addChild(encoding_item)
415415

416-
def refresh_plots_item(self, item, vname):
416+
def get_plots_item(self, item):
417+
for child in map(item.child, range(item.childCount())):
418+
if child.text(0) == 'Plots':
419+
return child
420+
421+
def refresh_plots_item(self, item, vname, mp=None, sp=None):
417422
expand = item.isExpanded()
418423
item.takeChildren()
419424
try:
420425
num = self.ds().psy.num
421426
except AttributeError:
422427
return
423-
mp = gcp(True)
424-
sp = gcp()
428+
if mp is None:
429+
mp = gcp(True)
430+
if sp is None:
431+
sp = gcp()
425432
for i in range(len(mp)):
426433
sub = mp[i:i+1]
427434
array_info = sub.array_info(ds_description={'arr', 'num'})
@@ -471,10 +478,12 @@ def __init__(self, *args, **kwargs):
471478
Project.oncpchange.connect(self.add_datasets_from_cp)
472479
self.hideColumn(1)
473480

474-
def is_variable(self, item):
481+
@staticmethod
482+
def is_variable(item):
475483
return re.match(r'variables \(\d+\)', item.parent().text(0))
476484

477-
def is_coord(self, item):
485+
@staticmethod
486+
def is_coord(item):
478487
return re.match(r'coords\(\d+\)', item.parent().text(0))
479488

480489
def load_variable_desc(self, item):
@@ -610,7 +619,7 @@ def open_menu(self, pos):
610619

611620
# ---- add plot option
612621
if item_type == 'variable':
613-
add2p_action = QAction(f'Add {vname} to project', self)
622+
add2p_action = QAction(f'Add new plot of {vname}', self)
614623
add2p_action.setToolTip(self.tooltips['Add to project'])
615624
add2p_action.triggered.connect(lambda: self.make_plot(
616625
parent.ds(), item.text(0), True))

0 commit comments

Comments
 (0)