diff --git a/.gitignore b/.gitignore index 4cca36c..bcc7033 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,7 @@ wav_converter.py to_do.txt csv_info.txt pyinstaller_cmd.txt -icons_imgs -TestData themes/.current_theme *.bat *.sh -splash.jpg \ No newline at end of file +.vscode/ diff --git a/artemis.py b/artemis.py index 3ce3b70..1eb0689 100644 --- a/artemis.py +++ b/artemis.py @@ -1,7 +1,6 @@ from collections import namedtuple from itertools import chain from functools import partial -from glob import glob import webbrowser import os import sys @@ -15,7 +14,6 @@ from PyQt5.QtWidgets import (QMainWindow, QListWidgetItem, QMessageBox, QSplashScreen, - QTreeView, QTreeWidgetItem,) from PyQt5.QtGui import QPixmap from PyQt5 import uic @@ -25,7 +23,6 @@ from PyQt5.QtCore import (QFileInfo, from audio_player import AudioPlayer from space_weather_data import SpaceWeatherData -from double_text_button import DoubleTextButton from download_window import DownloadWindow from switchable_label import SwitchableLabelsIterable from constants import (Constants, @@ -44,11 +41,10 @@ from utilities import (checksum_ok, filters_ok, is_undef_freq, is_undef_band, - change_unit, format_numbers, resource_path,) -import icon_rc +# import icon_rc qt_creator_file = resource_path("artemis.ui") Ui_MainWindow, _ = uic.loadUiType(qt_creator_file) @@ -60,6 +56,7 @@ class Artemis(QMainWindow, Ui_MainWindow): self.setupUi(self) self.set_initial_size() self.download_window = DownloadWindow() + self.download_window.complete.connect(self.show_downloaded_signals) self.actionExit.triggered.connect(qApp.quit) self.action_update_database.triggered.connect(self.ask_if_download) self.action_check_db_ver.triggered.connect(self.check_db_ver) @@ -456,11 +453,21 @@ class Artemis(QMainWindow, Ui_MainWindow): chain(k_storms_colors, a_storm_colors)): lab.set_colors(None, None) + self.forecast_labels = (self.forecast_lbl_0, + self.forecast_lbl_1, + self.forecast_lbl_2, + self.forecast_lbl_3, + self.forecast_lbl_4, + self.forecast_lbl_5, + self.forecast_lbl_6, + self.forecast_lbl_7, + self.forecast_lbl_8) + self.forecast_label_container.labels = self.forecast_labels + # Final operations. self.theme.initialize() self.load_db() self.display_signals() - self.show() @pyqtSlot() def start_update_space_weather(self): @@ -610,20 +617,11 @@ class Artemis(QMainWindow, Ui_MainWindow): val = int([x[4] for x in self.space_weather_data.sgas if "SSN" in x][0]) self.sn_lbl.setText(f"{val:d}") - forecast_labels = (self.forecast_lbl_0, - self.forecast_lbl_1, - self.forecast_lbl_2, - self.forecast_lbl_3, - self.forecast_lbl_4, - self.forecast_lbl_5, - self.forecast_lbl_6, - self.forecast_lbl_7, - self.forecast_lbl_8) - for label, pixmap in zip(forecast_labels, self.space_weather_data.images): + for label, pixmap in zip(self.forecast_labels, self.space_weather_data.images): label.setText('') - label.setPixmap(pixmap) - label.setScaledContents(True) - + label.pixmap = pixmap + label.setPixmap(pixmap.scaled(label.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation)) + label.setStyleSheet("background-color: transparent;") else: pop_up(self, title = Messages.BAD_DOWNLOAD, text = Messages.BAD_DOWNLOAD_MSG).show() @@ -687,10 +685,8 @@ class Artemis(QMainWindow, Ui_MainWindow): item.child(i).setSelected(True) def set_initial_size(self): - """ - Function to handle high resolution screens. The function sets bigger sizes - for all the relevant fixed-size widgets. - """ + """Function to handle high resolution screens. The function sets bigger sizes + for all the relevant fixed-size widgets.""" d = QDesktopWidget().availableGeometry() w = d.width() h = d.height() @@ -738,7 +734,6 @@ class Artemis(QMainWindow, Ui_MainWindow): @pyqtSlot() def download_db(self): if not self.download_window.isVisible(): - self.download_window.download_thread.finished.connect(self.show_downloaded_signals) self.download_window.download_thread.start() self.download_window.show() @@ -782,6 +777,8 @@ class Artemis(QMainWindow, Ui_MainWindow): text = Messages.NO_DB_AVAIL, informative_text = Messages.DOWNLOAD_NOW_QUESTION, is_question = True).exec() + if answer == QMessageBox.Yes: + self.download_db() else: try: is_checksum_ok = checksum_ok(db, ChecksumWhat.DB) @@ -792,7 +789,6 @@ class Artemis(QMainWindow, Ui_MainWindow): if is_checksum_ok: pop_up(self, title = Messages.DB_UP_TO_DATE, text = Messages.DB_UP_TO_DATE_MSG).show() - else: answer = pop_up(self, title = Messages.DB_NEW_VER, text = Messages.DB_NEW_VER_MSG, @@ -803,10 +799,9 @@ class Artemis(QMainWindow, Ui_MainWindow): @pyqtSlot() def show_downloaded_signals(self): - if self.download_window.everything_ok: - self.search_bar.setEnabled(True) - self.load_db() - self.display_signals() + self.search_bar.setEnabled(True) + self.load_db() + self.display_signals() def load_db(self): names = Database.NAMES @@ -831,7 +826,9 @@ class Artemis(QMainWindow, Ui_MainWindow): self.db.fillna(Constants.UNKNOWN, inplace = True) self.db[Signal.WIKI_CLICKED] = False self.update_status_tip(self.total_signals) + self.result_list.clear() self.result_list.addItems(self.signal_names) + self.result_list.setCurrentItem(None) @pyqtSlot() def set_min_value_upper_limit(self, lower_combo_box, @@ -845,7 +842,6 @@ class Artemis(QMainWindow, Ui_MainWindow): lower_units = lower_combo_box.currentText() upper_units = upper_combo_box.currentText() lower_value = lower_spin_box.value() - upper_value = upper_spin_box.value() inf_limit = (lower_value * Constants.CONVERSION_FACTORS[lower_units]) \ // Constants.CONVERSION_FACTORS[upper_units] counter = 0 @@ -949,7 +945,7 @@ class Artemis(QMainWindow, Ui_MainWindow): else: self.result_list.item(index).setHidden(True) # Remove selected item. - self.result_list.selectionModel().clear() + self.result_list.setCurrentItem(None) self.update_status_tip(available_signals) def update_status_tip(self, available_signals): @@ -1123,7 +1119,6 @@ class Artemis(QMainWindow, Ui_MainWindow): selected_items = [item for item in self.mode_tree_widget.selectedItems()] selected_items_text = [i.text(0) for i in selected_items] parents = [item for item in selected_items_text if item in Constants.MODES.keys()] - children = [item for item in selected_items_text if item not in parents] ok = [] for item in selected_items: if item.text(0) in parents: @@ -1288,11 +1283,11 @@ class Artemis(QMainWindow, Ui_MainWindow): if __name__ == '__main__': my_app = QApplication(sys.argv) - img = QPixmap(":/icons/Artemis3.500px.png") - # img = img.scaled(600, 600, aspectRatioMode = Qt.KeepAspectRatio) + # img = QPixmap(":/icons/Artemis3.500px.png") # splash = QSplashScreen(img) # splash.show() # sleep(2) - w = Artemis() + artemis = Artemis() + artemis.show() # splash.finish(w) sys.exit(my_app.exec_()) diff --git a/artemis.ui b/artemis.ui index d633fe0..690fa4c 100644 --- a/artemis.ui +++ b/artemis.ui @@ -6119,7 +6119,7 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto 0 - + @@ -6144,6 +6144,9 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto + + 0 + @@ -6163,30 +6166,6 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - - - - - 12 - 75 - true - - - - color:#ffffff; -background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); - - - OFF - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 12 - - - @@ -6206,30 +6185,6 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - - - - - 12 - 75 - true - - - - color:#ffffff; -background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); - - - OFF - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 12 - - - @@ -6249,30 +6204,6 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - - - - - 12 - 75 - true - - - - color:#ffffff; -background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); - - - OFF - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 12 - - - @@ -6292,30 +6223,6 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - - - - - 12 - 75 - true - - - - color:#ffffff; -background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); - - - OFF - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 12 - - - @@ -6335,30 +6242,6 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - - - - - 12 - 75 - true - - - - color:#ffffff; -background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); - - - OFF - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 12 - - - @@ -6378,30 +6261,6 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - - - - - 12 - 75 - true - - - - color:#ffffff; -background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); - - - OFF - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 12 - - - @@ -6421,7 +6280,7 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - + @@ -6440,31 +6299,7 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - - - - - 12 - 75 - true - - - - color:#ffffff; -background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); - - - OFF - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 12 - - - - + @@ -6483,52 +6318,292 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - - - - - 12 - 75 - true - + + + + + 0 + 0 + - - color:#ffffff; + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + Qt::NoFocus + + + color:#ffffff; background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); - - - OFF - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 12 - - - - - - - - 12 - 75 - true - - - - color:#ffffff; + + + OFF + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 0 + + + 12 + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + color:#ffffff; background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); - - - OFF - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 12 - + + + OFF + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 12 + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + color:#ffffff; +background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); + + + OFF + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 12 + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + color:#ffffff; +background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); + + + OFF + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 12 + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + color:#ffffff; +background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); + + + OFF + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 12 + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + color:#ffffff; +background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); + + + OFF + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 12 + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + color:#ffffff; +background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); + + + OFF + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 12 + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + color:#ffffff; +background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); + + + OFF + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 12 + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + color:#ffffff; +background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); + + + OFF + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 12 + + + + @@ -6588,27 +6663,63 @@ background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,sto - - - - 0 - 0 - - - - - 13 - 75 - true - - - - - - - Qt::AlignCenter - - + + + + + Qt::Horizontal + + + QSizePolicy::Maximum + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 13 + 75 + true + + + + + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + QSizePolicy::Maximum + + + + 40 + 20 + + + + + @@ -7018,6 +7129,17 @@ QSlider::handle:horizontal { QProgressBar
clickable_progress_bar.h
+ + FixedAspectRatioWidget + QWidget +
fixed_aspect_ratio_widget.h
+ 1 +
+ + FixedAspectRatioLabel + QLabel +
fixed_aspect_ratio_label.h
+
diff --git a/download_window.py b/download_window.py index 47907e2..6957f63 100644 --- a/download_window.py +++ b/download_window.py @@ -1,5 +1,5 @@ from PyQt5 import uic -from PyQt5.QtCore import Qt, pyqtSlot +from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal from PyQt5.QtWidgets import QWidget from threads import DownloadThread, ThreadStatus from utilities import pop_up, resource_path @@ -8,6 +8,9 @@ from constants import Messages Ui_Download_window, _ = uic.loadUiType(resource_path("download_db_window.ui")) class DownloadWindow(QWidget, Ui_Download_window): + + complete = pyqtSignal() + def __init__(self): super().__init__() self.setupUi(self) @@ -18,7 +21,6 @@ class DownloadWindow(QWidget, Ui_Download_window): Qt.WindowCloseButtonHint #| # Qt.WindowStaysOnTopHint ) - self.everything_ok = True self.no_internet_msg = pop_up(self, title = Messages.NO_CONNECTION, text = Messages.NO_CONNECTION_MSG, @@ -30,17 +32,8 @@ class DownloadWindow(QWidget, Ui_Download_window): self.download_thread = DownloadThread() self.download_thread.finished.connect(self.wait_close) - self.cancel_btn.clicked.connect(self.terminate_process) - def show_no_connection_warning(self): - self.no_internet_msg.show() - self.everything_ok = False - - def show_bad_download_warning(self): - self.bad_db_download_msg.show() - self.everything_ok = False - @pyqtSlot() def terminate_process(self): if self.download_thread.isRunning(): @@ -51,11 +44,12 @@ class DownloadWindow(QWidget, Ui_Download_window): @pyqtSlot() def wait_close(self): if self.download_thread.status is ThreadStatus.OK: + self.complete.emit() self.close() elif self.download_thread.status is ThreadStatus.NO_CONNECTION_ERR: - self.show_no_connection_warning() + self.no_internet_msg.show() elif self.download_thread.status is ThreadStatus.BAD_DOWNLOAD_ERR: - self.show_bad_download_warning() + self.bad_db_download_msg.show() else: self.close() diff --git a/fixed_aspect_ratio_label.py b/fixed_aspect_ratio_label.py new file mode 100644 index 0000000..e73103f --- /dev/null +++ b/fixed_aspect_ratio_label.py @@ -0,0 +1,14 @@ +from PyQt5.QtWidgets import QLabel +from PyQt5.QtCore import QSize, Qt + +class FixedAspectRatioLabel(QLabel): + def __init__(self, parent = None): + super().__init__(parent) + self.pixmap = None + + def rescale(self, w, h): + self.resize(QSize(w, h)) + if self.pixmap: + self.setPixmap( + self.pixmap.scaled( + self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation)) diff --git a/fixed_aspect_ratio_widget.py b/fixed_aspect_ratio_widget.py new file mode 100644 index 0000000..a867899 --- /dev/null +++ b/fixed_aspect_ratio_widget.py @@ -0,0 +1,19 @@ +from PyQt5.QtWidgets import QWidget + +class FixedAspectRatioWidget(QWidget): + space = 10 + def __init__(self, parent = None): + super().__init__(parent) + self.labels = [] + + def resizeEvent(self, event): + h, w = self.height(), self.width() + h_lbl = h / 9 - self.space + w_lbl = 5 * h_lbl + + if w_lbl > w: + w_lbl = w + h_lbl = h / 9 - self.space + + for label in self.labels: + label.rescale(w_lbl, h_lbl) diff --git a/threads.py b/threads.py index 0ca188b..50a6c0d 100644 --- a/threads.py +++ b/threads.py @@ -14,11 +14,12 @@ class ThreadStatus(Enum): NO_CONNECTION_ERR = auto() UNKNOWN_ERR = auto() BAD_DOWNLOAD_ERR = auto() + UNDEFINED = auto() class DownloadThread(QThread): def __init__(self): super().__init__() - self.__status = ThreadStatus.OK + self.__status = ThreadStatus.UNDEFINED self.reason = 0 @property @@ -55,12 +56,14 @@ class DownloadThread(QThread): zipped.extractall() except: self.__status = ThreadStatus.UNKNOWN_ERR + else: + self.__status = ThreadStatus.OK class UpadteSpaceWeatherThread(QThread): def __init__(self, space_weather_data): super().__init__() - self.__status = ThreadStatus.OK + self.__status = ThreadStatus.UNDEFINED self.__space_weather_data = space_weather_data @property @@ -89,3 +92,5 @@ class UpadteSpaceWeatherThread(QThread): self.__space_weather_data.images[8].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_8).data) except: self.__status = ThreadStatus.UNKNOWN_ERR + else: + self.__status = ThreadStatus.OK