Added Shift-Click functionality to list buttons and numbered buttons

This commit is contained in:
=
2024-08-15 20:42:05 -06:00
parent 4af65368b6
commit 971a5c507a
2 changed files with 66 additions and 35 deletions

View File

@@ -5,14 +5,20 @@ from PyQt6.QtWidgets import (
QHBoxLayout,
)
from PyQt6.QtCore import Qt
from components.customButton import CustomButton
from data.collectibles import collectibles
class MainWindow(QWidget):
collectibles = {}
def __init__(self, *args, **kwargs):
def __init__(self: QWidget, *args, **kwargs):
super().__init__(*args, **kwargs)
self.initUI()
def initUI(self):
# Set the window title
self.setWindowTitle('Y-Tracker')
self.collectibles = collectibles
@@ -30,6 +36,7 @@ class MainWindow(QWidget):
self.layout_dict = {}
self.label_dict = {}
self.button_dict = {}
self.modifiers = Qt.KeyboardModifier.NoModifier
# Build the Inputs
for type in self.collectibles:
@@ -47,7 +54,7 @@ class MainWindow(QWidget):
for item in self.collectibles[type]:
if item != 'meta':
self.button_dict[type][item] = QPushButton()
self.button_dict[type][item] = CustomButton()
self.button_dict[type][item].setObjectName(f'{type}-{item}')
if self.collectibles[type]['meta']['type'] == 'bool':
@@ -67,47 +74,62 @@ class MainWindow(QWidget):
}
""")
self.button_dict[type][item].clicked.connect(lambda state, x=[type, item]: boolButtonSelect(self, x[0], x[1]))
self.button_dict[type][item].clicked.connect(lambda state, x=[type, item]: self.boolButtonSelect(x[0], x[1]))
elif self.collectibles[type]['meta']['type'] == 'int':
self.button_dict[type][item].setText(f'{self.collectibles[type][item]["name"]}: {self.collectibles[type][item]["value"]}')
self.button_dict[type][item].clicked.connect(lambda state, x=[type, item]: intButtonSelect(self, x[0], x[1]))
self.button_dict[type][item].clicked.connect(lambda state, x=[type, item]: self.intButtonSelect(x[0], x[1]))
elif self.collectibles[type]['meta']['type'] == 'list':
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
self.button_dict[type][item].clicked.connect(lambda state, x=[type, item]: listButtonSelect(self, x[0], x[1]))
self.button_dict[type][item].clicked.connect(lambda state, x=[type, item]: self.listButtonSelect(x[0], x[1]))
self.layout_dict[type].addWidget(self.button_dict[type][item])
# Add Events
def boolButtonSelect(self, type, item):
if self.collectibles[type][item]['value']:
self.collectibles[type][item]['value'] = False
self.button_dict[type][item].setStyleSheet("""
QPushButton#""" + self.button_dict[type][item].objectName() + """ {
color: #88FFFFFF
}
""")
else:
self.collectibles[type][item]['value'] = True
self.button_dict[type][item].setStyleSheet("""
QPushButton#""" + self.button_dict[type][item].objectName() + """ {
color: #FFFFFFFF
}
""")
def intButtonSelect(self, type, item):
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] + 1
self.button_dict[type][item].setText(f'{self.collectibles[type][item]["name"]}: {self.collectibles[type][item]["value"]}')
def listButtonSelect(self, type, item):
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] + 1
try:
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
except:
self.collectibles[type][item]['value'] = 0
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
# show the window
self.show()
# Add Slots
def boolButtonSelect(self, type, item):
if self.collectibles[type][item]['value']:
self.collectibles[type][item]['value'] = False
self.button_dict[type][item].setStyleSheet("""
QPushButton#""" + self.button_dict[type][item].objectName() + """ {
color: #88FFFFFF
}
""")
else:
self.collectibles[type][item]['value'] = True
self.button_dict[type][item].setStyleSheet("""
QPushButton#""" + self.button_dict[type][item].objectName() + """ {
color: #FFFFFFFF
}
""")
def intButtonSelect(self, type, item):
if self.modifiers == Qt.KeyboardModifier.ShiftModifier:
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] - 1
else:
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] + 1
self.button_dict[type][item].setText(f'{self.collectibles[type][item]["name"]}: {self.collectibles[type][item]["value"]}')
def listButtonSelect(self, type, item):
if self.modifiers == Qt.KeyboardModifier.ShiftModifier:
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] - 1
else:
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] + 1
try:
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
except:
if self.collectibles[type][item]['value'] < 0:
self.collectibles[type][item]['value'] = len(self.collectibles[type]['meta']['list']) - 1
else:
self.collectibles[type][item]['value'] = 0
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
def mousePressEvent(self, e):
self.modifiers = e.modifiers()