UI/UserInterface.py

changeset 537
72b32daeb8d6
parent 536
6d8d39753c82
child 538
7f1a56e80124
equal deleted inserted replaced
536:6d8d39753c82 537:72b32daeb8d6
15 from PyQt4.QtCore import * 15 from PyQt4.QtCore import *
16 from PyQt4.QtGui import * 16 from PyQt4.QtGui import *
17 from PyQt4.Qsci import QSCINTILLA_VERSION_STR 17 from PyQt4.Qsci import QSCINTILLA_VERSION_STR
18 from PyQt4.QtNetwork import QNetworkProxyFactory, QNetworkAccessManager, \ 18 from PyQt4.QtNetwork import QNetworkProxyFactory, QNetworkAccessManager, \
19 QNetworkRequest, QNetworkReply 19 QNetworkRequest, QNetworkReply
20
21 from E5Gui.E5Application import e5App
22 20
23 from Debugger.DebugUI import DebugUI 21 from Debugger.DebugUI import DebugUI
24 from Debugger.DebugServer import DebugServer 22 from Debugger.DebugServer import DebugServer
25 from Debugger.DebugViewer import DebugViewer 23 from Debugger.DebugViewer import DebugViewer
26 from Debugger.DebugClientCapabilities import HasUnittest 24 from Debugger.DebugClientCapabilities import HasUnittest
78 from E5Gui.E5ToolBarDialog import E5ToolBarDialog 76 from E5Gui.E5ToolBarDialog import E5ToolBarDialog
79 from E5Gui.E5SqueezeLabels import E5SqueezeLabelPath 77 from E5Gui.E5SqueezeLabels import E5SqueezeLabelPath
80 from E5Gui.E5ToolBox import E5VerticalToolBox, E5HorizontalToolBox 78 from E5Gui.E5ToolBox import E5VerticalToolBox, E5HorizontalToolBox
81 from E5Gui.E5SideBar import E5SideBar 79 from E5Gui.E5SideBar import E5SideBar
82 from E5Gui import E5MessageBox 80 from E5Gui import E5MessageBox
81 from E5Gui.E5Application import e5App
83 82
84 from VCS.StatusMonitorLed import StatusMonitorLed 83 from VCS.StatusMonitorLed import StatusMonitorLed
85 84
86 import Preferences 85 import Preferences
87 import ViewManager 86 import ViewManager
2727 if Preferences.getUser("UseSystemEmailClient"): 2726 if Preferences.getUser("UseSystemEmailClient"):
2728 self.__showSystemEmailClient(mode, attachFile, deleteAttachFile) 2727 self.__showSystemEmailClient(mode, attachFile, deleteAttachFile)
2729 else: 2728 else:
2730 if Preferences.getUser("Email") == "" or \ 2729 if Preferences.getUser("Email") == "" or \
2731 Preferences.getUser("MailServer") == "": 2730 Preferences.getUser("MailServer") == "":
2732 QMessageBox.critical(None, 2731 E5MessageBox.critical(self,
2733 self.trUtf8("Report Bug"), 2732 self.trUtf8("Report Bug"),
2734 self.trUtf8("""Email address or mail server address is empty.""" 2733 self.trUtf8("""Email address or mail server address is empty."""
2735 """ Please configure your Email settings in the""" 2734 """ Please configure your Email settings in the"""
2736 """ Preferences Dialog.""")) 2735 """ Preferences Dialog."""))
2737 self.showPreferences("emailPage") 2736 self.showPreferences("emailPage")
3942 if os.path.exists(tfn): 3941 if os.path.exists(tfn):
3943 prog = tfn 3942 prog = tfn
3944 else: 3943 else:
3945 prog = fn 3944 prog = fn
3946 else: 3945 else:
3947 QMessageBox.critical(self, 3946 E5MessageBox.critical(self,
3948 self.trUtf8("Unittest Project"), 3947 self.trUtf8("Unittest Project"),
3949 self.trUtf8("There is no main script defined for the" 3948 self.trUtf8("There is no main script defined for the"
3950 " current project. Aborting")) 3949 " current project. Aborting"))
3951 return 3950 return
3952 3951
4000 if fn is not None: 3999 if fn is not None:
4001 try: 4000 try:
4002 if os.path.isfile(fn) and os.path.getsize(fn): 4001 if os.path.isfile(fn) and os.path.getsize(fn):
4003 args.append(fn) 4002 args.append(fn)
4004 else: 4003 else:
4005 QMessageBox.critical(self, 4004 E5MessageBox.critical(self,
4006 self.trUtf8('Problem'), 4005 self.trUtf8('Problem'),
4007 self.trUtf8('<p>The file <b>{0}</b> does not exist or' 4006 self.trUtf8('<p>The file <b>{0}</b> does not exist or'
4008 ' is zero length.</p>') 4007 ' is zero length.</p>')
4009 .format(fn)) 4008 .format(fn))
4010 return 4009 return
4011 except EnvironmentError: 4010 except EnvironmentError:
4012 QMessageBox.critical(self, 4011 E5MessageBox.critical(self,
4013 self.trUtf8('Problem'), 4012 self.trUtf8('Problem'),
4014 self.trUtf8('<p>The file <b>{0}</b> does not exist or' 4013 self.trUtf8('<p>The file <b>{0}</b> does not exist or'
4015 ' is zero length.</p>') 4014 ' is zero length.</p>')
4016 .format(fn)) 4015 .format(fn))
4017 return 4016 return
4024 if Utilities.isWindowsPlatform(): 4023 if Utilities.isWindowsPlatform():
4025 designer = designer + '.exe' 4024 designer = designer + '.exe'
4026 4025
4027 proc = QProcess() 4026 proc = QProcess()
4028 if not proc.startDetached(designer, args): 4027 if not proc.startDetached(designer, args):
4029 QMessageBox.critical(self, 4028 E5MessageBox.critical(self,
4030 self.trUtf8('Process Generation Error'), 4029 self.trUtf8('Process Generation Error'),
4031 self.trUtf8( 4030 self.trUtf8(
4032 '<p>Could not start Qt-Designer.<br>' 4031 '<p>Could not start Qt-Designer.<br>'
4033 'Ensure that it is available as <b>{0}</b>.</p>' 4032 'Ensure that it is available as <b>{0}</b>.</p>'
4034 ).format(designer)) 4033 ).format(designer))
4057 fn = fn.replace('.qm', '.ts') 4056 fn = fn.replace('.qm', '.ts')
4058 try: 4057 try:
4059 if os.path.isfile(fn) and os.path.getsize(fn) and fn not in args: 4058 if os.path.isfile(fn) and os.path.getsize(fn) and fn not in args:
4060 args.append(fn) 4059 args.append(fn)
4061 else: 4060 else:
4062 QMessageBox.critical(self, 4061 E5MessageBox.critical(self,
4063 self.trUtf8('Problem'), 4062 self.trUtf8('Problem'),
4064 self.trUtf8('<p>The file <b>{0}</b> does not exist or' 4063 self.trUtf8('<p>The file <b>{0}</b> does not exist or'
4065 ' is zero length.</p>') 4064 ' is zero length.</p>')
4066 .format(fn)) 4065 .format(fn))
4067 return 4066 return
4068 except EnvironmentError: 4067 except EnvironmentError:
4069 QMessageBox.critical(self, 4068 E5MessageBox.critical(self,
4070 self.trUtf8('Problem'), 4069 self.trUtf8('Problem'),
4071 self.trUtf8('<p>The file <b>{0}</b> does not exist or' 4070 self.trUtf8('<p>The file <b>{0}</b> does not exist or'
4072 ' is zero length.</p>') 4071 ' is zero length.</p>')
4073 .format(fn)) 4072 .format(fn))
4074 return 4073 return
4081 if Utilities.isWindowsPlatform(): 4080 if Utilities.isWindowsPlatform():
4082 linguist = linguist + '.exe' 4081 linguist = linguist + '.exe'
4083 4082
4084 proc = QProcess() 4083 proc = QProcess()
4085 if not proc.startDetached(linguist, args): 4084 if not proc.startDetached(linguist, args):
4086 QMessageBox.critical(self, 4085 E5MessageBox.critical(self,
4087 self.trUtf8('Process Generation Error'), 4086 self.trUtf8('Process Generation Error'),
4088 self.trUtf8( 4087 self.trUtf8(
4089 '<p>Could not start Qt-Linguist.<br>' 4088 '<p>Could not start Qt-Linguist.<br>'
4090 'Ensure that it is available as <b>{0}</b>.</p>' 4089 'Ensure that it is available as <b>{0}</b>.</p>'
4091 ).format(linguist)) 4090 ).format(linguist))
4125 if Utilities.isWindowsPlatform(): 4124 if Utilities.isWindowsPlatform():
4126 assistant = assistant + '.exe' 4125 assistant = assistant + '.exe'
4127 4126
4128 proc = QProcess() 4127 proc = QProcess()
4129 if not proc.startDetached(assistant, args): 4128 if not proc.startDetached(assistant, args):
4130 QMessageBox.critical(self, 4129 E5MessageBox.critical(self,
4131 self.trUtf8('Process Generation Error'), 4130 self.trUtf8('Process Generation Error'),
4132 self.trUtf8( 4131 self.trUtf8(
4133 '<p>Could not start Qt-Assistant.<br>' 4132 '<p>Could not start Qt-Assistant.<br>'
4134 'Ensure that it is available as <b>{0}</b>.</p>' 4133 'Ensure that it is available as <b>{0}</b>.</p>'
4135 ).format(assistant)) 4134 ).format(assistant))
4166 args = [] 4165 args = []
4167 if home: 4166 if home:
4168 args.append(home) 4167 args.append(home)
4169 4168
4170 if not proc.startDetached(customViewer, args): 4169 if not proc.startDetached(customViewer, args):
4171 QMessageBox.critical(self, 4170 E5MessageBox.critical(self,
4172 self.trUtf8('Process Generation Error'), 4171 self.trUtf8('Process Generation Error'),
4173 self.trUtf8( 4172 self.trUtf8(
4174 '<p>Could not start custom viewer.<br>' 4173 '<p>Could not start custom viewer.<br>'
4175 'Ensure that it is available as <b>{0}</b>.</p>' 4174 'Ensure that it is available as <b>{0}</b>.</p>'
4176 ).format(customViewer)) 4175 ).format(customViewer))
4185 proc = QProcess() 4184 proc = QProcess()
4186 args = [] 4185 args = []
4187 args.append(home) 4186 args.append(home)
4188 4187
4189 if not proc.startDetached("hh", args): 4188 if not proc.startDetached("hh", args):
4190 QMessageBox.critical(self, 4189 E5MessageBox.critical(self,
4191 self.trUtf8('Process Generation Error'), 4190 self.trUtf8('Process Generation Error'),
4192 self.trUtf8( 4191 self.trUtf8(
4193 '<p>Could not start the help viewer.<br>' 4192 '<p>Could not start the help viewer.<br>'
4194 'Ensure that it is available as <b>hh</b>.</p>' 4193 'Ensure that it is available as <b>hh</b>.</p>'
4195 )) 4194 ))
4210 if fn is not None: 4209 if fn is not None:
4211 try: 4210 try:
4212 if os.path.isfile(fn) and os.path.getsize(fn): 4211 if os.path.isfile(fn) and os.path.getsize(fn):
4213 args.append(fn) 4212 args.append(fn)
4214 else: 4213 else:
4215 QMessageBox.critical(self, 4214 E5MessageBox.critical(self,
4216 self.trUtf8('Problem'), 4215 self.trUtf8('Problem'),
4217 self.trUtf8('<p>The file <b>{0}</b> does not exist or' 4216 self.trUtf8('<p>The file <b>{0}</b> does not exist or'
4218 ' is zero length.</p>') 4217 ' is zero length.</p>')
4219 .format(fn)) 4218 .format(fn))
4220 return 4219 return
4221 except EnvironmentError: 4220 except EnvironmentError:
4222 QMessageBox.critical(self, 4221 E5MessageBox.critical(self,
4223 self.trUtf8('Problem'), 4222 self.trUtf8('Problem'),
4224 self.trUtf8('<p>The file <b>{0}</b> does not exist or' 4223 self.trUtf8('<p>The file <b>{0}</b> does not exist or'
4225 ' is zero length.</p>') 4224 ' is zero length.</p>')
4226 .format(fn)) 4225 .format(fn))
4227 return 4226 return
4228 4227
4229 if not os.path.isfile(viewer) or not proc.startDetached(sys.executable, args): 4228 if not os.path.isfile(viewer) or not proc.startDetached(sys.executable, args):
4230 QMessageBox.critical(self, 4229 E5MessageBox.critical(self,
4231 self.trUtf8('Process Generation Error'), 4230 self.trUtf8('Process Generation Error'),
4232 self.trUtf8( 4231 self.trUtf8(
4233 '<p>Could not start UI Previewer.<br>' 4232 '<p>Could not start UI Previewer.<br>'
4234 'Ensure that it is available as <b>{0}</b>.</p>' 4233 'Ensure that it is available as <b>{0}</b>.</p>'
4235 ).format(viewer)) 4234 ).format(viewer))
4254 try: 4253 try:
4255 if os.path.isfile(fn) and os.path.getsize(fn): 4254 if os.path.isfile(fn) and os.path.getsize(fn):
4256 args.append(fn) 4255 args.append(fn)
4257 else: 4256 else:
4258 if not ignore: 4257 if not ignore:
4259 QMessageBox.critical(self, 4258 E5MessageBox.critical(self,
4260 self.trUtf8('Problem'), 4259 self.trUtf8('Problem'),
4261 self.trUtf8('<p>The file <b>{0}</b> does not exist or' 4260 self.trUtf8('<p>The file <b>{0}</b> does not exist or'
4262 ' is zero length.</p>') 4261 ' is zero length.</p>')
4263 .format(fn)) 4262 .format(fn))
4264 return 4263 return
4265 except EnvironmentError: 4264 except EnvironmentError:
4266 if not ignore: 4265 if not ignore:
4267 QMessageBox.critical(self, 4266 E5MessageBox.critical(self,
4268 self.trUtf8('Problem'), 4267 self.trUtf8('Problem'),
4269 self.trUtf8('<p>The file <b>{0}</b> does not exist or' 4268 self.trUtf8('<p>The file <b>{0}</b> does not exist or'
4270 ' is zero length.</p>') 4269 ' is zero length.</p>')
4271 .format(fn)) 4270 .format(fn))
4272 return 4271 return
4273 4272
4274 if not os.path.isfile(viewer) or not proc.startDetached(sys.executable, args): 4273 if not os.path.isfile(viewer) or not proc.startDetached(sys.executable, args):
4275 QMessageBox.critical(self, 4274 E5MessageBox.critical(self,
4276 self.trUtf8('Process Generation Error'), 4275 self.trUtf8('Process Generation Error'),
4277 self.trUtf8( 4276 self.trUtf8(
4278 '<p>Could not start Translation Previewer.<br>' 4277 '<p>Could not start Translation Previewer.<br>'
4279 'Ensure that it is available as <b>{0}</b>.</p>' 4278 'Ensure that it is available as <b>{0}</b>.</p>'
4280 ).format(viewer)) 4279 ).format(viewer))
4289 4288
4290 args = [] 4289 args = []
4291 args.append(browser) 4290 args.append(browser)
4292 4291
4293 if not os.path.isfile(browser) or not proc.startDetached(sys.executable, args): 4292 if not os.path.isfile(browser) or not proc.startDetached(sys.executable, args):
4294 QMessageBox.critical(self, 4293 E5MessageBox.critical(self,
4295 self.trUtf8('Process Generation Error'), 4294 self.trUtf8('Process Generation Error'),
4296 self.trUtf8( 4295 self.trUtf8(
4297 '<p>Could not start SQL Browser.<br>' 4296 '<p>Could not start SQL Browser.<br>'
4298 'Ensure that it is available as <b>{0}</b>.</p>' 4297 'Ensure that it is available as <b>{0}</b>.</p>'
4299 ).format(browser)) 4298 ).format(browser))
4395 if aw is not None: 4394 if aw is not None:
4396 aw.beginUndoAction() 4395 aw.beginUndoAction()
4397 4396
4398 proc.start(program, args) 4397 proc.start(program, args)
4399 if not proc.waitForStarted(): 4398 if not proc.waitForStarted():
4400 QMessageBox.critical(self, 4399 E5MessageBox.critical(self,
4401 self.trUtf8('Process Generation Error'), 4400 self.trUtf8('Process Generation Error'),
4402 self.trUtf8( 4401 self.trUtf8(
4403 '<p>Could not start the tool entry <b>{0}</b>.<br>' 4402 '<p>Could not start the tool entry <b>{0}</b>.<br>'
4404 'Ensure that it is available as <b>{1}</b>.</p>')\ 4403 'Ensure that it is available as <b>{1}</b>.</p>')\
4405 .format(tool['menutext'], tool['executable'])) 4404 .format(tool['menutext'], tool['executable']))
4905 if ex: 4904 if ex:
4906 fn += ex 4905 fn += ex
4907 4906
4908 res = Shortcuts.exportShortcuts(fn) 4907 res = Shortcuts.exportShortcuts(fn)
4909 if not res: 4908 if not res:
4910 QMessageBox.critical(None, 4909 E5MessageBox.critical(self,
4911 self.trUtf8("Export Keyboard Shortcuts"), 4910 self.trUtf8("Export Keyboard Shortcuts"),
4912 self.trUtf8("<p>The keyboard shortcuts could not be written to file" 4911 self.trUtf8("<p>The keyboard shortcuts could not be written to file"
4913 " <b>{0}</b>.</p>").format(fn)) 4912 " <b>{0}</b>.</p>").format(fn))
4914 4913
4915 def __importShortcuts(self): 4914 def __importShortcuts(self):
5038 TasksWriter(f, False).writeXML() 5037 TasksWriter(f, False).writeXML()
5039 5038
5040 f.close() 5039 f.close()
5041 5040
5042 except IOError: 5041 except IOError:
5043 QMessageBox.critical(None, 5042 E5MessageBox.critical(self,
5044 self.trUtf8("Save tasks"), 5043 self.trUtf8("Save tasks"),
5045 self.trUtf8("<p>The tasks file <b>{0}</b> could not be written.</p>") 5044 self.trUtf8("<p>The tasks file <b>{0}</b> could not be written.</p>")
5046 .format(fn)) 5045 .format(fn))
5047 5046
5048 def __readTasks(self): 5047 def __readTasks(self):
5056 f = open(fn, "r", encoding = "utf-8") 5055 f = open(fn, "r", encoding = "utf-8")
5057 line = f.readline() 5056 line = f.readline()
5058 dtdLine = f.readline() 5057 dtdLine = f.readline()
5059 f.close() 5058 f.close()
5060 except IOError: 5059 except IOError:
5061 QMessageBox.critical(None, 5060 E5MessageBox.critical(self,
5062 self.trUtf8("Read tasks"), 5061 self.trUtf8("Read tasks"),
5063 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>") 5062 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>")
5064 .format(fn)) 5063 .format(fn))
5065 return 5064 return
5066 5065
5085 buf = io.StringIO(f.read()) 5084 buf = io.StringIO(f.read())
5086 parser.parse(buf) 5085 parser.parse(buf)
5087 finally: 5086 finally:
5088 f.close() 5087 f.close()
5089 except IOError: 5088 except IOError:
5090 QMessageBox.critical(None, 5089 E5MessageBox.critical(self,
5091 self.trUtf8("Read tasks"), 5090 self.trUtf8("Read tasks"),
5092 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>")\ 5091 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>")\
5093 .format(fn)) 5092 .format(fn))
5094 return 5093 return
5095 except XMLFatalParseError: 5094 except XMLFatalParseError:
5096 pass 5095 pass
5097 5096
5098 eh.showParseMessages() 5097 eh.showParseMessages()
5099 else: 5098 else:
5100 QMessageBox.critical(None, 5099 E5MessageBox.critical(self,
5101 self.trUtf8("Read tasks"), 5100 self.trUtf8("Read tasks"),
5102 self.trUtf8("<p>The tasks file <b>{0}</b> has an unsupported format.</p>")\ 5101 self.trUtf8("<p>The tasks file <b>{0}</b> has an unsupported"
5103 .format(fn)) 5102 " format.</p>").format(fn))
5104 5103
5105 def __writeSession(self): 5104 def __writeSession(self):
5106 """ 5105 """
5107 Private slot to write the session data to an XML file (.e4s). 5106 Private slot to write the session data to an XML file (.e4s).
5108 """ 5107 """
5113 SessionWriter(f, None).writeXML() 5112 SessionWriter(f, None).writeXML()
5114 5113
5115 f.close() 5114 f.close()
5116 5115
5117 except IOError: 5116 except IOError:
5118 QMessageBox.critical(None, 5117 E5MessageBox.critical(self,
5119 self.trUtf8("Save session"), 5118 self.trUtf8("Save session"),
5120 self.trUtf8("<p>The session file <b>{0}</b> could not be written.</p>") 5119 self.trUtf8("<p>The session file <b>{0}</b> could not be written.</p>")
5121 .format(fn)) 5120 .format(fn))
5122 5121
5123 def __readSession(self): 5122 def __readSession(self):
5125 Private slot to read in the session file (.e4s) 5124 Private slot to read in the session file (.e4s)
5126 """ 5125 """
5127 try: 5126 try:
5128 fn = os.path.join(Utilities.getConfigDir(), "eric5session.e4s") 5127 fn = os.path.join(Utilities.getConfigDir(), "eric5session.e4s")
5129 if not os.path.exists(fn): 5128 if not os.path.exists(fn):
5130 QMessageBox.critical(None, 5129 E5MessageBox.critical(self,
5131 self.trUtf8("Read session"), 5130 self.trUtf8("Read session"),
5132 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\ 5131 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\
5133 .format(fn)) 5132 .format(fn))
5134 return 5133 return
5135 f = open(fn, "r", encoding = "utf-8") 5134 f = open(fn, "r", encoding = "utf-8")
5136 line = f.readline() 5135 line = f.readline()
5137 dtdLine = f.readline() 5136 dtdLine = f.readline()
5138 f.close() 5137 f.close()
5139 except IOError: 5138 except IOError:
5140 QMessageBox.critical(None, 5139 E5MessageBox.critical(self,
5141 self.trUtf8("Read session"), 5140 self.trUtf8("Read session"),
5142 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\ 5141 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\
5143 .format(fn)) 5142 .format(fn))
5144 return 5143 return
5145 5144
5164 buf = io.StringIO(f.read()) 5163 buf = io.StringIO(f.read())
5165 parser.parse(buf) 5164 parser.parse(buf)
5166 finally: 5165 finally:
5167 f.close() 5166 f.close()
5168 except IOError: 5167 except IOError:
5169 QMessageBox.critical(None, 5168 E5MessageBox.critical(self,
5170 self.trUtf8("Read session"), 5169 self.trUtf8("Read session"),
5171 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\ 5170 self.trUtf8("<p>The session file <b>{0}</b> could not be read.</p>")\
5172 .format(fn)) 5171 .format(fn))
5173 return 5172 return
5174 except XMLFatalParseError: 5173 except XMLFatalParseError:
5175 pass 5174 pass
5176 5175
5177 eh.showParseMessages() 5176 eh.showParseMessages()
5178 else: 5177 else:
5179 QMessageBox.critical(None, 5178 E5MessageBox.critical(self,
5180 self.trUtf8("Read session"), 5179 self.trUtf8("Read session"),
5181 self.trUtf8("<p>The session file <b>{0}</b> has an unsupported" 5180 self.trUtf8("<p>The session file <b>{0}</b> has an unsupported"
5182 " format.</p>").format(fn)) 5181 " format.</p>").format(fn))
5183 5182
5184 ########################################################## 5183 ##########################################################

eric ide

mercurial