comparison sat_frontends/quick_frontend/quick_games.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children 4b842c1fb686
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
34 _game_name = None 34 _game_name = None
35 _signal_prefix = None 35 _signal_prefix = None
36 _signal_suffixes = None 36 _signal_suffixes = None
37 37
38 @classmethod 38 @classmethod
39 def registerSignals(cls, host): 39 def register_signals(cls, host):
40 def make_handler(suffix, signal): 40 def make_handler(suffix, signal):
41 def handler(*args): 41 def handler(*args):
42 if suffix in ("Started", "Players"): 42 if suffix in ("Started", "Players"):
43 return cls.startedHandler(host, suffix, *args) 43 return cls.started_handler(host, suffix, *args)
44 return cls.genericHandler(host, signal, *args) 44 return cls.generic_handler(host, signal, *args)
45 45
46 return handler 46 return handler
47 47
48 for suffix in cls._signal_suffixes: 48 for suffix in cls._signal_suffixes:
49 signal = cls._signal_prefix + suffix 49 signal = cls._signal_prefix + suffix
50 host.registerSignal( 50 host.register_signal(
51 signal, handler=make_handler(suffix, signal), iface="plugin" 51 signal, handler=make_handler(suffix, signal), iface="plugin"
52 ) 52 )
53 53
54 @classmethod 54 @classmethod
55 def startedHandler(cls, host, suffix, *args): 55 def started_handler(cls, host, suffix, *args):
56 room_jid, args, profile = jid.JID(args[0]), args[1:-1], args[-1] 56 room_jid, args, profile = jid.JID(args[0]), args[1:-1], args[-1]
57 referee, players, args = args[0], args[1], args[2:] 57 referee, players, args = args[0], args[1], args[2:]
58 chat_widget = host.widgets.getOrCreateWidget( 58 chat_widget = host.widgets.get_or_create_widget(
59 quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile 59 quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile
60 ) 60 )
61 61
62 # update symbols 62 # update symbols
63 if cls._game_name not in chat_widget.visible_states: 63 if cls._game_name not in chat_widget.visible_states:
64 chat_widget.visible_states.append(cls._game_name) 64 chat_widget.visible_states.append(cls._game_name)
65 symbols = games.SYMBOLS[cls._game_name] 65 symbols = games.SYMBOLS[cls._game_name]
66 index = 0 66 index = 0
67 contact_list = host.contact_lists[profile] 67 contact_list = host.contact_lists[profile]
68 for occupant in chat_widget.occupants: 68 for occupant in chat_widget.occupants:
69 occupant_jid = jid.newResource(room_jid, occupant) 69 occupant_jid = jid.new_resource(room_jid, occupant)
70 contact_list.setCache( 70 contact_list.set_cache(
71 occupant_jid, 71 occupant_jid,
72 cls._game_name, 72 cls._game_name,
73 symbols[index % len(symbols)] if occupant in players else None, 73 symbols[index % len(symbols)] if occupant in players else None,
74 ) 74 )
75 chat_widget.update(occupant_jid) 75 chat_widget.update(occupant_jid)
76 76
77 if suffix == "Players" or chat_widget.nick not in players: 77 if suffix == "Players" or chat_widget.nick not in players:
78 return # waiting for other players to join, or not playing 78 return # waiting for other players to join, or not playing
79 if cls._game_name in chat_widget.games: 79 if cls._game_name in chat_widget.games:
80 return # game panel is already there 80 return # game panel is already there
81 real_class = host.widgets.getRealClass(cls) 81 real_class = host.widgets.get_real_class(cls)
82 if real_class == cls: 82 if real_class == cls:
83 host.showDialog( 83 host.show_dialog(
84 _( 84 _(
85 "A {game} activity between {players} has been started, but you couldn't take part because your client doesn't support it." 85 "A {game} activity between {players} has been started, but you couldn't take part because your client doesn't support it."
86 ).format(game=cls._game_name, players=", ".join(players)), 86 ).format(game=cls._game_name, players=", ".join(players)),
87 _("{game} Game").format(game=cls._game_name), 87 _("{game} Game").format(game=cls._game_name),
88 ) 88 )
89 return 89 return
90 panel = real_class(chat_widget, referee, players, *args) 90 panel = real_class(chat_widget, referee, players, *args)
91 chat_widget.games[cls._game_name] = panel 91 chat_widget.games[cls._game_name] = panel
92 chat_widget.addGamePanel(panel) 92 chat_widget.add_game_panel(panel)
93 93
94 @classmethod 94 @classmethod
95 def genericHandler(cls, host, signal, *args): 95 def generic_handler(cls, host, signal, *args):
96 room_jid, args, profile = jid.JID(args[0]), args[1:-1], args[-1] 96 room_jid, args, profile = jid.JID(args[0]), args[1:-1], args[-1]
97 chat_widget = host.widgets.getWidget(quick_chat.QuickChat, room_jid, profile) 97 chat_widget = host.widgets.get_widget(quick_chat.QuickChat, room_jid, profile)
98 if chat_widget: 98 if chat_widget:
99 try: 99 try:
100 game_panel = chat_widget.games[cls._game_name] 100 game_panel = chat_widget.games[cls._game_name]
101 except KeyError: 101 except KeyError:
102 log.error( 102 log.error(