From c9e36ac0331cedd3b7cf343c352773b892a37c57 Mon Sep 17 00:00:00 2001 From: mahmoud atef <109464635+MahmoudAtefFarook@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:43:05 +0200 Subject: [PATCH] Fixed a bug related to the action after finishing listening to the current verse when changing the navigation mode. --- ui/quran_interface.py | 10 ++++++---- ui/widgets/qText_edit.py | 5 ----- ui/widgets/toolbar.py | 13 ++++++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ui/quran_interface.py b/ui/quran_interface.py index 33aac2b..a5ecf74 100644 --- a/ui/quran_interface.py +++ b/ui/quran_interface.py @@ -141,6 +141,7 @@ def set_focus_to_ayah(self, ayah_number: int): cursor = QTextCursor(self.quran_view.document()) cursor.setPosition(text_position) self.quran_view.setTextCursor(cursor) + def OnNext(self): self.quran_view.setText(self.quran.next()) @@ -195,7 +196,7 @@ def set_text_ctrl_label(self): self.quran_title.setText(label) self.quran_view.setAccessibleName(label) UniversalSpeech.say(label) - + # Enable back and next item next_status = self.quran.current_pos < self.quran.max_pos back_status = self.quran.current_pos > 1 @@ -203,7 +204,8 @@ def set_text_ctrl_label(self): self.menu_bar.next_action.setEnabled(next_status) self.back_to.setEnabled(back_status) self.menu_bar.previous_action.setEnabled(back_status) - + self.toolbar.navigation.reset_position() + def OnQuickAccess(self): dialog = QuickAccess(self, "الوصول السريع") if not dialog.exec(): @@ -338,9 +340,9 @@ def OnChangeNavigationMode(self, mode): ayah_number = ayah_info[1] self.quran.type = mode self.quran_view.setText(self.quran.get_by_ayah_number(ayah_number)["full_text"]) - self.set_text_ctrl_label() self.set_focus_to_ayah(ayah_number) - + self.set_text_ctrl_label() + def closeEvent(self, event): if SettingsManager.current_settings["general"]["run_in_background_enabled"]: event.ignore() diff --git a/ui/widgets/qText_edit.py b/ui/widgets/qText_edit.py index a4d4fa4..272f7bd 100644 --- a/ui/widgets/qText_edit.py +++ b/ui/widgets/qText_edit.py @@ -23,11 +23,6 @@ def __init__(self, parent=None): self.parent = parent self.textChanged.connect(self.set_ctrl) - def setText(self, text): - self.parent.toolbar.navigation.reset_position() - self.parent.toolbar.set_buttons_status() - return super().setText(text) - def set_ctrl(self): current_line_text = self.textCursor().block().text() status = False if "سُورَةُ" in current_line_text or current_line_text == "|" or not re.search(r"\(\d+\)$", current_line_text) else True diff --git a/ui/widgets/toolbar.py b/ui/widgets/toolbar.py index 4b95e8c..2ee4d87 100644 --- a/ui/widgets/toolbar.py +++ b/ui/widgets/toolbar.py @@ -2,6 +2,7 @@ from typing import Optional from PyQt6.QtWidgets import QToolBar, QPushButton, QSlider from PyQt6.QtCore import Qt, QThread, pyqtSignal, QTimer +from core_functions.quran_class import quran_mgr from core_functions.Reciters import RecitersManager from utils.audio_player import AudioPlayer from utils.settings import SettingsManager @@ -33,7 +34,6 @@ def run(self): def check_playback_status(self): if not self.player.is_playing() and not self.player.is_stalled(): - print(self.player.get_playback_status()) self.timer.stop() self.statusChanged.emit() if not self.player.is_paused() and not self.manually_stopped: @@ -45,7 +45,8 @@ def set_audio_url(self, url: str): self.wait() class NavigationManager: - def __init__(self, quran): + def __init__(self, parent, quran: quran_mgr): + self.parent = parent self.quran = quran self.ayah_range = None self.current_surah = None @@ -56,8 +57,10 @@ def initialize_ayah_range(self): def reset_position(self): self.initialize_ayah_range() - self.current_surah = min(self.ayah_range.keys()) - self.current_ayah = self.ayah_range[self.current_surah]["min_ayah"] - 1 + ayah_info = self.parent.get_current_ayah_info() + if ayah_info[0] != self.current_surah or not (self.ayah_range[self.current_surah]["min_ayah"] < ayah_info[3] < self.ayah_range[self.current_surah]["max_ayah"]): + self.current_surah = min(self.ayah_range.keys()) + self.current_ayah = self.ayah_range[self.current_surah]["min_ayah"] - 1 def set_position(self, surah_number: int, ayah_number: int) -> None: self.initialize_ayah_range() @@ -118,7 +121,7 @@ def __init__(self, parent: Optional[object] = None): self.parent = parent self.player = AudioPlayer() self.reciters = RecitersManager(data_folder / "quran" / "reciters.db") - self.navigation = NavigationManager(self.parent.quran) + self.navigation = NavigationManager(self.parent, self.parent.quran) self.audio_thread = AudioPlayerThread(self.player, self.parent) self.play_pause_button = self.create_button("استماع الآية الحالية", self.toggle_play_pause)