UI/UserInterface.py

changeset 599
ee87fe94bf96
parent 595
7d2c8346021c
child 608
d8fea1e76975
equal deleted inserted replaced
598:76c36b6ebbdb 599:ee87fe94bf96
7 Module implementing the main user interface. 7 Module implementing the main user interface.
8 """ 8 """
9 9
10 import os 10 import os
11 import sys 11 import sys
12 import io
13 import logging 12 import logging
14 13
15 from PyQt4.QtCore import * 14 from PyQt4.QtCore import *
16 from PyQt4.QtGui import * 15 from PyQt4.QtGui import *
17 from PyQt4.Qsci import QSCINTILLA_VERSION_STR 16 from PyQt4.Qsci import QSCINTILLA_VERSION_STR
89 from Graphics.PixmapDiagram import PixmapDiagram 88 from Graphics.PixmapDiagram import PixmapDiagram
90 from Graphics.SvgDiagram import SvgDiagram 89 from Graphics.SvgDiagram import SvgDiagram
91 90
92 import UI.PixmapCache 91 import UI.PixmapCache
93 92
94 from E5XML.XMLUtilities import make_parser
95 from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError
96 from E5XML.XMLEntityResolver import XMLEntityResolver
97 from E5XML.TasksReader import TasksReader 93 from E5XML.TasksReader import TasksReader
98 from E5XML.TasksWriter import TasksWriter 94 from E5XML.TasksWriter import TasksWriter
95 from E5XML.SessionReader import SessionReader
99 from E5XML.SessionWriter import SessionWriter 96 from E5XML.SessionWriter import SessionWriter
100 from E5XML.SessionHandler import SessionHandler
101 97
102 from E5Network.E5NetworkProxyFactory import E5NetworkProxyFactory, \ 98 from E5Network.E5NetworkProxyFactory import E5NetworkProxyFactory, \
103 proxyAuthenticationRequired 99 proxyAuthenticationRequired
104 100
105 from IconEditor.IconEditorWindow import IconEditorWindow 101 from IconEditor.IconEditorWindow import IconEditorWindow
5057 5053
5058 def __writeSession(self): 5054 def __writeSession(self):
5059 """ 5055 """
5060 Private slot to write the session data to an XML file (.e4s). 5056 Private slot to write the session data to an XML file (.e4s).
5061 """ 5057 """
5062 try: 5058 fn = os.path.join(Utilities.getConfigDir(), "eric5session.e4s")
5063 fn = os.path.join(Utilities.getConfigDir(), "eric5session.e4s") 5059 f = QFile(fn)
5064 f = open(fn, "w", encoding = "utf-8") 5060 if f.open(QIODevice.WriteOnly):
5065
5066 SessionWriter(f, None).writeXML() 5061 SessionWriter(f, None).writeXML()
5067
5068 f.close() 5062 f.close()
5069 5063 else:
5070 except IOError:
5071 E5MessageBox.critical(self, 5064 E5MessageBox.critical(self,
5072 self.trUtf8("Save session"), 5065 self.trUtf8("Save session"),
5073 self.trUtf8("<p>The session file <b>{0}</b> could not be written.</p>") 5066 self.trUtf8("<p>The session file <b>{0}</b> could not be written.</p>")
5074 .format(fn)) 5067 .format(fn))
5075 5068
5076 def __readSession(self): 5069 def __readSession(self):
5077 """ 5070 """
5078 Private slot to read in the session file (.e4s) 5071 Private slot to read in the session file (.e4s)
5079 """ 5072 """
5080 try: 5073 fn = os.path.join(Utilities.getConfigDir(), "eric5session.e4s")
5081 fn = os.path.join(Utilities.getConfigDir(), "eric5session.e4s") 5074 if not os.path.exists(fn):
5082 if not os.path.exists(fn):
5083 E5MessageBox.critical(self,
5084 self.trUtf8("Read session"),
5085 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\
5086 .format(fn))
5087 return
5088 f = open(fn, "r", encoding = "utf-8")
5089 line = f.readline()
5090 dtdLine = f.readline()
5091 f.close()
5092 except IOError:
5093 E5MessageBox.critical(self, 5075 E5MessageBox.critical(self,
5094 self.trUtf8("Read session"), 5076 self.trUtf8("Read session"),
5095 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\ 5077 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\
5096 .format(fn)) 5078 .format(fn))
5097 return 5079 return
5098 5080
5099 # now read the file 5081 f = QFile(fn)
5100 if line.startswith('<?xml'): 5082 if f.open(QIODevice.ReadOnly):
5101 parser = make_parser(dtdLine.startswith("<!DOCTYPE")) 5083 reader = SessionReader(f, True)
5102 handler = SessionHandler(None) 5084 reader.readXML()
5103 er = XMLEntityResolver() 5085 f.close()
5104 eh = XMLErrorHandler()
5105
5106 parser.setContentHandler(handler)
5107 parser.setEntityResolver(er)
5108 parser.setErrorHandler(eh)
5109
5110 try:
5111 f = open(fn, "r", encoding = "utf-8")
5112 try:
5113 try:
5114 parser.parse(f)
5115 except UnicodeEncodeError:
5116 f.seek(0)
5117 buf = io.StringIO(f.read())
5118 parser.parse(buf)
5119 finally:
5120 f.close()
5121 except IOError:
5122 E5MessageBox.critical(self,
5123 self.trUtf8("Read session"),
5124 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\
5125 .format(fn))
5126 return
5127 except XMLFatalParseError:
5128 pass
5129
5130 eh.showParseMessages()
5131 else: 5086 else:
5132 E5MessageBox.critical(self, 5087 E5MessageBox.critical(self,
5133 self.trUtf8("Read session"), 5088 self.trUtf8("Read session"),
5134 self.trUtf8("<p>The session file <b>{0}</b> has an unsupported" 5089 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\
5135 " format.</p>").format(fn)) 5090 .format(fn))
5136 5091
5137 ########################################################## 5092 ##########################################################
5138 ## Below are slots to handle StdOut and StdErr 5093 ## Below are slots to handle StdOut and StdErr
5139 ########################################################## 5094 ##########################################################
5140 5095

eric ide

mercurial