# ----------------------------------- FloatingSummary - Initial Function (defines and sets floating summary GUI objects which are not updated on every loop) -----------------------------------
deffloating_summary_initial_func():
# Floating Summary window is closed when main window is closed (when application is run as running a desktop application). But it is not closed when main window is closed if application is run from an IDE for debugging/develoing purposes.
floating_summary_window.set_transient_for(MainGUI.window1)# To be able to use "set_destroy_with_parent"
floating_summary_window.set_destroy_with_parent(True)# To be able to destroy "floating_summary_window" when application main window is destroyed
floating_summary_window.set_opacity(Config.floating_summary_window_transparency)# Set transperancy of the window.
# ----------------------------------- FloatingSummary - Loop Function (updates performance data on the floating summary window) -----------------------------------
floating_summary_data_shown_prev=list(floating_summary_data_shown)# list1 = list(list2) have to be used for proper working of the code because using this equation without "list()" makes a connection between these lists instead of copying one list with a different variable name.
# ----------------------------------- FloatingSummary Initial Thread Function (runs the code in the function as threaded in order to avoid blocking/slowing down GUI operations and other operations) -----------------------------------
# ----------------------------------- MainGUI - Main Function Run Function (runs main functions (Performance, Processes, Users, Storage, Startup, Services, Environment Variables, OS) when their stack page is selected. All main tabs and performance tab sub-tabs switches are controlled in this function) -----------------------------------
defmain_gui_main_function_run_func():
ifConfig.show_floating_summary==1:# Show Floating Summary window appropriate with user preferences
remember_last_opened_tabs_on_application_start=Config.remember_last_opened_tabs_on_application_start# Local definition of this variable is made for lower CPU usage becuse this variable is used multiple times.
ifradiobutton1.get_active()==True:# It switches to "Performance" tab if relevant radiobutton is clicked.
ifConfig.show_floating_summary==1:# Show Floating Summary window appropriate with user preferences. Code below this statement have to be used after "Performance" tab functions, variables, data are defined and functions are run in order to avoid errors.
defon_menuitem1003m_activate(widget):# "Restart as Root" menu item
defrestart_as_root():# Running action is performed in a separate thread for letting rest of the function code to be run without waiting closing the new opened application.
os.system("pkexec system-monitoring-center")# For running application as root by using polkit authentication window
os.system("pkexec system-monitoring-center")# For running application as root by using polkit authentication window
restart_as_root_thread=Thread(target=restart_as_root,daemon=True).start()# Define a thread and run it
os.kill(os.getpid(),signal.SIGTERM)# Get PID of the current application and end it
# ----------------------------------- Processes - Processes End Process Warning Dialog Function (shows an warning dialog when a process is tried to be end) -----------------------------------
# ----------------------------------- Processes - Processes End Process Warning Dialog Function (shows a warning dialog when a process is tried to be end) -----------------------------------
# ----------------------------------- Processes - Processes End Process Tree Warning Dialog Function (shows an warning dialog when a process tree is tried to be end) -----------------------------------
# ----------------------------------- Processes - Processes End Process Tree Warning Dialog Function (shows a warning dialog when a process tree is tried to be end) -----------------------------------
selected_startup_application_file_name=Startup.all_autostart_applications_list[Startup.startup_data_rows.index(model[treeiter][:])]# "[:]" is used in order to copy entire list to be able to use it for getting index in the "startup_data_rows" list to use it getting name of the startup application file name.
# ----------------------------------- Startup - No Startup Item Selected Dialog Function (shows a dialog when Open Startup Item Right Click Menu is clicked without selecting a startup item) -----------------------------------
# Get current username which will be used for determining current user home directory.
globalcurrent_user_name
current_user_name=os.environ.get('SUDO_USER')# Get user name that gets root privileges. Othervise, username is get as "root" when root access is get.
ifcurrent_user_nameisNone:# Get username in the following way if current application has not been run by root privileges.
current_user_name=os.environ.get('USER')
pkexec_uid=os.environ.get('PKEXEC_UID')
ifcurrent_user_name=="root"andpkexec_uid!=None:# current_user_name is get as "None" if application is run with "pkexec" command. In this case, "os.environ.get('PKEXEC_UID')" is used to be able to get username of which user has run the application with "pkexec" command.
# Get human and root user usernames and UIDs. This data will be used if application is run with "pkexec" command.
usernames_startup_applications_visibility_list=[]
usernames_username_list=[]
usernames_uid_list=[]
withopen("/etc/passwd")asreader:# "/etc/passwd" file (also knonw as Linux password database) contains all local user (system + human users) information.
etc_passwd_lines=reader.read().strip().split("\n")# "strip()" is used in order to prevent errors due to an empty line at the end of the list.
# Get current username which will be used for determining current user home directory.
globalcurrent_user_name
current_user_name=os.environ.get('SUDO_USER')# Get user name that gets root privileges. Othervise, username is get as "root" when root access is get.
ifcurrent_user_nameisNone:# Get username in the following way if current application has not been run by root privileges.
current_user_name=os.environ.get('USER')
pkexec_uid=os.environ.get('PKEXEC_UID')
ifcurrent_user_name=="root"andpkexec_uid!=None:# current_user_name is get as "None" if application is run with "pkexec" command. In this case, "os.environ.get('PKEXEC_UID')" is used to be able to get username of which user has run the application with "pkexec" command.
# Get startup item file directories. System default autostart directory is "system_autostart_directory". Startup items are copied into "current_user_autostart_directory" directory with modified values if user make modifications for the startup item. For the user, these values override system values for the user-modified startup item.
# ----------------------------------- Startup - Startup Overwrite Existing Startup Item Warning Dialog Function (shows a warning dialog when a new startup item file is tried to be generated with the same name of an existing one) -----------------------------------
buttons=Gtk.ButtonsType.YES_NO,text=_tr("Do You Want To Overwrite Existing File?"),)
warning_dialog5103.format_secondary_text(_tr("There is already a '.desktop' file with the same name.\nExisting file will be overwritten if you continue.\nDo you want to continue?")+"\n"+" Existing Startup Item: "+new_startup_application_name+"\n"+_tr(" Existing '.desktop' File Name: ")+new_startup_application_file_name)