Par souci de concision: J'essaie d'implémenter this avec wxPython, mais j'ai du mal à intégrer ce code dans un script basé sur wxPython.wxPython et barre des tâches Windows 7
Mon code de test PyQt simple fonctionne correctement. Ici, il est:
from PyQt4 import QtGui
from threading import Thread
import time
import sys
import comtypes.client as cc
import comtypes.gen.TaskbarLib as tbl
TBPF_NOPROGRESS = 0
TBPF_INDETERMINATE = 0x1
TBPF_NORMAL = 0x2
TBPF_ERROR = 0x4
TBPF_PAUSED = 0x8
cc.GetModule("taskbar.tlb")
taskbar = cc.CreateObject("{56FDF344-FD6D-11d0-958A-006097C9A090}", interface=tbl.ITaskbarList3)
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setWindowTitle("Test")
self.progress_bar = QtGui.QProgressBar(self)
self.setCentralWidget(self.progress_bar)
self.progress_bar.setRange(0, 100)
self.progress = 0
self.show()
thread = Thread(target=self.counter)
thread.setDaemon(True)
thread.start()
def counter(self):
while True:
self.progress += 1
if self.progress > 100:
self.progress = 0
time.sleep(.2)
self.progress_bar.setValue(self.progress)
taskbar.HrInit()
hWnd = self.winId()
taskbar.SetProgressState(hWnd, TBPF_ERROR)
taskbar.SetProgressValue(hWnd, self.progress, 100)
app = QtGui.QApplication(sys.argv)
ui = MainWindow()
sys.exit(app.exec_())
Mais, lorsque je tente d'exécuter la contrepartie wxPython, la barre des tâches ne fonctionne pas comme prévu. Voici le code wxPython:
import wx
import time
import comtypes.client as cc
import comtypes.gen.TaskbarLib as tbl
from threading import Thread
TBPF_NOPROGRESS = 0
TBPF_INDETERMINATE = 0x1
TBPF_NORMAL = 0x2
TBPF_ERROR = 0x4
TBPF_PAUSED = 0x8
cc.GetModule("taskbar.tlb")
taskbar = cc.CreateObject("{56FDF344-FD6D-11d0-958A-006097C9A090}", interface=tbl.ITaskbarList3)
class MainWindow(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title)
self.panel = wx.Panel(self)
self.gauge = wx.Gauge(self.panel)
self.gauge.SetValue(0)
self.progress = 0
self.Show()
thread = Thread(target=self.counter)
thread.setDaemon(True)
thread.start()
def counter(self):
while True:
self.progress += 1
if self.progress > 100:
self.progress = 0
time.sleep(.2)
self.gauge.SetValue(self.progress)
taskbar.HrInit()
hWnd = self.GetHandle()
taskbar.SetProgressState(hWnd, TBPF_ERROR)
taskbar.SetProgressValue(hWnd, self.progress, 100)
app = wx.PySimpleApp()
frame = MainWindow(None, wx.ID_ANY, "Test")
app.SetTopWindow(frame)
app.MainLoop()
En particulier, je pense que la question est due à la méthode poignée de fenêtre wxWindow (hWnd), qui diffèrent de son équivalent Qt, l'ancien retournant un entier et celui-ci un « sip.voidptr objet". Le problème est que j'ai déjà écrit le code entier (1200+ lignes) avec wxPython, donc je ne peux pas le réécrire pour utiliser Qt (ne pas parler des différentes licences).
Qu'en pensez-vous? Devrais-je abandonner?
Merci beaucoup à l'avance :)
EDIT
Merci à Robert O'Connor, maintenant il fonctionne. Cependant, je n'arrive toujours pas à comprendre pourquoi GetHandle
renvoie un entier alors que winId
renvoie un objet. Dans le fichier .idl, l'argument hwnd est déclaré long
dans toutes les définitions de fonctions. Peut-être que c'est une question simple aussi;) Des idées?
PySide est le même que PyQT avec une meilleure licence ... – JBernardo
Merci, je vais le considérer dans le futur –