8 """ |
8 """ |
9 |
9 |
10 import sys |
10 import sys |
11 import re |
11 import re |
12 |
12 |
13 from PyQt4.QtCore import QFileInfo, Qt, QEvent |
13 from PyQt4.QtCore import pyqtSignal, QFileInfo, Qt, QEvent |
14 from PyQt4.QtGui import QDialog, QInputDialog, QApplication, QClipboard, QMenu, \ |
14 from PyQt4.QtGui import QDialog, QInputDialog, QApplication, QClipboard, QMenu, \ |
15 QPalette, QFont |
15 QPalette, QFont, QWidget, QHBoxLayout, QVBoxLayout, QShortcut |
16 from PyQt4.Qsci import QsciScintilla |
16 from PyQt4.Qsci import QsciScintilla |
17 |
17 |
18 from E5Gui.E5Application import e5App |
18 from E5Gui.E5Application import e5App |
19 from E5Gui import E5MessageBox |
19 from E5Gui import E5MessageBox |
20 |
20 |
21 from . import Lexers |
21 from . import Lexers |
22 from .QsciScintillaCompat import QsciScintillaCompat |
22 from .QsciScintillaCompat import QsciScintillaCompat |
23 |
23 |
24 import Preferences |
24 import Preferences |
|
25 |
25 import UI.PixmapCache |
26 import UI.PixmapCache |
|
27 from UI.SearchWidget import SearchWidget |
26 |
28 |
27 from Debugger.DebugClientCapabilities import HasCompleter |
29 from Debugger.DebugClientCapabilities import HasCompleter |
28 |
30 |
29 from .ShellHistoryDialog import ShellHistoryDialog |
31 from .ShellHistoryDialog import ShellHistoryDialog |
|
32 |
|
33 |
|
34 class ShellAssembly(QWidget): |
|
35 """ |
|
36 Class implementing the containing widget for the shell. |
|
37 """ |
|
38 def __init__(self, dbs, vm, horizontal=True, parent=None): |
|
39 """ |
|
40 Constructor |
|
41 |
|
42 @param dbs reference to the debug server object |
|
43 @param vm reference to the viewmanager object |
|
44 @param horizontal flag indicating a horizontal layout (boolean) |
|
45 @param parent parent widget (QWidget) |
|
46 """ |
|
47 super().__init__(parent) |
|
48 |
|
49 self.__shell = Shell(dbs, vm, self) |
|
50 self.__searchWidget = SearchWidget(self.__shell, self, horizontal) |
|
51 self.__searchWidget.hide() |
|
52 |
|
53 if horizontal: |
|
54 self.__layout = QHBoxLayout(self) |
|
55 else: |
|
56 self.__layout = QVBoxLayout(self) |
|
57 self.__layout.setContentsMargins(1, 1, 1, 1) |
|
58 self.__layout.addWidget(self.__shell) |
|
59 self.__layout.addWidget(self.__searchWidget) |
|
60 |
|
61 self.__searchWidget.searchNext.connect(self.__shell.searchNext) |
|
62 self.__searchWidget.searchPrevious.connect(self.__shell.searchPrev) |
|
63 self.__shell.searchStringFound.connect(self.__searchWidget.searchStringFound) |
|
64 |
|
65 def showFind(self, txt=""): |
|
66 """ |
|
67 Public method to display the search widget. |
|
68 |
|
69 @param txt text to be shown in the combo (string) |
|
70 """ |
|
71 self.__searchWidget.showFind(txt) |
|
72 |
|
73 def shell(self): |
|
74 """ |
|
75 Public method to get a reference to the terminal widget. |
|
76 |
|
77 @return reference to the terminal widget (Terminal) |
|
78 """ |
|
79 return self.__shell |
30 |
80 |
31 |
81 |
32 class Shell(QsciScintillaCompat): |
82 class Shell(QsciScintillaCompat): |
33 """ |
83 """ |
34 Class implementing a graphical Python shell. |
84 Class implementing a graphical Python shell. |
35 |
85 |
36 A user can enter commands that are executed in the remote |
86 A user can enter commands that are executed in the remote |
37 Python interpreter. |
87 Python interpreter. |
|
88 |
|
89 @signal searchStringFound(found) emitted to indicate the search result (boolean) |
38 """ |
90 """ |
|
91 searchStringFound = pyqtSignal(bool) |
|
92 |
39 def __init__(self, dbs, vm, parent=None): |
93 def __init__(self, dbs, vm, parent=None): |
40 """ |
94 """ |
41 Constructor |
95 Constructor |
42 |
96 |
43 @param dbs reference to the debug server object |
97 @param dbs reference to the debug server object |
157 self.menu = QMenu(self) |
213 self.menu = QMenu(self) |
158 self.menu.addAction(self.trUtf8('Cut'), self.cut) |
214 self.menu.addAction(self.trUtf8('Cut'), self.cut) |
159 self.menu.addAction(self.trUtf8('Copy'), self.copy) |
215 self.menu.addAction(self.trUtf8('Copy'), self.copy) |
160 self.menu.addAction(self.trUtf8('Paste'), self.paste) |
216 self.menu.addAction(self.trUtf8('Paste'), self.paste) |
161 self.menu.addMenu(self.hmenu) |
217 self.menu.addMenu(self.hmenu) |
|
218 self.menu.addSeparator() |
|
219 self.menu.addAction(self.trUtf8('Find'), self.__find) |
162 self.menu.addSeparator() |
220 self.menu.addSeparator() |
163 self.menu.addAction(self.trUtf8('Clear'), self.clear) |
221 self.menu.addAction(self.trUtf8('Clear'), self.clear) |
164 self.menu.addAction(self.trUtf8('Reset'), self.__reset) |
222 self.menu.addAction(self.trUtf8('Reset'), self.__reset) |
165 self.menu.addAction(self.trUtf8('Reset and Clear'), |
223 self.menu.addAction(self.trUtf8('Reset and Clear'), |
166 self.__resetAndClear) |
224 self.__resetAndClear) |
1456 """ |
1514 """ |
1457 if not self.__actionsAdded: |
1515 if not self.__actionsAdded: |
1458 self.addActions(self.vm.editorActGrp.actions()) |
1516 self.addActions(self.vm.editorActGrp.actions()) |
1459 self.addActions(self.vm.copyActGrp.actions()) |
1517 self.addActions(self.vm.copyActGrp.actions()) |
1460 self.addActions(self.vm.viewActGrp.actions()) |
1518 self.addActions(self.vm.viewActGrp.actions()) |
|
1519 self.__searchShortcut = QShortcut(self.vm.searchAct.shortcut(), self, |
|
1520 self.__find, self.__find) |
|
1521 self.__searchNextShortcut = QShortcut(self.vm.searchNextAct.shortcut(), self, |
|
1522 self.__searchNext, self.__searchNext) |
|
1523 self.__searchPrevShortcut = QShortcut(self.vm.searchPrevAct.shortcut(), self, |
|
1524 self.__searchPrev, self.__searchPrev) |
1461 |
1525 |
1462 try: |
1526 try: |
1463 self.vm.editActGrp.setEnabled(False) |
1527 self.vm.editActGrp.setEnabled(False) |
1464 self.vm.editorActGrp.setEnabled(True) |
1528 self.vm.editorActGrp.setEnabled(True) |
1465 self.vm.copyActGrp.setEnabled(True) |
1529 self.vm.copyActGrp.setEnabled(True) |
1466 self.vm.viewActGrp.setEnabled(True) |
1530 self.vm.viewActGrp.setEnabled(True) |
1467 self.vm.searchActGrp.setEnabled(False) |
1531 self.vm.searchActGrp.setEnabled(False) |
1468 except AttributeError: |
1532 except AttributeError: |
1469 pass |
1533 pass |
|
1534 self.__searchShortcut.setEnabled(True) |
|
1535 self.__searchNextShortcut.setEnabled(True) |
|
1536 self.__searchPrevShortcut.setEnabled(True) |
1470 self.setCaretWidth(self.caretWidth) |
1537 self.setCaretWidth(self.caretWidth) |
1471 self.setCursorFlashTime(QApplication.cursorFlashTime()) |
1538 self.setCursorFlashTime(QApplication.cursorFlashTime()) |
1472 |
1539 |
1473 super().focusInEvent(event) |
1540 super().focusInEvent(event) |
1474 |
1541 |
1503 def __configure(self): |
1573 def __configure(self): |
1504 """ |
1574 """ |
1505 Private method to open the configuration dialog. |
1575 Private method to open the configuration dialog. |
1506 """ |
1576 """ |
1507 e5App().getObject("UserInterface").showPreferences("shellPage") |
1577 e5App().getObject("UserInterface").showPreferences("shellPage") |
|
1578 |
|
1579 def __find(self): |
|
1580 """ |
|
1581 Private slot to show the find widget. |
|
1582 """ |
|
1583 txt = self.selectedText() |
|
1584 self.__mainWindow.showFind(txt) |
|
1585 |
|
1586 def __searchNext(self): |
|
1587 """ |
|
1588 Private method to search for the next occurrence. |
|
1589 """ |
|
1590 if self.__lastSearch: |
|
1591 self.searchNext(*self.__lastSearch) |
|
1592 |
|
1593 def searchNext(self, txt, caseSensitive, wholeWord): |
|
1594 """ |
|
1595 Public method to search the next occurrence of the given text. |
|
1596 |
|
1597 @param txt text to search for (string) |
|
1598 @param caseSensitive flag indicating to perform a case sensitive |
|
1599 search (boolean) |
|
1600 @param wholeWord flag indicating to search for whole words |
|
1601 only (boolean) |
|
1602 """ |
|
1603 self.__lastSearch = (txt, caseSensitive, wholeWord) |
|
1604 ok = self.findFirst(txt, False, caseSensitive, wholeWord, False, forward=True) |
|
1605 self.searchStringFound.emit(ok) |
|
1606 |
|
1607 def __searchPrev(self): |
|
1608 """ |
|
1609 Private method to search for the next occurrence. |
|
1610 """ |
|
1611 if self.__lastSearch: |
|
1612 self.searchPrev(*self.__lastSearch) |
|
1613 |
|
1614 def searchPrev(self, txt, caseSensitive, wholeWord): |
|
1615 """ |
|
1616 Public method to search the previous occurrence of the given text. |
|
1617 |
|
1618 @param txt text to search for (string) |
|
1619 @param caseSensitive flag indicating to perform a case sensitive |
|
1620 search (boolean) |
|
1621 @param wholeWord flag indicating to search for whole words |
|
1622 only (boolean) |
|
1623 """ |
|
1624 self.__lastSearch = (txt, caseSensitive, wholeWord) |
|
1625 if self.hasSelectedText(): |
|
1626 line, index = self.getSelection()[:2] |
|
1627 else: |
|
1628 line, index = -1, -1 |
|
1629 ok = self.findFirst(txt, False, caseSensitive, wholeWord, False, forward=False, |
|
1630 line=line, index=index) |
|
1631 self.searchStringFound.emit(ok) |