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 pathServicesMenu.py
262 lines (203 loc) · 8.65 KB
/
ServicesMenu.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
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
from .Config import Config
from .Services import Services
from .MainWindow import MainWindow
from . import Common
_tr = Config._tr
class ServicesMenu:
def __init__(self):
self.menu_gui()
def menu_gui(self):
"""
Generate menu GUI.
"""
# Popover
self.menu_po = Gtk.Popover()
# Grid (main)
main_grid = Common.menu_main_grid()
self.menu_po.set_child(main_grid)
# Label - menu title (Services)
label = Common.menu_title_label(_tr("Services"))
main_grid.attach(label, 0, 0, 1, 1)
# Notebook
notebook = Gtk.Notebook()
notebook.set_hexpand(True)
notebook.set_vexpand(True)
main_grid.attach(notebook, 0, 1, 1, 1)
# Tab pages and ScrolledWindow
# "Add/Remove Columns" tab
label = Gtk.Label()
label.set_label(_tr("Add/Remove Columns"))
self.grid_add_remove_columns_tab = Gtk.Grid()
self.grid_add_remove_columns_tab.set_margin_top(15)
self.grid_add_remove_columns_tab.set_margin_bottom(5)
self.grid_add_remove_columns_tab.set_margin_start(5)
self.grid_add_remove_columns_tab.set_margin_end(5)
self.grid_add_remove_columns_tab.set_row_spacing(5)
notebook.append_page(self.grid_add_remove_columns_tab, label)
# Button (Reset)
self.reset_button = Common.reset_button()
main_grid.attach(self.reset_button, 0, 2, 1, 1)
# "Add/Remove Columns" tab GUI
self.add_remove_columns_tab_gui()
# GUI signals
self.gui_signals()
def add_remove_columns_tab_gui(self):
"""
Generate "Add/Remove Columns" tab GUI objects.
"""
# Grid
grid = Gtk.Grid()
grid.set_margin_top(5)
grid.set_margin_bottom(5)
grid.set_margin_start(5)
grid.set_margin_end(5)
grid.set_column_spacing(10)
grid.set_row_spacing(3)
self.grid_add_remove_columns_tab.attach(grid, 0, 0, 1, 1)
# Label - tab title (Add/Remove Columns)
label = Common.title_label(_tr("Add/Remove Columns"))
grid.attach(label, 0, 0, 2, 1)
# CheckButton (Name)
self.name_cb = Common.checkbutton(_tr("Name"), None)
self.name_cb.set_active(True)
self.name_cb.set_sensitive(False)
grid.attach(self.name_cb, 0, 1, 1, 1)
# CheckButton (State)
self.state_cb = Common.checkbutton(_tr("State"), None)
grid.attach(self.state_cb, 0, 2, 1, 1)
# CheckButton (Main PID)
self.main_pid_cb = Common.checkbutton(_tr("Main PID"), None)
grid.attach(self.main_pid_cb, 0, 3, 1, 1)
# CheckButton (Active State)
self.active_state_cb = Common.checkbutton(_tr("Active State"), None)
grid.attach(self.active_state_cb, 0, 4, 1, 1)
# CheckButton (Load State)
self.load_state_cb = Common.checkbutton(_tr("Load State"), None)
grid.attach(self.load_state_cb, 1, 1, 1, 1)
# CheckButton (Sub-State)
self.sub_state_cb = Common.checkbutton(_tr("Sub-State"), None)
grid.attach(self.sub_state_cb, 1, 2, 1, 1)
# CheckButton (Memory (RSS))
self.memory_rss_cb = Common.checkbutton(_tr("Memory (RSS)"), None)
grid.attach(self.memory_rss_cb, 1, 3, 1, 1)
# CheckButton (Description)
self.description_cb = Common.checkbutton(_tr("Description"), None)
grid.attach(self.description_cb, 1, 4, 1, 1)
def gui_signals(self):
"""
Connect GUI signals.
"""
self.menu_po.connect("show", self.on_menu_po_show)
self.reset_button.connect("clicked", self.on_reset_button_clicked)
def connect_signals(self):
"""
Connect some of the signals to be able to disconnect them for setting GUI.
"""
self.name_cb.connect("toggled", self.on_add_remove_checkbuttons_toggled)
self.state_cb.connect("toggled", self.on_add_remove_checkbuttons_toggled)
self.main_pid_cb.connect("toggled", self.on_add_remove_checkbuttons_toggled)
self.active_state_cb.connect("toggled", self.on_add_remove_checkbuttons_toggled)
self.load_state_cb.connect("toggled", self.on_add_remove_checkbuttons_toggled)
self.sub_state_cb.connect("toggled", self.on_add_remove_checkbuttons_toggled)
self.memory_rss_cb.connect("toggled", self.on_add_remove_checkbuttons_toggled)
self.description_cb.connect("toggled", self.on_add_remove_checkbuttons_toggled)
def disconnect_signals(self):
"""
Disconnect some of the signals for setting GUI.
"""
self.name_cb.disconnect_by_func(self.on_add_remove_checkbuttons_toggled)
self.state_cb.disconnect_by_func(self.on_add_remove_checkbuttons_toggled)
self.main_pid_cb.disconnect_by_func(self.on_add_remove_checkbuttons_toggled)
self.active_state_cb.disconnect_by_func(self.on_add_remove_checkbuttons_toggled)
self.load_state_cb.disconnect_by_func(self.on_add_remove_checkbuttons_toggled)
self.sub_state_cb.disconnect_by_func(self.on_add_remove_checkbuttons_toggled)
self.memory_rss_cb.disconnect_by_func(self.on_add_remove_checkbuttons_toggled)
self.description_cb.disconnect_by_func(self.on_add_remove_checkbuttons_toggled)
def on_menu_po_show(self, widget):
"""
Run code when customizations menu popover is shown.
"""
try:
self.disconnect_signals()
except TypeError:
pass
self.set_gui()
self.connect_signals()
def on_reset_button_clicked(self, widget):
"""
Reset customizations.
"""
# Load default settings
Config.config_default_services_func()
Config.config_save_func()
Common.update_tab_and_menu_gui(self, Services)
def on_add_remove_checkbuttons_toggled(self, widget):
"""
Run a function for adding/removing columns to treeview.
"""
self.add_remove_columns()
def set_gui(self):
"""
Set GUI items.
"""
if 0 in Config.services_treeview_columns_shown:
self.name_cb.set_active(True)
else:
self.name_cb.set_active(False)
if 1 in Config.services_treeview_columns_shown:
self.state_cb.set_active(True)
else:
self.state_cb.set_active(False)
if 2 in Config.services_treeview_columns_shown:
self.main_pid_cb.set_active(True)
else:
self.main_pid_cb.set_active(False)
if 3 in Config.services_treeview_columns_shown:
self.active_state_cb.set_active(True)
else:
self.active_state_cb.set_active(False)
if 4 in Config.services_treeview_columns_shown:
self.load_state_cb.set_active(True)
else:
self.load_state_cb.set_active(False)
if 5 in Config.services_treeview_columns_shown:
self.sub_state_cb.set_active(True)
else:
self.sub_state_cb.set_active(False)
if 6 in Config.services_treeview_columns_shown:
self.memory_rss_cb.set_active(True)
else:
self.memory_rss_cb.set_active(False)
if 7 in Config.services_treeview_columns_shown:
self.description_cb.set_active(True)
else:
self.description_cb.set_active(False)
def add_remove_columns(self):
"""
Add/Remove columns to treeview.
"""
Config.services_treeview_columns_shown = []
if self.name_cb.get_active() == True:
Config.services_treeview_columns_shown.append(0)
if self.state_cb.get_active() == True:
Config.services_treeview_columns_shown.append(1)
if self.main_pid_cb.get_active() == True:
Config.services_treeview_columns_shown.append(2)
if self.active_state_cb.get_active() == True:
Config.services_treeview_columns_shown.append(3)
if self.load_state_cb.get_active() == True:
Config.services_treeview_columns_shown.append(4)
if self.sub_state_cb.get_active() == True:
Config.services_treeview_columns_shown.append(5)
if self.memory_rss_cb.get_active() == True:
Config.services_treeview_columns_shown.append(6)
if self.description_cb.get_active() == True:
Config.services_treeview_columns_shown.append(7)
# Apply changes immediately (without waiting update interval).
Common.treeview_column_order_width_row_sorting(None, None, Services)
#Common.save_tab_settings(Services)
Config.config_save_func()
ServicesMenu = ServicesMenu()