9 |
9 |
10 import io |
10 import io |
11 |
11 |
12 from PyQt4.QtCore import pyqtSlot, QFileInfo |
12 from PyQt4.QtCore import pyqtSlot, QFileInfo |
13 from PyQt4.QtGui import QPalette, QFileDialog, QColorDialog, QFontDialog, \ |
13 from PyQt4.QtGui import QPalette, QFileDialog, QColorDialog, QFontDialog, \ |
14 QInputDialog, QMessageBox, QFont, QMenu |
14 QInputDialog, QFont, QMenu |
15 |
15 |
16 from .ConfigurationPageBase import ConfigurationPageBase |
16 from .ConfigurationPageBase import ConfigurationPageBase |
17 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage |
17 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage |
|
18 |
|
19 from E5Gui import E5MessageBox |
18 |
20 |
19 from E5XML.XMLUtilities import make_parser |
21 from E5XML.XMLUtilities import make_parser |
20 from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError |
22 from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError |
21 from E5XML.XMLEntityResolver import XMLEntityResolver |
23 from E5XML.XMLEntityResolver import XMLEntityResolver |
22 from E5XML.HighlightingStylesWriter import HighlightingStylesWriter |
24 from E5XML.HighlightingStylesWriter import HighlightingStylesWriter |
386 try: |
388 try: |
387 f = open(fn, "w", encoding = "utf-8") |
389 f = open(fn, "w", encoding = "utf-8") |
388 HighlightingStylesWriter(f, lexers).writeXML() |
390 HighlightingStylesWriter(f, lexers).writeXML() |
389 f.close() |
391 f.close() |
390 except IOError as err: |
392 except IOError as err: |
391 QMessageBox.critical(self, |
393 E5MessageBox.critical(self, |
392 self.trUtf8("Export Highlighting Styles"), |
394 self.trUtf8("Export Highlighting Styles"), |
393 self.trUtf8("""<p>The highlighting styles could not be exported""" |
395 self.trUtf8("""<p>The highlighting styles could not be exported""" |
394 """ to file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
396 """ to file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
395 .format(fn, str(err)) |
397 .format(fn, str(err)) |
396 ) |
398 ) |
416 f.readline() |
418 f.readline() |
417 dtdLine = f.readline() |
419 dtdLine = f.readline() |
418 finally: |
420 finally: |
419 f.close() |
421 f.close() |
420 except IOError as err: |
422 except IOError as err: |
421 QMessageBox.critical(self, |
423 E5MessageBox.critical(self, |
422 self.trUtf8("Import Highlighting Styles"), |
424 self.trUtf8("Import Highlighting Styles"), |
423 self.trUtf8("""<p>The highlighting styles could not be read""" |
425 self.trUtf8("""<p>The highlighting styles could not be read""" |
424 """ from file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
426 """ from file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
425 .format(fn, str(err)) |
427 .format(fn, str(err)) |
426 ) |
428 ) |
446 buf = io.StringIO(f.read()) |
448 buf = io.StringIO(f.read()) |
447 parser.parse(buf) |
449 parser.parse(buf) |
448 finally: |
450 finally: |
449 f.close() |
451 f.close() |
450 except IOError as err: |
452 except IOError as err: |
451 QMessageBox.critical(self, |
453 E5MessageBox.critical(self, |
452 self.trUtf8("Import Highlighting Styles"), |
454 self.trUtf8("Import Highlighting Styles"), |
453 self.trUtf8("""<p>The highlighting styles could not be read""" |
455 self.trUtf8("""<p>The highlighting styles could not be read""" |
454 """ from file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
456 """ from file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
455 .format(fn, str(err)) |
457 .format(fn, str(err)) |
456 ) |
458 ) |
457 return |
459 return |
458 except XMLFatalParseError: |
460 except XMLFatalParseError: |
459 QMessageBox.critical(self, |
461 E5MessageBox.critical(self, |
460 self.trUtf8("Import Highlighting Styles"), |
462 self.trUtf8("Import Highlighting Styles"), |
461 self.trUtf8("""<p>The highlighting styles file <b>{0}</b>""" |
463 self.trUtf8("""<p>The highlighting styles file <b>{0}</b>""" |
462 """ has invalid contents.</p>""").format(fn)) |
464 """ has invalid contents.</p>""").format(fn)) |
463 eh.showParseMessages() |
465 eh.showParseMessages() |
464 return |
466 return |