Upgrade to PyQt5
This commit is contained in:
parent
71c579f5c8
commit
b98a31a505
@ -1,22 +1,22 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt4 import QtGui
|
from PyQt5 import QtWidgets
|
||||||
|
|
||||||
from colourterm.mainwindow import MainWindow
|
from colourterm.mainwindow import MainWindow
|
||||||
from colourterm.resources import init_resources, cleanup_resources
|
from colourterm.resources import init_resources, cleanup_resources
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
app.setOrganizationName(u'Snyman')
|
app.setOrganizationName('Snyman')
|
||||||
app.setOrganizationDomain(u'snyman.info')
|
app.setOrganizationDomain('snyman.info')
|
||||||
app.setApplicationName(u'ColourTerm')
|
app.setApplicationName('ColourTerm')
|
||||||
init_resources()
|
init_resources()
|
||||||
main_window = MainWindow()
|
main_window = MainWindow()
|
||||||
main_window.show()
|
main_window.show()
|
||||||
exit_code = app.exec_()
|
exit_code = app.exec()
|
||||||
cleanup_resources()
|
cleanup_resources()
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt5 import QtCore, QtWidgets
|
||||||
try:
|
try:
|
||||||
from_utf8 = QtCore.QString.fromUtf8
|
from_utf8 = QtCore.QString.fromUtf8
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
from_utf8 = lambda s: s
|
def from_utf8(s):
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
class SComboBox(QtGui.QComboBox):
|
class SComboBox(QtWidgets.QComboBox):
|
||||||
"""
|
"""
|
||||||
Special combobox derivative that emits a signal when a key is pressed.
|
Special combobox derivative that emits a signal when a key is pressed.
|
||||||
"""
|
"""
|
||||||
@ -19,7 +20,7 @@ class SComboBox(QtGui.QComboBox):
|
|||||||
Override the inherited keyPressEvent to emit a signal.
|
Override the inherited keyPressEvent to emit a signal.
|
||||||
"""
|
"""
|
||||||
self.keyPressed.emit(event.key())
|
self.keyPressed.emit(event.key())
|
||||||
return QtGui.QComboBox.keyPressEvent(self, event)
|
return QtWidgets.QComboBox.keyPressEvent(self, event)
|
||||||
|
|
||||||
|
|
||||||
class Highlight(object):
|
class Highlight(object):
|
||||||
@ -38,7 +39,7 @@ class Highlight(object):
|
|||||||
|
|
||||||
|
|
||||||
def translate(context, string, description=None):
|
def translate(context, string, description=None):
|
||||||
return QtGui.QApplication.translate(context, string, description, QtGui.QApplication.UnicodeUTF8)
|
return QtWidgets.QApplication.translate(context, string, description)
|
||||||
|
|
||||||
|
|
||||||
def create_default_highlights():
|
def create_default_highlights():
|
||||||
@ -49,8 +50,8 @@ def create_default_highlights():
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
from colourterm.settingsdialog import SettingsDialog
|
from colourterm.settingsdialog import SettingsDialog # noqa
|
||||||
from colourterm.connectdialog import ConnectDialog
|
from colourterm.connectdialog import ConnectDialog # noqa
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['SettingsDialog', 'ConnectDialog', 'SComboBox', 'Highlight', 'translate', 'from_utf8']
|
__all__ = ['SettingsDialog', 'ConnectDialog', 'SComboBox', 'Highlight', 'translate', 'from_utf8']
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt5 import QtWidgets
|
||||||
from serial import Serial, FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS, PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK,\
|
from serial import Serial, FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS, PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK,\
|
||||||
PARITY_SPACE, STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO, SerialException
|
PARITY_SPACE, STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO, SerialException
|
||||||
from serial.tools import list_ports
|
from serial.tools import list_ports
|
||||||
@ -56,21 +56,21 @@ class UiConnectDialog(object):
|
|||||||
"""
|
"""
|
||||||
Set up the user interface
|
Set up the user interface
|
||||||
"""
|
"""
|
||||||
self.device_layout = QtGui.QGridLayout(connect_dialog)
|
self.device_layout = QtWidgets.QGridLayout(connect_dialog)
|
||||||
self.device_layout.setSpacing(8)
|
self.device_layout.setSpacing(8)
|
||||||
self.device_layout.setContentsMargins(8, 8, 8, 0)
|
self.device_layout.setContentsMargins(8, 8, 8, 0)
|
||||||
self.device_layout.setObjectName(from_utf8('device_layout'))
|
self.device_layout.setObjectName(from_utf8('device_layout'))
|
||||||
self.port_label = QtGui.QLabel(connect_dialog)
|
self.port_label = QtWidgets.QLabel(connect_dialog)
|
||||||
self.port_label.setObjectName(from_utf8('port_label'))
|
self.port_label.setObjectName(from_utf8('port_label'))
|
||||||
self.device_layout.addWidget(self.port_label, 0, 0, 1, 1)
|
self.device_layout.addWidget(self.port_label, 0, 0, 1, 1)
|
||||||
self.port_edit = QtGui.QComboBox(connect_dialog)
|
self.port_edit = QtWidgets.QComboBox(connect_dialog)
|
||||||
self.port_edit.setObjectName(from_utf8('port_edit'))
|
self.port_edit.setObjectName(from_utf8('port_edit'))
|
||||||
self.port_edit.setEditable(True)
|
self.port_edit.setEditable(True)
|
||||||
self.device_layout.addWidget(self.port_edit, 0, 1, 1, 1)
|
self.device_layout.addWidget(self.port_edit, 0, 1, 1, 1)
|
||||||
self.baud_label = QtGui.QLabel(connect_dialog)
|
self.baud_label = QtWidgets.QLabel(connect_dialog)
|
||||||
self.baud_label.setObjectName(from_utf8('baud_label'))
|
self.baud_label.setObjectName(from_utf8('baud_label'))
|
||||||
self.device_layout.addWidget(self.baud_label, 1, 0, 1, 1)
|
self.device_layout.addWidget(self.baud_label, 1, 0, 1, 1)
|
||||||
self.baud_combobox = QtGui.QComboBox(connect_dialog)
|
self.baud_combobox = QtWidgets.QComboBox(connect_dialog)
|
||||||
self.baud_combobox.setObjectName(from_utf8('baud_combobox'))
|
self.baud_combobox.setObjectName(from_utf8('baud_combobox'))
|
||||||
self.baud_combobox.addItem(from_utf8(''))
|
self.baud_combobox.addItem(from_utf8(''))
|
||||||
self.baud_combobox.addItem(from_utf8(''))
|
self.baud_combobox.addItem(from_utf8(''))
|
||||||
@ -83,29 +83,29 @@ class UiConnectDialog(object):
|
|||||||
self.baud_combobox.addItem(from_utf8(''))
|
self.baud_combobox.addItem(from_utf8(''))
|
||||||
self.baud_combobox.addItem(from_utf8(''))
|
self.baud_combobox.addItem(from_utf8(''))
|
||||||
self.device_layout.addWidget(self.baud_combobox, 1, 1, 1, 1)
|
self.device_layout.addWidget(self.baud_combobox, 1, 1, 1, 1)
|
||||||
self.data_bits_label = QtGui.QLabel(connect_dialog)
|
self.data_bits_label = QtWidgets.QLabel(connect_dialog)
|
||||||
self.data_bits_label.setObjectName(from_utf8('data_bits_label'))
|
self.data_bits_label.setObjectName(from_utf8('data_bits_label'))
|
||||||
self.device_layout.addWidget(self.data_bits_label, 2, 0, 1, 1)
|
self.device_layout.addWidget(self.data_bits_label, 2, 0, 1, 1)
|
||||||
self.data_bits_combobox = QtGui.QComboBox(connect_dialog)
|
self.data_bits_combobox = QtWidgets.QComboBox(connect_dialog)
|
||||||
self.data_bits_combobox.setObjectName(from_utf8('data_bits_combobox'))
|
self.data_bits_combobox.setObjectName(from_utf8('data_bits_combobox'))
|
||||||
self.data_bits_combobox.addItem(from_utf8(''))
|
self.data_bits_combobox.addItem(from_utf8(''))
|
||||||
self.data_bits_combobox.addItem(from_utf8(''))
|
self.data_bits_combobox.addItem(from_utf8(''))
|
||||||
self.data_bits_combobox.addItem(from_utf8(''))
|
self.data_bits_combobox.addItem(from_utf8(''))
|
||||||
self.data_bits_combobox.addItem(from_utf8(''))
|
self.data_bits_combobox.addItem(from_utf8(''))
|
||||||
self.device_layout.addWidget(self.data_bits_combobox, 2, 1, 1, 1)
|
self.device_layout.addWidget(self.data_bits_combobox, 2, 1, 1, 1)
|
||||||
self.stop_bits_label = QtGui.QLabel(connect_dialog)
|
self.stop_bits_label = QtWidgets.QLabel(connect_dialog)
|
||||||
self.stop_bits_label.setObjectName(from_utf8('stop_bits_label'))
|
self.stop_bits_label.setObjectName(from_utf8('stop_bits_label'))
|
||||||
self.device_layout.addWidget(self.stop_bits_label, 3, 0, 1, 1)
|
self.device_layout.addWidget(self.stop_bits_label, 3, 0, 1, 1)
|
||||||
self.stop_bits_combobox = QtGui.QComboBox(connect_dialog)
|
self.stop_bits_combobox = QtWidgets.QComboBox(connect_dialog)
|
||||||
self.stop_bits_combobox.setObjectName(from_utf8('stop_bits_combobox'))
|
self.stop_bits_combobox.setObjectName(from_utf8('stop_bits_combobox'))
|
||||||
self.stop_bits_combobox.addItem(from_utf8(''))
|
self.stop_bits_combobox.addItem(from_utf8(''))
|
||||||
self.stop_bits_combobox.addItem(from_utf8(''))
|
self.stop_bits_combobox.addItem(from_utf8(''))
|
||||||
self.stop_bits_combobox.addItem(from_utf8(''))
|
self.stop_bits_combobox.addItem(from_utf8(''))
|
||||||
self.device_layout.addWidget(self.stop_bits_combobox, 3, 1, 1, 1)
|
self.device_layout.addWidget(self.stop_bits_combobox, 3, 1, 1, 1)
|
||||||
self.parity_label = QtGui.QLabel(connect_dialog)
|
self.parity_label = QtWidgets.QLabel(connect_dialog)
|
||||||
self.parity_label.setObjectName(from_utf8('parity_label'))
|
self.parity_label.setObjectName(from_utf8('parity_label'))
|
||||||
self.device_layout.addWidget(self.parity_label, 4, 0, 1, 1)
|
self.device_layout.addWidget(self.parity_label, 4, 0, 1, 1)
|
||||||
self.parity_combobox = QtGui.QComboBox(connect_dialog)
|
self.parity_combobox = QtWidgets.QComboBox(connect_dialog)
|
||||||
self.parity_combobox.setObjectName(from_utf8('parity_combobox'))
|
self.parity_combobox.setObjectName(from_utf8('parity_combobox'))
|
||||||
self.parity_combobox.addItem(from_utf8(''))
|
self.parity_combobox.addItem(from_utf8(''))
|
||||||
self.parity_combobox.addItem(from_utf8(''))
|
self.parity_combobox.addItem(from_utf8(''))
|
||||||
@ -113,27 +113,27 @@ class UiConnectDialog(object):
|
|||||||
self.parity_combobox.addItem(from_utf8(''))
|
self.parity_combobox.addItem(from_utf8(''))
|
||||||
self.parity_combobox.addItem(from_utf8(''))
|
self.parity_combobox.addItem(from_utf8(''))
|
||||||
self.device_layout.addWidget(self.parity_combobox, 4, 1, 1, 1)
|
self.device_layout.addWidget(self.parity_combobox, 4, 1, 1, 1)
|
||||||
self.handshake_label = QtGui.QLabel(connect_dialog)
|
self.handshake_label = QtWidgets.QLabel(connect_dialog)
|
||||||
self.handshake_label.setObjectName(from_utf8('handshake_label'))
|
self.handshake_label.setObjectName(from_utf8('handshake_label'))
|
||||||
self.device_layout.addWidget(self.handshake_label, 0, 2, 1, 1)
|
self.device_layout.addWidget(self.handshake_label, 0, 2, 1, 1)
|
||||||
self.software_checkbox = QtGui.QCheckBox(connect_dialog)
|
self.software_checkbox = QtWidgets.QCheckBox(connect_dialog)
|
||||||
self.software_checkbox.setObjectName(from_utf8('software_checkbox'))
|
self.software_checkbox.setObjectName(from_utf8('software_checkbox'))
|
||||||
self.device_layout.addWidget(self.software_checkbox, 0, 3, 1, 1)
|
self.device_layout.addWidget(self.software_checkbox, 0, 3, 1, 1)
|
||||||
self.hardware_checkbox = QtGui.QCheckBox(connect_dialog)
|
self.hardware_checkbox = QtWidgets.QCheckBox(connect_dialog)
|
||||||
self.hardware_checkbox.setObjectName(from_utf8('hardware_checkbox'))
|
self.hardware_checkbox.setObjectName(from_utf8('hardware_checkbox'))
|
||||||
self.device_layout.addWidget(self.hardware_checkbox, 1, 3, 1, 1)
|
self.device_layout.addWidget(self.hardware_checkbox, 1, 3, 1, 1)
|
||||||
self.open_mode_label = QtGui.QLabel(connect_dialog)
|
self.open_mode_label = QtWidgets.QLabel(connect_dialog)
|
||||||
self.open_mode_label.setObjectName(from_utf8('open_mode_label'))
|
self.open_mode_label.setObjectName(from_utf8('open_mode_label'))
|
||||||
self.device_layout.addWidget(self.open_mode_label, 2, 2, 1, 1)
|
self.device_layout.addWidget(self.open_mode_label, 2, 2, 1, 1)
|
||||||
self.reading_checkbox = QtGui.QCheckBox(connect_dialog)
|
self.reading_checkbox = QtWidgets.QCheckBox(connect_dialog)
|
||||||
self.reading_checkbox.setChecked(True)
|
self.reading_checkbox.setChecked(True)
|
||||||
self.reading_checkbox.setObjectName(from_utf8('reading_checkbox'))
|
self.reading_checkbox.setObjectName(from_utf8('reading_checkbox'))
|
||||||
self.device_layout.addWidget(self.reading_checkbox, 2, 3, 1, 1)
|
self.device_layout.addWidget(self.reading_checkbox, 2, 3, 1, 1)
|
||||||
self.writing_checkbox = QtGui.QCheckBox(connect_dialog)
|
self.writing_checkbox = QtWidgets.QCheckBox(connect_dialog)
|
||||||
self.writing_checkbox.setChecked(True)
|
self.writing_checkbox.setChecked(True)
|
||||||
self.writing_checkbox.setObjectName(from_utf8('writing_checkbox'))
|
self.writing_checkbox.setObjectName(from_utf8('writing_checkbox'))
|
||||||
self.device_layout.addWidget(self.writing_checkbox, 3, 3, 1, 1)
|
self.device_layout.addWidget(self.writing_checkbox, 3, 3, 1, 1)
|
||||||
self.button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
|
self.button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
|
||||||
self.device_layout.addWidget(self.button_box, 5, 0, 1, 4)
|
self.device_layout.addWidget(self.button_box, 5, 0, 1, 4)
|
||||||
|
|
||||||
self.retranslate_ui(connect_dialog)
|
self.retranslate_ui(connect_dialog)
|
||||||
@ -181,18 +181,17 @@ class UiConnectDialog(object):
|
|||||||
self.writing_checkbox.setText(translate('ConnectDialog', 'Writing'))
|
self.writing_checkbox.setText(translate('ConnectDialog', 'Writing'))
|
||||||
|
|
||||||
|
|
||||||
class ConnectDialog(QtGui.QDialog, UiConnectDialog):
|
class ConnectDialog(QtWidgets.QDialog, UiConnectDialog):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
#super(ConnectDialog, self).__init__()
|
super().__init__(parent=parent)
|
||||||
QtGui.QDialog.__init__(self, parent=parent)
|
|
||||||
self.setup_ui(self)
|
self.setup_ui(self)
|
||||||
|
|
||||||
def get_port(self):
|
def get_port(self):
|
||||||
return unicode(self.port_edit.currentText())
|
return self.port_edit.currentText()
|
||||||
|
|
||||||
def get_baud(self):
|
def get_baud(self):
|
||||||
return int(unicode(self.baud_combobox.currentText()))
|
return int(self.baud_combobox.currentText())
|
||||||
|
|
||||||
def get_data_bits(self):
|
def get_data_bits(self):
|
||||||
return DATA_BITS[str(self.data_bits_combobox.currentText())]
|
return DATA_BITS[str(self.data_bits_combobox.currentText())]
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
This module contains a child class of QWebView in order to reimplement the wheelEvent event handler.
|
This module contains a child class of QWebView in order to reimplement the wheelEvent event handler.
|
||||||
"""
|
"""
|
||||||
from PyQt4 import QtCore, QtWebKit
|
from PyQt5 import QtCore, QtWebKitWidgets
|
||||||
|
|
||||||
|
|
||||||
class CWebView(QtWebKit.QWebView):
|
class CWebView(QtWebKitWidgets.QWebView):
|
||||||
"""
|
"""
|
||||||
This is a reimplementation of QWebView in order to override the wheelEvent method.
|
This is a reimplementation of QWebView in order to override the wheelEvent method.
|
||||||
"""
|
"""
|
||||||
@ -12,5 +12,4 @@ class CWebView(QtWebKit.QWebView):
|
|||||||
|
|
||||||
def wheelEvent(self, event):
|
def wheelEvent(self, event):
|
||||||
self.scrolled.emit()
|
self.scrolled.emit()
|
||||||
QtWebKit.QWebView.wheelEvent(self, event)
|
super().wheelEvent(event)
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import os
|
|||||||
import threading
|
import threading
|
||||||
from string import printable
|
from string import printable
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui, QtWebKit
|
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebKit
|
||||||
from serial import SerialException, serial_for_url
|
from serial import SerialException, serial_for_url
|
||||||
from select import error as SelectError
|
from select import error as SelectError
|
||||||
from socket import error as SocketError
|
from socket import error as SocketError
|
||||||
@ -13,7 +13,7 @@ from os.path import getsize
|
|||||||
from colourterm import SettingsDialog, ConnectDialog, SComboBox, Highlight, from_utf8, translate, \
|
from colourterm import SettingsDialog, ConnectDialog, SComboBox, Highlight, from_utf8, translate, \
|
||||||
create_default_highlights
|
create_default_highlights
|
||||||
from colourterm.cwebview import CWebView
|
from colourterm.cwebview import CWebView
|
||||||
from colourterm.xmodem import XMODEM1k, XMODEM
|
from colourterm.xmodem import XMODEM
|
||||||
|
|
||||||
|
|
||||||
class MessageType(object):
|
class MessageType(object):
|
||||||
@ -59,17 +59,17 @@ class UiMainWindow(object):
|
|||||||
main_window.setObjectName(from_utf8('MainWindow'))
|
main_window.setObjectName(from_utf8('MainWindow'))
|
||||||
main_window.resize(800, 600)
|
main_window.resize(800, 600)
|
||||||
main_window.setWindowIcon(QtGui.QIcon(':/icons/colourterm-icon.ico'))
|
main_window.setWindowIcon(QtGui.QIcon(':/icons/colourterm-icon.ico'))
|
||||||
self.central_widget = QtGui.QWidget(main_window)
|
self.central_widget = QtWidgets.QWidget(main_window)
|
||||||
self.central_widget.setObjectName(from_utf8('central_widget'))
|
self.central_widget.setObjectName(from_utf8('central_widget'))
|
||||||
self.central_layout = QtGui.QVBoxLayout(self.central_widget)
|
self.central_layout = QtWidgets.QVBoxLayout(self.central_widget)
|
||||||
self.central_layout.setSpacing(0)
|
self.central_layout.setSpacing(0)
|
||||||
self.central_layout.setContentsMargins(0, 0, 0, 0)
|
self.central_layout.setContentsMargins(0, 0, 0, 0)
|
||||||
self.central_layout.setObjectName(from_utf8('central_layout'))
|
self.central_layout.setObjectName(from_utf8('central_layout'))
|
||||||
self.find_widget = QtGui.QWidget(main_window)
|
self.find_widget = QtWidgets.QWidget(main_window)
|
||||||
self.find_widget.setVisible(False)
|
self.find_widget.setVisible(False)
|
||||||
self.find_widget.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum)
|
self.find_widget.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
|
||||||
self.find_widget.setObjectName(from_utf8('find_widget'))
|
self.find_widget.setObjectName(from_utf8('find_widget'))
|
||||||
self.find_layout = QtGui.QHBoxLayout(self.find_widget)
|
self.find_layout = QtWidgets.QHBoxLayout(self.find_widget)
|
||||||
self.find_layout.setContentsMargins(0, 2, 0, 2)
|
self.find_layout.setContentsMargins(0, 2, 0, 2)
|
||||||
self.find_layout.setObjectName(from_utf8('find_layout'))
|
self.find_layout.setObjectName(from_utf8('find_layout'))
|
||||||
self.find_combobox = SComboBox(self.find_widget)
|
self.find_combobox = SComboBox(self.find_widget)
|
||||||
@ -81,11 +81,11 @@ class UiMainWindow(object):
|
|||||||
self.output_browser = CWebView(self.central_widget)
|
self.output_browser = CWebView(self.central_widget)
|
||||||
self.output_browser.setHtml('<html><head><style>body { color: %s; font-family: monospace; margin: 0; '
|
self.output_browser.setHtml('<html><head><style>body { color: %s; font-family: monospace; margin: 0; '
|
||||||
'padding: 0; }</style></head><body><pre></pre></body></html>' %
|
'padding: 0; }</style></head><body><pre></pre></body></html>' %
|
||||||
str(QtGui.QApplication.palette().color(QtGui.QPalette.Text).name()))
|
str(QtWidgets.QApplication.palette().color(QtGui.QPalette.Text).name()))
|
||||||
self.output_browser.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
|
self.output_browser.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
|
||||||
self.output_browser.setObjectName(from_utf8('output_browser'))
|
self.output_browser.setObjectName(from_utf8('output_browser'))
|
||||||
self.central_layout.addWidget(self.output_browser)
|
self.central_layout.addWidget(self.output_browser)
|
||||||
self.send_layout = QtGui.QHBoxLayout()
|
self.send_layout = QtWidgets.QHBoxLayout()
|
||||||
self.send_layout.setSpacing(8)
|
self.send_layout.setSpacing(8)
|
||||||
self.send_layout.setContentsMargins(0, 4, 0, 0)
|
self.send_layout.setContentsMargins(0, 4, 0, 0)
|
||||||
self.send_layout.setObjectName(from_utf8('sendLayout'))
|
self.send_layout.setObjectName(from_utf8('sendLayout'))
|
||||||
@ -94,8 +94,8 @@ class UiMainWindow(object):
|
|||||||
self.send_combobox.setEnabled(False)
|
self.send_combobox.setEnabled(False)
|
||||||
self.send_combobox.setObjectName(from_utf8('sendComboBox'))
|
self.send_combobox.setObjectName(from_utf8('sendComboBox'))
|
||||||
self.send_layout.addWidget(self.send_combobox)
|
self.send_layout.addWidget(self.send_combobox)
|
||||||
self.send_button = QtGui.QPushButton(self.central_widget)
|
self.send_button = QtWidgets.QPushButton(self.central_widget)
|
||||||
size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
|
size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
|
||||||
size_policy.setHorizontalStretch(0)
|
size_policy.setHorizontalStretch(0)
|
||||||
size_policy.setVerticalStretch(0)
|
size_policy.setVerticalStretch(0)
|
||||||
size_policy.setHeightForWidth(self.send_button.sizePolicy().hasHeightForWidth())
|
size_policy.setHeightForWidth(self.send_button.sizePolicy().hasHeightForWidth())
|
||||||
@ -106,30 +106,30 @@ class UiMainWindow(object):
|
|||||||
self.send_layout.addWidget(self.send_button)
|
self.send_layout.addWidget(self.send_button)
|
||||||
self.central_layout.addLayout(self.send_layout)
|
self.central_layout.addLayout(self.send_layout)
|
||||||
main_window.setCentralWidget(self.central_widget)
|
main_window.setCentralWidget(self.central_widget)
|
||||||
self.status_bar = QtGui.QStatusBar(main_window)
|
self.status_bar = QtWidgets.QStatusBar(main_window)
|
||||||
self.status_bar.setObjectName(from_utf8('status_bar'))
|
self.status_bar.setObjectName(from_utf8('status_bar'))
|
||||||
main_window.setStatusBar(self.status_bar)
|
main_window.setStatusBar(self.status_bar)
|
||||||
self.tool_bar = QtGui.QToolBar(main_window)
|
self.tool_bar = QtWidgets.QToolBar(main_window)
|
||||||
self.tool_bar.setMovable(False)
|
self.tool_bar.setMovable(False)
|
||||||
self.tool_bar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
|
self.tool_bar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
|
||||||
self.tool_bar.setFloatable(False)
|
self.tool_bar.setFloatable(False)
|
||||||
self.tool_bar.setObjectName(from_utf8('tool_bar'))
|
self.tool_bar.setObjectName(from_utf8('tool_bar'))
|
||||||
main_window.addToolBar(QtCore.Qt.TopToolBarArea, self.tool_bar)
|
main_window.addToolBar(QtCore.Qt.TopToolBarArea, self.tool_bar)
|
||||||
self.open_action = QtGui.QAction(main_window)
|
self.open_action = QtWidgets.QAction(main_window)
|
||||||
connect_icon = QtGui.QIcon()
|
connect_icon = QtGui.QIcon()
|
||||||
connect_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/network-connect.png')),
|
connect_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/network-connect.png')),
|
||||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
self.open_action.setIcon(connect_icon)
|
self.open_action.setIcon(connect_icon)
|
||||||
self.open_action.setObjectName(from_utf8('open_action'))
|
self.open_action.setObjectName(from_utf8('open_action'))
|
||||||
self.open_action.setShortcut(QtGui.QKeySequence.Open)
|
self.open_action.setShortcut(QtGui.QKeySequence.Open)
|
||||||
self.close_action = QtGui.QAction(main_window)
|
self.close_action = QtWidgets.QAction(main_window)
|
||||||
disconnect_icon = QtGui.QIcon()
|
disconnect_icon = QtGui.QIcon()
|
||||||
disconnect_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/network-disconnect.png')),
|
disconnect_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/network-disconnect.png')),
|
||||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
self.close_action.setIcon(disconnect_icon)
|
self.close_action.setIcon(disconnect_icon)
|
||||||
self.close_action.setShortcut(QtGui.QKeySequence.Close)
|
self.close_action.setShortcut(QtGui.QKeySequence.Close)
|
||||||
self.close_action.setObjectName(from_utf8('close_action'))
|
self.close_action.setObjectName(from_utf8('close_action'))
|
||||||
self.find_action = QtGui.QAction(main_window)
|
self.find_action = QtWidgets.QAction(main_window)
|
||||||
find_icon = QtGui.QIcon()
|
find_icon = QtGui.QIcon()
|
||||||
find_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/find.png')),
|
find_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/find.png')),
|
||||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
@ -138,7 +138,7 @@ class UiMainWindow(object):
|
|||||||
self.find_action.setCheckable(True)
|
self.find_action.setCheckable(True)
|
||||||
self.find_action.setChecked(False)
|
self.find_action.setChecked(False)
|
||||||
self.find_action.setObjectName(from_utf8('find_action'))
|
self.find_action.setObjectName(from_utf8('find_action'))
|
||||||
self.capture_action = QtGui.QAction(main_window)
|
self.capture_action = QtWidgets.QAction(main_window)
|
||||||
capture_icon = QtGui.QIcon()
|
capture_icon = QtGui.QIcon()
|
||||||
capture_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/capture-to-disk.png')),
|
capture_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/capture-to-disk.png')),
|
||||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
@ -146,7 +146,7 @@ class UiMainWindow(object):
|
|||||||
self.capture_action.setCheckable(True)
|
self.capture_action.setCheckable(True)
|
||||||
self.capture_action.setChecked(False)
|
self.capture_action.setChecked(False)
|
||||||
self.capture_action.setObjectName(from_utf8('capture_action'))
|
self.capture_action.setObjectName(from_utf8('capture_action'))
|
||||||
self.follow_action = QtGui.QAction(main_window)
|
self.follow_action = QtWidgets.QAction(main_window)
|
||||||
self.follow_action.setShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.SHIFT + QtCore.Qt.Key_F))
|
self.follow_action.setShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.SHIFT + QtCore.Qt.Key_F))
|
||||||
follow_icon = QtGui.QIcon()
|
follow_icon = QtGui.QIcon()
|
||||||
follow_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/follow-output.png')),
|
follow_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/follow-output.png')),
|
||||||
@ -155,7 +155,7 @@ class UiMainWindow(object):
|
|||||||
self.follow_action.setCheckable(True)
|
self.follow_action.setCheckable(True)
|
||||||
self.follow_action.setChecked(True)
|
self.follow_action.setChecked(True)
|
||||||
self.follow_action.setObjectName(from_utf8('follow_action'))
|
self.follow_action.setObjectName(from_utf8('follow_action'))
|
||||||
self.clear_action = QtGui.QAction(main_window)
|
self.clear_action = QtWidgets.QAction(main_window)
|
||||||
clear_icon = QtGui.QIcon()
|
clear_icon = QtGui.QIcon()
|
||||||
clear_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/clear.png')),
|
clear_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/clear.png')),
|
||||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
@ -163,21 +163,21 @@ class UiMainWindow(object):
|
|||||||
self.clear_action.setObjectName(from_utf8('clear_action'))
|
self.clear_action.setObjectName(from_utf8('clear_action'))
|
||||||
self.clear_action.setShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_Backspace))
|
self.clear_action.setShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_Backspace))
|
||||||
|
|
||||||
self.xmodem_action = QtGui.QAction(main_window)
|
self.xmodem_action = QtWidgets.QAction(main_window)
|
||||||
xmodem_icon = QtGui.QIcon()
|
xmodem_icon = QtGui.QIcon()
|
||||||
xmodem_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/move-up.png')),
|
xmodem_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/move-up.png')),
|
||||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
self.xmodem_action.setIcon(xmodem_icon)
|
self.xmodem_action.setIcon(xmodem_icon)
|
||||||
self.xmodem_action.setObjectName(from_utf8('xmodem_action'))
|
self.xmodem_action.setObjectName(from_utf8('xmodem_action'))
|
||||||
self.xmodem_action.setShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.SHIFT + QtCore.Qt.Key_X))
|
self.xmodem_action.setShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.SHIFT + QtCore.Qt.Key_X))
|
||||||
|
|
||||||
self.configure_action = QtGui.QAction(main_window)
|
self.configure_action = QtWidgets.QAction(main_window)
|
||||||
configure_icon = QtGui.QIcon()
|
configure_icon = QtGui.QIcon()
|
||||||
configure_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/configure.png')),
|
configure_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/configure.png')),
|
||||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
self.configure_action.setIcon(configure_icon)
|
self.configure_action.setIcon(configure_icon)
|
||||||
self.configure_action.setObjectName(from_utf8('configure_action'))
|
self.configure_action.setObjectName(from_utf8('configure_action'))
|
||||||
self.exit_action = QtGui.QAction(main_window)
|
self.exit_action = QtWidgets.QAction(main_window)
|
||||||
exit_icon = QtGui.QIcon()
|
exit_icon = QtGui.QIcon()
|
||||||
exit_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/application-exit.png')),
|
exit_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/application-exit.png')),
|
||||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
@ -205,14 +205,14 @@ class UiMainWindow(object):
|
|||||||
self.send_button.setText(translate('MainWindow', 'Send'))
|
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.setText(translate('MainWindow', 'Open...'))
|
||||||
self.open_action.setToolTip(translate('MainWindow',
|
self.open_action.setToolTip(translate(
|
||||||
'Open (%s)' % QtGui.QKeySequence(QtGui.QKeySequence.Open).toString()))
|
'MainWindow', 'Open (%s)' % QtGui.QKeySequence(QtGui.QKeySequence.Open)))
|
||||||
self.close_action.setText(translate('MainWindow', 'Close'))
|
self.close_action.setText(translate('MainWindow', 'Close'))
|
||||||
self.close_action.setToolTip(translate('MainWindow',
|
self.close_action.setToolTip(translate(
|
||||||
'Close (%s)' % QtGui.QKeySequence(QtGui.QKeySequence.Close).toString()))
|
'MainWindow', 'Close (%s)' % QtGui.QKeySequence(QtGui.QKeySequence.Close)))
|
||||||
self.find_action.setText(translate('MainWindow', 'Find'))
|
self.find_action.setText(translate('MainWindow', 'Find'))
|
||||||
self.find_action.setToolTip(translate('MainWindow',
|
self.find_action.setToolTip(translate(
|
||||||
'Find (%s)' % QtGui.QKeySequence(QtGui.QKeySequence.Find).toString()))
|
'MainWindow', 'Find (%s)' % QtGui.QKeySequence(QtGui.QKeySequence.Find)))
|
||||||
self.capture_action.setText(translate('MainWindow', 'Capture'))
|
self.capture_action.setText(translate('MainWindow', 'Capture'))
|
||||||
self.capture_action.setToolTip(translate('MainWindow', 'Capture to File'))
|
self.capture_action.setToolTip(translate('MainWindow', 'Capture to File'))
|
||||||
self.follow_action.setText(translate('MainWindow', '&Follow'))
|
self.follow_action.setText(translate('MainWindow', '&Follow'))
|
||||||
@ -227,7 +227,7 @@ class UiMainWindow(object):
|
|||||||
self.exit_action.setToolTip(translate('MainWindow', 'Exit (Alt+F4)'))
|
self.exit_action.setToolTip(translate('MainWindow', 'Exit (Alt+F4)'))
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
class MainWindow(QtWidgets.QMainWindow, UiMainWindow):
|
||||||
updateOutput = QtCore.pyqtSignal(str)
|
updateOutput = QtCore.pyqtSignal(str)
|
||||||
showMessage = QtCore.pyqtSignal(str, str, int)
|
showMessage = QtCore.pyqtSignal(str, str, int)
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
self.device_closed = True
|
self.device_closed = True
|
||||||
self.follow_output = True
|
self.follow_output = True
|
||||||
self.capture_file = None
|
self.capture_file = None
|
||||||
self.capture_filename = u''
|
self.capture_filename = ''
|
||||||
self.highlights = self.load_highlights()
|
self.highlights = self.load_highlights()
|
||||||
self.disable_output = False
|
self.disable_output = False
|
||||||
self.xmodem_send_progress_window = None
|
self.xmodem_send_progress_window = None
|
||||||
@ -271,10 +271,10 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
if self.capture_file:
|
if self.capture_file:
|
||||||
self.capture_file.flush()
|
self.capture_file.flush()
|
||||||
self.capture_file.close()
|
self.capture_file.close()
|
||||||
return QtGui.QMainWindow.close(self)
|
return QtWidgets.QMainWindow.close(self)
|
||||||
|
|
||||||
def document_body(self):
|
def document_body(self):
|
||||||
return self.output_browser.page().mainFrame().documentElement().findFirst(u'pre')
|
return self.output_browser.page().mainFrame().documentElement().findFirst('pre')
|
||||||
|
|
||||||
def receive_text(self):
|
def receive_text(self):
|
||||||
output = ''
|
output = ''
|
||||||
@ -285,15 +285,10 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
continue
|
continue
|
||||||
output += self.device.read(1)
|
output += self.device.read(1)
|
||||||
except SerialException as e:
|
except SerialException as e:
|
||||||
self.showMessage.emit(u'Port Error', u'Error reading from serial port: %s' % e, MessageType.Critical)
|
self.showMessage.emit('Port Error', 'Error reading from serial port: %s' % e, MessageType.Critical)
|
||||||
self.on_close_action_triggered()
|
self.on_close_action_triggered()
|
||||||
continue
|
continue
|
||||||
if output.endswith('\r\n'):
|
if output.endswith('\r\n'):
|
||||||
#self.terminal_lines.append(output.strip('\r\n'))
|
|
||||||
#if len(self.terminal_lines) > self.max_lines:
|
|
||||||
# self.terminal_lines = self.terminal_lines[-self.max_lines:]
|
|
||||||
# self.refreshOutput()
|
|
||||||
#else:
|
|
||||||
self.updateOutput.emit(output.strip('\r\n'))
|
self.updateOutput.emit(output.strip('\r\n'))
|
||||||
output = ''
|
output = ''
|
||||||
elif output.endswith('\n'):
|
elif output.endswith('\n'):
|
||||||
@ -303,20 +298,20 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
def on_open_action_triggered(self):
|
def on_open_action_triggered(self):
|
||||||
self.connect_dialog.update_port_combobox()
|
self.connect_dialog.update_port_combobox()
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
self.connect_dialog.set_port(unicode(settings.value(u'previous-port', u'').toString()))
|
self.connect_dialog.set_port(settings.value('previous-port', ''))
|
||||||
if self.connect_dialog.exec_() == QtGui.QDialog.Accepted:
|
if self.connect_dialog.exec_() == QtWidgets.QDialog.Accepted:
|
||||||
if not self.device_closed:
|
if not self.device_closed:
|
||||||
self.device_closed = True
|
self.device_closed = True
|
||||||
self.device.close()
|
self.device.close()
|
||||||
try:
|
try:
|
||||||
port = self.connect_dialog.get_port()
|
port = self.connect_dialog.get_port()
|
||||||
settings.setValue(u'previous-port', port)
|
settings.setValue('previous-port', port)
|
||||||
if isinstance(port, basestring) and port.startswith('COM'):
|
if isinstance(port, str) and port.startswith('COM'):
|
||||||
try:
|
try:
|
||||||
# On Windows ports are 0-based, so strip the COM and subtract 1 from the port number
|
# On Windows ports are 0-based, so strip the COM and subtract 1 from the port number
|
||||||
port = int(port[3:]) - 1
|
port = int(port[3:]) - 1
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
QtGui.QMessageBox.critical(self, 'Error opening port', 'Error: Port is not valid')
|
QtWidgets.QMessageBox.critical(self, 'Error opening port', 'Error: Port is not valid')
|
||||||
return
|
return
|
||||||
self.device = serial_for_url(
|
self.device = serial_for_url(
|
||||||
url=port,
|
url=port,
|
||||||
@ -336,7 +331,7 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
output_thread = threading.Thread(target=self.receive_text)
|
output_thread = threading.Thread(target=self.receive_text)
|
||||||
output_thread.start()
|
output_thread.start()
|
||||||
except SerialException as e:
|
except SerialException as e:
|
||||||
QtGui.QMessageBox.critical(self, 'Error opening port', e.args[0])
|
QtWidgets.QMessageBox.critical(self, 'Error opening port', e.args[0])
|
||||||
self.send_combobox.setEnabled(not self.device_closed)
|
self.send_combobox.setEnabled(not self.device_closed)
|
||||||
self.send_button.setEnabled(not self.device_closed)
|
self.send_button.setEnabled(not self.device_closed)
|
||||||
if self.send_combobox.isEnabled():
|
if self.send_combobox.isEnabled():
|
||||||
@ -361,13 +356,13 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
if self.capture_filename:
|
if self.capture_filename:
|
||||||
base_dir = os.path.basename(self.capture_filename)
|
base_dir = os.path.basename(self.capture_filename)
|
||||||
else:
|
else:
|
||||||
base_dir = u''
|
base_dir = ''
|
||||||
self.capture_filename = QtGui.QFileDialog.getSaveFileName(self, u'Capture To File', base_dir,
|
self.capture_filename = QtWidgets.QFileDialog.getSaveFileName(self, 'Capture To File', base_dir,
|
||||||
u'Text files (*.txt *.log);;All files (*)')
|
'Text files (*.txt *.log);;All files (*)')
|
||||||
self.capture_file = open(self.capture_filename, u'w')
|
self.capture_file = open(self.capture_filename, 'w')
|
||||||
self.status_bar.showMessage(self.capture_filename)
|
self.status_bar.showMessage(self.capture_filename)
|
||||||
elif self.capture_file and not enabled:
|
elif self.capture_file and not enabled:
|
||||||
self.capture_filename = u''
|
self.capture_filename = ''
|
||||||
self.capture_file.flush()
|
self.capture_file.flush()
|
||||||
self.capture_file.close()
|
self.capture_file.close()
|
||||||
self.capture_file = None
|
self.capture_file = None
|
||||||
@ -388,10 +383,10 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
def xmodem_callback(self, total_packets, success_count, error_count):
|
def xmodem_callback(self, total_packets, success_count, error_count):
|
||||||
if self.xmodem_send_progress_window:
|
if self.xmodem_send_progress_window:
|
||||||
self.xmodem_send_progress_window.setValue(success_count)
|
self.xmodem_send_progress_window.setValue(success_count)
|
||||||
print total_packets, success_count, error_count
|
print('{} {} {}'.format(total_packets, success_count, error_count))
|
||||||
|
|
||||||
def on_xmodem_action_triggered(self):
|
def on_xmodem_action_triggered(self):
|
||||||
file_dialog = QtGui.QFileDialog()
|
file_dialog = QtWidgets.QFileDialog()
|
||||||
if file_dialog.exec_():
|
if file_dialog.exec_():
|
||||||
self.disable_output = True
|
self.disable_output = True
|
||||||
try:
|
try:
|
||||||
@ -401,7 +396,7 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
self.device.flushOutput()
|
self.device.flushOutput()
|
||||||
xmodem_transfer = XMODEM(self.getc, self.putc, mode='xmodem1k', pad='\xff')
|
xmodem_transfer = XMODEM(self.getc, self.putc, mode='xmodem1k', pad='\xff')
|
||||||
stream = open(upload_file, 'rb')
|
stream = open(upload_file, 'rb')
|
||||||
self.xmodem_send_progress_window = QtGui.QProgressDialog(u'Sending File...', u'', 0, 0)
|
self.xmodem_send_progress_window = QtWidgets.QProgressDialog('Sending File...', '', 0, 0)
|
||||||
self.xmodem_send_progress_window.setCancelButton(None)
|
self.xmodem_send_progress_window.setCancelButton(None)
|
||||||
self.xmodem_send_progress_window.setMinimum(0)
|
self.xmodem_send_progress_window.setMinimum(0)
|
||||||
self.xmodem_send_progress_window.setMaximum(file_size/1024)
|
self.xmodem_send_progress_window.setMaximum(file_size/1024)
|
||||||
@ -409,7 +404,7 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
self.xmodem_send_progress_window.setModal(True)
|
self.xmodem_send_progress_window.setModal(True)
|
||||||
self.xmodem_send_progress_window.show()
|
self.xmodem_send_progress_window.show()
|
||||||
success = xmodem_transfer.send(stream, retry=200, callback=self.xmodem_callback)
|
success = xmodem_transfer.send(stream, retry=200, callback=self.xmodem_callback)
|
||||||
print success
|
print(success)
|
||||||
finally:
|
finally:
|
||||||
if self.xmodem_send_progress_window:
|
if self.xmodem_send_progress_window:
|
||||||
self.xmodem_send_progress_window.close()
|
self.xmodem_send_progress_window.close()
|
||||||
@ -454,14 +449,9 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
self.output_browser.update()
|
self.output_browser.update()
|
||||||
|
|
||||||
def on_update_output(self, output):
|
def on_update_output(self, output):
|
||||||
#self.terminal_lines.append(output)
|
|
||||||
if self.capture_file:
|
if self.capture_file:
|
||||||
self.capture_file.write(output + '\n')
|
self.capture_file.write(output + '\n')
|
||||||
self.capture_file.flush()
|
self.capture_file.flush()
|
||||||
#if len(self.terminal_lines) > 5000:
|
|
||||||
# self.terminal_lines = self.terminal_lines[-5000:]
|
|
||||||
# self.refreshOutput()
|
|
||||||
#else:
|
|
||||||
output = self.style_output(output)
|
output = self.style_output(output)
|
||||||
self.document_body().appendInside(output)
|
self.document_body().appendInside(output)
|
||||||
|
|
||||||
@ -477,17 +467,17 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
|
|
||||||
def on_show_message(self, title, message, type_=MessageType.Info):
|
def on_show_message(self, title, message, type_=MessageType.Info):
|
||||||
if type_ == MessageType.Info:
|
if type_ == MessageType.Info:
|
||||||
QtGui.QMessageBox.information(self, title, message)
|
QtWidgets.QMessageBox.information(self, title, message)
|
||||||
elif type_ == MessageType.Question:
|
elif type_ == MessageType.Question:
|
||||||
QtGui.QMessageBox.question(self, title, message)
|
QtWidgets.QMessageBox.question(self, title, message)
|
||||||
elif type_ == MessageType.Warning:
|
elif type_ == MessageType.Warning:
|
||||||
QtGui.QMessageBox.warning(self, title, message)
|
QtWidgets.QMessageBox.warning(self, title, message)
|
||||||
elif type_ == MessageType.Critical:
|
elif type_ == MessageType.Critical:
|
||||||
QtGui.QMessageBox.critical(self, title, message)
|
QtWidgets.QMessageBox.critical(self, title, message)
|
||||||
|
|
||||||
def refresh_output(self):
|
def refresh_output(self):
|
||||||
elements = self.output_browser.page().mainFrame().findAllElements('div')
|
elements = self.output_browser.page().mainFrame().findAllElements('div')
|
||||||
lines = [unicode(element.toPlainText()) for element in elements]
|
lines = [element.toPlainText() for element in elements]
|
||||||
pre = self.output_browser.page().mainFrame().findFirstElement('pre')
|
pre = self.output_browser.page().mainFrame().findFirstElement('pre')
|
||||||
pre.setInnerXml('')
|
pre.setInnerXml('')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
@ -497,59 +487,58 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
self.output_browser.update()
|
self.output_browser.update()
|
||||||
|
|
||||||
def style_output(self, output):
|
def style_output(self, output):
|
||||||
style = u'font-family: \'Ubuntu Mono\', monospace; '
|
style = 'font-family: \'Hack\', \'Ubuntu Mono\', monospace; '
|
||||||
if not output:
|
if not output:
|
||||||
output = u' '
|
output = ' '
|
||||||
for highlight in self.highlights:
|
for highlight in self.highlights:
|
||||||
if highlight.regex.search(output):
|
if highlight.regex.search(output):
|
||||||
if highlight.foreground:
|
if highlight.foreground:
|
||||||
style = u'%scolor: %s; ' % (style, highlight.foreground)
|
style = '%scolor: %s; ' % (style, highlight.foreground)
|
||||||
if highlight.background:
|
if highlight.background:
|
||||||
style = u'%sbackground-color: %s; ' % (style, highlight.background)
|
style = '%sbackground-color: %s; ' % (style, highlight.background)
|
||||||
break
|
break
|
||||||
if style:
|
if style:
|
||||||
try:
|
try:
|
||||||
output = u'<div style="%s">%s</div>' % (style, self.filter_printable(output))
|
output = '<div style="%s">%s</div>' % (style, self.filter_printable(output))
|
||||||
#output = u'<div style="%s">%s</div>' % (style, unicode(output, u'utf-8'))
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
output = u'<div style="%s">%s</div>' % (style, output)
|
output = '<div style="%s">%s</div>' % (style, output)
|
||||||
else:
|
else:
|
||||||
output = u'<div>%s</div>' % output
|
output = '<div>%s</div>' % output
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def filter_printable(self, output):
|
def filter_printable(self, output):
|
||||||
printable_output = u''
|
printable_output = ''
|
||||||
for char in output:
|
for char in output:
|
||||||
if char not in printable:
|
if char not in printable:
|
||||||
printable_output += u'\\x{:02x}'.format(ord(char))
|
printable_output += '\\x{:02x}'.format(ord(char))
|
||||||
else:
|
else:
|
||||||
printable_output += unicode(char, u'utf8')
|
printable_output += str(char, 'utf8')
|
||||||
|
|
||||||
def save_highlights(self, highlights):
|
def save_highlights(self, highlights):
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
settings.setValue(u'highlights/count', len(highlights))
|
settings.setValue('highlights/count', len(highlights))
|
||||||
for index, highlight in enumerate(highlights):
|
for index, highlight in enumerate(highlights):
|
||||||
settings.beginGroup(u'highlight-%s' % index)
|
settings.beginGroup('highlight-%s' % index)
|
||||||
settings.setValue(u'pattern', highlight.pattern)
|
settings.setValue('pattern', highlight.pattern)
|
||||||
settings.setValue(u'foreground', highlight.foreground)
|
settings.setValue('foreground', highlight.foreground)
|
||||||
if highlight.background:
|
if highlight.background:
|
||||||
settings.setValue(u'background', highlight.background)
|
settings.setValue('background', highlight.background)
|
||||||
else:
|
else:
|
||||||
if settings.contains(u'background'):
|
if settings.contains('background'):
|
||||||
settings.remove(u'background')
|
settings.remove('background')
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
||||||
def load_highlights(self):
|
def load_highlights(self):
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
highlight_count = settings.value(u'highlights/count', 0).toInt()[0]
|
highlight_count = settings.value('highlights/count', 0)
|
||||||
highlights = []
|
highlights = []
|
||||||
for index in range(highlight_count):
|
for index in range(highlight_count):
|
||||||
settings.beginGroup(u'highlight-%s' % index)
|
settings.beginGroup('highlight-%s' % index)
|
||||||
pattern = unicode(settings.value(u'pattern', u'').toString())
|
pattern = settings.value('pattern', '')
|
||||||
foreground = unicode(settings.value(u'foreground', u'').toString())
|
foreground = settings.value('foreground', '')
|
||||||
background = None
|
background = None
|
||||||
if settings.contains(u'background'):
|
if settings.contains('background'):
|
||||||
background = unicode(settings.value(u'background', u'').toString())
|
background = settings.value('background', '')
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
highlights.append(Highlight(pattern, foreground, background))
|
highlights.append(Highlight(pattern, foreground, background))
|
||||||
return highlights
|
return highlights
|
||||||
@ -585,7 +574,7 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
try:
|
try:
|
||||||
self.device.write(data)
|
self.device.write(data)
|
||||||
except SerialException as se:
|
except SerialException as se:
|
||||||
self.error(u'Got a SerialException: %s', se)
|
self.error('Got a SerialException: {}'.format(se))
|
||||||
if 'interrupted system call' in str(se.args[0]).lower():
|
if 'interrupted system call' in str(se.args[0]).lower():
|
||||||
self.device.write(data)
|
self.device.write(data)
|
||||||
else:
|
else:
|
||||||
@ -594,6 +583,6 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
|||||||
if se.args[0] == 4:
|
if se.args[0] == 4:
|
||||||
self.device.write(data)
|
self.device.write(data)
|
||||||
else:
|
else:
|
||||||
self.error(u'Got a SocketError or SelectError: %s', se)
|
self.error('Got a SocketError or SelectError: {}'.format(se))
|
||||||
raise Exception(str(se))
|
raise Exception(str(se))
|
||||||
return None
|
return None
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
from colourterm import Highlight, from_utf8, translate
|
from colourterm import Highlight, from_utf8, translate
|
||||||
|
|
||||||
@ -43,15 +43,15 @@ class UiSettingsDialog(object):
|
|||||||
def setup_ui(self, settings_dialog):
|
def setup_ui(self, settings_dialog):
|
||||||
settings_dialog.setObjectName(from_utf8('SettingsDialog'))
|
settings_dialog.setObjectName(from_utf8('SettingsDialog'))
|
||||||
settings_dialog.resize(587, 390)
|
settings_dialog.resize(587, 390)
|
||||||
self.settings_layout = QtGui.QVBoxLayout(settings_dialog)
|
self.settings_layout = QtWidgets.QVBoxLayout(settings_dialog)
|
||||||
self.settings_layout.setSpacing(8)
|
self.settings_layout.setSpacing(8)
|
||||||
self.settings_layout.setMargin(8)
|
self.settings_layout.setContentsMargins(8, 8, 8, 8)
|
||||||
self.settings_layout.setObjectName(from_utf8('settings_layout'))
|
self.settings_layout.setObjectName(from_utf8('settings_layout'))
|
||||||
self.splitter = QtGui.QSplitter(settings_dialog)
|
self.splitter = QtWidgets.QSplitter(settings_dialog)
|
||||||
self.splitter.setOrientation(QtCore.Qt.Horizontal)
|
self.splitter.setOrientation(QtCore.Qt.Horizontal)
|
||||||
self.splitter.setObjectName(from_utf8('splitter'))
|
self.splitter.setObjectName(from_utf8('splitter'))
|
||||||
self.section_list_widget = QtGui.QListWidget(self.splitter)
|
self.section_list_widget = QtWidgets.QListWidget(self.splitter)
|
||||||
size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
|
size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
|
||||||
size_policy.setHorizontalStretch(0)
|
size_policy.setHorizontalStretch(0)
|
||||||
size_policy.setVerticalStretch(0)
|
size_policy.setVerticalStretch(0)
|
||||||
size_policy.setHeightForWidth(self.section_list_widget.sizePolicy().hasHeightForWidth())
|
size_policy.setHeightForWidth(self.section_list_widget.sizePolicy().hasHeightForWidth())
|
||||||
@ -59,120 +59,122 @@ class UiSettingsDialog(object):
|
|||||||
self.section_list_widget.setMinimumSize(QtCore.QSize(100, 0))
|
self.section_list_widget.setMinimumSize(QtCore.QSize(100, 0))
|
||||||
self.section_list_widget.setMaximumSize(QtCore.QSize(200, 16777215))
|
self.section_list_widget.setMaximumSize(QtCore.QSize(200, 16777215))
|
||||||
self.section_list_widget.setObjectName(from_utf8('section_list_widget'))
|
self.section_list_widget.setObjectName(from_utf8('section_list_widget'))
|
||||||
item = QtGui.QListWidgetItem()
|
item = QtWidgets.QListWidgetItem()
|
||||||
self.section_list_widget.addItem(item)
|
self.section_list_widget.addItem(item)
|
||||||
item = QtGui.QListWidgetItem()
|
item = QtWidgets.QListWidgetItem()
|
||||||
self.section_list_widget.addItem(item)
|
self.section_list_widget.addItem(item)
|
||||||
self.section_stacked_widget = QtGui.QStackedWidget(self.splitter)
|
self.section_stacked_widget = QtWidgets.QStackedWidget(self.splitter)
|
||||||
size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
|
size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
|
||||||
size_policy.setHorizontalStretch(0)
|
size_policy.setHorizontalStretch(0)
|
||||||
size_policy.setVerticalStretch(0)
|
size_policy.setVerticalStretch(0)
|
||||||
size_policy.setHeightForWidth(self.section_stacked_widget.sizePolicy().hasHeightForWidth())
|
size_policy.setHeightForWidth(self.section_stacked_widget.sizePolicy().hasHeightForWidth())
|
||||||
self.section_stacked_widget.setSizePolicy(size_policy)
|
self.section_stacked_widget.setSizePolicy(size_policy)
|
||||||
self.section_stacked_widget.setObjectName(from_utf8('section_stacked_widget'))
|
self.section_stacked_widget.setObjectName(from_utf8('section_stacked_widget'))
|
||||||
self.highlight_page = QtGui.QWidget()
|
self.highlight_page = QtWidgets.QWidget()
|
||||||
self.highlight_page.setObjectName(from_utf8('highlight_page'))
|
self.highlight_page.setObjectName(from_utf8('highlight_page'))
|
||||||
self.vertical_layout = QtGui.QVBoxLayout(self.highlight_page)
|
self.vertical_layout = QtWidgets.QVBoxLayout(self.highlight_page)
|
||||||
self.vertical_layout.setObjectName(from_utf8('vertical_layout'))
|
self.vertical_layout.setObjectName(from_utf8('vertical_layout'))
|
||||||
self.highlight_list_widget = QtGui.QListWidget(self.highlight_page)
|
self.highlight_list_widget = QtWidgets.QListWidget(self.highlight_page)
|
||||||
self.highlight_list_widget.setObjectName(from_utf8('highlight_list_widget'))
|
self.highlight_list_widget.setObjectName(from_utf8('highlight_list_widget'))
|
||||||
self.vertical_layout.addWidget(self.highlight_list_widget)
|
self.vertical_layout.addWidget(self.highlight_list_widget)
|
||||||
self.button_layout = QtGui.QHBoxLayout()
|
self.button_layout = QtWidgets.QHBoxLayout()
|
||||||
self.button_layout.setSpacing(8)
|
self.button_layout.setSpacing(8)
|
||||||
self.button_layout.setContentsMargins(0, -1, -1, -1)
|
self.button_layout.setContentsMargins(0, -1, -1, -1)
|
||||||
self.button_layout.setObjectName(from_utf8('button_layout'))
|
self.button_layout.setObjectName(from_utf8('button_layout'))
|
||||||
self.up_button = QtGui.QToolButton(self.highlight_page)
|
self.up_button = QtWidgets.QToolButton(self.highlight_page)
|
||||||
self.up_button.setIcon(QtGui.QIcon(':/settings/move-up.png'))
|
self.up_button.setIcon(QtGui.QIcon(':/settings/move-up.png'))
|
||||||
self.up_button.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
|
self.up_button.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
|
||||||
self.up_button.setFocusPolicy(QtCore.Qt.NoFocus)
|
self.up_button.setFocusPolicy(QtCore.Qt.NoFocus)
|
||||||
self.up_button.setObjectName(from_utf8('up_button'))
|
self.up_button.setObjectName(from_utf8('up_button'))
|
||||||
self.button_layout.addWidget(self.up_button)
|
self.button_layout.addWidget(self.up_button)
|
||||||
self.down_button = QtGui.QToolButton(self.highlight_page)
|
self.down_button = QtWidgets.QToolButton(self.highlight_page)
|
||||||
self.down_button.setIcon(QtGui.QIcon(':/settings/move-down.png'))
|
self.down_button.setIcon(QtGui.QIcon(':/settings/move-down.png'))
|
||||||
self.down_button.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
|
self.down_button.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
|
||||||
self.down_button.setFocusPolicy(QtCore.Qt.NoFocus)
|
self.down_button.setFocusPolicy(QtCore.Qt.NoFocus)
|
||||||
self.down_button.setObjectName(from_utf8('down_button'))
|
self.down_button.setObjectName(from_utf8('down_button'))
|
||||||
self.button_layout.addWidget(self.down_button)
|
self.button_layout.addWidget(self.down_button)
|
||||||
self.button_layout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
|
self.button_layout.addItem(QtWidgets.QSpacerItem(40, 20,
|
||||||
self.add_button = QtGui.QPushButton(self.highlight_page)
|
QtWidgets.QSizePolicy.Expanding,
|
||||||
|
QtWidgets.QSizePolicy.Minimum))
|
||||||
|
self.add_button = QtWidgets.QPushButton(self.highlight_page)
|
||||||
self.add_button.setIcon(QtGui.QIcon(':/settings/highlight-add.png'))
|
self.add_button.setIcon(QtGui.QIcon(':/settings/highlight-add.png'))
|
||||||
self.add_button.setObjectName(from_utf8('add_button'))
|
self.add_button.setObjectName(from_utf8('add_button'))
|
||||||
self.button_layout.addWidget(self.add_button)
|
self.button_layout.addWidget(self.add_button)
|
||||||
self.edit_button = QtGui.QPushButton(self.highlight_page)
|
self.edit_button = QtWidgets.QPushButton(self.highlight_page)
|
||||||
self.edit_button.setIcon(QtGui.QIcon(':/settings/highlight-edit.png'))
|
self.edit_button.setIcon(QtGui.QIcon(':/settings/highlight-edit.png'))
|
||||||
self.edit_button.setObjectName(from_utf8('edit_button'))
|
self.edit_button.setObjectName(from_utf8('edit_button'))
|
||||||
self.button_layout.addWidget(self.edit_button)
|
self.button_layout.addWidget(self.edit_button)
|
||||||
self.delete_button = QtGui.QPushButton(self.highlight_page)
|
self.delete_button = QtWidgets.QPushButton(self.highlight_page)
|
||||||
self.delete_button.setIcon(QtGui.QIcon(':/settings/highlight-remove.png'))
|
self.delete_button.setIcon(QtGui.QIcon(':/settings/highlight-remove.png'))
|
||||||
self.delete_button.setObjectName(from_utf8('delete_button'))
|
self.delete_button.setObjectName(from_utf8('delete_button'))
|
||||||
self.button_layout.addWidget(self.delete_button)
|
self.button_layout.addWidget(self.delete_button)
|
||||||
self.save_button = QtGui.QPushButton(self.highlight_page)
|
self.save_button = QtWidgets.QPushButton(self.highlight_page)
|
||||||
self.save_button.setIcon(QtGui.QIcon(':/settings/highlight-save.png'))
|
self.save_button.setIcon(QtGui.QIcon(':/settings/highlight-save.png'))
|
||||||
self.save_button.setObjectName(from_utf8('save_button'))
|
self.save_button.setObjectName(from_utf8('save_button'))
|
||||||
self.save_button.setVisible(False)
|
self.save_button.setVisible(False)
|
||||||
self.button_layout.addWidget(self.save_button)
|
self.button_layout.addWidget(self.save_button)
|
||||||
self.discard_button = QtGui.QPushButton(self.highlight_page)
|
self.discard_button = QtWidgets.QPushButton(self.highlight_page)
|
||||||
self.discard_button.setIcon(QtGui.QIcon(':/settings/highlight-discard.png'))
|
self.discard_button.setIcon(QtGui.QIcon(':/settings/highlight-discard.png'))
|
||||||
self.discard_button.setObjectName(from_utf8('discard_button'))
|
self.discard_button.setObjectName(from_utf8('discard_button'))
|
||||||
self.discard_button.setVisible(False)
|
self.discard_button.setVisible(False)
|
||||||
self.button_layout.addWidget(self.discard_button)
|
self.button_layout.addWidget(self.discard_button)
|
||||||
self.vertical_layout.addLayout(self.button_layout)
|
self.vertical_layout.addLayout(self.button_layout)
|
||||||
self.highlight_groupbox = QtGui.QGroupBox(self.highlight_page)
|
self.highlight_groupbox = QtWidgets.QGroupBox(self.highlight_page)
|
||||||
self.highlight_groupbox.setObjectName(from_utf8('highlight_groupbox'))
|
self.highlight_groupbox.setObjectName(from_utf8('highlight_groupbox'))
|
||||||
self.highlight_layout = QtGui.QFormLayout(self.highlight_groupbox)
|
self.highlight_layout = QtWidgets.QFormLayout(self.highlight_groupbox)
|
||||||
self.highlight_layout.setMargin(8)
|
self.highlight_layout.setContentsMargins(8, 8, 8, 8)
|
||||||
self.highlight_layout.setSpacing(8)
|
self.highlight_layout.setSpacing(8)
|
||||||
self.highlight_layout.setObjectName(from_utf8('highlight_layout'))
|
self.highlight_layout.setObjectName(from_utf8('highlight_layout'))
|
||||||
self.regex_label = QtGui.QLabel(self.highlight_groupbox)
|
self.regex_label = QtWidgets.QLabel(self.highlight_groupbox)
|
||||||
self.regex_label.setObjectName(from_utf8('regex_label'))
|
self.regex_label.setObjectName(from_utf8('regex_label'))
|
||||||
self.highlight_layout.setWidget(0, QtGui.QFormLayout.LabelRole, self.regex_label)
|
self.highlight_layout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.regex_label)
|
||||||
self.regex_edit = QtGui.QLineEdit(self.highlight_groupbox)
|
self.regex_edit = QtWidgets.QLineEdit(self.highlight_groupbox)
|
||||||
self.regex_edit.setObjectName(from_utf8('regex_edit'))
|
self.regex_edit.setObjectName(from_utf8('regex_edit'))
|
||||||
self.highlight_layout.setWidget(0, QtGui.QFormLayout.FieldRole, self.regex_edit)
|
self.highlight_layout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.regex_edit)
|
||||||
self.foreground_label = QtGui.QLabel(self.highlight_groupbox)
|
self.foreground_label = QtWidgets.QLabel(self.highlight_groupbox)
|
||||||
self.foreground_label.setObjectName(from_utf8('foreground_label'))
|
self.foreground_label.setObjectName(from_utf8('foreground_label'))
|
||||||
self.highlight_layout.setWidget(1, QtGui.QFormLayout.LabelRole, self.foreground_label)
|
self.highlight_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.foreground_label)
|
||||||
self.fg_colour_button = QtGui.QPushButton(self.highlight_groupbox)
|
self.fg_colour_button = QtWidgets.QPushButton(self.highlight_groupbox)
|
||||||
self.fg_colour_button.setText(from_utf8(''))
|
self.fg_colour_button.setText(from_utf8(''))
|
||||||
self.fg_colour_button.setObjectName(from_utf8('fg_colour_button'))
|
self.fg_colour_button.setObjectName(from_utf8('fg_colour_button'))
|
||||||
self.highlight_layout.setWidget(1, QtGui.QFormLayout.FieldRole, self.fg_colour_button)
|
self.highlight_layout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.fg_colour_button)
|
||||||
self.background_checkbox = QtGui.QCheckBox(self.highlight_groupbox)
|
self.background_checkbox = QtWidgets.QCheckBox(self.highlight_groupbox)
|
||||||
self.background_checkbox.setObjectName(from_utf8('background_checkbox'))
|
self.background_checkbox.setObjectName(from_utf8('background_checkbox'))
|
||||||
self.highlight_layout.setWidget(2, QtGui.QFormLayout.LabelRole, self.background_checkbox)
|
self.highlight_layout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.background_checkbox)
|
||||||
self.bg_colour_button = QtGui.QPushButton(self.highlight_groupbox)
|
self.bg_colour_button = QtWidgets.QPushButton(self.highlight_groupbox)
|
||||||
self.bg_colour_button.setText(from_utf8(''))
|
self.bg_colour_button.setText(from_utf8(''))
|
||||||
self.bg_colour_button.setObjectName(from_utf8('bg_colour_button'))
|
self.bg_colour_button.setObjectName(from_utf8('bg_colour_button'))
|
||||||
self.highlight_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.bg_colour_button)
|
self.highlight_layout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.bg_colour_button)
|
||||||
self.vertical_layout.addWidget(self.highlight_groupbox)
|
self.vertical_layout.addWidget(self.highlight_groupbox)
|
||||||
self.section_stacked_widget.addWidget(self.highlight_page)
|
self.section_stacked_widget.addWidget(self.highlight_page)
|
||||||
self.font_page = QtGui.QWidget()
|
self.font_page = QtWidgets.QWidget()
|
||||||
self.font_page.setObjectName(from_utf8('font_page'))
|
self.font_page.setObjectName(from_utf8('font_page'))
|
||||||
self.font_layout = QtGui.QFormLayout(self.font_page)
|
self.font_layout = QtWidgets.QFormLayout(self.font_page)
|
||||||
self.font_layout.setMargin(8)
|
self.font_layout.setContentsMargins(8, 8, 8, 8)
|
||||||
self.font_layout.setSpacing(8)
|
self.font_layout.setSpacing(8)
|
||||||
self.font_layout.setObjectName(from_utf8('font_layout'))
|
self.font_layout.setObjectName(from_utf8('font_layout'))
|
||||||
self.font_label = QtGui.QLabel(self.font_page)
|
self.font_label = QtWidgets.QLabel(self.font_page)
|
||||||
self.font_label.setObjectName(from_utf8('font_label'))
|
self.font_label.setObjectName(from_utf8('font_label'))
|
||||||
self.font_layout.setWidget(0, QtGui.QFormLayout.LabelRole, self.font_label)
|
self.font_layout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.font_label)
|
||||||
self.font_combobox = QtGui.QFontComboBox(self.font_page)
|
self.font_combobox = QtWidgets.QFontComboBox(self.font_page)
|
||||||
self.font_combobox.setObjectName(from_utf8('font_combobox'))
|
self.font_combobox.setObjectName(from_utf8('font_combobox'))
|
||||||
self.font_layout.setWidget(0, QtGui.QFormLayout.FieldRole, self.font_combobox)
|
self.font_layout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.font_combobox)
|
||||||
self.size_label = QtGui.QLabel(self.font_page)
|
self.size_label = QtWidgets.QLabel(self.font_page)
|
||||||
self.size_label.setObjectName(from_utf8('size_label'))
|
self.size_label.setObjectName(from_utf8('size_label'))
|
||||||
self.font_layout.setWidget(1, QtGui.QFormLayout.LabelRole, self.size_label)
|
self.font_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.size_label)
|
||||||
self.size_spinbox = QtGui.QSpinBox(self.font_page)
|
self.size_spinbox = QtWidgets.QSpinBox(self.font_page)
|
||||||
self.size_spinbox.setReadOnly(True)
|
self.size_spinbox.setReadOnly(True)
|
||||||
self.size_spinbox.setSpecialValueText(from_utf8(''))
|
self.size_spinbox.setSpecialValueText(from_utf8(''))
|
||||||
self.size_spinbox.setMinimum(6)
|
self.size_spinbox.setMinimum(6)
|
||||||
self.size_spinbox.setMaximum(50)
|
self.size_spinbox.setMaximum(50)
|
||||||
self.size_spinbox.setProperty('value', 12)
|
self.size_spinbox.setProperty('value', 12)
|
||||||
self.size_spinbox.setObjectName(from_utf8('size_spinbox'))
|
self.size_spinbox.setObjectName(from_utf8('size_spinbox'))
|
||||||
self.font_layout.setWidget(1, QtGui.QFormLayout.FieldRole, self.size_spinbox)
|
self.font_layout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.size_spinbox)
|
||||||
self.section_stacked_widget.addWidget(self.font_page)
|
self.section_stacked_widget.addWidget(self.font_page)
|
||||||
self.settings_layout.addWidget(self.splitter)
|
self.settings_layout.addWidget(self.splitter)
|
||||||
self.button_box = QtGui.QDialogButtonBox(settings_dialog)
|
self.button_box = QtWidgets.QDialogButtonBox(settings_dialog)
|
||||||
self.button_box.setOrientation(QtCore.Qt.Horizontal)
|
self.button_box.setOrientation(QtCore.Qt.Horizontal)
|
||||||
self.button_box.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
|
self.button_box.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
|
||||||
self.button_box.setObjectName(from_utf8('button_box'))
|
self.button_box.setObjectName(from_utf8('button_box'))
|
||||||
self.settings_layout.addWidget(self.button_box)
|
self.settings_layout.addWidget(self.button_box)
|
||||||
|
|
||||||
@ -216,10 +218,10 @@ class UiSettingsDialog(object):
|
|||||||
self.size_spinbox.setSuffix(translate('SettingsDialog', 'pt'))
|
self.size_spinbox.setSuffix(translate('SettingsDialog', 'pt'))
|
||||||
|
|
||||||
|
|
||||||
class SettingsDialog(QtGui.QDialog, UiSettingsDialog):
|
class SettingsDialog(QtWidgets.QDialog, UiSettingsDialog):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtGui.QDialog.__init__(self)
|
QtWidgets.QDialog.__init__(self)
|
||||||
self.setup_ui(self)
|
self.setup_ui(self)
|
||||||
self._highlights = {}
|
self._highlights = {}
|
||||||
self._current_highlight = None
|
self._current_highlight = None
|
||||||
@ -258,10 +260,10 @@ class SettingsDialog(QtGui.QDialog, UiSettingsDialog):
|
|||||||
self.highlight_list_widget.clear()
|
self.highlight_list_widget.clear()
|
||||||
for index, highlight in enumerate(highlights):
|
for index, highlight in enumerate(highlights):
|
||||||
self._highlights[index] = highlight
|
self._highlights[index] = highlight
|
||||||
item = QtGui.QListWidgetItem()
|
item = QtWidgets.QListWidgetItem()
|
||||||
if highlight.background:
|
if highlight.background:
|
||||||
item.setBackgroundColor(QtGui.QColor(highlight.background))
|
item.setBackground(QtGui.QBrush(QtGui.QColor(highlight.background)))
|
||||||
item.setTextColor(QtGui.QColor(highlight.foreground))
|
item.setForeground(QtGui.QBrush(QtGui.QColor(highlight.foreground)))
|
||||||
item.setText(highlight.pattern)
|
item.setText(highlight.pattern)
|
||||||
self.highlight_list_widget.addItem(item)
|
self.highlight_list_widget.addItem(item)
|
||||||
|
|
||||||
@ -271,7 +273,7 @@ class SettingsDialog(QtGui.QDialog, UiSettingsDialog):
|
|||||||
self._current_highlight = self._highlights[self._current_row]
|
self._current_highlight = self._highlights[self._current_row]
|
||||||
|
|
||||||
def on_regex_edit_text_edited(self):
|
def on_regex_edit_text_edited(self):
|
||||||
self._current_highlight.set_pattern(unicode(self.regex_edit.text()))
|
self._current_highlight.set_pattern(self.regex_edit.text())
|
||||||
|
|
||||||
def on_background_checkbox_toggled(self, checked):
|
def on_background_checkbox_toggled(self, checked):
|
||||||
self.bg_colour_button.setEnabled(checked)
|
self.bg_colour_button.setEnabled(checked)
|
||||||
@ -279,18 +281,18 @@ class SettingsDialog(QtGui.QDialog, UiSettingsDialog):
|
|||||||
self._current_highlight.background = None
|
self._current_highlight.background = None
|
||||||
|
|
||||||
def on_fg_colour_button_clicked(self):
|
def on_fg_colour_button_clicked(self):
|
||||||
colour = QtGui.QColor(self._current_highlight.foreground)
|
colour = QtWidgets.QColor(self._current_highlight.foreground)
|
||||||
colour = QtGui.QColorDialog.getColor(colour, self)
|
colour = QtWidgets.QColorDialog.getColor(colour, self)
|
||||||
if colour.isValid():
|
if colour.isValid():
|
||||||
self.fg_colour_button.setStyleSheet('background-color: %s' % colour.name())
|
self.fg_colour_button.setStyleSheet('background-color: %s' % colour.name())
|
||||||
self._current_highlight.foreground = colour.name()
|
self._current_highlight.foreground = colour.name()
|
||||||
|
|
||||||
def on_bg_colour_button_clicked(self):
|
def on_bg_colour_button_clicked(self):
|
||||||
if self._current_highlight.background:
|
if self._current_highlight.background:
|
||||||
colour = QtGui.QColor(self._current_highlight.background)
|
colour = QtWidgets.QColor(self._current_highlight.background)
|
||||||
colour = QtGui.QColorDialog.getColor(colour, self)
|
colour = QtWidgets.QColorDialog.getColor(colour, self)
|
||||||
else:
|
else:
|
||||||
colour = QtGui.QColorDialog.getColor(QtCore.Qt.white, self)
|
colour = QtWidgets.QColorDialog.getColor(QtCore.Qt.white, self)
|
||||||
if colour.isValid():
|
if colour.isValid():
|
||||||
self.bg_colour_button.setStyleSheet('background-color: %s' % colour.name())
|
self.bg_colour_button.setStyleSheet('background-color: %s' % colour.name())
|
||||||
self._current_highlight.background = colour.name()
|
self._current_highlight.background = colour.name()
|
||||||
@ -319,7 +321,7 @@ class SettingsDialog(QtGui.QDialog, UiSettingsDialog):
|
|||||||
|
|
||||||
def on_add_button_clicked(self):
|
def on_add_button_clicked(self):
|
||||||
self._current_row = -1
|
self._current_row = -1
|
||||||
self._current_highlight = Highlight(u'', QtGui.QColor(QtGui.QPalette.WindowText).name())
|
self._current_highlight = Highlight(u'', QtWidgets.QColor(QtWidgets.QPalette.WindowText).name())
|
||||||
self._set_current_highlight()
|
self._set_current_highlight()
|
||||||
self.set_edit_mode(True)
|
self.set_edit_mode(True)
|
||||||
|
|
||||||
@ -328,9 +330,11 @@ class SettingsDialog(QtGui.QDialog, UiSettingsDialog):
|
|||||||
self.set_edit_mode(True)
|
self.set_edit_mode(True)
|
||||||
|
|
||||||
def on_delete_button_clicked(self):
|
def on_delete_button_clicked(self):
|
||||||
if QtGui.QMessageBox.question(self, translate('SettingsDialog', 'Confirm Delete'),
|
if QtWidgets.QMessageBox.question(self, translate('SettingsDialog', 'Confirm Delete'),
|
||||||
translate('SettingsDialog', 'Are you sure you want to delete this highlight?'),
|
translate('SettingsDialog',
|
||||||
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) == QtGui.QMessageBox.Yes:
|
'Are you sure you want to delete this highlight?'),
|
||||||
|
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) == \
|
||||||
|
QtWidgets.QMessageBox.Yes:
|
||||||
del self._highlights[self._current_row]
|
del self._highlights[self._current_row]
|
||||||
self.highlight_list_widget.takeItem(self._current_row)
|
self.highlight_list_widget.takeItem(self._current_row)
|
||||||
self._current_row = -1
|
self._current_row = -1
|
||||||
@ -340,10 +344,10 @@ class SettingsDialog(QtGui.QDialog, UiSettingsDialog):
|
|||||||
if self._current_row < 0:
|
if self._current_row < 0:
|
||||||
new_index = len(self._highlights)
|
new_index = len(self._highlights)
|
||||||
self._highlights[new_index] = self._current_highlight
|
self._highlights[new_index] = self._current_highlight
|
||||||
item = QtGui.QListWidgetItem()
|
item = QtWidgets.QListWidgetItem()
|
||||||
if self._current_highlight.background:
|
if self._current_highlight.background:
|
||||||
item.setBackgroundColor(QtGui.QColor(self._current_highlight.background))
|
item.setBackgroundColor(QtWidgets.QColor(self._current_highlight.background))
|
||||||
item.setTextColor(QtGui.QColor(self._current_highlight.foreground))
|
item.setTextColor(QtWidgets.QColor(self._current_highlight.foreground))
|
||||||
item.setText(self._current_highlight.pattern)
|
item.setText(self._current_highlight.pattern)
|
||||||
self.highlight_list_widget.addItem(item)
|
self.highlight_list_widget.addItem(item)
|
||||||
self.highlight_list_widget.setCurrentRow(new_index)
|
self.highlight_list_widget.setCurrentRow(new_index)
|
||||||
|
Loading…
Reference in New Issue
Block a user