Skip to content

Commit 588fda8

Browse files
committed
More input fixes
1 parent 1ec5358 commit 588fda8

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/m64py/frontend/input.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from PyQt5.QtGui import QKeySequence
2121

2222
from sdl2 import SDL_WasInit, SDL_InitSubSystem, SDL_QuitSubSystem, SDL_INIT_VIDEO
23-
from sdl2.keyboard import SDL_GetScancodeFromName
23+
from sdl2.keyboard import SDL_GetScancodeName, SDL_GetScancodeFromName
2424

2525
from m64py.core.defs import *
2626
from m64py.utils import format_tooltip
@@ -123,8 +123,8 @@ def add_items(self):
123123
devices = [(self.tr("Keyboard/Mouse"), -1)]
124124
self.device_map[-1] = "Keyboard"
125125
for num, joy in enumerate(self.joystick.joystick_names):
126-
devices.append((self.tr("Joystick %s (%s)" % (num, joy)), num))
127-
self.device_map[num] = joy
126+
devices.append((self.tr("Joystick %s (%s)" % (num, joy.decode())), num))
127+
self.device_map[num] = joy.decode()
128128

129129
for device, dtype in devices:
130130
self.comboDevice.addItem(device, dtype)
@@ -224,9 +224,9 @@ def set_opts(self):
224224
elif ptype == M64TYPE_INT:
225225
widget.setCurrentIndex(widget.findData(param))
226226
elif ptype == M64TYPE_STRING:
227-
param = param.decode()
228227
if key in ["AnalogDeadzone", "AnalogPeak"]:
229228
if param:
229+
param = param.decode()
230230
paramX, paramY = param.split(",")
231231
spin1, spin2 = widget
232232
spin1.setValue(int(paramX))
@@ -332,9 +332,9 @@ def save_keys(self):
332332
continue
333333

334334
def get_axis(self, axis):
335-
param = self.config.get_parameter(axis).decode()
335+
param = self.config.get_parameter(axis)
336336
if param:
337-
return AXIS_RE.findall(param)
337+
return AXIS_RE.findall(param.decode())
338338

339339
def set_axis(self, key, ckey, widget):
340340
if key.startswith("X Axis"):
@@ -390,15 +390,18 @@ def save_axis(self):
390390
self.config.set_parameter("Y Axis", axis.encode())
391391

392392
def get_key(self, key):
393-
param = self.config.get_parameter(key).decode()
394-
if not param:
393+
param = self.config.get_parameter(key)
394+
if param:
395+
param = param.decode()
396+
else:
395397
return [0, 0]
396398

397399
if not self.is_joystick:
398400
value = KEY_RE.findall(param)
399-
items = [item.strip() for item in value[0][1].split(",")]
400-
if items:
401-
return items
401+
if value:
402+
items = [item.strip() for item in value[0][1].split(",")]
403+
if items:
404+
return items
402405
else:
403406
if key.startswith("X Axis"):
404407
axis = self.get_axis("X Axis")
@@ -408,13 +411,13 @@ def get_key(self, key):
408411
return [axis[0][1], axis[0][2]]
409412
else:
410413
return [param, 0]
414+
411415
return [0, 0]
412416

413417
def get_sdl_key(self, text):
414418
if "Shift" in text or "Ctrl" in text or "Alt" in text:
415419
text = "Left %s" % text
416-
text = text.encode()
417-
return SCANCODE2KEYCODE[SDL_GetScancodeFromName(text)]
420+
return SCANCODE2KEYCODE[SDL_GetScancodeFromName(text.encode())]
418421

419422
def get_key_name(self, sdl_key):
420423
if not sdl_key:
@@ -425,9 +428,11 @@ def get_key_name(self, sdl_key):
425428
except Exception:
426429
return self.tr("Select...")
427430

428-
text = text.decode()
429-
if not text:
431+
if text:
432+
text = text.decode()
433+
else:
430434
return self.tr("Select...")
435+
431436
if "Shift" in text or "Ctrl" in text or "Alt" in text:
432437
text = text.replace("Left ", "")
433438

0 commit comments

Comments
 (0)