|
| 1 | +from PyQt6.QtWidgets import ( |
| 2 | + QApplication, QDialog, QVBoxLayout, QHBoxLayout, QLineEdit, |
| 3 | + QComboBox, QListWidget, QPushButton, QMenu, QLabel, QGridLayout |
| 4 | +) |
| 5 | +from PyQt6.QtCore import Qt |
| 6 | +import sys |
| 7 | + |
| 8 | + |
| 9 | +class DownloadVersesDialog(QDialog): |
| 10 | + def __init__(self, parent=None): |
| 11 | + super().__init__(parent) |
| 12 | + self.setWindowTitle("تنزيل آيات") |
| 13 | + self.setAccessibleName("نافذة تنزيل آيات") |
| 14 | + |
| 15 | + layout = QVBoxLayout() |
| 16 | + grid = QGridLayout() |
| 17 | + |
| 18 | + self.reader_combo = QComboBox() |
| 19 | + self.reader_combo.addItems(["القارئ 1", "القارئ 2"]) |
| 20 | + grid.addWidget(QLabel("القارئ:"), 0, 0) |
| 21 | + grid.addWidget(self.reader_combo, 0, 1) |
| 22 | + |
| 23 | + self.from_surah_combo = QComboBox() |
| 24 | + self.from_surah_combo.addItems(["الفاتحة", "البقرة", "آل عمران"]) |
| 25 | + grid.addWidget(QLabel("من السورة:"), 1, 0) |
| 26 | + grid.addWidget(self.from_surah_combo, 1, 1) |
| 27 | + |
| 28 | + self.from_ayah_combo = QComboBox() |
| 29 | + self.from_ayah_combo.addItems([str(i) for i in range(1, 21)]) |
| 30 | + grid.addWidget(QLabel("من الآية:"), 2, 0) |
| 31 | + grid.addWidget(self.from_ayah_combo, 2, 1) |
| 32 | + |
| 33 | + self.to_surah_combo = QComboBox() |
| 34 | + self.to_surah_combo.addItems(["الفاتحة", "البقرة", "آل عمران"]) |
| 35 | + grid.addWidget(QLabel("إلى السورة:"), 3, 0) |
| 36 | + grid.addWidget(self.to_surah_combo, 3, 1) |
| 37 | + |
| 38 | + self.to_ayah_combo = QComboBox() |
| 39 | + self.to_ayah_combo.addItems([str(i) for i in range(1, 21)]) |
| 40 | + grid.addWidget(QLabel("إلى الآية:"), 4, 0) |
| 41 | + grid.addWidget(self.to_ayah_combo, 4, 1) |
| 42 | + |
| 43 | + layout.addLayout(grid) |
| 44 | + |
| 45 | + btn_layout = QHBoxLayout() |
| 46 | + btn_download = QPushButton("تنزيل") |
| 47 | + btn_close = QPushButton("إغلاق") |
| 48 | + btn_close.clicked.connect(self.close) |
| 49 | + btn_layout.addWidget(btn_download) |
| 50 | + btn_layout.addWidget(btn_close) |
| 51 | + |
| 52 | + layout.addLayout(btn_layout) |
| 53 | + self.setLayout(layout) |
| 54 | + |
| 55 | + |
| 56 | +class DownloadSurahsDialog(QDialog): |
| 57 | + def __init__(self, parent=None): |
| 58 | + super().__init__(parent) |
| 59 | + self.setWindowTitle("تنزيل سور") |
| 60 | + self.setAccessibleName("نافذة تنزيل سور") |
| 61 | + |
| 62 | + layout = QVBoxLayout() |
| 63 | + grid = QGridLayout() |
| 64 | + |
| 65 | + self.reader_combo = QComboBox() |
| 66 | + self.reader_combo.addItems(["القارئ 1", "القارئ 2"]) |
| 67 | + grid.addWidget(QLabel("القارئ:"), 0, 0) |
| 68 | + grid.addWidget(self.reader_combo, 0, 1) |
| 69 | + |
| 70 | + self.from_surah_combo = QComboBox() |
| 71 | + self.from_surah_combo.addItems(["الفاتحة", "البقرة", "آل عمران"]) |
| 72 | + grid.addWidget(QLabel("من السورة:"), 1, 0) |
| 73 | + grid.addWidget(self.from_surah_combo, 1, 1) |
| 74 | + |
| 75 | + self.to_surah_combo = QComboBox() |
| 76 | + self.to_surah_combo.addItems(["الفاتحة", "البقرة", "آل عمران"]) |
| 77 | + grid.addWidget(QLabel("إلى السورة:"), 2, 0) |
| 78 | + grid.addWidget(self.to_surah_combo, 2, 1) |
| 79 | + |
| 80 | + layout.addLayout(grid) |
| 81 | + |
| 82 | + btn_layout = QHBoxLayout() |
| 83 | + btn_download = QPushButton("تنزيل") |
| 84 | + btn_close = QPushButton("إغلاق") |
| 85 | + btn_close.clicked.connect(self.close) |
| 86 | + btn_layout.addWidget(btn_download) |
| 87 | + btn_layout.addWidget(btn_close) |
| 88 | + |
| 89 | + layout.addLayout(btn_layout) |
| 90 | + self.setLayout(layout) |
| 91 | + |
| 92 | + |
| 93 | +class MainDialog(QDialog): |
| 94 | + def __init__(self): |
| 95 | + super().__init__() |
| 96 | + self.setWindowTitle("إدارة التنزيلات") |
| 97 | + self.setAccessibleName("نافذة إدارة التنزيلات") |
| 98 | + |
| 99 | + layout = QVBoxLayout() |
| 100 | + |
| 101 | + # مربع البحث + الفلتر |
| 102 | + top_layout = QHBoxLayout() |
| 103 | + self.search_box = QLineEdit() |
| 104 | + self.search_box.setPlaceholderText("بحث...") |
| 105 | + self.search_box.setAccessibleName("مربع البحث") |
| 106 | + |
| 107 | + self.filter_combo = QComboBox() |
| 108 | + self.filter_combo.addItems(["الكل", "قيد التنزيل", "المكتمل"]) |
| 109 | + self.filter_combo.setAccessibleName("فلتر العرض") |
| 110 | + |
| 111 | + top_layout.addWidget(self.search_box) |
| 112 | + top_layout.addWidget(self.filter_combo) |
| 113 | + layout.addLayout(top_layout) |
| 114 | + |
| 115 | + # القائمة |
| 116 | + self.list_widget = QListWidget() |
| 117 | + self.list_widget.setAccessibleName("قائمة العناصر") |
| 118 | + self.list_widget.addItems([ |
| 119 | + "عنصر 1 - مكتمل", |
| 120 | + "عنصر 2 - قيد التنزيل", |
| 121 | + "عنصر 3 - مكتمل", |
| 122 | + "عنصر 4 - قيد التنزيل" |
| 123 | + ]) |
| 124 | + self.list_widget.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
| 125 | + self.list_widget.customContextMenuRequested.connect(self.show_context_menu) |
| 126 | + layout.addWidget(self.list_widget) |
| 127 | + |
| 128 | + # الأزرار |
| 129 | + btn_layout = QHBoxLayout() |
| 130 | + self.btn_download = QPushButton("تنزيل") |
| 131 | + self.btn_delete = QPushButton("حذف") |
| 132 | + self.btn_close = QPushButton("إغلاق") |
| 133 | + |
| 134 | + self.btn_download.clicked.connect(self.show_download_menu) |
| 135 | + self.btn_delete.clicked.connect(self.show_delete_menu) |
| 136 | + self.btn_close.clicked.connect(self.close) |
| 137 | + |
| 138 | + btn_layout.addWidget(self.btn_download) |
| 139 | + btn_layout.addWidget(self.btn_delete) |
| 140 | + btn_layout.addWidget(self.btn_close) |
| 141 | + layout.addLayout(btn_layout) |
| 142 | + |
| 143 | + self.setLayout(layout) |
| 144 | + |
| 145 | + def show_context_menu(self, pos): |
| 146 | + menu = QMenu(self) |
| 147 | + delete_action = menu.addAction("حذف العنصر المحدد") |
| 148 | + delete_action.triggered.connect(self.delete_selected_item) |
| 149 | + |
| 150 | + download_menu = menu.addMenu("تنزيل") |
| 151 | + download_menu.addAction("تنزيل سور", self.open_download_surahs) |
| 152 | + download_menu.addAction("تنزيل آيات", self.open_download_verses) |
| 153 | + |
| 154 | + menu.exec(self.list_widget.mapToGlobal(pos)) |
| 155 | + |
| 156 | + def delete_selected_item(self): |
| 157 | + current_row = self.list_widget.currentRow() |
| 158 | + if current_row >= 0: |
| 159 | + self.list_widget.takeItem(current_row) |
| 160 | + |
| 161 | + def show_delete_menu(self): |
| 162 | + menu = QMenu(self) |
| 163 | + menu.addAction("حذف الكل", self.delete_all) |
| 164 | + menu.addAction("حذف المكتمل", lambda: self.delete_by_filter("المكتمل")) |
| 165 | + menu.addAction("حذف غير المكتمل", lambda: self.delete_by_filter("قيد التنزيل")) |
| 166 | + menu.exec(self.btn_delete.mapToGlobal(self.btn_delete.rect().bottomLeft())) |
| 167 | + |
| 168 | + def delete_all(self): |
| 169 | + self.list_widget.clear() |
| 170 | + |
| 171 | + def delete_by_filter(self, filter_text): |
| 172 | + for i in reversed(range(self.list_widget.count())): |
| 173 | + item_text = self.list_widget.item(i).text() |
| 174 | + if filter_text in item_text: |
| 175 | + self.list_widget.takeItem(i) |
| 176 | + |
| 177 | + def show_download_menu(self): |
| 178 | + menu = QMenu(self) |
| 179 | + menu.addAction("تنزيل سور", self.open_download_surahs) |
| 180 | + menu.addAction("تنزيل آيات", self.open_download_verses) |
| 181 | + menu.exec(self.btn_download.mapToGlobal(self.btn_download.rect().bottomLeft())) |
| 182 | + |
| 183 | + def open_download_surahs(self): |
| 184 | + dlg = DownloadSurahsDialog(self) |
| 185 | + dlg.exec() |
| 186 | + |
| 187 | + def open_download_verses(self): |
| 188 | + dlg = DownloadVersesDialog(self) |
| 189 | + dlg.exec() |
| 190 | + |
| 191 | + |
| 192 | +if __name__ == "__main__": |
| 193 | + app = QApplication(sys.argv) |
| 194 | + app.setLayoutDirection(Qt.LayoutDirection.RightToLeft) # دعم الاتجاه العربي |
| 195 | + dlg = MainDialog() |
| 196 | + dlg.resize(500, 400) |
| 197 | + dlg.show() |
| 198 | + sys.exit(app.exec()) |
0 commit comments