|
|
|
|
from PyQt6.QtCore import Qt, QTimer, QThreadPool
|
|
|
|
|
from PyQt6.QtWidgets import QMenu
|
|
|
|
|
from PyQt6.QtGui import QAction
|
|
|
|
|
|
|
|
|
|
from ui.workers import GatherPokemonFormsWorker
|
|
|
|
|
|
|
|
|
|
from db import db
|
|
|
|
|
|
|
|
|
|
class MainWindowController:
|
|
|
|
|
def __init__(self, view):
|
|
|
|
|
self.view = view
|
|
|
|
|
self.pokemon_data_cache = []
|
|
|
|
|
self.filter_timer = QTimer()
|
|
|
|
|
self.filter_timer.setInterval(300) # 300 ms delay to wait for user to stop typing
|
|
|
|
|
self.filter_timer.setSingleShot(True)
|
|
|
|
|
self.filter_timer.timeout.connect(self.apply_filters)
|
|
|
|
|
self.thread_pool = QThreadPool()
|
|
|
|
|
|
|
|
|
|
def initialize_pokemon_list(self, data):
|
|
|
|
|
self.pokemon_data_cache = data
|
|
|
|
|
self.view.update_pokemon_forms(data)
|
|
|
|
|
|
|
|
|
|
def filter_pokemon_list(self):
|
|
|
|
|
self.filter_timer.start()
|
|
|
|
|
|
|
|
|
|
def apply_filters(self):
|
|
|
|
|
search_text = self.view.search_bar.text().lower()
|
|
|
|
|
show_only_home_storable = self.view.filter_home_storable.isChecked()
|
|
|
|
|
show_only_missing_encounters = self.view.highlight_no_encounters.isChecked()
|
|
|
|
|
|
|
|
|
|
filtered_data = []
|
|
|
|
|
for pfic, display_name in self.pokemon_data_cache:
|
|
|
|
|
# Check if the item matches the search text
|
|
|
|
|
text_match = search_text in display_name.lower()
|
|
|
|
|
|
|
|
|
|
# Check if the item is storable in Home (if the filter is active)
|
|
|
|
|
home_storable = True
|
|
|
|
|
if show_only_home_storable:
|
|
|
|
|
# TODO: update the call to correctly filter the data, or better yet update the data at the source to include this info.
|
|
|
|
|
home_storable = True #event_system.call_sync('get_home_storable', pfic)
|
|
|
|
|
|
|
|
|
|
# Check to see if the pokemon has encounters
|
|
|
|
|
has_encounters = True
|
|
|
|
|
if show_only_missing_encounters:
|
|
|
|
|
# TODO: reimplement this check.
|
|
|
|
|
has_encounters = True
|
|
|
|
|
|
|
|
|
|
# If both conditions are met, add to filtered data
|
|
|
|
|
if text_match and home_storable:
|
|
|
|
|
filtered_data.append((pfic, display_name))
|
|
|
|
|
|
|
|
|
|
# Update the view with the filtered data
|
|
|
|
|
self.view.update_pokemon_forms(filtered_data)
|
|
|
|
|
|
|
|
|
|
def show_pokemon_context_menu(self, position):
|
|
|
|
|
item = self.view.pokemon_list.itemAt(position)
|
|
|
|
|
if item is not None:
|
|
|
|
|
context_menu = QMenu(self)
|
|
|
|
|
refresh_action = QAction("Refresh Encounters", self)
|
|
|
|
|
refresh_action.triggered.connect(lambda: self.refresh_pokemon_encounters(item))
|
|
|
|
|
context_menu.addAction(refresh_action)
|
|
|
|
|
context_menu.exec(self.pokemon_list.viewport().mapToGlobal(position))
|
|
|
|
|
|
|
|
|
|
def on_pokemon_selected(self, item):
|
|
|
|
|
pfic = item.data(Qt.ItemDataRole.UserRole)
|
|
|
|
|
self.refresh_pokemon_details_panel(pfic)
|
|
|
|
|
|
|
|
|
|
def edit_encounter(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def add_new_encounter(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def add_new_evolution(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def save_changes(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def export_database(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def gather_pokemon_forms(self):
|
|
|
|
|
worker = GatherPokemonFormsWorker()
|
|
|
|
|
worker.signals.finished.connect(self.on_forms_gathered)
|
|
|
|
|
self.thread_pool.start(worker)
|
|
|
|
|
|
|
|
|
|
def on_forms_gathered(self, data):
|
|
|
|
|
# This method will be called in the main thread when the worker finishes
|
|
|
|
|
# Update the UI with the gathered forms
|
|
|
|
|
for pokemon in data:
|
|
|
|
|
db.add_pokemon_form(pokemon["pfic"], pokemon["name"], pokemon["form_name"], pokemon["national_dex"], pokemon["generation"], pokemon["sprite_url"])
|
|
|
|
|
self.pokemon_data_cache = data
|
|
|
|
|
self.view.update_pokemon_forms(data)
|
|
|
|
|
|
|
|
|
|
db.save_changes()
|
|
|
|
|
|
|
|
|
|
def gather_home_storage_info(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def gather_evolution_info(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def reinitialize_database(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def gather_encounter_info(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def gather_marks_info(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def load_shiftable_forms(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def on_exclusive_set_selected(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def add_new_exclusive_set(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def show_encounter_context_menu(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def add_encounter_to_set(self):
|
|
|
|
|
pass
|