6 """ |
6 """ |
7 Module implementing a dialog to show help about rope. |
7 Module implementing a dialog to show help about rope. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtCore import Qt |
10 from PyQt6.QtCore import Qt |
11 from PyQt6.QtGui import QTextDocument, QTextCursor |
11 from PyQt6.QtWidgets import QDialog |
12 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
13 |
12 |
14 from .Ui_HelpDialog import Ui_HelpDialog |
13 from .Ui_HelpDialog import Ui_HelpDialog |
15 |
14 |
16 import Globals |
15 import Globals |
17 |
16 |
18 |
17 |
19 # TODO: modify help dialog to use the eric7 EricTextEditSearchWidget |
|
20 class HelpDialog(QDialog, Ui_HelpDialog): |
18 class HelpDialog(QDialog, Ui_HelpDialog): |
21 """ |
19 """ |
22 Class implementing a dialog to show help about rope. |
20 Class implementing a dialog to show help about rope. |
23 """ |
21 """ |
24 def __init__(self, title, helpfile, parent=None): |
22 def __init__(self, title, helpfile, parent=None): |
34 """ |
32 """ |
35 QDialog.__init__(self, parent) |
33 QDialog.__init__(self, parent) |
36 self.setupUi(self) |
34 self.setupUi(self) |
37 self.setWindowFlags(Qt.WindowType.Window) |
35 self.setWindowFlags(Qt.WindowType.Window) |
38 |
36 |
39 self.searchButton = self.buttonBox.addButton( |
|
40 self.tr("Search..."), QDialogButtonBox.ButtonRole.ActionRole) |
|
41 self.__searchDlg = None |
|
42 |
|
43 if Globals.isWindowsPlatform(): |
37 if Globals.isWindowsPlatform(): |
44 self.helpEdit.setFontFamily("Lucida Console") |
38 self.helpEdit.setFontFamily("Lucida Console") |
45 else: |
39 else: |
46 self.helpEdit.setFontFamily("Monospace") |
40 self.helpEdit.setFontFamily("Monospace") |
47 |
41 |
51 self.helpEdit.setPlainText(txt) |
45 self.helpEdit.setPlainText(txt) |
52 except OSError as err: |
46 except OSError as err: |
53 self.helpEdit.setPlainText( |
47 self.helpEdit.setPlainText( |
54 self.tr("Could not read file {0}.\nReason: {1}") |
48 self.tr("Could not read file {0}.\nReason: {1}") |
55 .format(helpfile, str(err))) |
49 .format(helpfile, str(err))) |
56 |
|
57 def on_buttonBox_clicked(self, button): |
|
58 """ |
|
59 Private slot called by a button of the button box clicked. |
|
60 |
50 |
61 @param button button that was clicked |
51 self.searchWidget.attachTextEdit(self.helpEdit) |
62 @type QAbstractButton |
|
63 """ |
|
64 if button == self.searchButton: |
|
65 if self.__searchDlg is None: |
|
66 from .SearchDialog import SearchDialog |
|
67 self.__searchDlg = SearchDialog(self) |
|
68 self.__searchDlg.showFind() |
|
69 |
|
70 def findNextPrev(self, txt, case, word, backwards): |
|
71 """ |
|
72 Public slot to find the next occurrence of a text. |
|
73 |
|
74 @param txt text to search for |
|
75 @type str |
|
76 @param case flag indicating a case sensitive search |
|
77 @type bool |
|
78 @param word flag indicating a word based search |
|
79 @type bool |
|
80 @param backwards flag indicating a backwards search |
|
81 @type bool |
|
82 @return flag indicating the search found another occurrence |
|
83 @rtype bool |
|
84 """ |
|
85 doc = self.helpEdit.document() |
|
86 cur = self.helpEdit.textCursor() |
|
87 |
|
88 findFlags = QTextDocument.FindFlag(0) |
|
89 if case: |
|
90 findFlags |= QTextDocument.FindCaseSensitively |
|
91 if word: |
|
92 findFlags |= QTextDocument.FindWholeWords |
|
93 if backwards: |
|
94 findFlags |= QTextDocument.FindBackward |
|
95 |
|
96 if cur.hasSelection(): |
|
97 cur.setPosition(backwards and cur.anchor() or cur.position(), |
|
98 QTextCursor.MoveMode.MoveAnchor) |
|
99 newCur = doc.find(txt, cur, findFlags) |
|
100 if newCur.isNull(): |
|
101 return False |
|
102 else: |
|
103 self.helpEdit.setTextCursor(newCur) |
|
104 return True |
|
105 |
|
106 def helpWidget(self): |
|
107 """ |
|
108 Public method to get a reference to the help widget. |
|
109 |
|
110 @return reference to the help widget |
|
111 @rtype QTextEdit |
|
112 """ |
|
113 return self.helpEdit |
|