Ejemplo n.º 1
0
 def save_book(self, *a):
     page_dict = {}
     res = asm_customs.sure(self.parent, 'هل أكملت جميع التغييرات المبتغاة وتريد الحفظ؟')
     if res == Gtk.ResponseType.YES:
         self.db.cur.execute("BEGIN;")
         self.db.cur.execute('ATTACH ? as f',(self.new_book,))
         for tb in asm_customs.schema.keys():
             self.db.cur.execute('CREATE TABLE IF NOT EXISTS f.{} ({})'.format(tb, asm_customs.schema[tb]))
         for i in ['main', 'shorts', 'shrooh', 'com']:
             self.db.cur.execute("INSERT INTO f.{} SELECT * FROM main.{}".format(i,i))
         pg = 0
         while pg in range(len(self.all_pages)):
             if self.all_pages[pg][0] <= len(self.db.list_pages):
                 all_in_page = self.db.get_text_body(self.all_pages[pg][0])
                 text = all_in_page[2]
                 hno, sora, aya, na = all_in_page[5:]
             else: 
                 text = u''
                 hno, sora, aya, na = [0, 0, 0, 0]
             if self.all_pages[pg][0] in self.modified_pages.keys():
                 text = self.modified_pages[self.all_pages[pg][0]]
             part, page = self.all_pages[pg][1], self.all_pages[pg][2]
             self.db.cur.execute('INSERT INTO f.pages VALUES (?, ?, ?, ?, ?, ?, ?, ?)', 
                                 (pg+1, text, part, page, hno, sora, aya, na))
             page_dict[self.all_pages[pg][0]] = pg+1
             pg += 1
         for ti in self.store_index:
             try: self.db.cur.execute('INSERT INTO f.titles VALUES (?, ?, ?, ?)', 
                                      (page_dict[ti[0]], ti[1].strip(), ti[1].count('      ')+1, 0))
             except: continue
         self.db.con.commit()
         self.db.cur.execute('DETACH f')
         os.unlink(self.book)
         os.rename(self.new_book, self.book)
Ejemplo n.º 2
0
 def editbk_cb(self, *a):
     msg = asm_customs.sure(self.parent, 'عملية تعديل الكتاب عملية دقيقة،\nأي خطأ قد يؤدي لتلف الكتاب،\nهل تريد الاستمرار؟')
     if msg == Gtk.ResponseType.YES:         
         self.parent.editbook.close_db()
         book = self.db_list.file_book(self.id_book)
         self.parent.editbook.add_book(book, self.id_book, self.all_in_page[1])
         self.parent.notebook.set_current_page(7)
Ejemplo n.º 3
0
 def remove_iters(self, *a):
     res_self = asm_customs.sure(self, " هل ترغب في حذف جميع النتائج الموجودة ؟")
     if res_self:
         for a in self.list_n:
             if a[-4:] == '.pkl':
                 os.remove(join(asm_path.HOME_DIR, a))
         self.store_sav.clear()
Ejemplo n.º 4
0
 def remove_iter(self, *a):
     (model, i) = self.tree_sav.get_selection().get_selected()
     if i :
         res_self = asm_customs.sure(self, " هل ترغب في حذف النتيجة المحددة ؟")
         if res_self:
             nm = model.get_value(i,0)
             os.remove(join(asm_path.HOME_DIR, nm+'.pkl'))
             self.store_sav.remove(i)
Ejemplo n.º 5
0
 def remove_all(self, *a):
     msg = asm_customs.sure(self.parent, "هل تريد مسح جميع أوراق البحث")
     if msg == Gtk.ResponseType.YES:
         list_n = os.listdir(join(asm_path.LIBRARY_DIR_rw, u"waraka-search"))
         for v in list_n:
             os.remove(join(asm_path.LIBRARY_DIR_rw, u"waraka-search", v))
         self.store_waraka.clear()
         self.edit_html.set_sensitive(False)
         self.edit_html.clear_page()
Ejemplo n.º 6
0
 def remove_one(self, *a):
     model, i = self.tree_waraka.get_selection().get_selected()
     if i:
         msg = asm_customs.sure(self.parent, "هل تريد مسح الورقة المحددة")
         if msg == Gtk.ResponseType.YES:
             waraka = model.get_value(i, 0)
             os.remove(join(asm_path.LIBRARY_DIR_rw, u"waraka-search", waraka))
             model.remove(i)
             self.edit_html.set_sensitive(False)
Ejemplo n.º 7
0
 def rm_fav_one(self, *a):
     model, i = self.sel_favorite.get_selected()
     if i:
         msg = asm_customs.sure(self.parent, "هل تريد مسح الكتاب المحدد من المفضلة")
         if msg == Gtk.ResponseType.YES:
             id_book = model.get_value(i,0)
             check = self.db.out_favorite(id_book)
             if check == None:
                 model.remove(i)
Ejemplo n.º 8
0
 def edit_tafsir_cb(self, *a):
     book = self.db.file_book(self.id_book)
     info = self.db.info_book(book)
     if info[8] != 1:
         msg = asm_customs.sure(self.parent, 'هذا الكتاب ليس تفسيرا هل تريد جعله كذلك')
         if msg == Gtk.ResponseType.YES:
             self.db.make_tafsir(book, self.id_book)
         else:
             return
     EditTafsir(self.parent, self.id_book)
Ejemplo n.º 9
0
 def out_tafsir(self, *a):
     model, i = self.sel_tafsir_no_added.get_selected()
     if i:
         nm = model.get_value(i, 1)
         msg = asm_customs.sure(self.parent, 'هل تريد إزالة {} من القائمة؟'.format(nm, ))
         if msg == Gtk.ResponseType.YES:
             id_tafsir = model.get_value(i, 0)
             tafsir = self.db.file_book(id_tafsir)
             self.db.out_tafsir(tafsir, id_tafsir)
             model.remove(i)
     else:
         asm_customs.info(self.parent, "يجب تعليم التفسير في قائمة التفاسير المهملة\n ليتم إزالته منها")
Ejemplo n.º 10
0
 def remove_book(self,*a):
     model0, i0 = self.sel_group.get_selected()
     nm_group = model0.get_value(i0, 1)
     model, i = self.sel_book.get_selected()
     if i:
         id_book = model.get_value(i, 0)
         nm_book = model.get_value(i, 1)
         msg = asm_customs.sure(self.parent, u'''
         سيتم حذف كتاب "{}"
         هل تريد الاستمرار ؟
         '''.format(nm_book,))
         if msg == Gtk.ResponseType.YES:
             check = self.db.remove_book(id_book)
             if check == None:
                 unlink(join(asm_path.BOOK_DIR_rw, nm_group, nm_book+u'.asm'))
                 self.ok_group()
Ejemplo n.º 11
0
 def remove_group(self,*a):
     model, i = self.sel_group.get_selected()
     id_group = model.get_value(i, 0)
     nm_group = model.get_value(i, 1)
     if self.db.check_books_part(id_group) == True:
         asm_customs.erro(self.parent, 'لا يمكن حذف هذا القسم\nلأن بعض كتبه للقراءة فقط')
         return
     if i:
         msg = asm_customs.sure(self.parent, u'''
         سيتم حذف قسم "{}"
         مع جميع كتبه، هل تريد الاستمرار ؟
         '''.format(nm_group,))
         if msg == Gtk.ResponseType.YES:
             check = self.db.remove_group(id_group)
             if check == None:
                 rmtree(join(asm_path.BOOK_DIR_rw, nm_group))
                 self.refresh_groups()
Ejemplo n.º 12
0
 def import_docs(self, *a):
     self.no_add = u""
     if len(self.store_add_doc) == 0:
         return
     id_group = asm_customs.value_active(self.groups_doc)
     nm_group = asm_customs.value_active(self.groups_doc, 1)
     self.progress.set_fraction(0.0)
     self.btn_clear_doc.set_sensitive(False)
     self.btn_convert.set_sensitive(False)
     self.btn_remove_doc.set_sensitive(False)
     self.btn_add_doc.set_sensitive(False)
     if not self.is_book_radio.get_active():
         new_book = self.name_book_entry.get_text()
         if new_book == u"":
             asm_customs.info(self, "ضع اسما للكتاب المراد استيراده")
             return
         list_page = []
         list_title = []
         id_page = 1
     n_docs = len(self.store_add_doc)
     f = 0
     self.no_add = u""
     while len(self.store_add_doc) > 0:
         f += 1
         self.progress.set_fraction(float(f) / float(n_docs))
         while Gtk.events_pending():
             Gtk.main_iteration()
         if self.is_book_radio.get_active():
             new_book = re.sub(u"\....?.?$", u"", self.store_add_doc[0][1])
             text_book = self.get_text_from_file(self.store_add_doc[0][0], self.store_add_doc[0][1])
             if text_book != None and len(text_book) != 0:
                 pages = self.split_text_to_pages(text_book)
                 list_page = []
                 for a in range(len(pages)):
                     list_page.append([a + 1, pages[a], 1, a + 1])
                 list_title = [[1, new_book, 1, 0]]
                 self.make_book(new_book, id_group, nm_group, list_page, list_title)
         elif self.is_part_radio.get_active():
             text_book = self.get_text_from_file(self.store_add_doc[0][0], self.store_add_doc[0][1])
             if text_book != None and len(text_book) != 0:
                 pages = self.split_text_to_pages(text_book)
                 for a in range(len(pages)):
                     list_page.append([id_page, pages[a], f, a + 1])
                     id_page += 1
                 list_title.append([id_page - len(pages), u"الجزء {}".format(f), 1, 0])
         else:
             text_book = self.get_text_from_file(self.store_add_doc[0][0], self.store_add_doc[0][1])
             if text_book != None and len(text_book) != 0:
                 list_page.append([f, text_book, 1, f])
         i = self.store_add_doc.get_iter_first()
         self.store_add_doc.remove(i)
     if not self.is_book_radio.get_active():
         if list_title == []:
             list_title = [[1, new_book, 1, 0]]
         if self.no_add != u"":
             msg = asm_customs.sure(
                 self,
                 u"""
             عدد الملفات التي لم يتمكن من إضافتها هو {}
             هل تريد الاستمرار في تكوين الكتاب ؟
             """.format(
                     len(self.no_add.split("\n"))
                 ),
             )
             if msg == Gtk.ResponseType.YES:
                 self.make_book(new_book, id_group, nm_group, list_page, list_title)
     self.progress.set_text("انتهى !!")
     self.progress.set_fraction(1.0)
     self.btn_clear_doc.set_sensitive(True)
     self.btn_convert.set_sensitive(True)
     self.btn_remove_doc.set_sensitive(True)
     self.btn_add_doc.set_sensitive(True)
     if self.no_add != u"":
         asm_customs.erro(self, u"الملفات التي لم يتم إضافتها {}".format(self.no_add))
Ejemplo n.º 13
0
 def rm_last_all(self, *a):
     msg = asm_customs.sure(self.parent, "هل تريد مسح قائمة الكتب المفتوحة أخيرا")
     if msg == Gtk.ResponseType.YES:
         remove(join(asm_path.DATA_DIR_rw, u'last-books.pkl'))
         self.last_books = []
         self.store_last.clear()