gui: tweak layout

This commit is contained in:
2019-06-26 13:25:48 +02:00
parent 62bbde8bf7
commit 59ec9f6abf

View File

@@ -188,36 +188,27 @@ class KeyBindingDialog(QtWidgets.QDialog):
def __init__(self):
super().__init__()
self.result = {}
self.layout = QtWidgets.QVBoxLayout()
self.layout = QtWidgets.QFormLayout()
self.layout.setFieldGrowthPolicy(
QtWidgets.QFormLayout.AllNonFixedFieldsGrow
)
sub_layout = QtWidgets.QHBoxLayout()
sub_layout.addWidget(QtWidgets.QLabel('Key'))
self.key = QtWidgets.QLineEdit()
sub_layout.addWidget(self.key)
self.layout.addLayout(sub_layout)
self.layout.addRow(QtWidgets.QLabel('Key'), self.key)
sub_layout = QtWidgets.QHBoxLayout()
sub_layout.addWidget(QtWidgets.QLabel('Mods'))
self.mods = QtWidgets.QListWidget()
for option in self.modifier_options:
self.mods.addItem(option)
self.mods.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
sub_layout.addWidget(self.mods)
self.layout.addLayout(sub_layout)
self.layout.addRow(QtWidgets.QLabel('Mods'), self.mods)
sub_layout = QtWidgets.QHBoxLayout()
sub_layout.addWidget(QtWidgets.QLabel('Action'))
self.action = QtWidgets.QComboBox()
for option in self.action_options:
self.action.addItem(option)
sub_layout.addWidget(self.action)
self.layout.addLayout(sub_layout)
self.layout.addRow(QtWidgets.QLabel('Action'), self.action)
sub_layout = QtWidgets.QHBoxLayout()
sub_layout.addWidget(QtWidgets.QLabel('Chars'))
self.chars = QtWidgets.QLineEdit()
sub_layout.addWidget(self.chars)
self.layout.addLayout(sub_layout)
self.layout.addRow(QtWidgets.QLabel('Chars'), self.chars)
buttons = QtWidgets.QDialogButtonBox()
buttons.addButton(buttons.Ok)
@@ -258,6 +249,7 @@ class KeyBindingsWidget(QtWidgets.QWidget):
def init(self):
self.layout = QtWidgets.QVBoxLayout()
self.layout.setContentsMargins(0, 0, 0, 0)
self.update()
btn_group = QtWidgets.QHBoxLayout()
btn_group.setAlignment(QtCore.Qt.AlignLeft)
@@ -338,19 +330,15 @@ class ConfigWidget(QtWidgets.QWidget):
def prettify(self, s):
return ' '.join(x.capitalize() for x in s.split('_'))
def render_item(self, layout, name, widget):
sub_layout = QtWidgets.QHBoxLayout()
sub_layout.addWidget(QtWidgets.QLabel(self.prettify(name)))
sub_layout.addWidget(widget)
layout.addLayout(sub_layout)
def render_section(self, widgets, sup=None, name=None):
layout = QtWidgets.QVBoxLayout()
layout = QtWidgets.QFormLayout()
layout.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow)
for wname, widget in widgets.items():
if type(widget) is dict:
self.render_section(widget, layout, wname)
else:
self.render_item(layout, wname, widget)
layout.addRow(QtWidgets.QLabel(self.prettify(wname)), widget)
if name and sup is not None:
layout.setContentsMargins(10, 0, 0, 0)
@@ -706,7 +694,6 @@ class Config(QtWidgets.QWidget):
self.config = config
self.add_tabs()
self.add_buttons()
self.setWindowTitle(NAME)
self.setLayout(self.layout)
def add_tabs(self):
@@ -751,11 +738,27 @@ class Config(QtWidgets.QWidget):
sys.exit()
if __name__ == '__main__':
def main():
app = QtWidgets.QApplication([NAME])
app.setApplicationName(NAME)
with open(ALACRITTY_CONFIG) as f:
config = yaml.safe_load(f.read())
conf = Config(config)
conf.show()
window = QtWidgets.QMainWindow()
window.setCentralWidget(Config(config))
window.setGeometry(
QtWidgets.QStyle.alignedRect(
QtCore.Qt.LeftToRight,
QtCore.Qt.AlignCenter,
QtCore.QSize(300, 400),
app.desktop().availableGeometry()
)
)
window.setWindowFlags(QtCore.Qt.FramelessWindowHint)
window.setWindowTitle(NAME)
window.setUnifiedTitleAndToolBarOnMac(True)
window.show()
app.exec_()
if __name__ == '__main__':
main()