def build(self, font='Simplified Naskh 18'): size = self.parent.get_size() self.width_window = size[0]-240 if self.view_poem.get_allocated_width() > 100: self.width_window = self.view_poem.get_allocated_width() b_a = daw_config.getn('b_abiat')*2 self.font = font self.size_font = int(self.font[-2:]) label = Gtk.Label() label.override_font(Pango.FontDescription(self.font)) if self.naw3 != 5: if daw_tools.is_machtor(self.text_poem): arodh = 1 else: arodh = 0 self.new_poem, self.t = daw_tools.length_Half(self.text_poem, label, self.length, self.size_font, self.width_window, arodh) poem = self.new_poem poem = self.speaker+poem self.view_poem_bfr.set_text(poem) daw_customs.with_tag(self.view_poem_bfr, self.speaker_poem_tag, [self.speaker,]) self.view_poem.override_font(Pango.FontDescription(self.font)) self.view_poem.set_pixels_below_lines((self.size_font*b_a)/3) self.view_poem.set_pixels_above_lines((self.size_font*b_a)/3)
def load_poem(label, list_verses, long_verse, long_tatwil, long_space, size_font, width_window): poem = u'' max_v = int(daw_config.getf('max_long')) min_v = int(daw_config.getf('min_long')) b_h = (daw_config.getn('b_half')+1)*2 half_space = (width_window-30)/2 if half_space >= long_verse*5/6: v = (long_verse*2)/3 else: v = (2*half_space)-long_verse if daw_config.getf('tarakeb') == 0 or long_verse > max_v or \ long_verse > half_space-((size_font*b_h)/2) or min_v > half_space-((size_font*b_h)/2): t = 2 for a in list_verses: if a[1] == 'title': poem += right_space(a[0])+'\n' elif a[1] == 'half': poem += re.sub('\n\n', '\n', ta3dil(a[0], label, long_verse, long_tatwil, long_space)+'\n') else: h1 = ta3dil(a[0], label, long_verse, long_tatwil, long_space) h2 = ta3dil(a[1], label, long_verse, long_tatwil, long_space) poem += h1+u' '*(v/long_space)+u'\n' poem += u' '*(v/long_space)+h2+u'\n' else: t = 1 for a in list_verses: if a[1] == 'title': poem += right_space(a[0])+'\n' elif a[1] == 'half': poem += re.sub('\n\n', '\n', ta3dil(a[0], label, long_verse, long_tatwil, long_space)+'\n') else: h1 = ta3dil(a[0], label, long_verse, long_tatwil, long_space) h2 = ta3dil(a[1], label, long_verse, long_tatwil, long_space) poem += h1 poem += u' '*(size_font*b_h/long_space) poem += h2+u'\n' return poem, t #ddd = u''' #هَلِ البابُ مَفروجٌ فَأنظر نظرةً * بِعينيَ أَرضاً عزّ عندي مرامها #فَيا حبّذا الدهنا وَطيبُ تُرابِها * وَأَرضٌ فضاءٌ يصدح الليلُ هامها #''' #print rawi_poem(ddd)
def ok_poet(self, *a): model, i = self.sel_poet.get_selected() if i: id_poet = model.get_value(i,0) list_poems, tarjama = self.db.poems_of_poet(id_poet) self.tarjama_bfr.set_text(tarjama) ls = [tarjama.splitlines(1)[0],] daw_customs.with_tag(self.tarjama_bfr, self.tarjama_tag, ls) self.poems_store.clear() n = self.notebook.get_current_page() if n > 1: self.notebook.set_current_page(daw_config.getn('open')) if len(list_poems) != 0: self.names_list0 = [] self.modelfilter0 = self.poems_store.filter_new() for a in list_poems: i = a[0] rakm = list_poems.index(a, )+1 name = a[1] abiat = a[2] if a[3] != 0: baher = daw_tools.get_name(daw_tools.elbehor, a[3]) else: baher = u'____' if a[4] != 0: rawi = daw_tools.get_name(daw_tools.elrawi, a[4]) else: rawi = u'____' if a[6] != 0: gharadh = daw_tools.get_name(daw_tools.elgharadh, a[6]) else: gharadh = u'____' if a[7] != 0: naw3 = daw_tools.get_name(daw_tools.elnaw3, a[7]) else: naw3 = u'____' self.poems_store.append([i, rakm, name, naw3, baher, gharadh, rawi, abiat]) self.names_list0.append(name) self.theword0 = self.names_list0[:] self.modelfilter0.set_visible_func(self.visible_cb0, self.theword0) self.tree_poems.set_model(self.modelfilter0) lab = ' .: {} :. عدد القصائد : {} ، عدد الأبيات : {}'.format((self.db.name_poet(id_poet)[1]).encode('utf8'), self.db.n_poems_poet(id_poet).decode('utf8'), self.db.n_verses_poet(id_poet).decode('utf8')) self.lab_count.set_label(lab)
def build(self,*a): Gtk.Dialog.__init__(self, parent=self.parent) self.set_icon_name("Dawawin") self.set_title("التفضيلات") self.resize(500, 300) area = self.get_content_area() area.set_spacing(6) self.connect('delete-event', lambda w,*a: w.hide() or True) self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) lab_info = Gtk.Label('بعض الخيارات قد تحتاج إلى إعادة تشغيل البرنامج') lab_info.override_background_color(Gtk.StateFlags.NORMAL, daw_customs.rgba('#FFF14E')) lab_info.override_color(Gtk.StateFlags.NORMAL, daw_customs.rgba('#E90003')) lab_info.override_font(Pango.FontDescription("8")) self.notebook = Gtk.Notebook() self.box0 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.box00 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.box1 = Gtk.Box(spacing=4, orientation=Gtk.Orientation.VERTICAL) self.box2 = Gtk.Box(spacing=4,orientation=Gtk.Orientation.VERTICAL) hbox = Gtk.Box(spacing=40,orientation=Gtk.Orientation.HORIZONTAL) hbox.pack_start(self.box1, False, False, 0) hbox.pack_start(self.box2, False, False, 0) self.frame = Gtk.Frame() self.frame.add(hbox) hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) self.dfo = Gtk.RadioButton.new_with_label_from_widget(None, 'افتراضي') self.cos = Gtk.RadioButton.new_with_label_from_widget(self.dfo,'مخصص') self.dfo.connect('toggled',self.specified,'0') self.cos.connect('toggled',self.specified,'1') hbox.pack_start(self.dfo, False, False, 0) hbox.pack_start(self.cos, False, False, 0) self.sel_theme = Gtk.CheckButton('تلوين النافذة') hbox.pack_end(self.sel_theme, False, False, 0) if daw_config.getv('theme') == '1': self.sel_theme.set_active(True) else: self.sel_theme.set_active(False) self.sel_theme.connect("toggled", self.has_mytheme) hbox.set_border_width(5) self.box0.pack_start(hbox, False, False, 0) self.box0.pack_start(self.frame, True, True, 0) list_w1 = [[u'القوائم الجانبية','td'], [u'قائمة القصائد','tp'], [u'متن القصيدة','mp'], [u'الشرح والترجمة','ch'], [u'العناوين','an']] list_w2 = [[u'لون خلفية العرض','b'], [u'لون خط التحديد','fs'], [u'لون خلفية التحديد','bs'], [u'لون تحديد البحث','ss'], [u'لون خلفية خاص','bp']] for a in list_w1: hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) btn1 = Gtk.ToolButton(stock_id = Gtk.STOCK_SELECT_FONT) btn1.set_name('font'+a[1]) btn1.connect('clicked',self.ch_font) btn2 = Gtk.ToolButton(stock_id = Gtk.STOCK_SELECT_COLOR) btn2.set_name('color'+a[1]) btn2.connect('clicked',self.ch_color) hbox.pack_start(btn2, False, False, 0) hbox.pack_start(btn1, False, False, 0) hbox.pack_start(Gtk.Label(a[0]), False, False, 0) self.box1.pack_start(hbox, False, False, 0) for a in list_w2: hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) btn = Gtk.ToolButton(stock_id = Gtk.STOCK_SELECT_COLOR) btn.set_name('color'+a[1]) btn.connect('clicked',self.ch_color) hbox.pack_start(btn, False, False, 0) hbox.pack_start(Gtk.Label(a[0]), False, False, 0) self.box2.pack_start(hbox, False, False, 0) self.notebook.append_page(self.box0, Gtk.Label('خط ولون')) vb = Gtk.VBox(False, 6) vb.set_border_width(6) ls = [[0, u'ضيق'], [1, u'وسط'], [2, u'واسع']] hb, self.bayn_abiat = daw_customs.combo(ls, u'المسافة بين الأبيات', 3) self.bayn_abiat.set_active(daw_config.getn('b_abiat')) self.bayn_abiat.connect('changed', self.change_vls, u'b_abiat') vb.pack_start(hb, False, False, 0) ls = [[0, u'ضيق'], [1, u'وسط'], [2, u'واسع']] hb, self.bayn_shater = daw_customs.combo(ls, u'المسافة بين شطري البيت', 3) self.bayn_shater.set_active(daw_config.getn('b_half')) self.bayn_shater.connect('changed', self.change_vls, u'b_half') vb.pack_start(hb, False, False, 0) ls = [[0, u'دوما'], [1, u'للحاجة']] hb, self.tarakeb = daw_customs.combo(ls, u'تراكب شطري البيت', 3) self.tarakeb.set_active(daw_config.getn('tarakeb')) self.tarakeb.connect('changed', self.change_vls, u'tarakeb') vb.pack_start(hb, False, False, 0) ls = [[0, u'بالتطويلات'], [1, u'بالمسافات']] hb, self.tandhid = daw_customs.combo(ls, u'تعديل طول الشطر', 3) self.tandhid.set_active(daw_config.getn('tandhid')) self.tandhid.connect('changed', self.change_vls, u'tandhid') vb.pack_start(hb, False, False, 0) hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) lab = Gtk.Label('أدنى طول للشطر بالبكسلات') lab.set_alignment(0,0.5) hbox.pack_start(lab, False, False, 0) adj = Gtk.Adjustment(150, 100, 700, 1, 5, 0) self.min_long = Gtk.SpinButton() self.min_long.set_adjustment(adj) self.min_long.set_wrap(True) self.min_long.set_value(daw_config.getf('min_long')) def change_min(widget, *a): v = self.min_long.get_value() daw_config.setv('min_long', v) self.min_long.connect('value-changed', change_min) hbox.pack_start(self.min_long, False, False, 0) vb.pack_start(hbox, False, False, 0) hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) lab = Gtk.Label('التراكب إذا تجاوز طول الشطر') lab.set_alignment(0,0.5) hbox.pack_start(lab, False, False, 0) adj = Gtk.Adjustment(350, 300, 1000, 1, 5, 0) self.max_long = Gtk.SpinButton() self.max_long.set_adjustment(adj) self.max_long.set_wrap(True) self.max_long.set_value(daw_config.getf('max_long')) def change_max(widget, *a): v = self.max_long.get_value() daw_config.setv('max_long', v) self.max_long.connect('value-changed', change_max) hbox.pack_start(self.max_long, False, False, 0) vb.pack_start(hbox, False, False, 0) self.notebook.append_page(vb, Gtk.Label('تخطيط')) vb = Gtk.VBox(False, 6) vb.set_border_width(6) hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) self.del_all = daw_customs.ButtonClass('مسح عام') self.del_all.connect('clicked', self.del_all_cb) hbox.pack_start(self.del_all, False, False, 0) vb.pack_start(hbox, False, False, 0) hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) self.add_db = daw_customs.ButtonClass('أنشاء قاعدة بيانات جديدة') self.add_db.connect('clicked', self.new_db) hbox.pack_start(self.add_db, False, False, 0) if not exists(dirname(daw_config.getv('path'))): self.add_db.set_sensitive(False) vb.pack_start(hbox, False, False, 0) hbox = Gtk.Box(spacing=6,orientation=Gtk.Orientation.HORIZONTAL) self.e_dest = Gtk.Entry() self.e_dest.set_text(daw_config.getv('path').decode('utf8')) self.b_dest = daw_customs.ButtonClass('تغيير المسار') self.b_dest.connect('clicked', self.change_path_db) hbox.pack_start(self.b_dest, False, False, 0) hbox.pack_start(self.e_dest, True, True, 0) vb.pack_start(hbox, False, False, 0) hbox = Gtk.Box(spacing=6,orientation=Gtk.Orientation.HORIZONTAL) db_void = Gtk.LinkButton.new_with_label("http://sourceforge.net/projects/dawawin/files/", 'صفحة البرنامج على النت') hbox.pack_start(db_void, False, False, 0) vb.pack_start(hbox, False, False, 0) self.notebook.append_page(vb, Gtk.Label('خيارات')) vb = Gtk.VBox(False, 6) vb.set_border_width(6) self.n_dawawin = Gtk.Label('عدد الدواوين : '+daw_config.getv('n_dawawin')) self.n_dawawin.set_alignment(0,0.5) vb.pack_start(self.n_dawawin, False, False, 0) self.n_poems = Gtk.Label('عدد القصائد : '+daw_config.getv('n_poems')) self.n_poems.set_alignment(0,0.5) vb.pack_start(self.n_poems, False, False, 0) self.n_verses = Gtk.Label('عدد الأبيات : '+daw_config.getv('n_verses')) self.n_verses.set_alignment(0,0.5) vb.pack_start(self.n_verses, False, False, 0) hbox = Gtk.Box(spacing=6,orientation=Gtk.Orientation.HORIZONTAL) self.rapid_count = daw_customs.ButtonClass('إحصاء سريع') self.rapid_count.connect('clicked', self.count_cb) self.detail_count = daw_customs.ButtonClass('إحصاء مفصل') self.detail_count.connect('clicked', self.show_count) self.web_count = daw_customs.ButtonClass('صفحة ويب') self.web_count.connect('clicked', lambda *a: self.parent.countpage.make_html()) hbox.pack_start(self.rapid_count, False, False, 0) hbox.pack_start(self.detail_count, False, False, 0) hbox.pack_start(self.web_count, False, False, 0) vb.pack_end(hbox, False, False, 0) self.notebook.append_page(vb, Gtk.Label('إحصاء')) vbox = Gtk.Box(spacing=4, orientation=Gtk.Orientation.VERTICAL) hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) self.sel_ornament = Gtk.CheckButton('اعتمد زخرفة الخلفية') hbox.pack_start(self.sel_ornament, False, False, 0) if daw_config.getv('ornament') == '1': self.sel_ornament.set_active(True) else: self.sel_ornament.set_active(False) self.sel_ornament.connect("toggled", self.has_ornament) vbox.pack_start(hbox, False, False, 0) liststore = Gtk.ListStore(Pixbuf, str) iconview = Gtk.IconView.new() iconview.set_model(liststore) iconview.set_pixbuf_column(0) iconview.set_reorderable(True) list_icons = os.listdir(daw_customs.ORNAMENT) iconview.set_columns(6) iconview.connect('item-activated', self.sel_ORNAMENT) for a in list_icons: try: pixbuf = Pixbuf.new_from_file_at_size(join(daw_customs.ORNAMENT, a), 64, 64 ) liststore.append([pixbuf, a]) except: pass scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(iconview) scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) vbox.pack_start(scroll, True, True, 0) self.notebook.append_page(vbox, Gtk.Label('الزخرفة')) self.box.pack_start(self.notebook, True, True, 0) self.box.pack_start(lab_info, False, False, 0) clo = daw_customs.ButtonClass("إغلاق") clo.connect('clicked',lambda *a: self.hide()) ref = daw_customs.ButtonClass("تحديث الواجهة") ref.connect('clicked',lambda *a: self.parent.theme.refrech()) ref.connect('clicked',lambda *a: self.parent.refrech()) hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) hbox.set_border_width(5) hbox.pack_start(ref, False, False, 0) hbox.pack_end(clo, False, False, 0) self.box.pack_start(hbox, False, False, 0) if daw_config.getv('tr') == '1': self.cos.set_active(True) else: self.frame.set_sensitive(False) self.dfo.set_active(True) area.pack_start(self.box, True, True, 0)
def __init__(self, parent): self.parent = parent self.db = MyDB() self.size_font = int(self.parent.theme.fontch[-2:]) Gtk.HPaned.__init__(self) self.vbox = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL) hb, self.ages = daw_customs.combo(daw_tools.age_poet, u'العصر', 1) self.vbox.pack_start(hb, False, False, 0) self.ages.connect('changed', self.search_cb) self.ages.connect('changed', self.select_age) hb, self.lands = daw_customs.combo(daw_tools.elbalad, u'البلد', 1) self.lands.set_sensitive(False) self.vbox.pack_start(hb, False, False, 0) self.lands.connect('changed', self.search_cb) hb, self.sexs = daw_customs.combo(daw_tools.sex_poet, u'الجنس', 1) self.vbox.pack_start(hb, False, False, 0) self.sexs.connect('changed', self.search_cb) try: self.search_poets = Gtk.SearchEntry() except: self.search_poets = Gtk.Entry() self.search_poets.set_placeholder_text('بحث عن شاعر') self.search_poets.connect('changed', self.search_cb) hbox = Gtk.HBox(False, 2) # self.btn_refresh = Gtk.ToolButton(Gtk.STOCK_REFRESH) # self.btn_refresh.set_tooltip_text('تحديث قائمة الدواوين') # self.btn_refresh.connect('clicked', self.refresh_poets) # hbox.pack_start(self.btn_refresh, False, False, 0) hbox.pack_start(self.search_poets, True, True, 0) self.vbox.pack_start(hbox, False, False, 0) self.tree_poet = daw_customs.TreeClass() cell = Gtk.CellRendererText() cell.set_property("wrap-mode", Pango.WrapMode.WORD_CHAR) cell.set_property("wrap-width", 200) kal = Gtk.TreeViewColumn('دواوين الشعراء', cell, text=1) self.tree_poet.append_column(kal) self.store_poet = Gtk.ListStore(int, str, int, int, int) self.refresh_poets() # self.store_poet.clear() # ls = self.db.all_poets() # ls.append([0, u'ما لا يعرف قائله', 0, 22, 9]) # self.names_list = [] # for a in ls: # s_list = [] # self.store_poet.append(a) # s_list.append(a[1]) # s_list.append(a[2]) # s_list.append(a[3]) # s_list.append(a[4]) # self.names_list.append(s_list) # self.theword = self.names_list[:] # self.modelfilter.set_visible_func(self.visible_cb, self.theword) # self.tree_poet.set_model(self.modelfilter) self.sel_poet = self.tree_poet.get_selection() self.tree_poet.connect("cursor-changed", self.ok_poet) scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(self.tree_poet) scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.vbox.pack_start(scroll, True, True, 0) #self.tree_poet.scroll_to_cell(0, kal, False, 1.0, 1.0) vbox2 = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL) self.notebook = Gtk.Notebook() self.notebook.set_scrollable(True) self.tarjama = daw_customs.ViewClass() self.tarjama_bfr = self.tarjama.get_buffer() self.tarjama_tag = self.tarjama_bfr.create_tag("title") scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(self.tarjama) self.notebook.append_page(scroll, Gtk.Label("الترجمة")) self.notebook.set_current_page(-1) self.poems_store = Gtk.ListStore(int,int,str,str,str,str,str,int) self.tree_poems = daw_customs.TreePoem() vbox = Gtk.VBox(False, 2) self.lab_count = Gtk.Label(' .: :. عدد القصائد : ، عدد الأبيات : ') self.lab_count.set_alignment(0, 0.5) vbox.pack_start(self.lab_count, False, False, 0) self.tree_poems.set_grid_lines(Gtk.TreeViewGridLines.HORIZONTAL) self.tree_poems.connect("button-press-event", self.on_button_press) raq = Gtk.TreeViewColumn('الرقم', Gtk.CellRendererText(), text=1) raq.set_max_width(30) self.tree_poems.append_column(raq) poems = Gtk.TreeViewColumn('القصيدة', Gtk.CellRendererText(), text=2) self.tree_poems.append_column(poems) poems.set_max_width(300) elnaw3 = Gtk.TreeViewColumn('النوع', Gtk.CellRendererText(), text=3) self.tree_poems.append_column(elnaw3) elnaw3.set_max_width(100) elbaher = Gtk.TreeViewColumn('البحر', Gtk.CellRendererText(), text=4) self.tree_poems.append_column(elbaher) elbaher.set_max_width(120) elgharadh = Gtk.TreeViewColumn('الغرض', Gtk.CellRendererText(), text=5) self.tree_poems.append_column(elgharadh) elgharadh.set_max_width(80) elrawi = Gtk.TreeViewColumn('الروي', Gtk.CellRendererText(), text=6) self.tree_poems.append_column(elrawi) elrawi.set_max_width(50) verses = Gtk.TreeViewColumn('عدد الأبيات', Gtk.CellRendererText(), text=7) self.tree_poems.append_column(verses) verses.set_max_width(50) scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(self.tree_poems) vbox.pack_start(scroll, True, True, 0) self.notebook.append_page(vbox, Gtk.Label("القصائد")) self.notebook.set_current_page(-1) def switch(widget, *a): n = self.notebook.get_current_page() daw_config.setv('open', n) self.notebook.connect('set-focus-child', switch) vbox2.pack_start(self.notebook, True, True, 0) self.pack1(self.vbox, False, False) self.pack2(vbox2, True, False) self.show_all() self.change_font() self.notebook.set_current_page(daw_config.getn('open')) #--- Popup menu self.popup = Gtk.Menu() show_poem = Gtk.ImageMenuItem('اعرض القصيدة') show_poem.connect('activate', self.show_poem_cb) self.popup.append(show_poem) modify_poem = Gtk.ImageMenuItem('عدّل القصيدة') modify_poem.connect('activate', self.modify_poem_cb) self.popup.append(modify_poem) self.popup.show_all()