Пример #1
0
    def __init__(self):
        graphics.Scene.__init__(self)
        self.background_color = "#333"

        self.roller = Roller()
        self.roller_container = graphics.Sprite(y=200, x=300)
        self.roller_container.add_child(self.roller)

        self.roller2 = Roller()
        self.roller_container2 = graphics.Sprite(y=200, x=300, scale_y=-1)
        self.roller_container2.add_child(self.roller2)

        self.add_child(self.roller_container, self.roller_container2)

        self.connect("on-enter-frame", self.on_enter_frame)
Пример #2
0
 def __init__(self):
     graphics.Scene.__init__(self, background_color="#333")
     self.handles = graphics.Sprite()
     self.add_child(self.handles)
     self.repeater = None
     self.connect("on-resize", self.on_resize)
     self.connect("on-first-frame", self.on_first_frame)
Пример #3
0
    def __init__(self):
        graphics.Scene.__init__(self)

        pair = graphics.Sprite(x=200, y=200)
        pair.add_child(Rect(), Rect(rotation=math.radians(-90)))
        self.add_child(pair)
        self.kick(pair.sprites[0], 180)

        triplet = graphics.Sprite(x=500, y=200)
        triplet.add_child(
            Rect(),
            Rect(rotation=math.radians(-90)),
            Rect(rotation=math.radians(-180)),
        )
        self.add_child(triplet)
        self.kick(triplet.sprites[0], 90)
Пример #4
0
    def __init__(self):
        graphics.Scene.__init__(self)

        storage = hamster.client.Storage()

        self.day_counts = {}
        categories = defaultdict(int)

        self.colors = ("#20b6de", "#fff", "#333", "#ff0", "#0ff")

        self.container = graphics.Sprite()
        self.add_child(self.container)

        self.start_date_label = graphics.Label(color = "#000")
        self.add_child(self.start_date_label)


        facts = storage.get_facts(dt.date(2006,1,1), dt.datetime.now())
        facts_per_category = defaultdict(list)
        categories = defaultdict(int)

        #facts = [fact for fact in facts if fact.category in ('work', 'hacking')]

        for category, facts in itertools.groupby(sorted(facts, key=lambda fact:fact.category), lambda fact:fact.category):
            for day, day_facts in itertools.groupby(sorted(facts, key=lambda fact:fact.date), lambda fact:fact.date):
                delta = dt.timedelta()
                for fact in day_facts:
                    delta += fact.delta
                delta = delta.seconds / 60 / 60 + delta.days * 24

                facts_per_category[category].append((day, delta))

            categories[category] += 1


        self.categories = categories.keys()


        self.spirals = []
        self.start_date = dt.date(2006, 1, 1)

        for i, category in enumerate(categories):
            ring = TimeRing(facts_per_category[category],
                            self.start_date,
                            self.colors[i + 1])
            ring.min_radius = i * 20 + 0
            ring.width = len(self.categories) * 30

            #self.animate(ring, 3, width = len(self.categories) * 30, easing = pytweener.Easing.Expo.ease_out)
            self.container.add_child(ring)
            self.spirals.append(ring)

        self.connect("on-enter-frame", self.on_enter_frame)
        self.connect("on-mouse-move", self.on_mouse_move)
        self.connect("on-scroll", self.on_scroll)
Пример #5
0
    def __init__(self):
        graphics.Scene.__init__(self)

        self.nodes = []
        self.tick = 0
        self.phase = 0
        self.container = graphics.Sprite()
        self.add_child(self.container)
        self.framerate = 30

        self.connect("on-enter-frame", self.on_enter_frame)
        self.connect("on-mouse-move", self.on_mouse_move)
Пример #6
0
    def __init__(self):
        graphics.Scene.__init__(self)

        self.tweener.default_duration = 0.1

        self.total_hours = 24
        self.height = 500
        self.pixels_in_minute = float(self.height) / (self.total_hours * 60)

        self.spacing = 1

        self.fact_list = graphics.Sprite(x=40, y=50)
        self.add_child(self.fact_list)

        self.fragments = Container(30)

        self.connectors = graphics.Sprite(x=self.fragments.x +
                                          self.fragments.width)
        self.connectors.width = 30

        self.entries = Container(500,
                                 x=self.connectors.x + self.connectors.width)

        self.fact_list.add_child(self.fragments, self.connectors, self.entries)

        self.storage = hamster.client.Storage()

        self._date = dt.datetime.combine(dt.date.today(),
                                         dt.time()) + dt.timedelta(hours=5)

        self.date_label = graphics.Label("", size=18, y=10, color="#444")
        self.add_child(self.date_label)

        self.entry_positions = []

        self.set_size_request(610, 500)

        self.current_entry = None

        self.connect("on-enter-frame", self.on_enter_frame)
Пример #7
0
    def __init__(self):
        graphics.Scene.__init__(self)


        # letter display
        letter_display = graphics.Sprite(x=100)
        self.letter = graphics.Label(x=30, y = 40, text="F", size=200, color="#333")
        letter_display.add_child(self.letter)

        self.add_child(letter_display)


        # cell board
        cellboard = graphics.Sprite(x=450)
        self.letter_cell = BrailCell("f", x = 50, y=50, width = 200, interactive = True)
        cellboard.add_child(self.letter_cell)

        for i in range(2):
            for j in range(3):
                cellboard.add_child(graphics.Label(str(j + 1 + i * 3),
                                                   size = 50,
                                                   color = "#333",
                                                   x = i * 230 + 20,
                                                   y = j * 90 + 60))

        self.add_child(cellboard)

        # lowerboard
        lowerboard = graphics.Sprite(x=50, y = 450)
        cell_width = 40
        for i, letter in enumerate(string.ascii_uppercase[:13]):
            tile = BrailTile(letter = letter, cell_width = cell_width, x = i * (cell_width + 10) + 10)
            tile.connect("on-click", self.on_tile_click)
            lowerboard.add_child(tile)

        self.add_child(lowerboard)
Пример #8
0
    def __init__(self):
        graphics.Scene.__init__(self)

        self.circle1 = CenteredCircle(100, 300, 90)
        self.circle2 = CenteredCircle(350, 300, 50)

        self.add_child(self.circle1)
        self.add_child(self.circle2)

        self.tangent = graphics.Sprite(interactive=False)
        self.add_child(self.tangent)

        self.draw_tangent()

        self.connect("on-drag", self.on_drag_circle)
Пример #9
0
    def __init__(self):
        graphics.Scene.__init__(self)

        self.container = graphics.Sprite(x=300, y=250)
        self.add_child(self.container)

        width, height = 10, 10

        self.inner = Cog(radius=40,
                         teeth=20,
                         rotation=-0.114,
                         fill="#D5C439",
                         tooth_width=width,
                         tooth_height=height)
        self.outer = Cog(radius=200,
                         teeth=100,
                         fill="#CEE2A6",
                         inset=True,
                         tooth_height=height,
                         tooth_width=width,
                         axis_distance=10)

        radius, teeth = 75, 37

        self.middles = []
        distance, angle = -120, 0
        for i in range(3):
            angle += 120
            x, y = (math.sin(math.radians(angle)) * distance,
                    math.cos(math.radians(angle)) * distance)
            middle = Cog(x=x,
                         y=y,
                         rotation=-0.114,
                         radius=75,
                         teeth=37,
                         fill="#3D699B",
                         tooth_width=width,
                         tooth_height=height,
                         axis_distance=50)
            self.middles.append(middle)

        self.container.add_child(self.outer, self.inner)
        self.container.add_child(*self.middles)

        self.reference_point = None
        self.connect("on-click", self.on_click)

        self.connect("on-enter-frame", self.on_enter_frame)
Пример #10
0
    def __init__(self, active=True, **kwargs):
        Container.__init__(self, **kwargs)

        #: whether the spinner is spinning or not
        self.active = active

        self._scene = None
        self.expose_handler = None

        #: number of beams in the progress indicator
        self.edges = 11

        self.inner_radius = 6
        self.outer_radius = 13
        self.tick_thickness = 3

        #: motion speed. the higher the number the slower the redraw is performed
        self.speed = 2
        self._frame = 0

        self._spinner = graphics.Sprite(cache_as_bitmap=False)
        self.connect_child(self._spinner, "on-render", self.on_spinner_render)
        self.add_child(self._spinner)
Пример #11
0
    def __init__(self, poly=[], **kwargs):
        graphics.Sprite.__init__(self, **kwargs)

        # the inner radius of the square
        self.inner_radius = 20

        self.poly = poly or [(10, 250), (500, 150)]

        self.vector = self.poly[:2]

        self.snap_to_pixel = False

        # roll directoin - clockwise or counter-clockwise
        self.direction = 1
        self.outside = False  # if outside is set to true, will flip to the other side of the vector

        self._abs_distance_to_b = 0

        self.roller = graphics.Sprite()
        self.add_child(self.roller)
        self.roller.connect("on-render", self.on_render_roller)

        self.connect("on-render", self.on_render)
Пример #12
0
    def __init__(self, width, fact, color, **kwargs):
        graphics.Sprite.__init__(self, **kwargs)
        self.width = width
        self.height = 27
        self.natural_height = 27
        self.fact = fact
        self.color = color

        self.interactive = True
        self.mouse_cursor = gdk.CursorType.XTERM

        self.fact_labels = graphics.Sprite()

        self.start_label = graphics.Label("",
                                          color="#333",
                                          size=11,
                                          x=10,
                                          y=5,
                                          interactive=True,
                                          mouse_cursor=gdk.CursorType.XTERM)
        self.start_label.text = "%s - " % fact.start_time.strftime("%H:%M")
        self.fact_labels.add_child(self.start_label)

        self.end_label = graphics.Label("",
                                        color="#333",
                                        size=11,
                                        x=65,
                                        y=5,
                                        interactive=True,
                                        mouse_cursor=gdk.CursorType.XTERM)
        if fact.end_time:
            self.end_label.text = fact.end_time.strftime("%H:%M")
        self.fact_labels.add_child(self.end_label)

        self.activity_label = graphics.Label(fact.activity,
                                             color="#333",
                                             size=11,
                                             x=120,
                                             y=5,
                                             interactive=True,
                                             mouse_cursor=gdk.CursorType.XTERM)
        self.fact_labels.add_child(self.activity_label)

        self.category_label = graphics.Label("",
                                             color="#333",
                                             size=9,
                                             y=7,
                                             interactive=True,
                                             mouse_cursor=gdk.CursorType.XTERM)
        self.category_label.text = stuff.escape_pango(" - %s" % fact.category)
        self.category_label.x = self.activity_label.x + self.activity_label.width
        self.fact_labels.add_child(self.category_label)

        self.duration_label = graphics.Label(stuff.format_duration(fact.delta),
                                             size=11,
                                             color="#333",
                                             interactive=True,
                                             mouse_cursor=gdk.CursorType.XTERM)
        self.duration_label.x = self.width - self.duration_label.width - 5
        self.duration_label.y = 5
        self.fact_labels.add_child(self.duration_label)

        self.add_child(self.fact_labels)

        self.edit_links = graphics.Sprite(x=10, y=110, opacity=0)

        self.delete_link = graphics.Label("Delete",
                                          size=11,
                                          color="#555",
                                          interactive=True)
        self.save_link = graphics.Label("Save",
                                        size=11,
                                        x=390,
                                        color="#555",
                                        interactive=True)
        self.cancel_link = graphics.Label("Cancel",
                                          size=11,
                                          x=440,
                                          color="#555",
                                          interactive=True)
        self.edit_links.add_child(self.delete_link, self.save_link,
                                  self.cancel_link)

        self.add_child(self.edit_links)

        for sprite in self.fact_labels.sprites:
            sprite.connect("on-click", self.on_sprite_click)

        self.connect("on-render", self.on_render)
        self.connect("on-click", self.on_click)