QScintilla/MarkupProviders/HyperlinkMarkupDialog.py

changeset 5404
6b19ad5470a3
child 5407
f833f89571b8
equal deleted inserted replaced
5403:d6b43ecf2488 5404:6b19ad5470a3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2017 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter data to insert a hyperlink.
8 """
9
10 from PyQt5.QtCore import pyqtSlot
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
12
13 from .Ui_HyperlinkMarkupDialog import Ui_HyperlinkMarkupDialog
14
15
16 class HyperlinkMarkupDialog(QDialog, Ui_HyperlinkMarkupDialog):
17 """
18 Class implementing a dialog to enter data to insert a hyperlink.
19 """
20 def __init__(self, textMayBeEmpty, targetMayBeEmpty, noTitle=False,
21 parent=None):
22 """
23 Constructor
24
25 @param textMayBeEmpty flag indicating, that the link text may
26 be empty
27 @type bool
28 @param targetMayBeEmpty flag indicating, that the link target may
29 be empty
30 @type bool
31 @param noTitle flag indicating, that no title is supported
32 @type bool
33 @param parent reference to the parent widget
34 @type QWidget
35 """
36 super(HyperlinkMarkupDialog, self).__init__(parent)
37 self.setupUi(self)
38
39 self.__allowEmptyText = textMayBeEmpty
40 self.__allowEmptyTarget = targetMayBeEmpty
41
42 self.titelEdit.setEnabled(not noTitle)
43
44 self.__updateOkButton()
45
46 def __updateOkButton(self):
47 """
48 Private method to update the state of the OK button.
49 """
50 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
51 (bool(self.textEdit.text()) or self.__allowEmptyText) and
52 (bool(self.targetEdit.text()) or self.__allowEmptyTarget)
53 )
54
55 @pyqtSlot(str)
56 def on_textEdit_textChanged(self, txt):
57 """
58 Private slot handling a change of the link text.
59
60 @param txt link text
61 @type str
62 """
63 self.__updateOkButton()
64
65 @pyqtSlot(str)
66 def on_targetEdit_textChanged(self, tyt):
67 """
68 Private slot handling a change of the link target.
69
70 @param txt link target
71 @type str
72 """
73 self.__updateOkButton()
74
75 def getData(self):
76 """
77 Public method to get the entered data.
78
79 @return tuple containing the link text, link target and the optional
80 link title
81 @rtype tuple of (str, str, str)
82 """
83 return (
84 self.textEdit.text(),
85 self.targetEdit.text(),
86 self.titelEdit.text()
87 )

eric ide

mercurial