--- a/WebBrowser/WebBrowserView.py Sat Mar 12 16:49:36 2016 +0100 +++ b/WebBrowser/WebBrowserView.py Sat Mar 12 17:02:04 2016 +0100 @@ -109,8 +109,6 @@ self.__currentZoom = 100 self.__zoomLevels = WebBrowserView.ZoomLevels[:] -## self.__mw.zoomTextOnlyChanged.connect(self.__applyZoom) - ## self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) ## self.linkClicked.connect(self.setSource) ## @@ -202,64 +200,64 @@ """ return self.__mw - def load(self, urlOrRequest): + def load(self, url): """ Public method to load a web site. - @param urlOrRequest URL or request object + @param url URL to be loaded @type QUrl or LoadRequest """ - if isinstance(urlOrRequest, QUrl): - super(WebBrowserView, self).load(urlOrRequest) - - if not self.__firstLoad: - self.__firstLoad = True - WebInspector.pushView(self) - elif isinstance(urlOrRequest, LoadRequest): - reqUrl = urlOrRequest.url() - if reqUrl.isEmpty(): - return - - if reqUrl.scheme() == "javascript": - script = reqUrl.toString()[11:] - # check if the javascript script is percent encode - # i.e. it contains '%' characters - if '%' in script: - script = QUrl.fromPercentEncoding( - QByteArray(script.encode("utf-8"))) - self.page().runJavaScript(script) - return - - if self.__isUrlValid(reqUrl): - self.loadRequest(urlOrRequest) - return - - # ensure proper loading of hosts without a '.' - if not reqUrl.isEmpty() and \ - reqUrl.scheme() and \ - not WebBrowserTools.containsSpace(reqUrl.path()) and \ - '.' not in reqUrl.path(): - u = QUrl("http://" + reqUrl.path()) - if u.isValid(): - info = QHostInfo.fromName(u.path()) - if info.error() == QHostInfo.NoError: - req = LoadRequest(urlOrRequest) - req.setUrl(u) - self.loadRequest(req) - return - - def loadRequest(self, req): - """ - Public method to load a page via a load request object. +## if isinstance(urlOrRequest, QUrl): + super(WebBrowserView, self).load(url) - @param req loaf request object - @type LoadRequest - """ - if req.Operation == LoadRequestOperations.GetOperation: - self.load(req.url()) - else: - self.page().runJavaScript( - Scripts.sendPostData(req.url(), req.data())) + if not self.__firstLoad: + self.__firstLoad = True + WebInspector.pushView(self) +## elif isinstance(urlOrRequest, LoadRequest): +## reqUrl = urlOrRequest.url() +## if reqUrl.isEmpty(): +## return +## +## if reqUrl.scheme() == "javascript": +## script = reqUrl.toString()[11:] +## # check if the javascript script is percent encode +## # i.e. it contains '%' characters +## if '%' in script: +## script = QUrl.fromPercentEncoding( +## QByteArray(script.encode("utf-8"))) +## self.page().runJavaScript(script) +## return +## +## if self.__isUrlValid(reqUrl): +## self.loadRequest(urlOrRequest) +## return +## +## # ensure proper loading of hosts without a '.' +## if not reqUrl.isEmpty() and \ +## reqUrl.scheme() and \ +## not WebBrowserTools.containsSpace(reqUrl.path()) and \ +## '.' not in reqUrl.path(): +## u = QUrl("http://" + reqUrl.path()) +## if u.isValid(): +## info = QHostInfo.fromName(u.path()) +## if info.error() == QHostInfo.NoError: +## req = LoadRequest(urlOrRequest) +## req.setUrl(u) +## self.loadRequest(req) +## return +## +## def loadRequest(self, req): +## """ +## Public method to load a page via a load request object. +## +## @param req loaf request object +## @type LoadRequest +## """ +## if req.Operation == LoadRequestOperations.GetOperation: +## self.load(req.url()) +## else: +## self.page().runJavaScript( +## Scripts.sendPostData(req.url(), req.data())) # TODO: eliminate requestData, add param to get rid of __ctrlPressed def setSource(self, name, requestData=None): @@ -466,12 +464,6 @@ break return index - def __applyZoom(self): - """ - Private slot to apply the current zoom factor. - """ - self.setZoomValue(self.__currentZoom) - def setZoomValue(self, value, saveValue=True): """ Public method to set the zoom value. @@ -504,8 +496,7 @@ """ index = self.__levelForZoom(self.__currentZoom) if index < len(self.__zoomLevels) - 1: - self.__currentZoom = self.__zoomLevels[index + 1] - self.__applyZoom() + self.setZoomValue(self.__zoomLevels[index + 1]) def zoomOut(self): """ @@ -513,16 +504,14 @@ """ index = self.__levelForZoom(self.__currentZoom) if index > 0: - self.__currentZoom = self.__zoomLevels[index - 1] - self.__applyZoom() + self.setZoomValue(self.__zoomLevels[index - 1]) def zoomReset(self): """ Public method to reset the zoom factor. """ index = self.__levelForZoom(WebBrowserView.ZoomLevelDefault) - self.__currentZoom = self.__zoomLevels[index] - self.__applyZoom() + self.setZoomValue(self.__zoomLevels[index]) def hasSelection(self): """ @@ -1409,8 +1398,7 @@ pinch.setScaleFactor(self.__currentZoom / 100.0) else: scaleFactor = pinch.scaleFactor() - self.__currentZoom = int(scaleFactor * 100) - self.__applyZoom() + self.setZoomValue(int(scaleFactor * 100)) evt.accept() def eventFilter(self, obj, evt):