Merge branch 'initial_dev' of https://github.com/norweeg/portable-computing-tookit-installer into initial_dev
This commit is contained in:
100
portable_computing_toolkit_installer/ui/downloader.py
Normal file
100
portable_computing_toolkit_installer/ui/downloader.py
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
|
from PyQt5 import QtCore, QtGui, QtNetwork, QtWebEngineWidgets, QtWidgets
|
||||||
|
from PyQt5.uic import loadUi
|
||||||
|
|
||||||
|
|
||||||
|
class Downloader(QtWidgets.QMainWindow):
|
||||||
|
def __init__(self, tool_name, tool_info, download_directory, parent = None, flags = None):
|
||||||
|
super().__init__(parent, flags)
|
||||||
|
loadUi(Path(__file__).parent / "downloader.ui", baseinstance = self)
|
||||||
|
self.hide()
|
||||||
|
#create an off-the-record profile, isolated from other Downloader objects
|
||||||
|
new_page = QtWebEngineWidgets.QtWebEnginePage(QtWebEngineWidgets.QWebEngineProfile(self.web_view))
|
||||||
|
self.web_view.setPage(new_page)
|
||||||
|
#set application style and decorate pushbuttons
|
||||||
|
self._style = QtWidgets.QApplication.instance().style()
|
||||||
|
self.setWindowIcon(QtWidgets.QApplication.instance().windowIcon())
|
||||||
|
self.back_button.setIcon(self._style.standardIcon(self._style.SP_ArrowBack))
|
||||||
|
self.forward_button.setIcon(self._style.standardIcon(self._style.SP_ArrowForward))
|
||||||
|
self.reload_stop_button.setIcon(self._style.standardIcon(self._style.SP_BrowserReload))
|
||||||
|
self.home_button.setIcon(self._style.standardIcon(self._style.SP_ArrowUp))
|
||||||
|
#connect signals to make useable as a browser
|
||||||
|
self.web_view.urlChanged.connect(lambda url: self.address_bar.setText(url.toString()))
|
||||||
|
self.web_view.loadStarted.connect(self._reload_becomes_stop)
|
||||||
|
self.web_view.loadFinished.connect(self._stop_becomes_reload)
|
||||||
|
self.address_bar.returnPressed.connect(lambda: self.web_view.load(QtCore.QUrl(self.address_bar.text())))
|
||||||
|
#connect cancel actions to handlers
|
||||||
|
self.actionCancel.triggered.connect(self._cancel_manual_search)
|
||||||
|
self.actionCancel_and_Open_Issue_on_Github.triggered.connect(self._cancel_manual_search_open_issue)
|
||||||
|
#set attributes
|
||||||
|
self._tool_name = tool_name
|
||||||
|
self._tool_info = tool_info
|
||||||
|
self._download_directory = download_directory
|
||||||
|
#name window from attribute
|
||||||
|
self.setWindowTitle(f"Find {self._tool_name}")
|
||||||
|
#get homepage from attributes and set home button to load it
|
||||||
|
self._home_page = tool_info["homepage"]
|
||||||
|
self.home_button.clicked.connect(lambda: self.web_view.load(QtCore.QUrl(self._home_page)))
|
||||||
|
|
||||||
|
def _reload_becomes_stop(self):
|
||||||
|
"""Turns the reload button into a stop button.
|
||||||
|
"""
|
||||||
|
self._reload_stop_button.clicked.disconnect()
|
||||||
|
self._reload_stop_button.clicked.connect(self.web_view.stop)
|
||||||
|
self._reload_stop_button.setToolTip("Stop")
|
||||||
|
self._reload_stop_button.setIcon(self._style.standardIcon(self._style.SP_BrowserStop))
|
||||||
|
self._check_history()
|
||||||
|
|
||||||
|
def _stop_becomes_reload(self, ok):
|
||||||
|
"""Turns a temporary stop button back into a reload button
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ok (bool): Received from signal indicating load was stopped without error (True) or because of error (False). Ignored.
|
||||||
|
"""
|
||||||
|
self._reload_stop_button.clicked.disconnect()
|
||||||
|
self._reload_stop_button.clicked.connect(self.web_view.reload)
|
||||||
|
self._reload_stop_button.setToolTip("Reload")
|
||||||
|
self._reload_stop_button.setIcon(self._style.standardIcon(self._style.SP_BrowserReload))
|
||||||
|
self._check_history()
|
||||||
|
|
||||||
|
def _check_history(self):
|
||||||
|
if self.web_view.history().canGoBack():
|
||||||
|
self.back_button.setEnabled(True)
|
||||||
|
else:
|
||||||
|
self.back_button.setEnabled(False)
|
||||||
|
|
||||||
|
if self.web_view.history().canGoForward():
|
||||||
|
self.forward_button.setEnabled(True)
|
||||||
|
else:
|
||||||
|
self.forward_button.setEnabled(False)
|
||||||
|
|
||||||
|
def _cancel_manual_search(self):
|
||||||
|
self.close()
|
||||||
|
QtCore.QThread.currentThread().exit(1)
|
||||||
|
|
||||||
|
def _cancel_manual_search_open_issue(self):
|
||||||
|
self.close()
|
||||||
|
webbrowser.open_new_tab("https://github.com/norweeg/portable-computing-toolkit-installer/issues/new")
|
||||||
|
QtCore.QThread.currentThread().exit(1)
|
||||||
|
|
||||||
|
def begin_manual_search(self):
|
||||||
|
self.web_view.history().clear()
|
||||||
|
self._check_history()
|
||||||
|
self.show()
|
||||||
|
self.web_view.load(QtCore.QUrl(self._home_page))
|
||||||
|
|
||||||
|
def begin_auto_search(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _download_file(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class DownloadWorker(QtCore.QRunnable):
|
||||||
|
def __init__(self, tool_name, tool_info, download_directory):
|
||||||
|
super().__init__()
|
||||||
|
self._downloader = Downloader(tool_name, tool_info, download_directory)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self._downloader.begin_auto_search()
|
||||||
182
portable_computing_toolkit_installer/ui/downloader.ui
Normal file
182
portable_computing_toolkit_installer/ui/downloader.ui
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QFrame" name="frame">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="back_button">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Back</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="forward_button">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Forward</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="reload_stop_button">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Reload</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="home_button">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Home</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="address_bar">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Enter a URL</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWebEngineView" name="web_view">
|
||||||
|
<property name="url">
|
||||||
|
<url>
|
||||||
|
<string>about:blank</string>
|
||||||
|
</url>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuActions">
|
||||||
|
<property name="title">
|
||||||
|
<string>Actions</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionCancel"/>
|
||||||
|
<addaction name="actionCancel_and_Open_Issue_on_Github"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuActions"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<action name="actionCancel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cancel</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionCancel_and_Open_Issue_on_Github">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cancel and Open Issue on Github</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QWebEngineView</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header location="global">QtWebEngineWidgets/QWebEngineView</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>back_button</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>web_view</receiver>
|
||||||
|
<slot>back()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>34</x>
|
||||||
|
<y>51</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>399</x>
|
||||||
|
<y>324</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>forward_button</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>web_view</receiver>
|
||||||
|
<slot>forward()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>72</x>
|
||||||
|
<y>51</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>399</x>
|
||||||
|
<y>324</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>reload_stop_button</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>web_view</receiver>
|
||||||
|
<slot>reload()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>110</x>
|
||||||
|
<y>51</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>399</x>
|
||||||
|
<y>324</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user