1212
1313
1414def get_monitor_selection_list ():
15- _monitor_selection_list = []
1615 monitor_df = _get_monitor_df ()
17- # pylint: disable=unused-variable
18- for index , row in monitor_df .iterrows ():
19- _monitor_id = row [MMT_CSV_NAME ][- 1 ]
20- _monitor_name = row [MMT_CSV_MONITOR_NAME ]
21- _monitor_serial = row [MMT_CSV_SERIAL_NUMBER ]
22- _display_string = f"{ _monitor_id } | { _monitor_name } | { _monitor_serial } "
23- _monitor_selection_list .append (_display_string )
24- log (f"Monitor detected: { _display_string } " )
25-
26- _monitor_selection_list .sort ()
27- return _monitor_selection_list
16+ monitor_df ["display_string" ] = monitor_df .apply (
17+ lambda row : f"{ row [MMT_CSV_NAME ][- 1 ]} | { row [MMT_CSV_MONITOR_NAME ]} | { row [MMT_CSV_SERIAL_NUMBER ]} " ,
18+ axis = 1 ,
19+ )
20+ monitor_df ["display_string" ].apply (lambda x : log (f"Monitor detected: { x } " ))
21+ return sorted (monitor_df ["display_string" ].tolist ())
2822
2923
3024def _get_monitor_df ():
3125 _run_mmt_command ("/scomma" , paths .MMT_CSV_PATH )
32- data = pd .read_csv (paths .MMT_CSV_PATH )
33- return data
26+ return pd .read_csv (paths .MMT_CSV_PATH )
3427
3528
3629def _run_mmt_command (command , destination ):
30+ command_line = [config .get_mmt_path_value (), command , destination ]
3731 try :
38- subprocess .run (
39- [
40- config .get_mmt_path_value (),
41- command ,
42- destination ,
43- ],
44- check = True ,
45- )
46- log (f"MultiMonitorTool.exe { command } { destination } " )
32+ subprocess .run (command_line , check = True )
33+ log (f"{ ' ' .join (command_line )} " )
4734 except subprocess .CalledProcessError as error :
48- log (f"MultiMonitorTool.exe { command } { destination } failed: { error } " )
35+ log (f"{ ' ' . join ( command_line ) } failed: { error } " )
4936
5037
5138def save_mmt_config ():
@@ -57,11 +44,8 @@ def enable_monitor():
5744
5845
5946def disable_monitor ():
60- selected_monitor_id = get_selected_monitor_id ()
61- if selected_monitor_id :
47+ if selected_monitor_id := get_selected_monitor_id ():
6248 _run_mmt_command ("/disable" , selected_monitor_id )
63- else :
64- log ("disable_monitor() - Can't find selected monitor id" )
6549
6650
6751def enable_all_disabled_monitors ():
@@ -72,32 +56,31 @@ def enable_all_disabled_monitors():
7256
7357
7458def get_selected_monitor_id ():
75- # pylint: disable=unused-variable
76- for index , monitor in _get_monitor_df ().iterrows ():
77- if (
78- monitor [MMT_CSV_MONITOR_NAME ] == config .get_monitor_name_value ()
79- and str (monitor [MMT_CSV_SERIAL_NUMBER ]) == config .get_monitor_serial_value ()
80- ):
81- return monitor [MMT_CSV_NAME ][- 1 ]
59+ condition = (
60+ _get_monitor_df ()[MMT_CSV_MONITOR_NAME ] == config .get_monitor_name_value ()
61+ ) & (
62+ _get_monitor_df ()[MMT_CSV_SERIAL_NUMBER ].astype (str )
63+ == config .get_monitor_serial_value ()
64+ )
65+ filtered_df = _get_monitor_df ().loc [condition ]
66+ if not filtered_df .empty :
67+ return filtered_df .iloc [0 ][MMT_CSV_NAME ][- 1 ]
8268
8369
8470def _get_all_disabled_monitor_ids ():
8571 monitor_df = _get_monitor_df ()
86- disabled_monitor_ids = []
87- # pylint: disable=unused-variable
88- for index , monitor in monitor_df .iterrows ():
89- if monitor [MMT_CSV_ACTIVE ].lower () == MMT_CSV_NO :
90- disabled_monitor_ids .append (monitor [MMT_CSV_NAME ][- 1 ])
91- return disabled_monitor_ids
72+ return (
73+ monitor_df [monitor_df [MMT_CSV_ACTIVE ].str .lower () == MMT_CSV_NO ][MMT_CSV_NAME ]
74+ .apply (lambda x : x [- 1 ])
75+ .tolist ()
76+ )
9277
9378
9479def is_selected_monitor_enabled ():
95- # pylint: disable=unused-variable
96- for index , monitor in _get_monitor_df ().iterrows ():
97- if (
98- monitor [MMT_CSV_MONITOR_NAME ] == config .get_monitor_name_value ()
99- and str (monitor [MMT_CSV_SERIAL_NUMBER ]) == config .get_monitor_serial_value ()
100- and monitor [MMT_CSV_ACTIVE ].lower () == MMT_CSV_YES
101- ):
102- return True
103- return False
80+ df = _get_monitor_df ()
81+ condition = (
82+ (df [MMT_CSV_MONITOR_NAME ] == config .get_monitor_name_value ())
83+ & (df [MMT_CSV_SERIAL_NUMBER ].astype (str ) == config .get_monitor_serial_value ())
84+ & (df [MMT_CSV_ACTIVE ].str .lower () == MMT_CSV_YES )
85+ )
86+ return condition .any ()
0 commit comments