コード例 #1
0
ファイル: view.py プロジェクト: oceanchild/goobleprojects
    def create_layout(self):
        start = StartGameButton()
        howto = HowToPlayButton()
        settings = SettingsButton()

        layout = Layout()
        layout.add_to_row(0, start)
        layout.add_to_row(1, howto)
        layout.add_to_row(2, settings)

        self.layout = layout
        self.buttons = [start, howto, settings]
コード例 #2
0
ファイル: view.py プロジェクト: oceanchild/goobleprojects
    def create_layout(self, info={}):
        back = BackButton()
        turnoff = DrawableFactory().create_image("leftarrow.bmp", "TurnOffPredictions")
        turnon = DrawableFactory().create_image("rightarrow.bmp", "TurnOnPredictions")

        if "predictions.enabled" in info.keys():
            if info["predictions.enabled"]:
                onoroff = "Enabled"
            else:
                onoroff = "Disabled"
            predictions_text = "Predictions " + onoroff
        else:
            predictions_text = "Predictions Disabled"
        predictions_label = TextButton(predictions_text)

        decrement = DrawableFactory().create_image("leftarrow.bmp", "DecrementLevel")
        increment = DrawableFactory().create_image("rightarrow.bmp", "IncrementLevel")

        if "start.level" in info.keys():
            level_text = "Level " + str(info["start.level"])
        else:
            level_text = "Level 1"

        level_label = TextButton(level_text)

        layout = Layout()
        layout.add_to_row(0, turnoff, predictions_label, turnon)
        layout.add_to_row(1, decrement, level_label, increment)
        layout.add_to_row(2, back)

        self.layout = layout
        self.buttons = [back, turnon, turnoff, decrement, increment]
コード例 #3
0
ファイル: view.py プロジェクト: oceanchild/goobleprojects
    def create_layout(self):
        down = LabeledImage("downarrow.bmp", "Press the Down Arrow Key to speed up the shape")
        rotate = LabeledImage("uparrow.bmp", "Press the Up Arrow Key to rotate the shape")
        left = LabeledImage("leftarrow.bmp", "Press the Left Arrow Key to move the shape left")
        right = LabeledImage("rightarrow.bmp", "Press the Right Arrow Key to move the shape right")
        spacebar = LabeledImage("spacebar.bmp", "Press the Space Bar to drop the shape") 
        backbutton = BackButton()
        
        layout = Layout()
        layout.add_to_row(0, left)
        layout.add_to_row(1, right)
        layout.add_to_row(2, down)
        layout.add_to_row(3, rotate)
        layout.add_to_row(4, spacebar)
        layout.add_to_row(6, backbutton)

        self.buttons = [backbutton]
        self.layout = layout
コード例 #4
0
class Test(unittest.TestCase):
    
    def setUp(self):
        self.layout = Layout()
    
    def test_add_to_row_0_aligns_one_obj_in_center(self):
        drawable = self.make_drawable()
        
        self.add(0, drawable)
        self.align()
        
        self.assert_x_y(drawable, 225, 237)
        
    def test_add_to_row_0_aligns_two_obj_in_center_of_same_height(self):
        drawable = self.make_drawable()
        drawable2 = self.make_drawable()
        
        self.add(0, drawable, drawable2)
        self.align()
        
        self.assert_x_y(drawable, 195, 237)
        self.assert_x_y(drawable2, 255, 237)
    
    def test_add_to_row_0_aligns_two_obj_in_center_of_different_height(self):
        drawable = self.make_drawable()
        drawable2 = self.make_drawable(height=50)
        
        self.add(0, drawable, drawable2)
        self.align()
        
        self.assert_x_y(drawable, 195, 237)
        self.assert_x_y(drawable2, 255, 225)
        
        
    def test_add_to_row_0_and_1_align_all_in_center(self):
        drawable = self.make_drawable()
        drawable2 = self.make_drawable()
        
        self.add(0, drawable)
        self.add(1, drawable2)
        self.align()
        
        self.assert_x_y(drawable, 225, 220)
        self.assert_x_y(drawable2, 225, 255)
        
    def test_add_several_drawables(self):
        toggle_left = self.make_drawable(width=25)
        label = self.make_drawable(height=40)
        toggle_right = self.make_drawable(width=25)
        long_text = self.make_drawable(width=100)
        
        self.add(0, toggle_left, label, toggle_right)
        self.add(1, long_text)
        self.align()
        
        self.assert_x_y(toggle_left, 190, 219)
        self.assert_x_y(label, 225, 212)
        self.assert_x_y(toggle_right, 285, 219)
        self.assert_x_y(long_text, 200, 262)
        
    def test_skip_a_row(self):
        drawable = self.make_drawable()
        drawable2 = self.make_drawable()
        
        self.add(0, drawable)
        self.add(2, drawable2)
        self.align()
        self.assert_x_y(drawable, 225, 215)
        self.assert_x_y(drawable2, 225, 260)
        
    def make_drawable(self, width=50, height=25):
        drawable = MockDrawableFactory().create_text("", 0, 0)
        drawable.width = width
        drawable.height = height
        return drawable
        
    def add(self, row, *drawables):
        self.layout.add_to_row(row, *drawables)
        
    def align(self):
        self.layout.align_all(500, 500)
        
    def assert_x_y(self, drawable, x, y):
        self.assertEqual(x, drawable.get_x())
        self.assertEqual(y, drawable.get_y())
コード例 #5
0
 def setUp(self):
     self.layout = Layout()