class ShowResult(Gtk.Box): def search_on_poem(self, text): self.showpoem.search_on_poem(text) def move_in_page(self, v): model, i = self.tree_results.get_selection().get_selected() if i: p = model.get_path(i).get_indices()[0] if p+v == -1 or p+v == len(model): return i1 = model.get_iter((p+v,)) self.tree_results.get_selection().select_iter(i1) self.tree_results.scroll_to_cell((p+v,)) elif len(self.tree_results.get_model()) == 0: return else: i2 = model.get_iter((0,)) self.tree_results.get_selection().select_iter(i2) self.tree_results.scroll_to_cell((0,)) self.show_result() def __init__(self, parent): self.parent = parent self.showpoem = ShowPoem(self.parent) self.text = '' self.cursive = False self.results_list = [] self.build() def show_result(self, *a): model, i = self.sel_result.get_selected() if i: id_poem = model.get_value(i,0) self.showpoem.loading(id_poem, self.parent.theme.fontmp) self.showpoem.mark_on_poem(self.text, self.cursive) def search(self, text, dict_perf, selected_list): self.text = text self.cursive = dict_perf['cursive'] text = text.replace('"','') text = text.replace("'","") ls_term = [] if dict_perf['with_tachkil'] == True: cond = 'nasse LIKE ?' else: cond = 'fuzzy(nasse) LIKE ?' text = daw_araby.fuzzy_plus(text) if dict_perf['identical'] == True: pfx, sfx = '% ', ' %' else: pfx, sfx = '%', '%' if dict_perf['cursive'] == True: self.condition = 'fuzzy(nasse) LIKE ?' ls_term.append(pfx+text+sfx) else: for a in text.split(u' '): ls_term.append(pfx+a+sfx) #if dict_perf['one_verse'] == True: # self.condition = u'fuzzy(nasse) LIKE ?' # ls_term = ['%'+u'%[.+]%'.join(text.split(u' '))+u'%',] #else: if dict_perf['one_term'] == True: self.condition = ' OR '.join([cond]*len(ls_term)) else : self.condition = ' AND '.join([cond]*len(ls_term)) n = 0 for a in selected_list: ls = self.parent.db.poems_id(a) for b in ls: check = self.parent.db.search(b, self.condition, ls_term) if check == True: n += 1 self.results_store.append([b, n, self.parent.db.name_poem(b), self.parent.db.name_poet(self.parent.db.id_poet(b))[1], daw_tools.get_name(daw_tools.elbehor, self.parent.db.get_id_baher(b)), daw_tools.get_name(daw_tools.elgharadh, self.parent.db.gharadh_poem(b)), daw_tools.get_name(daw_tools.elrawi, self.parent.db.rawi_poem(b)),]) self.results_list.append([b, n, self.parent.db.name_poem(b), self.parent.db.name_poet(self.parent.db.id_poet(b))[1], daw_tools.get_name(daw_tools.elbehor, self.parent.db.get_id_baher(b)), daw_tools.get_name(daw_tools.elgharadh, self.parent.db.gharadh_poem(b)), daw_tools.get_name(daw_tools.elrawi, self.parent.db.rawi_poem(b)),]) else: pass if len(self.results_list)>0: output = open(join(daw_customs.HOME_DIR,'آخر بحث.pkl'), 'wb') cPickle.dump(self.results_list, output) output.close() def sav_result_cb(self, *a): nm = self.sav_result_entry.get_text() if nm == "": daw_customs.erro(self.parent, "أدخل الاسم أولا.") elif nm in os.listdir(daw_customs.HOME_DIR): daw_customs.erro(self.parent, "يوجد بحث محفوظ بنفس الاسم !!") else: output = open(join(daw_customs.HOME_DIR, nm+'.pkl'), 'wb') cPickle.dump(self.results_list, output) output.close() self.sav_result_entry.set_text("") def build(self, *a): Gtk.Box.__init__(self,spacing=7,orientation=Gtk.Orientation.VERTICAL) hb = Gtk.HBox(False, 7) self.sav_result_btn = Gtk.ToolButton(Gtk.STOCK_SAVE) hb.pack_start(self.sav_result_btn, False, False, 0) self.sav_result_btn.connect('clicked', self.sav_result_cb) self.sav_result_entry = Gtk.Entry() hb.pack_start(self.sav_result_entry, False, False, 0) self.showpoem.pack_end(hb, False, False, 0) self.pack_start(self.showpoem, True, True, 0) self.results_store = Gtk.ListStore(int,int,str,str,str,str,str) self.tree_results = daw_customs.TreeClass() self.tree_results.set_model(self.results_store) self.sel_result = self.tree_results.get_selection() self.tree_results.connect("cursor-changed", self.show_result) self.tree_results.set_grid_lines(Gtk.TreeViewGridLines.HORIZONTAL) raq = Gtk.TreeViewColumn('الرقم', Gtk.CellRendererText(), text=1) raq.set_max_width(50) self.tree_results.append_column(raq) poems = Gtk.TreeViewColumn('القصيدة', Gtk.CellRendererText(), text=2) self.tree_results.append_column(poems) poems.set_max_width(300) eldimwan = Gtk.TreeViewColumn('الشاعر', Gtk.CellRendererText(), text=3) self.tree_results.append_column(eldimwan) eldimwan.set_max_width(300) elbaher = Gtk.TreeViewColumn('البحر', Gtk.CellRendererText(), text=4) self.tree_results.append_column(elbaher) elbaher.set_max_width(120) elgharadh = Gtk.TreeViewColumn('الغرض', Gtk.CellRendererText(), text=5) self.tree_results.append_column(elgharadh) elgharadh.set_max_width(80) elrawi = Gtk.TreeViewColumn('الروي', Gtk.CellRendererText(), text=6) self.tree_results.append_column(elrawi) elrawi.set_max_width(50) scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(self.tree_results) scroll.set_size_request(-1, 200) self.pack_start(scroll, False, False, 0) self.show_all()
class RecitePoem(Gtk.HPaned): def show_poem(self, *a): self.player.stop() model, i = self.tree_recited.get_selection().get_selected() if i: id_poem = model.get_value(i,0) self.iv.loading(id_poem, self.parent.theme.fontmp) self.player.set_sensitive(True) file_media = join(daw_customs.AUDIO_DIR,'00'+str(id_poem)+'.ogg') self.player.set_media(file_media) if not exists(file_media): daw_customs.erro(self.parent, u'لا يوجد ملف صوتي لهذه القصيدة') def show_info(self, *a): model, i = self.sel_recited.get_selected() if i: self.view_info_bfr.set_text(u'إلقاء : {}'.format(model.get_value(i,2).decode('utf8'),)) def store(self, *a): self.store_recited.clear() ls = self.parent.db.recited_poems() map(self.store_recited.append, ls) def search_on_page(self, text): self.iv.search_on_poem(text) def near_page(self, v): self.iv.near_poem(v) def move_in_page(self, v): model, i = self.tree_recited.get_selection().get_selected() if i: p = model.get_path(i).get_indices()[0] if p+v == -1 or p+v == len(model): return i1 = model.get_iter((p+v,)) self.tree_recited.get_selection().select_iter(i1) self.tree_recited.scroll_to_cell((p+v,)) elif len(self.tree_recited.get_model()) == 0: return else: i2 = model.get_iter((0,)) self.tree_recited.get_selection().select_iter(i2) self.tree_recited.scroll_to_cell((0,)) self.show_poem() def __init__(self, parent): self.parent = parent Gtk.HPaned.__init__(self) self.set_position(150) vbox = Gtk.Box(spacing=6,orientation=Gtk.Orientation.VERTICAL) self.vbox1= Gtk.Box(spacing=6,orientation=Gtk.Orientation.VERTICAL) self.tree_recited = daw_customs.TreeClass() self.sel_recited = self.tree_recited.get_selection() cell = Gtk.CellRendererText() cell.set_property("wrap-mode", Pango.WrapMode.WORD_CHAR) self.tree_recited.set_size_request(150, -1) kal = Gtk.TreeViewColumn('القصائد المقروءة', cell, text=1) self.tree_recited.append_column(kal) self.store_recited = Gtk.ListStore(int, str, str) self.store() self.tree_recited.set_model(self.store_recited) self.tree_recited.connect("cursor-changed", self.show_info) self.tree_recited.connect("row-activated", self.show_poem) scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(self.tree_recited) scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) vbox.pack_start(scroll, True, True, 0) self.view_info = daw_customs.ViewClass() self.view_info.set_right_margin(5) self.view_info.set_left_margin(5) self.view_info_bfr = self.view_info.get_buffer() scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(self.view_info) scroll.set_size_request(-1, 50) vbox.pack_start(scroll, False, False, 0) self.player = Mawso3aPlayer() self.iv = ShowPoem(self.parent) self.vbox1.pack_start(self.iv, True, True, 0) self.iv.pack_end(self.player, False, False, 0) self.vbox1.show_all() self.player.set_sensitive(False) self.pack1(vbox, False, False) self.pack2(self.vbox1, True, False) self.show_all()