I know how to show the attribute table of a specific layer (with showAttributeTable), but how to check if the attribute table of a specific layer is already opened ? I don't want to show it again if it's already visible.
Answer
You could use something like the following:
from PyQt4.QtGui import QApplication
attrTables = [d for d in QApplication.instance().allWidgets() if d.objectName() in (u'QgsAttributeTableDialog', u'AttributeTable')]
for x in attrTables:
if 'layerName' in x.windowTitle():
pass
else:
# do something
Edit:
As @Etienne mentioned in the comments, you could use the following for a more accurate method of obtaining the attribute table of a specific layer (assuming no layers have duplicate names):
from PyQt4.QtGui import QApplication
attrTables = [d for d in QApplication.instance().allWidgets() if d.objectName() in (u'QgsAttributeTableDialog', u'AttributeTable')]
for x in attrTables:
w_title = x.windowTitle()
tab_lyr = w_title[:w_title.index("::")-1]
if tab_lyr == 'layer_name':
# do something
No comments:
Post a Comment