92 import UI.PixmapCache |
92 import UI.PixmapCache |
93 |
93 |
94 from E5XML.XMLUtilities import make_parser |
94 from E5XML.XMLUtilities import make_parser |
95 from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError |
95 from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError |
96 from E5XML.XMLEntityResolver import XMLEntityResolver |
96 from E5XML.XMLEntityResolver import XMLEntityResolver |
97 from E5XML.TasksHandler import TasksHandler |
97 from E5XML.TasksReader import TasksReader |
98 from E5XML.TasksWriter import TasksWriter |
98 from E5XML.TasksWriter import TasksWriter |
99 from E5XML.SessionWriter import SessionWriter |
99 from E5XML.SessionWriter import SessionWriter |
100 from E5XML.SessionHandler import SessionHandler |
100 from E5XML.SessionHandler import SessionHandler |
101 |
101 |
102 from E5Network.E5NetworkProxyFactory import E5NetworkProxyFactory, \ |
102 from E5Network.E5NetworkProxyFactory import E5NetworkProxyFactory, \ |
5044 |
5044 |
5045 def __readTasks(self): |
5045 def __readTasks(self): |
5046 """ |
5046 """ |
5047 Private slot to read in the tasks file (.e4t) |
5047 Private slot to read in the tasks file (.e4t) |
5048 """ |
5048 """ |
5049 try: |
5049 fn = os.path.join(Utilities.getConfigDir(), "eric5tasks.e4t") |
5050 fn = os.path.join(Utilities.getConfigDir(), "eric5tasks.e4t") |
5050 if not os.path.exists(fn): |
5051 if not os.path.exists(fn): |
5051 return |
5052 return |
5052 f = QFile(fn) |
5053 f = open(fn, "r", encoding = "utf-8") |
5053 if f.open(QIODevice.ReadOnly): |
5054 line = f.readline() |
5054 reader = TasksReader(f, viewer = self.taskViewer) |
5055 dtdLine = f.readline() |
5055 reader.readXML() |
5056 f.close() |
5056 else: |
5057 except IOError: |
|
5058 E5MessageBox.critical(self, |
5057 E5MessageBox.critical(self, |
5059 self.trUtf8("Read tasks"), |
5058 self.trUtf8("Read tasks"), |
5060 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>") |
5059 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>") |
5061 .format(fn)) |
5060 .format(fn)) |
5062 return |
|
5063 |
|
5064 # now read the file |
|
5065 if line.startswith('<?xml'): |
|
5066 parser = make_parser(dtdLine.startswith("<!DOCTYPE")) |
|
5067 handler = TasksHandler(taskViewer = self.taskViewer) |
|
5068 er = XMLEntityResolver() |
|
5069 eh = XMLErrorHandler() |
|
5070 |
|
5071 parser.setContentHandler(handler) |
|
5072 parser.setEntityResolver(er) |
|
5073 parser.setErrorHandler(eh) |
|
5074 |
|
5075 try: |
|
5076 f = open(fn, "r", encoding = "utf-8") |
|
5077 try: |
|
5078 try: |
|
5079 parser.parse(f) |
|
5080 except UnicodeEncodeError: |
|
5081 f.seek(0) |
|
5082 buf = io.StringIO(f.read()) |
|
5083 parser.parse(buf) |
|
5084 finally: |
|
5085 f.close() |
|
5086 except IOError: |
|
5087 E5MessageBox.critical(self, |
|
5088 self.trUtf8("Read tasks"), |
|
5089 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>")\ |
|
5090 .format(fn)) |
|
5091 return |
|
5092 except XMLFatalParseError: |
|
5093 pass |
|
5094 |
|
5095 eh.showParseMessages() |
|
5096 else: |
|
5097 E5MessageBox.critical(self, |
|
5098 self.trUtf8("Read tasks"), |
|
5099 self.trUtf8("<p>The tasks file <b>{0}</b> has an unsupported" |
|
5100 " format.</p>").format(fn)) |
|
5101 |
5061 |
5102 def __writeSession(self): |
5062 def __writeSession(self): |
5103 """ |
5063 """ |
5104 Private slot to write the session data to an XML file (.e4s). |
5064 Private slot to write the session data to an XML file (.e4s). |
5105 """ |
5065 """ |