Converted code to PEP8 style
This commit is contained in:
commit
3804d38040
1
.bzrignore
Normal file
1
.bzrignore
Normal file
@ -0,0 +1 @@
|
||||
.idea
|
@ -15,8 +15,8 @@ if __name__ == "__main__":
|
||||
app.setOrganizationDomain(u'snyman.info')
|
||||
app.setApplicationName(u'ColourTerm')
|
||||
init_resources()
|
||||
mainWindow = MainWindow()
|
||||
mainWindow.show()
|
||||
main_window = MainWindow()
|
||||
main_window.show()
|
||||
exit_code = app.exec_()
|
||||
cleanup_resources()
|
||||
sys.exit(exit_code)
|
||||
|
@ -3,9 +3,9 @@ import re
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
try:
|
||||
fromUtf8 = QtCore.QString.fromUtf8
|
||||
from_utf8 = QtCore.QString.fromUtf8
|
||||
except AttributeError:
|
||||
fromUtf8 = lambda s: s
|
||||
from_utf8 = lambda s: s
|
||||
|
||||
|
||||
class SComboBox(QtGui.QComboBox):
|
||||
@ -29,7 +29,7 @@ class Highlight(object):
|
||||
self.foreground = foreground
|
||||
self.background = background
|
||||
|
||||
def setPattern(self, pattern):
|
||||
def set_pattern(self, pattern):
|
||||
self.pattern = pattern
|
||||
try:
|
||||
self.regex = re.compile(pattern)
|
||||
@ -38,8 +38,7 @@ class Highlight(object):
|
||||
|
||||
|
||||
def translate(context, string, description=None):
|
||||
return QtGui.QApplication.translate(context, string, description,
|
||||
QtGui.QApplication.UnicodeUTF8)
|
||||
return QtGui.QApplication.translate(context, string, description, QtGui.QApplication.UnicodeUTF8)
|
||||
|
||||
|
||||
def create_default_highlights():
|
||||
@ -50,8 +49,8 @@ def create_default_highlights():
|
||||
]
|
||||
|
||||
|
||||
from settingsdialog import SettingsDialog
|
||||
from connectdialog import ConnectDialog
|
||||
from colourterm.settingsdialog import SettingsDialog
|
||||
from colourterm.connectdialog import ConnectDialog
|
||||
|
||||
|
||||
__all__ = ['SettingsDialog', 'ConnectDialog', 'SComboBox', 'Highlight', 'translate', 'fromUtf8']
|
||||
__all__ = ['SettingsDialog', 'ConnectDialog', 'SComboBox', 'Highlight', 'translate', 'from_utf8']
|
||||
|
@ -5,7 +5,7 @@ from serial import Serial, FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS, PARITY_NONE,
|
||||
PARITY_SPACE, STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO, SerialException
|
||||
from serial.tools import list_ports
|
||||
|
||||
from colourterm import fromUtf8, translate
|
||||
from colourterm import from_utf8, translate
|
||||
|
||||
|
||||
DATA_BITS = {
|
||||
@ -28,166 +28,196 @@ STOP_BITS = {
|
||||
}
|
||||
|
||||
|
||||
class Ui_ConnectDialog(object):
|
||||
def setupUi(self, connectDialog):
|
||||
self.deviceLayout = QtGui.QGridLayout(connectDialog)
|
||||
self.deviceLayout.setSpacing(8)
|
||||
self.deviceLayout.setContentsMargins(8, 8, 8, 0)
|
||||
self.deviceLayout.setObjectName(fromUtf8('deviceLayout'))
|
||||
self.portLabel = QtGui.QLabel(connectDialog)
|
||||
self.portLabel.setObjectName(fromUtf8('portLabel'))
|
||||
self.deviceLayout.addWidget(self.portLabel, 0, 0, 1, 1)
|
||||
self.portEdit = QtGui.QComboBox(connectDialog)
|
||||
self.portEdit.setObjectName(fromUtf8('portEdit'))
|
||||
self.portEdit.setEditable(True)
|
||||
self.deviceLayout.addWidget(self.portEdit, 0, 1, 1, 1)
|
||||
self.baudLabel = QtGui.QLabel(connectDialog)
|
||||
self.baudLabel.setObjectName(fromUtf8('baudLabel'))
|
||||
self.deviceLayout.addWidget(self.baudLabel, 1, 0, 1, 1)
|
||||
self.baudComboBox = QtGui.QComboBox(connectDialog)
|
||||
self.baudComboBox.setObjectName(fromUtf8('baudComboBox'))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.baudComboBox.addItem(fromUtf8(''))
|
||||
self.deviceLayout.addWidget(self.baudComboBox, 1, 1, 1, 1)
|
||||
self.dataBitsLabel = QtGui.QLabel(connectDialog)
|
||||
self.dataBitsLabel.setObjectName(fromUtf8('dataBitsLabel'))
|
||||
self.deviceLayout.addWidget(self.dataBitsLabel, 2, 0, 1, 1)
|
||||
self.dataBitsComboBox = QtGui.QComboBox(connectDialog)
|
||||
self.dataBitsComboBox.setObjectName(fromUtf8('dataBitsComboBox'))
|
||||
self.dataBitsComboBox.addItem(fromUtf8(''))
|
||||
self.dataBitsComboBox.addItem(fromUtf8(''))
|
||||
self.dataBitsComboBox.addItem(fromUtf8(''))
|
||||
self.dataBitsComboBox.addItem(fromUtf8(''))
|
||||
self.deviceLayout.addWidget(self.dataBitsComboBox, 2, 1, 1, 1)
|
||||
self.stopBitsLabel = QtGui.QLabel(connectDialog)
|
||||
self.stopBitsLabel.setObjectName(fromUtf8('stopBitsLabel'))
|
||||
self.deviceLayout.addWidget(self.stopBitsLabel, 3, 0, 1, 1)
|
||||
self.stopBitsComboBox = QtGui.QComboBox(connectDialog)
|
||||
self.stopBitsComboBox.setObjectName(fromUtf8('stopBitsComboBox'))
|
||||
self.stopBitsComboBox.addItem(fromUtf8(''))
|
||||
self.stopBitsComboBox.addItem(fromUtf8(''))
|
||||
self.stopBitsComboBox.addItem(fromUtf8(''))
|
||||
self.deviceLayout.addWidget(self.stopBitsComboBox, 3, 1, 1, 1)
|
||||
self.parityLabel = QtGui.QLabel(connectDialog)
|
||||
self.parityLabel.setObjectName(fromUtf8('parityLabel'))
|
||||
self.deviceLayout.addWidget(self.parityLabel, 4, 0, 1, 1)
|
||||
self.parityComboBox = QtGui.QComboBox(connectDialog)
|
||||
self.parityComboBox.setObjectName(fromUtf8('parityComboBox'))
|
||||
self.parityComboBox.addItem(fromUtf8(''))
|
||||
self.parityComboBox.addItem(fromUtf8(''))
|
||||
self.parityComboBox.addItem(fromUtf8(''))
|
||||
self.parityComboBox.addItem(fromUtf8(''))
|
||||
self.parityComboBox.addItem(fromUtf8(''))
|
||||
self.deviceLayout.addWidget(self.parityComboBox, 4, 1, 1, 1)
|
||||
self.handshakeLabel = QtGui.QLabel(connectDialog)
|
||||
self.handshakeLabel.setObjectName(fromUtf8('handshakeLabel'))
|
||||
self.deviceLayout.addWidget(self.handshakeLabel, 0, 2, 1, 1)
|
||||
self.softwareCheckBox = QtGui.QCheckBox(connectDialog)
|
||||
self.softwareCheckBox.setObjectName(fromUtf8('softwareCheckBox'))
|
||||
self.deviceLayout.addWidget(self.softwareCheckBox, 0, 3, 1, 1)
|
||||
self.hardwareCheckBox = QtGui.QCheckBox(connectDialog)
|
||||
self.hardwareCheckBox.setObjectName(fromUtf8('hardwareCheckBox'))
|
||||
self.deviceLayout.addWidget(self.hardwareCheckBox, 1, 3, 1, 1)
|
||||
self.openModeLabel = QtGui.QLabel(connectDialog)
|
||||
self.openModeLabel.setObjectName(fromUtf8('openModeLabel'))
|
||||
self.deviceLayout.addWidget(self.openModeLabel, 2, 2, 1, 1)
|
||||
self.readingCheckBox = QtGui.QCheckBox(connectDialog)
|
||||
self.readingCheckBox.setChecked(True)
|
||||
self.readingCheckBox.setObjectName(fromUtf8('readingCheckBox'))
|
||||
self.deviceLayout.addWidget(self.readingCheckBox, 2, 3, 1, 1)
|
||||
self.writingCheckBox = QtGui.QCheckBox(connectDialog)
|
||||
self.writingCheckBox.setChecked(True)
|
||||
self.writingCheckBox.setObjectName(fromUtf8('writingCheckBox'))
|
||||
self.deviceLayout.addWidget(self.writingCheckBox, 3, 3, 1, 1)
|
||||
self.buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
|
||||
self.deviceLayout.addWidget(self.buttonBox, 5, 0, 1, 4)
|
||||
|
||||
self.retranslateUi(connectDialog)
|
||||
self.baudComboBox.setCurrentIndex(4)
|
||||
QtCore.QMetaObject.connectSlotsByName(connectDialog)
|
||||
self.buttonBox.accepted.connect(connectDialog.accept)
|
||||
self.buttonBox.rejected.connect(connectDialog.reject)
|
||||
|
||||
def retranslateUi(self, connectDialog):
|
||||
connectDialog.setWindowTitle(translate('ConnectDialog', 'Open Port'))
|
||||
self.portLabel.setText(translate('ConnectDialog', 'Port:'))
|
||||
self.baudLabel.setText(translate('ConnectDialog', 'Baude rate:'))
|
||||
self.baudComboBox.setItemText(0, translate('ConnectDialog', '921600'))
|
||||
self.baudComboBox.setItemText(1, translate('ConnectDialog', '576000'))
|
||||
self.baudComboBox.setItemText(2, translate('ConnectDialog', '460800'))
|
||||
self.baudComboBox.setItemText(3, translate('ConnectDialog', '230400'))
|
||||
self.baudComboBox.setItemText(4, translate('ConnectDialog', '115200'))
|
||||
self.baudComboBox.setItemText(5, translate('ConnectDialog', '57600'))
|
||||
self.baudComboBox.setItemText(6, translate('ConnectDialog', '38400'))
|
||||
self.baudComboBox.setItemText(7, translate('ConnectDialog', '19200'))
|
||||
self.baudComboBox.setItemText(8, translate('ConnectDialog', '9600'))
|
||||
self.baudComboBox.setItemText(9, translate('ConnectDialog', '4800'))
|
||||
self.dataBitsLabel.setText(translate('ConnectDialog', 'Data bits:'))
|
||||
self.dataBitsComboBox.setItemText(0, translate('ConnectDialog', '8'))
|
||||
self.dataBitsComboBox.setItemText(1, translate('ConnectDialog', '7'))
|
||||
self.dataBitsComboBox.setItemText(2, translate('ConnectDialog', '6'))
|
||||
self.dataBitsComboBox.setItemText(3, translate('ConnectDialog', '5'))
|
||||
self.stopBitsLabel.setText(translate('ConnectDialog', 'Stop bits:'))
|
||||
self.stopBitsComboBox.setItemText(0, translate('ConnectDialog', '1'))
|
||||
self.stopBitsComboBox.setItemText(1, translate('ConnectDialog', '1.5'))
|
||||
self.stopBitsComboBox.setItemText(2, translate('ConnectDialog', '2'))
|
||||
self.parityLabel.setText(translate('ConnectDialog', 'Parity:'))
|
||||
self.parityComboBox.setItemText(0, translate('ConnectDialog', 'None'))
|
||||
self.parityComboBox.setItemText(1, translate('ConnectDialog', 'Odd'))
|
||||
self.parityComboBox.setItemText(2, translate('ConnectDialog', 'Even'))
|
||||
self.parityComboBox.setItemText(3, translate('ConnectDialog', 'Mark'))
|
||||
self.parityComboBox.setItemText(4, translate('ConnectDialog', 'Space'))
|
||||
self.handshakeLabel.setText(translate('ConnectDialog', 'Handshake:'))
|
||||
self.softwareCheckBox.setText(translate('ConnectDialog', 'Software'))
|
||||
self.hardwareCheckBox.setText(translate('ConnectDialog', 'Hardware'))
|
||||
self.openModeLabel.setText(translate('ConnectDialog', 'Open mode:'))
|
||||
self.readingCheckBox.setText(translate('ConnectDialog', 'Reading'))
|
||||
self.writingCheckBox.setText(translate('ConnectDialog', 'Writing'))
|
||||
|
||||
class ConnectDialog(QtGui.QDialog, Ui_ConnectDialog):
|
||||
|
||||
class UiConnectDialog(object):
|
||||
def __init__(self):
|
||||
QtGui.QDialog.__init__(self)
|
||||
self.setupUi(self)
|
||||
"""
|
||||
Just to satisfy PEP8/PyLint
|
||||
"""
|
||||
self.device_layout = None
|
||||
self.port_label = None
|
||||
self.port_edit = None
|
||||
self.baud_label = None
|
||||
self.baud_combobox = None
|
||||
self.data_bits_label = None
|
||||
self.data_bits_combobox = None
|
||||
self.stop_bits_label = None
|
||||
self.stop_bits_combobox = None
|
||||
self.parity_label = None
|
||||
self.parity_combobox = None
|
||||
self.handshake_label = None
|
||||
self.software_checkbox = None
|
||||
self.hardware_checkbox = None
|
||||
self.open_mode_label = None
|
||||
self.reading_checkbox = None
|
||||
self.writing_checkbox = None
|
||||
self.button_box = None
|
||||
|
||||
def getPort(self):
|
||||
return unicode(self.portEdit.currentText())
|
||||
def setup_ui(self, connect_dialog):
|
||||
"""
|
||||
Set up the user interface
|
||||
"""
|
||||
self.device_layout = QtGui.QGridLayout(connect_dialog)
|
||||
self.device_layout.setSpacing(8)
|
||||
self.device_layout.setContentsMargins(8, 8, 8, 0)
|
||||
self.device_layout.setObjectName(from_utf8('device_layout'))
|
||||
self.port_label = QtGui.QLabel(connect_dialog)
|
||||
self.port_label.setObjectName(from_utf8('port_label'))
|
||||
self.device_layout.addWidget(self.port_label, 0, 0, 1, 1)
|
||||
self.port_edit = QtGui.QComboBox(connect_dialog)
|
||||
self.port_edit.setObjectName(from_utf8('port_edit'))
|
||||
self.port_edit.setEditable(True)
|
||||
self.device_layout.addWidget(self.port_edit, 0, 1, 1, 1)
|
||||
self.baud_label = QtGui.QLabel(connect_dialog)
|
||||
self.baud_label.setObjectName(from_utf8('baud_label'))
|
||||
self.device_layout.addWidget(self.baud_label, 1, 0, 1, 1)
|
||||
self.baud_combobox = QtGui.QComboBox(connect_dialog)
|
||||
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(''))
|
||||
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.baud_combobox.addItem(from_utf8(''))
|
||||
self.baud_combobox.addItem(from_utf8(''))
|
||||
self.device_layout.addWidget(self.baud_combobox, 1, 1, 1, 1)
|
||||
self.data_bits_label = QtGui.QLabel(connect_dialog)
|
||||
self.data_bits_label.setObjectName(from_utf8('data_bits_label'))
|
||||
self.device_layout.addWidget(self.data_bits_label, 2, 0, 1, 1)
|
||||
self.data_bits_combobox = QtGui.QComboBox(connect_dialog)
|
||||
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.device_layout.addWidget(self.data_bits_combobox, 2, 1, 1, 1)
|
||||
self.stop_bits_label = QtGui.QLabel(connect_dialog)
|
||||
self.stop_bits_label.setObjectName(from_utf8('stop_bits_label'))
|
||||
self.device_layout.addWidget(self.stop_bits_label, 3, 0, 1, 1)
|
||||
self.stop_bits_combobox = QtGui.QComboBox(connect_dialog)
|
||||
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.device_layout.addWidget(self.stop_bits_combobox, 3, 1, 1, 1)
|
||||
self.parity_label = QtGui.QLabel(connect_dialog)
|
||||
self.parity_label.setObjectName(from_utf8('parity_label'))
|
||||
self.device_layout.addWidget(self.parity_label, 4, 0, 1, 1)
|
||||
self.parity_combobox = QtGui.QComboBox(connect_dialog)
|
||||
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(''))
|
||||
self.parity_combobox.addItem(from_utf8(''))
|
||||
self.device_layout.addWidget(self.parity_combobox, 4, 1, 1, 1)
|
||||
self.handshake_label = QtGui.QLabel(connect_dialog)
|
||||
self.handshake_label.setObjectName(from_utf8('handshake_label'))
|
||||
self.device_layout.addWidget(self.handshake_label, 0, 2, 1, 1)
|
||||
self.software_checkbox = QtGui.QCheckBox(connect_dialog)
|
||||
self.software_checkbox.setObjectName(from_utf8('software_checkbox'))
|
||||
self.device_layout.addWidget(self.software_checkbox, 0, 3, 1, 1)
|
||||
self.hardware_checkbox = QtGui.QCheckBox(connect_dialog)
|
||||
self.hardware_checkbox.setObjectName(from_utf8('hardware_checkbox'))
|
||||
self.device_layout.addWidget(self.hardware_checkbox, 1, 3, 1, 1)
|
||||
self.open_mode_label = QtGui.QLabel(connect_dialog)
|
||||
self.open_mode_label.setObjectName(from_utf8('open_mode_label'))
|
||||
self.device_layout.addWidget(self.open_mode_label, 2, 2, 1, 1)
|
||||
self.reading_checkbox = QtGui.QCheckBox(connect_dialog)
|
||||
self.reading_checkbox.setChecked(True)
|
||||
self.reading_checkbox.setObjectName(from_utf8('reading_checkbox'))
|
||||
self.device_layout.addWidget(self.reading_checkbox, 2, 3, 1, 1)
|
||||
self.writing_checkbox = QtGui.QCheckBox(connect_dialog)
|
||||
self.writing_checkbox.setChecked(True)
|
||||
self.writing_checkbox.setObjectName(from_utf8('writing_checkbox'))
|
||||
self.device_layout.addWidget(self.writing_checkbox, 3, 3, 1, 1)
|
||||
self.button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
|
||||
self.device_layout.addWidget(self.button_box, 5, 0, 1, 4)
|
||||
|
||||
def getBaud(self):
|
||||
return int(unicode(self.baudComboBox.currentText()))
|
||||
self.retranslate_ui(connect_dialog)
|
||||
self.baud_combobox.setCurrentIndex(4)
|
||||
self.button_box.accepted.connect(connect_dialog.accept)
|
||||
self.button_box.rejected.connect(connect_dialog.reject)
|
||||
|
||||
def getDataBits(self):
|
||||
return DATA_BITS[unicode(self.dataBitsComboBox.currentText())]
|
||||
def retranslate_ui(self, connect_dialog):
|
||||
"""
|
||||
Translate the user interface.
|
||||
"""
|
||||
connect_dialog.setWindowTitle(translate('ConnectDialog', 'Open Port'))
|
||||
self.port_label.setText(translate('ConnectDialog', 'Port:'))
|
||||
self.baud_label.setText(translate('ConnectDialog', 'Baude rate:'))
|
||||
self.baud_combobox.setItemText(0, translate('ConnectDialog', '921600'))
|
||||
self.baud_combobox.setItemText(1, translate('ConnectDialog', '576000'))
|
||||
self.baud_combobox.setItemText(2, translate('ConnectDialog', '460800'))
|
||||
self.baud_combobox.setItemText(3, translate('ConnectDialog', '230400'))
|
||||
self.baud_combobox.setItemText(4, translate('ConnectDialog', '115200'))
|
||||
self.baud_combobox.setItemText(5, translate('ConnectDialog', '57600'))
|
||||
self.baud_combobox.setItemText(6, translate('ConnectDialog', '38400'))
|
||||
self.baud_combobox.setItemText(7, translate('ConnectDialog', '19200'))
|
||||
self.baud_combobox.setItemText(8, translate('ConnectDialog', '9600'))
|
||||
self.baud_combobox.setItemText(9, translate('ConnectDialog', '4800'))
|
||||
self.data_bits_label.setText(translate('ConnectDialog', 'Data bits:'))
|
||||
self.data_bits_combobox.setItemText(0, translate('ConnectDialog', '8'))
|
||||
self.data_bits_combobox.setItemText(1, translate('ConnectDialog', '7'))
|
||||
self.data_bits_combobox.setItemText(2, translate('ConnectDialog', '6'))
|
||||
self.data_bits_combobox.setItemText(3, translate('ConnectDialog', '5'))
|
||||
self.stop_bits_label.setText(translate('ConnectDialog', 'Stop bits:'))
|
||||
self.stop_bits_combobox.setItemText(0, translate('ConnectDialog', '1'))
|
||||
self.stop_bits_combobox.setItemText(1, translate('ConnectDialog', '1.5'))
|
||||
self.stop_bits_combobox.setItemText(2, translate('ConnectDialog', '2'))
|
||||
self.parity_label.setText(translate('ConnectDialog', 'Parity:'))
|
||||
self.parity_combobox.setItemText(0, translate('ConnectDialog', 'None'))
|
||||
self.parity_combobox.setItemText(1, translate('ConnectDialog', 'Odd'))
|
||||
self.parity_combobox.setItemText(2, translate('ConnectDialog', 'Even'))
|
||||
self.parity_combobox.setItemText(3, translate('ConnectDialog', 'Mark'))
|
||||
self.parity_combobox.setItemText(4, translate('ConnectDialog', 'Space'))
|
||||
self.handshake_label.setText(translate('ConnectDialog', 'Handshake:'))
|
||||
self.software_checkbox.setText(translate('ConnectDialog', 'Software'))
|
||||
self.hardware_checkbox.setText(translate('ConnectDialog', 'Hardware'))
|
||||
self.open_mode_label.setText(translate('ConnectDialog', 'Open mode:'))
|
||||
self.reading_checkbox.setText(translate('ConnectDialog', 'Reading'))
|
||||
self.writing_checkbox.setText(translate('ConnectDialog', 'Writing'))
|
||||
|
||||
def getStopBits(self):
|
||||
return STOP_BITS[unicode(self.stopBitsComboBox.currentText())]
|
||||
|
||||
def getParity(self):
|
||||
return PARITY_BITS[unicode(self.parityComboBox.currentText())]
|
||||
class ConnectDialog(QtGui.QDialog, UiConnectDialog):
|
||||
|
||||
def getSoftwareHandshake(self):
|
||||
return self.softwareCheckBox.isChecked()
|
||||
def __init__(self, parent):
|
||||
#super(ConnectDialog, self).__init__()
|
||||
QtGui.QDialog.__init__(self, parent=parent)
|
||||
self.setup_ui(self)
|
||||
|
||||
def getHardwareHandshake(self):
|
||||
return self.hardwareCheckBox.isChecked()
|
||||
def get_port(self):
|
||||
return unicode(self.port_edit.currentText())
|
||||
|
||||
def updatePortCombobox(self):
|
||||
self.portEdit.clear()
|
||||
def get_baud(self):
|
||||
return int(unicode(self.baud_combobox.currentText()))
|
||||
|
||||
def get_data_bits(self):
|
||||
return DATA_BITS[str(self.data_bits_combobox.currentText())]
|
||||
|
||||
def get_stop_bits(self):
|
||||
return STOP_BITS[str(self.stop_bits_combobox.currentText())]
|
||||
|
||||
def get_parity(self):
|
||||
return PARITY_BITS[str(self.parity_combobox.currentText())]
|
||||
|
||||
def get_software_handshake(self):
|
||||
return self.software_checkbox.isChecked()
|
||||
|
||||
def get_hardware_handshake(self):
|
||||
return self.hardware_checkbox.isChecked()
|
||||
|
||||
def update_port_combobox(self):
|
||||
self.port_edit.clear()
|
||||
ports = []
|
||||
for port in self._getSerialPorts():
|
||||
for port in self._get_serial_ports():
|
||||
ports.append(port)
|
||||
ports.sort()
|
||||
self.portEdit.addItems(ports)
|
||||
self.port_edit.addItems(ports)
|
||||
|
||||
def _getSerialPorts(self):
|
||||
def _get_serial_ports(self):
|
||||
"""
|
||||
Returns a generator for all available serial ports
|
||||
"""
|
||||
|
@ -3,6 +3,7 @@ This module contains a child class of QWebView in order to reimplement the wheel
|
||||
"""
|
||||
from PyQt4 import QtCore, QtWebKit
|
||||
|
||||
|
||||
class CWebView(QtWebKit.QWebView):
|
||||
"""
|
||||
This is a reimplementation of QWebView in order to override the wheelEvent method.
|
||||
|
@ -5,284 +5,317 @@ import threading
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from serial import Serial, SerialException
|
||||
|
||||
from colourterm import SettingsDialog, ConnectDialog, SComboBox, Highlight, fromUtf8, translate, create_default_highlights
|
||||
from colourterm import SettingsDialog, ConnectDialog, SComboBox, Highlight, from_utf8, translate, \
|
||||
create_default_highlights
|
||||
from colourterm.cwebview import CWebView
|
||||
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
def setupUi(self, mainWindow):
|
||||
mainWindow.setObjectName(fromUtf8('MainWindow'))
|
||||
mainWindow.resize(800, 600)
|
||||
self.centralwidget = QtGui.QWidget(mainWindow)
|
||||
self.centralwidget.setObjectName(fromUtf8('centralwidget'))
|
||||
self.centralLayout = QtGui.QVBoxLayout(self.centralwidget)
|
||||
self.centralLayout.setSpacing(8)
|
||||
self.centralLayout.setContentsMargins(0, 0, 0, 8)
|
||||
self.centralLayout.setObjectName(fromUtf8('centralLayout'))
|
||||
self.outputBrowser = CWebView(self.centralwidget)
|
||||
self.outputBrowser.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.outputBrowser.setObjectName(fromUtf8('outputBrowser'))
|
||||
self.centralLayout.addWidget(self.outputBrowser)
|
||||
self.sendLayout = QtGui.QHBoxLayout()
|
||||
self.sendLayout.setSpacing(8)
|
||||
self.sendLayout.setObjectName(fromUtf8('sendLayout'))
|
||||
self.sendComboBox = SComboBox(self.centralwidget)
|
||||
self.sendComboBox.setEditable(True)
|
||||
self.sendComboBox.setEnabled(False)
|
||||
self.sendComboBox.setObjectName(fromUtf8('sendComboBox'))
|
||||
self.sendLayout.addWidget(self.sendComboBox)
|
||||
self.sendButton = QtGui.QPushButton(self.centralwidget)
|
||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.sendButton.sizePolicy().hasHeightForWidth())
|
||||
self.sendButton.setSizePolicy(sizePolicy)
|
||||
self.sendButton.setMaximumSize(QtCore.QSize(100, 16777215))
|
||||
self.sendButton.setObjectName(fromUtf8('sendButton'))
|
||||
self.sendLayout.addWidget(self.sendButton)
|
||||
self.centralLayout.addLayout(self.sendLayout)
|
||||
mainWindow.setCentralWidget(self.centralwidget)
|
||||
self.statusbar = QtGui.QStatusBar(mainWindow)
|
||||
self.statusbar.setObjectName(fromUtf8('statusbar'))
|
||||
mainWindow.setStatusBar(self.statusbar)
|
||||
self.toolBar = QtGui.QToolBar(mainWindow)
|
||||
self.toolBar.setMovable(False)
|
||||
self.toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
|
||||
self.toolBar.setFloatable(False)
|
||||
self.toolBar.setObjectName(fromUtf8('toolBar'))
|
||||
mainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
|
||||
self.openAction = QtGui.QAction(mainWindow)
|
||||
connectIcon = QtGui.QIcon()
|
||||
connectIcon.addPixmap(QtGui.QPixmap(fromUtf8(':/toolbar/network-connect.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.openAction.setIcon(connectIcon)
|
||||
self.openAction.setObjectName(fromUtf8('openAction'))
|
||||
self.closeAction = QtGui.QAction(mainWindow)
|
||||
disconnectIcon = QtGui.QIcon()
|
||||
disconnectIcon.addPixmap(QtGui.QPixmap(fromUtf8(':/toolbar/network-disconnect.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.closeAction.setIcon(disconnectIcon)
|
||||
self.closeAction.setObjectName(fromUtf8('closeAction'))
|
||||
self.captureAction = QtGui.QAction(mainWindow)
|
||||
captureIcon = QtGui.QIcon()
|
||||
captureIcon.addPixmap(QtGui.QPixmap(fromUtf8(':/toolbar/capture-to-disk.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.captureAction.setIcon(captureIcon)
|
||||
self.captureAction.setCheckable(True)
|
||||
self.captureAction.setChecked(False)
|
||||
self.captureAction.setObjectName(fromUtf8('captureAction'))
|
||||
self.followAction = QtGui.QAction(mainWindow)
|
||||
self.followAction.setShortcut(QtCore.Qt.Key_F)
|
||||
followIcon = QtGui.QIcon()
|
||||
followIcon.addPixmap(QtGui.QPixmap(fromUtf8(':/toolbar/follow-output.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.followAction.setIcon(followIcon)
|
||||
self.followAction.setCheckable(True)
|
||||
self.followAction.setChecked(True)
|
||||
self.followAction.setObjectName(fromUtf8('followAction'))
|
||||
self.configureAction = QtGui.QAction(mainWindow)
|
||||
configureIcon = QtGui.QIcon()
|
||||
configureIcon.addPixmap(QtGui.QPixmap(fromUtf8(':/toolbar/configure.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.configureAction.setIcon(configureIcon)
|
||||
self.configureAction.setObjectName(fromUtf8('configureAction'))
|
||||
self.exitAction = QtGui.QAction(mainWindow)
|
||||
exitIcon = QtGui.QIcon()
|
||||
exitIcon.addPixmap(QtGui.QPixmap(fromUtf8(':/toolbar/application-exit.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.exitAction.setIcon(exitIcon)
|
||||
self.exitAction.setObjectName(fromUtf8('exitAction'))
|
||||
self.toolBar.addAction(self.openAction)
|
||||
self.toolBar.addAction(self.closeAction)
|
||||
self.toolBar.addAction(self.captureAction)
|
||||
self.toolBar.addAction(self.followAction)
|
||||
self.toolBar.addAction(self.configureAction)
|
||||
self.toolBar.addAction(self.exitAction)
|
||||
class UiMainWindow(object):
|
||||
def __init__(self):
|
||||
"""
|
||||
Just to satisfy PEP8/PyLint
|
||||
"""
|
||||
self.central_widget = None
|
||||
self.central_layout = None
|
||||
self.output_browser = None
|
||||
self.send_layout = None
|
||||
self.send_combobox = None
|
||||
self.send_button = None
|
||||
self.status_bar = None
|
||||
self.tool_bar = None
|
||||
self.open_action = None
|
||||
self.close_action = None
|
||||
self.capture_action = None
|
||||
self.follow_action = None
|
||||
self.configure_action = None
|
||||
self.exit_action = None
|
||||
|
||||
self.retranslateUi(mainWindow)
|
||||
QtCore.QMetaObject.connectSlotsByName(mainWindow)
|
||||
def setup_ui(self, main_window):
|
||||
"""
|
||||
Set up the user interface
|
||||
"""
|
||||
main_window.setObjectName(from_utf8('MainWindow'))
|
||||
main_window.resize(800, 600)
|
||||
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.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.central_layout.addWidget(self.output_browser)
|
||||
self.send_layout = QtGui.QHBoxLayout()
|
||||
self.send_layout.setSpacing(8)
|
||||
self.send_layout.setObjectName(from_utf8('sendLayout'))
|
||||
self.send_combobox = SComboBox(self.central_widget)
|
||||
self.send_combobox.setEditable(True)
|
||||
self.send_combobox.setEnabled(False)
|
||||
self.send_combobox.setObjectName(from_utf8('sendComboBox'))
|
||||
self.send_layout.addWidget(self.send_combobox)
|
||||
self.send_button = QtGui.QPushButton(self.central_widget)
|
||||
size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
|
||||
size_policy.setHorizontalStretch(0)
|
||||
size_policy.setVerticalStretch(0)
|
||||
size_policy.setHeightForWidth(self.send_button.sizePolicy().hasHeightForWidth())
|
||||
self.send_button.setSizePolicy(size_policy)
|
||||
self.send_button.setMaximumSize(QtCore.QSize(100, 16777215))
|
||||
self.send_button.setObjectName(from_utf8('sendButton'))
|
||||
self.send_layout.addWidget(self.send_button)
|
||||
self.central_layout.addLayout(self.send_layout)
|
||||
main_window.setCentralWidget(self.central_widget)
|
||||
self.status_bar = QtGui.QStatusBar(main_window)
|
||||
self.status_bar.setObjectName(from_utf8('status_bar'))
|
||||
main_window.setStatusBar(self.status_bar)
|
||||
self.tool_bar = QtGui.QToolBar(main_window)
|
||||
self.tool_bar.setMovable(False)
|
||||
self.tool_bar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
|
||||
self.tool_bar.setFloatable(False)
|
||||
self.tool_bar.setObjectName(from_utf8('tool_bar'))
|
||||
main_window.addToolBar(QtCore.Qt.TopToolBarArea, self.tool_bar)
|
||||
self.open_action = QtGui.QAction(main_window)
|
||||
connect_icon = QtGui.QIcon()
|
||||
connect_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/network-connect.png')),
|
||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.open_action.setIcon(connect_icon)
|
||||
self.open_action.setObjectName(from_utf8('open_action'))
|
||||
self.close_action = QtGui.QAction(main_window)
|
||||
disconnect_icon = QtGui.QIcon()
|
||||
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.setObjectName(from_utf8('close_action'))
|
||||
self.capture_action = QtGui.QAction(main_window)
|
||||
capture_icon = QtGui.QIcon()
|
||||
capture_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/capture-to-disk.png')),
|
||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.capture_action.setIcon(capture_icon)
|
||||
self.capture_action.setCheckable(True)
|
||||
self.capture_action.setChecked(False)
|
||||
self.capture_action.setObjectName(from_utf8('capture_action'))
|
||||
self.follow_action = QtGui.QAction(main_window)
|
||||
self.follow_action.setShortcut(QtCore.Qt.Key_F)
|
||||
follow_icon = QtGui.QIcon()
|
||||
follow_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/follow-output.png')),
|
||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.follow_action.setIcon(follow_icon)
|
||||
self.follow_action.setCheckable(True)
|
||||
self.follow_action.setChecked(True)
|
||||
self.follow_action.setObjectName(from_utf8('follow_action'))
|
||||
self.configure_action = QtGui.QAction(main_window)
|
||||
configure_icon = QtGui.QIcon()
|
||||
configure_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/configure.png')),
|
||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.configure_action.setIcon(configure_icon)
|
||||
self.configure_action.setObjectName(from_utf8('configure_action'))
|
||||
self.exit_action = QtGui.QAction(main_window)
|
||||
exit_icon = QtGui.QIcon()
|
||||
exit_icon.addPixmap(QtGui.QPixmap(from_utf8(':/toolbar/application-exit.png')),
|
||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.exit_action.setIcon(exit_icon)
|
||||
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.addAction(self.capture_action)
|
||||
self.tool_bar.addAction(self.follow_action)
|
||||
self.tool_bar.addAction(self.configure_action)
|
||||
self.tool_bar.addAction(self.exit_action)
|
||||
|
||||
def retranslateUi(self, mainWindow):
|
||||
mainWindow.setWindowTitle(translate('MainWindow', 'ColourTerm'))
|
||||
self.sendButton.setText(translate('MainWindow', 'Send'))
|
||||
self.toolBar.setWindowTitle(translate('MainWindow', 'toolBar'))
|
||||
self.openAction.setText(translate('MainWindow', 'Open...'))
|
||||
self.openAction.setToolTip(translate('MainWindow', 'Open...'))
|
||||
self.closeAction.setText(translate('MainWindow', 'Close'))
|
||||
self.closeAction.setToolTip(translate('MainWindow', 'Close'))
|
||||
self.captureAction.setText(translate('MainWindow', 'Capture'))
|
||||
self.captureAction.setToolTip(translate('MainWindow', 'Capture to File'))
|
||||
self.followAction.setText(translate('MainWindow', '&Follow'))
|
||||
self.configureAction.setText(translate('MainWindow', 'Configure...'))
|
||||
self.configureAction.setToolTip(translate('MainWindow', 'Configure...'))
|
||||
self.exitAction.setText(translate('MainWindow', 'Exit'))
|
||||
self.retranslate_ui(main_window)
|
||||
|
||||
def retranslate_ui(self, main_window):
|
||||
"""
|
||||
Translate the user interface
|
||||
"""
|
||||
main_window.setWindowTitle(translate('MainWindow', 'ColourTerm'))
|
||||
self.send_button.setText(translate('MainWindow', 'Send'))
|
||||
self.tool_bar.setWindowTitle(translate('MainWindow', 'tool_bar'))
|
||||
self.open_action.setText(translate('MainWindow', 'Open...'))
|
||||
self.open_action.setToolTip(translate('MainWindow', 'Open...'))
|
||||
self.close_action.setText(translate('MainWindow', 'Close'))
|
||||
self.close_action.setToolTip(translate('MainWindow', 'Close'))
|
||||
self.capture_action.setText(translate('MainWindow', 'Capture'))
|
||||
self.capture_action.setToolTip(translate('MainWindow', 'Capture to File'))
|
||||
self.follow_action.setText(translate('MainWindow', '&Follow'))
|
||||
self.configure_action.setText(translate('MainWindow', 'Configure...'))
|
||||
self.configure_action.setToolTip(translate('MainWindow', 'Configure...'))
|
||||
self.exit_action.setText(translate('MainWindow', 'Exit'))
|
||||
|
||||
|
||||
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
class MainWindow(QtGui.QMainWindow, UiMainWindow):
|
||||
updateOutput = QtCore.pyqtSignal(str)
|
||||
|
||||
def __init__(self):
|
||||
QtGui.QMainWindow.__init__(self)
|
||||
self.terminalLines = []
|
||||
self.maxLines = 5000
|
||||
self.setupUi(self)
|
||||
super(MainWindow, self).__init__()
|
||||
self.terminal_lines = []
|
||||
self.max_lines = 5000
|
||||
self.setup_ui(self)
|
||||
self.device = None
|
||||
self.deviceClosed = True
|
||||
self.followOutput = True
|
||||
self.captureFile = None
|
||||
self.captureFileName = u''
|
||||
self.highlights = self.loadHighlights()
|
||||
self.device_closed = True
|
||||
self.follow_output = True
|
||||
self.capture_file = None
|
||||
self.capture_filename = u''
|
||||
self.highlights = self.load_highlights()
|
||||
if not self.highlights:
|
||||
self.highlights = create_default_highlights()
|
||||
self.settingsDialog = SettingsDialog()
|
||||
self.connectDialog = ConnectDialog()
|
||||
self.openAction.triggered.connect(self.onOpenActionTriggered)
|
||||
self.closeAction.triggered.connect(self.onCloseActionTriggered)
|
||||
self.captureAction.toggled.connect(self.onCaptureActionToggled)
|
||||
self.followAction.toggled.connect(self.onFollowActionToggled)
|
||||
self.configureAction.triggered.connect(self.onConfigureActionTriggered)
|
||||
self.exitAction.triggered.connect(self.close)
|
||||
self.sendComboBox.keyPressed.connect(self.onSendComboBoxKeyPressed)
|
||||
self.sendButton.clicked.connect(self.onSendButtonClicked)
|
||||
self.outputBrowser.page().mainFrame().contentsSizeChanged.connect(self.onContentsSizeChanged)
|
||||
self.outputBrowser.onScroll.connect(self.onOutputBrowserScrolled)
|
||||
self.updateOutput.connect(self.onUpdateOutput)
|
||||
self.settings_dialog = SettingsDialog()
|
||||
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.capture_action.toggled.connect(self.on_capture_action_toggled)
|
||||
self.follow_action.toggled.connect(self.on_follow_action_toggled)
|
||||
self.configure_action.triggered.connect(self.on_configure_action_triggered)
|
||||
self.exit_action.triggered.connect(self.close)
|
||||
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.updateOutput.connect(self.on_update_output)
|
||||
|
||||
def close(self):
|
||||
if not self.deviceClosed:
|
||||
self.deviceClosed = True
|
||||
if self.captureFile:
|
||||
self.captureFile.flush()
|
||||
self.captureFile.close()
|
||||
if not self.device_closed:
|
||||
self.device_closed = True
|
||||
if self.capture_file:
|
||||
self.capture_file.flush()
|
||||
self.capture_file.close()
|
||||
return QtGui.QMainWindow.close(self)
|
||||
|
||||
def documentBody(self):
|
||||
return self.outputBrowser.page().mainFrame().documentElement().findFirst('pre')
|
||||
def document_body(self):
|
||||
return self.output_browser.page().mainFrame().documentElement().findFirst('pre')
|
||||
|
||||
def receiveText(self):
|
||||
def receive_text(self):
|
||||
output = ''
|
||||
while not self.deviceClosed:
|
||||
while not self.device_closed:
|
||||
output += self.device.read(1)
|
||||
if output.endswith('\r\n'):
|
||||
#self.terminalLines.append(output.strip('\r\n'))
|
||||
#if len(self.terminalLines) > self.maxLines:
|
||||
# self.terminalLines = self.terminalLines[-self.maxLines:]
|
||||
#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'))
|
||||
output = ''
|
||||
|
||||
def onOpenActionTriggered(self):
|
||||
self.connectDialog.updatePortCombobox()
|
||||
if self.connectDialog.exec_() == QtGui.QDialog.Accepted:
|
||||
if not self.deviceClosed:
|
||||
self.deviceClosed = True
|
||||
def on_open_action_triggered(self):
|
||||
self.connect_dialog.update_port_combobox()
|
||||
if self.connect_dialog.exec_() == QtGui.QDialog.Accepted:
|
||||
if not self.device_closed:
|
||||
self.device_closed = True
|
||||
self.device.close()
|
||||
try:
|
||||
self.device = Serial(
|
||||
port=self.connectDialog.getPort(),
|
||||
baudrate=self.connectDialog.getBaud(),
|
||||
bytesize=self.connectDialog.getDataBits(),
|
||||
parity=self.connectDialog.getParity(),
|
||||
stopbits=self.connectDialog.getStopBits(),
|
||||
port=self.connect_dialog.get_port(),
|
||||
baudrate=self.connect_dialog.get_baud(),
|
||||
bytesize=self.connect_dialog.get_data_bits(),
|
||||
parity=self.connect_dialog.get_parity(),
|
||||
stopbits=self.connect_dialog.get_stop_bits(),
|
||||
timeout=0,
|
||||
xonxoff=self.connectDialog.getSoftwareHandshake(),
|
||||
rtscts=self.connectDialog.getHardwareHandshake(),
|
||||
xonxoff=self.connect_dialog.get_software_handshake(),
|
||||
rtscts=self.connect_dialog.get_hardware_handshake(),
|
||||
dsrdtr=None
|
||||
)
|
||||
self.deviceClosed = False
|
||||
self.device_closed = False
|
||||
if not self.device.isOpen():
|
||||
self.device.open()
|
||||
outputThread = threading.Thread(target=self.receiveText)
|
||||
outputThread.start()
|
||||
except SerialException, e:
|
||||
output_thread = threading.Thread(target=self.receive_text)
|
||||
output_thread.start()
|
||||
except SerialException as e:
|
||||
QtGui.QMessageBox.critical(self, 'Error opening port', e.args[0])
|
||||
self.sendComboBox.setEnabled(not self.deviceClosed)
|
||||
if self.sendComboBox.isEnabled():
|
||||
self.sendComboBox.setFocus()
|
||||
self.send_combobox.setEnabled(not self.device_closed)
|
||||
if self.send_combobox.isEnabled():
|
||||
self.send_combobox.setFocus()
|
||||
|
||||
def onCloseActionTriggered(self):
|
||||
self.deviceClosed = True
|
||||
def on_close_action_triggered(self):
|
||||
self.device_closed = True
|
||||
if self.device.isOpen():
|
||||
self.device.close()
|
||||
self.sendComboBox.setEnabled(not self.deviceClosed)
|
||||
self.send_combobox.setEnabled(not self.device_closed)
|
||||
|
||||
def onCaptureActionToggled(self, enabled):
|
||||
if enabled and not self.captureFile:
|
||||
if self.captureFileName:
|
||||
baseDir = os.path.basename(self.captureFileName)
|
||||
def on_capture_action_toggled(self, enabled):
|
||||
if enabled and not self.capture_file:
|
||||
if self.capture_filename:
|
||||
base_dir = os.path.basename(self.capture_filename)
|
||||
else:
|
||||
baseDir = u''
|
||||
self.captureFileName = QtGui.QFileDialog.getSaveFileName(self, u'Capture To File',
|
||||
baseDir, u'Text files (*.txt *.log);;All files (*)')
|
||||
self.captureFile = open(self.captureFileName, u'w')
|
||||
self.statusbar.showMessage(self.captureFileName)
|
||||
elif self.captureFile and not enabled:
|
||||
self.captureFileName = u''
|
||||
self.captureFile.flush()
|
||||
self.captureFile.close()
|
||||
self.captureFile = None
|
||||
self.statusbar.clearMessage()
|
||||
base_dir = u''
|
||||
self.capture_filename = QtGui.QFileDialog.getSaveFileName(self, u'Capture To File', base_dir,
|
||||
u'Text files (*.txt *.log);;All files (*)')
|
||||
self.capture_file = open(self.capture_filename, u'w')
|
||||
self.status_bar.showMessage(self.capture_filename)
|
||||
elif self.capture_file and not enabled:
|
||||
self.capture_filename = u''
|
||||
self.capture_file.flush()
|
||||
self.capture_file.close()
|
||||
self.capture_file = None
|
||||
self.status_bar.clearMessage()
|
||||
|
||||
def onFollowActionToggled(self, enabled):
|
||||
self.followOutput = enabled
|
||||
def on_follow_action_toggled(self, enabled):
|
||||
self.follow_output = enabled
|
||||
if enabled:
|
||||
self.outputBrowser.page().mainFrame().scroll(0,
|
||||
self.outputBrowser.page().mainFrame().contentsSize().height())
|
||||
self.output_browser.page().mainFrame().scroll(
|
||||
0, self.output_browser.page().mainFrame().contentsSize().height())
|
||||
|
||||
def onConfigureActionTriggered(self):
|
||||
self.settingsDialog.setHighlights(self.highlights)
|
||||
self.settingsDialog.exec_()
|
||||
self.highlights = self.settingsDialog.highlights()
|
||||
self.saveHighlights(self.highlights)
|
||||
self.refreshOutput()
|
||||
def on_configure_action_triggered(self):
|
||||
self.settings_dialog.set_highlights(self.highlights)
|
||||
self.settings_dialog.exec_()
|
||||
self.highlights = self.settings_dialog.highlights()
|
||||
self.save_highlights(self.highlights)
|
||||
self.refresh_output()
|
||||
|
||||
def onSendComboBoxKeyPressed(self, key):
|
||||
def on_send_combobox_key_pressed(self, key):
|
||||
if key == QtCore.Qt.Key_Return or key == QtCore.Qt.Key_Enter:
|
||||
self.onSendButtonClicked()
|
||||
self.on_send_button_clicked()
|
||||
|
||||
def onSendButtonClicked(self):
|
||||
def on_send_button_clicked(self):
|
||||
if self.device.isOpen():
|
||||
output = str(self.sendComboBox.currentText())
|
||||
self.sendComboBox.insertItem(0, output)
|
||||
self.sendComboBox.setCurrentIndex(0)
|
||||
self.sendComboBox.clearEditText()
|
||||
output = str(self.send_combobox.currentText())
|
||||
self.send_combobox.insertItem(0, output)
|
||||
self.send_combobox.setCurrentIndex(0)
|
||||
self.send_combobox.clearEditText()
|
||||
self.device.write(output + '\r\n')
|
||||
|
||||
def onContentsSizeChanged(self, size):
|
||||
if self.followOutput:
|
||||
self.outputBrowser.page().mainFrame().scroll(0, size.height())
|
||||
self.outputBrowser.update()
|
||||
def on_contents_size_changed(self, size):
|
||||
if self.follow_output:
|
||||
self.output_browser.page().mainFrame().scroll(0, size.height())
|
||||
self.output_browser.update()
|
||||
|
||||
def onUpdateOutput(self, output):
|
||||
#self.terminalLines.append(output)
|
||||
if self.captureFile:
|
||||
self.captureFile.write(output + u'\n')
|
||||
self.captureFile.flush()
|
||||
#if len(self.terminalLines) > 5000:
|
||||
# self.terminalLines = self.terminalLines[-5000:]
|
||||
def on_update_output(self, output):
|
||||
#self.terminal_lines.append(output)
|
||||
if self.capture_file:
|
||||
self.capture_file.write(output + '\n')
|
||||
self.capture_file.flush()
|
||||
#if len(self.terminal_lines) > 5000:
|
||||
# self.terminal_lines = self.terminal_lines[-5000:]
|
||||
# self.refreshOutput()
|
||||
#else:
|
||||
output = self.styleOutput(output)
|
||||
self.documentBody().appendInside(output)
|
||||
output = self.style_output(output)
|
||||
self.document_body().appendInside(output)
|
||||
|
||||
def onOutputBrowserScrolled(self):
|
||||
scrollValue = self.outputBrowser.page().mainFrame().scrollBarValue(QtCore.Qt.Vertical)
|
||||
scrollMax = self.outputBrowser.page().mainFrame().scrollBarMaximum(QtCore.Qt.Vertical)
|
||||
if scrollValue < scrollMax:
|
||||
self.onFollowActionToggled(False)
|
||||
self.followAction.setChecked(False)
|
||||
def on_output_browser_scrolled(self):
|
||||
scroll_value = self.output_browser.page().mainFrame().scrollBarValue(QtCore.Qt.Vertical)
|
||||
scroll_max = self.output_browser.page().mainFrame().scrollBarMaximum(QtCore.Qt.Vertical)
|
||||
if scroll_value < scroll_max:
|
||||
self.on_follow_action_toggled(False)
|
||||
self.follow_action.setChecked(False)
|
||||
else:
|
||||
self.onFollowActionToggled(True)
|
||||
self.followAction.setChecked(True)
|
||||
self.on_follow_action_toggled(True)
|
||||
self.follow_action.setChecked(True)
|
||||
|
||||
def refreshOutput(self):
|
||||
elements = self.outputBrowser.page().mainFrame().findAllElements('div')
|
||||
def refresh_output(self):
|
||||
elements = self.output_browser.page().mainFrame().findAllElements('div')
|
||||
lines = [unicode(element.toPlainText()) for element in elements]
|
||||
pre = self.outputBrowser.page().mainFrame().findFirstElement('pre')
|
||||
pre = self.output_browser.page().mainFrame().findFirstElement('pre')
|
||||
pre.setInnerXml('')
|
||||
for line in lines:
|
||||
output = self.styleOutput(line)
|
||||
self.documentBody().appendInside(output)
|
||||
self.outputBrowser.page().mainFrame().scroll(0, self.outputBrowser.page().mainFrame().contentsSize().height())
|
||||
self.outputBrowser.update()
|
||||
output = self.style_output(line)
|
||||
self.document_body().appendInside(output)
|
||||
self.output_browser.page().mainFrame().scroll(0, self.output_browser.page().mainFrame().contentsSize().height())
|
||||
self.output_browser.update()
|
||||
|
||||
def styleOutput(self, output):
|
||||
style = u'font-family: Ubuntu Mono; '
|
||||
def style_output(self, output):
|
||||
style = u'font-family: \'Ubuntu Mono\', monospace; '
|
||||
if not output:
|
||||
output = u' '
|
||||
for highlight in self.highlights:
|
||||
@ -301,7 +334,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
output = u'<div>%s</div>' % output
|
||||
return output
|
||||
|
||||
def saveHighlights(self, highlights):
|
||||
def save_highlights(self, highlights):
|
||||
settings = QtCore.QSettings()
|
||||
settings.setValue(u'highlights/count', len(highlights))
|
||||
for index, highlight in enumerate(highlights):
|
||||
@ -315,17 +348,17 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
settings.remove(u'background')
|
||||
settings.endGroup()
|
||||
|
||||
def loadHighlights(self):
|
||||
def load_highlights(self):
|
||||
settings = QtCore.QSettings()
|
||||
highlight_count = settings.value(u'highlights/count', 0).toInt()[0]
|
||||
highlights = []
|
||||
for index in range(highlight_count):
|
||||
settings.beginGroup('highlight-%s' % index)
|
||||
pattern = unicode(settings.value('pattern', '').toString())
|
||||
foreground = unicode(settings.value('foreground', '').toString())
|
||||
settings.beginGroup(u'highlight-%s' % index)
|
||||
pattern = unicode(settings.value(u'pattern', u'').toString())
|
||||
foreground = unicode(settings.value(u'foreground', u'').toString())
|
||||
background = None
|
||||
if settings.contains('background'):
|
||||
background = unicode(settings.value('background', '').toString())
|
||||
if settings.contains(u'background'):
|
||||
background = unicode(settings.value(u'background', u'').toString())
|
||||
settings.endGroup()
|
||||
highlights.append(Highlight(pattern, foreground, background))
|
||||
return highlights
|
||||
|
@ -1,224 +1,261 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from colourterm import Highlight, fromUtf8, translate
|
||||
from colourterm import Highlight, from_utf8, translate
|
||||
|
||||
class Ui_SettingsDialog(object):
|
||||
def setupUi(self, settingsDialog):
|
||||
settingsDialog.setObjectName(fromUtf8('SettingsDialog'))
|
||||
settingsDialog.resize(587, 390)
|
||||
self.settingsLayout = QtGui.QVBoxLayout(settingsDialog)
|
||||
self.settingsLayout.setSpacing(8)
|
||||
self.settingsLayout.setMargin(8)
|
||||
self.settingsLayout.setObjectName(fromUtf8('settingsLayout'))
|
||||
self.splitter = QtGui.QSplitter(settingsDialog)
|
||||
|
||||
class UiSettingsDialog(object):
|
||||
def __init__(self):
|
||||
"""
|
||||
Just to satisfy PEP8/PyLint
|
||||
"""
|
||||
self.settings_layout = None
|
||||
self.splitter = None
|
||||
self.section_list_widget = None
|
||||
self.section_stacked_widget = None
|
||||
self.highlight_page = None
|
||||
self.vertical_layout = None
|
||||
self.highlight_list_widget = None
|
||||
self.button_layout = None
|
||||
self.up_button = None
|
||||
self.down_button = None
|
||||
self.add_button = None
|
||||
self.edit_button = None
|
||||
self.delete_button = None
|
||||
self.save_button = None
|
||||
self.discard_button = None
|
||||
self.highlight_groupbox = None
|
||||
self.highlight_layout = None
|
||||
self.regex_label = None
|
||||
self.regex_edit = None
|
||||
self.foreground_label = None
|
||||
self.fg_colour_button = None
|
||||
self.background_checkbox = None
|
||||
self.bg_colour_button = None
|
||||
self.font_page = None
|
||||
self.font_layout = None
|
||||
self.font_label = None
|
||||
self.font_combobox = None
|
||||
self.size_label = None
|
||||
self.size_spinbox = None
|
||||
self.button_box = None
|
||||
|
||||
def setup_ui(self, settings_dialog):
|
||||
settings_dialog.setObjectName(from_utf8('SettingsDialog'))
|
||||
settings_dialog.resize(587, 390)
|
||||
self.settings_layout = QtGui.QVBoxLayout(settings_dialog)
|
||||
self.settings_layout.setSpacing(8)
|
||||
self.settings_layout.setMargin(8)
|
||||
self.settings_layout.setObjectName(from_utf8('settings_layout'))
|
||||
self.splitter = QtGui.QSplitter(settings_dialog)
|
||||
self.splitter.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.splitter.setObjectName(fromUtf8('splitter'))
|
||||
self.sectionListWidget = QtGui.QListWidget(self.splitter)
|
||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.sectionListWidget.sizePolicy().hasHeightForWidth())
|
||||
self.sectionListWidget.setSizePolicy(sizePolicy)
|
||||
self.sectionListWidget.setMinimumSize(QtCore.QSize(100, 0))
|
||||
self.sectionListWidget.setMaximumSize(QtCore.QSize(200, 16777215))
|
||||
self.sectionListWidget.setObjectName(fromUtf8('sectionListWidget'))
|
||||
self.splitter.setObjectName(from_utf8('splitter'))
|
||||
self.section_list_widget = QtGui.QListWidget(self.splitter)
|
||||
size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
|
||||
size_policy.setHorizontalStretch(0)
|
||||
size_policy.setVerticalStretch(0)
|
||||
size_policy.setHeightForWidth(self.section_list_widget.sizePolicy().hasHeightForWidth())
|
||||
self.section_list_widget.setSizePolicy(size_policy)
|
||||
self.section_list_widget.setMinimumSize(QtCore.QSize(100, 0))
|
||||
self.section_list_widget.setMaximumSize(QtCore.QSize(200, 16777215))
|
||||
self.section_list_widget.setObjectName(from_utf8('section_list_widget'))
|
||||
item = QtGui.QListWidgetItem()
|
||||
self.sectionListWidget.addItem(item)
|
||||
self.section_list_widget.addItem(item)
|
||||
item = QtGui.QListWidgetItem()
|
||||
self.sectionListWidget.addItem(item)
|
||||
self.sectionStackedWidget = QtGui.QStackedWidget(self.splitter)
|
||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.sectionStackedWidget.sizePolicy().hasHeightForWidth())
|
||||
self.sectionStackedWidget.setSizePolicy(sizePolicy)
|
||||
self.sectionStackedWidget.setObjectName(fromUtf8('sectionStackedWidget'))
|
||||
self.highlightPage = QtGui.QWidget()
|
||||
self.highlightPage.setObjectName(fromUtf8('highlightPage'))
|
||||
self.verticalLayout = QtGui.QVBoxLayout(self.highlightPage)
|
||||
self.verticalLayout.setObjectName(fromUtf8('verticalLayout'))
|
||||
self.highlightListWidget = QtGui.QListWidget(self.highlightPage)
|
||||
self.highlightListWidget.setObjectName(fromUtf8('highlightListWidget'))
|
||||
self.verticalLayout.addWidget(self.highlightListWidget)
|
||||
self.buttonLayout = QtGui.QHBoxLayout()
|
||||
self.buttonLayout.setSpacing(8)
|
||||
self.buttonLayout.setContentsMargins(0, -1, -1, -1)
|
||||
self.buttonLayout.setObjectName(fromUtf8('buttonLayout'))
|
||||
self.upButton = QtGui.QToolButton(self.highlightPage)
|
||||
self.upButton.setIcon(QtGui.QIcon(':/settings/move-up.png'))
|
||||
self.upButton.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
|
||||
self.upButton.setFocusPolicy(QtCore.Qt.NoFocus)
|
||||
self.upButton.setObjectName(fromUtf8('upButton'))
|
||||
self.buttonLayout.addWidget(self.upButton)
|
||||
self.downButton = QtGui.QToolButton(self.highlightPage)
|
||||
self.downButton.setIcon(QtGui.QIcon(':/settings/move-down.png'))
|
||||
self.downButton.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
|
||||
self.downButton.setFocusPolicy(QtCore.Qt.NoFocus)
|
||||
self.downButton.setObjectName(fromUtf8('downButton'))
|
||||
self.buttonLayout.addWidget(self.downButton)
|
||||
self.buttonLayout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
|
||||
self.addButton = QtGui.QPushButton(self.highlightPage)
|
||||
self.addButton.setIcon(QtGui.QIcon(':/settings/highlight-add.png'))
|
||||
self.addButton.setObjectName(fromUtf8('addButton'))
|
||||
self.buttonLayout.addWidget(self.addButton)
|
||||
self.editButton = QtGui.QPushButton(self.highlightPage)
|
||||
self.editButton.setIcon(QtGui.QIcon(':/settings/highlight-edit.png'))
|
||||
self.editButton.setObjectName(fromUtf8('editButton'))
|
||||
self.buttonLayout.addWidget(self.editButton)
|
||||
self.deleteButton = QtGui.QPushButton(self.highlightPage)
|
||||
self.deleteButton.setIcon(QtGui.QIcon(':/settings/highlight-remove.png'))
|
||||
self.deleteButton.setObjectName(fromUtf8('deleteButton'))
|
||||
self.buttonLayout.addWidget(self.deleteButton)
|
||||
self.saveButton = QtGui.QPushButton(self.highlightPage)
|
||||
self.saveButton.setIcon(QtGui.QIcon(':/settings/highlight-save.png'))
|
||||
self.saveButton.setObjectName(fromUtf8('saveButton'))
|
||||
self.saveButton.setVisible(False)
|
||||
self.buttonLayout.addWidget(self.saveButton)
|
||||
self.discardButton = QtGui.QPushButton(self.highlightPage)
|
||||
self.discardButton.setIcon(QtGui.QIcon(':/settings/highlight-discard.png'))
|
||||
self.discardButton.setObjectName(fromUtf8('discardButton'))
|
||||
self.discardButton.setVisible(False)
|
||||
self.buttonLayout.addWidget(self.discardButton)
|
||||
self.verticalLayout.addLayout(self.buttonLayout)
|
||||
self.highlightGroupBox = QtGui.QGroupBox(self.highlightPage)
|
||||
self.highlightGroupBox.setObjectName(fromUtf8('highlightGroupBox'))
|
||||
self.highlightLayout = QtGui.QFormLayout(self.highlightGroupBox)
|
||||
self.highlightLayout.setMargin(8)
|
||||
self.highlightLayout.setSpacing(8)
|
||||
self.highlightLayout.setObjectName(fromUtf8('highlightLayout'))
|
||||
self.regexLabel = QtGui.QLabel(self.highlightGroupBox)
|
||||
self.regexLabel.setObjectName(fromUtf8('regexLabel'))
|
||||
self.highlightLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.regexLabel)
|
||||
self.regexEdit = QtGui.QLineEdit(self.highlightGroupBox)
|
||||
self.regexEdit.setObjectName(fromUtf8('regexEdit'))
|
||||
self.highlightLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.regexEdit)
|
||||
self.foregroundLabel = QtGui.QLabel(self.highlightGroupBox)
|
||||
self.foregroundLabel.setObjectName(fromUtf8('foregroundLabel'))
|
||||
self.highlightLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.foregroundLabel)
|
||||
self.fgColourButton = QtGui.QPushButton(self.highlightGroupBox)
|
||||
self.fgColourButton.setText(fromUtf8(''))
|
||||
self.fgColourButton.setObjectName(fromUtf8('fgColourButton'))
|
||||
self.highlightLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.fgColourButton)
|
||||
self.backgroundCheckBox = QtGui.QCheckBox(self.highlightGroupBox)
|
||||
self.backgroundCheckBox.setObjectName(fromUtf8('backgroundCheckBox'))
|
||||
self.highlightLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.backgroundCheckBox)
|
||||
self.bgColourButton = QtGui.QPushButton(self.highlightGroupBox)
|
||||
self.bgColourButton.setText(fromUtf8(''))
|
||||
self.bgColourButton.setObjectName(fromUtf8('bgColourButton'))
|
||||
self.highlightLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.bgColourButton)
|
||||
self.verticalLayout.addWidget(self.highlightGroupBox)
|
||||
self.sectionStackedWidget.addWidget(self.highlightPage)
|
||||
self.fontPage = QtGui.QWidget()
|
||||
self.fontPage.setObjectName(fromUtf8('fontPage'))
|
||||
self.fontLayout = QtGui.QFormLayout(self.fontPage)
|
||||
self.fontLayout.setMargin(8)
|
||||
self.fontLayout.setSpacing(8)
|
||||
self.fontLayout.setObjectName(fromUtf8('fontLayout'))
|
||||
self.fontLabel = QtGui.QLabel(self.fontPage)
|
||||
self.fontLabel.setObjectName(fromUtf8('fontLabel'))
|
||||
self.fontLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.fontLabel)
|
||||
self.fontComboBox = QtGui.QFontComboBox(self.fontPage)
|
||||
self.fontComboBox.setObjectName(fromUtf8('fontComboBox'))
|
||||
self.fontLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.fontComboBox)
|
||||
self.sizeLabel = QtGui.QLabel(self.fontPage)
|
||||
self.sizeLabel.setObjectName(fromUtf8('sizeLabel'))
|
||||
self.fontLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.sizeLabel)
|
||||
self.sizeSpinBox = QtGui.QSpinBox(self.fontPage)
|
||||
self.sizeSpinBox.setReadOnly(True)
|
||||
self.sizeSpinBox.setSpecialValueText(fromUtf8(''))
|
||||
self.sizeSpinBox.setMinimum(6)
|
||||
self.sizeSpinBox.setMaximum(50)
|
||||
self.sizeSpinBox.setProperty('value', 12)
|
||||
self.sizeSpinBox.setObjectName(fromUtf8('sizeSpinBox'))
|
||||
self.fontLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.sizeSpinBox)
|
||||
self.sectionStackedWidget.addWidget(self.fontPage)
|
||||
self.settingsLayout.addWidget(self.splitter)
|
||||
self.buttonBox = QtGui.QDialogButtonBox(settingsDialog)
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
|
||||
self.buttonBox.setObjectName(fromUtf8('buttonBox'))
|
||||
self.settingsLayout.addWidget(self.buttonBox)
|
||||
self.section_list_widget.addItem(item)
|
||||
self.section_stacked_widget = QtGui.QStackedWidget(self.splitter)
|
||||
size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
|
||||
size_policy.setHorizontalStretch(0)
|
||||
size_policy.setVerticalStretch(0)
|
||||
size_policy.setHeightForWidth(self.section_stacked_widget.sizePolicy().hasHeightForWidth())
|
||||
self.section_stacked_widget.setSizePolicy(size_policy)
|
||||
self.section_stacked_widget.setObjectName(from_utf8('section_stacked_widget'))
|
||||
self.highlight_page = QtGui.QWidget()
|
||||
self.highlight_page.setObjectName(from_utf8('highlight_page'))
|
||||
self.vertical_layout = QtGui.QVBoxLayout(self.highlight_page)
|
||||
self.vertical_layout.setObjectName(from_utf8('vertical_layout'))
|
||||
self.highlight_list_widget = QtGui.QListWidget(self.highlight_page)
|
||||
self.highlight_list_widget.setObjectName(from_utf8('highlight_list_widget'))
|
||||
self.vertical_layout.addWidget(self.highlight_list_widget)
|
||||
self.button_layout = QtGui.QHBoxLayout()
|
||||
self.button_layout.setSpacing(8)
|
||||
self.button_layout.setContentsMargins(0, -1, -1, -1)
|
||||
self.button_layout.setObjectName(from_utf8('button_layout'))
|
||||
self.up_button = QtGui.QToolButton(self.highlight_page)
|
||||
self.up_button.setIcon(QtGui.QIcon(':/settings/move-up.png'))
|
||||
self.up_button.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
|
||||
self.up_button.setFocusPolicy(QtCore.Qt.NoFocus)
|
||||
self.up_button.setObjectName(from_utf8('up_button'))
|
||||
self.button_layout.addWidget(self.up_button)
|
||||
self.down_button = QtGui.QToolButton(self.highlight_page)
|
||||
self.down_button.setIcon(QtGui.QIcon(':/settings/move-down.png'))
|
||||
self.down_button.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
|
||||
self.down_button.setFocusPolicy(QtCore.Qt.NoFocus)
|
||||
self.down_button.setObjectName(from_utf8('down_button'))
|
||||
self.button_layout.addWidget(self.down_button)
|
||||
self.button_layout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
|
||||
self.add_button = QtGui.QPushButton(self.highlight_page)
|
||||
self.add_button.setIcon(QtGui.QIcon(':/settings/highlight-add.png'))
|
||||
self.add_button.setObjectName(from_utf8('add_button'))
|
||||
self.button_layout.addWidget(self.add_button)
|
||||
self.edit_button = QtGui.QPushButton(self.highlight_page)
|
||||
self.edit_button.setIcon(QtGui.QIcon(':/settings/highlight-edit.png'))
|
||||
self.edit_button.setObjectName(from_utf8('edit_button'))
|
||||
self.button_layout.addWidget(self.edit_button)
|
||||
self.delete_button = QtGui.QPushButton(self.highlight_page)
|
||||
self.delete_button.setIcon(QtGui.QIcon(':/settings/highlight-remove.png'))
|
||||
self.delete_button.setObjectName(from_utf8('delete_button'))
|
||||
self.button_layout.addWidget(self.delete_button)
|
||||
self.save_button = QtGui.QPushButton(self.highlight_page)
|
||||
self.save_button.setIcon(QtGui.QIcon(':/settings/highlight-save.png'))
|
||||
self.save_button.setObjectName(from_utf8('save_button'))
|
||||
self.save_button.setVisible(False)
|
||||
self.button_layout.addWidget(self.save_button)
|
||||
self.discard_button = QtGui.QPushButton(self.highlight_page)
|
||||
self.discard_button.setIcon(QtGui.QIcon(':/settings/highlight-discard.png'))
|
||||
self.discard_button.setObjectName(from_utf8('discard_button'))
|
||||
self.discard_button.setVisible(False)
|
||||
self.button_layout.addWidget(self.discard_button)
|
||||
self.vertical_layout.addLayout(self.button_layout)
|
||||
self.highlight_groupbox = QtGui.QGroupBox(self.highlight_page)
|
||||
self.highlight_groupbox.setObjectName(from_utf8('highlight_groupbox'))
|
||||
self.highlight_layout = QtGui.QFormLayout(self.highlight_groupbox)
|
||||
self.highlight_layout.setMargin(8)
|
||||
self.highlight_layout.setSpacing(8)
|
||||
self.highlight_layout.setObjectName(from_utf8('highlight_layout'))
|
||||
self.regex_label = QtGui.QLabel(self.highlight_groupbox)
|
||||
self.regex_label.setObjectName(from_utf8('regex_label'))
|
||||
self.highlight_layout.setWidget(0, QtGui.QFormLayout.LabelRole, self.regex_label)
|
||||
self.regex_edit = QtGui.QLineEdit(self.highlight_groupbox)
|
||||
self.regex_edit.setObjectName(from_utf8('regex_edit'))
|
||||
self.highlight_layout.setWidget(0, QtGui.QFormLayout.FieldRole, self.regex_edit)
|
||||
self.foreground_label = QtGui.QLabel(self.highlight_groupbox)
|
||||
self.foreground_label.setObjectName(from_utf8('foreground_label'))
|
||||
self.highlight_layout.setWidget(1, QtGui.QFormLayout.LabelRole, self.foreground_label)
|
||||
self.fg_colour_button = QtGui.QPushButton(self.highlight_groupbox)
|
||||
self.fg_colour_button.setText(from_utf8(''))
|
||||
self.fg_colour_button.setObjectName(from_utf8('fg_colour_button'))
|
||||
self.highlight_layout.setWidget(1, QtGui.QFormLayout.FieldRole, self.fg_colour_button)
|
||||
self.background_checkbox = QtGui.QCheckBox(self.highlight_groupbox)
|
||||
self.background_checkbox.setObjectName(from_utf8('background_checkbox'))
|
||||
self.highlight_layout.setWidget(2, QtGui.QFormLayout.LabelRole, self.background_checkbox)
|
||||
self.bg_colour_button = QtGui.QPushButton(self.highlight_groupbox)
|
||||
self.bg_colour_button.setText(from_utf8(''))
|
||||
self.bg_colour_button.setObjectName(from_utf8('bg_colour_button'))
|
||||
self.highlight_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.bg_colour_button)
|
||||
self.vertical_layout.addWidget(self.highlight_groupbox)
|
||||
self.section_stacked_widget.addWidget(self.highlight_page)
|
||||
self.font_page = QtGui.QWidget()
|
||||
self.font_page.setObjectName(from_utf8('font_page'))
|
||||
self.font_layout = QtGui.QFormLayout(self.font_page)
|
||||
self.font_layout.setMargin(8)
|
||||
self.font_layout.setSpacing(8)
|
||||
self.font_layout.setObjectName(from_utf8('font_layout'))
|
||||
self.font_label = QtGui.QLabel(self.font_page)
|
||||
self.font_label.setObjectName(from_utf8('font_label'))
|
||||
self.font_layout.setWidget(0, QtGui.QFormLayout.LabelRole, self.font_label)
|
||||
self.font_combobox = QtGui.QFontComboBox(self.font_page)
|
||||
self.font_combobox.setObjectName(from_utf8('font_combobox'))
|
||||
self.font_layout.setWidget(0, QtGui.QFormLayout.FieldRole, self.font_combobox)
|
||||
self.size_label = QtGui.QLabel(self.font_page)
|
||||
self.size_label.setObjectName(from_utf8('size_label'))
|
||||
self.font_layout.setWidget(1, QtGui.QFormLayout.LabelRole, self.size_label)
|
||||
self.size_spinbox = QtGui.QSpinBox(self.font_page)
|
||||
self.size_spinbox.setReadOnly(True)
|
||||
self.size_spinbox.setSpecialValueText(from_utf8(''))
|
||||
self.size_spinbox.setMinimum(6)
|
||||
self.size_spinbox.setMaximum(50)
|
||||
self.size_spinbox.setProperty('value', 12)
|
||||
self.size_spinbox.setObjectName(from_utf8('size_spinbox'))
|
||||
self.font_layout.setWidget(1, QtGui.QFormLayout.FieldRole, self.size_spinbox)
|
||||
self.section_stacked_widget.addWidget(self.font_page)
|
||||
self.settings_layout.addWidget(self.splitter)
|
||||
self.button_box = QtGui.QDialogButtonBox(settings_dialog)
|
||||
self.button_box.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.button_box.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
|
||||
self.button_box.setObjectName(from_utf8('button_box'))
|
||||
self.settings_layout.addWidget(self.button_box)
|
||||
|
||||
self.retranslateUi(settingsDialog)
|
||||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(fromUtf8('accepted()')), settingsDialog.accept)
|
||||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(fromUtf8('rejected()')), settingsDialog.reject)
|
||||
QtCore.QObject.connect(self.sectionListWidget, QtCore.SIGNAL(fromUtf8('currentRowChanged(int)')), self.sectionStackedWidget.setCurrentIndex)
|
||||
QtCore.QMetaObject.connectSlotsByName(settingsDialog)
|
||||
settingsDialog.setTabOrder(self.sectionListWidget, self.highlightListWidget)
|
||||
settingsDialog.setTabOrder(self.highlightListWidget, self.addButton)
|
||||
settingsDialog.setTabOrder(self.addButton, self.editButton)
|
||||
settingsDialog.setTabOrder(self.editButton, self.deleteButton)
|
||||
settingsDialog.setTabOrder(self.deleteButton, self.saveButton)
|
||||
settingsDialog.setTabOrder(self.saveButton, self.discardButton)
|
||||
settingsDialog.setTabOrder(self.discardButton, self.buttonBox)
|
||||
self.retranslate_ui(settings_dialog)
|
||||
self.button_box.accepted.connect(settings_dialog.accept)
|
||||
self.button_box.rejected.connect(settings_dialog.reject)
|
||||
self.section_list_widget.currentRowChanged.connect(self.section_stacked_widget.setCurrentIndex)
|
||||
settings_dialog.setTabOrder(self.section_list_widget, self.highlight_list_widget)
|
||||
settings_dialog.setTabOrder(self.highlight_list_widget, self.add_button)
|
||||
settings_dialog.setTabOrder(self.add_button, self.edit_button)
|
||||
settings_dialog.setTabOrder(self.edit_button, self.delete_button)
|
||||
settings_dialog.setTabOrder(self.delete_button, self.save_button)
|
||||
settings_dialog.setTabOrder(self.save_button, self.discard_button)
|
||||
settings_dialog.setTabOrder(self.discard_button, self.button_box)
|
||||
|
||||
def retranslateUi(self, settingsDialog):
|
||||
settingsDialog.setWindowTitle(translate('SettingsDialog', 'Settings'))
|
||||
__sortingEnabled = self.sectionListWidget.isSortingEnabled()
|
||||
self.sectionListWidget.setSortingEnabled(False)
|
||||
item = self.sectionListWidget.item(0)
|
||||
def retranslate_ui(self, settings_dialog):
|
||||
"""
|
||||
Translate the user interface
|
||||
"""
|
||||
settings_dialog.setWindowTitle(translate('SettingsDialog', 'Settings'))
|
||||
__sortingEnabled = self.section_list_widget.isSortingEnabled()
|
||||
self.section_list_widget.setSortingEnabled(False)
|
||||
item = self.section_list_widget.item(0)
|
||||
item.setText(translate('SettingsDialog', 'Highlighting'))
|
||||
item = self.sectionListWidget.item(1)
|
||||
item = self.section_list_widget.item(1)
|
||||
item.setText(translate('SettingsDialog', 'Font'))
|
||||
self.sectionListWidget.setSortingEnabled(__sortingEnabled)
|
||||
self.upButton.setText(translate('SettingsDialog', 'Move Up'))
|
||||
self.downButton.setText(translate('SettingsDialog', 'Move Down'))
|
||||
self.addButton.setText(translate('SettingsDialog', 'Add'))
|
||||
self.editButton.setText(translate('SettingsDialog', 'Edit'))
|
||||
self.deleteButton.setText(translate('SettingsDialog', 'Delete'))
|
||||
self.saveButton.setText(translate('SettingsDialog', 'Save'))
|
||||
self.discardButton.setText(translate('SettingsDialog', 'Discard'))
|
||||
self.highlightGroupBox.setTitle(translate('SettingsDialog', 'Highlight'))
|
||||
self.regexLabel.setText(translate('SettingsDialog', 'Regular Expression:'))
|
||||
self.foregroundLabel.setText(translate('SettingsDialog', 'Foreground:'))
|
||||
self.backgroundCheckBox.setText(translate('SettingsDialog', 'Background:'))
|
||||
self.fontLabel.setText(translate('SettingsDialog', 'Font:'))
|
||||
self.sizeLabel.setText(translate('SettingsDialog', 'Size:'))
|
||||
self.sizeSpinBox.setSuffix(translate('SettingsDialog', 'pt'))
|
||||
self.section_list_widget.setSortingEnabled(__sortingEnabled)
|
||||
self.up_button.setText(translate('SettingsDialog', 'Move Up'))
|
||||
self.down_button.setText(translate('SettingsDialog', 'Move Down'))
|
||||
self.add_button.setText(translate('SettingsDialog', 'Add'))
|
||||
self.edit_button.setText(translate('SettingsDialog', 'Edit'))
|
||||
self.delete_button.setText(translate('SettingsDialog', 'Delete'))
|
||||
self.save_button.setText(translate('SettingsDialog', 'Save'))
|
||||
self.discard_button.setText(translate('SettingsDialog', 'Discard'))
|
||||
self.highlight_groupbox.setTitle(translate('SettingsDialog', 'Highlight'))
|
||||
self.regex_label.setText(translate('SettingsDialog', 'Regular Expression:'))
|
||||
self.foreground_label.setText(translate('SettingsDialog', 'Foreground:'))
|
||||
self.background_checkbox.setText(translate('SettingsDialog', 'Background:'))
|
||||
self.font_label.setText(translate('SettingsDialog', 'Font:'))
|
||||
self.size_label.setText(translate('SettingsDialog', 'Size:'))
|
||||
self.size_spinbox.setSuffix(translate('SettingsDialog', 'pt'))
|
||||
|
||||
|
||||
class SettingsDialog(QtGui.QDialog, Ui_SettingsDialog):
|
||||
class SettingsDialog(QtGui.QDialog, UiSettingsDialog):
|
||||
|
||||
def __init__(self):
|
||||
QtGui.QDialog.__init__(self)
|
||||
self.setupUi(self)
|
||||
self.setup_ui(self)
|
||||
self._highlights = {}
|
||||
self._currentHighlight = None
|
||||
self._currentRow = -1
|
||||
self.highlightListWidget.itemSelectionChanged.connect(self.onHighlightItemSelected)
|
||||
self.regexEdit.textEdited.connect(self.onRegexEditTextEdited)
|
||||
self.fgColourButton.clicked.connect(self.onFgColourButtonClicked)
|
||||
self.backgroundCheckBox.toggled.connect(self.onBackgroundCheckboxToggled)
|
||||
self.bgColourButton.clicked.connect(self.onBgColourButtonClicked)
|
||||
self.upButton.clicked.connect(self.onUpButtonClicked)
|
||||
self.downButton.clicked.connect(self.onDownButtonClicked)
|
||||
self.addButton.clicked.connect(self.onAddButtonClicked)
|
||||
self.editButton.clicked.connect(self.onEditButtonClicked)
|
||||
self.deleteButton.clicked.connect(self.onDeleteButtonClicked)
|
||||
self.saveButton.clicked.connect(self.onSaveButtonClicked)
|
||||
self.discardButton.clicked.connect(self.onDiscardButtonClicked)
|
||||
self._current_highlight = None
|
||||
self._current_row = -1
|
||||
self.highlight_list_widget.itemSelectionChanged.connect(self.on_highlight_item_selected)
|
||||
self.regex_edit.textEdited.connect(self.on_regex_edit_text_edited)
|
||||
self.fg_colour_button.clicked.connect(self.on_fg_colour_button_clicked)
|
||||
self.background_checkbox.toggled.connect(self.on_background_checkbox_toggled)
|
||||
self.bg_colour_button.clicked.connect(self.on_bg_colour_button_clicked)
|
||||
self.up_button.clicked.connect(self.on_up_button_clicked)
|
||||
self.down_button.clicked.connect(self.on_down_button_clicked)
|
||||
self.add_button.clicked.connect(self.on_add_button_clicked)
|
||||
self.edit_button.clicked.connect(self.on_edit_button_clicked)
|
||||
self.delete_button.clicked.connect(self.on_delete_button_clicked)
|
||||
self.save_button.clicked.connect(self.on_save_button_clicked)
|
||||
self.discard_button.clicked.connect(self.on_discard_button_clicked)
|
||||
|
||||
def _setCurrentHighlight(self):
|
||||
self.regexEdit.setText(self._currentHighlight.pattern)
|
||||
if self._currentHighlight.background:
|
||||
self.backgroundCheckBox.setChecked(True)
|
||||
self.bgColourButton.setEnabled(True)
|
||||
self.bgColourButton.setStyleSheet('background-color: %s' % self._currentHighlight.background)
|
||||
def _set_current_highlight(self):
|
||||
self.regex_edit.setText(self._current_highlight.pattern)
|
||||
if self._current_highlight.background:
|
||||
self.background_checkbox.setChecked(True)
|
||||
self.bg_colour_button.setEnabled(True)
|
||||
self.bg_colour_button.setStyleSheet('background-color: %s' % self._current_highlight.background)
|
||||
else:
|
||||
self.backgroundCheckBox.setChecked(False)
|
||||
self.bgColourButton.setEnabled(False)
|
||||
self.bgColourButton.setStyleSheet('')
|
||||
self.fgColourButton.setStyleSheet('background-color: %s' % self._currentHighlight.foreground)
|
||||
self.setEditMode(True)
|
||||
self.background_checkbox.setChecked(False)
|
||||
self.bg_colour_button.setEnabled(False)
|
||||
self.bg_colour_button.setStyleSheet('')
|
||||
self.fg_colour_button.setStyleSheet('background-color: %s' % self._current_highlight.foreground)
|
||||
self.set_edit_mode(True)
|
||||
|
||||
def highlights(self):
|
||||
return self._highlights.values()
|
||||
|
||||
def setHighlights(self, highlights):
|
||||
def set_highlights(self, highlights):
|
||||
self._highlights = {}
|
||||
self.highlightListWidget.clear()
|
||||
self.highlight_list_widget.clear()
|
||||
for index, highlight in enumerate(highlights):
|
||||
self._highlights[index] = highlight
|
||||
item = QtGui.QListWidgetItem()
|
||||
@ -226,118 +263,116 @@ class SettingsDialog(QtGui.QDialog, Ui_SettingsDialog):
|
||||
item.setBackgroundColor(QtGui.QColor(highlight.background))
|
||||
item.setTextColor(QtGui.QColor(highlight.foreground))
|
||||
item.setText(highlight.pattern)
|
||||
self.highlightListWidget.addItem(item)
|
||||
self.highlight_list_widget.addItem(item)
|
||||
|
||||
def onHighlightItemSelected(self):
|
||||
self._currentRow = self.highlightListWidget.currentRow()
|
||||
if self._currentRow > -1:
|
||||
self._currentHighlight = self._highlights[self._currentRow]
|
||||
def on_highlight_item_selected(self):
|
||||
self._current_row = self.highlight_list_widget.currentRow()
|
||||
if self._current_row > -1:
|
||||
self._current_highlight = self._highlights[self._current_row]
|
||||
|
||||
def onRegexEditTextEdited(self):
|
||||
self._currentHighlight.setPattern(unicode(self.regexEdit.text()))
|
||||
def on_regex_edit_text_edited(self):
|
||||
self._current_highlight.set_pattern(unicode(self.regex_edit.text()))
|
||||
|
||||
def onBackgroundCheckboxToggled(self, checked):
|
||||
self.bgColourButton.setEnabled(checked)
|
||||
def on_background_checkbox_toggled(self, checked):
|
||||
self.bg_colour_button.setEnabled(checked)
|
||||
if not checked:
|
||||
self._currentHighlight.background = None
|
||||
self._current_highlight.background = None
|
||||
|
||||
def onFgColourButtonClicked(self):
|
||||
colour = QtGui.QColor(self._currentHighlight.foreground)
|
||||
def on_fg_colour_button_clicked(self):
|
||||
colour = QtGui.QColor(self._current_highlight.foreground)
|
||||
colour = QtGui.QColorDialog.getColor(colour, self)
|
||||
if colour.isValid():
|
||||
self.fgColourButton.setStyleSheet('background-color: %s' % colour.name())
|
||||
self._currentHighlight.foreground = colour.name()
|
||||
self.fg_colour_button.setStyleSheet('background-color: %s' % colour.name())
|
||||
self._current_highlight.foreground = colour.name()
|
||||
|
||||
def onBgColourButtonClicked(self):
|
||||
if self._currentHighlight.background:
|
||||
colour = QtGui.QColor(self._currentHighlight.background)
|
||||
def on_bg_colour_button_clicked(self):
|
||||
if self._current_highlight.background:
|
||||
colour = QtGui.QColor(self._current_highlight.background)
|
||||
colour = QtGui.QColorDialog.getColor(colour, self)
|
||||
else:
|
||||
colour = QtGui.QColorDialog.getColor(QtCore.Qt.white, self)
|
||||
if colour.isValid():
|
||||
self.bgColourButton.setStyleSheet('background-color: %s' % colour.name())
|
||||
self._currentHighlight.background = colour.name()
|
||||
self.bg_colour_button.setStyleSheet('background-color: %s' % colour.name())
|
||||
self._current_highlight.background = colour.name()
|
||||
|
||||
def onUpButtonClicked(self):
|
||||
if self._currentRow == 0:
|
||||
def on_up_button_clicked(self):
|
||||
if self._current_row == 0:
|
||||
return
|
||||
row = self._currentRow
|
||||
item = self.highlightListWidget.takeItem(row)
|
||||
self.highlightListWidget.insertItem(row - 1, item)
|
||||
row = self._current_row
|
||||
item = self.highlight_list_widget.takeItem(row)
|
||||
self.highlight_list_widget.insertItem(row - 1, item)
|
||||
self._highlights[row - 1], self._highlights[row] = \
|
||||
self._highlights[row], self._highlights[row - 1]
|
||||
self.highlightListWidget.setCurrentRow(row - 1)
|
||||
self.onHighlightItemSelected()
|
||||
self.highlight_list_widget.setCurrentRow(row - 1)
|
||||
self.on_highlight_item_selected()
|
||||
|
||||
def onDownButtonClicked(self):
|
||||
if self._currentRow == len(self._highlights) - 1:
|
||||
def on_down_button_clicked(self):
|
||||
if self._current_row == len(self._highlights) - 1:
|
||||
return
|
||||
row = self._currentRow
|
||||
item = self.highlightListWidget.takeItem(row)
|
||||
self.highlightListWidget.insertItem(row + 1, item)
|
||||
row = self._current_row
|
||||
item = self.highlight_list_widget.takeItem(row)
|
||||
self.highlight_list_widget.insertItem(row + 1, item)
|
||||
self._highlights[row + 1], self._highlights[row] = \
|
||||
self._highlights[row], self._highlights[row + 1]
|
||||
self.highlightListWidget.setCurrentRow(row + 1)
|
||||
self.onHighlightItemSelected()
|
||||
self.highlight_list_widget.setCurrentRow(row + 1)
|
||||
self.on_highlight_item_selected()
|
||||
|
||||
def onAddButtonClicked(self):
|
||||
self._currentRow = -1
|
||||
self._currentHighlight = Highlight(u'', QtGui.QColor(QtGui.QPalette.WindowText).name())
|
||||
self._setCurrentHighlight()
|
||||
self.setEditMode(True)
|
||||
def on_add_button_clicked(self):
|
||||
self._current_row = -1
|
||||
self._current_highlight = Highlight(u'', QtGui.QColor(QtGui.QPalette.WindowText).name())
|
||||
self._set_current_highlight()
|
||||
self.set_edit_mode(True)
|
||||
|
||||
def onEditButtonClicked(self):
|
||||
self._setCurrentHighlight()
|
||||
self.setEditMode(True)
|
||||
def on_edit_button_clicked(self):
|
||||
self._set_current_highlight()
|
||||
self.set_edit_mode(True)
|
||||
|
||||
def onDeleteButtonClicked(self):
|
||||
if QtGui.QMessageBox.question(self,
|
||||
translate('SettingsDialog', 'Confirm Delete'),
|
||||
translate('SettingsDialog', 'Are you sure you want to delete '
|
||||
'this highlight?'),
|
||||
def on_delete_button_clicked(self):
|
||||
if QtGui.QMessageBox.question(self, translate('SettingsDialog', 'Confirm Delete'),
|
||||
translate('SettingsDialog', 'Are you sure you want to delete this highlight?'),
|
||||
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) == QtGui.QMessageBox.Yes:
|
||||
del self._highlights[self._currentRow]
|
||||
self.highlightListWidget.takeItem(self._currentRow)
|
||||
self._currentRow = -1
|
||||
self._currentHighlight = None
|
||||
del self._highlights[self._current_row]
|
||||
self.highlight_list_widget.takeItem(self._current_row)
|
||||
self._current_row = -1
|
||||
self._current_highlight = None
|
||||
|
||||
def onSaveButtonClicked(self):
|
||||
if self._currentRow < 0:
|
||||
def on_save_button_clicked(self):
|
||||
if self._current_row < 0:
|
||||
new_index = len(self._highlights)
|
||||
self._highlights[new_index] = self._currentHighlight
|
||||
self._highlights[new_index] = self._current_highlight
|
||||
item = QtGui.QListWidgetItem()
|
||||
if self._currentHighlight.background:
|
||||
item.setBackgroundColor(QtGui.QColor(self._currentHighlight.background))
|
||||
item.setTextColor(QtGui.QColor(self._currentHighlight.foreground))
|
||||
item.setText(self._currentHighlight.pattern)
|
||||
self.highlightListWidget.addItem(item)
|
||||
self.highlightListWidget.setCurrentRow(new_index)
|
||||
if self._current_highlight.background:
|
||||
item.setBackgroundColor(QtGui.QColor(self._current_highlight.background))
|
||||
item.setTextColor(QtGui.QColor(self._current_highlight.foreground))
|
||||
item.setText(self._current_highlight.pattern)
|
||||
self.highlight_list_widget.addItem(item)
|
||||
self.highlight_list_widget.setCurrentRow(new_index)
|
||||
else:
|
||||
self._highlights[self._currentRow] = self._currentHighlight
|
||||
self.setEditMode(False)
|
||||
self._highlights[self._current_row] = self._current_highlight
|
||||
self.set_edit_mode(False)
|
||||
|
||||
def onDiscardButtonClicked(self):
|
||||
self.setEditMode(False)
|
||||
def on_discard_button_clicked(self):
|
||||
self.set_edit_mode(False)
|
||||
|
||||
def setEditMode(self, enable):
|
||||
for button in self.buttonBox.buttons():
|
||||
def set_edit_mode(self, enable):
|
||||
for button in self.button_box.buttons():
|
||||
button.setEnabled(not enable)
|
||||
self.upButton.setVisible(not enable)
|
||||
self.downButton.setVisible(not enable)
|
||||
self.addButton.setVisible(not enable)
|
||||
self.editButton.setVisible(not enable)
|
||||
self.deleteButton.setVisible(not enable)
|
||||
self.saveButton.setVisible(enable)
|
||||
self.discardButton.setVisible(enable)
|
||||
self.highlightListWidget.setEnabled(not enable)
|
||||
self.regexEdit.setEnabled(enable)
|
||||
self.fgColourButton.setEnabled(enable)
|
||||
self.backgroundCheckBox.setEnabled(enable)
|
||||
if enable and self.backgroundCheckBox.isChecked():
|
||||
self.bgColourButton.setEnabled(True)
|
||||
self.up_button.setVisible(not enable)
|
||||
self.down_button.setVisible(not enable)
|
||||
self.add_button.setVisible(not enable)
|
||||
self.edit_button.setVisible(not enable)
|
||||
self.delete_button.setVisible(not enable)
|
||||
self.save_button.setVisible(enable)
|
||||
self.discard_button.setVisible(enable)
|
||||
self.highlight_list_widget.setEnabled(not enable)
|
||||
self.regex_edit.setEnabled(enable)
|
||||
self.fg_colour_button.setEnabled(enable)
|
||||
self.background_checkbox.setEnabled(enable)
|
||||
if enable and self.background_checkbox.isChecked():
|
||||
self.bg_colour_button.setEnabled(True)
|
||||
else:
|
||||
self.bgColourButton.setEnabled(False)
|
||||
self.bg_colour_button.setEnabled(False)
|
||||
if not enable:
|
||||
self.regexEdit.clear()
|
||||
self.fgColourButton.setStyleSheet('')
|
||||
self.bgColourButton.setStyleSheet('')
|
||||
self.regex_edit.clear()
|
||||
self.fg_colour_button.setStyleSheet('')
|
||||
self.bg_colour_button.setStyleSheet('')
|
||||
|
Loading…
Reference in New Issue
Block a user