eric6/QScintilla/MarkupProviders/HyperlinkMarkupDialog.py

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

eric ide

mercurial