begin migrating code that can be reused from first iteration of this idea
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import platform
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import webbrowser
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
|
||||
import psutil
|
||||
from PyQt5 import QtCore, QtGui, QtWebEngineWidgets, QtWidgets
|
||||
from PyQt5.uic import loadUi
|
||||
|
||||
try:
|
||||
import win32api
|
||||
import win32file
|
||||
except ImportError:
|
||||
if platform.system()=='Windows':
|
||||
raise #require win32api and win32file on windows
|
||||
|
||||
from validators.location_validator import Location_Validator
|
||||
|
||||
class InstallerWizard(QtWidgets.QWizard):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
loadUi(Path(__file__).parent / "installer_wizard.ui", baseinstance=self)
|
||||
self.button(QtWidgets.QWizard.NextButton).clicked.connect(self._requirements_check)
|
||||
self.currentIdChanged.connect
|
||||
self.intro.anchorClicked.connect(self._link_clicked)
|
||||
self.license.anchorClicked.connect(self._link_clicked)
|
||||
self.install_location.setValidator(Location_Validator(parent=self))
|
||||
self.location_page.registerField("Location*", self.install_location)
|
||||
self.browse_button.clicked.connect(self._link_clicked)
|
||||
#Change button text on license page
|
||||
self.license_page.setButtonText(QtWidgets.QWizard.NextButton, "Agree")
|
||||
self.license_page.setButtonText(QtWidgets.QWizard.CancelButton, "Decline")
|
||||
|
||||
def _link_clicked(self, address):
|
||||
"""Receives anchorClicked signal from the intro or license text browsers and opens the address in an external web browser.
|
||||
Opens an error message window if it is not able to do so.
|
||||
|
||||
Arguments:
|
||||
address {QtCore.QUrl} -- The URL from the received signal
|
||||
"""
|
||||
try:
|
||||
webbrowser.open(address.toString())
|
||||
except webbrowser.Error as e:
|
||||
message=QtWidgets.QMessageBox(icon=QtWidgets.QMessageBox.Critical,parent=self,text="Unable to launch external browser")
|
||||
message.setDetailedText(str(e))
|
||||
message.show()
|
||||
|
||||
def _select_location(self):
|
||||
"""Opens a QFileDialog in either the root of the most-recently connected non-network, non-cd drive or the user's home directory,
|
||||
if no suitable external device is found
|
||||
"""
|
||||
if platform.system() == 'Windows':
|
||||
drives = [drive for drive in win32api.GetLogicalDriveStrings().split('\0') if drive]
|
||||
dialog_location = drives.pop()
|
||||
while (win32file.GetDriveType(dialog_location) == win32file.DRIVE_CDROM
|
||||
or win32file.GetDriveType(dialog_location) == win32file.DRIVE_REMOTE):
|
||||
dialog_location = drives.pop()
|
||||
if dialog_location == "C:\\":
|
||||
dialog_location = Path.home()
|
||||
break
|
||||
else:
|
||||
dialog_location = Path.home()
|
||||
selected_location = QtWidgets.QFileDialog.getExistingDirectory(parent=self,caption="Select Location",
|
||||
directory=str(dialog_location),
|
||||
options=(QtWidgets.QFileDialog.ShowDirsOnly))
|
||||
self.__window.install_location.clear()
|
||||
self.__window.install_location.insert(selected_location)
|
||||
|
||||
def _requirements_check(self):
|
||||
"""Checks that the minimum system requirements are met. Opens error message and resets the wizard if they are not.
|
||||
Minimum Requirements: Windows 7 or greater (64-bit)
|
||||
"""
|
||||
if not platform.system() == 'Windows' or int(platform.release()) < 7:
|
||||
QtWidgets.QMessageBox(icon=QtWidgets.QMessageBox.Critical,parent=self,text="This toolkit requires Microsoft Windows 7 or newer").show()
|
||||
self.restart()
|
||||
return False
|
||||
elif not platform.machine() == 'AMD64':
|
||||
QtWidgets.QMessageBox(icon=QtWidgets.QMessageBox.Critical,parent=self,text='''Parts of this toolkit require a 64-bit processor.
|
||||
Please open an issue on Github or Gitlab if you absolutely need it all 32-bit''').show()
|
||||
self.restart()
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
Reference in New Issue
Block a user