Exemple #1
0
 def __init__(self, pvg, parent=None):
 
     #gtk.Window.__init__(self)
     gtk.DrawingArea.__init__(self)
     
     www = gtk.gdk.screen_width();
     hhh = gtk.gdk.screen_height();
     
     #self.set_size_request(www/4, hhh/8)
     self.set_size_request(20, 20)
     
     self.lgap = 60; self.rgap = 20
     self.pangolayout = self.create_pango_layout("a")
     fd = pango.FontDescription()
     self.colormap = gtk.widget_get_default_colormap()
     self.textcol = self.colormap.alloc_color("#808080")
     self.clear()
     self.set_flags(gtk.CAN_FOCUS | gtk.SENSITIVE)
     self.set_events(  gtk.gdk.POINTER_MOTION_MASK |
                         gtk.gdk.POINTER_MOTION_HINT_MASK |
                         gtk.gdk.BUTTON_PRESS_MASK |
                         gtk.gdk.BUTTON_RELEASE_MASK |
                         gtk.gdk.KEY_PRESS_MASK |
                         gtk.gdk.KEY_RELEASE_MASK |
                         gtk.gdk.FOCUS_CHANGE_MASK )
                         
     self.connect("expose-event", self.area_expose_cb)
     self.connect("motion-notify-event", self.area_motion)
     self.connect("button-press-event", self.area_button)
     self.connect("button-release-event", self.area_button)
Exemple #2
0
    def __init__(self, wwww=100, hhhh=100):

        gtk.DrawingArea.__init__(self)

        self.pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 300, 300)
        self.divider = DIVIDER
        self.wwww = wwww
        self.hhhh = hhhh
        self.set_size_request(wwww, hhhh)

        self.annote = []
        self.aframe = []
        self.atext = []

        self.mag = False
        self.event_x = self.event_y = 0
        self.image = None
        self.colormap = gtk.widget_get_default_colormap()

        self.set_flags(gtk.CAN_FOCUS | gtk.SENSITIVE)

        #self.area.set_events(gtk.gdk.ALL_EVENTS_MASK)

        self.set_events(gtk.gdk.POINTER_MOTION_MASK
                        | gtk.gdk.POINTER_MOTION_HINT_MASK
                        | gtk.gdk.BUTTON_PRESS_MASK
                        | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.KEY_PRESS_MASK
                        | gtk.gdk.KEY_RELEASE_MASK | gtk.gdk.FOCUS_CHANGE_MASK)

        self.connect("key-press-event", self.key_press_event)
        self.connect("button-press-event", self.area_button)
        self.connect("expose-event", self.expose)
        self.connect("motion-notify-event", self.area_motion)
Exemple #3
0
 def __init__(self):
     gtk.DrawingArea.__init__(self)
     self.set_flags(gtk.CAN_FOCUS | gtk.SENSITIVE)
     self.set_events(    gtk.gdk.ALL_EVENTS_MASK )
     self.pangolayout = self.create_pango_layout("a")
     self.connect("expose-event", self.area_expose_cb)
     self.colormap = gtk.widget_get_default_colormap()        
     self.items = []; self.coords = []; self.curr = 0
     self.scrolly = 0;  self.scrollx = 0
     self.limit = 1000
     self.txcol = self.colormap.alloc_color(FGCOLOR)
     self.bgcol = self.colormap.alloc_color(BGCOLOR)
     self.hlcol = self.colormap.alloc_color(HICOLOR)
     
     # Get Pango steps
     self.cxx, self.cyy = self.pangolayout.get_pixel_size()
     
     # Create scroll items        
     #sm = len(self.items) + self.get_height() / self.cyy + 10        
     self.hadj = gtk.Adjustment(0, 0, 200, 1, 15, 25);
     self.vadj = gtk.Adjustment(0, 0, 200, 1, 15, 25)
     
     self.vscroll = gtk.VScrollbar(self.vadj)
     self.hscroll = gtk.HScrollbar(self.hadj)
     
     # We connect scrollers after construction
     self.hadj.connect("value-changed", self.hscroll_cb)
     self.vadj.connect("value-changed", self.vscroll_cb)
     
     self.connect("key-press-event", self.key_press_event)        
     self.connect("button-press-event", self.button_press_event)        
Exemple #4
0
 def expose(self, area, a3):
     winn = self.area.window
     rc = area.get_allocation()
     gc = gtk.gdk.GC(winn);
     colormap = gtk.widget_get_default_colormap()        
     
     winn.draw_pixbuf( gc, self.image2.get_pixbuf(), 0, 0, 0, 0)
Exemple #5
0
    def _drawcaret(self):

        #print "drawing caret", self.caret[0], self.caret[1], \
        #        self.caret[0] * self.cxx, self.caret[1] * self. cyy

        colormap = gtk.widget_get_default_colormap()
        if self.focus:
            color = colormap.alloc_color("#008888")
        else:
            color = colormap.alloc_color("#aaaaaa")

        gcx = gtk.gdk.GC(self.window)
        gcx.copy(self.gc)
        gcx.set_foreground(color)

        xx = self.caret[0] * self.cxx  #+ self.cxx / 2
        yy = self.caret[1] * self.cyy
        cw = self.cxx / 2

        # The actual caret. Change drawing instructions for a different caret.
        # Order: Top, left right, buttom
        if self.focus:
            self.window.draw_line(gcx, xx, yy, xx + cw, yy)
        self.window.draw_line(gcx, xx + 1, yy, xx + 1, yy + self.cyy)
        self.window.draw_line(gcx, xx + 3, yy, xx + 3, yy + self.cyy)
        if self.focus:
            self.window.draw_line(gcx, xx, yy + self.cyy, xx + cw,
                                  yy + self.cyy)
Exemple #6
0
    def area_expose_cb(self, area, event):
        rect = self.get_allocation()
        www = rect.width
        hhh = rect.height
        style = self.get_style()
        self.gc = style.fg_gc[gtk.STATE_NORMAL]
        colormap = gtk.widget_get_default_colormap()
        gcr = gtk.gdk.GC(self.window)
        gcr.copy(self.gc)
        gcr.set_foreground(colormap.alloc_color(BGCOLOR))
        self.window.draw_rectangle(gcr, True, 0, 0, www - 1, hhh - 1)

        gct = gtk.gdk.GC(self.window)
        gcr.copy(self.gc)

        foreground = None
        background = None
        for aa in self.txtarr:
            if aa[0] == TEXT:
                self.setfont(aa[6], aa[5])
                try:
                    foreground = colormap.alloc_color(aa[4])
                except:
                    pass
                self.pangolayout.set_text(aa[3])
                self.window.draw_layout(gct, aa[1], aa[2], \
                            self.pangolayout, foreground, background)

            if aa[0] == RECT:
                try:
                    foreground = colormap.alloc_color(aa[5])
                except:
                    pass

                gcr.set_foreground(colormap.alloc_color(foreground))
                self.window.draw_rectangle(gcr, True, aa[1], aa[2], \
                                    aa[3], aa[4])

            if aa[0] == CIRC:
                try:
                    foreground = colormap.alloc_color(aa[5])
                except:
                    pass

                gcr.set_foreground(colormap.alloc_color(foreground))
                self.window.draw_arc(gcr, True, aa[1], aa[2], \
                                    aa[3], aa[4], 0, 360 * 64)

            if aa[0] == LINE:
                try:
                    foreground = colormap.alloc_color(aa[5])
                except:
                    pass
                gcr.set_foreground(colormap.alloc_color(foreground))
                self.window.draw_line(gcr, aa[1], aa[2], \
                                        aa[3], aa[4])
Exemple #7
0
 def post_expose_cb(self, area, event):
     hhh = self.get_height()
     www = self.get_width()
     style = self.window.get_style()
     self.gc = style.fg_gc[gtk.STATE_NORMAL]
     colormap = gtk.widget_get_default_colormap()
     gcr = gtk.gdk.GC(self.window.window)
     gcr.copy(self.gc)
     gcr.set_foreground(colormap.alloc_color(BGCOLOR))
     self.vbox.window.draw_rectangle(gcr, True, 0, 0, www - 1, hhh - 1)
Exemple #8
0
    def area_expose_cb(self, area, event):

        #print "area_expose_cb()", event.area.width, event.area.height

        hhh = self.get_height()
        xlen = len(self.text)

        style = self.get_style()
        self.gc = style.fg_gc[gtk.STATE_NORMAL]

        # Paint text
        xx = 0
        yy = 0
        cnt = self.ypos
        while cnt < xlen:
            dx, dy = self._draw_text(self.gc, xx, yy, self.text[cnt])
            cnt = cnt + 1
            yy += dy
            if yy > hhh:
                break

        # Paint selection
        colormap = gtk.widget_get_default_colormap()
        bgcolor = colormap.alloc_color("#4488ff")
        color = colormap.alloc_color("#000000")
        gcx = gtk.gdk.GC(self.window)
        gcx.copy(self.gc)

        xx = 0
        yy = 0
        cnt = self.ypos

        # Normalize
        xssel = min(self.xsel, self.xsel2)
        xesel = max(self.xsel, self.xsel2)
        yssel = min(self.ysel, self.ysel2)
        yesel = max(self.ysel, self.ysel2)

        if xssel != -1:
            while cnt < xlen:
                if cnt >= yssel and cnt <= yesel:
                    line = self.text[cnt]
                    self._draw_text(gcx, xssel * self.cxx, yy,
                                    line[xssel:xesel], color, bgcolor)
                cnt = cnt + 1
                yy += self.cyy
                if yy > hhh:
                    break

        self._drawcaret()
        return True
Exemple #9
0
    def _drawcaret(self):

        #print "drawing caret", self.caret[0], self.caret[1], \
        #        self.caret[0] * self.cxx, self.caret[1] * self. cyy  
                        
        colormap = gtk.widget_get_default_colormap()
        if self.focus:    
            color = colormap.alloc_color("#008888")
        else:
            color = colormap.alloc_color("#aaaaaa")
        
        gcx = gtk.gdk.GC(self.window); gcx.copy(self.gc)
        gcx.set_foreground(color)
      
        xx = self.caret[0] * self.cxx #+ self.cxx / 2
        yy = self.caret[1] * self.cyy
        cw = self.cxx / 2
        ch = self.cyy / 2

        # The actual caret. Change drawing instructions for a different caret.
        # Order: Top, left right, buttom
        if self.focus:    
            # Flash cursor
            if self.bigcaret:
                rxx = xx + self.cxx
                ly = yy + self.cyy; uy = yy
                mmx = xx + cw; mmy = yy + ch
                dist = 80
                self.window.draw_line(gcx, mmx - dist, uy, mmx + dist, uy)
                self.window.draw_line(gcx, mmx - dist, ly, mmx + dist, ly)
                self.window.draw_line(gcx, xx , mmy - dist, xx, mmy + dist)        
                self.window.draw_line(gcx, rxx , mmy - dist, rxx, mmy + dist)        
            else:
                if self.insert:
                    self.window.draw_line(gcx, xx, yy, xx + cw, yy)
                    self.window.draw_line(gcx, xx + 1, yy, xx + 1, yy + self.cyy )
                    self.window.draw_line(gcx, xx + 3, yy, xx + 3, yy + self.cyy )
                    self.window.draw_line(gcx, xx , yy + self.cyy, xx + cw, yy + self.cyy )
                else:
                    self.window.draw_line(gcx, xx, yy, xx + cw, yy)
                    self.window.draw_line(gcx, xx + 1, yy, xx + 1, yy + self.cyy )
                    self.window.draw_line(gcx, xx + 2, yy, xx + 2, yy + self.cyy )
                    self.window.draw_line(gcx, xx + 3, yy, xx + 3, yy + self.cyy )
                    self.window.draw_line(gcx, xx + 4, yy, xx + 4, yy + self.cyy )
                    self.window.draw_line(gcx, xx , yy + self.cyy, xx + cw, yy + self.cyy )                
        else:
            #self.window.draw_line(gcx, xx, yy, xx + cw, yy)
            self.window.draw_line(gcx, xx + 1, yy + 2, xx + 1, yy -2 + self.cyy )
            self.window.draw_line(gcx, xx + 3, yy + 2, xx + 3, yy -2 + self.cyy )
Exemple #10
0
 def area_expose_cb(self, area, event):
     #print "area_expose_cb()", event.area.width, event.area.height
     
     # We have a window, goto start pos
     hhh = self.get_height();  www = self.get_width()
     #print "www", www, "hhh", hhh
     style = self.window.get_style()
     self.gc = style.fg_gc[gtk.STATE_NORMAL]
     colormap = gtk.widget_get_default_colormap()        
     gcr = gtk.gdk.GC(self.window.window); gcr.copy(self.gc)
     gcr.set_foreground(colormap.alloc_color(BGCOLOR))
     self.window.window.draw_rectangle(gcr, True, 0, 0, www - 1, hhh - 1)
     
     gct = gtk.gdk.GC(self.window.window); gcr.copy(self.gc)
     
     foreground = None; background = None
     for aa in self.txtarr:
         print aa
         
         if aa[0] == TEXT:
             self.setfont(aa[6], aa[5])
             try:
                 foreground = colormap.alloc_color(aa[4])
             except: pass
             self.pangolayout.set_text(aa[3])            
             self.window.window.draw_layout(gct, aa[1], aa[2], \
                         self.pangolayout, foreground, background)
             
         if aa[0] == RECT:
             try:
                 foreground = colormap.alloc_color(aa[5])
             except: pass
             
             gcr.set_foreground(colormap.alloc_color(foreground))
             self.window.window.draw_rectangle(gcr, True, aa[1], aa[2], \
                                 aa[3], aa[4])
         
         if aa[0] == CIRC:
             try:
                 foreground = colormap.alloc_color(aa[5])
             except: pass
             
             gcr.set_foreground(colormap.alloc_color(foreground))
             self.window.window.draw_arc(gcr, True, aa[1], aa[2], \
                                 aa[3], aa[4], 0, 360 * 64)
         
     return True
Exemple #11
0
    def __expose_event(self, widget, event):
    
        #print "__expose_event"
        
        gldrawable = widget.get_gl_drawable()
        glcontext = widget.get_gl_context()

        if not gldrawable.gl_begin(glcontext):
            return

        glViewport (0, 0, self.width, self.height)

        # OpenGL begin.
        glMatrixMode (GL_MODELVIEW)
        
        glPushMatrix()
        glLoadIdentity ()
        glRenderMode(GL_RENDER)
        self.renderscene(True)
        glPopMatrix()
        
        if 1: #showall:
            style = self.glarea.get_style()
            self.gc = style.fg_gc[gtk.STATE_NORMAL]
            gcx = gtk.gdk.GC(self.glarea.window); gcx.copy(self.gc)
            gcr = gtk.gdk.GC(self.glarea.window); gcr.copy(self.gc)
            colormap = gtk.widget_get_default_colormap()        
            gcr.set_foreground(colormap.alloc_color("#ff0000"))

            for vv in self.arr:
                aa,bb,cc = vv.vertex
                aa=int(aa); bb=int(bb); cc=int(cc)
                bb = self.height-bb
                self.glarea.window.draw_line(gcr, aa, bb, aa+10, bb+10)
                #self.win.window.draw_line(gcr, bb, cc)
          
                #print aa,bb,cc
                #glPushMatrix()
                #glTranslatef (aa/self.width, bb/self.height, cc)
                #gtk.gdkgl.draw_sphere (True, 0.05, 20, 20)
                #glPopMatrix()
      
        if gldrawable.is_double_buffered():
            gldrawable.swap_buffers()
        else:
            glFlush()
        gldrawable.gl_end()
Exemple #12
0
    def _drawcaret(self):

        #print "drawing caret", self.caret[0], self.caret[1], \
        #        self.caret[0] * self.cxx, self.caret[1] * self. cyy  
                
        colormap = gtk.widget_get_default_colormap()
        color = colormap.alloc_color("#008888")
        
        gcx = gtk.gdk.GC(self.window); gcx.copy(self.gc)
        gcx.set_foreground(color)
      
        xx = self.caret[0] * self.cxx #+ self.cxx / 2
        yy = self.caret[1] * self.cyy
        cw = self.cxx / 2

        # Top, left right, buttom
        self.window.draw_line(gcx, xx, yy, xx + cw, yy)
        self.window.draw_line(gcx, xx + 1, yy, xx + 1, yy + self.cyy )
        self.window.draw_line(gcx, xx + 3, yy, xx + 3, yy + self.cyy )
        self.window.draw_line(gcx, xx , yy + self.cyy, xx + cw, yy + self.cyy )
Exemple #13
0
    def area_expose_cb(self, area, event):
        #print "expose", area, event, len(self.coords)
        ww, hh = area.window.get_size()
        style = self.get_style()
        self.gc = style.fg_gc[gtk.STATE_NORMAL]
        gcx = gtk.gdk.GC(self.window); gcx.copy(self.gc)
        gcr = gtk.gdk.GC(self.window); gcr.copy(self.gc)
        colormap = gtk.widget_get_default_colormap()        
        gcr.set_foreground(colormap.alloc_color("#ff0000"))

        if len(self.coords) > 1:
            olda = self.coords[0][0]; oldb = self.coords[0][1]
            for aa, bb, cc in self.coords:
                if cc != 0:
                    area.window.draw_line(gcr, olda, oldb, aa, bb)
                olda = aa; oldb = bb
        
        # Draw text
        gcr.set_foreground(colormap.alloc_color("#000080"))
        ttt = "Text in custom View"
        self.pangolayout.set_text(ttt)
        xx, yy = self.pangolayout.get_pixel_size()
        area.window.draw_layout(gcr, ww / 2 - xx / 2 + self.lgap / 2, 5, self.pangolayout)
Exemple #14
0
    def expose(self, area, a3):

        rc = self.get_allocation()
        self.stepx = rc.width / self.divider
        self.stepy = rc.height / self.divider

        winn = self.window
        #rc = area.get_allocation()
        gc = gtk.gdk.GC(winn)
        #colormap = gtk.widget_get_default_colormap()
        winn.draw_pixbuf(gc, self.image2.get_pixbuf(), 0, 0, 0, 0)

        # Paint annotations:
        for xx, yy, txt in self.atext:
            self.pangolayout.set_text(txt)
            winn.draw_layout(gc, xx, yy, self.pangolayout)

        for xx, yy, col in self.aframe:
            colormap = gtk.widget_get_default_colormap()
            gc.set_foreground(colormap.alloc_color("#%06x" % (col & 0xffffff)))
            winn.draw_rectangle(gc, False, xx * self.stepx, yy * self.stepy,
                                self.stepx, self.stepy)
            #winn.draw_line(gc, xx*self.stepx, yy*self.stepy,
            #                    (xx+1)*self.stepx, (yy+1)*self.stepy)

        for xx, yy, func in self.annote:
            func(winn)

        if self.mag:
            #print  "paint mag:", self.event_x, self.event_y
            #iw = self.image.get_pixbuf().get_width()
            #ih = self.image.get_pixbuf().get_height()
            #iw2 = self.image2.get_pixbuf().get_width()
            #ih2 = self.image2.get_pixbuf().get_height()
            #print iw, ih, iw2, ih2

            mags = MAG_SIZE

            rendx = self.event_x - mags / 2
            if rendx < 0: rendx = 0
            rendy = self.event_y - mags / 2
            if rendy < 0: rendy = 0
            #src_x = self.event_x  * self.scalef - mags/2
            src_x = self.event_x
            if src_x < 0: src_x = 0
            #src_y = self.event_y  * self.scalef - mags/2
            src_y = self.event_y
            if src_y < 0: src_y = 0
            magsx = mags
            #if rendx + magsx > self.wwww: magsx = self.wwww - rendx
            magsy = mags
            #if rendy + magsy > self.hhhh: magsh = self.hhhh - rendy

            #print self.image2.get_pixbuf().get_has_alpha()
            #print self.pb.get_has_alpha()

            self.image2.get_pixbuf().scale(self.pb, 0, 0, 300, 300, int(src_x),
                                           int(src_y), 2, 2,
                                           gtk.gdk.INTERP_NEAREST)

            print src_x, src_y, rendx, rendy, magsx, magsy

            #print self.pb.get_width(), self.pb.get_height()

            winn.draw_pixbuf(gc, self.pb, 0, 0, int(self.event_x),
                             int(self.event_y), int(magsx), int(magsy))
Exemple #15
0
    def __init__(self, buff, appwin, readonly=False):

        # Save params
        self.appwin = appwin
        self.readonly = readonly

        # Gather globals
        self.keyh = pedconfig.conf.keyh

        # Init vars
        self.xpos = 0
        self.ypos = 0
        self.changed = False
        self.needscan = True
        self.record = False
        self.recarr = []  # Macros
        self.undoarr = []  # Undo
        self.redoarr = []  # Redo
        self.queue = []  # Idle tasks
        self.colsel = False
        self.oldsearch = ""
        self.oldgoto = ""
        self.oldrep = ""
        self.xsel = -1
        self.ysel = -1
        self.xsel2 = -1
        self.ysel2 = -1
        self.mx = -1
        self.my = -1
        self.caret = []
        self.caret.append(0)
        self.caret.append(0)
        self.focus = False
        self.insert = True
        self.startxxx = -1
        self.startyyy = -1
        self.hex = False
        self.colflag = True
        self.acorr = True
        self.scol = False
        self.accum = []
        self.tokens = []
        self.ularr = []
        self.bigcaret = False
        self.stab = False
        self.honeshot = False
        self.initial_undo_size = 0
        self.initial_redo_size = 0
        self.spell = False
        self.spellmode = False
        # Init configurables
        self.vscgap = VSCROLLGAP
        self.hscgap = HSCROLLGAP
        self.pgup = PAGEUP
        self.tabstop = TABSTOP
        # Process buffer into list
        self.text = buff
        self.maxlinelen = 0
        self.maxlines = 0
        self.fired = 0
        self.countup = 0

        # Parent widget
        gtk.DrawingArea.__init__(self)
        self.set_flags(gtk.CAN_FOCUS | gtk.SENSITIVE)

        # Our font
        fsize = pedconfig.conf.sql.get_int("fsize")
        fname = pedconfig.conf.sql.get_str("fname")
        if fsize == 0: fsize = 14
        if fname == "": fname = "Mono"

        self.setfont(fname, fsize)

        if self.readonly:
            self.set_tooltip_text("Read only buffer")

        # Create scroll items
        sm = len(self.text) + self.get_height() / self.cyy + 10
        self.hadj = gtk.Adjustment(0, 0, self.maxlinelen, 1, 15, 25)
        self.vadj = gtk.Adjustment(0, 0, sm, 1, 15, 25)

        self.vscroll = gtk.VScrollbar(self.vadj)
        self.hscroll = gtk.HScrollbar(self.hadj)

        # We connect scrollers after construction
        self.hadj.connect("value-changed", self.hscroll_cb)
        self.vadj.connect("value-changed", self.vscroll_cb)

        self.set_events(gtk.gdk.POINTER_MOTION_MASK
                        | gtk.gdk.POINTER_MOTION_HINT_MASK
                        | gtk.gdk.BUTTON_PRESS_MASK
                        | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.KEY_PRESS_MASK
                        | gtk.gdk.KEY_RELEASE_MASK)

        self.set_events(gtk.gdk.ALL_EVENTS_MASK)

        self.colormap = gtk.widget_get_default_colormap()

        # Set default background color
        if self.readonly:
            color = self.colormap.alloc_color("#d8d8d8")
            self.modify_bg(gtk.STATE_NORMAL, color)

        # Customize your colors here

        self.fgcolor = self.colormap.alloc_color(FGCOLOR)
        self.rbgcolor = self.colormap.alloc_color(RBGCOLOR)
        self.cbgcolor = self.colormap.alloc_color(CBGCOLOR)
        self.kwcolor = self.colormap.alloc_color(KWCOLOR)
        self.clcolor = self.colormap.alloc_color(CLCOLOR)
        self.cocolor = self.colormap.alloc_color(COCOLOR)
        self.stcolor = self.colormap.alloc_color(STCOLOR)

        self.connect("expose-event", self.area_expose_cb)
        self.connect("motion-notify-event", self.area_motion)
        self.connect("button-press-event", self.area_button)
        self.connect("button-release-event", self.area_button)
        self.connect("key-press-event", self.area_key)
        self.connect("key-release-event", self.area_key)
        self.connect("focus", self.area_focus)
        self.connect("configure_event", self.configure_event)
        self.connect("size-request", self.size_request)
        self.connect("size-allocate", self.size_alloc)
        self.connect("scroll-event", self.scroll_event)
        self.connect("focus-in-event", self.focus_in_cb)
        self.connect("focus-out-event", self.focus_out_cb)
Exemple #16
0
    def _drawcaret(self):

        #print "drawing caret", self.caret[0], self.caret[1], \
        #        self.caret[0] * self.cxx, self.caret[1] * self. cyy

        colormap = gtk.widget_get_default_colormap()
        if self.focus:
            color = colormap.alloc_color("#008888")
        else:
            color = colormap.alloc_color("#aaaaaa")

        gcx = gtk.gdk.GC(self.window)
        gcx.copy(self.gc)
        gcx.set_foreground(color)

        try:
            line = self.text[self.ypos + self.caret[1]]
        except:
            line = ""

        xxx = calc_tabs2(line[self.xpos:], self.caret[0])
        xx = xxx * self.cxx
        #xx = self.caret[0] * self.cxx
        yy = self.caret[1] * self.cyy

        ch = self.cyy / 2
        cw = self.cxx / 2

        # Order: Top, left right, buttom
        if self.focus:
            # Flash cursor
            if self.bigcaret:
                rxx = xx + self.cxx
                ly = yy + self.cyy
                uy = yy
                mmx = xx + cw
                mmy = yy + ch
                dist = 80
                self.window.draw_line(gcx, mmx - dist, uy, mmx + dist, uy)
                self.window.draw_line(gcx, mmx - dist, ly, mmx + dist, ly)
                self.window.draw_line(gcx, xx, mmy - dist, xx, mmy + dist)
                self.window.draw_line(gcx, rxx, mmy - dist, rxx, mmy + dist)
            else:
                if self.insert:
                    self.window.draw_line(gcx, xx, yy, xx + cw, yy)
                    self.window.draw_line(gcx, xx + 1, yy, xx + 1,
                                          yy + self.cyy)
                    self.window.draw_line(gcx, xx + 3, yy, xx + 3,
                                          yy + self.cyy)
                    self.window.draw_line(gcx, xx, yy + self.cyy, xx + cw,
                                          yy + self.cyy)
                else:
                    self.window.draw_line(gcx, xx, yy, xx + cw, yy)
                    self.window.draw_line(gcx, xx + 1, yy, xx + 1,
                                          yy + self.cyy)
                    self.window.draw_line(gcx, xx + 2, yy, xx + 2,
                                          yy + self.cyy)
                    self.window.draw_line(gcx, xx + 3, yy, xx + 3,
                                          yy + self.cyy)
                    self.window.draw_line(gcx, xx + 4, yy, xx + 4,
                                          yy + self.cyy)
                    self.window.draw_line(gcx, xx, yy + self.cyy, xx + cw,
                                          yy + self.cyy)
        else:
            #self.window.draw_line(gcx, xx, yy, xx + cw, yy)
            self.window.draw_line(gcx, xx + 1, yy + 2, xx + 1,
                                  yy - 2 + self.cyy)
            self.window.draw_line(gcx, xx + 3, yy + 2, xx + 3,
                                  yy - 2 + self.cyy)
Exemple #17
0
    def area_expose_cb(self, area, event):

        #print "area_expose_cb()", event.area.width, event.area.height

        # We have a window, goto start pos
        hhh = self.get_height()
        xlen = len(self.text)

        style = self.get_style()
        self.gc = style.fg_gc[gtk.STATE_NORMAL]
        gcx = gtk.gdk.GC(self.window)
        gcx.copy(self.gc)
        gcr = gtk.gdk.GC(self.window)
        gcr.copy(self.gc)

        colormap = gtk.widget_get_default_colormap()
        gcr.set_foreground(colormap.alloc_color("#ff0000"))

        #got_clock = time.clock()

        # Paint text
        xx = 0
        yy = 0
        cnt = self.ypos
        while cnt < xlen:
            #dx, dy = self._draw_text(self.gc, xx, yy, self.text[cnt])
            dx, dy = self._draw_text(gcx, xx, yy, self.text[cnt], self.fgcolor)
            cnt = cnt + 1
            yy += dy
            if yy > hhh:
                break

        # Do not paint color on hex:
        if self.hex or self.stab:
            self._drawcaret()
            return True

        # Paint selection
        xx = 0
        yy = 0
        cnt = self.ypos

        # Normalize (Read: [xy]ssel - startsel  [xy]esel - endsel
        xssel = min(self.xsel, self.xsel2)
        xesel = max(self.xsel, self.xsel2)
        yssel = min(self.ysel, self.ysel2)
        yesel = max(self.ysel, self.ysel2)
        # Override
        if not self.colsel:
            if yssel != yesel:
                xssel = self.xsel
                xesel = self.xsel2

        draw_start = xssel
        if xssel != -1:
            if self.colsel: bgcol = self.cbgcolor
            else: bgcol = self.rbgcolor

            while cnt < xlen:
                if cnt >= yssel and cnt <= yesel:
                    line = self.text[cnt]
                    if self.colsel:
                        frag = line[xssel:xesel]
                    else:  # Startsel - endsel
                        if cnt == yssel and cnt == yesel:  # sel on the same line
                            frag = line[xssel:xesel]
                        elif cnt == yssel:  # start line
                            frag = line[xssel:]
                        elif cnt == yesel:  # end line
                            draw_start = 0
                            frag = line[:xesel]
                        else:
                            draw_start = 0  # intermediate line
                            frag = line[:]

                    dss = calc_tabs(line, draw_start)
                    self._draw_text(gcx, dss * self.cxx, yy, frag,
                                    self.fgcolor, bgcol)
                cnt = cnt + 1
                yy += self.cyy
                if yy > hhh:
                    break

        #print  "sel", time.clock() - got_clock

        if not self.colflag:
            self._drawcaret()
            return True

        # Color keywords. Very primitive coloring, a compromise for speed
        xx = 0
        yy = 0
        cnt = self.ypos
        while cnt < xlen:
            line = self.text[cnt]
            for kw in keywords:
                ff = 0  # SOL
                while True:
                    ff = line.find(kw, ff)
                    if ff >= 0:
                        ff2 = calc_tabs(line, ff)

                        self._draw_text(gcx, ff2 * self.cxx, yy,
                                        line[ff:ff + len(kw)], self.kwcolor,
                                        None)

                        ff += len(kw)
                        #break
                    else:
                        break

            for kw in clwords:
                cc = 0  # SOL
                while True:
                    cc = line.find(kw, cc)
                    if cc >= 0:
                        cc2 = calc_tabs(line, cc)
                        self._draw_text(gcx, cc2 * self.cxx, yy,
                                        line[cc:cc + len(kw)], self.clcolor,
                                        None)

                        cc += len(kw)
                        #break
                    else:
                        break

            # Comments
            ccc = line.find("#")
            cccc = line.find('"')

            # See if hash preceeds quote (if any)
            if ccc >= 0 and (cccc > ccc or cccc == -1):
                ccc -= self.xpos
                ccc2 = calc_tabs(line, ccc)
                self._draw_text(gcx, ccc2 * self.cxx, yy, line[ccc:],
                                self.cocolor, None)
            else:
                qqq = 0
                while True:
                    quote = '"'
                    sss = qqq
                    qqq = line.find(quote, qqq)
                    if qqq < 0:
                        # See if single quote is foound
                        qqq = line.find("'", sss)
                        if qqq >= 0:
                            quote = '\''
                    if qqq >= 0:
                        qqq += 1
                        qqqq = line.find(quote, qqq)
                        if qqqq >= 0:
                            qqq -= self.xpos
                            qqq2 = calc_tabs(line, qqq)
                            self._draw_text(gcx, qqq2 * self.cxx, yy,
                                            line[qqq:qqqq], self.stcolor, None)
                            qqq = qqqq + 1
                        else:
                            break
                    else:
                        break

            cnt = cnt + 1
            yy += self.cyy
            if yy > hhh:
                break

        # Underline spelling errors
        yyy = self.ypos + self.get_height() / self.cyy
        for xaa, ybb, lcc in self.ularr:
            # Draw within visible range
            if ybb >= self.ypos and ybb < yyy:
                ybb -= self.ypos
                xaa -= self.xpos
                lcc -= self.xpos
                self.draw_wiggle(gcr, xaa * self.cxx,
                                 ybb * self.cyy + self.cyy, lcc * self.cxx,
                                 ybb * self.cyy + self.cyy)

        #print  "kw", time.clock() - got_clock

        if self.startxxx != -1:
            self.gotoxy(self.startxxx, self.startyyy)
            self.startxxx = -1
            self.startyyy = -1

        self._drawcaret()
        return True
Exemple #18
0
    def set_caret(self, xx, yy):

        # Needs scroll?
        xxx, yyy = self.get_size()
        need_inval = False
        xlen = len(self.text)

        # Put it back in view:
        hhh = yyy - self.scgap * self.cyy
        if yy * self.cyy > hhh:
            #print "Scroll from caret down"
            self.ypos += yy - (yyy / self.cyy - self.scgap)
            yy = yyy / self.cyy - self.scgap
            need_inval = True

        colormap = gtk.widget_get_default_colormap()
        color = colormap.alloc_color("#008888")

        gcx = gtk.gdk.GC(self.window)
        gcx.copy(self.gc)
        gcx.set_foreground(color)

        if yy < self.scgap and self.ypos > 0:
            #print "Scroll from caret up"
            #self.ypos = yy - yyy / self.cyy
            self.ypos += yy - self.scgap
            yy = self.scgap
            need_inval = True

        if self.ypos > xlen - self.scgap:
            self.ypos = xlen - self.scgap

        if self.ypos < 0:
            self.ypos = 0

        oldx = self.caret[0] * self.cxx
        oldy = self.caret[1] * self.cyy

        self.caret[0] = xx
        self.caret[1] = yy

        # Low limit
        if self.caret[0] < 0: self.caret[0] = 0
        if self.caret[1] < 0: self.caret[1] = 0

        # High Limit
        xxxx = xxx / self.cxx
        yyyy = yyy / self.cyy
        if self.caret[0] > xxxx: self.caret[0] = xxxx
        if self.caret[1] > yyyy: self.caret[1] = yyyy

        wxx = self.caret[0] * self.cxx
        wyy = self.caret[1] * self.cyy

        # Optimize cursor movement invalidation
        rect = gtk.gdk.Rectangle(wxx, wyy, self.cxx * self.cxx / 2,
                                 self.cyy + 1)
        self.invalidate(rect)

        rect = gtk.gdk.Rectangle(oldx, oldy, self.cxx + self.cxx / 2,
                                 self.cyy + 1)
        self.invalidate(rect)

        # Update scroll bars:
        self.vscroll.set_value(self.ypos)
        #self.hscroll =

        self.mained.update_statusbar2(self.caret[0] + self.xpos,
                                      self.caret[1] + self.ypos)

        if need_inval:
            self.invalidate()

        if self.changed and not self.changed2:
            self.changed2 = True
            print "Setting changed on ", self.fname
            vcurr = self.notebook.get_nth_page(
                self.notebook.get_current_page())
            ss = shortenstr(os.path.basename(self.fname), 24)
            label = gtk.Label(" " + ss + " *")
            self.notebook.set_tab_label(vcurr, label)
Exemple #19
0
    def renderscene(self, showall=False):

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        glInitNames()
        glPushName(0)

        ss = float(self.__sside) / 100
        ud = float(self.__supdown) / 100
        gluLookAt(ss, ud, 0, 0, 0, -1, 0, 1, 0)

        glTranslatef(0.0, 0.0, self.__sdepth)
        glRotatef(-self.__stheta, 1.0, 0.0, 0.0)
        glRotatef(self.__sphi, 0.0, 0.0, 1.0)
        glRotatef(self.__sgamma, 0.0, 1.0, 0.0)

        if 0:  #self.anicount < 40:
            ver = "PYTHON"
            xstr = "FILE MANAGER"
            #glRotatef (self.anicount / 2, 1.0, 0.0, 0.0)
            #glRotatef (self.anicount/6, 0.0, 1.0, 0.0)

            glPushMatrix()
            hoffset = -self.font.extent3Dstr(ver)[0] / 2
            offset = 0
            self.zoffset += 1
            glPushMatrix()
            offset -= self.font.FontHeight + self.font.linegap
            glTranslatef(hoffset, offset, self.zoffset)
            self.font.print3Dstr(ver)
            glPopMatrix()

            glPushMatrix()
            offset -= self.font.FontHeight + self.font.linegap
            offset -= self.font.FontHeight + self.font.linegap
            hoffset = -self.font.extent3Dstr(xstr)[0] / 2
            glTranslatef(hoffset, offset, self.zoffset)
            self.font.print3Dstr(xstr)
            glPopMatrix()
            glPopMatrix()
        else:
            try:
                if self.showdonut:
                    donut(self)
                if self.showcubes:
                    cubes(self)
                if self.showrand:
                    randtri(self)
                if self.showtri:
                    stuff(self)
                if self.showtext:
                    text(self)
                if self.showstars:
                    stars(self)
                if self.showgrid:
                    grid(self)

            except:
                a, b, c = sys.exc_info()
                print sys.excepthook(a, b, c)
                exit
                return
                #raise SystemExit

        if 1:  #showall:
            style = self.glarea.get_style()
            self.gc = style.fg_gc[gtk.STATE_NORMAL]
            gcx = gtk.gdk.GC(self.glarea.window)
            gcx.copy(self.gc)
            gcr = gtk.gdk.GC(self.glarea.window)
            gcr.copy(self.gc)
            colormap = gtk.widget_get_default_colormap()
            gcr.set_foreground(colormap.alloc_color("#ff0000"))

            for vv in self.arr:
                aa, bb, cc = vv.vertex
                aa = int(aa)
                bb = int(bb)
                cc = int(cc)
                bb = self.height - bb
                dd = 5
                self.glarea.window.draw_line(gcr, aa - dd, bb - dd, aa + dd,
                                             bb + dd)
                self.glarea.window.draw_line(gcr, aa + dd, bb - dd, aa - dd,
                                             bb + dd)
                #self.win.window.draw_line(gcr, bb, cc, bb+dd, cc+dd)
            if 0:
                global pylonarr
                for vv in self.selarr:
                    if pylonarr.id in vv:
                        for vvv in pylonarr.arr:
                            for vv in vvv.verts:
                                glPushMatrix()
                                glRotatef(self.angle7, 0.0, 1.0, 0.0)
                                glTranslatef(vv._x, vv._y, vv._z)
                                gtk.gdkgl.draw_cube(True, 0.03)
                                glPopMatrix()
Exemple #20
0
    def area_expose_cb(self, area, event):
        #print "expose", area, event, len(self.coords)
        colormap = gtk.widget_get_default_colormap()
        style = area.get_style()
        self.gc = style.fg_gc[gtk.STATE_NORMAL]
        gcx = gtk.gdk.GC(area.window)
        gcx.copy(self.gc)
        gcr = gtk.gdk.GC(area.window)
        gcr.copy(self.gc)
        gcr.set_foreground(colormap.alloc_color("#ff0000"))
        gcg = gtk.gdk.GC(area.window)
        gcg.copy(self.gc)
        gcg.set_foreground(colormap.alloc_color("#00ff00"))
        gcb = gtk.gdk.GC(area.window)
        gcb.copy(self.gc)
        gcb.set_foreground(colormap.alloc_color("#0000ff"))

        if len(self.coords) > 1:
            # Estabilish boundary numbers
            self.maxx = 0
            self.maxy = 0
            self.minx = 0
            self.miny = 0
            for aa, bb, cc in self.coords:
                if self.maxy < bb: self.maxy = bb
                if self.miny > bb: self.miny = bb
                if self.maxx < aa: self.maxx = aa
                if self.minx > aa: self.minx = aa

            #print "Drawing Coords:", len(self.coords)
            olda = self.coords[0][0]
            oldb = self.coords[0][1]
            cnt = 0
            for aa, bb, cc in self.coords:
                self.draw_line(area, gcr, olda, oldb, aa, bb)
                olda = aa
                oldb = bb
                cnt += 1

        if len(self.coords2) > 1:
            olda = self.coords2[0][0]
            oldb = self.coords2[0][1]
            cnt = 0
            for aa, bb, cc in self.coords2:
                self.draw_line(area, gcg, olda, oldb, aa, bb)
                olda = aa
                oldb = bb
                cnt += 1

        if len(self.coords3) > 1:
            olda = self.coords3[0][0]
            oldb = self.coords3[0][1]
            cnt = 0
            for aa, bb, cc in self.coords3:
                self.draw_line(area, gcb, olda, oldb, aa, bb)
                olda = aa
                oldb = bb
                cnt += 1

        # Draw axes
        gcr.set_foreground(colormap.alloc_color("#000000"))
        ww, hh = area.window.get_size()
        area.window.draw_line(gcr, 10, hh / 2, ww - 10, hh / 2)
        area.window.draw_line(gcr, 10, 10, 10, hh - 10)
        ah = 1
        aw = 1

        for aa in range(10, ww - 10, 10):
            area.window.draw_line(gcr, aa, hh / 2 - ah, aa, hh / 2 + ah)

        for aa in range(hh / 2, 10, -10):
            area.window.draw_line(gcr, 10 - aw, aa, 10 + ah, aa)

        for aa in range(hh / 2, hh - 10, 10):
            area.window.draw_line(gcr, 10 - aw, aa, 10 + ah, aa)

        vhh = hh - 40  # Leave space on top / buttom

        # Draw text
        if self.maxy and self.maxx:
            raty = float((hh / 2 - 20)) / self.maxy
            ratx = float((ww - 20)) / self.maxx

            self.draw_text(area.window, gcr, 20, 10, str(self.minx) + " ...  " + str(self.maxx) \
                        + "      " + "%0.3f" % self.miny +  " ...  " + "%0.3f" % self.maxy)

            str2 = "xx = %f yy = %f " % (self.ex / ratx,
                                         ((hh / 2) - self.ey) / raty)
            ww2, hh2 = self.measure_text(str2)
            self.draw_text(area.window, gcr, ww - ww2 - 20, hh - hh2, str2)
Exemple #21
0
    def __init__(self, buff, appwin, readonly=False):

        # Save params
        self.appwin = appwin

        self.readonly = readonly

        # Gather globals
        self.keyh = pedconfig.conf.keyh

        # Init vars
        self.xpos = 0
        self.ypos = 0
        self.changed = False
        self.needscan = True
        self.record = False
        self.recarr = []  # Macros
        self.undoarr = []  # Undo
        self.redoarr = []  # Redo
        self.colsel = False
        self.oldsearch = ""
        self.xsel = -1
        self.ysel = -1
        self.xsel2 = -1
        self.ysel2 = -1
        self.mx = -1
        self.my = -1
        self.caret = []
        self.caret.append(0)
        self.caret.append(0)
        self.focus = False
        self.insert = True
        self.startxxx = -1
        self.startyyy = -1
        self.hex = False
        self.accum = []
        self.bigcaret = False

        # Init configurables
        self.scgap = SCROLLGAP
        self.pgup = PAGEUP
        self.tabstop = TABSTOP

        # Process buffer into list
        self.text = buff
        self.maxlinelen = 0

        # Parent widget
        gtk.DrawingArea.__init__(self)
        self.set_flags(gtk.CAN_FOCUS | gtk.SENSITIVE)
        self.pangolayout = self.create_pango_layout("a")

        if self.readonly:
            self.set_tooltip_text("Read only buffer")

        # Our font
        fd = pango.FontDescription()
        fd.set_size(14 * 1024)
        fd.set_family("mono")
        self.pangolayout.set_font_description(fd)

        # Get Pango steps
        self.cxx, self.cyy = self.pangolayout.get_pixel_size()
        ts = self.pangolayout.get_tabs()
        if ts == None: self.tabstop = TABSTOP
        else: al, self.tabstop = ts.get_tab(0)

        #print "tabstop", self.tabstop

        sm = len(self.text) + self.get_height() / self.cyy + 10
        self.hadj = gtk.Adjustment(0, 0, self.maxlinelen, 1, 15, 25)
        self.vadj = gtk.Adjustment(0, 0, sm, 1, 15, 25)

        self.vscroll = gtk.VScrollbar(self.vadj)
        self.hscroll = gtk.HScrollbar(self.hadj)

        # We connect scrollers after construction
        self.hadj.connect("value-changed", self.hscroll_cb)
        self.vadj.connect("value-changed", self.vscroll_cb)

        self.set_events(gtk.gdk.POINTER_MOTION_MASK
                        | gtk.gdk.POINTER_MOTION_HINT_MASK
                        | gtk.gdk.BUTTON_PRESS_MASK
                        | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.KEY_PRESS_MASK
                        | gtk.gdk.KEY_RELEASE_MASK)

        self.set_events(gtk.gdk.ALL_EVENTS_MASK)

        self.colormap = gtk.widget_get_default_colormap()

        # Set default background color
        if self.readonly:
            color = self.colormap.alloc_color("#d8d8d8")
            self.modify_bg(gtk.STATE_NORMAL, color)

        # Customize your colors here

        self.fgcolor = self.colormap.alloc_color(FGCOLOR)
        self.rbgcolor = self.colormap.alloc_color(RBGCOLOR)
        self.cbgcolor = self.colormap.alloc_color(CBGCOLOR)
        self.kwcolor = self.colormap.alloc_color(KWCOLOR)
        self.clcolor = self.colormap.alloc_color(CLCOLOR)
        self.cocolor = self.colormap.alloc_color(COCOLOR)
        self.stcolor = self.colormap.alloc_color(STCOLOR)

        self.connect("expose-event", self.area_expose_cb)
        self.connect("motion-notify-event", self.area_motion)
        self.connect("button-press-event", self.area_button)
        self.connect("button-release-event", self.area_button)
        self.connect("key-press-event", self.area_key)
        self.connect("key-release-event", self.area_key)
        self.connect("focus", self.area_focus)
        self.connect("configure_event", self.configure_event)
        self.connect("size-request", self.size_request)
        self.connect("size-allocate", self.size_alloc)
        self.connect("scroll-event", self.scroll_event)
        #self.connect("enter-notify-event", self.area_enter)
        #self.connect("leave-notify-event", self.area_leave)
        self.connect("focus-in-event", self.focus_in_cb)
        self.connect("focus-out-event", self.focus_out_cb)
Exemple #22
0
    def set_caret(self, xx, yy):

        # Needs scroll?
        xxx, yyy = self.get_size()
        need_inval = False
        xlen = len(self.text)

        # Put it back in view:
        hhh = yyy - self.scgap * self.cyy
        if yy * self.cyy > hhh:
            #print "Scroll from caret down"
            self.ypos += yy - (yyy / self.cyy - self.scgap)
            yy = yyy / self.cyy - self.scgap
            need_inval = True

        colormap = gtk.widget_get_default_colormap()
        color = colormap.alloc_color("#008888")

        gcx = gtk.gdk.GC(self.window)
        gcx.copy(self.gc)
        gcx.set_foreground(color)

        if yy < self.scgap and self.ypos > 0:
            #print "Scroll from caret up"
            #self.ypos = yy - yyy / self.cyy
            self.ypos += yy - self.scgap
            yy = self.scgap
            need_inval = True

        if self.ypos > xlen - self.scgap:
            self.ypos = xlen - self.scgap

        if self.ypos < 0:
            self.ypos = 0

        oldx = self.caret[0] * self.cxx
        oldy = self.caret[1] * self.cyy

        self.caret[0] = xx
        self.caret[1] = yy

        # Low limit
        if self.caret[0] < 0: self.caret[0] = 0
        if self.caret[1] < 0: self.caret[1] = 0

        # High Limit
        xxxx = xxx / self.cxx
        yyyy = yyy / self.cyy
        if self.caret[0] > xxxx: self.caret[0] = xxxx
        if self.caret[1] > yyyy: self.caret[1] = yyyy

        wxx = self.caret[0] * self.cxx
        wyy = self.caret[1] * self.cyy

        # Optimize cursor movement invalidation
        rect = gtk.gdk.Rectangle(wxx, wyy, self.cxx * self.cxx / 2,
                                 self.cyy + 1)
        self.invalidate(rect)

        rect = gtk.gdk.Rectangle(oldx, oldy, self.cxx + self.cxx / 2,
                                 self.cyy + 1)
        self.invalidate(rect)

        # Update scroll bars:
        self.vscroll.set_value(self.ypos)
        #self.hscroll =

        self.mained.update_statusbar2(self.caret[0] + self.xpos, \
                self.caret[1] + self.ypos, self.insert)

        if need_inval:
            self.invalidate()
Exemple #23
0
    def __init__(self, buff, appwin):
        
        # Save params
        global gl_appwin
        gl_appwin = appwin
        self.appwin = appwin; 

        # Gather globals
        self.keyh = pedconfig.pedconfig.keyh

        # Init vars
        self.xpos = 0; self.ypos = 0
        self.changed = False; self.colsel = False

        self.xsel = -1; self.ysel = -1
        self.xsel2 = -1; self.ysel2 = -1
        self.caret = []; self.caret.append(0); self.caret.append(0)        
        self.maxlinelen = 0
        self.focus = False

        # Init configurables
        self.scgap = SCROLLGAP      
        self.pgup  = PAGEUP
        self.tabstop = TABSTOP

        # Process buffer into list
        self.text = buff
        for aa in self.text:       
            xlen = len(aa)  
            if self.maxlinelen < xlen:
                self.maxlinelen = xlen

        # Parent widget                 
        gtk.DrawingArea.__init__(self)
        self.set_flags(gtk.CAN_FOCUS | gtk.SENSITIVE)
        self.pangolayout = self.create_pango_layout("a")
    
        # Set default background color
        '''colormap = gtk.widget_get_default_colormap()
        color = colormap.alloc_color("#d0d0d0")
        self.modify_bg(gtk.STATE_NORMAL, color)'''
        
        # Our font
        fd = pango.FontDescription()
        fd.set_size(14*1024); fd.set_family("mono")
        self.pangolayout.set_font_description(fd)

        # Get Pango steps
        self.cxx, self.cyy = self.pangolayout.get_pixel_size()
        ts = self.pangolayout.get_tabs()
        if ts == None: self.tabstop = TABSTOP    
        else: al, self.tabstop = ts.get_tab(0)

        #print "tabstop", self.tabstop
        # Set up scroll bars        
        sm = len(self.text) + self.get_height() / self.cyy + 10
        self.hadj = gtk.Adjustment(0, 0, 100, 1, 15, 25);
        self.vadj = gtk.Adjustment(0, 0, sm, 1, 15, 25);
        
        self.vscroll = gtk.VScrollbar(self.vadj)
        self.hscroll = gtk.HScrollbar(self.hadj)
        
        # We connect scrollers after construction
        self.hadj.connect("value-changed", self.hscroll_cb)
        self.vadj.connect("value-changed", self.vscroll_cb)
        
        #self.www = gtk.gdk.screen_width();
        #self.hhh = gtk.gdk.screen_height();
        
        # Start up with initial size 
        #self.set_size_request(3*self.www/4,    self.hhh/5)

        self.set_events(    gtk.gdk.POINTER_MOTION_MASK |
                            gtk.gdk.POINTER_MOTION_HINT_MASK |
                            gtk.gdk.BUTTON_PRESS_MASK |
                            gtk.gdk.BUTTON_RELEASE_MASK |
                            gtk.gdk.KEY_PRESS_MASK |
                            gtk.gdk.KEY_RELEASE_MASK )
    
        self.set_events(    gtk.gdk.ALL_EVENTS_MASK )

        colormap = gtk.widget_get_default_colormap()
        self.fgcolor = colormap.alloc_color("#000000")
        self.bgcolor = colormap.alloc_color("#4488ff")              
        self.kwcolor = colormap.alloc_color("#44aaff")
        self.clcolor = colormap.alloc_color("#44aa44")
        self.cocolor = colormap.alloc_color("#4444ff")
        self.stcolor = colormap.alloc_color("#ff44ff")

        self.connect("expose-event", self.area_expose_cb)
        self.connect("motion-notify-event", self.area_motion)
        self.connect("button-press-event", self.area_button)
        self.connect("button-release-event", self.area_button)
        self.connect("key-press-event", self.area_key)
        self.connect("key-release-event", self.area_key)
        self.connect("focus", self.area_focus)
        self.connect("configure_event", self.configure_event)
        self.connect("size-request", self.size_request)
        self.connect("size-allocate", self.size_alloc)    
        self.connect("scroll-event", self.scroll_event)    
        #self.connect("enter-notify-event", self.area_enter)
        #self.connect("leave-notify-event", self.area_leave)
        self.connect("focus-in-event", self.focus_in_cb)    
        self.connect("focus-out-event", self.focus_out_cb)