This repository was archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathSettingsWindow.py
759 lines (597 loc) · 34.8 KB
/
SettingsWindow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
import os
from .Config import Config
from .Performance import Performance
from .MainWindow import MainWindow
from . import Common
from . import Libsysmon
_tr = Config._tr
class SettingsWindow:
def __init__(self):
# Define data lists in order to add them into comboboxes.
self.language_dict = {"system":_tr("System"), "cs.UTF-8":"Čeština", "de.UTF-8":"Deutsch",
"en_US.UTF-8":"English (US)", "es":"Español", "fa.UTF-8":"فارسی",
"fr.UTF-8": "Français", "hu.UTF-8":"Magyar", "pl.UTF-8":"Polski",
"pt_BR.UTF-8":"Português do Brasil", "pt_PT.UTF-8":"Português europeu",
"ru_RU.UTF-8":"Русский", "tr.UTF-8":"Türkçe", "zh_CN":"简体中文",
"zh_TW":"繁體中文"}
self.gui_theme_dict = {"system":_tr("System"), "light":_tr("Light"), "dark":_tr("Dark")}
self.update_interval_list = [0.5, 0.75, 1.0, 1.25, 1.5, 2.0, 3.0, 5.0, 10.0]
self.chart_data_history_list = [30, 60, 90, 120, 150, 180, 300, 600, 1200]
self.default_main_tab_list = [_tr("Performance"), _tr("Processes"), _tr("Users"), _tr("Services"), _tr("System")]
self.performance_tab_default_sub_tab_list = [_tr("Summary"), _tr("CPU"), _tr("Memory"), _tr("Disk"), _tr("Network"), _tr("GPU"), _tr("Sensors")]
# For translating the text that is used in ".desktop" file.
_text = [_tr("System Monitor"), _tr("Task Manager")]
self.window_gui()
self.messagedialog_gui()
self.gui_signals()
def window_gui(self):
"""
Generate window GUI.
"""
# Window
self.settings_window = Gtk.Window()
self.settings_window.set_title(_tr("General Settings"))
self.settings_window.set_icon_name("system-monitoring-center")
self.settings_window.set_resizable(False)
self.settings_window.set_transient_for(MainWindow.main_window)
self.settings_window.set_modal(True)
self.settings_window.set_hide_on_close(True)
# Grid
main_grid = Gtk.Grid()
main_grid.set_hexpand(True)
main_grid.set_column_spacing(3)
main_grid.set_row_spacing(3)
main_grid.set_margin_top(10)
main_grid.set_margin_bottom(10)
main_grid.set_margin_start(10)
main_grid.set_margin_end(10)
self.settings_window.set_child(main_grid)
# Label (Language)
label = Common.static_information_label_no_ellipsize(_tr("Language (Requires restart)") + ":")
main_grid.attach(label, 0, 0, 1, 1)
# DropDown (Language)
item_list = list(self.language_dict.values())
self.language_dd = Common.dropdown_and_model(item_list)
main_grid.attach(self.language_dd, 1, 0, 1, 1)
# Label (Light/Dark theme)
label = Common.static_information_label_no_ellipsize(_tr("Light/Dark theme") + ":")
main_grid.attach(label, 0, 1, 1, 1)
# DropDown (Light/Dark theme)
item_list = list(self.gui_theme_dict.values())
self.light_dark_theme_dd = Common.dropdown_and_model(item_list)
main_grid.attach(self.light_dark_theme_dd, 1, 1, 1, 1)
# Label (Opacity)
label = Common.static_information_label_no_ellipsize(_tr("Opacity") + " (0.4 - 1.0)" + ":")
main_grid.attach(label, 0, 2, 1, 1)
# Adjustment (for SpinButton)
self.adjustment = Gtk.Adjustment()
self.adjustment.configure(1.0, 0.4, 1.0, 0.05, 0, 0)
# SpinButton (Opacity)
self.scale = Gtk.SpinButton.new_with_range(0.4, 1.0, 0.05)
self.scale.set_digits(2)
self.scale.set_snap_to_ticks(True)
self.scale.set_numeric(True)
self.scale.set_adjustment(self.adjustment)
main_grid.attach(self.scale, 1, 2, 1, 1)
# Separator
separator = Common.settings_window_separator()
main_grid.attach(separator, 0, 3, 2, 1)
# Label (Update interval)
label = Common.static_information_label_no_ellipsize(_tr("Update interval (seconds)") + ":")
main_grid.attach(label, 0, 4, 1, 1)
# DropDown (Update interval)
item_list = self.update_interval_list
self.update_interval_dd = Common.dropdown_and_model(item_list)
main_grid.attach(self.update_interval_dd, 1, 4, 1, 1)
# Label (Graph data history)
label = Common.static_information_label_no_ellipsize(_tr("Graph data history") + ":")
main_grid.attach(label, 0, 5, 1, 1)
# DropDown (Graph data history)
item_list = self.chart_data_history_list
self.graph_data_history_dd = Common.dropdown_and_model(item_list)
main_grid.attach(self.graph_data_history_dd, 1, 5, 1, 1)
# Separator
separator = Common.settings_window_separator()
main_grid.attach(separator, 0, 6, 2, 1)
# CheckButton (Show performance summary on headerbar)
self.show_performance_summary_on_hb_cb = Common.checkbutton(_tr("Show performance summary on the headerbar"), None)
main_grid.attach(self.show_performance_summary_on_hb_cb, 0, 7, 2, 1)
# Separator
separator = Common.settings_window_separator()
main_grid.attach(separator, 0, 8, 2, 1)
# CheckButton (Remember last opened tabs"
self.remember_last_opened_tabs_cb = Common.checkbutton(_tr("Remember last opened tabs"), None)
main_grid.attach(self.remember_last_opened_tabs_cb, 0, 9, 2, 1)
# Grid (Default main tab and sub-tab)
default_main_sub_tab_grid = Gtk.Grid()
default_main_sub_tab_grid.set_column_spacing(5)
default_main_sub_tab_grid.set_column_homogeneous(True)
main_grid.attach(default_main_sub_tab_grid, 0, 10, 2, 1)
# Label (Default main tab and sub-tab)
label = Common.static_information_label_no_ellipsize(_tr("Default main tab and sub-tab") + ":")
default_main_sub_tab_grid.attach(label, 0, 0, 2, 1)
# DropDown (Default main tab)
item_list = self.default_main_tab_list
self.default_main_tab_dd = Common.dropdown_and_model(item_list)
default_main_sub_tab_grid.attach(self.default_main_tab_dd, 0, 1, 1, 1)
# DropDown (Default sub-tab)
item_list = self.performance_tab_default_sub_tab_list
self.default_sub_tab_dd = Common.dropdown_and_model(item_list)
default_main_sub_tab_grid.attach(self.default_sub_tab_dd, 1, 1, 1, 1)
# Separator
separator = Common.settings_window_separator()
main_grid.attach(separator, 0, 11, 2, 1)
# CheckButton (Remember last selected devices)
self.remember_last_selected_devices_cb = Common.checkbutton(_tr("Remember last selected devices"), None)
main_grid.attach(self.remember_last_selected_devices_cb, 0, 12, 2, 1)
# Separator
separator = Common.settings_window_separator()
main_grid.attach(separator, 0, 13, 2, 1)
# CheckButton (Remember window size)
self.remember_window_size_cb = Common.checkbutton(_tr("Remember window size"), None)
main_grid.attach(self.remember_window_size_cb, 0, 14, 2, 1)
# Separator
separator = Common.settings_window_separator()
main_grid.attach(separator, 0, 15, 2, 1)
# Button (Reset)
self.reset_button = Common.reset_button()
main_grid.attach(self.reset_button, 0, 16, 2, 1)
# Separator
separator = Common.settings_window_separator()
main_grid.attach(separator, 0, 17, 2, 1)
# Button (Reset all settings of the application)
self.reset_all_settings_button = Gtk.Button()
self.reset_all_settings_button.set_halign(Gtk.Align.CENTER)
self.reset_all_settings_button.set_label(_tr("Reset all settings of the application"))
self.reset_all_settings_button.add_css_class("destructive-action")
main_grid.attach(self.reset_all_settings_button, 0, 18, 2, 1)
def gui_signals(self):
"""
Connect GUI signals.
"""
# Window signals
self.settings_window.connect("show", self.on_settings_window_show)
# Scale signal
self.adjustment.connect("value-changed", self.on_scale_value_changed)
# Button signals
self.reset_button.connect("clicked", self.on_reset_button_clicked)
self.reset_all_settings_button.connect("clicked", self.on_reset_all_settings_button_clicked)
def settings_connect_signals_func(self):
"""
Connect some of the signals to be able to disconnect them for setting GUI.
"""
self.language_dd.connect("notify::selected-item", self.on_selected_item_notify)
self.light_dark_theme_dd.connect("notify::selected-item", self.on_selected_item_notify)
self.update_interval_dd.connect("notify::selected-item", self.on_selected_item_notify)
self.graph_data_history_dd.connect("notify::selected-item", self.on_selected_item_notify)
self.show_performance_summary_on_hb_cb.connect("toggled", self.on_show_performance_summary_on_hb_cb_toggled)
self.remember_last_opened_tabs_cb.connect("toggled", self.on_remember_last_opened_tabs_cb_toggled)
self.default_main_tab_dd.connect("notify::selected-item", self.on_selected_item_notify)
self.default_sub_tab_dd.connect("notify::selected-item", self.on_selected_item_notify)
self.remember_last_selected_devices_cb.connect("toggled", self.on_remember_last_selected_devices_cb_toggled)
self.remember_window_size_cb.connect("toggled", self.on_remember_window_size_cb_toggled)
def settings_disconnect_signals_func(self):
"""
Disconnect some of the signals for setting GUI.
"""
self.language_dd.disconnect_by_func(self.on_selected_item_notify)
self.light_dark_theme_dd.disconnect_by_func(self.on_selected_item_notify)
self.update_interval_dd.disconnect_by_func(self.on_selected_item_notify)
self.graph_data_history_dd.disconnect_by_func(self.on_selected_item_notify)
self.show_performance_summary_on_hb_cb.disconnect_by_func(self.on_show_performance_summary_on_hb_cb_toggled)
self.remember_last_opened_tabs_cb.disconnect_by_func(self.on_remember_last_opened_tabs_cb_toggled)
self.default_main_tab_dd.disconnect_by_func(self.on_selected_item_notify)
self.default_sub_tab_dd.disconnect_by_func(self.on_selected_item_notify)
self.remember_last_selected_devices_cb.disconnect_by_func(self.on_remember_last_selected_devices_cb_toggled)
self.remember_window_size_cb.disconnect_by_func(self.on_remember_window_size_cb_toggled)
def on_settings_window_show(self, widget):
"""
Run code after window is shown.
"""
# Set GUI widgets for showing current preferences of settings.
try:
self.settings_disconnect_signals_func()
except TypeError:
pass
self.set_gui()
self.settings_connect_signals_func()
def on_show_performance_summary_on_hb_cb_toggled(self, widget):
"""
Show/Hide performance summary on the window title.
"""
# Add performance summary to the main window headerbar if preferred.
if widget.get_active() == True:
Config.performance_summary_on_the_headerbar = 1
MainWindow.window_headerbar.pack_start(MainWindow.performance_summary_hb_grid)
# Remove performance summary from the main window headerbar if preferred.
if widget.get_active() == False:
Config.performance_summary_on_the_headerbar = 0
MainWindow.window_headerbar.remove(MainWindow.performance_summary_hb_grid)
Config.config_save_func()
def on_remember_last_opened_tabs_cb_toggled(self, widget):
"""
Enable/Disable remembering last opened main tab and sub-tab.
"""
# Get currently opened tabs and save them if preferred.
if widget.get_active() == True:
Config.remember_last_opened_tabs_on_application_start = 1
self.default_main_tab_dd.set_sensitive(False)
self.default_sub_tab_dd.set_sensitive(False)
self.settings_gui_default_tab_func()
# Set setting for not remembering las opened tabs if preferred.
if widget.get_active() == False:
Config.remember_last_opened_tabs_on_application_start = 0
self.default_main_tab_dd.set_sensitive(True)
self.default_sub_tab_dd.set_sensitive(True)
Config.config_save_func()
def on_selected_item_notify(self, widget, parameter):
"""
Change update interval of the application, number of graph data points for graphs, default main tab and default sub-tab.
Notify signal is sent when DropDown widget selection is changed.
Currently GtkExpression parameter for DropDown can not be used because of PyGObject.
"""
if widget == self.language_dd:
Config.language = list(self.language_dict.keys())[widget.get_selected()]
if widget == self.light_dark_theme_dd:
Config.light_dark_theme = list(self.gui_theme_dict.keys())[widget.get_selected()]
if widget == self.update_interval_dd:
Config.update_interval = self.update_interval_list[widget.get_selected()]
if widget == self.graph_data_history_dd:
Config.chart_data_history = self.chart_data_history_list[widget.get_selected()]
if widget == self.default_main_tab_dd:
Config.default_main_tab = widget.get_selected()
if widget == self.default_sub_tab_dd:
Config.performance_tab_default_sub_tab = widget.get_selected()
Config.config_save_func()
if widget == self.light_dark_theme_dd:
MainWindow.light_dark_theme()
if widget == self.update_interval_dd:
self.settings_gui_apply_settings_immediately_func()
if widget == self.graph_data_history_dd:
self.settings_gui_set_chart_data_history_func()
self.settings_gui_apply_settings_immediately_func()
def on_remember_last_selected_devices_cb_toggled(self, widget):
"""
Enable/Disable remembering last selected devices.
"""
if widget.get_active() == True:
Config.remember_last_selected_hardware = 1
if widget.get_active() == False:
Config.remember_last_selected_hardware = 0
Config.config_save_func()
def on_remember_window_size_cb_toggled(self, widget):
"""
Enable/Disable remembering window size.
"""
# Get window state (if full screen or not), window size (width, height) and save if preferred.
if widget.get_active() == True:
remember_window_size_value = 1
main_window_state = MainWindow.main_window.is_maximized()
if main_window_state == True:
main_window_state = 1
if main_window_state == False:
main_window_state = 0
main_window_width = MainWindow.main_window.get_width()
main_window_height = MainWindow.main_window.get_height()
Config.remember_window_size = [remember_window_size_value, main_window_state, main_window_width, main_window_height]
# Reset window size/state settings if preferred.
if widget.get_active() == False:
remember_window_size_value = 0
main_window_state = 0
main_window_width = MainWindow.main_window.get_width()
main_window_height = MainWindow.main_window.get_height()
Config.remember_window_size = [remember_window_size_value, main_window_state, main_window_width, main_window_height]
Config.config_save_func()
def on_scale_value_changed(self, widget):
"""
Set opacity value of main window. This setting is not applied to child windows, dialogs, popover menus and tooltips.
"""
opacity_value = widget.get_value()
MainWindow.main_window.set_opacity(opacity_value)
Config.main_window_opacity = opacity_value
Config.config_save_func()
def on_reset_button_clicked(self, widget):
"""
Reset settings on the "Settings" window.
"""
Config.config_default_general_general_func()
Config.config_save_func()
# Set GUI objects of the Settings window without disconnecting signals
# of the widgets in order to use these signals to reset the settings.
self.set_gui()
# Length of performance data lists (cpu_usage_percent_ave, ram_usage_percent_ave, ...)
# have to be set after "chart_data_history" setting is reset in order to avoid errors.
self.settings_gui_set_chart_data_history_func()
# Apply selected CPU core, disk, network card changes
Performance.performance_set_selected_cpu_core_func()
Performance.performance_set_selected_disk_func()
Performance.performance_set_selected_network_card_func()
# Apply selected GPU changes
try:
from .MainWindow import Gpu
Libsysmon.gpu_set_selected_gpu(Gpu.selected_gpu, Gpu.default_gpu, Gpu.gpu_list)
# Prevent errors because "gpu_get_gpu_list_and_set_selected_gpu_func" module requires
# some modules in the Gpu module. They are imported if Gpu tab is switched on.
except ImportError:
pass
# Apply changes immediately (without waiting update interval).
self.settings_gui_apply_settings_immediately_func()
def on_reset_all_settings_button_clicked(self, widget):
"""
Reset all settings of the application.
"""
self.messagedialog.present()
def on_messagedialog_response(self, widget, response):
"""
Reset all settings of the application if "YES" button is clicked.
"""
if response == Gtk.ResponseType.YES:
self.reset_all_settings_func()
self.messagedialog.set_visible(False)
def reset_all_settings_func(self):
"""
Function for resetting all settings of the application.
"""
Config.config_default_reset_all_func()
Config.config_save_func()
self.settings_disconnect_signals_func()
self.set_gui()
self.settings_connect_signals_func()
# Reset "Light/Dark theme" setting.
MainWindow.light_dark_theme()
# Length of performance data lists (cpu_usage_percent_ave, ram_usage_percent_ave, ...)
# have to be set after "chart_data_history" setting is reset in order to avoid errors.
self.settings_gui_set_chart_data_history_func()
# Apply selected CPU core, disk, network card changes
Performance.performance_set_selected_cpu_core_func()
Performance.performance_set_selected_disk_func()
Performance.performance_set_selected_network_card_func()
# Apply selected GPU changes
try:
from .MainWindow import Gpu
Libsysmon.gpu_set_selected_gpu(Gpu.selected_gpu, Gpu.default_gpu, Gpu.gpu_list)
# Prevent errors because "gpu_get_gpu_list_and_set_selected_gpu_func" module requires
# some modules in the Gpu module. They are imported if Gpu tab is switched on.
except ImportError:
pass
# Reset selected device on the list between Performance tab sub-tab list.
if Config.performance_tab_current_sub_tab != -1:
MainWindow.main_gui_device_selection_list()
# Apply changes immediately (without waiting update interval).
self.settings_gui_apply_settings_immediately_func()
def set_gui(self):
"""
Set GUI objects.
"""
self.language_dd.set_selected(list(self.language_dict.keys()).index(Config.language))
self.light_dark_theme_dd.set_selected(list(self.gui_theme_dict.keys()).index(Config.light_dark_theme))
self.update_interval_dd.set_selected(self.update_interval_list.index(Config.update_interval))
self.graph_data_history_dd.set_selected(self.chart_data_history_list.index(Config.chart_data_history))
# Set GUI preferences for "show performance summary on the headerbar" setting
if Config.performance_summary_on_the_headerbar == 1:
self.show_performance_summary_on_hb_cb.set_active(True)
if Config.performance_summary_on_the_headerbar == 0:
self.show_performance_summary_on_hb_cb.set_active(False)
# Set GUI preferences for "remember last opened tabs" setting
if Config.remember_last_opened_tabs_on_application_start == 1:
self.remember_last_opened_tabs_cb.set_active(True)
if Config.remember_last_opened_tabs_on_application_start == 0:
self.remember_last_opened_tabs_cb.set_active(False)
# Set GUI preferences for "defult main tab" setting
self.default_main_tab_dd.set_selected(Config.default_main_tab)
if Config.remember_last_opened_tabs_on_application_start == 1:
self.default_main_tab_dd.set_sensitive(False)
if Config.remember_last_opened_tabs_on_application_start == 0:
self.default_main_tab_dd.set_sensitive(True)
# Set GUI preferences for "performance tab default sub-tab" setting
self.default_sub_tab_dd.set_selected(Config.performance_tab_default_sub_tab)
if Config.remember_last_opened_tabs_on_application_start == 1:
self.default_sub_tab_dd.set_sensitive(False)
if Config.remember_last_opened_tabs_on_application_start == 0:
self.default_sub_tab_dd.set_sensitive(True)
# Set GUI preferences for "remember last selected hardware" setting
if Config.remember_last_selected_hardware == 1:
self.remember_last_selected_devices_cb.set_active(True)
if Config.remember_last_selected_hardware == 0:
self.remember_last_selected_devices_cb.set_active(False)
# Set GUI preferences for "remember window size" setting
if Config.remember_window_size[0] == 1:
self.remember_window_size_cb.set_active(True)
if Config.remember_window_size[0] == 0:
self.remember_window_size_cb.set_active(False)
# Set scale value for "Opacity" setting
self.adjustment.set_value(Config.main_window_opacity)
def settings_gui_set_chart_data_history_func(self):
"""
Trim/Add performance data lists (cpu_usage_percent_ave, ram_usage_percent, ...)
when "chart_data_history" preference is changed.
"""
# Get current chart_data_history length which is same for all performance data lists (cpu_usage_percent_ave, ram_usage_percent, ...).
chart_data_history_current = len(Performance.cpu_usage_percent_ave)
chart_data_history_new = Config.chart_data_history
# Trim beginning part of the lists if new "chart_data_history" value is smaller than the old value.
if chart_data_history_current > chart_data_history_new:
length_difference = chart_data_history_current - chart_data_history_new
# "max_cpu_usage_list", "max_cpu_usage_process_name_list", "max_cpu_usage_process_pid_list" lists
Performance.max_cpu_usage_list = Performance.max_cpu_usage_list[length_difference:]
Performance.max_cpu_usage_process_name_list = Performance.max_cpu_usage_process_name_list[length_difference:]
Performance.max_cpu_usage_process_pid_list = Performance.max_cpu_usage_process_pid_list[length_difference:]
Performance.system_performance_data_dict_prev["cpu_usage_percent_ave"] = Performance.system_performance_data_dict_prev["cpu_usage_percent_ave"][length_difference:]
# "cpu_usage_percent_per_core" list
for device in Performance.logical_core_list:
Performance.system_performance_data_dict_prev["cpu_usage_percent_per_core"][device] = Performance.system_performance_data_dict_prev["cpu_usage_percent_per_core"][device][length_difference:]
# "ram_usage_percent" and "swap_usage_percent" lists
Performance.system_performance_data_dict_prev["ram_usage_percent"] = Performance.system_performance_data_dict_prev["ram_usage_percent"][length_difference:]
Performance.system_performance_data_dict_prev["swap_usage_percent"] = Performance.system_performance_data_dict_prev["swap_usage_percent"][length_difference:]
# "disk_read_speed" and "disk_write_speed" lists
for device in Performance.disk_list:
Performance.system_performance_data_dict_prev["disk_read_speed"][device] = Performance.system_performance_data_dict_prev["disk_read_speed"][device][length_difference:]
Performance.system_performance_data_dict_prev["disk_write_speed"][device] = Performance.system_performance_data_dict_prev["disk_write_speed"][device][length_difference:]
# "network_receive_speed" and "network_send_speed" lists
for device in Performance.network_card_list:
Performance.system_performance_data_dict_prev["network_receive_speed"][device] = Performance.system_performance_data_dict_prev["network_receive_speed"][device][length_difference:]
Performance.system_performance_data_dict_prev["network_send_speed"][device] = Performance.system_performance_data_dict_prev["network_send_speed"][device][length_difference:]
# "gpu_load_list", "gpu_memory_list", "gpu_encoder_load_list", "gpu_decoder_load_list" lists
if MainWindow.gpu_tb.get_active() == True:
from .Gpu import Gpu
Gpu.gpu_load_list = Gpu.gpu_load_list[length_difference:]
Gpu.gpu_memory_list = Gpu.gpu_memory_list[length_difference:]
Gpu.gpu_encoder_load_list = Gpu.gpu_encoder_load_list[length_difference:]
Gpu.gpu_decoder_load_list = Gpu.gpu_decoder_load_list[length_difference:]
# Process Details window CPU, memory (RSS), disk read speed and disk write speed lists
if MainWindow.processes_tab_main_grid.get_child_at(0,0) != None:
from . import ProcessesDetails
for process_details_object in ProcessesDetails.processes_details_object_list:
process_details_object.process_cpu_usage_list = process_details_object.process_cpu_usage_list[length_difference:]
process_details_object.process_ram_usage_list = process_details_object.process_ram_usage_list[length_difference:]
process_details_object.process_disk_read_speed_list = process_details_object.process_disk_read_speed_list[length_difference:]
process_details_object.process_disk_write_speed_list = process_details_object.process_disk_write_speed_list[length_difference:]
# Add list of zeroes to the beginning part of the lists if new "chart_data_history" value is bigger than the old value.
if chart_data_history_current < chart_data_history_new:
# Generate list of zeroes for adding to the beginning of the lists.
list_to_add = [0] * (chart_data_history_new - chart_data_history_current)
# "cpu_usage_percent_ave" list
Performance.system_performance_data_dict_prev["cpu_usage_percent_ave"] = list_to_add + Performance.system_performance_data_dict_prev["cpu_usage_percent_ave"]
# Generate list of dashes for adding to the beginning of some of the lists.
list_to_add_dashes = ["-"] * (chart_data_history_new - chart_data_history_current)
# "max_cpu_usage_list", "max_cpu_usage_process_name_list", "max_cpu_usage_process_pid_list" lists
Performance.max_cpu_usage_list = list_to_add + Performance.max_cpu_usage_list
Performance.max_cpu_usage_process_name_list = list_to_add_dashes + Performance.max_cpu_usage_process_name_list
Performance.max_cpu_usage_process_pid_list = list_to_add_dashes + Performance.max_cpu_usage_process_pid_list
# "cpu_usage_percent_per_core" list
for device in Performance.logical_core_list:
Performance.system_performance_data_dict_prev["cpu_usage_percent_per_core"][device] = list_to_add + Performance.system_performance_data_dict_prev["cpu_usage_percent_per_core"][device]
# "ram_usage_percent" and "swap_usage_percent" lists
Performance.system_performance_data_dict_prev["ram_usage_percent"] = list_to_add + Performance.system_performance_data_dict_prev["ram_usage_percent"]
Performance.system_performance_data_dict_prev["swap_usage_percent"] = list_to_add + Performance.system_performance_data_dict_prev["swap_usage_percent"]
# "disk_read_speed" and "disk_write_speed" lists
for device in Performance.disk_list:
Performance.system_performance_data_dict_prev["disk_read_speed"][device] = list_to_add + Performance.system_performance_data_dict_prev["disk_read_speed"][device]
Performance.system_performance_data_dict_prev["disk_write_speed"][device] = list_to_add + Performance.system_performance_data_dict_prev["disk_write_speed"][device]
# "network_receive_speed" and "network_send_speed" lists
for device in Performance.network_card_list:
Performance.system_performance_data_dict_prev["network_receive_speed"][device] = list_to_add + Performance.system_performance_data_dict_prev["network_receive_speed"][device]
Performance.system_performance_data_dict_prev["network_send_speed"][device] = list_to_add + Performance.system_performance_data_dict_prev["network_send_speed"][device]
# "gpu_load_list", "gpu_memory_list", "gpu_encoder_load_list", "gpu_decoder_load_list" lists
if MainWindow.gpu_tb.get_active() == True:
from .Gpu import Gpu
Gpu.gpu_load_list = list_to_add + Gpu.gpu_load_list
Gpu.gpu_memory_list = list_to_add + Gpu.gpu_memory_list
Gpu.gpu_encoder_load_list = list_to_add + Gpu.gpu_encoder_load_list
Gpu.gpu_decoder_load_list = list_to_add + Gpu.gpu_decoder_load_list
# Process Details window CPU, memory (RSS), disk read speed and disk write speed lists
if MainWindow.processes_tab_main_grid.get_child_at(0,0) != None:
from . import ProcessesDetails
for process_details_object in ProcessesDetails.processes_details_object_list:
process_details_object.process_cpu_usage_list = list_to_add + process_details_object.process_cpu_usage_list
process_details_object.process_ram_usage_list = list_to_add + process_details_object.process_ram_usage_list
process_details_object.process_disk_read_speed_list = list_to_add + process_details_object.process_disk_read_speed_list
process_details_object.process_disk_write_speed_list = list_to_add + process_details_object.process_disk_write_speed_list
def settings_gui_apply_settings_immediately_func(self):
"""
Apply settings for all opened tabs (since application start) without waiting update interval.
If "initial_already_run" variable is set as "0", initial and loop functions of the relevant
tab will be run in the next main loop if the tab is already opened or these functionswill be run
immediately when the relevant tab is switched on even if it is opened before the reset.
"""
try:
from .MainWindow import Summary
Summary.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import Cpu
Cpu.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import Memory
Memory.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import Disk
Disk.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import Network
Network.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import Gpu
Gpu.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import Sensors
Sensors.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import Processes
Processes.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import Users
Users.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import Services
Services.initial_already_run = 0
except ImportError:
pass
try:
from .MainWindow import System
System.initial_already_run = 0
except ImportError:
pass
MainWindow.main_gui_tab_loop()
def settings_gui_default_tab_func(self):
"""
Save default main tab and performace tab sub-tab when "Remember last opened tabs" option is enabled.
"""
if MainWindow.performance_tb.get_active() == True:
Config.default_main_tab = 0
elif MainWindow.processes_tb.get_active() == True:
Config.default_main_tab = 1
elif MainWindow.users_tb.get_active() == True:
Config.default_main_tab = 2
elif MainWindow.services_tb.get_active() == True:
Config.default_main_tab = 3
elif MainWindow.system_tb.get_active() == True:
Config.default_main_tab = 4
if MainWindow.summary_tb.get_active() == True:
Config.performance_tab_default_sub_tab = 0
elif MainWindow.cpu_tb.get_active() == True:
Config.performance_tab_default_sub_tab = 1
elif MainWindow.memory_tb.get_active() == True:
Config.performance_tab_default_sub_tab = 2
elif MainWindow.disk_tb.get_active() == True:
Config.performance_tab_default_sub_tab = 3
elif MainWindow.network_tb.get_active() == True:
Config.performance_tab_default_sub_tab = 4
elif MainWindow.gpu_tb.get_active() == True:
Config.performance_tab_default_sub_tab = 5
elif MainWindow.sensors_tb.get_active() == True:
Config.performance_tab_default_sub_tab = 6
def messagedialog_gui(self):
"""
Generate messagedialog GUI.
"""
self.messagedialog = Gtk.MessageDialog(transient_for=self.settings_window,
modal=True,
title="",
message_type=Gtk.MessageType.WARNING,
buttons=Gtk.ButtonsType.YES_NO,
text=_tr("Do you want to reset all settings to defaults?"),
secondary_text=""
)
self.messagedialog.connect("response", self.on_messagedialog_response)
SettingsWindow = SettingsWindow()