mirror of
https://github.com/marcriera/ddgo-converter.git
synced 2025-04-19 10:29:29 +02:00
Tests with configs
This commit is contained in:
parent
25ba4cdbc0
commit
8c875d3b8d
5 changed files with 48 additions and 27 deletions
|
@ -3,12 +3,14 @@
|
|||
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.main_view = MainWindow(GamepadHandler)
|
||||
self.config = ConfigHandler("config.json")
|
||||
self.main_view = MainWindow(GamepadHandler, self.config)
|
||||
self.main_view.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -6,10 +6,11 @@ from handlers.gamepad import Gamepad
|
|||
from models.gamepad import GamepadModel
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self, gamepad_handler):
|
||||
def __init__(self, gamepad_handler, config_handler):
|
||||
super().__init__()
|
||||
|
||||
self._gamepad_handler = gamepad_handler
|
||||
self._config_handler = config_handler
|
||||
self._gui = Ui_MainWindow()
|
||||
self._gui.setupUi(self)
|
||||
|
||||
|
@ -20,9 +21,12 @@ class MainWindow(QMainWindow):
|
|||
self._gui.tableView_physicalControllerList.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents)
|
||||
|
||||
self._gui.pushButton_physicalControllerRefresh.clicked.connect(self.controller_list_refresh)
|
||||
self._gui.pushButton_physicalControllerConfig.clicked.connect(self.save)
|
||||
|
||||
def controller_list_refresh(self):
|
||||
self.gamepad_model.beginResetModel()
|
||||
self.gamepad_model.gamepads = self._gamepad_handler.find_gamepads()
|
||||
self.gamepad_model.endResetModel()
|
||||
return
|
||||
|
||||
def save(self):
|
||||
self._config_handler.save()
|
|
@ -1,13 +1,27 @@
|
|||
import json
|
||||
|
||||
class ConfigHandler:
|
||||
def __init__(self):
|
||||
def __init__(self, path):
|
||||
super().__init__()
|
||||
|
||||
def load():
|
||||
return
|
||||
self._path = path
|
||||
self._config = []
|
||||
self.load()
|
||||
|
||||
def save():
|
||||
return
|
||||
def load(self):
|
||||
try:
|
||||
with open(self._path, 'r') as f:
|
||||
self._config = json.load(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def update():
|
||||
return
|
||||
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
|
||||
|
||||
|
|
|
@ -1,5 +1,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):
|
||||
|
@ -24,11 +25,23 @@ class Gamepad:
|
|||
self.vid = vid
|
||||
self.pid = pid
|
||||
self.name = name
|
||||
self.type = self.get_gamepad_type(vid, pid)
|
||||
self.config = None
|
||||
self.id = self._get_gamepad_id()
|
||||
self.hash = self._get_gamepad_hash()
|
||||
self.type = self._get_gamepad_type()
|
||||
self.config = []
|
||||
|
||||
def get_gamepad_type(self, vid, pid):
|
||||
match vid, pid:
|
||||
def _get_gamepad_id(self):
|
||||
vid = format(self.vid, "x").zfill(4)
|
||||
pid = format(self.pid, "x").zfill(4)
|
||||
id = str(vid + ":" + pid)
|
||||
return id
|
||||
|
||||
def _get_gamepad_hash(self):
|
||||
hash = sha1(str(self.id + ":" + self.name).encode('utf-8')).hexdigest()
|
||||
return hash
|
||||
|
||||
def _get_gamepad_type(self):
|
||||
match self.vid, self.pid:
|
||||
case 0x0f0d, 0x00c1:
|
||||
return self.GamepadType.NSWITCH
|
||||
return self.GamepadType.UNKNOWN
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from hashlib import sha1
|
||||
from PyQt5.QtCore import Qt, QVariant, QAbstractTableModel
|
||||
from handlers.gamepad import Gamepad
|
||||
|
||||
|
@ -13,7 +12,7 @@ class GamepadModel(QAbstractTableModel):
|
|||
if role == Qt.DisplayRole:
|
||||
match index.column():
|
||||
case 0:
|
||||
return self.get_gamepad_id(index)
|
||||
return self.gamepads[index.row()].id
|
||||
case 1:
|
||||
return self.gamepads[index.row()].name
|
||||
case 2:
|
||||
|
@ -35,14 +34,3 @@ class GamepadModel(QAbstractTableModel):
|
|||
return QVariant()
|
||||
return headers[section]
|
||||
|
||||
def get_gamepad_id(self, index):
|
||||
vid = format(self.gamepads[index.row()].vid, "x").zfill(4)
|
||||
pid = format(self.gamepads[index.row()].pid, "x").zfill(4)
|
||||
id = str(vid + ":" + pid)
|
||||
return id
|
||||
|
||||
def get_gamepad_hash(self, index):
|
||||
id = self.get_gamepad_id(index)
|
||||
name = self.gamepads[index.row()].name
|
||||
hash = sha1(str(id + ":" + name).encode('utf-8')).hexdigest()
|
||||
return hash
|
||||
|
|
Loading…
Add table
Reference in a new issue