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