Skip to content

Commit e16c1dc

Browse files
committed
back to a working state
1 parent 68c2743 commit e16c1dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6626
-523
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

app/components/__init__.py

Whitespace-only changes.

app/components/custom_button.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import colorsys
2+
from typing import List, Tuple
3+
from PyQt6.QtWidgets import QPushButton
4+
from PyQt6.QtCore import QRect, QSize, Qt
5+
from PyQt6.QtGui import QPainter, QColor, QPaintEvent
6+
7+
from app.models.device_actions import Action
8+
from app.models.joystick import JoyAction
9+
10+
11+
def get_palette_color(n: int) -> List[Tuple[int, int, int]]:
12+
colors = []
13+
for i in range(n):
14+
# Evenly distribute hues across the number of colors
15+
hue = i / n
16+
# Use full saturation and brightness for vibrant colors
17+
rgb = colorsys.hsv_to_rgb(hue, 1.0, 1.0)
18+
# Convert to 8-bit RGB values
19+
rgb = tuple(int(channel * 255) for channel in rgb)
20+
colors.append(rgb)
21+
return colors
22+
23+
24+
btn_modifiers= {
25+
"tap": "purple",
26+
"mod": "lightgreen",
27+
"multitap": "lightblue",
28+
"hold": "lightcoral",
29+
30+
}
31+
32+
33+
def gen_cat_colors(actions: List[Action]) -> dict[str, Tuple[int, int, int]]:
34+
colors = get_palette_color(len(actions))
35+
return {action.name: colors[i] for i, action in enumerate(actions)}
36+
37+
38+
39+
class CustomButton(QPushButton):
40+
def __init__(self, items: List[JoyAction] | None = None, parent=None):
41+
super().__init__(parent)
42+
self.items : List[JoyAction] = items if items is not None else [] # items is a list of tuples (text, action)
43+
self.setStyleSheet("background-color: transparent;")
44+
self.setMinimumSize(100, 50) # Adjust as needed
45+
46+
def sizeHint(self):
47+
# Compute the size based on number of items
48+
font_metrics = self.fontMetrics()
49+
height = font_metrics.height() * len(self.items)
50+
width = max([font_metrics.horizontalAdvance(text) for text, _ in self.items], default=0)
51+
# Add space for the colored squares
52+
width += 20 # Adjust as needed
53+
return QSize(width, height)
54+
55+
def paintEvent(self, event: QPaintEvent):
56+
painter = QPainter(self)
57+
font_metrics = painter.fontMetrics()
58+
y = font_metrics.ascent() + 2 # Adjust for padding
59+
text_x = 2
60+
for action in self.items:
61+
# Determine if we need to draw a colored square
62+
if action:
63+
colors = self.get_action_colors(action)
64+
for color in colors:
65+
66+
# Draw colored square
67+
square_size = font_metrics.height() - 4 # Adjust as needed
68+
rect = QRect(2, y - font_metrics.ascent(), square_size, square_size)
69+
painter.fillRect(rect, QColor(color))
70+
text_x = rect.right() + 5
71+
for category in action.category:
72+
if category in modes:
73+
color = modes[category]
74+
square_size = font_metrics.height() - 4
75+
76+
else:
77+
text_x = 2
78+
79+
# Draw text
80+
painter.drawText(text_x, y, action.name)
81+
82+
y += font_metrics.height()
83+
84+
85+
86+
def get_action_colors(self, action: JoyAction) -> List[str]:
87+
colors = []
88+
for modifier, color in btn_modifiers.items():
89+
if getattr(action, modifier):
90+
colors.append(color)
91+
92+
return colors

app/models/settings_dialog.py renamed to app/components/settings_dialog.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@
99

1010
from app.config import Config
1111

12-
13-
12+
from app.utils.devices import get_controller_devices #returns List[SystemDevices]
13+
14+
""" #for reference
15+
class SystemDevice(BaseModel):
16+
name: str
17+
instance: int
18+
product_guid: str
19+
product_name: str
20+
num_axes: int
21+
num_buttons: int
22+
"""
1423

1524
class SettingsDialog(QDialog):
1625
def __init__(self, config: Config, parent: Optional[QWidget] = None):

app/models/ui_action.py renamed to app/components/ui_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from PyQt6.QtCore import Qt, QSortFilterProxyModel, QModelIndex
55
from pydantic import BaseModel
66
from app.globals import localization_file
7-
from app.models.actions import AllActionMaps
7+
from models.full_game_control_options import AllActionMaps
88

99
class WidgetItemRoleData(BaseModel):
1010
is_category: bool = False

app/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import json
2+
from pathlib import Path
23
from typing import Literal
34
from pydantic_settings import BaseSettings
4-
from app.globals import APP_PATH
5+
6+
APP_PATH = Path(__file__).parent
57

68

79
class Config(BaseSettings):

0 commit comments

Comments
 (0)