Esempio n. 1
0
    def layout_progress(self, layout_manager, width, height):
        """Handle layout when we should display a progress bar """

        layout = cellpack.Layout()
        # add left button
        if not self.info.is_paused:
            left_button = 'pause'
        else:
            left_button = 'resume'
        left_button_rect = layout.add_image(self.button[left_button],
                                            0,
                                            0,
                                            hotspot=left_button)
        # add right button
        right_x = width - self.button['cancel'].width
        layout.add_image(self.button['cancel'], right_x, 0, hotspot='cancel')
        # pack the progress bar in the center
        progress_left = left_button_rect.width + 2
        progress_right = right_x - 2
        progress_rect = cellpack.LayoutRect(progress_left, 0,
                                            progress_right - progress_left,
                                            height)

        layout.add_rect(progress_rect, ItemProgressBarDrawer(self.info).draw)
        # middle-align everything
        layout.center_y(top=0, bottom=height)
        return layout
Esempio n. 2
0
 def test_add_image(self):
     layout = cellpack.Layout()
     image = mock.Mock()
     image.get_size.return_value = (20, 50)
     layout.add_image(image, 100, 100)
     layout.draw(self.context)
     image.draw.assert_called_with(self.context, 100, 100, 20, 50)
Esempio n. 3
0
 def test_add_text_line(self):
     layout = cellpack.Layout()
     textbox = mock.Mock()
     textbox.font.line_height.return_value = 30
     layout.add_text_line(textbox, 100, 100, 50)
     layout.draw(self.context)
     textbox.draw.assert_called_with(self.context, 100, 100, 50, 30)
Esempio n. 4
0
 def layout_all(self, layout_manager, width, height, selected):
     # make a Layout Object
     layout = cellpack.Layout()
     # add the text
     textbox = layout_manager.textbox(self.info.title)
     textbox.set_wrap_style('truncated-char')
     # 4px here is half of ListView.COLUMN_PADDING - 2px for luck
     layout.add_text_line(textbox, 4, 0, width)
     # middle-align everything
     layout.center_y(top=0, bottom=height)
     return layout
Esempio n. 5
0
 def test_alter_returned_rect(self):
     # test altering a LayoutRect after it's been returned by the add
     # method
     layout = cellpack.Layout()
     rect = layout.add(0, 0, 0, 0, self.drawer.altered)
     rect.x = 50
     rect.width = 100
     rect.height = 200
     layout.draw(self.context)
     self.assertSameList(self.drawer.method_calls,
                         [('altered', (self.context, 50, 0, 100, 200))])
Esempio n. 6
0
 def make_simple_layout(self):
     layout = cellpack.Layout()
     layout.add(0, 0, 200, 200, self.drawer.background)
     layout.add(0, 0, 50, 50, self.drawer.foo)
     layout.add_rect(cellpack.LayoutRect(50, 0, 30, 30),
                     self.drawer.right_of_foo,
                     hotspot='right_of_foo')
     layout.add_rect(cellpack.LayoutRect(0, 50, 30, 30),
                     self.drawer.under_foo,
                     hotspot='under_foo')
     return layout
Esempio n. 7
0
 def layout_text(self, layout_manager, width, height):
     """Handle layout when we should display status text"""
     layout = cellpack.Layout()
     text, color = self._calc_status_text()
     if text:
         layout_manager.set_font(self.font_size, bold=True)
         layout_manager.set_text_color(color)
         textbox = layout_manager.textbox(text)
         layout.add_text_line(textbox, 0, 0, width)
         self.add_extra_button(layout, width)
     # middle-align everything
     layout.center_y(top=0, bottom=height)
     return layout
Esempio n. 8
0
    def test_center(self):
        # check centering inside a layout
        layout = cellpack.Layout()
        layout.add(0, 0, 50, 50, self.drawer.foo)
        layout.add(55, 0, 30, 30, self.drawer.bar)

        # y-center #1 elements should be centered around y=25
        layout.center_y(top=0)
        layout.draw(self.context)
        self.assertSameList(self.drawer.method_calls,
                            [('foo', (self.context, 0, 0, 50, 50)),
                             ('bar', (self.context, 55, 10, 30, 30))])
        # y-center #2 elements should be centered around y=60
        self.drawer.reset_mock()
        layout.center_y(top=10, bottom=110)
        layout.draw(self.context)
        self.assertSameList(self.drawer.method_calls,
                            [('foo', (self.context, 0, 35, 50, 50)),
                             ('bar', (self.context, 55, 45, 30, 30))])
        # x-center #1 elements should be centered around x=50
        self.drawer.reset_mock()
        layout = cellpack.Layout()
        layout.add(0, 0, 50, 50, self.drawer.foo)
        layout.add(0, 50, 100, 50, self.drawer.bar)
        layout.center_x(left=0)
        layout.draw(self.context)
        self.assertSameList(self.drawer.method_calls,
                            [('foo', (self.context, 25, 0, 50, 50)),
                             ('bar', (self.context, 0, 50, 100, 50))])
        # x-center #2 elements should be centered with x=60 in the middle
        self.drawer.reset_mock()
        layout.center_x(left=50, right=70)
        layout.draw(self.context)
        self.assertSameList(self.drawer.method_calls,
                            [('foo', (self.context, 35, 0, 50, 50)),
                             ('bar', (self.context, 10, 50, 100, 50))]),
Esempio n. 9
0
 def test_merge(self):
     # check merging in a second layout
     layout1 = self.make_simple_layout()
     layout2 = cellpack.Layout()
     layout2.add(50, 50, 50, 50, self.drawer.merged)
     layout1.merge(layout2)
     layout1.draw(self.context)
     self.assertSameList(self.drawer.method_calls, [
         ('background', (self.context, 0, 0, 200, 200)),
         ('foo', (self.context, 0, 0, 50, 50)),
         ('right_of_foo', (self.context, 50, 0, 30, 30)),
         ('under_foo', (self.context, 0, 50, 30, 30)),
         ('merged', (self.context, 50, 50, 50, 50)),
     ])
     self.assertEquals(layout1.last_rect, layout2.last_rect)