From 9725dea853cb8a934ec017b00fb659968103912f Mon Sep 17 00:00:00 2001 From: Justin Eltoft Date: Mon, 22 Apr 2019 07:48:11 -0500 Subject: [PATCH] fixed visual appearance on mac by setting a theme, and added pref port support for first time seen ports --- .gitignore | 1 + main.py | 20 +++++++++++++++++++- src/gui/main_window.py | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7fce8bb..ce70407 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ dist/* *.exe *.swp *.DS_Store +*.pyc diff --git a/main.py b/main.py index 22a3e6e..3241718 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,8 @@ import sys -from PyQt5.QtGui import QIcon +from PyQt5.QtGui import QIcon, QPalette, QColor from PyQt5.QtWidgets import QApplication +from PyQt5.QtCore import Qt from src.gui.main_window import MainWindow from src.helpers.pyinstaller_helper import PyInstallerHelper @@ -15,6 +16,23 @@ myApp = QApplication(sys.argv) myApp.setQuitOnLastWindowClosed(True) + myApp.setStyle('Fusion') + palette = QPalette() + palette.setColor(QPalette.Window, QColor(53,53,53)) + palette.setColor(QPalette.WindowText, Qt.white) + palette.setColor(QPalette.Base, QColor(15,15,15)) + palette.setColor(QPalette.AlternateBase, QColor(53,53,53)) + palette.setColor(QPalette.ToolTipBase, Qt.white) + palette.setColor(QPalette.ToolTipText, Qt.white) + palette.setColor(QPalette.Text, Qt.white) + palette.setColor(QPalette.Button, QColor(53,53,53)) + palette.setColor(QPalette.ButtonText, Qt.white) + palette.setColor(QPalette.BrightText, Qt.red) + + palette.setColor(QPalette.Highlight, QColor(142,45,197).lighter()) + palette.setColor(QPalette.HighlightedText, Qt.black) + myApp.setPalette(palette) + path = PyInstallerHelper.resource_path("icons\\main.png") icon = QIcon(path) diff --git a/src/gui/main_window.py b/src/gui/main_window.py index fd3020a..c2fe876 100644 --- a/src/gui/main_window.py +++ b/src/gui/main_window.py @@ -38,6 +38,8 @@ def __init__(self): if geometry: self.localFilesTreeView.header().restoreState(geometry) + self._pref_port_found = False + self._connection_scanner = ConnectionScanner() self._connection = None self._root_dir = Settings().root_dir @@ -115,6 +117,7 @@ def connection_changed(self): def refresh_ports(self): # Cache value of last selected connection because it might change when manipulating combobox last_selected_connection = self.lastSelectedConnection + local_pref_port_found = False self._connection_scanner.scan_connections(with_wifi=True) self.connectionComboBox.clear() @@ -128,11 +131,18 @@ def refresh_ports(self): for i, port in enumerate(self._connection_scanner.port_list): self.connectionComboBox.addItem(port) if pref_port and port.upper() == pref_port.upper(): + local_pref_port_found = True selected_port_idx = i # Override preferred port if user made selection and this port is still available - if last_selected_connection and last_selected_connection in self._connection_scanner.port_list: - selected_port_idx = self._connection_scanner.port_list.index(last_selected_connection) + # unless pref port was just found for the FIRST time + if (self._pref_port_found): + if last_selected_connection and last_selected_connection in self._connection_scanner.port_list: + selected_port_idx = self._connection_scanner.port_list.index(last_selected_connection) + + if (local_pref_port_found): + self._pref_port_found = True; + # Set current port self.connectionComboBox.setCurrentIndex(selected_port_idx if selected_port_idx >= 0 else 0) self.connectButton.setEnabled(True)