Example #1
0
 def draw(self, color, width=0):
   global pixmap
   global pixmapGC
   global drawingArea
   x1 = self.fromnode.loc.x * WINDOW_WIDTH
   y1 = self.fromnode.loc.y * WINDOW_HEIGHT
   x2 = self.tonode.loc.x * WINDOW_WIDTH
   y2 = self.tonode.loc.y * WINDOW_HEIGHT
   pixmapGC.foreground = color
   pixmapGC.line_width = width
   gtk.draw_line(pixmap, pixmapGC, x1, y1, x2, y2)
   drawingArea.queue_draw()
Example #2
0
 def draw(self, color, width=0):
   if (self.fromnode == None or self.tonode == None): return
   global pixmap
   global pixmapGC
   global drawingArea
   x1 = (self.fromnode.loc.x / SCALING) * WINDOW_WIDTH
   y1 = (self.fromnode.loc.y / SCALING) * WINDOW_HEIGHT
   x2 = (self.tonode.loc.x / SCALING) * WINDOW_WIDTH
   y2 = (self.tonode.loc.y / SCALING) * WINDOW_HEIGHT
   pixmapGC.foreground = color
   pixmapGC.line_width = width
   gtk.draw_line(pixmap, pixmapGC, x1, y1, x2, y2)
   drawingArea.queue_draw()
 def paint(self, di):
     p1 = di.tx(self.p1)
     p2 = di.tx(self.p2)
     gtk.draw_line(di.area, di.gc, p1.x, p1.y, p2.x, p2.y)
Example #4
0
 def paint(self, di):
     p1 = di.tx(self.p1)
     p2 = di.tx(self.p2)
     gtk.draw_line(di.area, di.gc, p1.x, p1.y, p2.x, p2.y)
Example #5
0
    def expose( self, *args ):
        """Draw the widget
        """
        if not (self.flags() & gtk.REALIZED):
            return

        if len(self.col_widths) != len(self.titles):
            self.max_width = self.cell_full
            self.col_widths=[]
            for title in self.titles:
                col_width = self.title_font.width( title )

                self.col_widths.append( col_width )

                self.max_width = self.max_width + col_width + self.cell_full

            self. max_length = self.cell_full + \
                               ( len(self.titles) * ( self.row_height + self.cell_full ) )

        
        #
        # pre-calculate half a cell spacing because we use it a lot
        #
        cell_half = self.cell_half
        cell_full = self.cell_full

        #
        # create a memory pixmap to render into
        #
        win = self._area.get_window()
        width = win.width
        height = win.height
        pix = self._pixmap
        
        #
        # prefetch the style
        #
        style = self.get_style()
        
        #
        # clear the pixmap
        #
        gtk.draw_rectangle( pix, style.white_gc, gtk.TRUE, 
                            0, 0, width, height )
                            
        if self.source == None or self.source._o == None or len(self.source) == 0:
            msg = "NO DATA TO DISPLAY"
            msg_width = self.title_font.width( msg )
            msg_height = self.title_font.height( msg )
            msg_x = (width / 2) - (msg_width / 2)
            msg_y = (height / 2) + (msg_height / 2 )
            gtk.draw_text( pix, self.title_font, 
                           style.fg_gc[gtk.STATE_INSENSITIVE], 
                           msg_x, msg_y, msg )
            self._area.draw_pixmap(style.white_gc, self._pixmap, 
                                   0, 0, 0, 0, 
                                   width, height )
            
            return gtk.FALSE
            
        
        #
        # track changes in column width because of wide columns
        #
        bResetAdj = gtk.FALSE
        
        #
        # calculate the number of rows to draw
        #
        base_height = height
        title_height = self.title_height
        data_height = base_height - title_height
        disp_rows = int(data_height / ( self.row_height + 3 ))
        
        #
        # starting x for the the first column
        #
        x = cell_half 
        
        first_row = self.start_row
        last_row = first_row + disp_rows
        first_col = self.start_col
        last_col = len(self.titles)
        
        #
        # loop through a column at a time
        #
        for i in range( first_col, last_col ):
            #
            # don't bother drawing if we're going to start past the right edge
            #
            if x > width:
                continue
            
            #
            # pre-calculate the column width for this draw
            # and remember the text values to draw
            #
            cells = []
            
            # Info on whether or not shapes are selected (1 if selected)
            cell_is_selected = []

            for j in range( first_row, last_row ):
                idx = self.grid2src(j)
                if idx == -1:
                    continue
                
                txt = self.source[idx].get_property( self.titledict[self.titles[i]] )
                if txt is None:
                    txt = ""

                cell_width = self.cell_font.width( txt )
                cells.append( (txt, cell_width) )
                cell_is_selected.append(self.selected_shapes[idx])
                if cell_width > self.col_widths[i]:
                    bResetAdj = gtk.TRUE
                    self.col_widths[i] = cell_width

            #
            # figure out the size and placement of the title text
            #
            y = self.title_height + cell_half
            title_width = self.title_font.width( self.titles[i] )
            self.col_widths[i] = max( self.col_widths[i], title_width )
            
            #
            # draw the 'button'
            #
            bx = x - cell_half + 1
            by = y - self.title_height - cell_half
            bw = self.col_widths[i] + cell_full - 1
            bh = self.title_height + cell_full
            gtk.draw_rectangle( pix, style.bg_gc[gtk.STATE_NORMAL], 
                                gtk.TRUE, bx, by, bw, bh)
            
            gtk.draw_line( pix, style.bg_gc[gtk.STATE_PRELIGHT],
                           bx, by, bx, by + bh - 1 )
            gtk.draw_line( pix, style.bg_gc[gtk.STATE_PRELIGHT],
                           bx, by, bx + bw, by )
            #
            # draw the title
            #
            tx = x + ( ( self.col_widths[i] - title_width ) / 2 )
            gtk.draw_text( pix, self.title_font, 
                           style.fg_gc[gtk.STATE_NORMAL], 
                           tx, y, self.titles[i] )
            
            #
            # draw the horizontal line below the title
            #            
            ly = y + cell_half + 1
            lx = x + self.col_widths[i] + cell_half - 1
            gtk.draw_line( pix, style.fg_gc[gtk.STATE_INSENSITIVE], 
                           0, ly - 1, lx, ly - 1 ) 

            # Calculate total width of all cells
            sum_col_widths=0.0
            for cwidth in self.col_widths:
                sum_col_widths = sum_col_widths + cwidth + self.cell_full

            #
            # draw the contents of the cells
            #
            for j in range( len(cells) ):                    
                if cell_is_selected[j] == 1 and i == first_col:
                    gtk.draw_rectangle( pix, style.bg_gc[gtk.STATE_PRELIGHT],
                                       gtk.TRUE, 
                                       0, 
                                       y + cell_half, 
                                       sum_col_widths,
                                       self.row_height + cell_full )                    
                elif self.current_row is not None and \
                   self.current_col is not None and \
                   self.current_row != 0 and \
                   self.current_col == i and \
                   j + max(self.start_row-1,0) == self.current_row - 1:  
                   gtk.draw_rectangle( pix, style.bg_gc[gtk.STATE_PRELIGHT],
                                       gtk.TRUE, 
                                       x - cell_half, 
                                       y + cell_half, 
                                       self.col_widths[i] + cell_full,
                                       self.row_height + cell_full )
                y = y + self.row_height + cell_full
                cx = x + self.col_widths[i] - cells[j][1]
                gtk.draw_text(pix, self.cell_font, 
                              style.fg_gc[gtk.STATE_NORMAL], 
                              cx, y, cells[j][0])
                #
                # only draw the line under each row once, when we are drawing
                # the last column
                #
                if x + self.col_widths[i] + cell_full > width or \
                   i == last_col - 1:
                    ly = y + cell_half + 1
                    lx = x + self.col_widths[i] + cell_half - 1
                    gtk.draw_line( pix, style.fg_gc[gtk.STATE_INSENSITIVE], 
                                   0, ly - 1, lx, ly - 1) 
                              
            #
            # where does the line go
            #
            ly = y + cell_half + 1
            lx = x + self.col_widths[i] + cell_half
            
            #
            # special case for first column, start under the title row
            #
            if i == 0:
                gtk.draw_line( pix, style.fg_gc[gtk.STATE_INSENSITIVE], 
                               0, bh , 0, ly - 1 )

            #
            # draw the vertical lines to the right of each column
            #
            gtk.draw_line( pix, style.fg_gc[gtk.STATE_INSENSITIVE], 
                           lx, 1, lx , y + cell_half )
            
            #
            #advance to next column
            #
            x = x + self.col_widths[i] + cell_full
            
        #draw the backing pixmap onto the screen
        self._area.draw_pixmap(style.white_gc, self._pixmap, 0, 0, 0, 0, 
                               width, height )

        if bResetAdj or self.bCalcAdjustments:
            self.calc_adjustments()

        return gtk.FALSE
Example #6
0
    def expose(self, *args):
        """Draw the widget
        """
        if not (self.flags() & gtk.REALIZED):
            return

        if len(self.col_widths) != len(self.titles):
            self.max_width = self.cell_full
            self.col_widths = []
            for title in self.titles:
                col_width = self.title_font.width(title)

                self.col_widths.append(col_width)

                self.max_width = self.max_width + col_width + self.cell_full

            self. max_length = self.cell_full + \
                               ( len(self.titles) * ( self.row_height + self.cell_full ) )

        #
        # pre-calculate half a cell spacing because we use it a lot
        #
        cell_half = self.cell_half
        cell_full = self.cell_full

        #
        # create a memory pixmap to render into
        #
        win = self._area.get_window()
        width = win.width
        height = win.height
        pix = self._pixmap

        #
        # prefetch the style
        #
        style = self.get_style()

        #
        # clear the pixmap
        #
        gtk.draw_rectangle(pix, style.white_gc, gtk.TRUE, 0, 0, width, height)

        if self.source == None or self.source._o == None or len(
                self.source) == 0:
            msg = "NO DATA TO DISPLAY"
            msg_width = self.title_font.width(msg)
            msg_height = self.title_font.height(msg)
            msg_x = (width / 2) - (msg_width / 2)
            msg_y = (height / 2) + (msg_height / 2)
            gtk.draw_text(pix, self.title_font,
                          style.fg_gc[gtk.STATE_INSENSITIVE], msg_x, msg_y,
                          msg)
            self._area.draw_pixmap(style.white_gc, self._pixmap, 0, 0, 0, 0,
                                   width, height)

            return gtk.FALSE

        #
        # track changes in column width because of wide columns
        #
        bResetAdj = gtk.FALSE

        #
        # calculate the number of rows to draw
        #
        base_height = height
        title_height = self.title_height
        data_height = base_height - title_height
        disp_rows = int(data_height / (self.row_height + 3))

        #
        # starting x for the the first column
        #
        x = cell_half

        first_row = self.start_row
        last_row = first_row + disp_rows
        first_col = self.start_col
        last_col = len(self.titles)

        #
        # loop through a column at a time
        #
        for i in range(first_col, last_col):
            #
            # don't bother drawing if we're going to start past the right edge
            #
            if x > width:
                continue

            #
            # pre-calculate the column width for this draw
            # and remember the text values to draw
            #
            cells = []

            # Info on whether or not shapes are selected (1 if selected)
            cell_is_selected = []

            for j in range(first_row, last_row):
                idx = self.grid2src(j)
                if idx == -1:
                    continue

                txt = self.source[idx].get_property(
                    self.titledict[self.titles[i]])
                if txt is None:
                    txt = ""

                cell_width = self.cell_font.width(txt)
                cells.append((txt, cell_width))
                cell_is_selected.append(self.selected_shapes[idx])
                if cell_width > self.col_widths[i]:
                    bResetAdj = gtk.TRUE
                    self.col_widths[i] = cell_width

            #
            # figure out the size and placement of the title text
            #
            y = self.title_height + cell_half
            title_width = self.title_font.width(self.titles[i])
            self.col_widths[i] = max(self.col_widths[i], title_width)

            #
            # draw the 'button'
            #
            bx = x - cell_half + 1
            by = y - self.title_height - cell_half
            bw = self.col_widths[i] + cell_full - 1
            bh = self.title_height + cell_full
            gtk.draw_rectangle(pix, style.bg_gc[gtk.STATE_NORMAL], gtk.TRUE,
                               bx, by, bw, bh)

            gtk.draw_line(pix, style.bg_gc[gtk.STATE_PRELIGHT], bx, by, bx,
                          by + bh - 1)
            gtk.draw_line(pix, style.bg_gc[gtk.STATE_PRELIGHT], bx, by,
                          bx + bw, by)
            #
            # draw the title
            #
            tx = x + ((self.col_widths[i] - title_width) / 2)
            gtk.draw_text(pix, self.title_font, style.fg_gc[gtk.STATE_NORMAL],
                          tx, y, self.titles[i])

            #
            # draw the horizontal line below the title
            #
            ly = y + cell_half + 1
            lx = x + self.col_widths[i] + cell_half - 1
            gtk.draw_line(pix, style.fg_gc[gtk.STATE_INSENSITIVE], 0, ly - 1,
                          lx, ly - 1)

            # Calculate total width of all cells
            sum_col_widths = 0.0
            for cwidth in self.col_widths:
                sum_col_widths = sum_col_widths + cwidth + self.cell_full

            #
            # draw the contents of the cells
            #
            for j in range(len(cells)):
                if cell_is_selected[j] == 1 and i == first_col:
                    gtk.draw_rectangle(pix, style.bg_gc[gtk.STATE_PRELIGHT],
                                       gtk.TRUE, 0, y + cell_half,
                                       sum_col_widths,
                                       self.row_height + cell_full)
                elif self.current_row is not None and \
                   self.current_col is not None and \
                   self.current_row != 0 and \
                   self.current_col == i and \
                   j + max(self.start_row-1,0) == self.current_row - 1:
                    gtk.draw_rectangle(pix, style.bg_gc[gtk.STATE_PRELIGHT],
                                       gtk.TRUE, x - cell_half, y + cell_half,
                                       self.col_widths[i] + cell_full,
                                       self.row_height + cell_full)
                y = y + self.row_height + cell_full
                cx = x + self.col_widths[i] - cells[j][1]
                gtk.draw_text(pix, self.cell_font,
                              style.fg_gc[gtk.STATE_NORMAL], cx, y,
                              cells[j][0])
                #
                # only draw the line under each row once, when we are drawing
                # the last column
                #
                if x + self.col_widths[i] + cell_full > width or \
                   i == last_col - 1:
                    ly = y + cell_half + 1
                    lx = x + self.col_widths[i] + cell_half - 1
                    gtk.draw_line(pix, style.fg_gc[gtk.STATE_INSENSITIVE], 0,
                                  ly - 1, lx, ly - 1)

            #
            # where does the line go
            #
            ly = y + cell_half + 1
            lx = x + self.col_widths[i] + cell_half

            #
            # special case for first column, start under the title row
            #
            if i == 0:
                gtk.draw_line(pix, style.fg_gc[gtk.STATE_INSENSITIVE], 0, bh,
                              0, ly - 1)

            #
            # draw the vertical lines to the right of each column
            #
            gtk.draw_line(pix, style.fg_gc[gtk.STATE_INSENSITIVE], lx, 1, lx,
                          y + cell_half)

            #
            #advance to next column
            #
            x = x + self.col_widths[i] + cell_full

        #draw the backing pixmap onto the screen
        self._area.draw_pixmap(style.white_gc, self._pixmap, 0, 0, 0, 0, width,
                               height)

        if bResetAdj or self.bCalcAdjustments:
            self.calc_adjustments()

        return gtk.FALSE