/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: Curtis Hovey
  • Date: 2011-09-03 13:46:52 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110903134652-foz5thvhwg0kcolr
RemovedĀ unusedĀ code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import math
18
18
 
19
 
import gtk
20
 
import gobject
21
 
import pango
22
 
import cairo
23
 
 
24
 
 
25
 
class CellRendererGraph(gtk.GenericCellRenderer):
 
19
from gi.repository import Gtk
 
20
from gi.repository import GObject
 
21
from gi.repository import Pango
 
22
from gi.repository import cairo
 
23
 
 
24
 
 
25
class CellRendererGraph(Gtk.CellRendererPixbuf):
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":
65
65
        else:
66
66
            raise AttributeError, "no such property: '%s'" % property.name
67
67
 
 
68
    def do_get_property(self, property):
 
69
        """Set properties from GObject properties."""
 
70
        if property.name == "node":
 
71
            return self.node
 
72
        elif property.name == "tags":
 
73
            return self.tags
 
74
        elif property.name == "in-lines":
 
75
            return self.in_lines
 
76
        elif property.name == "out-lines":
 
77
            print "get outlines"
 
78
            return self.out_lines
 
79
        else:
 
80
            raise AttributeError, "no such property: '%s'" % property.name
 
81
 
68
82
    def box_size(self, widget):
69
83
        """Calculate box size based on widget's font.
70
84
 
76
90
        except AttributeError:
77
91
            pango_ctx = widget.get_pango_context()
78
92
            font_desc = widget.get_style().font_desc
79
 
            metrics = pango_ctx.get_metrics(font_desc)
80
 
 
81
 
            ascent = pango.PIXELS(metrics.get_ascent())
82
 
            descent = pango.PIXELS(metrics.get_descent())
 
93
            metrics = pango_ctx.get_metrics(font_desc, None)
 
94
 
 
95
            def PANGO_PIXELS(d):
 
96
                # Macro from  Pango header.
 
97
                return (d + 512) / 1000
 
98
 
 
99
            ascent = PANGO_PIXELS(metrics.get_ascent())
 
100
            descent = PANGO_PIXELS(metrics.get_descent())
83
101
 
84
102
            self._box_size = ascent + descent + 6
85
103
            return self._box_size
113
131
 
114
132
        ctx.set_source_rgb(red, green, blue)
115
133
 
116
 
    def on_get_size(self, widget, cell_area):
 
134
    def activate(event, widget, path, background_area, cell_area, flags):
 
135
        return True
 
136
 
 
137
    def start_editing(event, widget, path, background_area, cell_area, flags):
 
138
        return None
 
139
 
 
140
    def get_size(self, widget, cell_area, x_offset, y_offset, width, height):
117
141
        """Return the size we need for this cell.
118
142
 
119
143
        Each cell is drawn individually and is only as wide as it needs
128
152
        # FIXME I have no idea how to use cell_area properly
129
153
        return (0, 0, width, height)
130
154
 
131
 
    def on_render(self, window, widget, bg_area, cell_area, exp_area, flags):
 
155
    def render(self, ctx, widget, bg_area, cell_area, flags):
132
156
        """Render an individual cell.
133
157
 
134
158
        Draws the cell contents using cairo, taking care to clip what we
142
166
        instead of a pure diagonal ... this reduces confusion by an
143
167
        incredible amount.
144
168
        """
145
 
        ctx = window.cairo_create()
 
169
        print "rendering"
146
170
        ctx.rectangle(bg_area.x, bg_area.y, bg_area.width, bg_area.height)
147
171
        ctx.clip()
148
172
 
168
192
                cell_area.y + cell_area.height / 2,
169
193
                box_size / 4, 0, 2 * math.pi)
170
194
 
171
 
        if flags & gtk.CELL_RENDERER_SELECTED:
 
195
        if flags & Gtk.CELL_RENDERER_SELECTED:
172
196
            ctx.set_source_rgb(1.0, 1.0, 1.0)
173
197
            ctx.set_line_width(box_size / 4)
174
198
            ctx.stroke_preserve()
181
205
        ctx.fill()
182
206
 
183
207
        self.render_tags(ctx, widget.create_pango_context(), cell_area, box_size)
184
 
    
 
208
 
185
209
    def render_line(self, ctx, cell_area, box_size, mid, height, start, end, colour, flags):
186
210
        if start is None:
187
211
            ctx.set_line_cap(cairo.LINE_CAP_ROUND)
190
214
            ctx.line_to(x, mid + height / 3)
191
215
            ctx.move_to(x, mid + height / 6)
192
216
            ctx.line_to(x, mid + height / 6)
193
 
            
 
217
 
194
218
        elif end is None:
195
219
            ctx.set_line_cap(cairo.LINE_CAP_ROUND)
196
220
            x = cell_area.x + box_size * start + box_size / 2
203
227
            ctx.set_line_cap(cairo.LINE_CAP_BUTT)
204
228
            startx = cell_area.x + box_size * start + box_size / 2
205
229
            endx = cell_area.x + box_size * end + box_size / 2
206
 
            
 
230
 
207
231
            ctx.move_to(startx, mid - height / 2)
208
 
            
 
232
 
209
233
            if start - end == 0 :
210
234
                ctx.line_to(endx, mid + height / 2 + 1)
211
235
            else:
217
241
                             endx, mid + height / 5 ,
218
242
                             endx, mid + height / 2 + 1)
219
243
 
220
 
        if flags & gtk.CELL_RENDERER_SELECTED:
 
244
        if flags & Gtk.CELL_RENDERER_SELECTED:
221
245
            ctx.set_source_rgb(1.0, 1.0, 1.0)
222
246
            ctx.set_line_width(box_size / 5)
223
247
            ctx.stroke_preserve()
233
257
 
234
258
        (column, colour) = self.node
235
259
 
236
 
        font_desc = pango.FontDescription()
237
 
        font_desc.set_size(pango.SCALE * 7)
 
260
        font_desc = Pango.FontDescription()
 
261
        font_desc.set_size(Pango.SCALE * 7)
238
262
 
239
 
        tag_layout = pango.Layout(pango_ctx)
 
263
        tag_layout = Pango.Layout(pango_ctx)
240
264
        tag_layout.set_font_description(font_desc)
241
265
 
242
266
        # The width of the tag label stack