From 1d1ba28cb3d0ba0fb5894bb3c097d3251cb47d52 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 13 Oct 2021 18:37:08 +0300 Subject: [PATCH] - if the user is not admin then the application will not restart from within but the changes will be applied at the next app run --- CHANGELOG.md | 1 + FlatCAM.py | 4 ---- appTranslation.py | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 918def26..639ac01e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ CHANGELOG for FlatCAM beta - updated the Romanian translation - Google-translated the Spanish translation - updated the strings in all translation files +- if the user is not admin then the application will not restart from within but the changes will be applied at the next app run 12.10.2021 diff --git a/FlatCAM.py b/FlatCAM.py index f6ba5898..95340601 100644 --- a/FlatCAM.py +++ b/FlatCAM.py @@ -12,10 +12,6 @@ from multiprocessing import freeze_support # import copyreg # import types -if sys.platform == "win32": - # cx_freeze 'module win32' workaround - from win32comext.shell import shell, shellcon - MIN_VERSION_MAJOR = 3 MIN_VERSION_MINOR = 6 diff --git a/appTranslation.py b/appTranslation.py index cd137616..73d49184 100644 --- a/appTranslation.py +++ b/appTranslation.py @@ -5,7 +5,7 @@ # MIT Licence # # ########################################################## -import os +import os, ctypes import sys import logging from pathlib import Path @@ -40,6 +40,14 @@ translations = {} languages_path_search = '' +def isAdmin(): + try: + is_admin = (os.getuid() == 0) or (os.geteuid() == 0) + except AttributeError: + is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0 + return is_admin + + def load_languages(): available_translations = [] languages_path_search = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'locale') @@ -100,9 +108,11 @@ def on_language_apply_click(app, restart=False): if restart: msgbox = QtWidgets.QMessageBox() + msgbox.setText(_("The application will restart.")) msgbox.setInformativeText('%s %s?' % - (_("Are you sure do you want to change the current language to"), name.capitalize())) + (_("Are you sure do you want to change the current language to"), + name.capitalize())) msgbox.setWindowTitle('%s ...' % _("Apply Language")) msgbox.setWindowIcon(QtGui.QIcon(resource_loc + '/language32.png')) msgbox.setIcon(QtWidgets.QMessageBox.Icon.Question) @@ -221,5 +231,21 @@ def restart_program(app, ask=None): app.f_handlers.on_file_saveprojectas(use_thread=True, quit_action=True) app.preferencesUiManager.save_defaults() - python = sys.executable - os.execl(python, python, *sys.argv) + + try: + python = sys.executable + os.execl(python, python, *sys.argv) + except Exception as err: + # app_run_as_admin = isAdmin() + msgbox = QtWidgets.QMessageBox() + + msgbox.setText(_("The language will be applied at the next application start.")) + msgbox.setInformativeText(_("The user does not have admin rights or UAC issues.")) + msgbox.setDetailedText(str(err)) + msgbox.setWindowTitle('%s ...' % _("Quit")) + msgbox.setIcon(QtWidgets.QMessageBox.Icon.Critical) + + bt_yes = msgbox.addButton(_("Quit"), QtWidgets.QMessageBox.ButtonRole.YesRole) + + msgbox.setDefaultButton(bt_yes) + msgbox.exec()