コード例 #1
0
ファイル: card_game_view.py プロジェクト: dagophil/cardgame
    def ask_tricks(self, n):
        """
        Ask the user for the number of tricks.
        :param n: the maximum number of tricks
        """
        # Create the container with the fade in effect.
        container = Widget((self.screen.get_width()/2-200, 100), (400, self.screen.get_height()-120), 40)
        container.opacity = 0
        container.add_action(actions.FadeInAction(0.5))
        self._ask_tricks_widget = container
        self._background_widget.add_widget(container)

        # Create the question text.
        text_w = special_widgets.warning_widget((0, 0), (400, 60), "How many tricks do you make?", self._font,
                                                close_on_click=False)
        text_w.visible = True
        container.add_widget(text_w)

        # Create the numbers.
        class ChooseHandler(object):
            def __init__(self, view, nn):
                self._view = view
                self._n = nn
            def __call__(self, x, y):
                self._view._handle_say_tricks(self._n)
        for i in xrange(n+1):
            size = (50, 50)
            pos = ((i % 6) * (size[0]+20), 80 + (i/6) * (size[1] + 20))
            w = special_widgets.warning_widget(pos, size, str(i), self._font, close_on_click=False)
            w.visible = True
            w.handle_clicked = ChooseHandler(self, i)
            container.add_widget(w)
コード例 #2
0
    def ask_tricks(self, n):
        """
        Ask the user for the number of tricks.
        :param n: the maximum number of tricks
        """
        # Create the container with the fade in effect.
        container = Widget((self.screen.get_width() / 2 - 200, 100),
                           (400, self.screen.get_height() - 120), 40)
        container.opacity = 0
        container.add_action(actions.FadeInAction(0.5))
        self._ask_tricks_widget = container
        self._background_widget.add_widget(container)

        # Create the question text.
        text_w = special_widgets.warning_widget((0, 0), (400, 60),
                                                "How many tricks do you make?",
                                                self._font,
                                                close_on_click=False)
        text_w.visible = True
        container.add_widget(text_w)

        # Create the numbers.
        class ChooseHandler(object):
            def __init__(self, view, nn):
                self._view = view
                self._n = nn

            def __call__(self, x, y):
                self._view._handle_say_tricks(self._n)

        for i in xrange(n + 1):
            size = (50, 50)
            pos = ((i % 6) * (size[0] + 20), 80 + (i / 6) * (size[1] + 20))
            w = special_widgets.warning_widget(pos,
                                               size,
                                               str(i),
                                               self._font,
                                               close_on_click=False)
            w.visible = True
            w.handle_clicked = ChooseHandler(self, i)
            container.add_widget(w)
コード例 #3
0
ファイル: login_view.py プロジェクト: dagophil/cardgame
    def _create_widgets(self):
        """
        Create the widgets and return the one that contains them all.
        :return: the background widget
        """
        # Create the background widget.
        bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size())
        bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg)

        # Create the container for the input widgets.
        x = (self.screen.get_width() - INPUT_WIDTH - INPUT_PADDING[1] - INPUT_PADDING[3]) / 2
        y = self.screen.get_height() / 2
        w = INPUT_WIDTH + INPUT_PADDING[1] + INPUT_PADDING[3]
        h = self.screen.get_height() - y
        input_container = Widget((x, y), (w, h), 0)
        bg_widget.add_widget(input_container)

        # Create the input widgets.
        username_input = TextInput(
            (0, 0),
            INPUT_WIDTH,
            0,
            self._font,
            padding=INPUT_PADDING,
            color=INPUT_FORE_COLOR,
            fill=INPUT_FILL_COLOR,
            default_text="username",
            default_font=self._default_font,
        )
        host_input = copy.copy(username_input)
        host_input.default_text = "host"
        host_input.position = (0, INPUT_OFFSET)
        port_input = copy.copy(username_input)
        port_input.default_text = "port"
        port_input.position = (0, 2 * INPUT_OFFSET)
        input_container.add_widget(username_input)
        input_container.add_widget(host_input)
        input_container.add_widget(port_input)
        self._text_inputs = {"username": username_input, "host": host_input, "port": port_input}

        # Create the button widget.
        btn = special_widgets.simple_button((0, 3 * INPUT_OFFSET), (w, 100), "Login", self._font)

        def btn_clicked(x, y):
            self._ev_manager.post(events.LoginRequestedEvent())

        btn.handle_clicked = btn_clicked
        input_container.add_widget(btn)

        # Create the connection failed warning.
        self._connection_failed_warning = special_widgets.warning_widget(
            None, (400, 100), "Connection failed", self._font, screen_size=self.screen.get_size()
        )
        bg_widget.add_widget(self._connection_failed_warning)
        self._username_taken_warning = special_widgets.warning_widget(
            None, (400, 100), "Username already taken", self._font, screen_size=self.screen.get_size()
        )
        bg_widget.add_widget(self._username_taken_warning)

        return bg_widget
コード例 #4
0
ファイル: login_view.py プロジェクト: trust1995/cardgame
    def _create_widgets(self):
        """
        Create the widgets and return the one that contains them all.
        :return: the background widget
        """
        # Create the background widget.
        bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size())
        bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg)

        # Create the container for the input widgets.
        x = (self.screen.get_width() - INPUT_WIDTH - INPUT_PADDING[1] - INPUT_PADDING[3]) / 2
        y = self.screen.get_height() / 2
        w = INPUT_WIDTH + INPUT_PADDING[1] + INPUT_PADDING[3]
        h = self.screen.get_height() - y
        input_container = Widget((x, y), (w, h), 0)
        bg_widget.add_widget(input_container)

        # Create the input widgets.
        username_input = TextInput((0, 0), INPUT_WIDTH, 0, self._font, padding=INPUT_PADDING, color=INPUT_FORE_COLOR,
                                   fill=INPUT_FILL_COLOR, default_text="username",
                                   default_font=self._default_font)
        host_input = copy.copy(username_input)
        host_input.default_text = "host"
        host_input.position = (0, INPUT_OFFSET)
        port_input = copy.copy(username_input)
        port_input.default_text = "port"
        port_input.position = (0, 2*INPUT_OFFSET)
        input_container.add_widget(username_input)
        input_container.add_widget(host_input)
        input_container.add_widget(port_input)
        self._text_inputs = {"username": username_input, "host": host_input, "port": port_input}

        # Create the button widget.
        btn = special_widgets.simple_button((0, 3*INPUT_OFFSET), (w, 100), "Login", self._font)

        def btn_clicked(x, y):
            self._ev_manager.post(events.LoginRequestedEvent())
        btn.handle_clicked = btn_clicked
        input_container.add_widget(btn)

        # Create the connection failed warning.
        self._connection_failed_warning = special_widgets.warning_widget(None, (400, 100), "Connection failed",
                                                                         self._font, screen_size=self.screen.get_size())
        bg_widget.add_widget(self._connection_failed_warning)
        self._username_taken_warning = special_widgets.warning_widget(None, (400, 100), "Username already taken",
                                                                      self._font, screen_size=self.screen.get_size())
        bg_widget.add_widget(self._username_taken_warning)

        return bg_widget