From adefbb3069488ebedcd885001833c8974112d8fb Mon Sep 17 00:00:00 2001 From: punkrockguy318 Date: Sun, 7 Dec 2008 15:28:20 +0000 Subject: [PATCH] initial joystick config support in gfceux --- ChangeLog | 1 + config_parse.py | 3 +- get_key.py | 11 ++- gfceux | 21 +++-- gfceux.glade | 218 ++++++++++++++++++++++++------------------------ gfceux.xml | 214 +++++++++++++++++++++++------------------------ 6 files changed, 242 insertions(+), 226 deletions(-) diff --git a/ChangeLog b/ChangeLog index 07b94651..57d727ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ ================= version 2.0.4 ( yet to be released) ============ +* Initial joystick config support: supports buttons, but hot hats and axes * Documented and cleaned fceux config parser * Udated about box UI * Updated UI, explains joystick support isn't complete yet in the GUI diff --git a/config_parse.py b/config_parse.py index 5c5c29f6..d59e675d 100755 --- a/config_parse.py +++ b/config_parse.py @@ -68,6 +68,7 @@ class FceuxConfigParser: data = self.f.read(keyname.__len__()) buf += data if data == "": + print "key " + keyname + " not found" return None if data == keyname: break @@ -94,7 +95,7 @@ class FceuxConfigParser: self.f.close() # write the buffer to the config file - self.f._open('w') + self._open('w') self.f.write(buf) self.f.close() diff --git a/get_key.py b/get_key.py index 22831670..3547f2b8 100755 --- a/get_key.py +++ b/get_key.py @@ -14,6 +14,10 @@ class KeyGrabber: pygame.joystick.init() if pygame.joystick.get_count() > 0: print "Joystick found!" + for x in range(0, pygame.joystick.get_count()): + joy = pygame.joystick.Joystick(x) + joy.init() + print "joy " + str(x) + " initialized." screen = pygame.display.set_mode((width, height)) pygame.display.set_caption("Press any key. . .") @@ -23,14 +27,17 @@ class KeyGrabber: for event in pygame.event.get(): if event.type == KEYDOWN: pygame.display.quit() - return event.key + return ("Keyboard", event.key) # TODO: Make work with joystick. Do buttons first. if event.type == JOYBUTTONDOWN: pygame.display.quit() # TODO: Make sure we're returning the data we need # for config file here. I'm not sure if this is # the correct data. - return event.joy, event.button + return ("Joystick", event.button, event.joy) + #if event.type == JOYAXISMOTION: + # pygame.display.quit() + # return event.joy, event.axis, event.value if __name__ == "__main__": kg = KeyGrabber() diff --git a/gfceux b/gfceux index 619ce1d5..79906d89 100755 --- a/gfceux +++ b/gfceux @@ -557,15 +557,15 @@ class GfceuxApp: def gamepad_clicked(self, widget, data=None): widgets.get_object("gamepad_config_window").show_all() - d = {'gp1_button' : "1", - 'gp2_button' : "2", - 'gp3_button' : "3", - 'gp4_button' : "4"} + d = {'gp1_button' : "0", + 'gp2_button' : "1", + 'gp3_button' : "2", + 'gp4_button' : "3"} self.gamepad_config_no = d[widget.name] def button_clicked(self, widget, data=None): - prefix = "SDL.Input.GamePad" + self.gamepad_config_no + prefix = "SDL.Input.GamePad." + self.gamepad_config_no d = {'right_button' : prefix + "Right", 'left_button' : prefix + "Left", 'up_button' : prefix + "Up", @@ -582,9 +582,16 @@ class GfceuxApp: self.gamepad_clicked_old(widget) else: kg = get_key.KeyGrabber() - key = kg.get_key() + key_tuple = kg.get_key() cp = FceuxConfigParser(configfile) - cp.writeKey(d[widget.name], key) + cp.writeKey(prefix + "DeviceType", key_tuple[0]) + if key_tuple[0] == "Keyboard": + print key_tuple + cp.writeKey(d[widget.name], key_tuple[1]) + if key_tuple[0] == "Joystick": + print key_tuple + cp.writeKey(prefix + "DeviceNum", key_tuple[2]) + cp.writeKey(d[widget.name], key_tuple[1]) def gamepad_clicked_old(self, widget, data=None): command = '--inputcfg gamepad' + self.gamepad_config_no diff --git a/gfceux.glade b/gfceux.glade index b8af2201..016e1847 100644 --- a/gfceux.glade +++ b/gfceux.glade @@ -1,6 +1,6 @@ - + Gamepad Configuration @@ -13,7 +13,7 @@ True - <b>NOTE:</b> The below GUI is brand new and currently only works with keyboard input. To configure a joystick, use --inputcfg. + <b>NOTE:</b> The below GUI is brand new and joysticks are not completely support yet. To configure a joystick, use --inputcfg. True True @@ -52,17 +52,29 @@ - + True True True - Right + Up + 0 + + + + 1 + 2 + + + + + True + True + True + Left 0 - 2 - 3 1 2 @@ -84,33 +96,21 @@ - + True True True - Left + Right 0 + 2 + 3 1 2 - - - True - True - True - Up - 0 - - - - 1 - 2 - - @@ -503,17 +503,30 @@ 5 5 - + True True - Gamepad _3 + Gamepad _1 True 0 - 1 - 2 + + + + + + True + True + Gamepad _2 + True + 0 + + + + 1 + 2 @@ -535,30 +548,17 @@ - + True True - Gamepad _2 - True - 0 - - - - 1 - 2 - - - - - - True - True - Gamepad _1 + Gamepad _3 True 0 + 1 + 2 @@ -1054,28 +1054,13 @@ Invalid options may cause GFCE UltraX to behave incorrectly. 5 5 - + True - True + 0 + Port: - 1 - 2 - 1 - 2 - - - - - - True - True - 4046 1 65536 1 10 0 - 1 - - - 1 - 2 + GTK_FILL @@ -1093,13 +1078,28 @@ Invalid options may cause GFCE UltraX to behave incorrectly. - + True - 0 - Port: + True + 4046 1 65536 1 10 0 + 1 - GTK_FILL + 1 + 2 + + + + + + True + True + + + 1 + 2 + 1 + 2 @@ -1150,54 +1150,13 @@ Invalid options may cause GFCE UltraX to behave incorrectly. 3 5 - + True True - 4046 1 65536 1 10 0 - 1 1 2 - 1 - 2 - - - - - - True - 0 - Password: - - - 2 - 3 - GTK_FILL - - - - - - True - 0 - Server Port: - - - 1 - 2 - GTK_FILL - - - - - - True - 0 - Server Address: - - - GTK_FILL @@ -1217,13 +1176,54 @@ Invalid options may cause GFCE UltraX to behave incorrectly. - + + True + 0 + Server Address: + + + GTK_FILL + + + + + + True + 0 + Server Port: + + + 1 + 2 + GTK_FILL + + + + + + True + 0 + Password: + + + 2 + 3 + GTK_FILL + + + + + True True + 4046 1 65536 1 10 0 + 1 1 2 + 1 + 2 diff --git a/gfceux.xml b/gfceux.xml index 32232977..7e65b051 100644 --- a/gfceux.xml +++ b/gfceux.xml @@ -1,5 +1,5 @@ - + 5 @@ -44,7 +44,7 @@ True - <b>NOTE:</b> The below GUI is brand new and currently only works with keyboard input. To configure a joystick, use --inputcfg. + <b>NOTE:</b> The below GUI is brand new and joysticks are not completely support yet. To configure a joystick, use --inputcfg. True True @@ -83,16 +83,27 @@ - + True True True - Right + Up + + + + 1 + 2 + + + + + True + True + True + Left - 2 - 3 1 2 @@ -113,31 +124,20 @@ - + True True True - Left + Right + 2 + 3 1 2 - - - True - True - True - Up - - - - 1 - 2 - - @@ -511,16 +511,28 @@ 5 5 - + True True - Gamepad _3 + Gamepad _1 True - 1 - 2 + + + + + + True + True + Gamepad _2 + True + + + + 1 + 2 @@ -541,28 +553,16 @@ - + True True - Gamepad _2 - True - - - - 1 - 2 - - - - - - True - True - Gamepad _1 + Gamepad _3 True + 1 + 2 @@ -1035,28 +1035,13 @@ Invalid options may cause GFCE UltraX to behave incorrectly. 5 5 - + True - True + 0 + Port: - 1 - 2 - 1 - 2 - - - - - - True - True - adjustment3 - 1 - - - 1 - 2 + GTK_FILL @@ -1074,13 +1059,28 @@ Invalid options may cause GFCE UltraX to behave incorrectly. - + True - 0 - Port: + True + adjustment3 + 1 - GTK_FILL + 1 + 2 + + + + + + True + True + + + 1 + 2 + 1 + 2 @@ -1130,54 +1130,13 @@ Invalid options may cause GFCE UltraX to behave incorrectly. 3 5 - + True True - adjustment4 - 1 1 2 - 1 - 2 - - - - - - True - 0 - Password: - - - 2 - 3 - GTK_FILL - - - - - - True - 0 - Server Port: - - - 1 - 2 - GTK_FILL - - - - - - True - 0 - Server Address: - - - GTK_FILL @@ -1197,13 +1156,54 @@ Invalid options may cause GFCE UltraX to behave incorrectly. - + + True + 0 + Server Address: + + + GTK_FILL + + + + + + True + 0 + Server Port: + + + 1 + 2 + GTK_FILL + + + + + + True + 0 + Password: + + + 2 + 3 + GTK_FILL + + + + + True True + adjustment4 + 1 1 2 + 1 + 2