diff --git a/components/customButton.py b/components/customButton.py new file mode 100755 index 0000000..2830e9a --- /dev/null +++ b/components/customButton.py @@ -0,0 +1,9 @@ +from PyQt6.QtWidgets import ( + QPushButton, +) + +class CustomButton(QPushButton): + def mousePressEvent(self, e): + self.parentWidget().mousePressEvent(e) + + super().mousePressEvent(e) \ No newline at end of file diff --git a/components/mainWindow.py b/components/mainWindow.py index a5cc2f4..395a52b 100755 --- a/components/mainWindow.py +++ b/components/mainWindow.py @@ -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()