58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
import re
|
|
|
|
from PyQt5 import QtCore, QtWidgets
|
|
try:
|
|
from_utf8 = QtCore.QString.fromUtf8
|
|
except AttributeError:
|
|
def from_utf8(s):
|
|
return s
|
|
|
|
|
|
class SComboBox(QtWidgets.QComboBox):
|
|
"""
|
|
Special combobox derivative that emits a signal when a key is pressed.
|
|
"""
|
|
keyPressed = QtCore.pyqtSignal(int)
|
|
|
|
def keyPressEvent(self, event):
|
|
"""
|
|
Override the inherited keyPressEvent to emit a signal.
|
|
"""
|
|
self.keyPressed.emit(event.key())
|
|
return QtWidgets.QComboBox.keyPressEvent(self, event)
|
|
|
|
|
|
class Highlight(object):
|
|
def __init__(self, pattern, foreground, background=None):
|
|
self.pattern = pattern
|
|
self.regex = re.compile(pattern)
|
|
self.foreground = foreground
|
|
self.background = background
|
|
|
|
def set_pattern(self, pattern):
|
|
self.pattern = pattern
|
|
try:
|
|
self.regex = re.compile(pattern)
|
|
except re.error:
|
|
self.regex = None
|
|
|
|
|
|
def translate(context, string, description=None):
|
|
return QtWidgets.QApplication.translate(context, string, description)
|
|
|
|
|
|
def create_default_highlights():
|
|
return [
|
|
Highlight(r'PASSED', u'#ffffff', '#009900'),
|
|
Highlight(r'FAILED', u'#ffffff', '#990000'),
|
|
Highlight(r'^\\|/', u'#666666')
|
|
]
|
|
|
|
|
|
from colourterm.settingsdialog import SettingsDialog # noqa
|
|
from colourterm.connectdialog import ConnectDialog # noqa
|
|
|
|
|
|
__all__ = ['SettingsDialog', 'ConnectDialog', 'SComboBox', 'Highlight', 'translate', 'from_utf8']
|