Skip to content

Commit

Permalink
Fixed a bug related to the action after finishing listening to the cu…
Browse files Browse the repository at this point in the history
…rrent verse when changing the navigation mode.
  • Loading branch information
MahmoudAtef999 committed Nov 28, 2024
1 parent 7a50b6a commit c9e36ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 6 additions & 4 deletions ui/quran_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -195,15 +196,16 @@ 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
self.next_to.setEnabled(next_status)
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():
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 0 additions & 5 deletions ui/widgets/qText_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions ui/widgets/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c9e36ac

Please sign in to comment.