Added Shift-Click functionality to list buttons and numbered buttons
This commit is contained in:
9
components/customButton.py
Executable file
9
components/customButton.py
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
from PyQt6.QtWidgets import (
|
||||||
|
QPushButton,
|
||||||
|
)
|
||||||
|
|
||||||
|
class CustomButton(QPushButton):
|
||||||
|
def mousePressEvent(self, e):
|
||||||
|
self.parentWidget().mousePressEvent(e)
|
||||||
|
|
||||||
|
super().mousePressEvent(e)
|
@@ -5,14 +5,20 @@ from PyQt6.QtWidgets import (
|
|||||||
QHBoxLayout,
|
QHBoxLayout,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from PyQt6.QtCore import Qt
|
||||||
|
from components.customButton import CustomButton
|
||||||
|
|
||||||
from data.collectibles import collectibles
|
from data.collectibles import collectibles
|
||||||
|
|
||||||
class MainWindow(QWidget):
|
class MainWindow(QWidget):
|
||||||
collectibles = {}
|
collectibles = {}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self: QWidget, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
# Set the window title
|
# Set the window title
|
||||||
self.setWindowTitle('Y-Tracker')
|
self.setWindowTitle('Y-Tracker')
|
||||||
self.collectibles = collectibles
|
self.collectibles = collectibles
|
||||||
@@ -30,6 +36,7 @@ class MainWindow(QWidget):
|
|||||||
self.layout_dict = {}
|
self.layout_dict = {}
|
||||||
self.label_dict = {}
|
self.label_dict = {}
|
||||||
self.button_dict = {}
|
self.button_dict = {}
|
||||||
|
self.modifiers = Qt.KeyboardModifier.NoModifier
|
||||||
|
|
||||||
# Build the Inputs
|
# Build the Inputs
|
||||||
for type in self.collectibles:
|
for type in self.collectibles:
|
||||||
@@ -47,7 +54,7 @@ class MainWindow(QWidget):
|
|||||||
for item in self.collectibles[type]:
|
for item in self.collectibles[type]:
|
||||||
|
|
||||||
if item != 'meta':
|
if item != 'meta':
|
||||||
self.button_dict[type][item] = QPushButton()
|
self.button_dict[type][item] = CustomButton()
|
||||||
self.button_dict[type][item].setObjectName(f'{type}-{item}')
|
self.button_dict[type][item].setObjectName(f'{type}-{item}')
|
||||||
|
|
||||||
if self.collectibles[type]['meta']['type'] == 'bool':
|
if self.collectibles[type]['meta']['type'] == 'bool':
|
||||||
@@ -67,19 +74,22 @@ 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':
|
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].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':
|
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].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])
|
self.layout_dict[type].addWidget(self.button_dict[type][item])
|
||||||
|
|
||||||
# Add Events
|
# show the window
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
# Add Slots
|
||||||
def boolButtonSelect(self, type, item):
|
def boolButtonSelect(self, type, item):
|
||||||
if self.collectibles[type][item]['value']:
|
if self.collectibles[type][item]['value']:
|
||||||
self.collectibles[type][item]['value'] = False
|
self.collectibles[type][item]['value'] = False
|
||||||
@@ -97,17 +107,29 @@ class MainWindow(QWidget):
|
|||||||
""")
|
""")
|
||||||
|
|
||||||
def intButtonSelect(self, type, item):
|
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.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"]}')
|
self.button_dict[type][item].setText(f'{self.collectibles[type][item]["name"]}: {self.collectibles[type][item]["value"]}')
|
||||||
|
|
||||||
def listButtonSelect(self, type, item):
|
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
|
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] + 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
|
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
|
||||||
except:
|
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.collectibles[type][item]['value'] = 0
|
||||||
|
|
||||||
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
|
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
|
||||||
|
|
||||||
# show the window
|
def mousePressEvent(self, e):
|
||||||
self.show()
|
self.modifiers = e.modifiers()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user