def __init__(self, start_time = None, end_time = None): graphics.Sprite.__init__(self, z_order = 100) self.start_time, self.end_time = None, None self.width, self.height = None, None self.fill = None # will be set to proper theme color on render self.fixed = False self.start_label = graphics.Label("", 11, "#333", visible = False) self.end_label = graphics.Label("", 11, "#333", visible = False) self.duration_label = graphics.Label("", 11, "#FFF", visible = False) self.add_child(self.start_label, self.end_label, self.duration_label) self.connect("on-render", self.on_render)
def __init__(self, start_time = None): graphics.Scene.__init__(self) self.set_can_focus(False) # no interaction self.day_start = conf.day_start start_time = start_time or dt.datetime.now() self.view_time = start_time or dt.datetime.combine(start_time.date(), self.day_start) self.scope_hours = 24 self.fact_bars = [] self.categories = [] self.connect("on-enter-frame", self.on_enter_frame) self.plot_area = graphics.Sprite(y=15) self.chosen_selection = Selection() self.plot_area.add_child(self.chosen_selection) self.drag_start = None self.current_x = None self.date_label = graphics.Label(color=self._style.get_color(gtk.StateFlags.NORMAL), x=5, y=16) self.add_child(self.plot_area, self.date_label)
def plot(self, keys, data): self.data = data bars = dict([(bar.key, bar.normalized) for bar in self.bars]) max_val = float(max(data or [0])) new_bars, new_labels = [], [] for key, value in zip(keys, data): if max_val: normalized = value / max_val else: normalized = 0 bar = Bar(key, locale.format(self.value_format, value), normalized, self.label_color) bar.interactive = self.graph_interactive if key in bars: bar.normalized = bars[key] self.tweener.add_tween(bar, normalized=normalized) new_bars.append(bar) label = graphics.Label(stuff.escape_pango(key), size = 8, alignment = pango.Alignment.RIGHT) new_labels.append(label) self.plot_area.remove_child(*self.bars) self.remove_child(*self.labels) self.bars, self.labels = new_bars, new_labels self.add_child(*self.labels) self.plot_area.add_child(*self.bars) self.show() self.redraw()
def __init__(self, key, value, normalized, label_color): graphics.Sprite.__init__(self, cache_as_bitmap=True) self.key, self.value, self.normalized = key, value, normalized self.height = 0 self.width = 20 self.interactive = True self.fill = None self.label = graphics.Label(value, size=8, color=label_color) self.label_background = graphics.Rectangle(self.label.width + 4, self.label.height + 4, 4, visible=False) self.add_child(self.label_background) self.add_child(self.label) self.connect("on-render", self.on_render)
def __init__(self, text, interactive=True, color="#F1EAAA"): graphics.Sprite.__init__(self, interactive=interactive) self.width, self.height = 0, 0 font = gtk.Style().font_desc font_size = int(font.get_size() * 0.8 / pango.SCALE) # 80% of default self.label = graphics.Label(text, size=font_size, color=(30, 30, 30), y=1) self.color = color self.add_child(self.label) self.corner = int((self.label.height + 3) / 3) + 0.5 self.label.x = self.corner + 6 self.text = stuff.escape_pango(text) self.connect("on-render", self.on_render)