7 Module implementing a template viewer and associated classes. |
7 Module implementing a template viewer and associated classes. |
8 """ |
8 """ |
9 |
9 |
10 import datetime |
10 import datetime |
11 import os |
11 import os |
|
12 import pathlib |
12 import re |
13 import re |
13 |
14 |
14 from PyQt6.QtCore import QFile, QFileInfo, QIODevice, Qt, QCoreApplication |
15 from PyQt6.QtCore import QFile, QIODevice, Qt, QCoreApplication |
15 from PyQt6.QtWidgets import ( |
16 from PyQt6.QtWidgets import ( |
16 QTreeWidget, QDialog, QApplication, QMenu, QTreeWidgetItem |
17 QTreeWidget, QDialog, QApplication, QMenu, QTreeWidgetItem |
17 ) |
18 ) |
18 |
19 |
19 from EricWidgets.EricApplication import ericApp |
20 from EricWidgets.EricApplication import ericApp |
586 "All Files (*)"), |
587 "All Files (*)"), |
587 "", |
588 "", |
588 EricFileDialog.DontConfirmOverwrite) |
589 EricFileDialog.DontConfirmOverwrite) |
589 |
590 |
590 if fn: |
591 if fn: |
591 ext = QFileInfo(fn).suffix() |
592 fpath = pathlib.Path(fn) |
592 if not ext: |
593 if not fpath.suffix: |
593 ex = selectedFilter.split("(*")[1].split(")")[0] |
594 ex = selectedFilter.split("(*")[1].split(")")[0] |
594 if ex: |
595 if ex: |
595 fn += ex |
596 fpath = fpath.with_suffix(ex) |
596 if os.path.exists(fn): |
597 if fpath.exists(): |
597 ok = EricMessageBox.yesNo( |
598 ok = EricMessageBox.yesNo( |
598 self, |
599 self, |
599 self.tr("Export Templates"), |
600 self.tr("Export Templates"), |
600 self.tr("""<p>The templates file <b>{0}</b> exists""" |
601 self.tr("""<p>The templates file <b>{0}</b> exists""" |
601 """ already. Overwrite it?</p>""").format(fn)) |
602 """ already. Overwrite it?</p>""") |
|
603 .format(str(fpath))) |
602 else: |
604 else: |
603 ok = True |
605 ok = True |
604 |
606 |
605 if ok: |
607 if ok: |
606 self.writeTemplates(fn) |
608 self.writeTemplates(str(fpath)) |
607 |
609 |
608 def __reload(self): |
610 def __reload(self): |
609 """ |
611 """ |
610 Private slot to reload the templates. |
612 Private slot to reload the templates. |
611 """ |
613 """ |