begin migrating code that can be reused from first iteration of this idea
This commit is contained in:
0
portable_computing_toolkit_installer/ui/__init__.py
Normal file
0
portable_computing_toolkit_installer/ui/__init__.py
Normal file
87
portable_computing_toolkit_installer/ui/installer_wizard.py
Normal file
87
portable_computing_toolkit_installer/ui/installer_wizard.py
Normal file
@@ -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
|
||||
194
portable_computing_toolkit_installer/ui/installer_wizard.ui
Normal file
194
portable_computing_toolkit_installer/ui/installer_wizard.ui
Normal file
@@ -0,0 +1,194 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>toolkit_installer</class>
|
||||
<widget class="QWizard" name="toolkit_installer">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>610</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>800</width>
|
||||
<height>610</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Portable Computing Toolkit Installer</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>:/icons/toolbox.svg</normaloff>:/icons/toolbox.svg</iconset>
|
||||
</property>
|
||||
<property name="wizardStyle">
|
||||
<enum>QWizard::ClassicStyle</enum>
|
||||
</property>
|
||||
<property name="options">
|
||||
<set>QWizard::IndependentPages|QWizard::NoBackButtonOnLastPage|QWizard::NoBackButtonOnStartPage|QWizard::NoCancelButtonOnLastPage</set>
|
||||
</property>
|
||||
<widget class="QWizardPage" name="intro_page">
|
||||
<property name="title">
|
||||
<string>Portable Computing Toolkit Installer</string>
|
||||
</property>
|
||||
<property name="subTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="intro">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextBrowserInteraction</set>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="openLinks">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWizardPage" name="license_page">
|
||||
<property name="title">
|
||||
<string>Portable CS Toolkit Installer License Agreement</string>
|
||||
</property>
|
||||
<property name="subTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextBrowser" name="license">
|
||||
<property name="source">
|
||||
<url>
|
||||
<string>qrc:/resources/license.html</string>
|
||||
</url>
|
||||
</property>
|
||||
<property name="openLinks">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWizardPage" name="location_page">
|
||||
<property name="title">
|
||||
<string>Install Location</string>
|
||||
</property>
|
||||
<property name="subTitle">
|
||||
<string>Choose a drive or folder to install the portable toolkit to:</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="install_location">
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="browse_button">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWizardPage" name="selection_page">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>300</number>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Homepage</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWizardPage" name="progress_page">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progress_bar">
|
||||
<property name="minimum">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="progress_label">
|
||||
<property name="text">
|
||||
<string>Download Progress</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user