Python中的Windows Balloon-tooltips

时间:2010-07-22 18:48:26

标签: python notifications popup-balloons

按照http://article.gmane.org/gmane.comp.python.general/541418的示例,我成功地为气球工具提示创建了一个可调用类,但在定制时,该代码的复杂性更大。我通过msdn浏览了一下它是如何工作的,但是对于像c和vb等更多像Windows一样的语言来说,我是一个新手。我无法理解它。

所以我问蛇学者:

除了标准图标,标题,文字之外,我还希望能够使用该代码:

  • 根据点击工具提示执行操作
  • 修改加载后弹出系统托盘中图标的工具提示(以反映更改的值)
  • 多行? (不确定是否可以这样做,真的)
  • 有关在Windows 7环境中可以执行的其他操作的更多信息,而不是XP(这似乎就是为此编写的)。

理想情况下,当点击工具提示时,我会获得某种返回值或某种事件的相似性,这样我就可以运行一些代码,但是目前我将该代码作为模块导入并在不同时间调用,所以我不确定如何处理弹出代码本身之外的点击......

使用python处理这些事情的信息似乎很少。提前谢谢。

2 个答案:

答案 0 :(得分:0)

  • 根据点击工具提示执行操作

问题是什么OnTaskbarNotify?把自己捅到那里。

  • 修改加载后弹出系统托盘中图标的工具提示(以反映更改的值)

可能不是,我不确定这里的WinAPI。我没有在野外看到它,所以......

  • 多行? (不确定是否可以这样做,真的)

对于大多数WinAPI,只需在字符串中插入\n

  • 有关在Windows 7环境中可以执行的其他操作的更多信息,而不是XP(这似乎就是为此编写的)。

很多......但这有点模糊......这取决于你的需求。但对于kol feturez,你需要自己谷歌...

答案 1 :(得分:0)

在Linux和Unix系统上,我使用已经实现的import os os.system('notify-send "'+title+'" "'+message+'") 操作系统。

import csv
import random
import math


def loadCSV(filename):
    with open(filename, 'rb') as lines:
        reader = csv.reader(lines)
        dataset = list(lines)
        for i in range(len(dataset)):
            dataset[i] = [float(x) for x in dataset[i]]
        return dataset


#filename = 'blood-primal.csv'
#dataset = loadCSV(filename)
#print(('Load data file {0} with {1} rows').format(filename, len(dataset))) 

def splitData(dataset, splitRatio):
    trainsize = int(len(dataset) * splitRatio)
    trainSet = []
    copy = list(dataset)
    while len(trainSet)< trainsize:
        index = random.randrange(len(copy))
        trainSet.append(copy.pop(index))
    return[trainSet, copy]

#dataset = [[1], [2], [3], [4], [5]]
#splitRatio = 0.67
#train, test = splitData(dataset, splitRatio)
#print(('Split {0} rows into train with {1} and test with    {2}').format(len(dataset), train, test))   

def sepByClass(dataset):
    separated={}
    for i in range(len(dataset)):
        vector = dataset[i]
        if (vector[-1] not in separated ):
            separated[vector[-1]]=[]
        separated[vector[-1]].append(vector)
    return separated

# dataset = [[1,20,1], [2,21,0], [3,22,1]]
# separated = sepByClass(dataset)
# print(('Separated instances: {0}').format(separated))


def mean(num):
    return sum(num)/float(len(num))

def stdev(num):
    avg = mean(num)
    variance = sum([pow(x-avg,2) for x in num])/float(len(num) -1)
    return math.sqrt(variance)

# num = [1,2,3,4,5]
# print (('Summary of {0}: mean = {1}, stdev={2}').format(num,    mean(num), stdev(num

def summarize(dataset):
    summaries = [(mean(attribute),stdev(attribute)) for attribute in    zip(*dataset)]
    del summaries[-1]
    return summaries

# dataset=[[1,20,0], [2,21,1], [3,22,0]]
# Summary = summarize(dataset)
# print(('attribute Summary: {0}').format(Summary))

def sumByClass(dataset):
    separated = sepByClass(dataset)
    summaries = {}
    for classValue, instances in separated.items():
        summaries[classValue]=summarize(instances)
    return summaries

#dataset = [[1,20,1],[2,21,0],[3,22,1],[4,22,0]]
#summary = sumByClass(dataset)
#print(('Summary by class value :{0}').format(summary))

def calcProb(dataset):
    exponent = math.exp(-(math.pow(x-mean,2)/(2*math.pow(stdev,2))))
    return(1/(math.sqrt(2*math.pi)* stdev)) * exponent

#x = 71.5
#mean = 73
#stdev = 6.2
#probability = calcProb(x)
#probability2 = calcProb(mean)
#probability3 = calcProb(stdev)
#print(('Probability of belonging to this class:{0} ///////{1} ///////{2}').format(probability, probability2, probability3))

def calcClassProb(summaries, inputVector):
    probabilities = {}
    for classValue, classSummaries in summaries.items():
        probabilities[classValue]= 1
        for i in range (len(classSummaries)):
            mean , stdev = classSummaries[i]
            x = inputVector[i]
            probabilities[classValue]*=calcProb(x, mean,stdev)
        return probabilities

summaries = {0:[(1, 0.5)], 1:[(20,5.0)]}
inputVector = [1.1, '?']
probabilities= calcClassProb(summaries, inputVector)

print = (('Probabilities for each class: {0}/////{1}: ').format(probabilities, probabilities2))

也许在Windows中有一些API32。

选中此https://gist.github.com/wontoncc/1808234