16 |
16 |
17 class ExporterBase(QObject): |
17 class ExporterBase(QObject): |
18 """ |
18 """ |
19 Class implementing the exporter base class. |
19 Class implementing the exporter base class. |
20 """ |
20 """ |
|
21 |
21 def __init__(self, editor, parent=None): |
22 def __init__(self, editor, parent=None): |
22 """ |
23 """ |
23 Constructor |
24 Constructor |
24 |
25 |
25 @param editor reference to the editor object (QScintilla.Editor.Editor) |
26 @param editor reference to the editor object (QScintilla.Editor.Editor) |
26 @param parent parent object of the exporter (QObject) |
27 @param parent parent object of the exporter (QObject) |
27 """ |
28 """ |
28 super().__init__(parent) |
29 super().__init__(parent) |
29 self.editor = editor |
30 self.editor = editor |
30 |
31 |
31 def _getFileName(self, fileFilter): |
32 def _getFileName(self, fileFilter): |
32 """ |
33 """ |
33 Protected method to get the file name of the export file from the user. |
34 Protected method to get the file name of the export file from the user. |
34 |
35 |
35 @param fileFilter the filter string to be used (string). The filter for |
36 @param fileFilter the filter string to be used (string). The filter for |
36 "All Files (*)" is appended by this method. |
37 "All Files (*)" is appended by this method. |
37 @return file name entered by the user (string) |
38 @return file name entered by the user (string) |
38 """ |
39 """ |
39 fileFilter += ";;" |
40 fileFilter += ";;" |
40 fileFilter += QCoreApplication.translate('Exporter', "All Files (*)") |
41 fileFilter += QCoreApplication.translate("Exporter", "All Files (*)") |
41 fn, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
42 fn, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
42 self.editor, |
43 self.editor, |
43 QCoreApplication.translate('Exporter', "Export source"), |
44 QCoreApplication.translate("Exporter", "Export source"), |
44 "", |
45 "", |
45 fileFilter, |
46 fileFilter, |
46 "", |
47 "", |
47 EricFileDialog.DontConfirmOverwrite) |
48 EricFileDialog.DontConfirmOverwrite, |
48 |
49 ) |
|
50 |
49 if fn: |
51 if fn: |
50 fpath = pathlib.Path(fn) |
52 fpath = pathlib.Path(fn) |
51 if not fpath.suffix: |
53 if not fpath.suffix: |
52 ex = selectedFilter.split("(*")[1].split(")")[0] |
54 ex = selectedFilter.split("(*")[1].split(")")[0] |
53 if ex: |
55 if ex: |
54 fpath = fpath.with_suffix(ex) |
56 fpath = fpath.with_suffix(ex) |
55 if fpath.exists(): |
57 if fpath.exists(): |
56 res = EricMessageBox.yesNo( |
58 res = EricMessageBox.yesNo( |
57 self.editor, |
59 self.editor, |
|
60 QCoreApplication.translate("Exporter", "Export source"), |
58 QCoreApplication.translate( |
61 QCoreApplication.translate( |
59 'Exporter', "Export source"), |
62 "Exporter", |
60 QCoreApplication.translate( |
63 "<p>The file <b>{0}</b> already exists." " Overwrite it?</p>", |
61 'Exporter', |
64 ).format(fpath), |
62 "<p>The file <b>{0}</b> already exists." |
65 icon=EricMessageBox.Warning, |
63 " Overwrite it?</p>").format(fpath), |
66 ) |
64 icon=EricMessageBox.Warning) |
|
65 if not res: |
67 if not res: |
66 return "" |
68 return "" |
67 |
69 |
68 return str(fpath) |
70 return str(fpath) |
69 |
71 |
70 def exportSource(self): |
72 def exportSource(self): |
71 """ |
73 """ |
72 Public method performing the export. |
74 Public method performing the export. |
73 |
75 |
74 This method must be overridden by the real exporters. |
76 This method must be overridden by the real exporters. |
75 |
77 |
76 @exception NotImplementedError raised to indicate that this method |
78 @exception NotImplementedError raised to indicate that this method |
77 must be implemented by a subclass |
79 must be implemented by a subclass |
78 """ |
80 """ |
79 raise NotImplementedError |
81 raise NotImplementedError |