gui: better quotes and add mouse

This commit is contained in:
2019-07-16 16:54:32 +01:00
parent a54c05e9f7
commit 989f31634c

View File

@@ -8,20 +8,20 @@ import yaml
try: try:
from PyQt5 import QtWidgets, QtGui, QtCore from PyQt5 import QtWidgets, QtGui, QtCore
except: except:
print("alacritty-config-gui depends on PyQt5. I couldnt locate PyQt5.") print('alacritty-config-gui depends on PyQt5. I couldnt locate PyQt5.')
print("Sorry about that.") print('Sorry about that.')
print("\nRunning `pip3 install PyQt5` could help.") print('\nRunning `pip3 install PyQt5` could help.')
sys.exit(1) sys.exit(1)
ALACRITTY_CONFIG = os.path.expanduser("~/.config/alacritty/alacritty.yml") ALACRITTY_CONFIG = os.path.expanduser('~/.config/alacritty/alacritty.yml')
NAME = 'Alacritty Config' NAME = 'Alacritty Config'
MODIFIERS = ['None', 'Command', 'Control', 'Option', 'Super', 'Shift', 'Alt']
# TODO # TODO
# visual bell # visual bell
# cursor
# mouse
def delete_layout_items(layout): def delete_layout_items(layout):
@@ -51,7 +51,7 @@ class ColorSelect(QtWidgets.QPushButton):
color = QtGui.QColor(self._value) color = QtGui.QColor(self._value)
self.setFlat(True) self.setFlat(True)
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setStyleSheet(""" self.setStyleSheet('''
QPushButton {{ QPushButton {{
color: {0}; color: {0};
background-color: {0}; background-color: {0};
@@ -66,7 +66,7 @@ class ColorSelect(QtWidgets.QPushButton):
background-color: {0}; background-color: {0};
border-style: outset; border-style: outset;
}} }}
""".format(color.name())) '''.format(color.name()))
self.update() self.update()
def value(self): def value(self):
@@ -88,7 +88,7 @@ class FontSelect(QtWidgets.QPushButton):
def set_value(self, family, style): def set_value(self, family, style):
self.family = family self.family = family
self.style = style self.style = style
self.setStyleSheet(""" self.setStyleSheet('''
QPushButton {{ QPushButton {{
background-color: white; background-color: white;
font-family: {0}; font-family: {0};
@@ -99,7 +99,7 @@ class FontSelect(QtWidgets.QPushButton):
QPushButton:hover{{ QPushButton:hover{{
background-color: white; background-color: white;
}} }}
""".format(family)) '''.format(family))
self.setText(self.family) self.setText(self.family)
self.update() self.update()
@@ -114,7 +114,7 @@ class Spoiler(QtWidgets.QWidget):
def __init__(self, title): def __init__(self, title):
super().__init__() super().__init__()
self.toggle = QtWidgets.QToolButton() self.toggle = QtWidgets.QToolButton()
self.toggle.setStyleSheet("QToolButton { border: none; }") self.toggle.setStyleSheet('QToolButton { border: none; }')
self.toggle.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) self.toggle.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
self.toggle.setArrowType(QtCore.Qt.ArrowType.RightArrow) self.toggle.setArrowType(QtCore.Qt.ArrowType.RightArrow)
self.toggle.setText(title) self.toggle.setText(title)
@@ -129,9 +129,9 @@ class Spoiler(QtWidgets.QWidget):
) )
self.content = QtWidgets.QScrollArea() self.content = QtWidgets.QScrollArea()
self.content.setStyleSheet(""" self.content.setStyleSheet('''
QScrollArea { border: none; background-color: transparent; } QScrollArea { border: none; background-color: transparent; }
""") ''')
self.content.setSizePolicy( self.content.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed
) )
@@ -139,13 +139,13 @@ class Spoiler(QtWidgets.QWidget):
self.content.setMinimumHeight(0) self.content.setMinimumHeight(0)
self.animation = QtCore.QParallelAnimationGroup() self.animation = QtCore.QParallelAnimationGroup()
self.animation.addAnimation( self.animation.addAnimation(
QtCore.QPropertyAnimation(self, b"minimumHeight") QtCore.QPropertyAnimation(self, b'minimumHeight')
) )
self.animation.addAnimation( self.animation.addAnimation(
QtCore.QPropertyAnimation(self, b"maximumHeight") QtCore.QPropertyAnimation(self, b'maximumHeight')
) )
self.animation.addAnimation( self.animation.addAnimation(
QtCore.QPropertyAnimation(self.content, b"maximumHeight") QtCore.QPropertyAnimation(self.content, b'maximumHeight')
) )
self.layout = QtWidgets.QGridLayout() self.layout = QtWidgets.QGridLayout()
self.layout.addWidget(self.toggle, 0, 0, 1, 1, QtCore.Qt.AlignLeft) self.layout.addWidget(self.toggle, 0, 0, 1, 1, QtCore.Qt.AlignLeft)
@@ -181,16 +181,20 @@ class Spoiler(QtWidgets.QWidget):
last.setEndValue(content_height) last.setEndValue(content_height)
class CommandWidget(QtWidgets.QLineEdit):
def value(self):
res = self.text().split(' ')
return {'program': res[0], 'args': res[1:]}
class KeyBindingDialog(QtWidgets.QDialog): class KeyBindingDialog(QtWidgets.QDialog):
action_options = ([ action_options = ([
"", "Copy", "Paste", "PasteSelection", "IncreaseFontSize", "DecreaseFontSize", '', 'Copy', 'Paste', 'PasteSelection', 'IncreaseFontSize', 'DecreaseFontSize',
"ResetFontSize", "ScrollPageUp", "ScrollPageDown", "ScrollLineUp", 'ResetFontSize', 'ScrollPageUp', 'ScrollPageDown', 'ScrollLineUp',
"ScrollLineDown", "ScrollToTop", "ScrollToBottom", "ClearHistory", "Hide", 'ScrollLineDown', 'ScrollToTop', 'ScrollToBottom', 'ClearHistory', 'Hide',
"Quit", "ToggleFullscreen", "SpawnNewInstance", "ClearLogNotice", "None", 'Quit', 'ToggleFullscreen', 'SpawnNewInstance', 'ClearLogNotice', 'None',
] + (['ToggleSimpleFullscreen'] if platform.system() == 'Darwin' else [])) ] + (['ToggleSimpleFullscreen'] if platform.system() == 'Darwin' else []))
modifier_options = ["Command", "Control", "Option", "Super", "Shift", "Alt"]
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.result = {} self.result = {}
@@ -203,7 +207,7 @@ class KeyBindingDialog(QtWidgets.QDialog):
self.layout.addRow(QtWidgets.QLabel('Key'), self.key) self.layout.addRow(QtWidgets.QLabel('Key'), self.key)
self.mods = QtWidgets.QListWidget() self.mods = QtWidgets.QListWidget()
for option in self.modifier_options: for option in self.MODIFIERS:
self.mods.addItem(option) self.mods.addItem(option)
self.mods.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) self.mods.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.layout.addRow(QtWidgets.QLabel('Mods'), self.mods) self.layout.addRow(QtWidgets.QLabel('Mods'), self.mods)
@@ -218,7 +222,7 @@ class KeyBindingDialog(QtWidgets.QDialog):
self.chars = QtWidgets.QLineEdit() self.chars = QtWidgets.QLineEdit()
self.tabs.addTab(self.chars, 'Chars') self.tabs.addTab(self.chars, 'Chars')
self.command = QtWidgets.QLineEdit() self.command = CommandWidget('')
self.tabs.addTab(self.command, 'Command') self.tabs.addTab(self.command, 'Command')
self.layout.addWidget(self.tabs) self.layout.addWidget(self.tabs)
@@ -245,27 +249,23 @@ class KeyBindingDialog(QtWidgets.QDialog):
title = self.tabs.tabText(idx).lower() title = self.tabs.tabText(idx).lower()
if title == 'action': if title == 'action':
self.result['action'] = self.action.currentText() self.result['action'] = self.action.text()
elif title == 'chars': elif title == 'chars':
self.result['chars'] = self.chars.text() self.result['chars'] = self.chars.text()
elif title == 'command': elif title == 'command':
command = self.command.text().split(' ') self.result['command'] = self.command.value()
self.result['command'] = {
'program': command[0], 'args': command[1:]
}
self.accept() self.accept()
class MouseBindingDialog(QtWidgets.QDialog): class MouseBindingDialog(QtWidgets.QDialog):
action_options = ([ action_options = ([
"Copy", "Paste", "PasteSelection", "IncreaseFontSize", "DecreaseFontSize", 'Copy', 'Paste', 'PasteSelection', 'IncreaseFontSize', 'DecreaseFontSize',
"ResetFontSize", "ScrollPageUp", "ScrollPageDown", "ScrollLineUp", 'ResetFontSize', 'ScrollPageUp', 'ScrollPageDown', 'ScrollLineUp',
"ScrollLineDown", "ScrollToTop", "ScrollToBottom", "ClearHistory", "Hide", 'ScrollLineDown', 'ScrollToTop', 'ScrollToBottom', 'ClearHistory', 'Hide',
"Quit", "ToggleFullscreen", "SpawnNewInstance", "ClearLogNotice", "None", 'Quit', 'ToggleFullscreen', 'SpawnNewInstance', 'ClearLogNotice', 'None',
] + (['ToggleSimpleFullscreen'] if platform.system() == 'Darwin' else [])) ] + (['ToggleSimpleFullscreen'] if platform.system() == 'Darwin' else []))
modifier_options = ["Command", "Control", "Option", "Super", "Shift", "Alt"]
mouse_options = [ mouse_options = [
'Middle', 'Left', 'Right', '1', '2', '3', '4', '5', '6', '7', '8', '9' 'Middle', 'Left', 'Right', '1', '2', '3', '4', '5', '6', '7', '8', '9'
@@ -285,7 +285,7 @@ class MouseBindingDialog(QtWidgets.QDialog):
self.layout.addRow(QtWidgets.QLabel('Mouse'), self.mouse) self.layout.addRow(QtWidgets.QLabel('Mouse'), self.mouse)
self.mods = QtWidgets.QListWidget() self.mods = QtWidgets.QListWidget()
for option in self.modifier_options: for option in MODIFIERS:
self.mods.addItem(option) self.mods.addItem(option)
self.mods.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) self.mods.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.layout.addRow(QtWidgets.QLabel('Mods'), self.mods) self.layout.addRow(QtWidgets.QLabel('Mods'), self.mods)
@@ -590,7 +590,7 @@ class Shell(ConfigWidget):
for elem in config.get('args', []): for elem in config.get('args', []):
self.widgets['args'].addItem(elem) self.widgets['args'].addItem(elem)
for _ in range(3): for _ in range(3):
widget = QtWidgets.QListWidgetItem("") widget = QtWidgets.QListWidgetItem('')
widget.setFlags(widget.flags() | QtCore.Qt.ItemIsEditable) widget.setFlags(widget.flags() | QtCore.Qt.ItemIsEditable)
self.widgets['args'].addItem(widget) self.widgets['args'].addItem(widget)
self.render_state() self.render_state()
@@ -848,6 +848,47 @@ class MouseBindings(ConfigWidget):
self.render_state() self.render_state()
class Mouse(ConfigWidget):
def __init__(self, config):
super().__init__()
double_threshold = QtWidgets.QSpinBox()
double_threshold.setMaximum(10000)
double_threshold.setValue(config.get('double_click', {}).get('threshold'))
triple_threshold = QtWidgets.QSpinBox()
triple_threshold.setMaximum(10000)
triple_threshold.setValue(config.get('triple_click', {}).get('threshold'))
hide_when_typing = QtWidgets.QCheckBox()
hide_when_typing.setChecked(config.get('hide_when_typing', False))
launcher = CommandWidget(config.get('url', {}).get('launcher', ''))
modifiers = QtWidgets.QComboBox()
for modifier in MODIFIERS:
modifiers.addItem(modifier)
dec = config.get('modifiers')
if dec in MODIFIERS:
modifiers.setCurrentIndex(self.modifier_options.index(dec))
else:
modifiers.setCurrentIndex(0)
self.widgets = {
'hide_when_typing': hide_when_typing,
'url': {
'launcher': launcher
},
'modifiers': modifiers,
'double_click': {
'threshold': double_threshold,
},
'triple_click': {
'threshold': triple_threshold,
},
}
self.render_state()
class Config(QtWidgets.QWidget): class Config(QtWidgets.QWidget):
def __init__(self, config, dry=False): def __init__(self, config, dry=False):
super().__init__() super().__init__()
@@ -863,32 +904,34 @@ class Config(QtWidgets.QWidget):
def add_tabs(self): def add_tabs(self):
self.tabs = QtWidgets.QTabWidget() self.tabs = QtWidgets.QTabWidget()
self.tabs.addTab(General(self.config), "General") self.tabs.addTab(General(self.config), 'General')
self.tabs.setTabToolTip(0, "General") self.tabs.setTabToolTip(0, 'General')
self.tabs.addTab(Window(self.config.get('window', {})), "Window") self.tabs.addTab(Window(self.config.get('window', {})), 'Window')
self.tabs.setTabToolTip(1, "Window") self.tabs.setTabToolTip(1, 'Window')
self.tabs.addTab(Font(self.config.get('font', {})), "Font") self.tabs.addTab(Font(self.config.get('font', {})), 'Font')
self.tabs.setTabToolTip(2, "Font") self.tabs.setTabToolTip(2, 'Font')
self.tabs.addTab(Debug(self.config.get('debug', {})), "Debug") self.tabs.addTab(Debug(self.config.get('debug', {})), 'Debug')
self.tabs.setTabToolTip(3, "Debug") self.tabs.setTabToolTip(3, 'Debug')
self.tabs.addTab(Env(self.config.get('env', {})), "Env") self.tabs.addTab(Env(self.config.get('env', {})), 'Env')
self.tabs.setTabToolTip(4, "Env") self.tabs.setTabToolTip(4, 'Env')
self.tabs.addTab(Selection(self.config.get('selection', {})), "Selection") self.tabs.addTab(Selection(self.config.get('selection', {})), 'Selection')
self.tabs.setTabToolTip(5, "Selection") self.tabs.setTabToolTip(5, 'Selection')
self.tabs.addTab(Shell(self.config.get('shell', {})), "Shell") self.tabs.addTab(Shell(self.config.get('shell', {})), 'Shell')
self.tabs.setTabToolTip(6, "Shell") self.tabs.setTabToolTip(6, 'Shell')
self.tabs.addTab(Colors(self.config.get('colors', {})), "Colors") self.tabs.addTab(Colors(self.config.get('colors', {})), 'Colors')
self.tabs.setTabToolTip(7, "Colors") self.tabs.setTabToolTip(7, 'Colors')
self.tabs.addTab(Scrolling(self.config.get('scrolling', {})), "Scrolling") self.tabs.addTab(Scrolling(self.config.get('scrolling', {})), 'Scrolling')
self.tabs.setTabToolTip(8, "Scrolling") self.tabs.setTabToolTip(8, 'Scrolling')
self.tabs.addTab( self.tabs.addTab(
KeyBindings(self.config.get('key_bindings', [])), "Key Bindings" KeyBindings(self.config.get('key_bindings', [])), 'Key Bindings'
) )
self.tabs.setTabToolTip(9, "Key Bindings") self.tabs.setTabToolTip(9, 'Key Bindings')
self.tabs.addTab( self.tabs.addTab(
MouseBindings(self.config.get('mouse_bindings', [])), "Mouse Bindings" MouseBindings(self.config.get('mouse_bindings', [])), 'Mouse Bindings'
) )
self.tabs.setTabToolTip(10, "Mouse Bindings") self.tabs.setTabToolTip(10, 'Mouse Bindings')
self.tabs.addTab(Mouse(self.config.get('mouse', {})), 'Mouse')
self.tabs.setTabToolTip(11, 'Mouse')
self.layout.addWidget(self.tabs) self.layout.addWidget(self.tabs)
@@ -905,7 +948,7 @@ class Config(QtWidgets.QWidget):
for idx in range(self.tabs.count()): for idx in range(self.tabs.count()):
tab = self.tabs.widget(idx) tab = self.tabs.widget(idx)
title = "_".join(self.tabs.tabText(idx).lower().split(" ")) title = '_'.join(self.tabs.tabText(idx).lower().split(' '))
old = state.get(title, {}) old = state.get(title, {})
if type(old) == list: if type(old) == list:
state[title].extend(e for e in tab.gather_state() if e not in old) state[title].extend(e for e in tab.gather_state() if e not in old)