feat: Add search engine selection functionality
This commit is contained in:
49
app.py
49
app.py
@ -88,6 +88,17 @@ class URLManager(QWidget):
|
|||||||
# Load settings
|
# Load settings
|
||||||
self.load_settings()
|
self.load_settings()
|
||||||
|
|
||||||
|
# Search engines
|
||||||
|
self.search_engines = {
|
||||||
|
"Bing": "https://www.bing.com/search?q=",
|
||||||
|
"Brave": "https://search.brave.com/search?q=",
|
||||||
|
"DuckDuckGo": "https://duckduckgo.com/?q=",
|
||||||
|
"Ecosia": "https://www.ecosia.org/search?q=",
|
||||||
|
"Google": "https://www.google.com/search?q=",
|
||||||
|
"Startpage": "https://www.startpage.com/do/search?q=",
|
||||||
|
"Swisscows": "https://swisscows.com/web?query="
|
||||||
|
}
|
||||||
|
|
||||||
def update_icon_color(self):
|
def update_icon_color(self):
|
||||||
# Heuristic to check if the application is in dark mode
|
# Heuristic to check if the application is in dark mode
|
||||||
palette = self.palette()
|
palette = self.palette()
|
||||||
@ -141,8 +152,8 @@ class URLManager(QWidget):
|
|||||||
def search_url(self):
|
def search_url(self):
|
||||||
search_term = self.search_input.text()
|
search_term = self.search_input.text()
|
||||||
if search_term:
|
if search_term:
|
||||||
search_engine = "https://www.google.com/search?q="
|
search_engine_url = self.search_engines.get(self.search_engine, "https://www.google.com/search?q=")
|
||||||
search_url = search_engine + search_term
|
search_url = search_engine_url + search_term
|
||||||
QMessageBox.information(self, "Search", f"Searching for: {search_term}\nURL: {search_url}")
|
QMessageBox.information(self, "Search", f"Searching for: {search_term}\nURL: {search_url}")
|
||||||
self.search_input.clear()
|
self.search_input.clear()
|
||||||
|
|
||||||
@ -180,13 +191,15 @@ class URLManager(QWidget):
|
|||||||
if os.path.getsize(settings_path) > 0:
|
if os.path.getsize(settings_path) > 0:
|
||||||
with open(settings_path, 'r') as file:
|
with open(settings_path, 'r') as file:
|
||||||
settings = json.load(file)
|
settings = json.load(file)
|
||||||
# Use settings (for now, we only have the data_directory)
|
|
||||||
self.data_directory = settings.get('data_directory', 'data/')
|
self.data_directory = settings.get('data_directory', 'data/')
|
||||||
|
self.search_engine = settings.get('search_engine', 'Google')
|
||||||
else:
|
else:
|
||||||
self.data_directory = 'data/'
|
self.data_directory = 'data/'
|
||||||
|
self.search_engine = 'Google'
|
||||||
self.save_settings()
|
self.save_settings()
|
||||||
else:
|
else:
|
||||||
self.data_directory = 'data/'
|
self.data_directory = 'data/'
|
||||||
|
self.search_engine = 'Google'
|
||||||
self.save_settings()
|
self.save_settings()
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
@ -194,7 +207,8 @@ class URLManager(QWidget):
|
|||||||
os.makedirs(os.path.dirname(settings_path), exist_ok=True)
|
os.makedirs(os.path.dirname(settings_path), exist_ok=True)
|
||||||
with open(settings_path, 'w') as file:
|
with open(settings_path, 'w') as file:
|
||||||
settings = {
|
settings = {
|
||||||
'data_directory': self.data_directory
|
'data_directory': self.data_directory,
|
||||||
|
'search_engine': self.search_engine
|
||||||
}
|
}
|
||||||
json.dump(settings, file)
|
json.dump(settings, file)
|
||||||
|
|
||||||
@ -203,18 +217,35 @@ class SettingsDialog(QDialog):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setWindowTitle("Settings")
|
self.setWindowTitle("Settings")
|
||||||
|
self.setFixedWidth(360) # Set the width of the window to 360 pixels
|
||||||
|
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
|
|
||||||
# File/Directory selection
|
# Data Directory label
|
||||||
form_layout = QFormLayout()
|
directory_label = QLabel("Data Directory:")
|
||||||
|
layout.addWidget(directory_label)
|
||||||
|
|
||||||
|
# File/Directory selection layout
|
||||||
|
directory_layout = QHBoxLayout()
|
||||||
self.directory_input = QLineEdit(self.parent.data_directory)
|
self.directory_input = QLineEdit(self.parent.data_directory)
|
||||||
self.browse_button = QPushButton("Browse...")
|
self.browse_button = QPushButton("Browse...")
|
||||||
self.browse_button.clicked.connect(self.browse_directory)
|
self.browse_button.clicked.connect(self.browse_directory)
|
||||||
form_layout.addRow("Data Directory:", self.directory_input)
|
directory_layout.addWidget(self.directory_input)
|
||||||
form_layout.addWidget(self.browse_button)
|
directory_layout.addWidget(self.browse_button)
|
||||||
|
layout.addLayout(directory_layout)
|
||||||
|
|
||||||
|
# Add 4 pixels of empty space
|
||||||
|
layout.addSpacerItem(QSpacerItem(0, 4, QSizePolicy.Minimum, QSizePolicy.Fixed))
|
||||||
|
|
||||||
|
# Search engine selection
|
||||||
|
form_layout = QFormLayout()
|
||||||
|
self.search_engine_combobox = QComboBox()
|
||||||
|
search_engines = sorted(self.parent.search_engines.keys())
|
||||||
|
self.search_engine_combobox.addItems(search_engines)
|
||||||
|
self.search_engine_combobox.setCurrentText(self.parent.search_engine)
|
||||||
|
form_layout.addRow("Search Engine:", self.search_engine_combobox)
|
||||||
|
|
||||||
layout.addLayout(form_layout)
|
layout.addLayout(form_layout)
|
||||||
|
|
||||||
@ -232,10 +263,10 @@ class SettingsDialog(QDialog):
|
|||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
self.parent.data_directory = self.directory_input.text()
|
self.parent.data_directory = self.directory_input.text()
|
||||||
|
self.parent.search_engine = self.search_engine_combobox.currentText()
|
||||||
self.parent.save_settings()
|
self.parent.save_settings()
|
||||||
self.accept()
|
self.accept()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
app.setWindowIcon(QIcon('assets/logo.png')) # Set the application icon using PNG for compatibility
|
app.setWindowIcon(QIcon('assets/logo.png')) # Set the application icon using PNG for compatibility
|
||||||
|
|||||||
Reference in New Issue
Block a user