这是我的解决方案,但我认为这不是一个好的解决方案。任何人都可以建议我新的解决方案,我想枚举窗口,并通过仅使用 python 的核心库而不是 wnck 或 pygtk 来比较 Title 属性...
def linux_CountWindowsByTitle(title):
import commands
XWinInfoOutput = commands.getoutput("xwininfo -all -root")
resArray = XWinInfoOutput.split("\n")
resRange = len(resArray) - 1
res = 0
#Parse each line of output
for i in range(0, resRange):
index = resArray[i].find("\"") #Get index of Double quote
if (index < 0):
continue #This line does not have title we need
tmp = resArray[i].split("\": (")[0] #Remove tail
windowName = tmp.split("\"",1)[1] #Remove head
if (UTILITY.Compare(title, windowName)):
#LIBRARY.Report(windowName)
res += 1
return res