eric6/Sessions/SessionFile.py

Wed, 27 Jan 2021 15:09:20 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 27 Jan 2021 15:09:20 +0100
branch
jsonfiles
changeset 8009
29818ac4853c
child 8012
ecf45f723038
permissions
-rw-r--r--

Implemented the JSON based session files.

8009
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class representing the project debugger properties
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 JSON file.
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import json
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import time
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from PyQt5.QtCore import QObject
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui import E5MessageBox
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from E5Gui.E5OverrideCursor import E5OverridenCursor
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from E5Gui.E5Application import e5App
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import Preferences
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 class SessionFile(QObject):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Class representing the project debugger properties JSON file.
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 def __init__(self, isGlobal: bool, parent: QObject = None):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Constructor
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @param project reference to the project object
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @type Project
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param parent reference to the parent object
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @type QObject (optional)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 super(SessionFile, self).__init__(parent)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.__isGlobal = isGlobal
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 def writeFile(self, filename: str) -> bool:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Public method to write the project debugger properties data to a
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 project debugger properties JSON file.
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @param filename name of the user project file
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @type str
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @return flag indicating a successful write
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @rtype bool
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 # get references to objects we need
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 project = e5App().getObject("Project")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 projectBrowser = e5App().getObject("ProjectBrowser")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 multiProject = e5App().getObject("MultiProject")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 vm = e5App().getObject("ViewManager")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 dbg = e5App().getObject("DebugUI")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 dbs = e5App().getObject("DebugServer")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 name = os.path.splitext(os.path.basename(filename))[0]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 # prepare the session data dictionary
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 # step 0: header
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 sessionDict = {}
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 sessionDict["header"] = {}
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 if not self.__isGlobal:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 sessionDict["header"]["comment"] = (
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 f"eric session file for project {name}"
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 sessionDict["header"]["warning"] = (
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 "This file was generated automatically, do not edit."
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 # TODO: replace 'XMLTimestamp' by 'Timestamp'
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 if Preferences.getProject("XMLTimestamp") or self.__isGlobal:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 sessionDict["header"]["saved"] = (
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 time.strftime('%Y-%m-%d, %H:%M:%S')
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 # step 1: open multi project and project for global session
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 sessionDict["MultiProject"] = ""
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 sessionDict["Project"] = ""
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 if self.__isGlobal:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 if multiProject.isOpen():
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 sessionDict["MultiProject"] = (
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 multiProject.getMultiProjectFile()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 if project.isOpen():
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 sessionDict["Project"] = project.getProjectFile()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 # step 2: all open (project) filenames and the active editor
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 if vm.canSplit():
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 sessionDict["ViewManagerSplits"] = {
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 "Count": vm.splitCount(),
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 "Orientation": vm.getSplitOrientation(),
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 }
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 else:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 sessionDict["ViewManagerSplits"] = {
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 "Count": 0,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 "Orientation": 1,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 }
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 editorsDict = {} # remember editors by file name to detect clones
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 sessionDict["Editors"] = []
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 allOpenEditorLists = vm.getOpenEditorsForSession()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 for splitIndex, openEditorList in enumerate(allOpenEditorLists):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 for editorIndex, editor in enumerate(openEditorList):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 fileName = editor.getFileName()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if self.__isGlobal or project.isProjectFile(fileName):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 if fileName in editorsDict:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 isClone = editorsDict[fileName].isClone(editor)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 else:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 isClone = False
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 editorsDict[fileName] = editor
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 editorDict = {
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 "Filename": fileName,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 "Cursor": editor.getCursorPosition(),
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 "Folds": editor.contractedFolds(),
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 "Zoom": editor.getZoom(),
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 "Clone": isClone,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 "Splitindex": splitIndex,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 "Editorindex": editorIndex,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 }
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 sessionDict["Editors"].append(editorDict)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 aw = vm.getActiveName()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 sessionDict["ActiveWindow"] = {}
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 if aw and (self.__isGlobal or project.isProjectFile(aw)):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 ed = vm.getOpenEditor(aw)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 sessionDict["ActiveWindow"] = {
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 "Filename": aw,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 "Cursor": ed.getCursorPosition(),
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 }
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 # step 3: breakpoints
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 allBreaks = Preferences.getProject("SessionAllBreakpoints")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 projectFiles = project.getSources(True)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 bpModel = dbs.getBreakPointModel()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 if self.__isGlobal or allBreaks:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 sessionDict["Breakpoints"] = bpModel.getAllBreakpoints()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 else:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 sessionDict["Breakpoints"] = [
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 bp
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 for bp in bpModel.getAllBreakpoints()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 if bp[0] in projectFiles
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 ]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 # step 4: watch expressions
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 wpModel = dbs.getWatchPointModel()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 sessionDict["Watchpoints"] = wpModel.getAllWatchpoints()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 # step 5: debug info
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if self.__isGlobal:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 if len(dbg.argvHistory):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 dbgCmdline = dbg.argvHistory[0]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 else:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 dbgCmdline = ""
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 if len(dbg.wdHistory):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 dbgWd = dbg.wdHistory[0]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 else:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 dbgWd = ""
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 if len(dbg.envHistory):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 dbgEnv = dbg.envHistory[0]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 else:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 dbgEnv = ""
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 if len(dbg.multiprocessNoDebugHistory):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 dbgMultiprocessNoDebug = (
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 dbg.multiprocessNoDebugHistory[0]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 else:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 dbgMultiprocessNoDebug = ""
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 sessionDict["DebugInfo"] = {
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 "VirtualEnv": dbg.lastUsedVenvName,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 "CommandLine": dbgCmdline,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 "WorkingDirectory": dbgWd,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 "Environment": dbgEnv,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 "ReportExceptions": dbg.exceptions,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 "Exceptions": dbg.excList,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 "IgnoredExceptions": dbg.excIgnoreList,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 "AutoClearShell": dbg.autoClearShell,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 "TracePython": dbg.tracePython,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 "AutoContinue": dbg.autoContinue,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 "EnableMultiprocess": dbg.enableMultiprocess,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 "MultiprocessNoDebug": dbgMultiprocessNoDebug
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 }
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 else:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 sessionDict["DebugInfo"] = {
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 "VirtualEnv": project.dbgVirtualEnv,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 "CommandLine": project.dbgCmdline,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 "WorkingDirectory": project.dbgWd,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 "Environment": project.dbgEnv,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 "ReportExceptions": project.dbgReportExceptions,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 "Exceptions": project.dbgExcList,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 "IgnoredExceptions": project.dbgExcIgnoreList,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 "AutoClearShell": project.dbgAutoClearShell,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 "TracePython": project.dbgTracePython,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 "AutoContinue": project.dbgAutoContinue,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 "EnableMultiprocess": project.dbgEnableMultiprocess,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 "MultiprocessNoDebug": project.dbgMultiprocessNoDebug,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 }
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 # step 6: bookmarks
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 bookmarksList = []
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 for fileName in editorsDict:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 if self.__isGlobal or project.isProjectFile(fileName):
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 editor = editorsDict[fileName]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 bookmarks = editor.getBookmarks()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 if bookmarks:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 bookmarksList.append({
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 "Filename": fileName,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 "Lines": bookmarks,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 })
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 sessionDict["Bookmarks"] = bookmarksList
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 # step 7: state of the various project browsers
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 browsersList = []
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 for browserName in projectBrowser.getProjectBrowserNames():
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 expandedItems = (
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 projectBrowser.getProjectBrowser(browserName)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 .getExpandedItemNames()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 if expandedItems:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 browsersList.append({
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 "Name": browserName,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 "ExpandedItems": expandedItems,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 })
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 sessionDict["ProjectBrowserStates"] = browsersList
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 try:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 jsonString = json.dumps(sessionDict, indent=2)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 with open(filename, "w") as f:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 f.write(jsonString)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 except (TypeError, EnvironmentError) as err:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 with E5OverridenCursor():
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 E5MessageBox.critical(
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 None,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 self.tr("Save Session"),
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 self.tr(
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 "<p>The session file <b>{0}</b> could not be"
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 " written.</p><p>Reason: {1}</p>"
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 ).format(filename, str(err))
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 return False
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 return True
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 def readFile(self, filename: str) -> bool:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 Public method to read the session data from a session JSON file.
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 @param filename name of the project file
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 @type str
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 @return flag indicating a successful read
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 @rtype bool
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 """
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 try:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 with open(filename, "r") as f:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 jsonString = f.read()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 sessionDict = json.loads(jsonString)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 except (EnvironmentError, json.JSONDecodeError) as err:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 E5MessageBox.critical(
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 None,
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 self.tr("Read Debugger Properties"),
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 self.tr(
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 "<p>The project debugger properties file <b>{0}</b>"
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 " could not be read.</p><p>Reason: {1}</p>"
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 ).format(filename, str(err))
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 return False
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 # get references to objects we need
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 project = e5App().getObject("Project")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 projectBrowser = e5App().getObject("ProjectBrowser")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 multiProject = e5App().getObject("MultiProject")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 vm = e5App().getObject("ViewManager")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 dbg = e5App().getObject("DebugUI")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 dbs = e5App().getObject("DebugServer")
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 # step 1: multi project and project
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 if sessionDict["MultiProject"]:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 multiProject.openMultiProject(sessionDict["MultiProject"], False)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 if sessionDict["Project"]:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 project.openProject(sessionDict["Project"], False)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 # step 2: (project) filenames and the active editor
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 vm.setSplitOrientation(sessionDict["ViewManagerSplits"]["Orientation"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 vm.setSplitCount(sessionDict["ViewManagerSplits"]["Count"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 editorsDict = {}
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 for editorDict in sessionDict["Editors"]:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 if editorDict["Clone"] and editorDict["Filename"] in editorsDict:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 editor = editorsDict[editorDict["Filename"]]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 ed = vm.newEditorView(
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 editorDict["Filename"], editor, editor.getFileType(),
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 indexes=(editorDict["Splitindex"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 editorDict["Editorindex"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 else:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 ed = vm.openSourceFile(
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 editorDict["Filename"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 indexes=(editorDict["Splitindex"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 editorDict["Editorindex"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 editorsDict[editorDict["Filename"]] = ed
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 if ed is not None:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 ed.zoomTo(editorDict["Zoom"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 if editorDict["Folds"]:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 ed.recolor()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 ed.setContractedFolds(editorDict["Folds"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 ed.setCursorPosition(*editorDict["Cursor"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 # step 3: breakpoints
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 bpModel = dbs.getBreakPointModel()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 bpModel.addBreakPoints(sessionDict["Breakpoints"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 # step 4: watch expressions
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 wpModel = dbs.getWatchPointModel()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 wpModel.addWatchPoints(sessionDict["Watchpoints"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 # step 5: debug info
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 debugInfoDict = sessionDict["DebugInfo"]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 dbg.lastUsedVenvName = debugInfoDict["VirtualEnv"]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 dbg.setArgvHistory(debugInfoDict["CommandLine"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 dbg.setWdHistory(debugInfoDict["WorkingDirectory"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 dbg.setEnvHistory(debugInfoDict["Environment"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 dbg.setExceptionReporting(debugInfoDict["ReportExceptions"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 dbg.setExcList(debugInfoDict["Exceptions"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 dbg.setExcIgnoreList(debugInfoDict["IgnoredExceptions"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 dbg.setAutoClearShell(debugInfoDict["AutoClearShell"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 dbg.setTracePython(debugInfoDict["TracePython"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 dbg.setAutoContinue(debugInfoDict["AutoContinue"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 dbg.setEnableMultiprocess(debugInfoDict["EnableMultiprocess"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 dbg.setMultiprocessNoDebugHistory(debugInfoDict["MultiprocessNoDebug"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 if not self.__isGlobal:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 project.setDbgInfo(
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 debugInfoDict["VirtualEnv"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 debugInfoDict["CommandLine"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 debugInfoDict["WorkingDirectory"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 debugInfoDict["Environment"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 debugInfoDict["ReportExceptions"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 debugInfoDict["Exceptions"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 debugInfoDict["IgnoredExceptions"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 debugInfoDict["AutoClearShell"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 debugInfoDict["TracePython"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 debugInfoDict["AutoContinue"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 debugInfoDict["EnableMultiprocess"],
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 debugInfoDict["MultiprocessNoDebug"]
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 )
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 # step 6: bookmarks
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 for bookmark in sessionDict["Bookmarks"]:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 editor = vm.getOpenEditor(bookmark["Filename"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 if editor is not None:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 for lineno in bookmark["Lines"]:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 editor.toggleBookmark(lineno)
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 # step 7: state of the various project browsers
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 for browserState in sessionDict["ProjectBrowserStates"]:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 browser = projectBrowser.getProjectBrowser(browserState["Name"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 if browser is not None:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 browser.expandItemsByName(browserState["ExpandedItems"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 # step 8: active window
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 vm.openFiles(sessionDict["ActiveWindow"]["Filename"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 ed = vm.getOpenEditor(sessionDict["ActiveWindow"]["Filename"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 if ed is not None:
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 ed.setCursorPosition(*sessionDict["ActiveWindow"]["Cursor"])
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 ed.ensureCursorVisible()
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368
29818ac4853c Implemented the JSON based session files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 return True

eric ide

mercurial