PDA

View Full Version : QTimer Not Firing, very strange...



enjoysmath
15th September 2015, 01:12
:cool:


from PyQt5.QtCore import QObject, QTimer, pyqtSignal
from urllib import request
import xml.etree.ElementTree as ET
from datetime import datetime, time

class SignalSource(QObject):
valuesChecked = pyqtSignal(dict)

def __init__(self, xmlUrl, timerIntervalMs=10):
QObject.__init__(self)
self.xmlUrl = xmlUrl
self.timer = QTimer()
self.timer.setInterval(timerIntervalMs)
self.timer.timeout.connect(self.timerFires)
self.timer.start()

self.sample = {}

def getSample(self, sourcePiece):
return self.sample[sourcePiece[0], sourcePiece[1]]

def timerFires(self):
response = request.urlopen(self.xmlUrl)
xmlStr = response.read()
root = ET.fromstring(xmlStr)

for child in root:
asset = child.attrib["Symbol"]
self.sample[asset] = {
"bid": float(child.find("Bid").text),
"ask": float(child.find("Ask").text),
"high": float(child.find("High").text),
"low": float(child.find("Low").text),
"@ last": time(child.find("Last").text),
"direction": int(child.find("Direction").text),
}
self.valuesChecked.emit(self.sample)



I simply call
signalSource = SignalSource("myXmlUrl")
inside the main debug module at module scope.

No timer firing action, so I never get to take a sample :'(

anda_skoa
15th September 2015, 10:14
Is the event loop running?

Cheers,
_

yeye_olive
15th September 2015, 10:16
What does your main program do after the line

signalSource = SignalSource("myXmlUrl")
? You need to run an event loop to receive timer events.