eric7/QScintilla/Exporters/ExporterBase.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the exporter base class.
8 """
9
10 from PyQt5.QtCore import QFileInfo, QObject, QCoreApplication
11
12 from E5Gui import E5MessageBox, E5FileDialog
13
14 import Utilities
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 = E5FileDialog.getSaveFileNameAndFilter(
42 self.editor,
43 QCoreApplication.translate('Exporter', "Export source"),
44 "",
45 fileFilter,
46 "",
47 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
48
49 if fn:
50 ext = QFileInfo(fn).suffix()
51 if not ext:
52 ex = selectedFilter.split("(*")[1].split(")")[0]
53 if ex:
54 fn += ex
55 if QFileInfo(fn).exists():
56 res = E5MessageBox.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(fn),
64 icon=E5MessageBox.Warning)
65 if not res:
66 return ""
67
68 fn = Utilities.toNativeSeparators(fn)
69
70 return fn
71
72 def exportSource(self):
73 """
74 Public method performing the export.
75
76 This method must be overridden by the real exporters.
77
78 @exception NotImplementedError raised to indicate that this method
79 must be implemented by a subclass
80 """
81 raise NotImplementedError

eric ide

mercurial