pd: la identacion no es, eso lo arreglo lo que tengo malo es que no sé como coño cambiar esa propiedad, aunque ya he tratado al revés, de que se llame desde la clase Ui_MainWindow al self.progreso_barra y nada. como le voy a hacer?
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
from PyQt4 import QtWebKit
import sys
import urllib2
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
#~ construccion de la ventana
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(463, 527)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("img/Icon_308.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
MainWindow.setStyleSheet(_fromUtf8("background-color: qlineargradient(spread:pad, x1:1, y1:1, x2:0, y2:0.908682, stop:0 rgba(255, 178, 102, 255), stop:0.572139 rgba(235, 148, 61, 255), stop:1 rgba(0, 0, 0, 255));"))
#~ centrar los objetos
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
#~ pagina web
self.webView = QtWebKit.QWebView(self.centralwidget)
self.webView.setUrl(QtCore.QUrl(_fromUtf8("http://www.google.com")))
self.webView.setObjectName(_fromUtf8("webView"))
self.verticalLayout.addWidget(self.webView)
#~ barra de progreso
self.progressBar = QtGui.QProgressBar(self.centralwidget)
self.progressBar.setProperty("value", 12)
self.progressBar.setObjectName(_fromUtf8("progressBar"))
self.verticalLayout.addWidget(self.progressBar)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
#acciones
QtCore.QObject.connect(self.progressBar, QtCore.SIGNAL(_fromUtf8("valueChanged(int)")), MainWindow.progreso_barra)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "Lanzador", None))
class Myform(QtGui.QMainWindow):
def __init__(self):
QtGui.QWidget.__init__(self)
#~ Ui_MainWindow.__init__(self)
self.ui2 = Ui_MainWindow()
self.t = self.ui2.setupUi(self)
self.progreso_barra()
def progreso_barra(self):
remote = r"http://quecorralavoz.zz.mu/download/mia.jpg"
local = r"c:\Python27\update1.jpg"
u = urllib2.urlopen(remote)
h = u.info()
totalSize = int(h["Content-Length"])
#print "Descargando %s bytes..." % totalSize,
fp = open(local, 'wb')
blockSize = 8192 #100000 # urllib.urlretrieve uses 8192
count = 0
while True:
chunk = u.read(blockSize)
if not chunk:
break
fp.write(chunk)
count += 1
if totalSize > 0:
percent = int(count * blockSize * 100 / totalSize)
if percent > 100:
percent = 100
print "%2d%%" % percent,
if percent < 100:
self.t.progressBar.setValue(percent)
#~ print "\b\b\b\b\b", # Erase "NN% "
else:
print "Done."
fp.flush()
fp.close()
if not totalSize:
print
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
myapp = Myform()
myapp.show()
sys.exit(app.exec_())