Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions kratt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
DEFAULT_MAIN_MODEL,
DEFAULT_VISION_MODEL,
DEFAULT_SYSTEM_PROMPT,
HOTKEY,
)

__all__ = [
"DEFAULT_MAIN_MODEL",
"DEFAULT_VISION_MODEL",
"DEFAULT_SYSTEM_PROMPT",
"HOTKEY",
]
]
12 changes: 3 additions & 9 deletions kratt/config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
"""
Configuration constants, default settings, and settings persistence for Kratt.

This module defines default models, system prompts, hotkey bindings,
RAG (Retrieval-Augmented Generation) parameters, and handles loading/saving
user settings to a JSON file.
This module defines default models, system prompts, RAG (Retrieval-Augmented
Generation) parameters, and handles loading/saving user settings to a JSON file.
"""

from pynput import keyboard
import json
from pathlib import Path
from pynput import keyboard

# LLM Models
DEFAULT_MAIN_MODEL = "qwen2.5:7b"
Expand All @@ -34,9 +31,6 @@
- Use code blocks with language identifiers.
""".strip()

# Global Hotkey
HOTKEY = {keyboard.Key.ctrl_l, keyboard.Key.shift_l}

# RAG Settings
RAG_CHUNK_SIZE = 500
RAG_CHUNK_OVERLAP = 50
Expand Down Expand Up @@ -90,4 +84,4 @@ def save_settings(settings: dict) -> None:
with open(SETTINGS_FILE, "w", encoding="utf-8") as f:
json.dump(settings, f, indent=4)
except IOError as e:
print(f"Error saving settings: {e}")
print(f"Error saving settings: {e}")
5 changes: 2 additions & 3 deletions kratt/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
Core backend logic (workers, search, hotkeys).
Core backend logic (workers, search).
"""

from kratt.core.hotkey_manager import HotkeyManager
from kratt.core.worker import OllamaWorker

__all__ = ["HotkeyManager", "OllamaWorker"]
__all__ = ["OllamaWorker"]
96 changes: 0 additions & 96 deletions kratt/core/hotkey_manager.py

This file was deleted.

9 changes: 1 addition & 8 deletions kratt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
Application entry point.

Initializes the Qt Application, styling fixes for Linux,
and the global hotkey listener.
and the main window with system tray integration.
"""

import sys
from pathlib import Path
from PySide6.QtGui import QFontDatabase, QFont
from PySide6.QtWidgets import QApplication
from kratt.ui.main_window import MainWindow
from kratt.core.hotkey_manager import HotkeyManager
from kratt.config import HOTKEY


def load_stylesheet(app: QApplication) -> None:
Expand Down Expand Up @@ -47,13 +45,8 @@ def main() -> None:
app.setStyleSheet(current_style + f"\nQToolTip {{ font-family: '{font_family}'; }}")

window = MainWindow()

# Initialize global hotkey listener
hotkey_mgr = HotkeyManager(HOTKEY, window.toggle_visibility)

window.show()
exit_code = app.exec()
hotkey_mgr.stop()
sys.exit(exit_code)


Expand Down
18 changes: 2 additions & 16 deletions kratt/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class MainWindow(QWidget):
integration for minimized state.
"""

toggle_signal = Signal()

def __init__(self) -> None:
"""Initialize the main window and set up all components."""
super().__init__()
Expand All @@ -62,7 +60,6 @@ def __init__(self) -> None:

self._setup_ui()
self._setup_tray()
self._setup_hotkey()
self.new_chat()

def _setup_ui(self) -> None:
Expand Down Expand Up @@ -185,7 +182,7 @@ def _setup_header(self) -> None:
btn_close.setObjectName("CloseBtn")
btn_close.setFixedSize(28, 28)
btn_close.setCursor(Qt.CursorShape.PointingHandCursor)
btn_close.clicked.connect(self.toggle_visibility)
btn_close.clicked.connect(self.hide)

self.header_layout.addWidget(title)
self.header_layout.addStretch()
Expand Down Expand Up @@ -548,15 +545,4 @@ def _scroll_to_bottom(self) -> None:
lambda: self.scroll_area.verticalScrollBar().setValue(
self.scroll_area.verticalScrollBar().maximum()
)
)

def _setup_hotkey(self) -> None:
"""Connect the global hotkey signal to toggle visibility."""
self.toggle_signal.connect(self.toggle_visibility)

def toggle_visibility(self) -> None:
"""Show or hide the window, ensuring focus when shown."""
if self.isVisible():
self.hide()
else:
self.show_window()
)
9 changes: 1 addition & 8 deletions setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ pip install -r requirements.txt
echo "Installing Playwright browsers..."
playwright install

# 4. Add user to input group for global hotkey support
echo "Adding $USER to input group for global hotkey detection..."
sudo usermod -a -G input "$USER"
echo ""
echo "⚠️ Important: Log out and back in for global hotkeys to work (Ctrl+Alt_R)."
echo ""

# 5. Systemd Auto-startup
# 4. Systemd Auto-startup
read -p "Do you want to create a systemd user service for automatic startup? (y/N): " confirm
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then
echo "Creating systemd user service..."
Expand Down
30 changes: 2 additions & 28 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
"""
Pytest configuration and fixtures.

Handles mocking of system-level modules (pynput, keyboard) that require
input device access or display servers.
Handles mocking of system-level modules that require external services.
"""
import sys
from unittest.mock import MagicMock, patch

# Mock pynput
mock_pynput = MagicMock()
mock_pynput_keyboard = MagicMock()

# Create a mock Key object
mock_key = MagicMock()
mock_key.ctrl_l = "ctrl_l"
mock_key.ctrl_r = "ctrl_r"
mock_key.alt_l = "alt_l"
mock_key.alt_r = "alt_r"
mock_key.shift_l = "shift_l"
mock_key.shift_r = "shift_r"

mock_pynput_keyboard.Key = mock_key
mock_pynput.keyboard = mock_pynput_keyboard

sys.modules['pynput'] = mock_pynput
sys.modules['pynput.keyboard'] = mock_pynput_keyboard

# Mock keyboard
mock_keyboard = MagicMock()
sys.modules['keyboard'] = mock_keyboard

from unittest.mock import patch

import pytest

Expand Down
Loading