Added find and shortcuts to tooltips

This commit is contained in:
Raoul Snyman 2014-04-04 16:04:10 +02:00
parent f17d548b0b
commit 868bce0626
5 changed files with 138 additions and 20 deletions

View File

@ -8,9 +8,9 @@ class CWebView(QtWebKit.QWebView):
"""
This is a reimplementation of QWebView in order to override the wheelEvent method.
"""
onScroll = QtCore.pyqtSignal()
scrolled = QtCore.pyqtSignal()
def wheelEvent(self, event):
self.onScroll.emit()
self.scrolled.emit()
QtWebKit.QWebView.wheelEvent(self, event)

View File

@ -3,7 +3,7 @@ import os
import threading
from string import printable
from PyQt4 import QtCore, QtGui
from PyQt4 import QtCore, QtGui, QtWebKit
from serial import Serial, SerialException
from colourterm import SettingsDialog, ConnectDialog, SComboBox, Highlight, from_utf8, translate, \
@ -40,6 +40,11 @@ class UiMainWindow(object):
self.follow_action = None
self.configure_action = None
self.exit_action = None
self.clear_action = None
self.find_widget = None
self.find_layout = None
self.find_combobox = None
self.find_action = None
def setup_ui(self, main_window):
"""
@ -50,17 +55,32 @@ class UiMainWindow(object):
self.central_widget = QtGui.QWidget(main_window)
self.central_widget.setObjectName(from_utf8('central_widget'))
self.central_layout = QtGui.QVBoxLayout(self.central_widget)
self.central_layout.setSpacing(8)
self.central_layout.setContentsMargins(0, 0, 0, 8)
self.central_layout.setObjectName(from_utf8('centralLayout'))
self.central_layout.setSpacing(0)
self.central_layout.setContentsMargins(0, 4, 0, 0)
self.central_layout.setObjectName(from_utf8('central_layout'))
self.find_widget = QtGui.QWidget(main_window)
self.find_widget.setVisible(False)
self.find_widget.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum)
self.find_widget.setObjectName(from_utf8('find_widget'))
self.find_layout = QtGui.QHBoxLayout(self.find_widget)
self.find_layout.setContentsMargins(0, 0, 0, 4)
self.find_layout.setObjectName(from_utf8('find_layout'))
self.find_combobox = SComboBox(self.find_widget)
self.find_combobox.setEditable(True)
self.find_combobox.setEnabled(True)
self.find_combobox.setObjectName(from_utf8('find_combobox'))
self.find_layout.addWidget(self.find_combobox)
self.central_layout.addWidget(self.find_widget)
self.output_browser = CWebView(self.central_widget)
self.output_browser.setHtml('<html><head><style>body { color: %s; font-family: monospace; margin: 0; '
'padding: 0; }</style></head><body><pre></pre></body></html>' %
str(QtGui.QApplication.palette().color(QtGui.QPalette.Text).name()))
self.output_browser.setObjectName(from_utf8('outputBrowser'))
self.output_browser.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.output_browser.setObjectName(from_utf8('output_browser'))
self.central_layout.addWidget(self.output_browser)
self.send_layout = QtGui.QHBoxLayout()
self.send_layout.setSpacing(8)
self.send_layout.setContentsMargins(0, 4, 0, 0)
self.send_layout.setObjectName(from_utf8('sendLayout'))
self.send_combobox = SComboBox(self.central_widget)
self.send_combobox.setEditable(True)
@ -100,7 +120,17 @@ class UiMainWindow(object):
disconnect_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/network-disconnect.png')),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.close_action.setIcon(disconnect_icon)
self.close_action.setShortcut(QtGui.QKeySequence.Close)
self.close_action.setObjectName(from_utf8('close_action'))
self.find_action = QtGui.QAction(main_window)
find_icon = QtGui.QIcon()
find_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/find.png')),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.find_action.setIcon(find_icon)
self.find_action.setShortcut(QtGui.QKeySequence.Find)
self.find_action.setCheckable(True)
self.find_action.setChecked(False)
self.find_action.setObjectName(from_utf8('find_action'))
self.capture_action = QtGui.QAction(main_window)
capture_icon = QtGui.QIcon()
capture_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/capture-to-disk.png')),
@ -139,9 +169,12 @@ class UiMainWindow(object):
self.exit_action.setObjectName(from_utf8('exit_action'))
self.tool_bar.addAction(self.open_action)
self.tool_bar.addAction(self.close_action)
self.tool_bar.addSeparator()
self.tool_bar.addAction(self.find_action)
self.tool_bar.addAction(self.capture_action)
self.tool_bar.addAction(self.follow_action)
self.tool_bar.addAction(self.clear_action)
self.tool_bar.addSeparator()
self.tool_bar.addAction(self.configure_action)
self.tool_bar.addAction(self.exit_action)
@ -153,18 +186,26 @@ class UiMainWindow(object):
"""
main_window.setWindowTitle(translate('MainWindow', 'ColourTerm'))
self.send_button.setText(translate('MainWindow', 'Send'))
self.tool_bar.setWindowTitle(translate('MainWindow', 'tool_bar'))
self.tool_bar.setWindowTitle(translate('MainWindow', 'Tool Bar'))
self.open_action.setText(translate('MainWindow', 'Open...'))
self.open_action.setToolTip(translate('MainWindow', 'Open...'))
self.open_action.setToolTip(translate('MainWindow',
'Open (%s)' % QtGui.QKeySequence(QtGui.QKeySequence.Open).toString()))
self.close_action.setText(translate('MainWindow', 'Close'))
self.close_action.setToolTip(translate('MainWindow', 'Close'))
self.close_action.setToolTip(translate('MainWindow',
'Close (%s)' % QtGui.QKeySequence(QtGui.QKeySequence.Close).toString()))
self.find_action.setText(translate('MainWindow', 'Find'))
self.find_action.setToolTip(translate('MainWindow',
'Find (%s)' % QtGui.QKeySequence(QtGui.QKeySequence.Find).toString()))
self.capture_action.setText(translate('MainWindow', 'Capture'))
self.capture_action.setToolTip(translate('MainWindow', 'Capture to File'))
self.follow_action.setText(translate('MainWindow', '&Follow'))
self.follow_action.setToolTip(translate('MainWindow', 'Follow (Ctrl+Shift+F)'))
self.clear_action.setText(translate('MainWindow', 'Clear'))
self.clear_action.setToolTip(translate('MainWindow', 'Clear (Ctrl+BkSpace)'))
self.configure_action.setText(translate('MainWindow', 'Configure...'))
self.configure_action.setToolTip(translate('MainWindow', 'Configure...'))
self.exit_action.setText(translate('MainWindow', 'Exit'))
self.exit_action.setToolTip(translate('MainWindow', 'Exit (Alt+F4)'))
class MainWindow(QtGui.QMainWindow, UiMainWindow):
@ -188,15 +229,17 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
self.connect_dialog = ConnectDialog(self)
self.open_action.triggered.connect(self.on_open_action_triggered)
self.close_action.triggered.connect(self.on_close_action_triggered)
self.find_action.triggered.connect(self.on_find_action_toggled)
self.capture_action.toggled.connect(self.on_capture_action_toggled)
self.follow_action.toggled.connect(self.on_follow_action_toggled)
self.clear_action.triggered.connect(self.on_clear_action_triggered)
self.configure_action.triggered.connect(self.on_configure_action_triggered)
self.exit_action.triggered.connect(self.close)
self.find_combobox.keyPressed.connect(self.on_find_combobox_key_pressed)
self.send_combobox.keyPressed.connect(self.on_send_combobox_key_pressed)
self.send_button.clicked.connect(self.on_send_button_clicked)
self.output_browser.page().mainFrame().contentsSizeChanged.connect(self.on_contents_size_changed)
self.output_browser.onScroll.connect(self.on_output_browser_scrolled)
self.output_browser.scrolled.connect(self.on_output_browser_scrolled)
self.updateOutput.connect(self.on_update_output)
self.showMessage.connect(self.on_show_message)
@ -278,6 +321,11 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
self.send_combobox.setEnabled(not self.device_closed)
self.send_button.setEnabled(not self.device_closed)
def on_find_action_toggled(self, enabled):
self.find_widget.setVisible(enabled)
if enabled:
self.find_combobox.setFocus()
def on_capture_action_toggled(self, enabled):
if enabled and not self.capture_file:
if self.capture_filename:
@ -314,6 +362,13 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
self.save_highlights(self.highlights)
self.refresh_output()
def on_find_combobox_key_pressed(self, key):
if key == QtCore.Qt.Key_Return or key == QtCore.Qt.Key_Enter:
self.output_browser.findText(
self.find_combobox.currentText(),
QtWebKit.QWebPage.HighlightAllOccurrences | QtWebKit.QWebPage.FindWrapsAroundDocument
)
def on_send_combobox_key_pressed(self, key):
if key == QtCore.Qt.Key_Return or key == QtCore.Qt.Key_Enter:
self.on_send_button_clicked()
@ -400,7 +455,7 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
for char in output:
if char not in printable:
printable_output += u'\\x{:02x}'.format(ord(char))
else:
else:
printable_output += unicode(char, u'utf8')
def save_highlights(self, highlights):

View File

@ -2,7 +2,7 @@
# Resource object code
#
# Created: Thu Jan 16 15:10:18 2014
# Created: Fri Apr 4 14:42:39 2014
# by: The Resource Compiler for PyQt (Qt v4.8.4)
#
# WARNING! All changes made in this file will be lost!
@ -341,6 +341,63 @@ qt_resource_data = "\
\x30\x3c\x30\xd1\xd8\xaa\xf9\xda\x8d\x91\xcf\xb4\x17\x7e\x01\x5f\
\x22\xaf\xac\xbe\x86\x35\xeb\x00\x00\x00\x00\x49\x45\x4e\x44\xae\
\x42\x60\x82\
\x00\x00\x03\x67\
\x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
\x00\x00\x16\x00\x00\x00\x16\x08\x03\x00\x00\x00\xf3\x6a\x9c\x09\
\x00\x00\x01\xa4\x50\x4c\x54\x45\xff\xff\xff\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
\x2e\x2e\x2e\x2f\x2f\x2f\x16\x16\x16\x1a\x1a\x1a\x10\x10\x10\x00\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x00\x00\x12\x12\x12\x07\x07\x07\x11\x11\x11\
\x05\x05\x05\x05\x05\x05\x03\x03\x03\x05\x05\x05\x01\x01\x01\x00\
\x00\x00\x00\x00\x00\x00\x00\x00\x07\x07\x07\x00\x00\x00\x02\x02\
\x02\x05\x05\x05\x20\x20\x20\x20\x20\x20\x03\x03\x03\x00\x00\x00\
\x14\x14\x14\x16\x16\x16\x14\x14\x14\x15\x15\x15\x0e\x0e\x0e\x3b\
\x3b\x3b\x2c\x2c\x2c\x37\x37\x37\x37\x37\x37\x3f\x3f\x3f\x31\x31\
\x31\x43\x43\x43\x54\x54\x54\x75\x75\x75\x11\x11\x11\x53\x53\x52\
\x55\x54\x53\x3c\x36\x32\x8b\x8b\x8b\x4b\x4b\x4b\x50\x50\x50\x57\
\x57\x57\x20\x20\x20\x42\x42\x42\x4a\x4a\x4a\x51\x3b\x29\x72\x72\
\x72\x81\x81\x81\x84\x7b\x73\x9f\x91\x83\x03\x03\x03\x07\x07\x07\
\x0b\x0b\x0b\x0e\x0e\x0e\x10\x0a\x07\x10\x10\x10\x11\x11\x11\x12\
\x12\x12\x14\x14\x14\x1d\x15\x0f\x1e\x1e\x1e\x1f\x12\x0a\x20\x20\
\x20\x21\x21\x21\x22\x22\x22\x23\x10\x00\x24\x1a\x16\x26\x26\x26\
\x2d\x1c\x11\x2d\x2d\x2d\x30\x27\x21\x36\x20\x0e\x38\x38\x38\x3e\
\x3e\x3e\x41\x41\x41\x44\x20\x03\x47\x47\x47\x49\x49\x49\x4b\x28\
\x0c\x4e\x28\x0c\x52\x44\x39\x52\x52\x52\x54\x54\x54\x55\x55\x55\
\x58\x28\x00\x59\x56\x54\x5d\x5d\x5d\x5f\x3c\x22\x60\x2d\x01\x60\
\x3f\x25\x64\x48\x30\x66\x62\x61\x67\x52\x45\x69\x63\x60\x6c\x34\
\x01\x6f\x6f\x6f\x70\x56\x46\x74\x47\x21\x77\x38\x02\x78\x44\x15\
\x78\x78\x78\x7b\x5d\x43\x7c\x41\x0d\x7c\x65\x50\x7f\x7f\x7f\x83\
\x83\x83\x85\x85\x85\x89\x89\x89\x8a\x8a\x8a\x8e\x8e\x8e\x90\x60\
\x34\x90\x90\x90\x93\x93\x93\x9a\x62\x39\x9a\x63\x3a\xa4\x72\x4b\
\xa9\x79\x55\xb1\x99\x82\xb8\xb8\xb8\xc0\xc0\xc0\x67\x17\x18\xb9\
\x00\x00\x00\x46\x74\x52\x4e\x53\x00\x01\x02\x03\x07\x08\x0d\x0e\
\x1b\x1d\x23\x27\x2e\x33\x43\x59\x66\x81\x82\x84\x8d\x95\x9b\xaa\
\xac\xae\xb5\xb5\xb8\xb9\xc0\xc1\xc7\xcd\xcd\xcd\xcf\xd0\xd2\xd7\
\xdc\xdf\xe9\xea\xf0\xf2\xf5\xf5\xf7\xf7\xf8\xf9\xf9\xf9\xfa\xfb\
\xfb\xfc\xfc\xfd\xfd\xfd\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\x61\xda\
\xb4\x94\x00\x00\x01\x2c\x49\x44\x41\x54\x78\x01\x63\xa0\x39\x60\
\x16\x52\x92\xe6\x61\x60\xe0\x91\x56\x12\x62\x46\x12\xe6\x37\x74\
\xb6\x55\x60\x64\x54\xb0\x75\x36\xe5\x87\x0b\x32\xf1\x29\xda\x07\
\x79\xea\x48\x48\xea\x78\x06\x39\x29\xf2\x31\x41\x44\xd9\xe4\xf5\
\xac\x2a\xb2\x3c\x6c\xeb\xea\x6c\x3d\xb2\x9a\xad\xf4\xe4\xd9\xc0\
\xc2\x22\x26\xf5\x2d\x5d\x35\x7e\x21\x31\x31\x21\x7e\x35\xdd\x2d\
\xf5\x26\x22\x20\x51\x5e\x6d\x87\xd8\xc4\xb8\xc8\x74\x5f\x77\x77\
\xdf\xf4\xc8\x84\xc4\x58\x07\x6d\x5e\x06\x06\x76\x35\xeb\xda\x86\
\xc6\xe2\xe0\x80\x54\x33\xb3\xd4\x80\xe0\xe2\xc6\x86\x5a\x6b\x35\
\x76\x06\x61\xa3\xfc\x30\x2f\xff\xc2\x34\x9f\x70\x5d\xdd\x70\x9f\
\xb4\x42\x7f\xaf\xb0\x7c\x23\x61\x06\x59\x9b\xc0\x94\x92\x82\x88\
\x4c\xef\x38\x7d\xfd\x38\xef\xcc\x88\x82\x92\x94\x40\x1b\x59\x06\
\xf5\xa8\xd0\xe4\xd6\xf6\xdc\x68\x37\x3b\x55\x15\x3b\xb7\xe8\xec\
\x8e\xb6\xe4\xd0\x28\x75\x06\x19\xcb\xf8\xbc\xd2\xb2\x0c\x47\x2d\
\x51\x4e\x0e\x51\x2d\xc7\x8c\xb2\x9c\xea\x24\x4b\x19\x06\x01\x83\
\xca\xf2\xa2\xaa\x26\x0b\x71\x90\xab\xc4\x2d\x9a\xaa\x8a\xca\x2b\
\x0d\x04\x18\x58\xa4\x8c\x5d\x3a\x5d\xcd\x35\xb8\x41\xc2\xdc\x1a\
\xe6\xae\x9d\x2e\xc6\x52\x2c\x0c\x0c\xac\x82\x72\x9a\xca\x62\x5c\
\x10\x1f\x73\x89\x29\x6b\xca\x09\xb2\x42\x03\x10\x25\x34\xa9\x16\
\x2f\x00\x8e\xef\x43\x84\x4e\x93\x12\x3c\x00\x00\x00\x00\x49\x45\
\x4e\x44\xae\x42\x60\x82\
\x00\x00\x04\x79\
\x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
@ -858,6 +915,10 @@ qt_resource_name = "\
\x00\x68\
\x00\x69\x00\x67\x00\x68\x00\x6c\x00\x69\x00\x67\x00\x68\x00\x74\x00\x2d\x00\x61\x00\x64\x00\x64\x00\x2e\x00\x70\x00\x6e\x00\x67\
\
\x00\x08\
\x00\x47\x5a\xe7\
\x00\x66\
\x00\x69\x00\x6e\x00\x64\x00\x2e\x00\x70\x00\x6e\x00\x67\
\x00\x13\
\x04\xc4\x04\x47\
\x00\x6e\
@ -895,7 +956,7 @@ qt_resource_name = "\
qt_resource_struct = "\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x07\x00\x00\x00\x0b\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x08\x00\x00\x00\x0b\
\x00\x00\x00\x14\x00\x02\x00\x00\x00\x08\x00\x00\x00\x03\
\x00\x00\x00\x54\x00\x00\x00\x00\x00\x01\x00\x00\x02\xda\
\x00\x00\x01\x46\x00\x00\x00\x00\x00\x01\x00\x00\x11\x72\
@ -905,13 +966,14 @@ qt_resource_struct = "\
\x00\x00\x00\xea\x00\x00\x00\x00\x00\x01\x00\x00\x0d\x9e\
\x00\x00\x00\xa0\x00\x00\x00\x00\x00\x01\x00\x00\x08\xd2\
\x00\x00\x00\x2a\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x02\x28\x00\x00\x00\x00\x00\x01\x00\x00\x29\x95\
\x00\x00\x01\x6e\x00\x00\x00\x00\x00\x01\x00\x00\x13\xaa\
\x00\x00\x01\xe2\x00\x00\x00\x00\x00\x01\x00\x00\x20\x2b\
\x00\x00\x01\xc2\x00\x00\x00\x00\x00\x01\x00\x00\x1b\xda\
\x00\x00\x01\x9a\x00\x00\x00\x00\x00\x01\x00\x00\x18\x27\
\x00\x00\x02\x10\x00\x00\x00\x00\x00\x01\x00\x00\x24\x9d\
\x00\x00\x02\x5a\x00\x00\x00\x00\x00\x01\x00\x00\x2c\x91\
\x00\x00\x02\x3e\x00\x00\x00\x00\x00\x01\x00\x00\x2d\x00\
\x00\x00\x01\x84\x00\x00\x00\x00\x00\x01\x00\x00\x17\x15\
\x00\x00\x01\xf8\x00\x00\x00\x00\x00\x01\x00\x00\x23\x96\
\x00\x00\x01\xd8\x00\x00\x00\x00\x00\x01\x00\x00\x1f\x45\
\x00\x00\x01\xb0\x00\x00\x00\x00\x00\x01\x00\x00\x1b\x92\
\x00\x00\x02\x26\x00\x00\x00\x00\x00\x01\x00\x00\x28\x08\
\x00\x00\x02\x70\x00\x00\x00\x00\x00\x01\x00\x00\x2f\xfc\
"
def init_resources():

BIN
images/find.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 871 B

View File

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="toolbar">
<file>find.png</file>
<file>capture-to-disk.png</file>
<file>clear.png</file>
<file>follow-output.png</file>