WebBrowser/WebBrowserPage.py

changeset 5784
362bbcc49ac1
parent 5780
79d06c98c5c9
child 5785
7c7c5f9e4fad
equal deleted inserted replaced
5783:44a9f08de394 5784:362bbcc49ac1
376 level, message, lineNumber, sourceId) 376 level, message, lineNumber, sourceId)
377 377
378 #################################################### 378 ####################################################
379 ## Methods below implement session related functions 379 ## Methods below implement session related functions
380 #################################################### 380 ####################################################
381 381 ##
382 def getSessionData(self): 382 ## def getSessionData(self):
383 """ 383 ## """
384 Public method to populate the session data. 384 ## Public method to populate the session data.
385 385 ##
386 @return dictionary containing the session data 386 ## @return dictionary containing the session data
387 @rtype dict 387 ## @rtype dict
388 """ 388 ## """
389 sessionData = {} 389 ## sessionData = {}
390 390 ##
391 # 1. zoom factor 391 ## # 1. zoom factor
392 sessionData["ZoomFactor"] = self.zoomFactor() 392 ## sessionData["ZoomFactor"] = self.zoomFactor()
393 393 ##
394 # 2. scroll position 394 ## # 2. scroll position
395 scrollPos = self.scrollPosition() 395 ## scrollPos = self.scrollPosition()
396 sessionData["ScrollPosition"] = { 396 ## sessionData["ScrollPosition"] = {
397 "x": scrollPos.x(), 397 ## "x": scrollPos.x(),
398 "y": scrollPos.y(), 398 ## "y": scrollPos.y(),
399 } 399 ## }
400 400 ##
401 # 3. page history 401 ## # 3. page history
402 historyArray = QByteArray() 402 ## historyArray = QByteArray()
403 stream = QDataStream(historyArray, QIODevice.WriteOnly) 403 ## stream = QDataStream(historyArray, QIODevice.WriteOnly)
404 stream << self.history() 404 ## stream << self.history()
405 sessionData["History"] = str( 405 ## sessionData["History"] = str(
406 historyArray.toBase64(QByteArray.Base64UrlEncoding), 406 ## historyArray.toBase64(QByteArray.Base64UrlEncoding),
407 encoding="ascii") 407 ## encoding="ascii")
408 sessionData["HistoryIndex"] = self.history().currentItemIndex() 408 ## sessionData["HistoryIndex"] = self.history().currentItemIndex()
409 409 ##
410 # 4. current URL 410 ## # 4. current URL
411 sessionData["Url"] = self.url().toString( 411 ## sessionData["Url"] = self.url().toString(
412 QUrl.PrettyDecoded | QUrl.RemovePassword) 412 ## QUrl.PrettyDecoded | QUrl.RemovePassword)
413 413 ##
414 return sessionData 414 ## return sessionData
415 415 ##
416 def loadFromSessionData(self, sessionData): 416 ## def loadFromSessionData(self, sessionData):
417 """ 417 ## """
418 Public method to load the session data. 418 ## Public method to load the session data.
419 419 ##
420 @param sessionData dictionary containing the session data as 420 ## @param sessionData dictionary containing the session data as
421 generated by getSessionData() 421 ## generated by getSessionData()
422 @type dict 422 ## @type dict
423 """ 423 ## """
424 # 1. page history 424 ## # 1. page history
425 if "History" in sessionData: 425 ## if "History" in sessionData:
426 historyArray = QByteArray.fromBase64( 426 ## historyArray = QByteArray.fromBase64(
427 sessionData["History"].encode("ascii"), 427 ## sessionData["History"].encode("ascii"),
428 QByteArray.Base64UrlEncoding) 428 ## QByteArray.Base64UrlEncoding)
429 stream = QDataStream(historyArray, QIODevice.ReadOnly) 429 ## stream = QDataStream(historyArray, QIODevice.ReadOnly)
430 stream >> self.history() 430 ## stream >> self.history()
431 431 ##
432 if "HistoryIndex" in sessionData: 432 ## if "HistoryIndex" in sessionData:
433 item = self.history().itemAt(sessionData["HistoryIndex"]) 433 ## item = self.history().itemAt(sessionData["HistoryIndex"])
434 if item is not None: 434 ## if item is not None:
435 self.history().goToItem(item) 435 ## self.history().goToItem(item)
436 436 ##
437 # 2. zoom factor 437 ## # 2. zoom factor
438 if "ZoomFactor" in sessionData: 438 ## if "ZoomFactor" in sessionData:
439 self.setZoomFactor(sessionData["ZoomFactor"]) 439 ## self.setZoomFactor(sessionData["ZoomFactor"])
440 440 ##
441 # 3. scroll position 441 ## # 3. scroll position
442 if "ScrollPosition" in sessionData: 442 ## if "ScrollPosition" in sessionData:
443 scrollPos = sessionData["ScrollPosition"] 443 ## scrollPos = sessionData["ScrollPosition"]
444 self.scrollTo(QPointF(scrollPos["x"], scrollPos["y"])) 444 ## self.scrollTo(QPointF(scrollPos["x"], scrollPos["y"]))
445 445
446 ################################################## 446 ##################################################
447 ## Methods below implement compatibility functions 447 ## Methods below implement compatibility functions
448 ################################################## 448 ##################################################
449 449

eric ide

mercurial