Exemplo n.º 1
0
class HtmlBrowser(QWidget):
    def __init__(self,parent=None):
        QWidget.__init__(self,parent)
        
        self.__toolBar = QToolBar(self)
        self.__toolBar.setIconSize(QSize(16,16))
        self.__htmlBrowserView = HtmlBrowserView(self)
        self.__addressinput = QLineEdit(self)
        self.__loadlabel = QLabel(self)

        layout=QVBoxLayout(self)
        layout.setSpacing(0)
        layout.setMargin(0)
        layout.addWidget(self.__toolBar)
        layout.addWidget(self.__htmlBrowserView)
        
        self.__setupToolBarAction()
        
        QObject.connect(self.__addressinput, SIGNAL("returnPressed ()"),self.__evt_load)
        QObject.connect(self.__htmlBrowserView, SIGNAL("loadFinished (bool)"),lambda:self.__loadlabel.setMovie(None))
        QObject.connect(self.__htmlBrowserView, SIGNAL("loadStarted ()"),self.__evt_loadstarted)


    def __evt_loadstarted(self):
        if  not self.__loadlabel.movie():
            movie = QMovie(getPath('iconDir','loading.gif'), QByteArray(), self.__loadlabel)
            movie.setSpeed(50)
            self.__loadlabel.setMovie(movie)
            movie.start()

    
    def __evt_load(self):
        self.__htmlBrowserView.load(QUrl(self.__addressinput.text()))
        
    def setHtml(self,html):
        self.__htmlBrowserView.setHtml(html)
        
    def webview(self):
        return self.__htmlBrowserView
    def __setupToolBarAction(self):
        
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["pre"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["next"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["stop"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["reload"])
        self.__toolBar.addWidget(self.__loadlabel)
        self.__toolBar.addWidget(self.__addressinput)
        
        action = QAction(QIcon(getPath('iconDir','heditor/go.png')),"go",self,triggered=self.__evt_load)
        
        self.__toolBar.addAction(action)

        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["zoomin"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["zoomreset"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["zoomout"])
Exemplo n.º 2
0
 def setMovie(self, movie):
     QLabel.setMovie(self, movie)
     s=movie.currentImage().size()
     self._movieWidth = s.width()
     self._movieHeight = s.height()