-
April 7th, 2016, 04:40 PM
#1
Refresh python window with this code?
How can i refresh this code every x minutes without having user interaction?
Code:
from PyQt4.QtCore import Qt, QTimer
from PyQt4.QtGui import QWidget, QApplication, QSplitter, QLabel, QVBoxLayout, QColor
import Adafruit_DHT
import urllib2
from wunderground import high_0
from BeautifulSoup import BeautifulSoup
sensor_args = { '11': Adafruit_DHT.DHT11,
'22': Adafruit_DHT.DHT22,
'2302': Adafruit_DHT.AM2302 }
humidity, temperature = Adafruit_DHT.read_retry(11, 4)
#dayname_1, dayname_2, conditions_0, conditions_1, winddir_0, winddir_1, high_0, low_0, high_1, low_1 =
temp = 'Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity)
soup = BeautifulSoup(urllib2.urlopen('http://partner.mlb.com/partnerxml/gen/news/rss/bos.xml').read())
title = soup.find('item').title
desc = soup.find('item').description
url = soup.find('item').guid
temperature = temperature * 9/5.0 + 32
class MyWidget(QWidget):
def __init__( self, parent = None ):
super(MyWidget, self).__init__(parent)
# create widgets
a = QLabel('Humidity:{:0.1f}%'.format(humidity),self )
a.setMinimumSize(100, 100)
b = QLabel('Hello World''\nTemperature:{:0.1f}F'.format(temperature),self )
b.setMinimumSize(100, 100)
c = QLabel("Redsox News \nTitle: %s\nSummary: %s " % (title.text, desc.text), self)
c.setWordWrap(True)
c.setMinimumSize(280, 200)
d = QLabel("Todays High:{:1}".format(high_0),self)
d.setWordWrap(True)
d.setMinimumSize(180, 300)
for lbl in (a, b, c, d):
lbl.setAlignment(Qt.AlignLeft)
# create 2 horizontal splitters
h_splitter1 = QSplitter(Qt.Horizontal, self)
h_splitter1.addWidget(a)
h_splitter1.addWidget(b)
h_splitter2 = QSplitter(Qt.Horizontal, self)
h_splitter2.addWidget(c)
h_splitter2.addWidget(d)
h_splitter1.splitterMoved.connect(self.moveSplitter)
h_splitter2.splitterMoved.connect(self.moveSplitter)
self._spltA = h_splitter1
self._spltB = h_splitter2
# create a vertical splitter
v_splitter = QSplitter(Qt.Vertical, self)
v_splitter.addWidget(h_splitter1)
v_splitter.addWidget(h_splitter2)
layout = QVBoxLayout()
layout.addWidget(v_splitter)
self.setLayout(layout)
#color widget code
palette = self.palette()
role = self.backgroundRole()
palette.setColor(role, QColor('black'))
self.setPalette(palette)
a.setStyleSheet("QLabel {color:yellow}")
b.setStyleSheet("QLabel {color:yellow}")
c.setStyleSheet("QLabel {background-color: black; color:white}")
d.setStyleSheet("QLabel {background-color: black; color:white}")
#self.setWindowFlags(Qt.CustomizeWindowHint)
def moveSplitter( self, index, pos ):
splt = self._spltA if self.sender() == self._spltB else self._spltB
splt.blockSignals(True)
#splt.moveSplitter(index, pos)
splt.blockSignals(False)
timer=QTimer()
timer.start(500)
timer.timeout.connect(temp.update)
def main():
app = QApplication(sys.argv)
widget = TicTacToe()
widget.show()
sys.exit(app.exec_())
if ( __name__ == '__main__' ):
app = QApplication([])
widget = MyWidget()
widget.show()
app.exec_()
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
-
June 1st, 2016, 01:40 AM
#2
Re: Refresh python window with this code?
Not ready with the answer. But interested in solving it. So referring Python 3 Programming Tutorial Guide.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|