From 450f6441e26f6ee4e0af77546bfaf3a37c04a866 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 20 Aug 2022 20:29:33 +0300 Subject: [PATCH 1/6] Fix path to remove shared libraries when packaging the Windows app --- Khoj.spec | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Khoj.spec b/Khoj.spec index 3bee99b8..eae5be1c 100644 --- a/Khoj.spec +++ b/Khoj.spec @@ -41,8 +41,9 @@ torch_lib_paths = { } a.datas = [entry for entry in a.datas if not entry[0] in torch_lib_paths] -a.datas = [entry for entry in a.datas if not 'torch/_C.cp' in entry[0]] -a.datas = [entry for entry in a.datas if not 'torch/_dl.cp' in entry[0]] +os_path_separator = '\\' if system() == 'Windows' else '/' +a.datas = [entry for entry in a.datas if not f'torch{os_path_separator}_C.cp' in entry[0]] +a.datas = [entry for entry in a.datas if not f'torch{os_path_separator}_dl.cp' in entry[0]] pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) From 1b1f8f9272fa4cfcf7f31bca7c7e761f4b7929aa Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 20 Aug 2022 20:32:31 +0300 Subject: [PATCH 2/6] Move Splash screen text below icon. Set the text color to black - It is currently on top of the splash screen icon - Ballpark pixels to move such that text positioned below icon - Test later to verify if text is positioned fine now --- Khoj.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Khoj.spec b/Khoj.spec index eae5be1c..b191acd9 100644 --- a/Khoj.spec +++ b/Khoj.spec @@ -53,9 +53,9 @@ if system() != 'Darwin': 'src/interface/web/assets/icons/favicon-144x144.png', binaries=a.binaries, datas=a.datas, - text_pos=(10, 50), + text_pos=(10, 160), text_size=12, - text_color='blue', + text_color='black', minify_script=True, always_on_top=True ) From dfe2546c048dae7e22cd42f4d2184e2f08725964 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 20 Aug 2022 20:36:15 +0300 Subject: [PATCH 3/6] Set Khoj Icon on Main Desktop Window --- src/interface/desktop/main_window.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/interface/desktop/main_window.py b/src/interface/desktop/main_window.py index cf4168dd..a9b7ae2c 100644 --- a/src/interface/desktop/main_window.py +++ b/src/interface/desktop/main_window.py @@ -6,8 +6,8 @@ import webbrowser # External Packages -from PyQt6 import QtWidgets -from PyQt6.QtCore import Qt, QThread, QObject, pyqtSignal +from PyQt6 import QtGui, QtWidgets +from PyQt6.QtCore import QThread, QObject, pyqtSignal # Internal Packages from src.configure import configure_server @@ -49,6 +49,10 @@ class MainWindow(QtWidgets.QMainWindow): self.setWindowTitle("Khoj") self.setFixedWidth(600) + # Set Window Icon + icon_path = constants.web_directory / 'assets/icons/favicon-144x144.png' + self.setWindowIcon(QtGui.QIcon(f'{icon_path.absolute()}')) + # Initialize Configure Window Layout self.layout = QtWidgets.QVBoxLayout() From 1c122a8a91ad759d4d75a99dcec2fcd3671f9a35 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 20 Aug 2022 22:38:06 +0300 Subject: [PATCH 4/6] Place window near top so buttons are not hidden by OS bottom bar --- src/interface/desktop/main_window.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/interface/desktop/main_window.py b/src/interface/desktop/main_window.py index a9b7ae2c..5c49da2d 100644 --- a/src/interface/desktop/main_window.py +++ b/src/interface/desktop/main_window.py @@ -4,7 +4,6 @@ from pathlib import Path from copy import deepcopy import webbrowser - # External Packages from PyQt6 import QtGui, QtWidgets from PyQt6.QtCore import QThread, QObject, pyqtSignal @@ -76,7 +75,7 @@ class MainWindow(QtWidgets.QMainWindow): self.config_window = QtWidgets.QWidget() self.config_window.setLayout(self.layout) self.setCentralWidget(self.config_window) - + self.position_window() def add_settings_panel(self, current_content_config: dict, search_type: SearchType): "Add Settings Panel for specified Search Type. Toggle Editable Search Types" @@ -267,6 +266,13 @@ class MainWindow(QtWidgets.QMainWindow): self.thread.finished.connect(lambda: self.configure_button.setEnabled(True)) self.thread.finished.connect(lambda: self.search_button.setEnabled(True)) + def position_window(self): + "Position the window at center of X axis and near top on Y axis" + window_rectangle = self.geometry() + screen_center = self.screen().availableGeometry().center() + window_rectangle.moveCenter(screen_center) + self.move(window_rectangle.topLeft().x(), 25) + class SettingsLoader(QObject): "Load Settings Thread" From 8098b8c3a80859336c47f67146c1367d1d0445b1 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 20 Aug 2022 23:38:43 +0300 Subject: [PATCH 5/6] Bring Configure Window to Top when Opened from System Tray - Previously the window could get hidden behind other app windows when user clicked configure from the system tray --- src/interface/desktop/main_window.py | 9 ++++++++- src/interface/desktop/system_tray.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/interface/desktop/main_window.py b/src/interface/desktop/main_window.py index 5c49da2d..97bbb54a 100644 --- a/src/interface/desktop/main_window.py +++ b/src/interface/desktop/main_window.py @@ -6,7 +6,7 @@ import webbrowser # External Packages from PyQt6 import QtGui, QtWidgets -from PyQt6.QtCore import QThread, QObject, pyqtSignal +from PyQt6.QtCore import Qt, QThread, QObject, pyqtSignal # Internal Packages from src.configure import configure_server @@ -273,6 +273,13 @@ class MainWindow(QtWidgets.QMainWindow): window_rectangle.moveCenter(screen_center) self.move(window_rectangle.topLeft().x(), 25) + def show_on_top(self): + "Bring Window on Top" + self.show() + self.setWindowState(Qt.WindowState.WindowActive) + self.activateWindow() # For Bringing to Top on Windows + self.raise_() # For Bringing to Top from Minimized State on OSX + class SettingsLoader(QObject): "Load Settings Thread" diff --git a/src/interface/desktop/system_tray.py b/src/interface/desktop/system_tray.py index c24a9911..7b230c54 100644 --- a/src/interface/desktop/system_tray.py +++ b/src/interface/desktop/system_tray.py @@ -25,7 +25,7 @@ def create_system_tray(gui: QtWidgets.QApplication, main_window: QtWidgets.QMain menu = QtWidgets.QMenu() menu_actions = [ ('Search', lambda: webbrowser.open(f'http://{state.host}:{state.port}/')), - ('Configure', main_window.show), + ('Configure', main_window.show_on_top), ('Quit', gui.quit), ] From 5e6625ac6857543f728f3b3a0c8473a249caaf84 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sun, 21 Aug 2022 02:03:28 +0300 Subject: [PATCH 6/6] Fix file browser to not add empty line when no file/dir selected - When no file selected in file browser an empty line/entry gets added to input entries list - Bug got introduced due to insufficient update on change to add instead of insert - Update is_none_or_empty helper method to also check for empty string --- src/interface/desktop/file_browser.py | 16 ++++++---------- src/utils/helpers.py | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/interface/desktop/file_browser.py b/src/interface/desktop/file_browser.py index e14dfd1c..dca60bdf 100644 --- a/src/interface/desktop/file_browser.py +++ b/src/interface/desktop/file_browser.py @@ -4,10 +4,11 @@ from PyQt6.QtCore import QDir # Internal Packages from src.utils.config import SearchType +from src.utils.helpers import is_none_or_empty class FileBrowser(QtWidgets.QWidget): - def __init__(self, title, search_type: SearchType=None, default_files=[]): + def __init__(self, title, search_type: SearchType=None, default_files:list=[]): QtWidgets.QWidget.__init__(self) layout = QtWidgets.QHBoxLayout() self.setLayout(layout) @@ -57,16 +58,11 @@ class FileBrowser(QtWidgets.QWidget): filter=self.filter_name)[0]) self.setFiles(filepaths) - def setFiles(self, paths): - self.filepaths = paths - if not self.filepaths or len(self.filepaths) == 0: - return - elif len(self.filepaths) == 1: - self.lineEdit.setPlainText(self.filepaths[0]) - else: - self.lineEdit.setPlainText("\n".join(self.filepaths)) + def setFiles(self, paths:list): + self.filepaths = [path for path in paths if not is_none_or_empty(path)] + self.lineEdit.setPlainText("\n".join(self.filepaths)) - def getPaths(self): + def getPaths(self) -> list: if self.lineEdit.toPlainText() == '': return [] else: diff --git a/src/utils/helpers.py b/src/utils/helpers.py index e77e656d..989ddf09 100644 --- a/src/utils/helpers.py +++ b/src/utils/helpers.py @@ -5,7 +5,7 @@ from os.path import join def is_none_or_empty(item): - return item == None or (hasattr(item, '__iter__') and len(item) == 0) + return item == None or (hasattr(item, '__iter__') and len(item) == 0) or item == '' def to_snake_case_from_dash(item: str):