Hmm, I thought he wanted to have the list alphabetized (and only that, without taking the signal strength into account). According to
https://lazka.github.io/pgi-docs/#NM-1.0/classes/AccessPoint.html#NM.AccessPoint.get_strength
the strength is an integer between 0 and 100. That means that the likelihood of two networks having the same strength approaches 0. Therefore, trying to sort by strength first and then by name would probably result in the same output as if it were sorted only by strength (because each AccessPoint has its own strength like 81, 82, 64, 22, etc). A better way would be to map them.
The asterisks indicating the strength are made by the function NM.utils_wifi_strength_bars( *strength* )
. The function returns a string that has asterisks from 0 to 4. Now there are multiple ways to fix this issue, here is one:
- Locate to /usr/bin/ in a root-elevated File Manager (or you can’t save the new script)
- Open networkmanager_dmenu (the python script)
- Find the following line:
aps_all = sorted(adapter.get_access_points(),
key=lambda a: a.get_strength(), reverse=True)
it should be located in the function called def create_ap_list(adapter, active_connections):
- Replace this line with the following
aps_all = sorted(adapter.get_access_points(),
key=lambda a: mysort(a) , reverse=False)
The bold parts changed.
- Before the function
def create_ap_list(adapter, active_connections):
copy and paste this new sorting function:
def mysort(a):
bars = NM.utils_wifi_strength_bars(a.get_strength()) # asterisks from 0 to 4 characters
strength = bars.count(’*’) # count the ammount of asterisks
return str(4-strength) + ssid_to_utf8(a)
I don’t know how to insert tabs here but you have to align the last the lines with 1 tab.
- Save and retry (editor needs root privileges to save)
Result (first sorted by strenght, and then by name):
EDIT: Or if you don’t like adding a seperate function, you could change the sorting lambda itself by replacing it with another one liner. Go to step 4 and replace with this insetead:
aps_all = sorted(adapter.get_access_points(),key=lambda a: str(4-(NM.utils_wifi_strength_bars(a.get_strength())).count(’*’)) + ssid_to_utf8(a) , reverse=False)
yes, this is all one line.