Skip to content

Commit

Permalink
Display stick/pad press bindings in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
kozec committed Apr 28, 2016
1 parent 9f8ff2c commit 7f2b691
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
8 changes: 2 additions & 6 deletions default_profiles/Desktop.sccprofile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
"BACK" : { "action": "button(Keys.KEY_BACKSPACE)" },
"C" : { "action": "profile('XBox Controller with High Precision Camera')" },
"LB" : { "action": "button(Keys.KEY_LEFTCTRL)" },
"LGRIP" : { "action": "button(Keys.BTN_GAMEPAD)" },
"LPAD" : { "action": "button(Keys.BTN_THUMBL)" },
"RB" : { "action": "button(Keys.KEY_LEFTALT)" },
"RGRIP" : { "action": "button(Keys.BTN_NORTH)" },
"RPAD" : { "action": "button(Keys.BTN_THUMBR)" },
"RPAD" : { "action": "button(Keys.BTN_LEFT)" },
"START" : { "action": "button(Keys.KEY_LEFTSHIFT)" },
"X" : { "action": "button(Keys.KEY_SPACE)" },
"Y" : { "action": "button(Keys.KEY_TAB)" }
Expand All @@ -21,14 +18,13 @@
},

"stick": {
"action": "dpad(button(Keys.KEY_W), button(Keys.KEY_S), button(Keys.KEY_A), button(Keys.KEY_D))"
"action": "dpad(button(Keys.KEY_UP), button(Keys.KEY_DOWN), button(Keys.KEY_LEFT), button(Keys.KEY_RIGHT))"
},

"left_pad": {
"X": { "action": "mouse(Rels.REL_HWHEEL, 1.0)" },
"Y": { "action": "mouse(Rels.REL_WHEEL, 1.0)" }
},

"right_pad": {
"action": "trackball(1.0)"
}
Expand Down
32 changes: 24 additions & 8 deletions scc/gui/controller_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from scc.tools import _

from gi.repository import Gtk, Gdk, Pango
from scc.constants import SCButtons
from scc.constants import SCButtons, STICK, LEFT, RIGHT
from scc.actions import Action, XYAction
from scc.profile import Profile
import os, sys, logging
Expand All @@ -20,7 +20,7 @@

TRIGGERS = [ Profile.LEFT, Profile.RIGHT ]
PADS = [ "LPAD", "RPAD" ]
STICKS = [ "STICK" ]
STICKS = [ STICK ]
PRESSABLE = [ SCButtons.LPAD, SCButtons.RPAD, SCButtons.STICK ]
_NOT_BUTTONS = PADS + STICKS + [ "LT", "RT" ] + [ x + "TOUCH" for x in PADS ]
BUTTONS = [ b for b in SCButtons if b.name not in _NOT_BUTTONS ]
Expand Down Expand Up @@ -92,15 +92,23 @@ def update(self):
class ControllerStick(ControllerWidget):
ACTION_CONTEXT = Action.AC_STICK
def __init__(self, app, name, widget):
self.pressed = Gtk.Label()
ControllerWidget.__init__(self, app, name, widget)

vbox = Gtk.Box(Gtk.Orientation.HORIZONTAL)
grid = Gtk.Grid()
self.widget.set_events(Gdk.EventMask.POINTER_MOTION_MASK)
self.widget.connect('motion-notify-event', self.on_cursor_motion)
vbox.pack_start(self.icon, False, False, 1)
vbox.pack_start(self.label, False, False, 1)
self.label.set_property("vexpand", True)
self.label.set_property("hexpand", True)
self.label.set_xalign(0.0); self.label.set_yalign(0.5)
self.pressed.set_property("hexpand", True)
self.pressed.set_xalign(0.0); self.pressed.set_yalign(1.0)
self.icon.set_margin_right(5)
grid.attach(self.icon, 1, 1, 1, 2)
grid.attach(self.label, 2, 1, 1, 1)
grid.attach(self.pressed, 2, 2, 1, 1)
self.over_icon = False
self.widget.add(vbox)
self.widget.add(grid)
self.widget.show_all()


Expand Down Expand Up @@ -132,7 +140,9 @@ def _set_label(self, action):


def update(self):
action = self.app.current.buttons[SCButtons.STICK]
self._set_label(self.app.current.stick)
self.pressed.set_markup("<small>Pressed: %s</small>" % (action.describe(self.ACTION_CONTEXT),))


class ControllerTrigger(ControllerButton):
Expand All @@ -148,6 +158,12 @@ class ControllerPad(ControllerStick):
ACTION_CONTEXT = Action.AC_PAD
def update(self):
if self.id == "LPAD":
self._set_label(self.app.current.pads[Profile.LEFT])
action = self.app.current.pads[Profile.LEFT]
pressed = self.app.current.buttons[SCButtons.LPAD]
else:
self._set_label(self.app.current.pads[Profile.RIGHT])
action = self.app.current.pads[Profile.RIGHT]
pressed = self.app.current.buttons[SCButtons.RPAD]

self._set_label(action)
self.pressed.set_markup("<small>Pressed: %s</small>" % (pressed.describe(self.ACTION_CONTEXT),))

2 changes: 1 addition & 1 deletion scc/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Profile(object):

def __init__(self, parser):
self.parser = parser
self.buttons = {}
self.buttons = { x : NoAction() for x in SCButtons }
self.stick = NoAction()
self.triggers = { Profile.LEFT : NoAction(), Profile.RIGHT : NoAction() }
self.pads = { Profile.LEFT : NoAction(), Profile.RIGHT : NoAction() }
Expand Down

0 comments on commit 7f2b691

Please sign in to comment.