eric7/Templates/TemplatesFile.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8318
962bce857696
child 8358
144a6b854f70
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
11 import time 11 import time
12 import typing 12 import typing
13 13
14 from PyQt6.QtCore import QObject 14 from PyQt6.QtCore import QObject
15 15
16 from E5Gui import E5MessageBox 16 from E5Gui import EricMessageBox
17 from E5Gui.E5OverrideCursor import E5OverridenCursor 17 from E5Gui.EricOverrideCursor import EricOverridenCursor
18 18
19 19
20 TemplateViewer = typing.TypeVar("TemplateViewer") 20 TemplateViewer = typing.TypeVar("TemplateViewer")
21 21
22 22
75 try: 75 try:
76 jsonString = json.dumps(templatesDict, indent=2) 76 jsonString = json.dumps(templatesDict, indent=2)
77 with open(filename, "w") as f: 77 with open(filename, "w") as f:
78 f.write(jsonString) 78 f.write(jsonString)
79 except (TypeError, OSError) as err: 79 except (TypeError, OSError) as err:
80 with E5OverridenCursor(): 80 with EricOverridenCursor():
81 E5MessageBox.critical( 81 EricMessageBox.critical(
82 None, 82 None,
83 self.tr("Save Templates"), 83 self.tr("Save Templates"),
84 self.tr( 84 self.tr(
85 "<p>The templates file <b>{0}</b> could not be" 85 "<p>The templates file <b>{0}</b> could not be"
86 " written.</p><p>Reason: {1}</p>" 86 " written.</p><p>Reason: {1}</p>"
102 try: 102 try:
103 with open(filename, "r") as f: 103 with open(filename, "r") as f:
104 jsonString = f.read() 104 jsonString = f.read()
105 templatesDict = json.loads(jsonString) 105 templatesDict = json.loads(jsonString)
106 except (OSError, json.JSONDecodeError) as err: 106 except (OSError, json.JSONDecodeError) as err:
107 E5MessageBox.critical( 107 EricMessageBox.critical(
108 None, 108 None,
109 self.tr("Read Templates"), 109 self.tr("Read Templates"),
110 self.tr( 110 self.tr(
111 "<p>The templates file <b>{0}</b> could not be read.</p>" 111 "<p>The templates file <b>{0}</b> could not be read.</p>"
112 "<p>Reason: {1}</p>" 112 "<p>Reason: {1}</p>"

eric ide

mercurial