mirror of
https://github.com/marcriera/ddgo-converter.git
synced 2025-04-19 10:29:29 +02:00
Remove config, UI improvements
This commit is contained in:
parent
8c875d3b8d
commit
b6a1a9f5bb
7 changed files with 49 additions and 48 deletions
|
@ -3,14 +3,12 @@
|
|||
import sys
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from gui.main import MainWindow
|
||||
from handlers.config import ConfigHandler
|
||||
from handlers.gamepad import GamepadHandler
|
||||
|
||||
class App(QApplication):
|
||||
def __init__(self, sys_argv):
|
||||
super(App, self).__init__(sys_argv)
|
||||
self.config = ConfigHandler("config.json")
|
||||
self.main_view = MainWindow(GamepadHandler, self.config)
|
||||
self.main_view = MainWindow(GamepadHandler)
|
||||
self.main_view.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
21
gui/main.py
21
gui/main.py
|
@ -6,11 +6,10 @@ from handlers.gamepad import Gamepad
|
|||
from models.gamepad import GamepadModel
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self, gamepad_handler, config_handler):
|
||||
def __init__(self, gamepad_handler):
|
||||
super().__init__()
|
||||
|
||||
self._gamepad_handler = gamepad_handler
|
||||
self._config_handler = config_handler
|
||||
self._gui = Ui_MainWindow()
|
||||
self._gui.setupUi(self)
|
||||
|
||||
|
@ -19,14 +18,26 @@ class MainWindow(QMainWindow):
|
|||
self._gui.tableView_physicalControllerList.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
|
||||
self._gui.tableView_physicalControllerList.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
|
||||
self._gui.tableView_physicalControllerList.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents)
|
||||
self._gui.tableView_physicalControllerList.selectionModel().selectionChanged.connect(self.controller_list_selection_changed)
|
||||
self._gui.tableView_physicalControllerList.selectRow(0)
|
||||
|
||||
self._gui.pushButton_physicalControllerRefresh.clicked.connect(self.controller_list_refresh)
|
||||
self._gui.pushButton_physicalControllerConfig.clicked.connect(self.save)
|
||||
self._gui.pushButton_emulatedControllerStart.clicked.connect(self.start)
|
||||
|
||||
def controller_list_refresh(self):
|
||||
self.gamepad_model.beginResetModel()
|
||||
self.gamepad_model.gamepads = self._gamepad_handler.find_gamepads()
|
||||
self.gamepad_model.endResetModel()
|
||||
|
||||
def save(self):
|
||||
self._config_handler.save()
|
||||
def controller_list_selection_changed(self):
|
||||
enabled = False
|
||||
rows = self._gui.tableView_physicalControllerList.selectionModel().selectedRows()
|
||||
if rows and self.gamepad_model.gamepads[rows[0].row()].type != Gamepad.GamepadType.UNKNOWN:
|
||||
enabled = True
|
||||
self._gui.pushButton_emulatedControllerStart.setEnabled(enabled)
|
||||
|
||||
def start(self):
|
||||
rows = self._gui.tableView_physicalControllerList.selectionModel().selectedRows()
|
||||
if rows:
|
||||
gamepad = self.gamepad_model.gamepads[rows[0].row()]
|
||||
print(gamepad.name)
|
|
@ -76,6 +76,7 @@ class Ui_MainWindow(object):
|
|||
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
|
||||
self.horizontalLayout.addItem(spacerItem1)
|
||||
self.pushButton_emulatedControllerStart = QtWidgets.QPushButton(self.groupBox_emulatedController)
|
||||
self.pushButton_emulatedControllerStart.setEnabled(False)
|
||||
self.pushButton_emulatedControllerStart.setObjectName("pushButton_emulatedControllerStart")
|
||||
self.horizontalLayout.addWidget(self.pushButton_emulatedControllerStart)
|
||||
self.verticalLayout_main.addWidget(self.groupBox_emulatedController)
|
||||
|
|
|
@ -152,6 +152,9 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_emulatedControllerStart">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
import json
|
||||
|
||||
class ConfigHandler:
|
||||
def __init__(self, path):
|
||||
super().__init__()
|
||||
|
||||
self._path = path
|
||||
self._config = []
|
||||
self.load()
|
||||
|
||||
def load(self):
|
||||
try:
|
||||
with open(self._path, 'r') as f:
|
||||
self._config = json.load(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def save(self):
|
||||
with open(self._path, 'w') as f:
|
||||
json.dump(self._config, f, indent = 4)
|
||||
|
||||
def get_config(self, hash):
|
||||
return None
|
||||
|
||||
def set_config(self, hash, data):
|
||||
return
|
||||
|
|
@ -2,17 +2,6 @@ from enum import Enum
|
|||
from evdev import InputDevice, list_devices, ecodes as e, UInput, AbsInfo
|
||||
from hashlib import sha1
|
||||
|
||||
class GamepadHandler:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def find_gamepads():
|
||||
gamepads = []
|
||||
devices = [InputDevice(path) for path in list_devices()]
|
||||
for device in devices:
|
||||
gamepads.append(Gamepad(device.info.vendor, device.info.product, device.name))
|
||||
return gamepads
|
||||
|
||||
class Gamepad:
|
||||
|
||||
class GamepadType(Enum):
|
||||
|
@ -40,12 +29,39 @@ class Gamepad:
|
|||
hash = sha1(str(self.id + ":" + self.name).encode('utf-8')).hexdigest()
|
||||
return hash
|
||||
|
||||
def _get_gamepad_type(self):
|
||||
def get_gamepad_type(self):
|
||||
match self.vid, self.pid:
|
||||
case 0x0f0d, 0x00c1:
|
||||
return self.GamepadType.NSWITCH
|
||||
return self.GamepadType.UNKNOWN
|
||||
|
||||
class EmulatedGamepad:
|
||||
|
||||
class GamepadType(Enum):
|
||||
DGOC44U = 0
|
||||
PS1 = 1
|
||||
|
||||
def __init__(self, type):
|
||||
super().__init__()
|
||||
self.type = type
|
||||
|
||||
class GamepadHandler:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def find_gamepads():
|
||||
gamepads = []
|
||||
devices = [InputDevice(path) for path in list_devices()]
|
||||
for device in devices:
|
||||
gamepads.append(Gamepad(device.info.vendor, device.info.product, device.name))
|
||||
return gamepads
|
||||
|
||||
def start_gamepad_emulator(gamepad: Gamepad, emulated_gamepad: EmulatedGamepad):
|
||||
realtype = gamepad.type
|
||||
emutype = emulated_gamepad.type
|
||||
print(str(realtype)+str(emutype))
|
||||
|
||||
|
||||
""" cap = {
|
||||
e.EV_KEY : [e.BTN_NORTH, e.BTN_SOUTH, e.BTN_EAST, e.BTN_WEST, e.BTN_SELECT, e.BTN_START],
|
||||
e.EV_ABS : [(e.ABS_X, AbsInfo(0, 0, 255, 0, 0, 0)), (e.ABS_Y, AbsInfo(0, 0, 255, 0, 0, 0))]
|
||||
|
|
|
@ -33,4 +33,3 @@ class GamepadModel(QAbstractTableModel):
|
|||
if role != Qt.DisplayRole or orientation != Qt.Horizontal:
|
||||
return QVariant()
|
||||
return headers[section]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue