/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to branchview/graphcell.py

  • Committer: Jelmer Vernooij
  • Date: 2008-03-28 19:26:53 UTC
  • mto: (450.1.13 trunk)
  • mto: This revision was merged to the branch mainline in revision 458.
  • Revision ID: jelmer@samba.org-20080328192653-trzptkwahx1tulz9
Add module for preferences code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import math
18
18
 
19
 
from gi.repository import Gtk
20
 
from gi.repository import GObject
21
 
from gi.repository import Pango
 
19
import gtk
 
20
import gobject
 
21
import pango
22
22
import cairo
23
23
 
24
24
 
25
 
class CellRendererGraph(Gtk.GenericCellRenderer):
 
25
class CellRendererGraph(gtk.GenericCellRenderer):
26
26
    """Cell renderer for directed graph.
27
27
 
28
28
    Properties:
30
30
      in_lines          (start, end, colour) tuple list to draw inward lines,
31
31
      out_lines         (start, end, colour) tuple list to draw outward lines.
32
32
    """
33
 
 
 
33
    
34
34
    columns_len = 0
35
35
 
36
36
    __gproperties__ = {
37
 
        "node":         ( GObject.TYPE_PYOBJECT, "node",
 
37
        "node":         ( gobject.TYPE_PYOBJECT, "node",
38
38
                          "revision node instruction",
39
 
                          GObject.PARAM_WRITABLE
 
39
                          gobject.PARAM_WRITABLE
40
40
                        ),
41
 
        "tags":         ( GObject.TYPE_PYOBJECT, "tags",
 
41
        "tags":         ( gobject.TYPE_PYOBJECT, "tags",
42
42
                          "list of tags associated with the node",
43
 
                          GObject.PARAM_WRITABLE
 
43
                          gobject.PARAM_WRITABLE
44
44
                        ),
45
 
        "in-lines":     ( GObject.TYPE_PYOBJECT, "in-lines",
 
45
        "in-lines":     ( gobject.TYPE_PYOBJECT, "in-lines",
46
46
                          "instructions to draw lines into the cell",
47
 
                          GObject.PARAM_WRITABLE
 
47
                          gobject.PARAM_WRITABLE
48
48
                        ),
49
 
        "out-lines":    ( GObject.TYPE_PYOBJECT, "out-lines",
 
49
        "out-lines":    ( gobject.TYPE_PYOBJECT, "out-lines",
50
50
                          "instructions to draw lines out of the cell",
51
 
                          GObject.PARAM_WRITABLE
 
51
                          gobject.PARAM_WRITABLE
52
52
                        ),
53
53
        }
54
 
 
 
54
    
55
55
    def do_set_property(self, property, value):
56
56
        """Set properties from GObject properties."""
57
57
        if property.name == "node":
78
78
            font_desc = widget.get_style().font_desc
79
79
            metrics = pango_ctx.get_metrics(font_desc)
80
80
 
81
 
            ascent = Pango.PIXELS(metrics.get_ascent())
82
 
            descent = Pango.PIXELS(metrics.get_descent())
 
81
            ascent = pango.PIXELS(metrics.get_ascent())
 
82
            descent = pango.PIXELS(metrics.get_descent())
83
83
 
84
84
            self._box_size = ascent + descent + 6
85
85
            return self._box_size
149
149
        box_size = self.box_size(widget)
150
150
 
151
151
        ctx.set_line_width(box_size / 8)
 
152
        ctx.set_line_cap(cairo.LINE_CAP_ROUND)
152
153
 
153
154
        # Draw lines into the cell
154
155
        for start, end, colour in self.in_lines:
155
156
            self.render_line (ctx, cell_area, box_size,
156
157
                         bg_area.y, bg_area.height,
157
 
                         start, end, colour, flags)
 
158
                         start, end, colour)
158
159
 
159
160
        # Draw lines out of the cell
160
161
        for start, end, colour in self.out_lines:
161
162
            self.render_line (ctx, cell_area, box_size,
162
163
                         bg_area.y + bg_area.height, bg_area.height,
163
 
                         start, end, colour, flags)
 
164
                         start, end, colour)
164
165
 
165
166
        # Draw the revision node in the right column
166
167
        (column, colour) = self.node
168
169
                cell_area.y + cell_area.height / 2,
169
170
                box_size / 4, 0, 2 * math.pi)
170
171
 
171
 
        if flags & Gtk.CELL_RENDERER_SELECTED:
172
 
            ctx.set_source_rgb(1.0, 1.0, 1.0)
173
 
            ctx.set_line_width(box_size / 4)
174
 
            ctx.stroke_preserve()
175
 
            ctx.set_line_width(box_size / 8)
176
 
 
177
172
        self.set_colour(ctx, colour, 0.0, 0.5)
178
173
        ctx.stroke_preserve()
179
174
 
181
176
        ctx.fill()
182
177
 
183
178
        self.render_tags(ctx, widget.create_pango_context(), cell_area, box_size)
184
 
 
185
 
    def render_line(self, ctx, cell_area, box_size, mid, height, start, end, colour, flags):
 
179
    
 
180
    def render_line(self, ctx, cell_area, box_size, mid, height, start, end, colour):
186
181
        if start is None:
187
 
            ctx.set_line_cap(cairo.LINE_CAP_ROUND)
188
182
            x = cell_area.x + box_size * end + box_size / 2
189
183
            ctx.move_to(x, mid + height / 3)
190
184
            ctx.line_to(x, mid + height / 3)
191
185
            ctx.move_to(x, mid + height / 6)
192
186
            ctx.line_to(x, mid + height / 6)
193
 
 
 
187
            
194
188
        elif end is None:
195
 
            ctx.set_line_cap(cairo.LINE_CAP_ROUND)
196
189
            x = cell_area.x + box_size * start + box_size / 2
197
190
            ctx.move_to(x, mid - height / 3)
198
191
            ctx.line_to(x, mid - height / 3)
199
192
            ctx.move_to(x, mid - height / 6)
200
193
            ctx.line_to(x, mid - height / 6)
201
 
 
202
194
        else:
203
 
            ctx.set_line_cap(cairo.LINE_CAP_BUTT)
204
195
            startx = cell_area.x + box_size * start + box_size / 2
205
196
            endx = cell_area.x + box_size * end + box_size / 2
206
 
 
 
197
            
207
198
            ctx.move_to(startx, mid - height / 2)
208
 
 
 
199
            
209
200
            if start - end == 0 :
210
 
                ctx.line_to(endx, mid + height / 2 + 1)
 
201
                ctx.line_to(endx, mid + height / 2)
211
202
            else:
212
203
                ctx.curve_to(startx, mid - height / 5,
213
204
                             startx, mid - height / 5,
214
205
                             startx + (endx - startx) / 2, mid)
215
 
 
 
206
                
216
207
                ctx.curve_to(endx, mid + height / 5,
217
208
                             endx, mid + height / 5 ,
218
 
                             endx, mid + height / 2 + 1)
219
 
 
220
 
        if flags & Gtk.CELL_RENDERER_SELECTED:
221
 
            ctx.set_source_rgb(1.0, 1.0, 1.0)
222
 
            ctx.set_line_width(box_size / 5)
223
 
            ctx.stroke_preserve()
224
 
            ctx.set_line_width(box_size / 8)
225
 
 
 
209
                             endx, mid + height / 2)
 
210
                
226
211
        self.set_colour(ctx, colour, 0.0, 0.65)
227
 
 
228
212
        ctx.stroke()
229
213
 
230
214
    def render_tags(self, ctx, pango_ctx, cell_area, box_size):
233
217
 
234
218
        (column, colour) = self.node
235
219
 
236
 
        font_desc = Pango.FontDescription()
237
 
        font_desc.set_size(Pango.SCALE * 7)
 
220
        font_desc = pango.FontDescription()
 
221
        font_desc.set_size(pango.SCALE * 7)
238
222
 
239
 
        tag_layout = Pango.Layout(pango_ctx)
 
223
        tag_layout = pango.Layout(pango_ctx)
240
224
        tag_layout.set_font_description(font_desc)
241
225
 
242
226
        # The width of the tag label stack