def show_tafsir(self, tafsir, sura, aya): self.aya_now = aya self.db = bookDB(asm_path.TAFSIR_DB, -1) if tafsir != None: if tafsir != -1: self.db.close_db() del self.db book = self.listbook.file_book(tafsir) self.db = bookDB(book, tafsir) id_page = self.db.page_ayat(sura, aya) self.show_page(id_page)
def search_in_result(self, *a): text = self.sav_result_entry.get_text() if text == u"": asm_customs.erro(self.parent, "أدخل كلمة للبحث أولا.") return sr = ShowResult(self.parent) self.parent.viewerbook.append_page(sr, TabLabel(sr, u"بحث عن :" + text)) self.parent.viewerbook.set_current_page(-1) n = 0 s = 0 for a in self.store_results: while Gtk.events_pending(): Gtk.main_iteration() n += 1 if self.stop_n == 0: break book = self.db_list.file_book(a[6]) db = bookDB(book, a[6]) res = db.search_in_page(a[0], text) if res == True: s += 1 sr.store_results.append([a[0], s, a[2], a[3], a[4], a[5], a[6]]) sr.progress.set_fraction(float(n) / (float(len(self.store_results)))) sr.lab_n_result.set_text("عدد النتائج : {}".format(s)) sr.progress.set_fraction(0.0) sr.hb_stop.hide() if len(sr.store_results) > 0: for a in sr.store_results: sr.results_books.append([a[0], a[1], a[2], a[3], a[4], a[5], a[6]]) output = open(join(asm_path.HOME_DIR, u"آخر بحث.pkl"), "wb") pickle.dump(sr.results_books, output) output.close()
def search_in_index(self, id_book, text, dict_perf, dict_field, limit): from Asmaa.asm_indexer import SearchIndexed search_in_indexed = SearchIndexed() filebook = self.db_list.file_book(id_book) db = bookDB(filebook, id_book) results = search_in_indexed.search_in_book(id_book, text, dict_perf, dict_field, limit) print len(results) for a in results: print db.get_text_body(a["page"])[3], db.get_text_body(a["page"])[4]
def show_result(self, *a): model, i = self.sel_result.get_selected() if i: if self.db != None: self.db.close_db() del self.db id_page = model.get_value(i, 0) self.id_book = model.get_value(i, 6) self.book = self.db_list.file_book(self.id_book) self.nm_book = model.get_value(i, 2) self.db = bookDB(self.book, self.id_book) self.show_page(id_page)
def __init__(self, parent, book, id_book): Gtk.VBox.__init__(self, False, 3) self.db_list = listDB() self.parent = parent self.othman = Othman() self.id_book = id_book self.book = book self.nm_book = basename(book)[:-4] self.db = bookDB(book, id_book) self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) self.current_id = 1 self.opened_new = [] self.opened_old = [] self.build()
def add_book(self, book, id_book, id_page): self.current_id = id_page-1 self.modified_pages = {} self.opened_new = [] self.opened_old = [] self.id_book = id_book self.book = book self.new_book = book+u'.new' self.nm_book = basename(book)[:-4] self.db = bookDB(book, id_book) self.all_pages = self.db.all_page() self.n_all_page = len(self.all_pages)+1 self.set_index() self.show_page(id_page) try: self.store_index.foreach(self.index_highlight, id_page) except: pass
def start_indexation(self, *a): self.btn_index_start.set_sensitive(False) writer = self.creat_writer_index('my_index') s = 0 for id_book in self.selected_books: s += 1 self.progress.set_fraction(float(s)/float(len(self.selected_books))) filebook = self.db.file_book(id_book) db = bookDB(filebook, id_book) for a in db.all_page(): title = "-".join(db.titles_page(a[0])) if title == "": title = "-" content = db.get_text_body(a[0])[2] page = str(a[0]) book = str(id_book) writer.add_document(book=book, title=title, content=content, page=page) print (s) self.db.add_indexed(id_book) writer.commit() asm_customs.info(self, "تمت عملية الفهرسة") self.destroy()
def __init__(self, parent, id_book): self.parent = parent self.listdb = listDB() book = self.listdb.file_book(id_book) self.db = bookDB(book, id_book) self.othman = Othman() Gtk.Dialog.__init__(self, parent=self.parent) self.set_icon_name("asmaa") self.resize(750, 450) self.set_modal(True) self.set_title(u'تعديل تفسير : {}'.format(self.db.book_name,)) self.connect('destroy', self.quit_dlg) box = self.vbox box.set_border_width(5) # a عارض النص----------------------------------- self.view_nasse = asm_customs.ViewClass() self.view_nasse_bfr = self.view_nasse.get_buffer() self.view_quran_tag = self.view_nasse_bfr.create_tag("quran") self.view_quran_tag.set_property('foreground', self.parent.theme.color_qrn) self.view_quran_tag.set_property("paragraph-background", self.parent.theme.color_bg_qrn) self.view_quran_tag.set_property('font', self.parent.theme.font_qrn) self.scroll_nasse = Gtk.ScrolledWindow() self.scroll_nasse.set_shadow_type(Gtk.ShadowType.IN) self.scroll_nasse.add(self.view_nasse) box.pack_start(self.scroll_nasse, True, True, 0) box.pack_start(Gtk.HSeparator(), False, False, 3) hb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.HORIZONTAL) self.lab_id_pg = Gtk.Label('جزء 1 ، صفحة 1') hb.pack_start(self.lab_id_pg, False, False, 3) adj = Gtk.Adjustment(1, 1, len(self.db.list_pages), 1, 5.0, 0.0) self.id_pg = Gtk.SpinButton() self.id_pg.connect('changed', self.change_id_pg) self.id_pg.set_adjustment(adj) lab = Gtk.Label('معرف الصفحة') self.id_pg.set_wrap(True) self.id_pg.set_size_request(100, -1) hb.pack_end(self.id_pg, False, False, 0) hb.pack_end(lab, False, False, 0) box.pack_start(hb, False, False, 3) box.pack_start(Gtk.HSeparator(), False, False, 3) hb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.HORIZONTAL) sura_list = self.othman.get_suras_names() hb0, self.suras = asm_customs.combo(sura_list, u'السورة') hb.pack_start(hb0, False, False, 3) self.suras.set_active(-1) adj = Gtk.Adjustment(0, 0, 0, 1, 5.0, 0.0) self.n_ayas = Gtk.SpinButton() self.n_ayas.set_adjustment(adj) lab = Gtk.Label('عدد الآيات') self.n_ayas.set_wrap(True) self.n_ayas.set_size_request(100, -1) hb.pack_end(self.n_ayas, False, False, 0) hb.pack_end(lab, False, False, 0) adj = Gtk.Adjustment(0, 0, 0, 1, 5.0, 0.0) self.ayas = Gtk.SpinButton() self.ayas.set_adjustment(adj) lab = Gtk.Label('أول آية') self.ayas.set_wrap(True) self.ayas.set_size_request(100, -1) hb.pack_end(self.ayas, False, False, 0) hb.pack_end(lab, False, False, 0) box.pack_start(hb, False, False, 3) hbox = Gtk.Box(spacing=5,orientation=Gtk.Orientation.HORIZONTAL) save_btn = asm_customs.ButtonClass("غيّر") save_btn.set_tooltip_text('ثبت السورة والآيات للصفحة الحالية') save_btn.connect('clicked', self.save_cb) hbox.pack_start(save_btn, False, False, 0) no_save_btn = asm_customs.ButtonClass("أخل") no_save_btn.set_tooltip_text('ألغ ربط الصفحة الحالية بالآيات') no_save_btn.connect('clicked', self.no_save_cb) hbox.pack_start(no_save_btn, False, False, 0) clo = asm_customs.ButtonClass("إغلاق") clo.connect('clicked', self.quit_dlg) hbox.pack_end(clo, False, False, 0) box.pack_end(hbox, False, False, 0) box.pack_end(Gtk.HSeparator(), False, False, 3) self.suras.connect('changed', self.select_sura) self.show_all()
def search_in_index(self, id_book, text, dict_perf, dict_field, limit): from Asmaa.asm_indexer import SearchIndexed search_in_indexed = SearchIndexed() filebook = self.db_list.file_book(id_book) db = bookDB(filebook, id_book) results = search_in_indexed.search_in_book(id_book, text, dict_perf, dict_field, limit)