From a46aafb8b27bd86d046385a569deee6b4c9b8bb6 Mon Sep 17 00:00:00 2001 From: Liming An Date: Mon, 9 Apr 2012 22:13:32 +0800 Subject: Hob: add fadeout display effection for recipe view include page As UI request, in recipes selection page, if user exclude a item, the related depends recipes will be excluded together,so the view clearly to add it. [YOCTO #2100] (Bitbake rev: c9eed04c6275ef2c694f89e047f85c7de76f89b6) Signed-off-by: Liming An Signed-off-by: Shane Wang Signed-off-by: Richard Purdie --- bitbake/lib/bb/ui/crumbs/hobwidget.py | 129 ++++++++++++++++++++++++++++------ 1 file changed, 106 insertions(+), 23 deletions(-) (limited to 'bitbake/lib/bb/ui/crumbs/hobwidget.py') diff --git a/bitbake/lib/bb/ui/crumbs/hobwidget.py b/bitbake/lib/bb/ui/crumbs/hobwidget.py index 96894bf01c..c6e3bb1ae6 100644 --- a/bitbake/lib/bb/ui/crumbs/hobwidget.py +++ b/bitbake/lib/bb/ui/crumbs/hobwidget.py @@ -105,6 +105,11 @@ class HobViewTable (gtk.VBox): gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,)), + "cell-fadeinout-stopped" : (gobject.SIGNAL_RUN_LAST, + gobject.TYPE_NONE, + (gobject.TYPE_PYOBJECT, + gobject.TYPE_PYOBJECT, + gobject.TYPE_PYOBJECT,)), } def __init__(self, columns): @@ -136,9 +141,10 @@ class HobViewTable (gtk.VBox): col.pack_start(cell, True) col.set_attributes(cell, text=column['col_id']) elif column['col_style'] == 'check toggle': - cell = gtk.CellRendererToggle() + cell = HobCellRendererToggle() cell.set_property('activatable', True) cell.connect("toggled", self.toggled_cb, i, self.table_tree) + cell.connect_render_state_changed(self.stop_cell_fadeinout_cb, self.table_tree) self.toggle_id = i col.pack_end(cell, True) col.set_attributes(cell, active=column['col_id']) @@ -195,6 +201,9 @@ class HobViewTable (gtk.VBox): if not view_column.get_title() in self.toggle_columns: self.emit("row-activated", tree.get_model(), path) + def stop_cell_fadeinout_cb(self, ctrl, cell, tree): + self.emit("cell-fadeinout-stopped", ctrl, cell, tree) + """ A method to calculate a softened value for the colour of widget when in the provided state. @@ -858,14 +867,23 @@ class HobIconChecker(hic): return valid_stock_id -class RefreshRuningController(gobject.GObject): - def __init__(self, widget=None, iter=None): +class HobCellRendererController(gobject.GObject): + (MODE_CYCLE_RUNNING, MODE_ONE_SHORT) = range(2) + __gsignals__ = { + "run-timer-stopped" : (gobject.SIGNAL_RUN_LAST, + gobject.TYPE_NONE, + ()), + } + def __init__(self, runningmode=MODE_CYCLE_RUNNING, is_draw_row=False): gobject.GObject.__init__(self) self.timeout_id = None self.current_angle_pos = 0.0 self.step_angle = 0.0 self.tree_headers_height = 0 self.running_cell_areas = [] + self.running_mode = runningmode + self.is_queue_draw_row_area = is_draw_row + self.force_stop_enable = False def is_active(self): if self.timeout_id: @@ -873,10 +891,10 @@ class RefreshRuningController(gobject.GObject): else: return False - def reset(self): - self.force_stop(True) + def reset_run(self): + self.force_stop() + self.running_cell_areas = [] self.current_angle_pos = 0.0 - self.timeout_id = None self.step_angle = 0.0 ''' time_iterval: (1~1000)ms, which will be as the basic interval count for timer @@ -896,15 +914,16 @@ class RefreshRuningController(gobject.GObject): self.timeout_id = gobject.timeout_add(int(time_iterval), self.make_image_on_progressing_cb, tree) self.tree_headers_height = self.get_treeview_headers_height(tree) + self.force_stop_enable = False - def force_stop(self, after_hide_or_not=False): + def force_stop(self): + self.emit("run-timer-stopped") + self.force_stop_enable = True if self.timeout_id: - gobject.source_remove(self.timeout_id) - self.timeout_id = None - if self.running_cell_areas: - self.running_cell_areas = [] + if gobject.source_remove(self.timeout_id): + self.timeout_id = None - def on_draw_cb(self, pixbuf, cr, x, y, img_width, img_height, do_refresh=True): + def on_draw_pixbuf_cb(self, pixbuf, cr, x, y, img_width, img_height, do_refresh=True): if pixbuf: r = max(img_width/2, img_height/2) cr.translate(x + r, y + r) @@ -914,6 +933,16 @@ class RefreshRuningController(gobject.GObject): cr.set_source_pixbuf(pixbuf, -img_width/2, -img_height/2) cr.paint() + def on_draw_fadeinout_cb(self, cr, color, x, y, width, height, do_fadeout=True): + if do_fadeout: + alpha = self.current_angle_pos * 0.8 + else: + alpha = (1.0 - self.current_angle_pos) * 0.8 + + cr.set_source_rgba(color.red, color.green, color.blue, alpha) + cr.rectangle(x, y, width, height) + cr.fill() + def get_treeview_headers_height(self, tree): if tree and (tree.get_property("headers-visible") == True): height = tree.get_allocation().height - tree.get_bin_window().get_size()[1] @@ -923,13 +952,24 @@ class RefreshRuningController(gobject.GObject): def make_image_on_progressing_cb(self, tree): self.current_angle_pos += self.step_angle - if (self.current_angle_pos >= 1): - self.current_angle_pos = self.step_angle - - for rect in self.running_cell_areas: - tree.queue_draw_area(rect.x, rect.y + self.tree_headers_height, rect.width, rect.height) + if self.running_mode == self.MODE_CYCLE_RUNNING: + if (self.current_angle_pos >= 1): + self.current_angle_pos = self.step_angle + else: + if self.current_angle_pos > 1: + self.force_stop() + return False + + if self.is_queue_draw_row_area: + for path in self.running_cell_areas: + rect = tree.get_cell_area(path, tree.get_column(0)) + row_x, _, row_width, _ = tree.get_visible_rect() + tree.queue_draw_area(row_x, rect.y + self.tree_headers_height, row_width, rect.height) + else: + for rect in self.running_cell_areas: + tree.queue_draw_area(rect.x, rect.y + self.tree_headers_height, rect.width, rect.height) - return True + return (not self.force_stop_enable) def append_running_cell_area(self, cell_area): if cell_area and (cell_area not in self.running_cell_areas): @@ -939,14 +979,14 @@ class RefreshRuningController(gobject.GObject): if cell_area in self.running_cell_areas: self.running_cell_areas.remove(cell_area) if not self.running_cell_areas: - self.reset() + self.reset_run() -gobject.type_register(RefreshRuningController) +gobject.type_register(HobCellRendererController) class HobCellRendererPixbuf(gtk.CellRendererPixbuf): def __init__(self): gtk.CellRendererPixbuf.__init__(self) - self.control = RefreshRuningController() + self.control = HobCellRendererController() # add icon checker for make the gtk-icon transfer to hob-icon self.checker = HobIconChecker() self.set_property("stock-size", gtk.ICON_SIZE_DND) @@ -997,12 +1037,12 @@ class HobCellRendererPixbuf(gtk.CellRendererPixbuf): if stock_id == 'hic-task-refresh': self.control.append_running_cell_area(cell_area) if self.control.is_active(): - self.control.on_draw_cb(pix, window.cairo_create(), x, y, w, h, True) + self.control.on_draw_pixbuf_cb(pix, window.cairo_create(), x, y, w, h, True) else: self.control.start_run(200, 0, 0, 1000, 200, tree) else: self.control.remove_running_cell_area(cell_area) - self.control.on_draw_cb(pix, window.cairo_create(), x, y, w, h, False) + self.control.on_draw_pixbuf_cb(pix, window.cairo_create(), x, y, w, h, False) def on_get_size(self, widget, cell_area): if self.props.icon_name or self.props.pixbuf or self.props.stock_id: @@ -1020,3 +1060,46 @@ class HobCellRendererPixbuf(gtk.CellRendererPixbuf): return 0, 0, 0, 0 gobject.type_register(HobCellRendererPixbuf) + +class HobCellRendererToggle(gtk.CellRendererToggle): + def __init__(self): + gtk.CellRendererToggle.__init__(self) + self.ctrl = HobCellRendererController(is_draw_row=True) + self.ctrl.running_mode = self.ctrl.MODE_ONE_SHORT + self.cell_attr = {"fadeout": False} + + def do_render(self, window, widget, background_area, cell_area, expose_area, flags): + if (not self.ctrl) or (not widget): + return + if self.ctrl.is_active(): + path = widget.get_path_at_pos(cell_area.x + cell_area.width/2, cell_area.y + cell_area.height/2)[0] + if path in self.ctrl.running_cell_areas: + cr = window.cairo_create() + color = gtk.gdk.Color(HobColors.WHITE) + + row_x, _, row_width, _ = widget.get_visible_rect() + border_y = self.get_property("ypad") + self.ctrl.on_draw_fadeinout_cb(cr, color, row_x, cell_area.y - border_y, row_width, \ + cell_area.height + border_y * 2, self.cell_attr["fadeout"]) + + return gtk.CellRendererToggle.do_render(self, window, widget, background_area, cell_area, expose_area, flags) + + '''delay: normally delay time is 1000ms + cell_list: whilch cells need to be render + ''' + def fadeout(self, tree, delay, cell_list=None): + if (delay < 200) or (not tree): + return + self.cell_attr["fadeout"] = True + self.ctrl.running_cell_areas = cell_list + self.ctrl.start_run(200, 0, 0, delay, (delay * 200 / 1000), tree) + + def connect_render_state_changed(self, func, usrdata=None): + if not func: + return + if usrdata: + self.ctrl.connect("run-timer-stopped", func, self, usrdata) + else: + self.ctrl.connect("run-timer-stopped", func, self) + +gobject.type_register(HobCellRendererToggle) -- cgit v1.2.3-54-g00ecf