Skip to content

Commit

Permalink
Passed file name to save dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
MahmoudAtef999 committed Jun 8, 2024
1 parent 1eafe1c commit 8ed7127
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 6 additions & 11 deletions ui/dialogs/tafaseer_Dialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from PyQt6.QtWidgets import (
QWidget,
QHBoxLayout,
Expand All @@ -14,8 +15,7 @@
from ui.widgets.qText_edit import ReadOnlyTextEdit
from core_functions.tafaseer import TafaseerManager, Category
from utils.universal_speech import UniversalSpeech
import os

from utils.const import albayan_documents_dir


class TafaseerDialog(QDialog):
Expand Down Expand Up @@ -97,19 +97,14 @@ def copy_content(self):
clipboard.setText(copied_content)
UniversalSpeech.say("تم نسخ التفسير.")

def save_content(self):
# Get the path to the Documents directory
documents_dir = os.path.join(os.path.expanduser("~"), "Documents")
albayan_dir = os.path.join(documents_dir, "Albayan")

# Create the Albayan directory if it does not exist
if not os.path.exists(albayan_dir):
os.makedirs(albayan_dir)
def save_content(self):

file_name = os.path.join(albayan_documents_dir, self.windowTitle())
# Open the file dialog in the Albayan directory
file_path, _ = QFileDialog.getSaveFileName(
self, "Save File", albayan_dir, "Text files (*.txt)"
self, "Save File", file_name, "Text files (*.txt)",
)

if file_path:
with open(file_path, "w") as file:
file.write(self.text_edit.toPlainText())
4 changes: 4 additions & 0 deletions utils/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
temp_folder = os.path.join(os.getenv("TEMP"), "albayan")
os.makedirs(temp_folder, exist_ok=True)

# Get the path to the Documents directory
albayan_documents_dir = os.path.join(os.path.expanduser("~"), "Documents", "Albayan")
os.makedirs(albayan_documents_dir, exist_ok=True)

# program information
program_name = "البيان"
program_version = "1.0.0"
Expand Down

0 comments on commit 8ed7127

Please sign in to comment.