- 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

This commit is contained in:
Marius Stanciu
2021-10-13 18:37:08 +03:00
committed by Marius
parent cea57b532f
commit 1d1ba28cb3
3 changed files with 31 additions and 8 deletions

View File

@@ -21,6 +21,7 @@ CHANGELOG for FlatCAM beta
- updated the Romanian translation - updated the Romanian translation
- Google-translated the Spanish translation - Google-translated the Spanish translation
- updated the strings in all translation files - 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 12.10.2021

View File

@@ -12,10 +12,6 @@ from multiprocessing import freeze_support
# import copyreg # import copyreg
# import types # import types
if sys.platform == "win32":
# cx_freeze 'module win32' workaround
from win32comext.shell import shell, shellcon
MIN_VERSION_MAJOR = 3 MIN_VERSION_MAJOR = 3
MIN_VERSION_MINOR = 6 MIN_VERSION_MINOR = 6

View File

@@ -5,7 +5,7 @@
# MIT Licence # # MIT Licence #
# ########################################################## # ##########################################################
import os import os, ctypes
import sys import sys
import logging import logging
from pathlib import Path from pathlib import Path
@@ -40,6 +40,14 @@ translations = {}
languages_path_search = '' 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(): def load_languages():
available_translations = [] available_translations = []
languages_path_search = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'locale') 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: if restart:
msgbox = QtWidgets.QMessageBox() msgbox = QtWidgets.QMessageBox()
msgbox.setText(_("The application will restart.")) msgbox.setText(_("The application will restart."))
msgbox.setInformativeText('%s %s?' % 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.setWindowTitle('%s ...' % _("Apply Language"))
msgbox.setWindowIcon(QtGui.QIcon(resource_loc + '/language32.png')) msgbox.setWindowIcon(QtGui.QIcon(resource_loc + '/language32.png'))
msgbox.setIcon(QtWidgets.QMessageBox.Icon.Question) 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.f_handlers.on_file_saveprojectas(use_thread=True, quit_action=True)
app.preferencesUiManager.save_defaults() 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()