comparison sat_frontends/primitivus/status.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 559a625a236b
children 4b842c1fb686
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
29 self.host = host 29 self.host = host
30 self.presence = sat_widgets.ClickableText("") 30 self.presence = sat_widgets.ClickableText("")
31 status_prefix = urwid.Text("[") 31 status_prefix = urwid.Text("[")
32 status_suffix = urwid.Text("]") 32 status_suffix = urwid.Text("]")
33 self.status = sat_widgets.ClickableText("") 33 self.status = sat_widgets.ClickableText("")
34 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, "") 34 self.set_presence_status(C.PRESENCE_UNAVAILABLE, "")
35 urwid.Columns.__init__( 35 urwid.Columns.__init__(
36 self, 36 self,
37 [ 37 [
38 ("weight", 1, self.presence), 38 ("weight", 1, self.presence),
39 ("weight", 1, status_prefix), 39 ("weight", 1, status_prefix),
40 ("weight", 9, self.status), 40 ("weight", 9, self.status),
41 ("weight", 1, status_suffix), 41 ("weight", 1, status_suffix),
42 ], 42 ],
43 ) 43 )
44 urwid.connect_signal(self.presence, "click", self.onPresenceClick) 44 urwid.connect_signal(self.presence, "click", self.on_presence_click)
45 urwid.connect_signal(self.status, "click", self.onStatusClick) 45 urwid.connect_signal(self.status, "click", self.on_status_click)
46 46
47 def onPresenceClick(self, sender=None): 47 def on_presence_click(self, sender=None):
48 if not self.host.bridge.isConnected( 48 if not self.host.bridge.is_connected(
49 self.host.current_profile 49 self.host.current_profile
50 ): # FIXME: manage multi-profiles 50 ): # FIXME: manage multi-profiles
51 return 51 return
52 options = [commonConst.PRESENCE[presence] for presence in commonConst.PRESENCE] 52 options = [commonConst.PRESENCE[presence] for presence in commonConst.PRESENCE]
53 list_widget = sat_widgets.GenericList( 53 list_widget = sat_widgets.GenericList(
54 options=options, option_type=sat_widgets.ClickableText, on_click=self.onChange 54 options=options, option_type=sat_widgets.ClickableText, on_click=self.on_change
55 ) 55 )
56 decorated = sat_widgets.LabelLine( 56 decorated = sat_widgets.LabelLine(
57 list_widget, sat_widgets.SurroundedText(_("Set your presence")) 57 list_widget, sat_widgets.SurroundedText(_("Set your presence"))
58 ) 58 )
59 self.host.showPopUp(decorated) 59 self.host.show_pop_up(decorated)
60 60
61 def onStatusClick(self, sender=None): 61 def on_status_click(self, sender=None):
62 if not self.host.bridge.isConnected( 62 if not self.host.bridge.is_connected(
63 self.host.current_profile 63 self.host.current_profile
64 ): # FIXME: manage multi-profiles 64 ): # FIXME: manage multi-profiles
65 return 65 return
66 pop_up_widget = sat_widgets.InputDialog( 66 pop_up_widget = sat_widgets.InputDialog(
67 _("Set your status"), 67 _("Set your status"),
68 _("New status"), 68 _("New status"),
69 default_txt=self.status.get_text(), 69 default_txt=self.status.get_text(),
70 cancel_cb=lambda _: self.host.removePopUp(), 70 cancel_cb=lambda _: self.host.remove_pop_up(),
71 ok_cb=self.onChange, 71 ok_cb=self.on_change,
72 ) 72 )
73 self.host.showPopUp(pop_up_widget) 73 self.host.show_pop_up(pop_up_widget)
74 74
75 def onChange(self, sender=None, user_data=None): 75 def on_change(self, sender=None, user_data=None):
76 new_value = user_data.get_text() 76 new_value = user_data.get_text()
77 previous = ( 77 previous = (
78 [key for key in C.PRESENCE if C.PRESENCE[key][0] == self.presence.get_text()][ 78 [key for key in C.PRESENCE if C.PRESENCE[key][0] == self.presence.get_text()][
79 0 79 0
80 ], 80 ],
98 for ( 98 for (
99 profile 99 profile
100 ) in ( 100 ) in (
101 self.host.profiles 101 self.host.profiles
102 ): # FIXME: for now all the profiles share the same status 102 ): # FIXME: for now all the profiles share the same status
103 self.host.bridge.setPresence( 103 self.host.bridge.presence_set(
104 show=new[0], statuses=statuses, profile_key=profile 104 show=new[0], statuses=statuses, profile_key=profile
105 ) 105 )
106 self.setPresenceStatus(new[0], new[1]) 106 self.set_presence_status(new[0], new[1])
107 self.host.removePopUp() 107 self.host.remove_pop_up()
108 108
109 def setPresenceStatus(self, show, status): 109 def set_presence_status(self, show, status):
110 show_icon, show_attr = C.PRESENCE.get(show) 110 show_icon, show_attr = C.PRESENCE.get(show)
111 self.presence.set_text(("show_normal", show_icon)) 111 self.presence.set_text(("show_normal", show_icon))
112 if status is not None: 112 if status is not None:
113 self.status.set_text((show_attr, status)) 113 self.status.set_text((show_attr, status))
114 self.host.redraw() 114 self.host.redraw()