def ok_m(self,*a): (model, i) = self.tree_sav.get_selection().get_selected() self.destroy() id_poem = model.get_value(i,0) text = model.get_value(i,1) sr = ShowPoem(self.parent) sr.loading(id_poem, self.parent.theme.fontmp) self.parent.viewerpoem.append_page(sr,TabLabel(sr, text)) self.parent.viewerpoem.set_current_page(-1) self.parent.viewerpoem.show_all() sr.search_half(text) self.parent.set_title("دواوين العرب - القصائد") self.parent.main_notebook.set_current_page(2) self.parent.poems_page.set_sensitive(True) self.parent.poems_page.set_active(True)
def to_poem(self, btn, *a): id_poem = int(btn.get_name()) nm_poem = self.parent.db.name_poem(id_poem) self.parent.set_title("دواوين العرب - القصائد") self.parent.main_notebook.set_current_page(2) self.parent.poems_page.set_sensitive(True) self.parent.poems_page.set_active(True) n = self.parent.viewerpoem.get_n_pages() for s in range(n): ch = self.parent.viewerpoem.get_nth_page(s) if self.parent.viewerpoem.get_tab_label(ch).nm == nm_poem: self.parent.viewerpoem.set_current_page(s) return sr = ShowPoem(self.parent) sr.loading(id_poem, self.parent.theme.fontmp) self.parent.viewerpoem.append_page(sr,TabLabel(sr, nm_poem)) self.parent.viewerpoem.show_all() self.parent.viewerpoem.set_current_page(-1)
def show_poem_cb(self, *a): model, i = self.tree_poems.get_selection().get_selected() if i: id_poem = model.get_value(i,0) text = model.get_value(i,1) self.parent.set_title("دواوين العرب - القصائد") self.parent.main_notebook.set_current_page(2) self.parent.poems_page.set_sensitive(True) self.parent.poems_page.set_active(True) n = self.parent.viewerpoem.get_n_pages() for s in range(n): ch = self.parent.viewerpoem.get_nth_page(s) if self.parent.viewerpoem.get_tab_label(ch).nm == text: self.parent.viewerpoem.set_current_page(s) return sr = ShowPoem(self.parent) sr.loading(id_poem, self.parent.theme.fontmp) self.parent.viewerpoem.append_page(sr,TabLabel(sr, text)) self.parent.viewerpoem.show_all() self.parent.viewerpoem.set_current_page(-1)
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()