Exemple #1
0
 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()
Exemple #2
0
 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()
Exemple #3
0
class EditTafsir(Gtk.Dialog):
    
    def quit_dlg(self, *a):
        self.destroy()
        self.db.close_db()
        del self.db
    
    def save_cb(self, *a):
        id_page = self.id_pg.get_value()
        sura = self.suras.get_active()+1
        aya = self.ayas.get_value()
        na = self.n_ayas.get_value()
        if sura == 0 or aya == 0 or na == 0: return
        self.db.edit_tafsir(id_page, sura, aya, na)
        self.change_id_pg()
        
    def no_save_cb(self, *a):
        id_page = self.id_pg.get_value()
        #self.suras.set_active(-1)
        #self.ayas.set_value(0)
        #self.n_ayas.set_value(0)
        self.db.edit_tafsir(id_page, 0, 0, 0)
        self.change_id_pg()
    
    def is_tafsir(self, all_in_page):
        try: sora, aya, na = all_in_page[6], all_in_page[7], all_in_page[8]
        except: sora = 0
        if sora > 0 and sora < 115:
            try: na = int(na)
            except: na = 1
            nasse_quran = ' '.join(self.othman.get_ayat(sora,aya,aya+na))
            self.view_nasse_bfr.insert(self.view_nasse_bfr.get_start_iter(), u" \n")
            self.view_nasse_bfr.insert_with_tags(self.view_nasse_bfr.get_start_iter(), 
                                                 nasse_quran, self.view_quran_tag)
    
    def change_id_pg(self, *a):
        page_id = self.id_pg.get_value()
        all_in_page = self.db.get_text_body(page_id)
        self.lab_id_pg.set_text(u'جزء {} ، صفحة {}'.format(all_in_page[3], all_in_page[4]))
        try:
            if all_in_page[6] != 0:
                self.suras.set_active(int(all_in_page[6])-1)
                self.ayas.set_value(int(all_in_page[7]))
                self.n_ayas.set_value(int(all_in_page[8]))
        except:
            pass
        self.view_nasse_bfr.set_text(all_in_page[2])
        self.is_tafsir(all_in_page)
        self.scroll_nasse.get_vadjustment().set_value(0.0)
    
    def select_sura(self, w):
        if self.suras.get_active() == -1: return
        ayat = asm_customs.value_active(w, 2)
        adj = self.ayas.get_adjustment()
        adj.set_upper(ayat)
        adj.set_value(1)
        adj = self.n_ayas.get_adjustment()
        adj.set_upper(ayat)
        adj.set_value(1)
    
    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()
Exemple #4
0
class OpenBook(Gtk.VBox):
    
    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 set_tashkil(self, *a):
        self.show_page(self.all_in_page[1])
        if asm_config.getn('tashkil') == 0: now_text = asm_araby.stripHarakat(self.all_in_page[2])
        else: now_text = self.all_in_page[2]
        ch = self.stack.get_visible_child_name()
        if ch == "n1": 
            self.view_nasse_bfr1.set_text(now_text)
            self.view_nasse_bfr1.insert(self.view_nasse_bfr1.get_end_iter(), " \n")
        else:
            self.view_nasse_bfr2.set_text(now_text)
            self.view_nasse_bfr2.insert(self.view_nasse_bfr2.get_end_iter(), " \n")
    
    def show_bitaka(self, *a):
        box = Gtk.Box(spacing=5,orientation=Gtk.Orientation.VERTICAL)
        bitaka_book = self.db.info_book()[3]
        info_book = self.db.info_book()[4]
        dlg = Gtk.Dialog(parent=self.parent)
        dlg.set_icon_name("asmaa")
        dlg.set_default_size(450, 300)
        area = dlg.get_content_area()
        area.set_spacing(6)
        
        hb_bar = Gtk.HeaderBar()
        hb_bar.set_show_close_button(True)
        dlg.set_titlebar(hb_bar)
        stack = Gtk.Stack()
        stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
        stack.set_transition_duration(1000)
        stack_switcher = Gtk.StackSwitcher()
        stack_switcher.set_stack(stack)
        hb_bar.set_custom_title(stack_switcher)

        view_info = asm_customs.ViewBitaka()
        view_info_bfr = view_info.get_buffer()
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.add(view_info)
        stack.add_titled(scroll, 'n1',' بطاقة')
        view_info_bfr.set_text(bitaka_book)
        
        view_info1 = asm_customs.ViewBitaka()
        view_info_bfr1 = view_info1.get_buffer()
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.add(view_info1)
        stack.add_titled(scroll, 'n2', 'نبذة')
        view_info_bfr1.set_text(info_book)
        
        box.pack_start(stack, True, True, 0)
        area.pack_start(box, True, True, 0)
        dlg.show_all()
    
    def change_font(self, *a):
        self.view_title_tag1.set_property('foreground', self.parent.theme.color_tit)
        self.view_title_tag1.set_property('font', self.parent.theme.font_tit)
        self.view_quran_tag1.set_property('foreground', self.parent.theme.color_qrn)
        self.view_quran_tag1.set_property("paragraph-background", self.parent.theme.color_bg_qrn)
        self.view_quran_tag1.set_property('font', self.parent.theme.font_qrn)
        self.view_search_tag1.set_property('background', self.parent.theme.color_fnd)
        self.view_terms_tag1.set_property('foreground', self.parent.theme.color_tit)
        self.view_title_tag2.set_property('foreground', self.parent.theme.color_tit)
        self.view_title_tag2.set_property('font', self.parent.theme.font_tit)
        self.view_quran_tag2.set_property('foreground', self.parent.theme.color_qrn)
        self.view_quran_tag2.set_property("paragraph-background", self.parent.theme.color_bg_qrn)
        self.view_quran_tag2.set_property('font', self.parent.theme.font_qrn)
        self.view_search_tag2.set_property('background', self.parent.theme.color_fnd)
        self.view_terms_tag2.set_property('foreground', self.parent.theme.color_tit)
    
    def search_on_active(self, text):
        if text == '': return
        self.store_search.clear()
        self.scroll_index.hide()
        self.scroll_search.show_all()
        phrase = '''fuzzy(nass) LIKE ? ESCAPE "|"'''
        text = asm_araby.fuzzy(text)
        self.search_tokens = asm_araby.tokenize_search(text)
        phrase2 = list(map(lambda phrase: '%'+phrase.replace('|','||').replace('%','|%')+'%', self.search_tokens))
        if len(phrase2) < 1: return []
        condition = ' AND '.join([phrase]*len(phrase2))
        self.db.search(text, self.store_search, condition, phrase2)
        if len(self.store_search) == 0:
            self.hide_search()
            asm_customs.erro(self.parent, 'لا يوجد نتائج')
            return
        self.hp.set_position(200)
        
    def hide_search(self, *a):
        self.scroll_index.show_all()
        self.scroll_search.hide()
        if len(self.list_index) > 1:
            self.hp.set_position(200)
        else:
            self.hp.set_position(1)
        self.entry_index.set_text('')
        
    def search_on_page(self, text):
        self.show_page(self.all_in_page[1])
        self.search_now(text)
        
    def search_now(self, text):
        search_tokens1 = []
        search_tokens2 = []
        star_iter1 = self.view_nasse_bfr1.get_start_iter()
        end_iter1 = self.view_nasse_bfr1.get_end_iter()
        star_iter2 = self.view_nasse_bfr2.get_start_iter()
        end_iter2 = self.view_nasse_bfr2.get_end_iter()
        self.view_nasse_bfr1.remove_tag_by_name("search1", star_iter1, end_iter1)
        self.view_nasse_bfr2.remove_tag_by_name("search2", star_iter2, end_iter2)
        nasse1 = self.view_nasse_bfr1.get_text(star_iter1, end_iter1, True)
        nasse2 = self.view_nasse_bfr2.get_text(star_iter2, end_iter2, True)
        if text == '': 
            return
        else:
            text = text.strip()
            ls_term = asm_araby.fuzzy(text).split(' ')
        for text in ls_term:
            if len(text) == 1 or text == "ال": continue
            new_term = ''
            for l in text:
                new_term += '({}(\u0651)?([\u064b\u064c\u064d\u064e\u064f\u0650\u0652])?)'.format(l, )
            new_term = new_term.replace('ا', '[اأإؤءئى]')
            new_term = new_term.replace('ه', '[هة]')
            re_term = re.compile('({})'.format(new_term,))
            r_findall1 = re_term.findall(nasse1)
            r_findall2 = re_term.findall(nasse2)
            for r in r_findall1:
                if r[0] not in search_tokens1: search_tokens1.append(r[0])
            for r in r_findall2:
                if r[0] not in search_tokens2: search_tokens2.append(r[0])
        asm_customs.with_tag(self.view_nasse_bfr1, self.view_search_tag1, search_tokens1, 1, self.view_nasse1)
        asm_customs.with_tag(self.view_nasse_bfr2, self.view_search_tag2, search_tokens2, 1, self.view_nasse2)


    # a التصفح--------------------------------------------

    def index_highlight(self, model, path, i, page_id):
        pid = model.get(i,0)[0]
        if pid == page_id: 
            self.tree_index.expand_to_path(path)
            self.tree_index.scroll_to_cell(path)
            self.sel_index.select_path(path)
            return True 
        else:
            return False

    def first_page(self, *a):
        self.stack.set_transition_type(self.style_browse_prev)
        if self.db.first_page() == self.all_in_page[1]: return
        self.show_page(self.db.first_page())
        id_page = self.all_in_page[1]
        try: self.store_index.foreach(self.index_highlight, id_page)
        except: pass
        ch = self.stack.get_visible_child_name()
        if ch == "n1": self.stack.set_visible_child_name("n2")
        else: self.stack.set_visible_child_name("n1")
        GObject.timeout_add(200, self.reset_event)
    
    def previous_page(self, *a):
        self.stack.set_transition_type(self.style_browse_prev)
        if self.db.previous_page(self.current_id) == self.all_in_page[1]: return
        self.show_page(self.db.previous_page(self.current_id))
        id_page = self.all_in_page[1]
        try: self.store_index.foreach(self.index_highlight, id_page)
        except: pass
        ch = self.stack.get_visible_child_name()
        if ch == "n1": self.stack.set_visible_child_name("n2")
        else: self.stack.set_visible_child_name("n1")
        GObject.timeout_add(200, self.reset_event)
    
    def next_page(self, *a):
        self.stack.set_transition_type(self.style_browse_next)
        if self.db.next_page(self.current_id) == self.all_in_page[1]: return
        self.show_page(self.db.next_page(self.current_id))
        id_page = self.all_in_page[1]
        try: self.store_index.foreach(self.index_highlight, id_page)
        except: pass
        ch = self.stack.get_visible_child_name()
        if ch == "n1": self.stack.set_visible_child_name("n2")
        else: self.stack.set_visible_child_name("n1")
        GObject.timeout_add(200, self.reset_event)
    
    def last_page(self, *a):
        self.stack.set_transition_type(self.style_browse_next)
        if self.db.last_page() == self.all_in_page[1]: return
        self.show_page(self.db.last_page())
        id_page = self.all_in_page[1]
        try: self.store_index.foreach(self.index_highlight, id_page)
        except: pass
        ch = self.stack.get_visible_child_name()
        if ch == "n1": self.stack.set_visible_child_name("n2")
        else: self.stack.set_visible_child_name("n1")
        GObject.timeout_add(200, self.reset_event)
    
    def back_to_old(self, *a):
        if len(self.opened_old) == 1: return
        n = self.opened_old.pop()
        self.stack.set_transition_type(self.style_browse_prev)
        self.show_page(self.opened_old[-1])
        ch = self.stack.get_visible_child_name()
        if ch == "n1": self.stack.set_visible_child_name("n2")
        else: self.stack.set_visible_child_name("n1")
        self.opened_new.append(n)
        
    def advance_to_new(self, *a):
        if len(self.opened_new) == 0: return
        n = self.opened_new.pop()
        self.stack.set_transition_type(self.style_browse_prev)
        self.show_page(n)
        ch = self.stack.get_visible_child_name()
        if ch == "n1": self.stack.set_visible_child_name("n2")
        else: self.stack.set_visible_child_name("n1")
        if n != self.opened_old[-1]: self.opened_old.append(n)
    
    def set_index(self, *a):
        self.store_index.clear()
        self.list_index = self.db.index_book()
        iters = [None]
        last_iter = None
        last_level = 0
        last_id = self.db_list.get_last(self.id_book)
        if last_id == None or last_id[0] == 0: 
            self.show_page(self.db.first_page()) 
        else:
            self.show_page(last_id[0]) 
        self.stack.set_visible_child_name("n2")
        #-----------------------------------
        if len(self.list_index) > 1:
            self.hp.set_position(200)
        else:
            self.hp.set_position(1)
        v = 0
        for i in self.list_index:
            v += 1
            if v%1000 == 999: 
                while (Gtk.events_pending()): Gtk.main_iteration()
            level = i[3]
            if level > last_level: iters.append(last_iter)
            elif level < last_level:
                for j in range(last_level-level): iters.pop()
            try :
                last_iter = self.store_index.append(iters[-1], [i[1], i[2]])
            except :
                pass
            last_level = level
    
    def ok_index(self, *a):  
        model, i = self.sel_index.get_selected()
        if i:
            p = model.get_path(i)
            if model.iter_has_child(i) :
                if self.tree_index.row_expanded(p):
                    self.tree_index.collapse_row(p)
                else: 
                    self.tree_index.expand_row(p, False)
            id_page = model.get_value(i, 0)
            tit = model.get_value(i, 1)

            if self.current_id < id_page: self.stack.set_transition_type(self.style_browse_next)
            elif self.current_id > id_page: self.stack.set_transition_type(self.style_browse_prev)
            elif self.current_id == id_page: return
            self.show_page(id_page)
            ch = self.stack.get_visible_child_name()
            if ch == "n1": 
                self.stack.set_visible_child_name("n2")
                asm_customs.with_tag(self.view_nasse_bfr1, self.title_select_tag1, [tit,], 0, self.view_nasse1)
            else: 
                self.stack.set_visible_child_name("n1")
                asm_customs.with_tag(self.view_nasse_bfr2, self.title_select_tag2, [tit,], 0, self.view_nasse2)
            GObject.timeout_add(200, self.reset_event)
            
   
    def ok_search(self, *a):  
        model, i = self.sel_search.get_selected()
        if i:
            p = model.get_path(i)
            if model.iter_has_child(i) :
                if self.tree_search.row_expanded(p):
                    self.tree_search.collapse_row(p)
                else: self.tree_search.expand_row(p, False)
            id_page = model.get_value(i, 0)
            
            if self.current_id < id_page: self.stack.set_transition_type(self.style_browse_next)
            elif self.current_id > id_page: self.stack.set_transition_type(self.style_browse_prev)
            elif self.current_id == id_page: return
            self.show_page(id_page)
            ch = self.stack.get_visible_child_name()
            if ch == "n1": 
                self.stack.set_visible_child_name("n2")
            else: 
                self.stack.set_visible_child_name("n1")
    
    def show_page(self, id_page):
        self.all_in_page = self.db.get_text_body(id_page)#rowid, id, text, part, page, hno, sora, aya, na
        if asm_config.getn('tashkil') == 0: now_text = asm_araby.stripHarakat(self.all_in_page[2])
        else: now_text = self.all_in_page[2]
        self.has_commment(id_page)
        titles = self.db.titles_page(self.all_in_page[1])
        ch = self.stack.get_visible_child_name()
        if ch == "n1": 
            self.view_nasse_bfr2.set_text(now_text)
            self.view_nasse_bfr2.insert(self.view_nasse_bfr2.get_end_iter(), " \n")
            try: asm_customs.with_tag(self.view_nasse_bfr2, self.view_title_tag2, titles)
            except: pass 
        else:
            self.view_nasse_bfr1.set_text(now_text)
            self.view_nasse_bfr1.insert(self.view_nasse_bfr1.get_end_iter(), " \n")
            try: asm_customs.with_tag(self.view_nasse_bfr1, self.view_title_tag1, titles)
            except: pass
        self.is_tafsir(self.all_in_page)
        self.current_id = self.all_in_page[0]
        self.ent_page.set_text(str(self.all_in_page[4]))
        self.ent_part.set_text(str(self.all_in_page[3]))
        text = self.parent.entry_search.get_text()
        if len(text) >= 2 and text != "ال": 
            self.search_now(text)
        if len(self.opened_old) == 0: self.opened_old.append(id_page)
        elif id_page != self.opened_old[-1]: self.opened_old.append(id_page)
        self.stack.show_all()
        self.scroll_nasse1.get_vadjustment().set_value(0.0)
        self.scroll_nasse2.get_vadjustment().set_value(0.0)
    
    def reset_event(self, *a):
        self.scroll_nasse1.get_vadjustment().set_lower(True)
        self.scroll_nasse2.get_vadjustment().set_lower(True)
        self.scroll_nasse1.get_vadjustment().set_value(0.0)
        self.scroll_nasse2.get_vadjustment().set_value(0.0)
    
    def scroll_event(self, sc, ev):
        if asm_config.getn('mouse_browse') == 0: return
        vadj = sc.get_vadjustment()
        p = vadj.get_page_size()
        m = vadj.get_upper()-p
        v = vadj.get_value()
        if m == v:
            if self.vadj_page_next == 5:
                self.next_page()
                self.vadj_page_next = 0
            else:
                self.vadj_page_next += 1
        elif v <= 1.0:
            if self.vadj_page_prev == 5:
                if ev.get_scroll_deltas()[2] == -1.0:
                    self.previous_page()
                if ev.get_scroll_deltas()[2] == 1.0:
                    self.next_page()
                self.vadj_page_prev = 0
            else:
                self.vadj_page_prev += 1
        else:
            self.vadj_page_next = 0
            self.vadj_page_prev = 0
    
    def convert_browse(self, *a):
        ls = [1, 2, 5, 10, 15, 20, 30]
        self.stack.set_transition_duration(ls[asm_config.getn('time_browse')]*100)
        GObject.source_remove(self.timeo)
        self.timeo = GLib.timeout_add(100/((asm_config.getn('auto_browse'))*8), self.autoScroll, None)
        if asm_config.getn('style_browse') == 0:
            self.style_browse_next = Gtk.StackTransitionType.NONE
            self.style_browse_prev = Gtk.StackTransitionType.NONE
        elif asm_config.getn('style_browse') == 1:
            self.style_browse_next = Gtk.StackTransitionType.CROSSFADE
            self.style_browse_prev = Gtk.StackTransitionType.CROSSFADE
        elif asm_config.getn('style_browse') == 2:
            self.style_browse_next = Gtk.StackTransitionType.SLIDE_LEFT
            self.style_browse_prev = Gtk.StackTransitionType.SLIDE_RIGHT
        elif asm_config.getn('style_browse') == 3:
            self.style_browse_next = Gtk.StackTransitionType.SLIDE_UP
            self.style_browse_prev = Gtk.StackTransitionType.SLIDE_DOWN 
    
    def has_commment(self, id_page):
        if self.db.show_comment(id_page) != None and self.db.show_comment(id_page) != []:
            img = Gtk.Image.new_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.BUTTON)
        else:
            img = Gtk.Image.new_from_stock(Gtk.STOCK_FILE, Gtk.IconSize.BUTTON)
        self.comment_btn.set_image(img)
        self.comment_btn.show_all()
    
    def is_tafsir(self, all_in_page):
        try: sora, aya, na = int(all_in_page[6]), int(all_in_page[7]), all_in_page[8]
        except: sora = 0
        if sora > 0 and sora < 115:
            try: na = int(na)
            except: na = 1
            nasse_quran = ' '.join(self.othman.get_ayat(sora,aya,aya+na))
            ch = self.stack.get_visible_child_name()
            if ch == "n2":
                self.view_nasse_bfr1.insert(self.view_nasse_bfr1.get_start_iter(), " \n")
                self.view_nasse_bfr1.insert_with_tags(self.view_nasse_bfr1.get_start_iter(), 
                                                 nasse_quran, self.view_quran_tag1)
            else:
                self.view_nasse_bfr2.insert(self.view_nasse_bfr2.get_start_iter(), " \n")
                self.view_nasse_bfr2.insert_with_tags(self.view_nasse_bfr2.get_start_iter(), 
                                                 nasse_quran, self.view_quran_tag2)
    
    #aمؤقت-------------------------------
    def dialog_move_to_page(self, *a):
        dlg = Gtk.Dialog(parent=self.parent)
        dlg.set_icon_name("asmaa")
        dlg.set_position(Gtk.WindowPosition.MOUSE)
        dlg.set_title('انتقل إلى صفحة محدّدة')
        parts_all, pages_all = self.db.parts_pages(self.all_in_page[3])
        ent_page = Gtk.Entry()
        lab_page = Gtk.Label(u"عدد الصفحات "+str(pages_all))
        ent_page.set_text(str(self.all_in_page[4]))
        ent_part = Gtk.Entry()
        lab_part = Gtk.Label(u"عدد الأجزاء "+str(parts_all))
        ent_part.set_text(str(self.all_in_page[3]))
        clo = asm_customs.ButtonClass("ألغ")
        clo.connect('clicked',lambda *a: dlg.destroy())
        move = Gtk.Button("انتقل")
        def replace_cb(widget):
            n_page = int(ent_page.get_text())
            n_part = int(ent_part.get_text())
            id_page = self.db.go_to_page(n_part, n_page)
            if id_page == None: 
                for n in range(20):
                    id_page = self.db.go_to_nearer_page(n_part, n_page, n+1)
                    if id_page != None: break
            if id_page == None: 
                asm_customs.erro(self.parent, "لا يمكن الذهاب إلى الصفحة المحددة")
                return
            if self.current_id < id_page[0]: self.stack.set_transition_type(self.style_browse_next)
            elif self.current_id > id_page[0]: self.stack.set_transition_type(self.style_browse_prev)
            elif self.current_id == id_page[0]: return
            self.show_page(id_page[0])
            ch = self.stack.get_visible_child_name()
            if ch == "n1": 
                self.stack.set_visible_child_name("n2")
            else: 
                self.stack.set_visible_child_name("n1")
            dlg.destroy()
        move.connect('clicked', replace_cb)
        ent_page.connect('activate', replace_cb)
        ent_part.connect('activate', replace_cb)
        box = dlg.vbox
        box.set_border_width(5)
        hb = Gtk.Box(spacing=5,orientation=Gtk.Orientation.HORIZONTAL)
        hb.pack_start(ent_page, False, False, 3)
        hb.pack_start(lab_page, False, False, 3)
        box.pack_start(hb, False, False, 3)
        hb = Gtk.Box(spacing=5,orientation=Gtk.Orientation.HORIZONTAL)
        hb.pack_start(ent_part, False, False, 3)
        hb.pack_start(lab_part, False, False, 3)
        box.pack_start(hb, False, False, 3)
        hb = Gtk.Box(spacing=5,orientation=Gtk.Orientation.HORIZONTAL)
        hb.pack_start(move, False, False, 0)
        hb.pack_end(clo, False, False, 0)
        box.pack_end(hb, False, False, 0)
        dlg.show_all()
    
    def move_to_page(self, *a):
        parts_all, pages_all = self.db.parts_pages(self.all_in_page[3])
        self.lab_page_move.set_label("عدد الصفحات "+str(pages_all))
        self.lab_part_move.set_label("عدد الأجزاء "+str(parts_all))
        self.ent_page_move.set_text(str(self.all_in_page[4]))
        self.ent_part_move.set_text(str(self.all_in_page[3]))
    
    def search_entry(self, *a):
        text = asm_araby.fuzzy(self.entry_index.get_text())
        if text == '':
            self.scroll_index.show_all()
            self.scroll_search.hide()
        else:
            self.scroll_index.hide()
            titles = self.db.search_index(text)
            self.store_search.clear()
            c = 1
            for a in titles:
                self.store_search.append([a[0], c, a[1], '', 0, 0, '', 0]) 
                c += 1
            self.scroll_search.show_all()
    
    def autoScroll(self, *a):
        if not self.autoScrolling: return True
        ch = self.stack.get_visible_child_name()
        if ch == "n1":
            vadj = self.scroll_nasse1.get_vadjustment()
        else:
            vadj = self.scroll_nasse2.get_vadjustment()
        m = vadj.get_upper()-vadj.get_page_size()
        n = min(m, vadj.get_value()+0.1)
        if n == m: self.btn_autoScroll.set_active(False)
        vadj.set_value(n)
        return True
    
    def autoScrollCb(self, b, *a):
        self.autoScrolling = b.get_active()
        
    # a تحرير الكتاب المفتوح----------------------------------
    
    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)
    
    def comment_cb(self, *a):
        # interface--------------------------------------
        box = Gtk.Box(spacing=5,orientation=Gtk.Orientation.VERTICAL)
        dlg = Gtk.Dialog(parent=self.parent)
        dlg.set_icon_name("asmaa")
        dlg.set_default_size(380, 300)
        area = dlg.get_content_area()
        area.set_spacing(6)
        
        hb_bar = Gtk.HeaderBar()
        hb_bar.set_show_close_button(True)
        dlg.set_titlebar(hb_bar)
        hb_bar.set_title('التعليق')
        
        view_comment = Gtk.TextView()
        view_comment_bfr = view_comment.get_buffer()
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.add(view_comment)
        # functions------------------------------------
        id_page = self.all_in_page[1]
        def add_widget():
            dlg.show_all()
            if self.db.show_comment(id_page) != None and self.db.show_comment(id_page) != []:
                update_btn.show_all()
                delete_btn.show_all()
                save_btn.hide()
                view_comment_bfr.set_text(self.db.show_comment(id_page)[0])
            else:
                save_btn.show_all()
                update_btn.hide()
                delete_btn.hide()
        #-----------------------    
        def save_cb(w):
            comment = view_comment_bfr.get_text(view_comment_bfr.get_start_iter(),
                            view_comment_bfr.get_end_iter(), False)
            if comment == '': return
            self.db.add_comment(id_page, comment)
            add_widget()
            img = Gtk.Image.new_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.BUTTON)
            self.comment_btn.set_image(img)
            self.comment_btn.show_all()
        #------------------------    
        def update_cb(w):
            comment = view_comment_bfr.get_text(view_comment_bfr.get_start_iter(),
                            view_comment_bfr.get_end_iter(), False)
            self.db.update_comment(id_page, comment)
        #-------------------------
        def delete_cb(w):
            self.db.remove_comment(id_page)
            view_comment_bfr.set_text('')
            add_widget()
            img = Gtk.Image.new_from_stock(Gtk.STOCK_FILE, Gtk.IconSize.BUTTON)
            self.comment_btn.set_image(img)
            self.comment_btn.show_all()
        #-----------------------------------
        save_btn = asm_customs.ButtonClass("حفظ")
        save_btn.connect('clicked', save_cb)
        update_btn = asm_customs.ButtonClass("حفظ")
        update_btn.connect('clicked', update_cb)
        delete_btn = asm_customs.ButtonClass("حذف")
        delete_btn.connect('clicked', delete_cb)
        hbox = Gtk.Box(spacing=0,orientation=Gtk.Orientation.HORIZONTAL)
        Gtk.StyleContext.add_class(hbox.get_style_context(), "linked")
        hbox.pack_start(update_btn, False, False, 0)
        hbox.pack_start(delete_btn, False, False, 0)
        hb_bar.pack_start(hbox)
        hb_bar.pack_start(save_btn)
        #----------------------------
        box.pack_start(scroll, True, True, 0)
        area.pack_start(box, True, True, 0)
        add_widget()
        
    def build(self, *a):
        self.vadj_page_next = 0
        self.vadj_page_prev= 0
        self.hp = Gtk.HPaned()
        self.parent.connect("check-resize", self.convert_browse)
        
        # a الفهرس-----------------------------------
        vbox = Gtk.VBox(False, 0)
        self.tree_index = asm_customs.TreeIndex()
        cell = Gtk.CellRendererText()
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
        kal = Gtk.TreeViewColumn('الفهرس', cell, text=1)
        self.tree_index.append_column(kal)
        self.store_index = Gtk.TreeStore(int, str)
        self.tree_index.set_model(self.store_index)
        self.sel_index = self.tree_index.get_selection()
        self.tree_index.connect("cursor-changed", self.ok_index)
        self.scroll_index = Gtk.ScrolledWindow()
        self.scroll_index.set_shadow_type(Gtk.ShadowType.IN)
        self.scroll_index.add(self.tree_index)
        #self.scroll_index.set_policy(Gtk.PolicyType.ALWAYS, Gtk.PolicyType.AUTOMATIC)
        self.scroll_index.get_hadjustment().set_value(0.0) 
        vbox.pack_start(self.scroll_index, True, True, 0)
        #----------------------------------------------
        self.tree_search = asm_customs.TreeIndex()
        cell = Gtk.CellRendererText()
        raq = Gtk.TreeViewColumn('الرقم', cell, text=1)
        self.tree_search.append_column(raq)
        cell = Gtk.CellRendererText()
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
        kal = Gtk.TreeViewColumn('أغلق النتائج', cell, text=2)
        kal.set_expand(True)
        kal.set_clickable(True)
        kal.connect('clicked', self.hide_search)
        self.tree_search.append_column(kal)
        self.store_search = Gtk.ListStore(int, int, str, str, int, int, str, int)
        self.tree_search.set_model(self.store_search)
        self.sel_search = self.tree_search.get_selection()
        self.tree_search.connect("cursor-changed", self.ok_search)
        self.scroll_search = Gtk.ScrolledWindow()
        self.scroll_search.set_shadow_type(Gtk.ShadowType.IN)
        self.scroll_search.add(self.tree_search)
        self.scroll_search.get_hadjustment().set_value(0.0) 
        vbox.pack_start(self.scroll_search, True, True, 0)
        
        try: self.entry_index = Gtk.SearchEntry()
        except: self.entry_index = Gtk.Entry()
        self.entry_index.set_placeholder_text('بحث في الفهرس')
        self.entry_index.connect('changed', self.search_entry)
        vbox.pack_start(self.entry_index, False, False, 3)
        self.hp.pack1(vbox, True, True)
        
        # a عارض النص-----------------------------------
        vbox = Gtk.VBox(False, 0)
        self.stack = Gtk.Stack()
        vbox.pack_start(self.stack, True, True, 0)
        #-------------------------------------
        self.view_nasse1 = asm_customs.ViewClass()
        self.view_nasse_bfr1 = self.view_nasse1.get_buffer()
        self.view_nasse1.connect_after("populate-popup", asm_popup.populate_popup, self.parent)
        #self.view_nasse1.connect('button-press-event', self.sss)
        self.scroll_nasse1 = Gtk.ScrolledWindow()
        #self.scroll_nasse1.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        self.scroll_nasse1.set_shadow_type(Gtk.ShadowType.IN)
        self.scroll_nasse1.add(self.view_nasse1)
        self.scroll_event_name1 = self.scroll_nasse1.connect('scroll-event', self.scroll_event)
        self.view_title_tag1 = self.view_nasse_bfr1.create_tag("title1")
        self.view_quran_tag1 = self.view_nasse_bfr1.create_tag("quran1")
        self.view_search_tag1 = self.view_nasse_bfr1.create_tag("search1")
        self.view_terms_tag1 = self.view_nasse_bfr1.create_tag("terms1")
        self.title_select_tag1 = self.view_nasse_bfr1.create_tag("tit_select1")
        self.stack.add_named(self.scroll_nasse1, 'n1')
        #-------------------------------------
        self.view_nasse2 = asm_customs.ViewClass()
        self.view_nasse_bfr2 = self.view_nasse2.get_buffer()
        self.view_nasse2.connect_after("populate-popup", asm_popup.populate_popup, self.parent)
        self.scroll_nasse2 = Gtk.ScrolledWindow()
        #self.scroll_nasse2.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        self.scroll_nasse2.set_shadow_type(Gtk.ShadowType.IN)
        self.scroll_nasse2.add(self.view_nasse2)
        self.scroll_event_name2 = self.scroll_nasse2.connect('scroll-event', self.scroll_event)
        self.view_title_tag2 = self.view_nasse_bfr2.create_tag("title2")
        self.view_quran_tag2 = self.view_nasse_bfr2.create_tag("quran2")
        self.view_search_tag2 = self.view_nasse_bfr2.create_tag("search2")
        self.view_terms_tag2 = self.view_nasse_bfr2.create_tag("terms2")
        self.title_select_tag2 = self.view_nasse_bfr2.create_tag("tit_select2")
        self.stack.add_named(self.scroll_nasse2, 'n2')
        #----------------------------------------
        hbox = Gtk.HBox(False, 3)
        hbox.set_border_width(3)
        hbox.pack_start(Gtk.Label('('), False, False, 0) 
        self.ent_page = Gtk.Label()
        hbox.pack_start(self.ent_page, False, False, 0)
        hbox.pack_start(Gtk.Label('/'), False, False, 0) 
        self.ent_part = Gtk.Label()
        hbox.pack_start(self.ent_part, False, False, 0) 
        hbox.pack_start(Gtk.Label(')'), False, False, 0)
        
        try:
            move_btn = Gtk.MenuButton()
            img = Gtk.Image()
            img.set_from_stock(Gtk.STOCK_JUMP_TO, Gtk.IconSize.BUTTON)
            move_btn.set_image(img)
            self.popover = Gtk.Popover()
            move_btn.set_popover(self.popover)
            self.ent_page_move = Gtk.Entry()
            self.ent_part_move = Gtk.Entry()
            self.lab_page_move = Gtk.Label("عدد الصفحات ")
            self.lab_part_move = Gtk.Label("عدد الأجزاء ")
            move = Gtk.Button("انتقل")
            def replace_cb(widget):
                n_page = int(self.ent_page_move.get_text())
                n_part = int(self.ent_part_move.get_text())
                id_page = self.db.go_to_page(n_part, n_page)
                if id_page == None: 
                    for n in range(20):
                        id_page = self.db.go_to_nearer_page(n_part, n_page, n+1)
                        if id_page != None: break
                if id_page == None: 
                    asm_customs.erro(self.parent, "لا يمكن الذهاب إلى الصفحة المحددة")
                    return
                if self.current_id < id_page[0]: self.stack.set_transition_type(self.style_browse_next)
                elif self.current_id > id_page[0]: self.stack.set_transition_type(self.style_browse_prev)
                elif self.current_id == id_page[0]: return
                self.show_page(id_page[0])
                ch = self.stack.get_visible_child_name()
                if ch == "n1": 
                    self.stack.set_visible_child_name("n2")
                else: 
                    self.stack.set_visible_child_name("n1")
                self.popover.hide()
            move.connect('clicked', replace_cb)
            self.ent_page_move.connect('activate', replace_cb)
            self.ent_part_move.connect('activate', replace_cb)
            box = Gtk.Box(spacing=5,orientation=Gtk.Orientation.VERTICAL)
            box.set_border_width(5)
            hb = Gtk.Box(spacing=5,orientation=Gtk.Orientation.HORIZONTAL)
            hb.pack_start(self.ent_page_move, False, False, 3)
            hb.pack_start(self.lab_page_move, False, False, 3)
            box.pack_start(hb, False, False, 3)
            hb = Gtk.Box(spacing=5,orientation=Gtk.Orientation.HORIZONTAL)
            hb.pack_start(self.ent_part_move, False, False, 3)
            hb.pack_start(self.lab_part_move, False, False, 3)
            box.pack_start(hb, False, False, 3)
            hb = Gtk.Box(spacing=5,orientation=Gtk.Orientation.HORIZONTAL)
            hb.pack_start(move, False, False, 0)
            box.pack_end(hb, False, False, 0)
            move_btn.connect("clicked", self.move_to_page)
            box.show_all()
            self.popover.add(box)
            move_btn.set_tooltip_text('الانتقال إلى الصفحة المحددة')
            hbox.pack_start(move_btn,False,False,10)
        except:
            move_btn = Gtk.Button()
            move_btn.set_tooltip_text('الانتقال إلى الصفحة المحددة')
            img = Gtk.Image()
            move_btn.connect("clicked", self.dialog_move_to_page)
            img.set_from_stock(Gtk.STOCK_JUMP_TO, Gtk.IconSize.LARGE_TOOLBAR)
            move_btn.set_image(img)
            hbox.pack_start(move_btn,False,False,10)

        btnbox_action = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        Gtk.StyleContext.add_class(btnbox_action.get_style_context(), "linked")
        
        self.comment_btn = Gtk.Button() 
        self.comment_btn.set_tooltip_text("أظهر التعليق")
        self.comment_btn.connect('clicked', self.comment_cb)
        btnbox_action.pack_start(self.comment_btn, False, False, 0)
        vbox.pack_start(hbox, False, False, 0)
        img = Gtk.Image()
        img.set_from_stock(Gtk.STOCK_MEDIA_FORWARD, Gtk.IconSize.BUTTON)
        self.btn_autoScroll = Gtk.ToggleButton()
        self.btn_autoScroll.add(img)
        self.btn_autoScroll.set_tooltip_text("استعراض آلي")
        btnbox_action.pack_start(self.btn_autoScroll, False, False, 0 )
        hbox.pack_start(btnbox_action, False, False, 0 )
        self.autoScrolling = False
        self.btn_autoScroll.connect("clicked", self.autoScrollCb)
        self.timeo = GLib.timeout_add(100/((asm_config.getn('auto_browse'))*8), self.autoScroll, None)
        
        btnbox_info = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        Gtk.StyleContext.add_class(btnbox_info.get_style_context(), "linked")
        
        bitaka = Gtk.Button()
        bitaka.set_tooltip_text("بطاقة عن الكتاب")
        bitaka.connect('clicked', self.show_bitaka)
        img = Gtk.Image()
        img.set_from_stock(Gtk.STOCK_INFO, Gtk.IconSize.BUTTON)
        bitaka.set_image(img)
        btnbox_info.pack_start(bitaka, False, False, 0 ) 
        edit_book = Gtk.Button()
        edit_book.set_tooltip_text("تحرير الكتاب الحاليّ")
        edit_book.connect('clicked', self.editbk_cb)
        img = Gtk.Image()
        img.set_from_stock(Gtk.STOCK_EDIT, Gtk.IconSize.BUTTON)
        edit_book.set_image(img)
        btnbox_info.pack_start(edit_book, False, False, 0 ) 
        hbox.pack_end(btnbox_info, False, False, 0 ) 
        
        self.convert_browse()
        self.hp.pack2(vbox, True, False)
        self.pack_start(self.hp, True, True, 0)
        self.show_all()
        self.scroll_search.hide()
        self.change_font()
        if self.id_book != -1:
            if self.db_list.book_dir(self.id_book) == asm_path.BOOK_DIR_r:
                self.comment_btn.set_sensitive(False)
Exemple #5
0
 def __init__(self, parent):
     self.parent = parent
     self.db = Othman()
     self.opened_new = []
     self.opened_old = []
     self.build()
Exemple #6
0
class ViewerMoshaf(Gtk.HPaned):
    
    def __init__(self, parent):
        self.parent = parent
        self.db = Othman()
        self.opened_new = []
        self.opened_old = []
        self.build()
    
    def show_bitaka(self, *a):
        return [u'',u'',u'',u'''
كلام رب العالمين على الحقيقة بألفاظه ومعانيه 
محفوظ في الصدور ، مقروء بالألسنة مكتوب في المصاحف
تكلم به الله تعالى فسمعه جبريل منه 
وتكلم به جبريل فسمعه النبي - صلى الله عليه وسلم - منه ، 
وتكلم به النبي - صلى الله عليه وسلم - فسمعته منه أمته وحفظته عنه ، 
فالكلام كلام الباري والصوت صوت القارئ . 
قال الله تعالى : فأجره حتى يسمع كلام الله  الآية 
        ''', u'''''']
    
    def first_page(self, *a):
        self.show_page(1)
    
    def previous_page(self, *a):
        if self.page_id == 1:
            return
        self.show_page(self.page_id-1)
    
    def next_page(self, *a):
        if self.page_id == 604:
            return
        self.show_page(self.page_id+1)
    
    def last_page(self, *a):
        self.show_page(604)
    
    def back_to_old(self, *a):
        if len(self.opened_old) == 1: return
        n = self.opened_old.pop()
        self.show_page(self.opened_old[-1])
        self.opened_new.append(n)
        
    def advance_to_new(self, *a):
        if len(self.opened_new) == 0: return
        n = self.opened_new.pop()
        self.show_page(n)
        if n != self.opened_old[-1]: self.opened_old.append(n)
    
    def ok_index(self, *a):
        model, i = self.sel_index.get_selected()
        if i:
            page= model.get_value(i,0)
            self.show_page(page)
            
    def show_page(self, page=1):
        new_list = []
        sura = u''
        ls_text = self.db.text_in_page(page)
        ls_text.reverse()
        for a in range(len(ls_text)):
            if a%2 == 0:
                txt = u'<div id = "nasse">'+' '.join(ls_text[a])+'</div>'
                new_list.append(txt)
            else:
                sura = ls_text[a][1]
                if page != 1 and page != 187: 
                    new_list.append(u'<div id = "basmala">بِــــسۡمِ ٱللهِ ٱلرَّحۡمَـٰنِ ٱلرَّحِيمِ</div>')
                tit = title_sura.replace(u'الترتيب', u'الترتيب{}'.format(ls_text[a][0]),).\
                replace(u'السورة', u'سورة '+ls_text[a][1]).replace(u'الآيات', u'الآيات{}'.format(ls_text[a][3]))
                new_list.append(tit)
        new_list.reverse()
        if [] in new_list: new_list.remove([])
        if sura == u'': sura = self.db.info_page(page)[0]
        new_text = ' '.join(new_list)
        html = open(join(asm_path.MOSHAF_DIR, 'page_quran.html'), 'r')
        html = html.read()
        html = html.replace('{nasse}', new_text)
        html = html.replace('{sura}', u'سورة '+sura)
        html = html.replace('{joze}', u'الجزء '+ajzaa[self.db.info_page(page)[1]])
        html = html.replace('{page}', str(page))
        if len(self.my_aya.keys()) != 0:
            if page in self.my_aya.keys():
                for a in self.my_aya[page]:
                    aya_txt = self.db.get_aya(a)
                    html = re.sub(aya_txt, u'<span style="background-color: rgb(255, 245, 177);">{}</span>'.format(aya_txt,), html)
        self.view_quran.load_html_string(html, u'file://{}/'.format(asm_path.MOSHAF_DIR,))
        self.page_id = page
        if len(self.opened_old) == 0: self.opened_old.append(page)
        elif page != self.opened_old[-1]: self.opened_old.append(page)
    
    def load_sura(self, *a):
        for a in self.list_sura:
            while (Gtk.events_pending()): Gtk.main_iteration()
            s = self.store_index.append(None, a[0])
            for b in a[1:]:
                self.store_index.append(s, b)
    
    def load_tahzib(self, *a):
        iters = [None]
        last_iter = None
        last_level = 0
        for i in self.list_ahzab:
            level = i[2]
            if level > last_level: iters.append(last_iter)
            elif level < last_level:
                for j in range(last_level-level): iters.pop()
            try :
                last_iter = self.store_index.append(iters[-1], [i[0], i[1]])
            except :
                pass
            last_level = level
    
    def load_page(self, *a):
        for page in range(1, 605):
            self.store_index.append(None, [page, u'الصفحة {}'.format(page,)])
    
    def load_index(self, btn):
        self.tree_index.handler_block(self.changed_index)
        v = btn.get_active()
        self.store_index.clear()
        if v == 0:
            self.load_sura()
        elif v == 1:
            self.load_tahzib()
        elif v == 2:
            self.load_page()
        self.my_aya = {}
        self.show_page(self.page_id)
        self.tree_index.handler_unblock(self.changed_index)
   
    def tafsir_ayat(self, *a):
        all_ayat = self.db.ayat_in_page(self.page_id)
        self.parent.tafsirpage.store_search.clear()
        if len(all_ayat[0]) == 0:
            asm_customs.erro(self.parent, 'لا يوجد نتيجة'); return
        else: 
            for ayat in all_ayat:
                i_sura = ayat[0]
                i_ayat = ayat[1]
                suras_names = Othman().get_suras_names()
                sura = suras_names[i_sura-1]
                self.parent.tafsirpage.store_search.append(None, [i_sura, i_ayat, sura[1]])
                self.parent.tafsirpage.notebook.set_current_page(1)
        self.parent.tafsirpage.view_tafsir_bfr.set_text('')
        self.parent.tafsirpage.sel_search.select_path((0,))
        self.parent.notebook.set_current_page(4)
        self.parent.tafsirpage.ok_result()
   
    def populate_page_popup_cb(self, view, menu):
        for a in menu.get_children():
            a.destroy()
        f1 = Gtk.MenuItem('تفسير الآيات')
        f1.connect('activate', self.tafsir_ayat) 
        menu.append(f1)
        c1 = Gtk.SeparatorMenuItem()
        menu.append(c1)
        c1.show()
        i = Gtk.MenuItem('تكبير النص')
        i.connect('activate', lambda m,v,*a,**k: v.zoom_in(), view)
        menu.append(i)
        i = Gtk.MenuItem('تصغير النص')
        i.connect('activate', lambda m,v,**k: v.zoom_out(), view)
        menu.append(i)
        i = Gtk.MenuItem('الحجم العادي')
        i.connect('activate', lambda m,v,*a,**k: v.get_zoom_level() == 1.0 or v.set_zoom_level(1.0), view)
        menu.append(i)
        menu.show_all()
        return False
    
    def search_on_page(self, text):
        return
     
    def search_on_active(self, text):
        if len(text) >= 3:
            all_ayat = Othman().search(text)
            self.store_index.clear()
            if len(all_ayat) == 0:
                asm_customs.erro(self.parent, 'لا يوجد نتيجة'); return
            else: 
                for ayat in all_ayat:
                    sura = ayat[0]
                    aya = ayat[1]
                    suras_names = Othman().get_suras_names()
                    suranm = suras_names[sura-1]
                    id_page = self.db.aya_page(aya, sura)
                    if id_page != self.id_page_last:
                        self.my_aya[id_page] = [ayat[5]]
                        self.id_page_last = id_page
                        self.store_index.append(None, [id_page, suranm[1]])
                    else:
                        self.my_aya[id_page].append(ayat[5])                
        
    def build(self, *a):
        self.id_page_last = 0
        try:
            self.list_sura = pickle.load(open(join(asm_path.MOSHAF_DIR, 'list_sura.pkl'), "rb"))
            self.list_ahzab =  pickle.load(open(join(asm_path.MOSHAF_DIR, 'list_ahzab.pkl'), "rb"))
        except:
            self.list_sura = []
            self.list_ahzab =  []
        self.my_aya = {}
        self.page_id = asm_config.getn('quran_pos')
        Gtk.HPaned.__init__(self)
        self.set_border_width(3)
        self.set_position(150)
        # a الفهرس-----------------------------------
        vbox = Gtk.VBox(False, 3)
        index_by = Gtk.ComboBoxText()
        index_by.append_text(u'السور')
        index_by.append_text(u'الأجزاء')
        index_by.append_text(u'الصفحات')
        index_by.set_active(0)
        vbox.pack_start(index_by, False, False, 0)
        self.tree_index = asm_customs.TreeIndex()
        self.tree_index.set_headers_visible(False)
        cell = Gtk.CellRendererText()
        cell.set_property("wrap-width", 150)
        kal = Gtk.TreeViewColumn('الفهرس', cell, text=1)
        self.tree_index.append_column(kal)
        self.store_index = Gtk.TreeStore(int, str)
        self.tree_index.set_model(self.store_index)
        self.sel_index = self.tree_index.get_selection()
        self.changed_index = self.tree_index.connect("cursor-changed", self.ok_index)
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.add(self.tree_index)
        scroll.get_hadjustment().set_value(0.0) 
        vbox.pack_start(scroll, True, True, 0)
        self.pack1(vbox, True, True)
        
        self.view_quran = WebKit.WebView()
        self.view_quran.connect("populate-popup", self.populate_page_popup_cb)
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.add(self.view_quran)
        self.view_quran.set_full_content_zoom(True)
        self.pack2(scroll, True, True)
        index_by.connect('changed', self.load_index)
        self.load_index(index_by)
Exemple #7
0
 def __init__(self, parent):
     self.db = None
     self.current_id = 1
     self.part_now = 1
     self.page_now = 1
     self.nm_book = 'التفسير الميسر'
     self.parent = parent
     self.othman = Othman()
     self.listbook = listDB()
     sura_list = self.othman.get_suras_names()
     self.opened_new = []
     self.opened_old = []
     Gtk.HBox.__init__(self, False, 0)
     vbox = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL)
     
     self.notebook = Gtk.Notebook()
     self.notebook.set_show_tabs(False)
     vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL)
     vb.set_border_width(5)
     self.load_list()
     self.tafsirs = asm_customs.combo(self.store_tafasir, 'التفسير')
     self.tafsirs.set_wrap_width(self.n_warp)
     vb.pack_start(self.tafsirs, False, False, 0)
     self.tafsirs.set_active(0)
     
     adj = Gtk.Adjustment(1, 1, 7, 1, 5.0, 0.0)
     self.ayas = Gtk.SpinButton()
     self.ayas.set_adjustment(adj)
     self.ayas.set_value(1.0)
     self.ayas.connect('activate', self.select_aya)
     
     hb, self.suras = asm_customs.combo(sura_list, 'السورة')
     self.suras.set_wrap_width(10)
     vb.pack_start(hb, False, False, 0)
     self.suras.set_active(0)
     
     hb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.HORIZONTAL)
     lab = Gtk.Label('الآيــــة')
     self.ayas.set_wrap(True)
     self.ayas.set_size_request(140, -1)
     hb.pack_start(lab, False, False, 0)
     hb.pack_end(self.ayas, False, False, 0)
     vb.pack_start(hb, False, False, 0)
     
     show_search = Gtk.Button('أظهر البحث')
     def show_search_cb(w):
         self.notebook.set_current_page(1)
         self.ok_result()
     show_search.connect('clicked', show_search_cb)
     vb.pack_end(show_search, False, False, 0)
     modif_list_tafsir = Gtk.Button('تعديل قائمة التفاسير')
     modif_list_tafsir.connect('clicked', self.show_modif_list_tafsir)
     vb.pack_end(modif_list_tafsir, False, False, 0)
     self.notebook.append_page(vb, Gtk.Label('تصفح'))
     
     vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL)
     vb.set_border_width(5)
     
     self.tafsirs1 = asm_customs.combo(self.store_tafasir, 'التفسير')
     self.tafsirs1.set_wrap_width(self.n_warp)
     vb.pack_start(self.tafsirs1, False, False, 0)
     self.tafsirs1.set_active(0)
     
     self.search_entry = Gtk.SearchEntry()
     self.search_entry.set_placeholder_text('بحث في القرآن')
     self.search_entry.connect('activate', self.search_on_quran)
     hbox = Gtk.HBox(False, 2)
     hbox.pack_start(self.search_entry, True, True, 0)
     vb.pack_start(hbox, False, False, 0)
     
     self.store_search = Gtk.TreeStore(int, int, str)
     self.tree_search = asm_customs.TreeIndex()
     self.tree_search.set_model(self.store_search)
     cell = Gtk.CellRendererText()
     column = Gtk.TreeViewColumn('السورة', cell, text=2)
     self.tree_search.append_column(column)
     cell = Gtk.CellRendererText()
     column = Gtk.TreeViewColumn('الآية', cell, text=1)
     self.tree_search.append_column(column)
     self.sel_search = self.tree_search.get_selection()
     self.tree_search.connect("cursor-changed", self.ok_result)
     scroll = Gtk.ScrolledWindow()
     scroll.set_shadow_type(Gtk.ShadowType.IN)
     scroll.add(self.tree_search)
     
     show_browse = Gtk.Button('أظهر التصفح')
     def show_browse_cb(w):
         self.notebook.set_current_page(0)
         self.select_tafsir()
     show_browse.connect('clicked', show_browse_cb)
     vb.pack_end(show_browse, False, False, 0)
     
     scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
     vb.pack_start(scroll, True, True, 0)
     self.notebook.append_page(vb, Gtk.Label('بحث'))
     vbox.pack_start(self.notebook, True, True, 0)
     self.pack_start(vbox, False, False, 0)
     
     self.view_tafsir = asm_customs.ViewClass()
     self.view_tafsir_bfr = self.view_tafsir.get_buffer()
     self.view_tafsir.connect_after("populate-popup", asm_popup.populate_popup, self.parent)
     self.view_quran_tag = self.view_tafsir_bfr.create_tag("quran")
     self.view_search_tag = self.view_tafsir_bfr.create_tag("search")
     self.change_font()
     self.scroll_nasse = Gtk.ScrolledWindow()
     self.scroll_nasse.set_shadow_type(Gtk.ShadowType.IN)
     self.scroll_nasse.add(self.view_tafsir)
     self.pack_start(self.scroll_nasse, True, True, 0)
     
     self.tafsirs.connect('changed', self.select_tafsir)
     self.tafsirs1.connect('changed', self.ok_result)
     self.change_sura = self.suras.connect('changed', self.select_sura)
     self.change_aya = self.ayas.connect('value-changed', self.select_aya)
     self.show_all()
     self.select_aya(self.ayas)
Exemple #8
0
class Tafsir(Gtk.HBox):
    
    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 mov_browse(self, id_page):
        self.suras.handler_block(self.change_sura)
        self.ayas.handler_block(self.change_aya)
        self.all_in_page = self.db.get_text_body(id_page)#rowid, id, text, part, page, hno, sora, aya, na
        if self.all_in_page in [None, "", 0] or self.all_in_page[7] in [None, "", 0]: 
            self.suras.set_active(-1)
            self.ayas.set_sensitive(False)
        elif self.notebook.get_current_page() == 0: 
            if self.all_in_page[6] >= 1 and self.suras.get_active() != self.all_in_page[6]-1:
                self.suras.set_active(self.all_in_page[6]-1)
                self.ayas.set_sensitive(True)
                ayat = asm_customs.value_active(self.suras, 2)
                adj = self.ayas.get_adjustment()
                if ayat == None: ayat = 100
                adj.set_upper(ayat)
                adj.set_value(1)
            if self.aya_now in range(self.all_in_page[7], self.all_in_page[7]+self.all_in_page[8]):
                self.ayas.set_value(self.aya_now)
            else: self.ayas.set_value(self.all_in_page[7])
                
        self.suras.handler_unblock(self.change_sura)
        self.ayas.handler_unblock(self.change_aya)
        
    def show_page(self, id_page):
        self.all_in_page = self.db.get_text_body(id_page)#rowid, id, text, part, page, hno, sora, aya, na
        self.current_id = self.all_in_page[0]
        self.part_now = self.all_in_page[3]
        self.page_now = self.all_in_page[4]
        self.view_tafsir_bfr.set_text(self.all_in_page[2])
        text = self.parent.entry_search.get_text()
        if len(text) >= 2 and text != u"ال": 
            self.search_now(text)
        try: sora, aya, na = self.all_in_page[6], self.all_in_page[7], self.all_in_page[8]
        except: sora = 0
        if sora > 0 and sora < 115:
            try: na = int(na)
            except: na = 1
            tafsir_quran = ' '.join(self.othman.get_ayat(sora,aya,aya+na))
            self.view_tafsir_bfr.insert(self.view_tafsir_bfr.get_start_iter(), u" \nـــــــــــــــــــ\n")
            self.view_tafsir_bfr.insert_with_tags(self.view_tafsir_bfr.get_start_iter(), 
                                                  tafsir_quran, self.view_quran_tag)
        # add to list browse
        if len(self.opened_old) == 0: 
            self.opened_old.append([id_page, self.tafsirs.get_active()])
        elif ([id_page, self.tafsirs.get_active()]) != self.opened_old[-1]: 
            self.opened_old.append([id_page, self.tafsirs.get_active()])
        # change n aya and n sura
        self.mov_browse(id_page)
        self.scroll_nasse.get_vadjustment().set_value(0.0)
        
    def ok_result(self, *a):
        model, i = self.sel_search.get_selected()
        if i:
            sura = model.get_value(i,0)
            aya = model.get_value(i,1)
            tafsir = asm_customs.value_active(self.tafsirs1, 0)
            self.show_tafsir(tafsir, sura, aya)
                
    def near_page(self, v):
        self.size_font += v
        self.view_tafsir.override_font(Pango.FontDescription("{}".format(self.size_font,))) 
    
    def select_tafsir(self, *a):
        self.nm_book = asm_customs.value_active(self.tafsirs, 1)
        tafsir = asm_customs.value_active(self.tafsirs, 0)
        sura = asm_customs.value_active(self.suras, 0)
        aya = self.ayas.get_value()
        self.show_tafsir(tafsir, sura, aya)
    
    def select_sura(self, w):
        self.ayas.set_sensitive(True)
        sura = asm_customs.value_active(w, 0)
        ayat = asm_customs.value_active(w, 2)
        adj = self.ayas.get_adjustment()
        adj.set_upper(ayat)
        adj.set_value(1)
        tafsir = asm_customs.value_active(self.tafsirs, 0)
        self.show_tafsir(tafsir, sura, 1)
        
    def select_aya(self, w):
        sura = asm_customs.value_active(self.suras, 0)
        aya = int(w.get_text())
        adj = self.ayas.get_adjustment()
        if aya > adj.get_upper(): aya = adj.get_upper()
        tafsir = asm_customs.value_active(self.tafsirs, 0)
        self.show_tafsir(tafsir, sura, aya)
    
    def first_page(self, *a):
        self.show_page(self.db.first_page())
    
    def previous_page(self, *a):
        self.show_page(self.db.previous_page(self.current_id))
    
    def next_page(self, *a):
        self.show_page(self.db.next_page(self.current_id))
    
    def last_page(self, *a):
        self.show_page(self.db.last_page())
    
    def back_to_old(self, *a):
        if len(self.opened_old) == 1: return
        n = self.opened_old.pop()
        self.tafsirs.set_active(self.opened_old[-1][1])
        self.show_page(self.opened_old[-1][0])
        self.opened_new.append(n)
        
    def advance_to_new(self, *a):
        if len(self.opened_new) == 0: return
        n = self.opened_new.pop()
        self.tafsirs.set_active(n[1])
        self.show_page(n[0])
        if n != self.opened_old[-1]: self.opened_old.append(n)
    
    def search_on_quran(self, *a):
        text = self.search_entry.get_text()
        if len(text) >= 3:
            all_ayat = Othman().search('"'+text+'"')
            self.store_search.clear()
            if len(all_ayat) == 0:
                asm_customs.erro(self.parent, 'لا يوجد نتيجة'); return
            else: 
                for ayat in all_ayat:
                    i_sura = ayat[0]
                    i_ayat = ayat[1]
                    suras_names = Othman().get_suras_names()
                    sura = suras_names[i_sura-1]
                    self.store_search.append(None, [i_sura, i_ayat, sura[1]])
    
    def search_on_active(self, text):
        return
    
    def search_on_page(self, text):
        self.show_page(self.all_in_page[1])
        self.search_now(text)
        
    def search_now(self, text):
        search_tokens = []
        nasse = self.view_tafsir_bfr.get_text(self.view_tafsir_bfr.get_start_iter(), 
                                            self.view_tafsir_bfr.get_end_iter(),True)
        if text == '': 
            return
        else:
            text = text.strip()
            ls_term = asm_araby.fuzzy(text).split(' ')
        for text in ls_term:
            if len(text) == 1 or text == u"ال": continue
            new_term = ''
            for l in text:
                new_term += '({}(\u0651)?([\u064b\u064c\u064d\u064e\u064f\u0650\u0652])?)'.format(l, )
            new_term = new_term.replace('ا', '[اأإؤءئى]')
            new_term = new_term.replace('ه', '[هة]')
            re_term = re.compile('({})'.format(new_term,))
            r_findall = re_term.findall(nasse)
            for r in r_findall:
                if r[0] not in search_tokens: search_tokens.append(r[0])
        asm_customs.with_tag(self.view_tafsir_bfr, self.view_search_tag, search_tokens, 1, self.view_tafsir)
                    
    def change_font(self, *a):
        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.view_search_tag.set_property('background', self.parent.theme.color_fnd)
    
    def load_list(self, *a):
        self.store_tafasir = []
        list_tafsir = eval(asm_config.getv('list_tafsir'))
        if list_tafsir[2] == 0:
            all_tafsir = self.listbook.all_tafsir()
            for a in all_tafsir: 
                self.store_tafasir.append(a)
        elif list_tafsir[2] == 1:
            for a in list_tafsir[1]:
                if self.listbook.tit_book(a) != None and len(self.listbook.tit_book(a)) > 1:
                    self.store_tafasir.append([a, self.listbook.tit_book(a)[1]])
        self.store_tafasir.insert(0, [-1, 'التفسير الميسر'])
        self.n_warp = list_tafsir[0]+1
        
    def refresh_list(self, *a):
        model = self.tafsirs.get_model()
        model1 = self.tafsirs1.get_model()
        model.clear()
        model1.clear()
        list_tafsir = eval(asm_config.getv('list_tafsir'))
        model.append([-1, 'التفسير الميسر', 0])
        model1.append([-1, 'التفسير الميسر', 0])
        for a in list_tafsir[1]:
            model.append([a, self.listbook.tit_book(a)[1], 0])
            model1.append([a, self.listbook.tit_book(a)[1], 0])
        self.tafsirs.set_active(0)
        self.tafsirs1.set_active(0)
        self.tafsirs.set_wrap_width(list_tafsir[0]+1)
        self.tafsirs1.set_wrap_width(list_tafsir[0]+1)
        self.tafsirs.show_all()
        self.tafsirs1.show_all()
        
    def show_modif_list_tafsir(self, *a):
        ListTafasir(self.parent)
        return
    
    def __init__(self, parent):
        self.db = None
        self.current_id = 1
        self.part_now = 1
        self.page_now = 1
        self.nm_book = 'التفسير الميسر'
        self.parent = parent
        self.othman = Othman()
        self.listbook = listDB()
        sura_list = self.othman.get_suras_names()
        self.opened_new = []
        self.opened_old = []
        Gtk.HBox.__init__(self, False, 0)
        vbox = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL)
        
        self.notebook = Gtk.Notebook()
        self.notebook.set_show_tabs(False)
        vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL)
        vb.set_border_width(5)
        self.load_list()
        self.tafsirs = asm_customs.combo(self.store_tafasir, 'التفسير')
        self.tafsirs.set_wrap_width(self.n_warp)
        vb.pack_start(self.tafsirs, False, False, 0)
        self.tafsirs.set_active(0)
        
        adj = Gtk.Adjustment(1, 1, 7, 1, 5.0, 0.0)
        self.ayas = Gtk.SpinButton()
        self.ayas.set_adjustment(adj)
        self.ayas.set_value(1.0)
        self.ayas.connect('activate', self.select_aya)
        
        hb, self.suras = asm_customs.combo(sura_list, 'السورة')
        self.suras.set_wrap_width(10)
        vb.pack_start(hb, False, False, 0)
        self.suras.set_active(0)
        
        hb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.HORIZONTAL)
        lab = Gtk.Label('الآيــــة')
        self.ayas.set_wrap(True)
        self.ayas.set_size_request(140, -1)
        hb.pack_start(lab, False, False, 0)
        hb.pack_end(self.ayas, False, False, 0)
        vb.pack_start(hb, False, False, 0)
        
        show_search = Gtk.Button('أظهر البحث')
        def show_search_cb(w):
            self.notebook.set_current_page(1)
            self.ok_result()
        show_search.connect('clicked', show_search_cb)
        vb.pack_end(show_search, False, False, 0)
        modif_list_tafsir = Gtk.Button('تعديل قائمة التفاسير')
        modif_list_tafsir.connect('clicked', self.show_modif_list_tafsir)
        vb.pack_end(modif_list_tafsir, False, False, 0)
        self.notebook.append_page(vb, Gtk.Label('تصفح'))
        
        vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL)
        vb.set_border_width(5)
        
        self.tafsirs1 = asm_customs.combo(self.store_tafasir, 'التفسير')
        self.tafsirs1.set_wrap_width(self.n_warp)
        vb.pack_start(self.tafsirs1, False, False, 0)
        self.tafsirs1.set_active(0)
        
        self.search_entry = Gtk.SearchEntry()
        self.search_entry.set_placeholder_text('بحث في القرآن')
        self.search_entry.connect('activate', self.search_on_quran)
        hbox = Gtk.HBox(False, 2)
        hbox.pack_start(self.search_entry, True, True, 0)
        vb.pack_start(hbox, False, False, 0)
        
        self.store_search = Gtk.TreeStore(int, int, str)
        self.tree_search = asm_customs.TreeIndex()
        self.tree_search.set_model(self.store_search)
        cell = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('السورة', cell, text=2)
        self.tree_search.append_column(column)
        cell = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('الآية', cell, text=1)
        self.tree_search.append_column(column)
        self.sel_search = self.tree_search.get_selection()
        self.tree_search.connect("cursor-changed", self.ok_result)
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.add(self.tree_search)
        
        show_browse = Gtk.Button('أظهر التصفح')
        def show_browse_cb(w):
            self.notebook.set_current_page(0)
            self.select_tafsir()
        show_browse.connect('clicked', show_browse_cb)
        vb.pack_end(show_browse, False, False, 0)
        
        scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        vb.pack_start(scroll, True, True, 0)
        self.notebook.append_page(vb, Gtk.Label('بحث'))
        vbox.pack_start(self.notebook, True, True, 0)
        self.pack_start(vbox, False, False, 0)
        
        self.view_tafsir = asm_customs.ViewClass()
        self.view_tafsir_bfr = self.view_tafsir.get_buffer()
        self.view_tafsir.connect_after("populate-popup", asm_popup.populate_popup, self.parent)
        self.view_quran_tag = self.view_tafsir_bfr.create_tag("quran")
        self.view_search_tag = self.view_tafsir_bfr.create_tag("search")
        self.change_font()
        self.scroll_nasse = Gtk.ScrolledWindow()
        self.scroll_nasse.set_shadow_type(Gtk.ShadowType.IN)
        self.scroll_nasse.add(self.view_tafsir)
        self.pack_start(self.scroll_nasse, True, True, 0)
        
        self.tafsirs.connect('changed', self.select_tafsir)
        self.tafsirs1.connect('changed', self.ok_result)
        self.change_sura = self.suras.connect('changed', self.select_sura)
        self.change_aya = self.ayas.connect('value-changed', self.select_aya)
        self.show_all()
        self.select_aya(self.ayas)