99from SettingsWidgets import SidePage , SettingsWidget
1010from xapp .GSettingsWidgets import *
1111
12- SCHEMA = "org.cinnamon.gestures" ;
12+ SCHEMA = "org.cinnamon.gestures"
1313NON_GESTURE_KEYS = [
1414 "enabled" ,
1515 "swipe-percent-threshold" ,
1818
1919DEBUG_SHOW_ALL = False
2020
21+
2122class Module :
2223 name = "gestures"
2324 category = "prefs"
@@ -33,7 +34,7 @@ def __init__(self, content_box):
3334
3435 def on_module_selected (self ):
3536 have_touchpad = DEBUG_SHOW_ALL
36- have_touchscreen = DEBUG_SHOW_ALL
37+ have_touchscreen = DEBUG_SHOW_ALL
3738
3839 # Detect devices.
3940 out = subprocess .getoutput ("csd-input-helper" ).replace ("\t " , " " ).split ("\n " )[:4 ]
@@ -70,7 +71,7 @@ def on_module_selected(self):
7071
7172 self .disabled_label = Gtk .Label (expand = True )
7273 box .pack_start (self .disabled_label , False , False , 0 )
73-
74+
7475 self .disabled_page_switch = Gtk .Switch (active = self .gesture_settings .get_boolean ("enabled" ), no_show_all = True )
7576 self .disabled_page_switch .connect ("notify::active" , self .enabled_switch_changed )
7677 box .pack_start (self .disabled_page_switch , False , False , 0 )
@@ -79,23 +80,25 @@ def on_module_selected(self):
7980 self .disabled_retry_button .connect ("clicked" , lambda w : self .on_module_selected ())
8081 box .pack_start (self .disabled_retry_button , False , False , 0 )
8182
82- ssource = Gio .SettingsSchemaSource .get_default ();
83- schema = ssource .lookup (SCHEMA , True );
84- all_keys = schema .list_keys ();
83+ ssource = Gio .SettingsSchemaSource .get_default ()
84+ schema = ssource .lookup (SCHEMA , True )
85+ all_keys = schema .list_keys ()
8586
86- order = [ "left" , "right" , "up" , "down" , "in" , "out" ]
87+ order = ["left" , "right" , "up" , "down" , "in" , "out" ]
8788
8889 def sort_by_direction (key1 , key2 ):
8990 v1 = 0
9091 v2 = 0
91- for i in range ( 0 , len ( order ) ):
92- if order [ i ] in key1 :
92+ for i , k in enumerate ( order ):
93+ if k in key1 :
9394 v1 = i
94- if order [ i ] in key2 :
95+ if k in key2 :
9596 v2 = i
9697
97- if v1 < v2 : return - 1
98- if v1 > v2 : return 1
98+ if v1 < v2 :
99+ return - 1
100+ if v1 > v2 :
101+ return 1
99102 return 0
100103
101104 keys = sorted ([key for key in all_keys if key not in NON_GESTURE_KEYS ], key = cmp_to_key (sort_by_direction ))
@@ -184,7 +187,7 @@ def sort_by_direction(key1, key2):
184187
185188 if have_touchpad or have_touchscreen :
186189 for fingers in range (2 , 5 ):
187- section = page .add_section (_ ("Pinch with %d fingers" ) % fingers )
190+ section = page .add_section (_ (f "Pinch with { fingers } fingers" ))
188191
189192 for key in keys :
190193 label = self .get_key_label (key , "pinch" , fingers )
@@ -253,13 +256,13 @@ def sort_by_direction(key1, key2):
253256 text = _ ("The Touchegg service is not running" )
254257 self .disabled_retry_button .show ()
255258 elif not have_touchpad and not have_touchscreen :
256- text = _ ("No compatible devices found" )
259+ text = _ ("No compatible devices found" )
257260 self .disabled_retry_button .show ()
258261 else :
259262 self .disabled_page_switch .set_visible (True )
260263 text = _ ("Gestures are disabled" )
261264
262- self .disabled_label .set_markup ("<big><b>%s </b></big>" % text )
265+ self .disabled_label .set_markup (f "<big><b>{ text } </b></big>" )
263266
264267 self .sidePage .stack .set_transition_type (Gtk .StackTransitionType .NONE )
265268
@@ -306,24 +309,18 @@ def get_key_label(self, key, gtype, fingers):
306309 if gtype != parts [0 ]:
307310 return None
308311
309- if gtype == "swipe" :
310- if int (parts [2 ]) != fingers :
311- return None
312- direction = parts [1 ]
313- if direction == "left" : return _ ("Left" )
314- elif direction == "right" : return _ ("Right" )
315- elif direction == "up" : return _ ("Up" )
316- elif direction == "down" : return _ ("Down" )
317- elif gtype == "pinch" :
312+ gesture_directions = {"left" : _ ("Left" ), "right" : _ ("Right" ),
313+ "up" : _ ("Up" ), "down" : _ ("Down" ),
314+ "in" : _ ("In" ), "out" : _ ("Out" )}
315+ if gtype in ("swipe" , "pinch" ):
318316 if int (parts [2 ]) != fingers :
319317 return None
320318 direction = parts [1 ]
321- if direction == "in" : return _ ("In" )
322- elif direction == "out" : return _ ("Out" )
323- elif gtype == "tap" :
319+ return gesture_directions .get (direction , None )
320+ if gtype == "tap" :
324321 if int (parts [1 ]) != fingers :
325- return
326- return _ ("Tap with %d fingers" ) % fingers
322+ return None
323+ return _ (f "Tap with { fingers } fingers" )
327324
328325 return None
329326
@@ -334,7 +331,7 @@ def test_daemon_alive(self):
334331 None , None )
335332 conn .close_sync (None )
336333 return True
337- except GLib .Error as e :
334+ except GLib .Error :
338335 pass
339336
340337 return False
@@ -376,10 +373,10 @@ def __init__(self, label, settings=None, key=None, options=[], size_group=None):
376373
377374 def on_my_value_changed (self , widget ):
378375 tree_iter = widget .get_active_iter ()
379- if tree_iter != None :
376+ if tree_iter is not None :
380377 self .value = self .model [tree_iter ][0 ]
381378
382- if self .value not in list (self .option_map . keys () )[0 :- 1 ]:
379+ if self .value not in list (self .option_map )[0 :- 1 ]:
383380 self .custom_entry .show ()
384381 self .settings .set_string (self .key , "EXEC:" + self .custom_entry .get_text ())
385382 else :
@@ -392,7 +389,7 @@ def on_custom_entry_changed(self, entry):
392389 self .settings .set_string (self .key , "EXEC:" + entry .get_text ())
393390
394391 def on_setting_changed (self , settings , key ):
395- self .updating_from_setting = True
392+ self .updating_from_setting = True
396393
397394 self .value = settings .get_string (key )
398395 try :
@@ -403,7 +400,7 @@ def on_setting_changed(self, settings, key):
403400 self .custom_entry .show ()
404401 self .custom_entry .set_text (self .value .replace ("EXEC:" , "" ))
405402
406- self .updating_from_setting = False
403+ self .updating_from_setting = False
407404
408405 def set_options (self , options ):
409406 self .model = Gtk .ListStore (str , str )
@@ -412,4 +409,4 @@ def set_options(self, options):
412409 self .option_map [option [0 ]] = self .model .append ([option [0 ], option [1 ]])
413410
414411 self .content_widget .set_model (self .model )
415- self .content_widget .set_id_column (0 )
412+ self .content_widget .set_id_column (0 )
0 commit comments