54
55
#~ xo = h_overhang / (n_cols-1)
58
59
if len(children) % n_cols:
59
self.n_rows = len(children)/n_cols + 1
60
self.n_rows = len(children) / n_cols + 1
61
self.n_rows = len(children)/n_cols
62
self.n_rows = len(children) / n_cols
64
65
for i, child in enumerate(children):
85
85
def do_get_preferred_height_for_width(self, width):
86
86
old = self.get_allocation()
87
if width == old.width: old.height, old.height
87
if width == old.width:
88
old.height, old.height
89
90
cell_w, cell_h = self.get_cell_size()
90
91
n_cols = self._get_n_columns_for_width(
91
92
width, cell_w, self.column_spacing)
93
if not n_cols: return self.MIN_HEIGHT, self.MIN_HEIGHT
95
return self.MIN_HEIGHT, self.MIN_HEIGHT
95
97
children = self.get_children()
96
98
n_rows = len(children) / n_cols
107
109
def do_size_allocate(self, allocation):
108
110
self.set_allocation(allocation)
109
111
self._layout_children(allocation)
112
113
def do_draw(self, cr):
113
if not (self.n_columns and self.n_rows): return
114
if not (self.n_columns and self.n_rows):
115
117
if self.paint_grid_pattern:
116
118
self.render_grid(cr)
118
for child in self: self.propagate_draw(child, cr)
121
self.propagate_draw(child, cr)
122
124
def render_grid(self, cr):
135
137
w = a.width / self.n_columns
137
139
for i in range(self.n_columns):
138
cr.move_to(i*w+0.5, 0)
139
cr.rel_line_to(0, a.height-3)
140
cr.move_to(i * w + 0.5, 0)
141
cr.rel_line_to(0, a.height - 3)
142
144
w = a.height / self.n_rows
144
146
for i in range(self.n_rows):
145
cr.move_to(2, i*w+0.5)
146
cr.rel_line_to(a.width-4, 0)
147
cr.move_to(2, i * w + 0.5)
148
cr.rel_line_to(a.width - 4, 0)
152
153
def add_child(self, child):
153
154
self._cell_size = None
154
155
self.put(child, 0, 0)
157
157
def get_cell_size(self):
158
158
if self._cell_size is not None:
171
171
def set_row_spacing(self, value):
172
172
self.row_spacing = value
175
174
def set_column_spacing(self, value):
176
175
self.column_spacing = value
177
176
self._layout_children(self.get_allocation())
180
178
def remove_all(self):
181
179
self._cell_size = None
182
180
for child in self:
183
181
self.remove(child)
186
184
# first tier of caching, cache component assets from which frames are
188
186
_frame_asset_cache = {}
189
189
class Frame(Gtk.Alignment):
191
191
BORDER_RADIUS = 8
200
200
# set padding + some additional padding in the bottom, left and
201
201
# right edges to factor in the dropshadow width, and ensure even
203
self.set_padding(padding, padding+2, padding+1, padding+1)
203
self.set_padding(padding, padding + 2, padding + 1, padding + 1)
205
205
# corner lable jazz
206
206
#~ self.show_corner_label = False
218
218
self._allocation = Gdk.Rectangle()
219
219
self.connect("size-allocate", self.on_size_allocate)
220
220
self.connect("style-updated", self.on_style_updated)
223
222
def on_style_updated(self, widget):
224
223
self._frame_surface_cache = None
227
225
def on_size_allocate(self, *args):
228
226
old = self._allocation
275
272
# northern edge pattern
276
273
cache_edge_pattern("%s-n" % at,
278
w-2*cnr_slice, cnr_slice)
275
w - 2 * cnr_slice, cnr_slice)
279
276
# north-east corner
280
cache_corner_surface("%s-ne" % at, -(w-cnr_slice), 0)
277
cache_corner_surface("%s-ne" % at, -(w - cnr_slice), 0)
281
278
# eastern edge pattern
282
279
cache_edge_pattern("%s-e" % at,
283
-(w-cnr_slice), -cnr_slice,
284
cnr_slice, h-2*cnr_slice)
280
-(w - cnr_slice), -cnr_slice,
281
cnr_slice, h - 2 * cnr_slice)
285
282
# south-east corner
286
cache_corner_surface("%s-se" % at, -(w-cnr_slice), -(h-cnr_slice))
283
cache_corner_surface("%s-se" % at, -(w - cnr_slice), -(h - cnr_slice))
287
284
# southern edge pattern
288
285
cache_edge_pattern("%s-s" % at,
289
-cnr_slice, -(h-cnr_slice),
290
w-2*cnr_slice, cnr_slice)
286
-cnr_slice, -(h - cnr_slice),
287
w - 2 * cnr_slice, cnr_slice)
291
288
# south-west corner
292
cache_corner_surface("%s-sw" % at, 0, -(h-cnr_slice))
289
cache_corner_surface("%s-sw" % at, 0, -(h - cnr_slice))
293
290
# western edge pattern
294
291
cache_edge_pattern("%s-w" % at, 0, -cnr_slice,
295
cnr_slice, h-2*cnr_slice)
292
cnr_slice, h - 2 * cnr_slice)
305
301
def on_draw(self, cr):
306
302
a = self.get_allocation()
307
303
self.render_frame(cr, a, self.BORDER_RADIUS, _frame_asset_cache)
309
for child in self: self.propagate_draw(child, cr)
306
self.propagate_draw(child, cr)
312
308
#~ def on_draw_after(self, widget, cr, assets, layout):
313
#~ if not self.show_corner_label: return
309
#~ if not self.show_corner_label:
315
312
#~ surf = assets["corner-label"]
316
313
#~ w = surf.get_width()
320
317
#~ # corner-label.png image...
322
319
#~ # alter the to allow drawing outside of the widget bounds
323
#~ cr.rectangle(-10, -10, w+4, h+4)
320
#~ cr.rectangle(-10, -10, w + 4, h + 4)
325
322
#~ cr.set_source_surface(surf, -7, -8)
329
326
#~ # transalate to the visual center of the corner-label
330
327
#~ cr.translate(19, 18)
331
328
#~ # rotate counter-clockwise
332
#~ cr.rotate(-pi*0.25)
329
#~ cr.rotate(-pi * 0.25)
333
330
#~ # paint normal markup
334
331
#~ Gtk.render_layout(widget.get_style_context(),
335
#~ cr, -ex.width/2, -ex.height/2, layout)
332
#~ cr, -ex.width / 2, -ex.height / 2, layout)
339
335
def set_show_corner_label(self, show_label):
340
336
if (not self.layout.get_text() and
341
self.show_corner_label == show_label): return
337
self.show_corner_label == show_label):
342
339
global _frame_asset_cache
343
340
assets = _frame_asset_cache
350
347
self.show_corner_label = show_label
351
348
self.queue_draw()
354
350
#~ def set_corner_label(self, markup):
355
#~ markup = '<span font_desc="12" color="white"><b>%s</b></span>' % markup
351
#~ markup = ('<span font_desc="12" color="white"><b>%s</b></span>' %
356
353
#~ self.set_show_corner_label(True)
357
354
#~ self.layout.set_markup(markup, -1)
358
355
#~ self.queue_draw()
361
357
def render_frame(self, cr, a, border_radius, assets):
362
358
# we cache as much of the drawing as possible
379
375
# paint north length
381
377
_cr.set_source(assets["%s-n" % at])
382
_cr.rectangle(cnr_slice, 0, width-2*cnr_slice, cnr_slice)
378
_cr.rectangle(cnr_slice, 0, width - 2 * cnr_slice, cnr_slice)
387
383
# paint north-east corner
388
384
_cr.set_source_surface(assets["%s-ne" % at],
385
width - cnr_slice, 0)
392
388
# paint east length
394
_cr.translate(width-cnr_slice, cnr_slice)
390
_cr.translate(width - cnr_slice, cnr_slice)
395
391
_cr.set_source(assets["%s-e" % at])
396
_cr.rectangle(0, 0, cnr_slice, height-2*cnr_slice)
392
_cr.rectangle(0, 0, cnr_slice, height - 2 * cnr_slice)
401
397
# paint south-east corner
402
398
_cr.set_source_surface(assets["%s-se" % at],
407
403
# paint south length
409
_cr.translate(cnr_slice, height-cnr_slice)
405
_cr.translate(cnr_slice, height - cnr_slice)
410
406
_cr.set_source(assets["%s-s" % at])
411
_cr.rectangle(0, 0, width-2*cnr_slice, cnr_slice)
407
_cr.rectangle(0, 0, width - 2 * cnr_slice, cnr_slice)
416
412
# paint south-west corner
417
413
_cr.set_source_surface(assets["%s-sw" % at],
414
0, height - cnr_slice)
421
417
# paint west length
423
419
_cr.translate(0, cnr_slice)
424
420
_cr.set_source(assets["%s-w" % at])
425
_cr.rectangle(0, 0, cnr_slice, height-2*cnr_slice)
421
_cr.rectangle(0, 0, cnr_slice, height - 2 * cnr_slice)
431
rounded_rect(_cr, 3, 2, a.width-6, a.height-6, border_radius)
427
rounded_rect(_cr, 3, 2, a.width - 6, a.height - 6, border_radius)
432
428
context = self.get_style_context()
433
429
bg = context.get_background_color(self.get_state_flags())
447
443
# paint the cached surface and apply a rounded rect clip to
449
445
A = self.get_allocation()
450
xo, yo = a.x-A.x, a.y-A.y
446
xo, yo = a.x - A.x, a.y - A.y
452
448
cr.set_source_surface(self._frame_surface_cache, xo, yo)
455
451
#~ rounded_rect(cr, xo+3, yo+2, a.width-6, a.height-6, border_radius)
460
455
class SmallBorderRadiusFrame(Frame):
462
457
BORDER_RADIUS = 3
463
458
ASSET_TAG = "small"
464
459
BORDER_IMAGE = os.path.join(
465
softwarecenter.paths.datadir, "ui/gtk3/art/frame-border-image-2px-border-radius.png")
460
softwarecenter.paths.datadir,
461
"ui/gtk3/art/frame-border-image-2px-border-radius.png")
467
463
def __init__(self, padding=3):
468
464
Frame.__init__(self, padding)
472
467
class FramedBox(Frame):
474
def __init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=0, padding=0):
469
def __init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=0,
475
471
Frame.__init__(self, padding)
476
472
self.box = Gtk.Box.new(orientation, spacing)
477
473
Gtk.Alignment.add(self, self.box)
480
475
def add(self, *args, **kwargs):
481
476
return self.box.add(*args, **kwargs)
525
519
a = self.header_alignment.get_allocation()
526
520
self.render_header(cr, a, Frame.BORDER_RADIUS, _frame_asset_cache)
528
for child in self: self.propagate_draw(child, cr)
523
self.propagate_draw(child, cr)
531
525
def add(self, *args, **kwargs):
532
526
return self.content_box.add(*args, **kwargs)
537
531
def pack_end(self, *args, **kwargs):
538
532
return self.content_box.pack_end(*args, **kwargs)
540
534
# XXX: non-functional with current code...
541
535
#~ def set_header_expand(self, expand):
542
536
#~ alignment = self.header_alignment
564
558
self.title.show()
566
560
self.title.set_markup(self.MARKUP % label)
569
562
def header_implements_more_button(self):
570
563
if not hasattr(self, "more"):
571
564
self.more = MoreLink()
572
565
self.header.pack_end(self.more, False, False, 0)
575
567
def render_header(self, cr, a, border_radius, assets):
596
588
w = ta.width + StockEms.MEDIUM
598
590
cr.new_sub_path()
599
cr.arc(r+x, r+y, r, PI, 270*PI_OVER_180)
601
cr.line_to(x+w - StockEms.MEDIUM, y + h/2)
591
cr.arc(r + x, r + y, r, PI, 270 * PI_OVER_180)
593
cr.line_to(x + w - StockEms.MEDIUM, y + h / 2)
594
cr.line_to(x + w, y + h)
609
cr.line_to(x+w - StockEms.MEDIUM, y + h/2)
601
cr.line_to(x + w - StockEms.MEDIUM, y + h / 2)
602
cr.line_to(x + w, y + h)
613
605
x = ta.x - a.x - StockEms.MEDIUM
614
606
w = ta.width + StockEms.MEDIUM - 1
617
cr.arc(x+w-r, y+r, r, 270*PI_OVER_180, 0)
620
cr.line_to(x + StockEms.MEDIUM, y + h/2)
609
cr.arc(x + w - r, y + r, r, 270 * PI_OVER_180, 0)
610
cr.line_to(x + w, y + h)
612
cr.line_to(x + StockEms.MEDIUM, y + h / 2)
626
cr.line_to(x + StockEms.MEDIUM, y + h/2)
618
cr.line_to(x + StockEms.MEDIUM, y + h / 2)
629
621
bc = context.get_border_color(self.get_state_flags())
630
622
Gdk.cairo_set_source_rgba(cr, bc)