# Unicode char searcher # Copyright 2003 Nathan Hurst # Licensed under GPL import pygtk pygtk.require('2.0') import gtk import pango def draw_pango_string(widget, gc, s, x, y): context = widget.get_pango_context() pfd = pango.FontDescription("Sans 10") context.set_font_description(pfd) pl = pango.Layout(context); pl.set_width(1024*1000); pl.set_markup(s); gtk.gdk.Drawable.draw_layout(widget.window, gc, x, y, pl); window = gtk.Window() vbox = gtk.VBox(gtk.FALSE, 0) current_x,current_y = 0,0 gridspace = 16 def redraw_da(widget, event): xsize,ysize = widget.get_allocation().width,widget.get_allocation().height cx = xsize /2 cy = ysize/2 drawable = widget.window black_gc = widget.get_style().black_gc #for i in range(xsize/gridspace): # gtk.gdk.Drawable.draw_line(drawable, # black_gc, # i*gridspace, 0, # i*gridspace, ysize) #for i in range(ysize/gridspace): # gtk.gdk.Drawable.draw_line(drawable, # black_gc, # 0, i*gridspace, # ysize, i*gridspace) global notebook,baselist base = baselist[notebook.get_current_page()] for i in range(xsize/gridspace): for j in range(ysize/gridspace): c = i + j*(xsize/gridspace) + base if(c >= 0x20): draw_pango_string(widget, black_gc, "&#%d;" % c, i*gridspace,j*gridspace) global current_x,current_y gtk.gdk.Drawable.draw_rectangle(drawable, black_gc, 0, current_x*gridspace, current_y*gridspace, gridspace, gridspace) import unicodedata c = current_x + current_y*int(xsize/gridspace) + base name = "" try: name = unicodedata.name(unichr(c)) except: pass label.set_text("%d (0x%x) : %s" % (c, c, name)) notebook = gtk.Notebook() notebook.set_scrollable(1) baselist = range(0,0x1400, 0x100) + [0x1680,0x2000] for i in baselist: notebook.append_page(gtk.DrawingArea(),gtk.Label("0x%x" % i)) vbox.pack_start(notebook, 0, 0, 0) da = gtk.DrawingArea() vbox.pack_start(da, 1, 1, 0) da.set_size_request(256,256) da.connect('expose-event', redraw_da) label = gtk.Label('') vbox.pack_start(label, 0, 0, 0) def mouse_click(widget,event): xsize,ysize = widget.get_allocation().width,widget.get_allocation().height def drag_motion(widget, event): xsize,ysize = widget.get_allocation().width,widget.get_allocation().height global current_x, current_y current_x,current_y = int(event.x/gridspace), int(event.y/gridspace) widget.queue_draw() da.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK ) da.connect("button-press-event", mouse_click) da.connect("motion-notify-event", drag_motion) window.add(vbox) window.connect('destroy', lambda win: gtk.main_quit()) window.show_all() gtk.mainloop()