11 |
11 |
12 from PyQt4.QtCore import * |
12 from PyQt4.QtCore import * |
13 from PyQt4.QtGui import * |
13 from PyQt4.QtGui import * |
14 |
14 |
15 from E5Gui.E5Application import e5App |
15 from E5Gui.E5Application import e5App |
|
16 from E5Gui import E5MessageBox |
16 |
17 |
17 from Preferences import Prefs, syncPreferences |
18 from Preferences import Prefs, syncPreferences |
18 |
19 |
19 from E5XML.XMLUtilities import make_parser |
20 from E5XML.XMLUtilities import make_parser |
20 from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError |
21 from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError |
193 try: |
194 try: |
194 if fn.lower().endswith("e4kz"): |
195 if fn.lower().endswith("e4kz"): |
195 try: |
196 try: |
196 import gzip |
197 import gzip |
197 except ImportError: |
198 except ImportError: |
198 QMessageBox.critical(None, |
199 E5MessageBox.critical(None, |
199 QApplication.translate("Shortcuts", "Export Keyboard Shortcuts"), |
200 QApplication.translate("Shortcuts", "Export Keyboard Shortcuts"), |
200 QApplication.translate("Shortcuts", |
201 QApplication.translate("Shortcuts", |
201 """Compressed keyboard shortcut files""" |
202 """Compressed keyboard shortcut files""" |
202 """ not supported. The compression library is missing.""")) |
203 """ not supported. The compression library is missing.""")) |
203 return 0 |
204 return 0 |
226 try: |
227 try: |
227 if fn.lower().endswith("kz"): |
228 if fn.lower().endswith("kz"): |
228 try: |
229 try: |
229 import gzip |
230 import gzip |
230 except ImportError: |
231 except ImportError: |
231 QMessageBox.critical(None, |
232 E5MessageBox.critical(None, |
232 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
233 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
233 QApplication.translate("Shortcuts", |
234 QApplication.translate("Shortcuts", |
234 """Compressed keyboard shortcut files""" |
235 """Compressed keyboard shortcut files""" |
235 """ not supported. The compression library is missing.""")) |
236 """ not supported. The compression library is missing.""")) |
236 return False |
237 return False |
243 f.readline() |
244 f.readline() |
244 dtdLine = f.readline() |
245 dtdLine = f.readline() |
245 finally: |
246 finally: |
246 f.close() |
247 f.close() |
247 except IOError: |
248 except IOError: |
248 QMessageBox.critical(None, |
249 E5MessageBox.critical(None, |
249 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
250 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
250 QApplication.translate("Shortcuts", |
251 QApplication.translate("Shortcuts", |
251 "<p>The keyboard shortcuts could not be read from file <b>{0}</b>.</p>") |
252 "<p>The keyboard shortcuts could not be read from file <b>{0}</b>.</p>") |
252 .format(fn)) |
253 .format(fn)) |
253 return False |
254 return False |
269 try: |
270 try: |
270 if fn.lower().endswith("kz"): |
271 if fn.lower().endswith("kz"): |
271 try: |
272 try: |
272 import gzip |
273 import gzip |
273 except ImportError: |
274 except ImportError: |
274 QMessageBox.critical(None, |
275 E5MessageBox.critical(None, |
275 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
276 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
276 QApplication.translate("Shortcuts", |
277 QApplication.translate("Shortcuts", |
277 """Compressed keyboard shortcut files""" |
278 """Compressed keyboard shortcut files""" |
278 """ not supported. The compression library is missing.""")) |
279 """ not supported. The compression library is missing.""")) |
279 return False |
280 return False |
290 buf = io.StringIO(f.read()) |
291 buf = io.StringIO(f.read()) |
291 parser.parse(buf) |
292 parser.parse(buf) |
292 finally: |
293 finally: |
293 f.close() |
294 f.close() |
294 except IOError: |
295 except IOError: |
295 QMessageBox.critical(None, |
296 E5MessageBox.critical(None, |
296 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
297 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
297 QApplication.translate("Shortcuts", |
298 QApplication.translate("Shortcuts", |
298 "<p>The keyboard shortcuts could not be read from file <b>{0}</b>.</p>") |
299 "<p>The keyboard shortcuts could not be read from file <b>{0}</b>.</p>") |
299 .format(fn)) |
300 .format(fn)) |
300 return False |
301 return False |
301 |
302 |
302 except XMLFatalParseError: |
303 except XMLFatalParseError: |
303 QMessageBox.critical(None, |
304 E5MessageBox.critical(None, |
304 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
305 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
305 QApplication.translate("Shortcuts", |
306 QApplication.translate("Shortcuts", |
306 "<p>The keyboard shortcuts file <b>{0}</b> has invalid contents.</p>") |
307 "<p>The keyboard shortcuts file <b>{0}</b> has invalid contents.</p>") |
307 .format(fn)) |
308 .format(fn)) |
308 eh.showParseMessages() |
309 eh.showParseMessages() |