Skip to content

Commit e7565ae

Browse files
Merge branch 'upgrade_to_python3.13' into albayan_beta
2 parents fcbd674 + 36ba486 commit e7565ae

21 files changed

+340
-246
lines changed

albayan_env.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cd /d "%~dp0"
77
set /p create_activate=Do you want to Create or Activate the environment? (C/A):
88

99
if /i !create_activate! equ C (
10-
start /wait py -3.12 -m venv albayan_env
10+
start /wait py -3.13 -m venv albayan_env
1111
start cmd.exe /k "call albayan_env\Scripts\activate.bat && cd /d ""%~dp0"" && pip install -r requirements.txt"
1212
) else if /i !create_activate! equ A (
1313
start cmd.exe /k "call albayan_env\Scripts\activate.bat"

build.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set VENV_DIR=albayan_env
44

55
if not exist %VENV_DIR% (
66
echo Creating virtual environment...
7-
py -3.12 -m venv %VENV_DIR%
7+
py -3.13 -m venv %VENV_DIR%
88
)
99

1010
call %VENV_DIR%\Scripts\activate

core_functions/quran_class.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import sqlite3
2323
from typing import List, Dict, Union
2424
from core_functions.ayah_data import AyahData
25-
from utils.settings import SettingsManager
25+
from utils.settings import Config
2626
from utils.const import data_folder
2727
from exceptions.database import DBNotFoundError
2828

@@ -298,7 +298,7 @@ def get_text(self):
298298
last_position = current_position - 1
299299
ayah_data.insert(ayah[1], ayah[3], ayah[4], first_position, last_position)
300300

301-
text = text + "|" if SettingsManager.current_settings["reading"]["auto_page_turn"] else text.strip()
301+
text = text + "|" if Config.reading.auto_page_turn else text.strip()
302302
self.text = text
303303
self.ayah_data = ayah_data
304304

main.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
from ui.quran_interface import QuranInterface
1111
from core_functions.athkar.athkar_scheduler import AthkarScheduler
1212
from utils.update import UpdateManager
13-
from utils.settings import SettingsManager
13+
from utils.settings import Config
1414
from utils.const import program_name, program_icon, user_db_path
1515
from utils.logger import Logger
1616
from utils.audio_player import StartupSoundEffectPlayer, VolumeController
1717

18+
Logger.initialize_logger()
19+
Config.load_settings()
20+
1821
class SingleInstanceApplication(QApplication):
1922
def __init__(self, *args, **kwargs) -> None:
2023
super().__init__(*args, **kwargs)
@@ -70,9 +73,6 @@ def eventFilter(self, obj, event):
7073

7174
return super().eventFilter(obj, event)
7275

73-
74-
75-
7676
def setup_local_server(self) -> None:
7777
if not self.local_server.listen(self.server_name):
7878
Logger.error(f"Failed to start local server: {self.local_server.errorString()}")
@@ -111,7 +111,7 @@ def call_after_starting(parent: QuranInterface) -> None:
111111
basmala = StartupSoundEffectPlayer("Audio/basmala")
112112
basmala.play()
113113

114-
check_update_enabled = SettingsManager.current_settings["general"].get("check_update_enabled", False)
114+
check_update_enabled = getattr(Config.general, "check_update_enabled", False)
115115
update_manager = UpdateManager(parent, check_update_enabled)
116116
update_manager.check_auto_update()
117117

@@ -130,7 +130,6 @@ def main():
130130
call_after_starting(main_window)
131131
sys.exit(app.exec())
132132
except Exception as e:
133-
print(e)
134133
Logger.error(str(e))
135134
msg_box = QMessageBox(None)
136135
msg_box.setIcon(QMessageBox.Icon.Critical)

ui/dialogs/find.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from PyQt6.QtCore import Qt, QRegularExpression
1919
from PyQt6.QtGui import QKeyEvent, QKeySequence, QRegularExpressionValidator, QShortcut
2020
from core_functions.search import SearchCriteria, QuranSearchManager
21-
from utils.settings import SettingsManager
21+
from utils.settings import Config
2222
from utils.universal_speech import UniversalSpeech
2323
from utils.const import Globals
2424

@@ -39,7 +39,7 @@ def __init__(self, parent, title):
3939
self.resize(500, 400)
4040
self.search_manager = QuranSearchManager()
4141
self.criteria = None
42-
self.current_settings = SettingsManager.current_settings
42+
4343
self.initUI()
4444

4545
def initUI(self):
@@ -77,11 +77,11 @@ def initUI(self):
7777
self.search_to_combobox = QComboBox()
7878
self.search_to_combobox.setAccessibleName(self.search_to_label.text())
7979
self.ignore_diacritics_checkbox = QCheckBox('تجاهل التشكيل')
80-
self.ignore_diacritics_checkbox.setChecked(self.current_settings["search"]["ignore_tashkeel"])
80+
self.ignore_diacritics_checkbox.setChecked(Config.search.ignore_tashkeel)
8181
self.ignore_hamza_checkbox = QCheckBox('تجاهل الهمزات')
82-
self.ignore_hamza_checkbox.setChecked(self.current_settings["search"]["ignore_hamza"])
82+
self.ignore_hamza_checkbox.setChecked(Config.search.ignore_hamza)
8383
self.match_whole_word_checkbox = QCheckBox('تطابق الكلمة بأكملها')
84-
self.match_whole_word_checkbox.setChecked(self.current_settings["search"]["match_whole_word"])
84+
self.match_whole_word_checkbox.setChecked(Config.search.match_whole_word)
8585

8686
self.search_type_layout = QVBoxLayout()
8787
self.search_type_layout.addWidget(self.search_type_radio_page)
@@ -134,7 +134,6 @@ def initUI(self):
134134
close_shortcut = QShortcut(QKeySequence("Ctrl+F4"), self)
135135
close_shortcut.activated.connect(self.reject)
136136

137-
138137
self.on_radio_toggled()
139138
self.OnEdit()
140139

@@ -272,7 +271,6 @@ def keyPressEvent(self, event: QKeyEvent | None) -> None:
272271

273272
return super().keyPressEvent(event)
274273

275-
276274
def reject(self):
277275
self.deleteLater()
278276

ui/dialogs/settings_dialog.py

Lines changed: 65 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
from PyQt6.QtCore import Qt
2323
from core_functions.Reciters import AyahReciter
2424
from utils.const import data_folder, program_english_name
25-
from utils.settings import SettingsManager
25+
from utils.settings import Config
26+
2627
from utils.audio_player import bass_initializer, AthkarPlayer, AyahPlayer, SurahPlayer, SoundEffectPlayer
2728
from utils.Startup import StartupManager
2829
import qtawesome as qta
@@ -39,6 +40,7 @@ def __init__(self, parent):
3940
self.set_current_settings()
4041

4142

43+
4244
def init_ui(self):
4345
main_layout = QVBoxLayout()
4446
taps_layout = QHBoxLayout()
@@ -60,7 +62,6 @@ def init_ui(self):
6062
listening_item.setIcon(0, qta.icon("fa.headphones"))
6163

6264

63-
6465
reading_item = QTreeWidgetItem(["القراءة"])
6566
reading_item.setIcon(0, qta.icon("fa.book"))
6667

@@ -318,62 +319,49 @@ def save_settings(self):
318319
AthkarPlayer.apply_new_sound_card(self.athkar_device_combo.currentData())
319320
SoundEffectPlayer.apply_new_sound_card(self.volume_device_combo.currentData())
320321

321-
if SettingsManager.current_settings["general"]["auto_start_enabled"] != self.start_on_system_start_checkbox.isChecked():
322+
if Config.general.auto_start_enabled != self.start_on_system_start_checkbox.isChecked():
322323
if self.start_on_system_start_checkbox.isChecked():
323324
StartupManager.add_to_startup(program_english_name)
324325
else:
325326
StartupManager.remove_from_startup(program_english_name)
326327

327-
if SettingsManager.current_settings["reading"]["font_type"] != self.font_type_combo.currentData():
328+
if Config.reading.font_type != self.font_type_combo.currentData():
328329
self.parent.quran_view.setText(self.parent.quran.reload_quran(self.font_type_combo.currentData()))
329330

330-
general_settings = {
331-
"run_in_background_enabled": self.run_in_background_checkbox.isChecked(),
332-
"auto_start_enabled": self.start_on_system_start_checkbox.isChecked(),
333-
"auto_save_position_enabled": self.auto_save_position_checkbox.isChecked(),
334-
"check_update_enabled": self.update_checkbox.isChecked(),
335-
"logging_enabled": self.log_checkbox.isChecked()
336-
}
337-
338-
audio_settings = {
339-
"sound_effect_enabled": self.sound_checkbox.isChecked(),
340-
"start_with_basmala_enabled": self.basmala_checkbox.isChecked(),
341-
"speak_actions_enabled": self.speech_checkbox.isChecked(),
342-
"volume_level": self.volume.value(),
343-
"volume_device": self.volume_device_combo.currentData(),
344-
"ayah_volume_level": self.ayah_volume.value(),
345-
"ayah_device": self.ayah_device_combo.currentData(),
346-
"surah_volume_level": self.surah_volume.value(),
347-
"surah_device": self.surah_device_combo.currentData(),
348-
"athkar_volume_level": self.athkar_volume.value(),
349-
"athkar_device": self.athkar_device_combo.currentData()
350-
}
351-
352-
listening_settings = {
353-
"reciter": self.reciters_combo.currentData(),
354-
"action_after_listening": self.action_combo.currentData(),
355-
"forward_time": self.duration_spinbox.value(),
356-
"auto_move_focus": self.auto_move_focus_checkbox.isChecked()
357-
}
358-
359-
reading_settings = {
360-
"font_type": self.font_type_combo.currentData(),
361-
"auto_page_turn": self.turn_pages_checkbox.isChecked()
362-
}
363-
364-
search_settings = {
365-
"ignore_tashkeel": self.ignore_tashkeel_checkbox.isChecked(),
366-
"ignore_hamza": self.ignore_hamza_checkbox.isChecked(),
367-
"match_whole_word": self.match_whole_word_checkbox.isChecked()
368-
}
369-
370-
SettingsManager.write_settings({
371-
"general": general_settings,
372-
"audio": audio_settings,
373-
"listening": listening_settings,
374-
"reading": reading_settings,
375-
"search": search_settings
376-
})
331+
# Update settings in Config
332+
Config.general.run_in_background_enabled = self.run_in_background_checkbox.isChecked()
333+
Config.general.auto_start_enabled = self.start_on_system_start_checkbox.isChecked()
334+
Config.general.auto_save_position_enabled = self.auto_save_position_checkbox.isChecked()
335+
Config.general.check_update_enabled = self.update_checkbox.isChecked()
336+
Config.general.logging_enabled = self.log_checkbox.isChecked()
337+
338+
Config.audio.sound_effect_enabled = self.sound_checkbox.isChecked()
339+
Config.audio.start_with_basmala_enabled = self.basmala_checkbox.isChecked()
340+
Config.audio.speak_actions_enabled = self.speech_checkbox.isChecked()
341+
Config.audio.volume_level = self.volume.value()
342+
Config.audio.volume_device = self.volume_device_combo.currentData()
343+
Config.audio.ayah_volume_level = self.ayah_volume.value()
344+
Config.audio.ayah_device = self.ayah_device_combo.currentData()
345+
Config.audio.surah_volume_level = self.surah_volume.value()
346+
Config.audio.surah_device = self.surah_device_combo.currentData()
347+
Config.audio.athkar_volume_level = self.athkar_volume.value()
348+
Config.audio.athkar_device = self.athkar_device_combo.currentData()
349+
350+
Config.listening.reciter = self.reciters_combo.currentData()
351+
Config.listening.action_after_listening = self.action_combo.currentData()
352+
Config.listening.forward_time = self.duration_spinbox.value()
353+
Config.listening.auto_move_focus = self.auto_move_focus_checkbox.isChecked()
354+
355+
Config.reading.font_type = self.font_type_combo.currentData()
356+
Config.reading.auto_page_turn = self.turn_pages_checkbox.isChecked()
357+
358+
Config.search.ignore_tashkeel = self.ignore_tashkeel_checkbox.isChecked()
359+
Config.search.ignore_hamza = self.ignore_hamza_checkbox.isChecked()
360+
Config.search.match_whole_word = self.match_whole_word_checkbox.isChecked()
361+
362+
# Save settings to file
363+
Config.save_settings()
364+
377365
self.accept()
378366
self.deleteLater()
379367

@@ -387,46 +375,45 @@ def OnReset(self):
387375
msg_box.exec()
388376

389377
if msg_box.clickedButton() == yes_button:
390-
SettingsManager.reset_settings()
378+
Config.reset_settings()
391379
self.set_current_settings()
392380

393381
def set_current_settings(self):
394-
current_settings = SettingsManager.current_settings
395-
self.sound_checkbox.setChecked(current_settings["audio"]["sound_effect_enabled"])
396-
self.basmala_checkbox.setChecked(current_settings["audio"]["start_with_basmala_enabled"])
397-
self.speech_checkbox.setChecked(current_settings["audio"]["speak_actions_enabled"])
398-
self.volume.setValue(current_settings["audio"]["volume_level"])
399-
self.athkar_volume.setValue(current_settings["audio"]["athkar_volume_level"])
400-
self.ayah_device_combo.setCurrentIndex(current_settings["audio"]["ayah_device"])
401-
self.surah_device_combo.setCurrentIndex(current_settings["audio"]["surah_device"])
402-
self.volume_device_combo.setCurrentIndex(current_settings["audio"]["volume_device"])
403-
self.athkar_device_combo.setCurrentIndex(current_settings["audio"]["athkar_device"])
404-
self.ayah_volume.setValue(current_settings["audio"]["ayah_volume_level"])
405-
self.surah_volume.setValue(current_settings["audio"]["surah_volume_level"])
406-
self.run_in_background_checkbox.setChecked(current_settings["general"]["run_in_background_enabled"])
407-
self.turn_pages_checkbox.setChecked(current_settings["reading"]["auto_page_turn"])
408-
self.start_on_system_start_checkbox.setChecked(current_settings["general"]["auto_start_enabled"])
409-
self.auto_save_position_checkbox.setChecked(current_settings["general"]["auto_save_position_enabled"])
410-
self.update_checkbox.setChecked(current_settings["general"]["check_update_enabled"])
411-
self.duration_spinbox.setValue(current_settings["listening"]["forward_time"])
412-
self.auto_move_focus_checkbox.setChecked(current_settings["listening"]["auto_move_focus"])
413-
self.log_checkbox.setChecked(current_settings["general"]["logging_enabled"])
414-
self.ignore_tashkeel_checkbox.setChecked(current_settings["search"]["ignore_tashkeel"])
415-
self.ignore_hamza_checkbox.setChecked(current_settings["search"]["ignore_hamza"])
416-
self.match_whole_word_checkbox.setChecked(current_settings["search"]["match_whole_word"])
382+
self.sound_checkbox.setChecked(Config.audio.sound_effect_enabled)
383+
self.basmala_checkbox.setChecked(Config.audio.start_with_basmala_enabled)
384+
self.speech_checkbox.setChecked(Config.audio.speak_actions_enabled)
385+
self.volume.setValue(Config.audio.volume_level)
386+
self.athkar_volume.setValue(Config.audio.athkar_volume_level)
387+
self.ayah_device_combo.setCurrentIndex(Config.audio.ayah_device)
388+
self.surah_device_combo.setCurrentIndex(Config.audio.surah_device)
389+
self.volume_device_combo.setCurrentIndex(Config.audio.volume_device)
390+
self.athkar_device_combo.setCurrentIndex(Config.audio.athkar_device)
391+
self.ayah_volume.setValue(Config.audio.ayah_volume_level)
392+
self.surah_volume.setValue(Config.audio.surah_volume_level)
393+
self.run_in_background_checkbox.setChecked(Config.general.run_in_background_enabled)
394+
self.turn_pages_checkbox.setChecked(Config.reading.auto_page_turn)
395+
self.start_on_system_start_checkbox.setChecked(Config.general.auto_start_enabled)
396+
self.auto_save_position_checkbox.setChecked(Config.general.auto_save_position_enabled)
397+
self.update_checkbox.setChecked(Config.general.check_update_enabled)
398+
self.duration_spinbox.setValue(Config.listening.forward_time)
399+
self.auto_move_focus_checkbox.setChecked(Config.listening.auto_move_focus)
400+
self.log_checkbox.setChecked(Config.general.logging_enabled)
401+
self.ignore_tashkeel_checkbox.setChecked(Config.search.ignore_tashkeel)
402+
self.ignore_hamza_checkbox.setChecked(Config.search.ignore_hamza)
403+
self.match_whole_word_checkbox.setChecked(Config.search.match_whole_word)
417404
# Update the reciter ComboBox
418-
reciter_id = current_settings["listening"]["reciter"]
405+
reciter_id = Config.listening.reciter
419406
for index in range(self.reciters_combo.count()):
420407
if self.reciters_combo.itemData(index) == reciter_id:
421408
self.reciters_combo.setCurrentIndex(index)
422409
break
423410

424-
stored_id = current_settings["listening"]["action_after_listening"]
411+
stored_id = Config.listening.action_after_listening
425412
index = self.action_combo.findData(stored_id)
426413
if index != -1:
427414
self.action_combo.setCurrentIndex(index)
428415

429-
stored_id = current_settings["reading"]["font_type"]
416+
stored_id = Config.reading.font_type
430417
index = self.font_type_combo.findData(stored_id)
431418
if index != -1:
432419
self.font_type_combo.setCurrentIndex(index)

ui/quran_interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from ui.sura_player_ui.sura_player_ui import SuraPlayerWindow
3636
from ui.widgets.system_tray import SystemTrayManager
3737
from ui.widgets.toolbar import AudioToolBar
38-
from utils.settings import SettingsManager
38+
from utils.settings import Config
3939
from utils.universal_speech import UniversalSpeech
4040
from utils.user_data import UserDataManager
4141
from utils.const import program_name, program_icon, user_db_path, data_folder, Globals
@@ -51,7 +51,7 @@ def __init__(self, title):
5151
self.center_window()
5252
self.setWindowIcon(QIcon("Albayan.ico"))
5353
self.quran = quran_mgr()
54-
self.quran.load_quran(SettingsManager.current_settings["reading"]["font_type"])
54+
self.quran.load_quran(Config.reading.font_type)
5555
self.user_data_manager = UserDataManager(user_db_path)
5656
self.sura_player_window = None
5757
Globals.effects_manager = SoundEffectPlayer("Audio/sounds")
@@ -202,7 +202,7 @@ def OnBack(self, is_auto_call: bool = False):
202202
Globals.effects_manager.play("previous")
203203
if self.quran.current_pos == 1:
204204
self.quran_view.setFocus()
205-
if SettingsManager.current_settings["reading"]["auto_page_turn"] and is_auto_call:
205+
if Config.reading.auto_page_turn and is_auto_call:
206206
self.set_focus_to_ayah(-1)
207207

208208
def set_text_ctrl_label(self):
@@ -517,7 +517,7 @@ def OnChangeNavigationMode(self, mode):
517517
Globals.effects_manager.play("change")
518518

519519
def closeEvent(self, event):
520-
if SettingsManager.current_settings["general"]["run_in_background_enabled"]:
520+
if Config.general.run_in_background_enabled:
521521
event.ignore()
522522
self.hide()
523523
icon_path = "Albayan.ico"

ui/sura_player_ui/sura_player_ui.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from utils.audio_player import SurahPlayer
1818
from utils.universal_speech import UniversalSpeech
1919
from utils.user_data import PreferencesManager
20-
from utils.settings import SettingsManager
20+
from utils.settings import Config
21+
2122
from.menubar import MenuBar
2223
from .key_handler import KeyHandler
2324
from .audio_looper import AudioLooper
@@ -339,13 +340,16 @@ def previous_reciter(self):
339340
def increase_volume(self):
340341
self.player.increase_volume()
341342
volume = int(self.player.volume * 100)
342-
SettingsManager.write_settings({"audio": {"surah_volume_level": volume}})
343+
Config.audio.surah_volume_level = volume
344+
Config.save_settings()
345+
343346

344347
def decrease_volume(self):
345348
self.player.decrease_volume()
346349
volume = int(self.player.volume * 100)
347-
SettingsManager.write_settings({"audio": {"surah_volume_level": volume}})
348-
350+
Config.audio.surah_volume_level = volume
351+
Config.save_settings()
352+
349353
def update_volume(self):
350354
self.player.set_volume(self.volume_slider.value())
351355

0 commit comments

Comments
 (0)