src/eric7/QScintilla/Exporters/ExporterBase.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 9153
506e35e424d5
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the exporter base class.
8 """
9
10 import pathlib
11
12 from PyQt6.QtCore import QObject, QCoreApplication
13
14 from EricWidgets import EricMessageBox, EricFileDialog
15
16
17 class ExporterBase(QObject):
18 """
19 Class implementing the exporter base class.
20 """
21 def __init__(self, editor, parent=None):
22 """
23 Constructor
24
25 @param editor reference to the editor object (QScintilla.Editor.Editor)
26 @param parent parent object of the exporter (QObject)
27 """
28 super().__init__(parent)
29 self.editor = editor
30
31 def _getFileName(self, fileFilter):
32 """
33 Protected method to get the file name of the export file from the user.
34
35 @param fileFilter the filter string to be used (string). The filter for
36 "All Files (*)" is appended by this method.
37 @return file name entered by the user (string)
38 """
39 fileFilter += ";;"
40 fileFilter += QCoreApplication.translate('Exporter', "All Files (*)")
41 fn, selectedFilter = EricFileDialog.getSaveFileNameAndFilter(
42 self.editor,
43 QCoreApplication.translate('Exporter', "Export source"),
44 "",
45 fileFilter,
46 "",
47 EricFileDialog.DontConfirmOverwrite)
48
49 if fn:
50 fpath = pathlib.Path(fn)
51 if not fpath.suffix:
52 ex = selectedFilter.split("(*")[1].split(")")[0]
53 if ex:
54 fpath = fpath.with_suffix(ex)
55 if fpath.exists():
56 res = EricMessageBox.yesNo(
57 self.editor,
58 QCoreApplication.translate(
59 'Exporter', "Export source"),
60 QCoreApplication.translate(
61 'Exporter',
62 "<p>The file <b>{0}</b> already exists."
63 " Overwrite it?</p>").format(fpath),
64 icon=EricMessageBox.Warning)
65 if not res:
66 return ""
67
68 return str(fpath)
69
70 def exportSource(self):
71 """
72 Public method performing the export.
73
74 This method must be overridden by the real exporters.
75
76 @exception NotImplementedError raised to indicate that this method
77 must be implemented by a subclass
78 """
79 raise NotImplementedError

eric ide

mercurial