Пример #1
0
    def __init__(self, repo, branches, display, pubsub):
        self.display = display
        self.repo = repo
        self.seq_combiner = Combiner(display, pubsub, self, repo, branches)
        self.button_switch = ButtonSwitch(self.display, pubsub, branches)

        self.pubsub = pubsub

        self.pubsub.sub('on_git_action', self.reconstruct_graphics)
        self.pubsub.sub('on_mouse_drag', self.offset_on_dragging)
        self.pubsub.sub('on_button_switch', self.reconstruct_graphics_on_switch_branch)
        self.pubsub.sub('on_wheel_up', self.reset_offset)

        self.invalidated = True
Пример #2
0
class Drawer:

    def __init__(self, repo, branches, display, pubsub):
        self.display = display
        self.repo = repo
        self.seq_combiner = Combiner(display, pubsub, self, repo, branches)
        self.button_switch = ButtonSwitch(self.display, pubsub, branches)

        self.pubsub = pubsub

        self.pubsub.sub('on_git_action', self.reconstruct_graphics)
        self.pubsub.sub('on_mouse_drag', self.offset_on_dragging)
        self.pubsub.sub('on_button_switch', self.reconstruct_graphics_on_switch_branch)
        self.pubsub.sub('on_wheel_up', self.reset_offset)

        self.invalidated = True

    def invalidate(self):
        self.invalidated = True

    def draw_all(self):

        if not self.invalidated:
            return

        self.draw_background()
        self.draw_buttons()
        self.draw_commits()

        self.invalidated = False

    def reconstruct_graphics(self):
        self.reconstruct_graphics_on_switch_branch(self.button_switch.value())

    def reconstruct_graphics_on_switch_branch(self, branch_name):
        self.pubsub.unsub('on_mouse_motion')
        self.seq_combiner.change_branch(branch_name)
        self.invalidate()

    def draw_background(self):
        self.display.fill(config['background'])

    def draw_buttons(self):
        self.button_switch.draw()

    def draw_commits(self):
        visible_on_screen = filter(lambda d: not d.is_out_of_screen(), self.seq_combiner.commits_to_draw)
        # print 'draw ', len(visible_on_screen), 'commits'
        for elem in visible_on_screen:
            elem.draw()

    def offset_on_dragging(self, event):
        self.offset_drawing(event.rel)
        self.invalidate()

    @staticmethod
    def offset_drawing(by):
        by_x, by_y = by
        offset_x, offset_y = relative['relative_offset']
        relative['relative_offset'] = (offset_x + 0, offset_y + by_y)

    def reset_offset(self):
        relative['relative_offset'] = (0, 0)
        self.invalidate()