colourterm/colourterm/__init__.py

58 lines
1.5 KiB
Python
Raw Normal View History

2013-12-05 14:16:09 +00:00
# -*- coding: utf-8 -*-
import re
2018-07-24 05:50:27 +00:00
from PyQt5 import QtCore, QtWidgets
2013-12-05 14:16:09 +00:00
try:
2013-12-10 12:55:20 +00:00
from_utf8 = QtCore.QString.fromUtf8
2013-12-05 14:16:09 +00:00
except AttributeError:
2018-07-24 05:50:27 +00:00
def from_utf8(s):
return s
2013-12-05 14:16:09 +00:00
2018-07-24 05:50:27 +00:00
class SComboBox(QtWidgets.QComboBox):
2013-12-05 14:16:09 +00:00
"""
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())
2018-07-24 05:50:27 +00:00
return QtWidgets.QComboBox.keyPressEvent(self, event)
2013-12-05 14:16:09 +00:00
class Highlight(object):
def __init__(self, pattern, foreground, background=None):
self.pattern = pattern
self.regex = re.compile(pattern)
self.foreground = foreground
self.background = background
2013-12-10 12:55:20 +00:00
def set_pattern(self, pattern):
2013-12-05 14:16:09 +00:00
self.pattern = pattern
try:
self.regex = re.compile(pattern)
except re.error:
self.regex = None
def translate(context, string, description=None):
2018-07-24 05:50:27 +00:00
return QtWidgets.QApplication.translate(context, string, description)
2013-12-05 14:16:09 +00:00
def create_default_highlights():
return [
Highlight(r'PASSED', u'#ffffff', '#009900'),
Highlight(r'FAILED', u'#ffffff', '#990000'),
Highlight(r'^\\|/', u'#666666')
]
2018-07-24 05:50:27 +00:00
from colourterm.settingsdialog import SettingsDialog # noqa
from colourterm.connectdialog import ConnectDialog # noqa
2013-12-05 14:16:09 +00:00
2013-12-10 12:55:20 +00:00
__all__ = ['SettingsDialog', 'ConnectDialog', 'SComboBox', 'Highlight', 'translate', 'from_utf8']