mirror of
https://github.com/marcriera/ddgo-converter.git
synced 2025-04-19 10:29:29 +02:00
List gamepads
This commit is contained in:
parent
139875808a
commit
5a8522d05a
5 changed files with 69 additions and 48 deletions
12
gui/main.py
12
gui/main.py
|
@ -3,6 +3,7 @@ from PyQt5 import uic
|
|||
from PyQt5.QtWidgets import QMainWindow, QTableWidgetItem
|
||||
from gui.main_ui import Ui_MainWindow
|
||||
from handlers.gamepad import Gamepad
|
||||
from models.gamepad import GamepadModel
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self, gamepad_handler):
|
||||
|
@ -12,11 +13,12 @@ class MainWindow(QMainWindow):
|
|||
self._gui = Ui_MainWindow()
|
||||
self._gui.setupUi(self)
|
||||
|
||||
model = GamepadModel(gamepad_handler.find_gamepads())
|
||||
self._gui.tableView_physicalControllerList.setModel(model)
|
||||
|
||||
self._gui.tableView_physicalControllerList.resizeColumnsToContents()
|
||||
|
||||
self._gui.pushButton_physicalControllerRefresh.clicked.connect(self.controller_list_refresh)
|
||||
|
||||
def controller_list_refresh(self):
|
||||
self._gui.tableWidget_physicalControllerList.setRowCount(0)
|
||||
for gamepad in self._gamepad_handler.find_gamepads():
|
||||
rowCount = self._gui.tableWidget_physicalControllerList.rowCount()
|
||||
self._gui.tableWidget_physicalControllerList.insertRow(rowCount)
|
||||
self._gui.tableWidget_physicalControllerList.setItem(rowCount , 1, QTableWidgetItem(gamepad.name))
|
||||
return
|
||||
|
|
|
@ -14,14 +14,14 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
|||
class Ui_MainWindow(object):
|
||||
def setupUi(self, MainWindow):
|
||||
MainWindow.setObjectName("MainWindow")
|
||||
MainWindow.resize(800, 600)
|
||||
MainWindow.resize(800, 400)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
|
||||
MainWindow.setSizePolicy(sizePolicy)
|
||||
MainWindow.setMinimumSize(QtCore.QSize(800, 600))
|
||||
MainWindow.setMaximumSize(QtCore.QSize(800, 600))
|
||||
MainWindow.setMinimumSize(QtCore.QSize(800, 400))
|
||||
MainWindow.setMaximumSize(QtCore.QSize(800, 400))
|
||||
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
||||
self.centralwidget.setObjectName("centralwidget")
|
||||
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
|
||||
|
@ -33,20 +33,13 @@ class Ui_MainWindow(object):
|
|||
self.groupBox_physicalControllers.setObjectName("groupBox_physicalControllers")
|
||||
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.groupBox_physicalControllers)
|
||||
self.verticalLayout_2.setObjectName("verticalLayout_2")
|
||||
self.tableWidget_physicalControllerList = QtWidgets.QTableWidget(self.groupBox_physicalControllers)
|
||||
self.tableWidget_physicalControllerList.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
|
||||
self.tableWidget_physicalControllerList.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
||||
self.tableWidget_physicalControllerList.setObjectName("tableWidget_physicalControllerList")
|
||||
self.tableWidget_physicalControllerList.setColumnCount(3)
|
||||
self.tableWidget_physicalControllerList.setRowCount(0)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.tableWidget_physicalControllerList.setHorizontalHeaderItem(0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.tableWidget_physicalControllerList.setHorizontalHeaderItem(1, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.tableWidget_physicalControllerList.setHorizontalHeaderItem(2, item)
|
||||
self.tableWidget_physicalControllerList.horizontalHeader().setStretchLastSection(True)
|
||||
self.verticalLayout_2.addWidget(self.tableWidget_physicalControllerList)
|
||||
self.tableView_physicalControllerList = QtWidgets.QTableView(self.groupBox_physicalControllers)
|
||||
self.tableView_physicalControllerList.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
|
||||
self.tableView_physicalControllerList.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
||||
self.tableView_physicalControllerList.setObjectName("tableView_physicalControllerList")
|
||||
self.tableView_physicalControllerList.horizontalHeader().setStretchLastSection(True)
|
||||
self.tableView_physicalControllerList.verticalHeader().setVisible(False)
|
||||
self.verticalLayout_2.addWidget(self.tableView_physicalControllerList)
|
||||
self.horizontalLayout_physicalControllerActions = QtWidgets.QHBoxLayout()
|
||||
self.horizontalLayout_physicalControllerActions.setObjectName("horizontalLayout_physicalControllerActions")
|
||||
self.pushButton_physicalControllerRefresh = QtWidgets.QPushButton(self.groupBox_physicalControllers)
|
||||
|
@ -99,12 +92,6 @@ class Ui_MainWindow(object):
|
|||
_translate = QtCore.QCoreApplication.translate
|
||||
MainWindow.setWindowTitle(_translate("MainWindow", "Densha de GO! Controller Converter"))
|
||||
self.groupBox_physicalControllers.setTitle(_translate("MainWindow", "Physical controllers"))
|
||||
item = self.tableWidget_physicalControllerList.horizontalHeaderItem(0)
|
||||
item.setText(_translate("MainWindow", "ID"))
|
||||
item = self.tableWidget_physicalControllerList.horizontalHeaderItem(1)
|
||||
item.setText(_translate("MainWindow", "Name"))
|
||||
item = self.tableWidget_physicalControllerList.horizontalHeaderItem(2)
|
||||
item.setText(_translate("MainWindow", "Status"))
|
||||
self.pushButton_physicalControllerRefresh.setText(_translate("MainWindow", "Refresh"))
|
||||
self.pushButton_physicalControllerConfig.setText(_translate("MainWindow", "Configuration"))
|
||||
self.groupBox_emulatedController.setTitle(_translate("MainWindow", "Emulated controller"))
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -19,13 +19,13 @@
|
|||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
<height>400</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
<height>400</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -54,7 +54,7 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget_physicalControllerList">
|
||||
<widget class="QTableView" name="tableView_physicalControllerList">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
|
@ -64,21 +64,9 @@
|
|||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>ID</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Status</string>
|
||||
</property>
|
||||
</column>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -20,7 +20,6 @@ class Gamepad:
|
|||
self.name = name
|
||||
|
||||
|
||||
|
||||
""" 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))]
|
||||
|
|
45
models/gamepad.py
Normal file
45
models/gamepad.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
from hashlib import sha1
|
||||
from PyQt5.QtCore import Qt, QVariant, QAbstractTableModel
|
||||
from handlers.gamepad import Gamepad
|
||||
|
||||
headers = ["ID", "Name", "Status"]
|
||||
|
||||
class GamepadModel(QAbstractTableModel):
|
||||
def __init__(self, gamepads=None):
|
||||
super(GamepadModel, self).__init__()
|
||||
self.gamepads = gamepads or []
|
||||
|
||||
def data(self, index, role):
|
||||
if role == Qt.DisplayRole:
|
||||
match index.column():
|
||||
case 0:
|
||||
return self.get_gamepad_id(index)
|
||||
case 1:
|
||||
return self.gamepads[index.row()].name
|
||||
case 2:
|
||||
return self.get_gamepad_hash(index)
|
||||
case _:
|
||||
return None
|
||||
|
||||
def rowCount(self, index):
|
||||
return len(self.gamepads)
|
||||
|
||||
def columnCount(self, index):
|
||||
return len(headers)
|
||||
|
||||
def headerData(self, section, orientation, role):
|
||||
if role != Qt.DisplayRole or orientation != Qt.Horizontal:
|
||||
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