9 |
9 |
10 |
10 |
11 import os |
11 import os |
12 import json |
12 import json |
13 |
13 |
14 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QObject, QTimer, QDir, \ |
14 from PyQt5.QtCore import ( |
15 QFile, QFileInfo, QFileSystemWatcher, QByteArray, QDateTime |
15 pyqtSlot, pyqtSignal, Qt, QObject, QTimer, QDir, QFile, QFileInfo, |
16 from PyQt5.QtWidgets import QActionGroup, QApplication, \ |
16 QFileSystemWatcher, QByteArray, QDateTime |
17 QInputDialog, QLineEdit, QDialog, QDialogButtonBox, QLabel, QComboBox, \ |
17 ) |
18 QVBoxLayout |
18 from PyQt5.QtWidgets import ( |
|
19 QActionGroup, QApplication, QInputDialog, QLineEdit, QDialog, |
|
20 QDialogButtonBox, QLabel, QComboBox, QVBoxLayout |
|
21 ) |
19 |
22 |
20 from E5Gui import E5MessageBox |
23 from E5Gui import E5MessageBox |
21 |
24 |
22 import Utilities |
25 import Utilities |
23 import Preferences |
26 import Preferences |
78 self.__lastActiveSession = Preferences.getWebBrowser( |
81 self.__lastActiveSession = Preferences.getWebBrowser( |
79 "SessionLastActivePath") |
82 "SessionLastActivePath") |
80 if not QFile.exists(self.__lastActiveSession): |
83 if not QFile.exists(self.__lastActiveSession): |
81 self.__lastActiveSession = self.__sessionDefault |
84 self.__lastActiveSession = self.__sessionDefault |
82 |
85 |
83 self.__sessionsDirectoryWatcher = \ |
86 self.__sessionsDirectoryWatcher = QFileSystemWatcher( |
84 QFileSystemWatcher([self.getSessionsDirectory()], self) |
87 [self.getSessionsDirectory()], self) |
85 self.__sessionsDirectoryWatcher.directoryChanged.connect( |
88 self.__sessionsDirectoryWatcher.directoryChanged.connect( |
86 self.__sessionDirectoryChanged) |
89 self.__sessionDirectoryChanged) |
87 |
90 |
88 self.__backupSavedSession() |
91 self.__backupSavedSession() |
89 |
92 |
200 data["WindowGeometry"] = bytes(geometry.toBase64()).decode("ascii") |
203 data["WindowGeometry"] = bytes(geometry.toBase64()).decode("ascii") |
201 |
204 |
202 sessionData["Windows"].append(data) |
205 sessionData["Windows"].append(data) |
203 |
206 |
204 if window is activeWindow: |
207 if window is activeWindow: |
205 sessionData["CurrentWindowIndex"] = \ |
208 sessionData["CurrentWindowIndex"] = ( |
206 len(sessionData["Windows"]) - 1 |
209 len(sessionData["Windows"]) - 1 |
|
210 ) |
207 |
211 |
208 if sessionData["Windows"]: |
212 if sessionData["Windows"]: |
209 sessionFile = open(sessionFileName, "w") |
213 sessionFile = open(sessionFileName, "w") |
210 json.dump(sessionData, sessionFile, indent=2) |
214 json.dump(sessionData, sessionFile, indent=2) |
211 sessionFile.close() |
215 sessionFile.close() |
413 if win is not window: |
417 if win is not window: |
414 win.forceClose() |
418 win.forceClose() |
415 |
419 |
416 if not ((flags & SessionManager.ReplaceSession) == |
420 if not ((flags & SessionManager.ReplaceSession) == |
417 SessionManager.ReplaceSession): |
421 SessionManager.ReplaceSession): |
418 self.__lastActiveSession = \ |
422 self.__lastActiveSession = ( |
419 QFileInfo(sessionFilePath).canonicalFilePath() |
423 QFileInfo(sessionFilePath).canonicalFilePath() |
|
424 ) |
420 self.__sessionMetaData = [] |
425 self.__sessionMetaData = [] |
421 |
426 |
422 self.restoreSessionFromData(window, sessionData) |
427 self.restoreSessionFromData(window, sessionData) |
423 |
428 |
424 @classmethod |
429 @classmethod |
444 window.restoreGeometry(geometry) |
449 window.restoreGeometry(geometry) |
445 QApplication.processEvents() |
450 QApplication.processEvents() |
446 |
451 |
447 # restore additional windows |
452 # restore additional windows |
448 for data in sessionData["Windows"]: |
453 for data in sessionData["Windows"]: |
449 window = WebBrowserWindow.mainWindow()\ |
454 window = ( |
450 .newWindow(restoreSession=True) |
455 WebBrowserWindow.mainWindow().newWindow(restoreSession=True) |
|
456 ) |
451 window.tabWidget().loadFromSessionData(data) |
457 window.tabWidget().loadFromSessionData(data) |
452 if "WindowGeometry" in data: |
458 if "WindowGeometry" in data: |
453 geometry = QByteArray.fromBase64( |
459 geometry = QByteArray.fromBase64( |
454 data["WindowGeometry"].encode("ascii")) |
460 data["WindowGeometry"].encode("ascii")) |
455 window.restoreGeometry(geometry) |
461 window.restoreGeometry(geometry) |
457 QApplication.restoreOverrideCursor() |
463 QApplication.restoreOverrideCursor() |
458 |
464 |
459 if "CurrentWindowIndex" in sessionData: |
465 if "CurrentWindowIndex" in sessionData: |
460 currentWindowIndex = sessionData["CurrentWindowIndex"] |
466 currentWindowIndex = sessionData["CurrentWindowIndex"] |
461 try: |
467 try: |
462 currentWindow = \ |
468 currentWindow = ( |
463 WebBrowserWindow.mainWindows()[currentWindowIndex] |
469 WebBrowserWindow.mainWindows()[currentWindowIndex] |
|
470 ) |
464 QTimer.singleShot(0, lambda: currentWindow.raise_()) |
471 QTimer.singleShot(0, lambda: currentWindow.raise_()) |
465 except IndexError: |
472 except IndexError: |
466 # ignore it |
473 # ignore it |
467 pass |
474 pass |
468 |
475 |