Beispiel #1
0
 def show_splash_screen(self):
     self.render_surface.fill(Theme.get_color("background"))
     Text(self.render_surface, (0, 200, 1920, 400),
          "Kanaraimasu").set_font_size(200).set_themed().render()
     Text(self.render_surface, (0, 700, 1920, 200),
          "Loading...").set_themed().render()
     self.render()
Beispiel #2
0
    def show_round_points(self, points):
        """
        Show the points that each player made in that trick.
        """
        texts = []
        for point, player in zip(points, self._player_order):
            if point >= 0:
                texts.append("%s made %d points." % (player, point))
            else:
                texts.append("%s lost %d points." % (player, -point))

        x = self.screen.get_width() / 2 - 200
        y = 150
        yd = 40
        ws = []
        for i, text in enumerate(texts):
            w = Text((x, y + i * yd), (400, 40),
                     50,
                     text,
                     self._font,
                     fill=(0, 0, 0, 160))
            w.opacity = 0
            fade_in = actions.FadeInAction(0.5)
            fade_out = actions.DelayedAction(3, actions.FadeOutAction(0.5))
            w.add_action(actions.ChainedAction(fade_in, fade_out))
            self._background_widget.add_widget(w)
            ws.append(w)

        def remove_widgets():
            for w in ws:
                self._background_widget.remove_widget(w)

        self._ev_manager.post(
            events.DelayedEvent(4, events.CallFunctionEvent(remove_widgets)))
Beispiel #3
0
    def __init__(self,
                 state,
                 gridpos: Vector2D,
                 size: Vector2D = None,
                 position: Vector2D = Vector2D.zero(),
                 onclick=None):
        super(Tile, self).__init__(Text(''), size, position, state, onclick)

        self.gridpos = gridpos
Beispiel #4
0
    def __init__(self, w, h, gsm):
        self.width = w
        self.height = h

        self.gsm = gsm

        self.widgets = [
            Button(self.width // 2, self.height // 2, 250, 75, 'Menu', self.gsm.menu),
            Text(self.width // 2, self.height // 3, 'You Won!', (255, 255, 255))
        ]
Beispiel #5
0
    def __init__(self, *args, **kwargs):
        super(Page, self).__init__(**kwargs)
        self.orientation = "vertical"

        self.textbox = MyBoxLayout(padding=[dp(10), 0], size_hint_y=0.3)
        self.text_container = ScrollView(
            scroll_type=["bars"],
            effect_cls="ScrollEffect",
            bar_width=15,
            do_scroll_y=False,
        )

        self.entry = Text(
            size_hint=(None, 1),
            base_direction="rtl",
            font_size="75dp",
            unfocus_on_touch=False,
        )

        self.preview = MLabel(
            halign="right",
            valign="bottom",
            font_size=self.entry.font_size // 3,
            color=self.entry.foreground_color[:3] + [0.8],
            size_hint_y=0.1,
            padding_x=10,
            markup=True,
            text=self.preview_text,
        )
        self.preview.bind(on_ref_press=lambda object, text: setattr(
            self.entry, "text", eval(text)))
        self.preview.bind(
            on_ref_press=lambda object, text: setattr(object, "text", ""))

        self.layout = ButtonStack(
            size_hint=(1, 0.5),
            spacing=5,
            rows=self.rows,
            cols=self.cols,
            font_size=dp(19),
            text_list=self.text_list,
        )

        self.text_container.add_widget(self.entry)
        self.textbox.add_widget(self.text_container)
        Clock.schedule_interval(self.scroll_focus, 0.1)

        self.layout.buttons[0][0].text = self.page_name
        self.layout.size_change(0, 0, 2)
        self.layout.size_change(-1, -1, 2)
        self.spacing = 5
        for widget in (self.preview, self.textbox, self.layout):
            self.add_widget(widget)
Beispiel #6
0
    def __init__(self, w, h, gsm):
        self.width = w
        self.height = h

        self.gsm = gsm

        self.font = pygame.font.SysFont('Source Code Pro', 24)

        self.widgets = [
            Button(self.width // 2, self.height // 2, 250, 75, 'Menu', self.gsm.menu),
            Text(self.width // 2, self.height // 3, 'Game Over!', (255, 255, 255))
        ]
Beispiel #7
0
    def __init__(self, w, h, gsm):
        self.width = w
        self.height = h

        self.gsm = gsm

        self.font = pygame.font.SysFont('Source Code Pro', 50)

        self.widgets = [
            Button(self.width // 2, self.height // 2, 250, 75, 'Play', self.gsm.play),
            Button(self.width // 2, self.height // 2 + 100, 250, 75, 'Quit', self.gsm.stop),
            Text(self.width // 2, self.height // 3, 'Snake', (255, 255, 255))
        ]
Beispiel #8
0
    def __init__(self, w: int, h: int, gsm: GameStateManager) -> None:
        self.width = w
        self.height = h

        self.gsm = gsm

        self.font = pygame.font.SysFont('Source Code Pro', 50)

        self.widgets = [
            Button(self.width // 2, self.height // 2, 250, 75, 'Resume', self.gsm.play),
            Button(self.width // 2, self.height // 2 + 100, 250, 75, 'Menu', self.gsm.menu),
            Text(self.width // 2, self.height // 3, 'Pause', (255, 255, 255))
        ]
Beispiel #9
0
    def show_final_points(self):
        """
        Show the final winners and the final points.
        """
        if len(self.final_winners) == 1:
            texts = ["Final winner: %s" % self.final_winners[0]]
        else:
            texts = ["Final winners: %s" % ", ".join(self.final_winners)]
        texts.append("")
        for point, player in zip(self.final_points, self._player_order):
            texts.append("%s: %s" % (player, point))

        x = self.screen.get_width() / 2 - 200
        y = 150
        yd = 40
        for i, text in enumerate(texts):
            w = Text((x, y + i * yd), (400, 40),
                     50,
                     text,
                     self._font,
                     fill=(0, 0, 0, 160))
            w.opacity = 0
            w.add_action(actions.FadeInAction(0.5))
            self._background_widget.add_widget(w)
Beispiel #10
0
    def __init__(self, render_surface, surface_size):
        Screen.__init__(self, render_surface, surface_size)

        self.checkboxes = {
            "randomize_kana": {
                "checkbox": Checkbox(
                    self.render_surface,
                    (600, 450, 720, 100),
                    "Randomize Kana",
                ).set_themed(),
                "setting": "randomize_kana",
            },
        }

        self.kana_widgets = {
            "hiragana": {
                "checkbox": Checkbox(
                    self.render_surface,
                    (200, 600, 700, 100),
                    "Learn Hiragana",
                ).set_themed(),
                "button": Button(
                    self.render_surface,
                    (1000, 600, 700, 100),
                    "Select which kana",
                ).set_themed(),
                "setting": "learn_hiragana",
            },
            "katakana": {
                "checkbox": Checkbox(
                    self.render_surface,
                    (200, 750, 700, 100),
                    "Learn Katakana",
                ).set_themed(),
                "button": Button(
                    self.render_surface,
                    (1000, 750, 700, 100),
                    "Select which kana",
                ).set_themed(),
                "setting": "learn_katakana",
            },
            "kanji": {
                "checkbox": Checkbox(
                    self.render_surface,
                    (200, 900, 700, 100),
                    "Learn Kanji",
                ).set_themed(),
                "button": Button(
                    self.render_surface,
                    (1000, 900, 700, 100),
                    "Kanji options",
                ).set_themed(),
                "setting": "learn_kanji",
            },
        }

        # set the 'selected' property of the checkboxes and kana_widgets
        for checkbox_widget_id, checkbox_widget in self.checkboxes.items():
            checkbox = checkbox_widget["checkbox"]
            checkbox.selected = Settings.get(checkbox_widget["setting"])
        for kana_widget_id, kana_widget in self.kana_widgets.items():
            checkbox = kana_widget["checkbox"]
            checkbox.selected = Settings.get(kana_widget["setting"])

        theme = Settings.get("theme")
        themes = Settings.get("themes")
        self.widgets = {
            "heading_settings": Heading(
                self.render_surface, (0, 0, 1920, 100), "Settings"
            ).set_themed(),
            "button_menu": Button(
                self.render_surface, (10, 10, 230, 80), "Menu"
            ).set_themed(),
            "theme_text": Text(
                self.render_surface,
                (500, 150, 920, 100),
                f"Current theme: '{theme}'",
            ).set_themed(),
        }

        # get the theme index of the current theme
        if theme in themes:
            self.theme_index = list(themes.keys()).index(theme)
        else:
            # somehow the theme in the settings file isn't available, reset
            print(f"theme {theme} is invalid! resetting to default")
            self.theme_index = 0
            Settings.set("theme", next(iter(themes)))
            Collections.reapply_theme()

        # theme related widgets
        theme_name = list(themes.keys())[self.theme_index]
        apply_theme_text = f"Apply theme: {theme_name}"
        self.theme_left = Button(
            self.render_surface, (300, 275, 100, 100), "<"
        ).set_themed()
        self.theme_apply = Button(
            self.render_surface, (500, 275, 920, 100), apply_theme_text
        ).set_themed()
        self.theme_right = Button(
            self.render_surface, (1520, 275, 100, 100), ">"
        ).set_themed()
            ("birthyear", "int"), ("gender", "int"),
            ("email", "text"), ("url", "text"),
            ("language1", "text"), ("language2", "text"),
            ("commment", "text"))

p = path.join(path.dirname(__file__), "questionnaire.dat")
con = sqlite3.connect(p)
BaseMapper.setconnention(con)
Profile.createtable(ignore_error=True)

from validators import NotEmpty, IntValidator, IntRangeValidator,\
    URLValidator, EmailValidator, ValidationError
from widgets import Text, Select, Radio, Submit, Reset, Form

languages = [("", "---")]+[(x, x) for x in ["Perl", "PHP", "Python", "Ruby"]]
forms = ( Text("lastname", u"名字", validators=(NotEmpty(),)),
          Text("firstname", u"名前", validators=(NotEmpty(),)),
          Select("birthyear", u"生まれた年",
                 options=[("0", "---")]+\
                 [(str(x), str(x)) for x in range(1900, 2007)],
                 validators=(NotEmpty(), IntRangeValidator(1900, 2007),)),
          Radio("gender", u"性別",
                 options=(("1", u"男性"), ("2", u"女性")),
                validators=(IntRangeValidator(1, 2),)),
          Text("Email", u"めーるあどれす",
               validators=(EmailValidator(),), attrs={"size":"40"}),
          Text("url", u"URL",
               validators=(URLValidator(),), attrs={"size":"40"}),
          Select("language1", u"一番好きな言語は?",
                 options=languages, validators=(NotEmpty(),)),
          Select("language2", u"二番目に好きな言語は?",
Beispiel #12
0
from grid import GridManager, AppDatabase
from widgets import Text, WidgetManager, Button

pygame.init()
size = width, height = 700, 720
screen = pygame.display.set_mode(size, pygame.DOUBLEBUF)

# allowed events
pygame.event.set_allowed([
    pygame.QUIT, pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP,
    pygame.MOUSEMOTION, pygame.KEYUP
])

pygame.display.set_caption('A* visualizer')

info = Text('', color=colors.WHITE)
manager = WidgetManager([info])

grid = GridManager(Vector2D(50, 50), info)

framerate = 0
t0 = time.time()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            AppDatabase.database().save()
            sys.exit()

        grid.event(event)
        manager.event(event)
Beispiel #13
0
	TRANSPARENCY = True
	TRANSPARENCY_VALUE = 0.4

COLOR_01="#282a2e"           # black
COLOR_02="#A54242"           # red
COLOR_03="#8C9440"           # green
COLOR_04="#de935f"           # yellow
COLOR_05="#5F819D"           # blue
COLOR_06="#85678F"           # magenta
COLOR_07="#5E8D87"           # cayn
COLOR_08="#969896"           # white



left = [
	Text(bgColor="", fgColor="#000000", text=" User: "******"", fgColor="#000000"), 
	#ProgressBar()
	#Text(bgColor=COLOR_01, fgColor=COLOR_02, text=" | "),
	#Text(text="2 label")
]
centr = [
	DateTime(fmt="%Y-%m-%d %H:%M:%S", bgColor="", fgColor="#000000"), 
	#Text(text="4 label"), 
	#Text(text="3 label")
]
right = [
	Text(bgColor="", fgColor="#000000", text="CPU: "),
	CpuUsage(fmt='%s %% ', percpu=True, bgColor="", fgColor="#000000"), 
	Text(bgColor="", fgColor="#000000", text="Vol: "),
	Volume(bgColor="", fgColor="#000000"),
Beispiel #14
0
    def _show_player_order(self, player_order):
        """
        Show the player order.
        :param player_order: the player order
        """
        width = 100
        height = 50
        margin_x = 10
        margin_y = 10

        cx = self._screen.get_width() / 2
        cy = self._screen.get_height() / 2
        rx = self._screen.get_width() / 2 - width / 2 - margin_x
        ry = self._screen.get_height() / 2 - height / 2 - margin_y

        # Rotate the players, so that the current user is at the bottom of the window and the player order is clockwise.
        i = player_order.index(self.username)
        player_order = player_order[i + 1:] + player_order[:i]

        # Compute the positions of the other players.
        if len(player_order) == 1:
            self._player_positions[player_order[0]] = (cx,
                                                       height / 2 + margin_y)
        else:
            n = len(player_order) - 1
            for i, p in enumerate(player_order):
                d = i * math.pi / n
                x = int(cx - math.cos(d) * rx)
                y = int(cy - math.sin(d) * ry)
                self._player_positions[p] = (x, y)
        self._player_positions[self.username] = self.screen.get_size()

        # Show the other players.
        # TODO: The widget size should adapt to the length of the player name.
        for p in player_order:
            pos = self._player_positions[p]
            x = pos[0] - width / 2
            y = pos[1] - height / 2
            w = special_widgets.warning_widget((x, y), (width, height),
                                               p,
                                               self._font,
                                               close_on_click=False)
            w.visible = True
            self._background_widget.add_widget(w)

        # Add the box for the said tricks.
        width = 80
        for p in player_order:
            pos = self._player_positions[p]
            x = pos[0] - width / 2
            y = pos[1] + height / 2 + 10
            w = Text((x, y), (width, height),
                     50,
                     "0/0",
                     self._font,
                     fill=(0, 0, 0, 160))
            w.opacity = 0
            self._said_tricks_widgets[p] = w
            self._background_widget.add_widget(w)
        height = 40
        x = self._user_move_widget.position[0] + self._user_move_widget.size[
            0] - width
        y = self._user_move_widget.position[1] + self._user_move_widget.size[
            1] + 10
        w = Text((x, y), (width, height),
                 50,
                 "0 / 0",
                 self._font,
                 fill=(0, 0, 0, 160))
        w.opacity = 0
        self._said_tricks_widgets[self.username] = w
        self._background_widget.add_widget(w)
Beispiel #15
0
bars = BarManager(screen, 200, shuffle=True, color=colors.WHITE)
bars_range = range(len(bars.sizes))

# change this as necessary to change sorting algorithm
# sorta = CocktailSort(bars.sizes[:])
# sorta = InsertionSort(bars.sizes[:])
# sorta = CycleSort(bars.sizes[:])
# sorta = QuickSort(bars.sizes[:], 0, len(bars.sizes) - 1)
sorta = algorithms.MergeSort(bars.sizes[:])

# limit queue size to be safe
ac = AlgorithmController(sorta, maxsize=10000)
ac.start()

# button to control algorithm flow
flip_button = Button(Text('', color=colors.WHITE),
                     size=Vector2D(70, 25),
                     color=Color(0, 0, 0, 0),
                     onclick=lambda _: should_sort.flip())
flip_button.position = Vector2D(
    Vector2D.center(screen.get_rect(),
                    screen.get_rect().size).x - (flip_button.size.x / 2), 0)
flip_button.onhover = Hover(BLACK_TEXT_WHITE_BACKGROUND,
                            WHITE_TEXT_TRANSPARENT_BACKGROUND)


def fbflip(val):
    flip_button.text.text = 'RUNNING' if val else 'STOPPED'


fbflip(should_sort.get())
Beispiel #16
0
#!/usr/bin/env python
# coding: utf-8

from SimpleAppServer import expose, test
from httphandler import Response
from simpletemplate import SimpleTemplate

from validators import NotEmpty, RegexValidator
from widgets import Text, Submit, Form

editforms = (Text(
    'username',
    u'ユーザ名',
    validators=(NotEmpty(), RegexValidator(r'[A-Za-z\d]')),
),
             Text(
                 'password',
                 u'パスワード',
                 validators=(NotEmpty(), RegexValidator(r'[A-Za-z\d]')),
             ), Submit('submit', u'ログイン'))
loginform = Form(editforms, {'action': '/login', 'method': 'POST'})

base_body = """<html><body>%s</body></html>"""
Beispiel #17
0
#!/usr/bin/env python
# coding: utf-8

from simpleappserver import expose, test
from httphandler import Response
from simpletemplate import SimpleTemplate

from validators import NotEmpty, RegexValidator
from widgets import Text, Submit, Form

editforms = (Text(
    "username",
    u"ユーザ名",
    validators=(NotEmpty(), RegexValidator(r"[A-Za-z\d]")),
),
             Text(
                 "password",
                 u"パスワード",
                 validators=(NotEmpty(), RegexValidator(r"[A-Za-z\d]")),
             ), Submit("submit", u"ログイン"))
loginform = Form(editforms, {"action": "/login", "method": "POST"})

base_body = """<html><body>%s</body></html>"""


@expose
def login_form(_request, values={}, errors={}):
    body = base_body % ("${form.display(values, errors)}")
    res = Response()
    t = SimpleTemplate(body)
    values["password"] = ""
Beispiel #18
0
class Rssurl(BaseMapper):
    rows = (("title", "text"), ("url", "text"))


p = path.join(path.dirname(__file__), "urls.dat")
con = sqlite3.connect(p)
BaseMapper.setconnection(con)

Rssurl.createtable(ignore_error=True)

from validators import NotEmpty, IntValidator, URLValidator
from widgets import Hidden, Text, Submit, Form

editforms = (Text("title",
                  u"タイトル",
                  validators=(NotEmpty(), ),
                  attrs={"size": 40}),
             Text("url",
                  u"RSSのURL",
                  validators=(URLValidator(), ),
                  attrs={"size": 40}),
             Hidden(
                 "item_id",
                 u"ID",
                 validators=(IntValidator(), ),
             ), Submit("submit", u"登録"))

editform = Form(editforms, {"action": "/edit", "method": "POST"})

addforms = (Text("title",
                 u"タイトル",
Beispiel #19
0
	#UserName(bgColor="#4B3B51", fgColor="#ffffff"), 
	#Mode(bgColor="#4B3B51", fgColor="#ffffff"),
	#ProgressBar()
	#Text(bgColor=COLOR_01, fgColor=COLOR_02, text=" | "),
	#Text(text="2 label")
]
centr = [
	#Text(text="4 label"), 
	#Text(text="3 label")
]
right = [
	#Image(bgColor="#ffffff", 
	#	path="/home/daniil/unknowdock/widgets/icons/arr5.png"),
	#Image(bgColor="#CB755B", 
	#	path="/home/daniil/unknowdock/widgets/icons/cpu.png"),
	Text(bgColor="#260b59", fgColor="#e90cb2", text=" CPU: "),
	CpuUsage(fmt='%s %% ', percpu=True, bgColor="#260b59", fgColor="#e90cb2"), 
	#Image(path="/home/daniil/unknowdock/widgets/icons/arr4.png"),
	#VolumeImage(), 
	Text(bgColor="#260b59", fgColor="#b70b41", text=" | "),
	#Volume(bgColor="#92B0A0", fgColor="#ffffff"),
	#Text(text=" % ", bgColor="#92B0A0", fgColor="#ffffff"),
	#Image(path="/home/daniil/unknowdock/widgets/icons/arr3.png"),
	#Text(bgColor="#4B3B51", fgColor="#ffffff", text=" | "),
	#WeatherLabel(bgColor="#C0C0A2", fgColor="#ffffff"),
	#Text(bgColor="#4B3B51", fgColor="#ffffff", text=" | "),
	#Image(path="/home/daniil/unknowdock/widgets/icons/arr2.png"),
	DateTime(fmt="%Y-%m-%d %H:%M:%S", bgColor="#260b59", fgColor="#e90cb2"), 
	Text(bgColor="#260b59", fgColor="#ffffff", text=" "),
]
Beispiel #20
0
from os import path
from simplemapper import BaseMapper

class Rssurl(BaseMapper):
    rows=(('title', 'text'), ('url', 'text'))

p=path.join(path.dirname(__file__), 'urls.dat')
con=sqlite3.connect(p)
BaseMapper.setconnection(con)

Rssurl.createtable(ignore_error=True)

from validators import NotEmpty, IntValidator, URLValidator
from widgets import Hidden, Text, TextArea, Submit, Reset, Form

editforms=(Text('title', u'タイトル',
            validators=(NotEmpty(),), attrs={'size':40}),
           Text('url', u'RSSのURL',
            validators=(URLValidator(),), attrs={'size':40}),
           Hidden('item_id', u'ID',
            validators=(IntValidator(),) ),
           Submit('submit', u'登録'))

editform=Form(editforms, {'action':'/edit', 'method':'POST'})

addforms=(Text('title', u'タイトル',
            validators=(NotEmpty(),), attrs={'size':40}),
          Text('url', u'RSSのURL',
            validators=(URLValidator(),), attrs={'size':40}),
          Submit('submit', u'登録'))

addform=Form(addforms, {'action':'/add', 'method':'POST'})
    rows = (('lastname', 'text'), ('firstname', 'text'), ('birthyear', 'int'),
            ('gender', 'int'), ('email', 'text'), ('url', 'text'),
            ('language1', 'text'), ('language2', 'text'), ('comment', 'text'))


p = path.join(path.dirname(__file__), 'questionnaire.dat')
con = sqlite3.connect(p)
BaseMapper.setconnection(con)
Profile.createtable(ignore_error=True)

from validators import NotEmpty, IntValidator, IntRangeValidator, \
        URLValidator, EmailValidator, ValidationError
from widgets import Text, Select, Radio, Submit, Reset, Form

languages = [('', '---')] + [(x, x) for x in ['Perl', 'PHP', 'Python', 'Ruby']]
forms = ( Text('lastname', u'名字', validators=(NotEmpty(),)),
          Text('firstname', u'名前', validators=(NotEmpty(),)),
          Select('birthyear', u'生まれた年',
                 options=[('0', '---')] +\
                         [(str(x), str(x)) for x in range(1940, 2007)],
                 validators=(NotEmpty(), IntRangeValidator(1900, 2007), )),
          Radio('gender', u'性別',
                  options = (('1', u'男性'), ('2', u'女性')),
                  validators = (IntRangeValidator(1, 2),)),
          Text('email', u'メールアドレス',
              validators=(EmailValidator(),), attrs={'size': '40'}),
          Text('url', u'URL',
              validators=(URLValidator(),), attrs={'size': '40'}),
          Select('language1', u'一番好きな言語は?',
              options=languages, validators=(NotEmpty(), )),
          Select('language2', u'に番目に好きな言語は?',
Beispiel #22
0
    def __init__(self, render_surface, surface_size):
        Screen.__init__(self, render_surface, surface_size)

        # the surface where the user draws on
        self.drawing_surface = pygame.Surface(self.surface_size)

        self.stroke_width = Settings.get("stroke_width")
        self.bounding_box_color = Theme.get_color("foreground")
        self.cross_color = Theme.get_color("secondary")
        self.draw_color = Theme.get_color("draw")

        # ingame parameters
        self.pos = (0, 0)

        # widgets that are always present
        self.widgets = {
            "heading":
            Heading(self.render_surface, (0, 0, 1920, 100)).set_themed(),
            "button_menu":
            Button(self.render_surface, (10, 10, 230, 80),
                   "Menu").set_themed(),
            "progress_text":
            Text(self.render_surface, (10, 125, 1900, 100),
                 "Completed: X / Y").set_align(
                     Text.ALIGN_RIGHT_CENTER).set_themed(),
        }

        # widgets that are kanji related
        self.kanji_widgets = [
            # these are used to show up to 3 lines of kanji information
            Text(
                self.render_surface,
                (1160, i, 660, 100),
            ).set_font_size(65).set_align(Text.ALIGN_LEFT_TOP).set_themed()
            for i in [225, 285, 345]
        ]
        self.kanji_widgets.append(
            # this is the kanji character itself
            Text(self.render_surface,
                 (1160, 400, 660, 660)).set_font_size(500).set_font_name(
                     "assets/font/KanjiStrokeOrders_v2.016.ttf").set_themed())

        # widgets in draw state
        self.clear_button = (Button(self.render_surface, (860, 290, 200, 150),
                                    "Clear").set_font_size(90).set_themed())
        self.done_button = Button(self.render_surface, (860, 490, 200, 200),
                                  "Done").set_themed()

        # widgets in the verify state
        self.wrong_button = (Button(
            self.render_surface, (860, 290, 200, 150),
            "Wrong").set_font_size(80).set_themed().set_rect_color(
                Theme.get_color("bad")))
        self.good_button = (Button(self.render_surface, (860, 490, 200, 200),
                                   "Good").set_themed().set_rect_color(
                                       Theme.get_color("good")))

        # widgets in the done state
        self.score_widget = Text(
            self.render_surface,
            (0, 550, 1920, 200),
            "Learned x kana while making y mistakes",
        ).set_themed()
        done_widgets = [
            Text(self.render_surface, (0, 400, 1920, 200),
                 "Done!").set_font_size(200).set_themed(),
            self.score_widget,
            Text(
                self.render_surface,
                (0, 650, 1920, 200),
                "Go back to the menu to try again,",
            ).set_themed(),
            Text(
                self.render_surface,
                (0, 750, 1920, 200),
                "or change the kana you want to learn",
            ).set_themed(),
        ]

        self.state_widgets = {
            "draw": [self.clear_button, self.done_button],
            "verify": [self.wrong_button, self.good_button],
            "done": done_widgets,
        }
Beispiel #23
0
    def _create_widgets(self):
        """
        Create the widgets and return the background widget.
        :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 waiting text.
        wait_box = special_widgets.warning_widget(
            None, (400, 100),
            "Waiting for other players",
            self._font,
            screen_size=self.screen.get_size(),
            close_on_click=False)
        wait_box.visible = True
        bg_widget.add_widget(wait_box)
        self._warnings["wait_box"] = wait_box

        # Create the "invalid num tricks" warning.
        invalid_num_warning = special_widgets.warning_widget(
            None, (400, 100),
            "Invalid number of tricks",
            self._font,
            screen_size=self.screen.get_size())
        bg_widget.add_widget(invalid_num_warning)
        self._warnings["invalid_num_tricks"] = invalid_num_warning

        # Create the chat widget.
        chat_box = special_widgets.warning_widget(
            (10, self.screen.get_height() - 260), (260, 200),
            "chat",
            self._font,
            close_on_click=False)
        chat_box.visible = True
        bg_widget.add_widget(chat_box)

        # Create the "Your move" box.
        your_move_w = Text(
            (self.screen.get_width() - 140, self.screen.get_height() - 110),
            (120, 40),
            0,
            "Your move",
            self._font,
            fill=(0, 0, 0, 160))
        your_move_w.opacity = 0
        bg_widget.add_widget(your_move_w)
        self._user_move_widget = your_move_w

        # Create the trump widgets.
        trump_pos = (180, 180)
        trump_size = (125, 125)
        for color in ["W", "H", "D", "S", "C"]:
            im_filename = get_color_image_filename(color)
            im = self._rm.get_image(im_filename, trump_size)
            im_w = ImageWidget(trump_pos, trump_size, 0, im)
            im_w.opacity = 0
            bg_widget.add_widget(im_w)
            self._trump_widgets[color] = im_w

        # Create the "choose trump" widgets.
        class ChooseHandler(object):
            def __init__(self, view, trump):
                self._view = view
                self._trump = trump

            def __call__(self, x, y):
                self._view._handle_choose_trump(self._trump)

        choose_size = (90, 90)
        choose_trump_bg = pygame.Surface((400, 170), flags=pygame.SRCALPHA)
        choose_trump_bg.fill((0, 0, 0, 160))
        font_obj = self._font.render("Choose the trump:", True,
                                     (255, 255, 255, 255))
        choose_trump_bg.blit(
            font_obj,
            ((choose_trump_bg.get_width() - font_obj.get_width()) / 2, 20))
        choose_trump_container = ImageWidget(
            (self.screen.get_width() / 2 - 200, 200),
            choose_trump_bg.get_size(),
            99,
            choose_trump_bg,
            visible=False)
        for i, color in enumerate(["D", "S", "H", "C"]):
            im_filename = get_color_image_filename(color)
            im = self._rm.get_image(im_filename, choose_size)
            im_w = ImageWidget((i * (choose_size[0] + 10), 70), choose_size, 0,
                               im)
            choose_trump_container.add_widget(im_w)
            im_w.handle_clicked = ChooseHandler(self, color)
        bg_widget.add_widget(choose_trump_container)
        self._choose_trump_widget = choose_trump_container

        return bg_widget
Beispiel #24
0
    def __init__(self, window):
        self.width = window.get_width()
        self.height = window.get_height()
        self.window = window

        self.running = True
        self.paused = False

        self.move = None
        self.mill = NineMenMorris()

        self.active_window = Window.MENU
        self.piece_being_held = False
        self.held_piece = -1

        # Faz o rescaling das posições da tela. O jogo foi originalmente feito para o tabuleiro ter 600x600.
        # Mas com a adição UI foi modificado para ter 500x500.
        for position in range(0, 24):
            tile_positions[position] = [int(tile_positions[position][0] * 5 / 6 + 50), int(tile_positions[position][1] * 5 / 6 + 50)]

        # Carregando as imagens do jogo.
        self.pieces_sprites = self.load_pieces_sprites()
        grey_panel = pygame.image.load(os.path.join("Assets", "grey_panel.png")).convert_alpha()

        self.background_sprite = pygame.image.load(os.path.join("Assets", 'background.png'))
        self.background_sprite = pygame.transform.scale(self.background_sprite, (self.width, self.height))

        self.board_sprite = pygame.image.load(os.path.join("Assets", "board.png"))
        self.board_sprite = pygame.transform.scale(self.board_sprite, (int(self.width * 5 / 6), int(self.height * 5 / 6)))

        grey_button_sprites = [
            pygame.image.load(os.path.join("Assets", "grey_button.png")).convert_alpha(),
            pygame.image.load(os.path.join("Assets", "grey_button_pushed.png")).convert_alpha()
        ]

        pause_button_sprites = [
            pygame.image.load(os.path.join("Assets", "pausar_idle.png")).convert_alpha(),
            pygame.image.load(os.path.join("Assets", "pausar_apertado.png")).convert_alpha()
        ]
        close_button_sprites = [
            pygame.image.load(os.path.join("Assets", "fechar_idle.png")).convert_alpha(),
            pygame.image.load(os.path.join("Assets", "fechar_apertado.png")).convert_alpha()
        ]
        play_button_sprites = [
            pygame.image.load(os.path.join("Assets", "play_idle.png")).convert_alpha(),
            pygame.image.load(os.path.join("Assets", "play_apertado.png")).convert_alpha()
        ]
        left_arrow_button_sprites = [
            pygame.image.load(os.path.join("Assets", "grey_slider_left.png")).convert_alpha(),
            pygame.image.load(os.path.join("Assets", "grey_slider_left_pushed.png")).convert_alpha()
        ]
        right_arrow_button_sprites = [
            pygame.image.load(os.path.join("Assets", "grey_slider_right.png")).convert_alpha(),
            pygame.image.load(os.path.join("Assets", "grey_slider_right_pushed.png")).convert_alpha()
        ]
        up_arrow_button_sprites = [
            pygame.image.load(os.path.join("Assets", "grey_slider_up.png")).convert_alpha(),
            pygame.image.load(os.path.join("Assets", "grey_slider_up_pushed.png")).convert_alpha()
        ]
        down_arrow_button_sprites = [
            pygame.image.load(os.path.join("Assets", "grey_slider_down.png")).convert_alpha(),
            pygame.image.load(os.path.join("Assets", "grey_slider_down_pushed.png")).convert_alpha()
        ]
        color_toggle_button_sprites = [
            pygame.image.load(os.path.join("Assets", "white_button.png")).convert_alpha(),
            pygame.image.load(os.path.join("Assets", "black_button.png")).convert_alpha()
        ]

        # Cria a fonte do jogo.
        self.font = pygame.freetype.SysFont('Comic Sans MS', 18)

        # Cria os botões
        game_window_buttons = {
            'Pause': PushButton([5, 5], 40, pause_button_sprites),
            'Close': PushButton([600 - 5 - 40, 5], 40, close_button_sprites),
            'Resume': PushButton([5, 5], 40, play_button_sprites),
        }
        main_window_buttons = {
            'Close': PushButton([600 - 5 - 40, 5], 40, close_button_sprites),
            'PlayAI': PushButton([self.width / 2 - 75, self.height / 2 - 80], [150, 40], grey_button_sprites,
                                  hint_text=Text('vs AI', 18, Color.BLACK)),
            'PlayHuman': PushButton([self.width / 2 - 75, self.height / 2], [150, 40], grey_button_sprites, hint_text=Text('vs  Jogador', 18, Color.BLACK))
        }

        config_window_buttons = {
            'Close': PushButton([600 - 5 - 40, 5], 40, close_button_sprites),
            'Color': ToggleButton([self.width / 2 + 65, self.height / 2 - 75], [30, 30], color_toggle_button_sprites),
            'Return': PushButton([40, 33], [39, 31], left_arrow_button_sprites),
            'Increase': PushButton([self.width / 2 + 30, self.height / 2 + 5], [int(31*0.75), int(39*0.75)], up_arrow_button_sprites),
            'Decrease': PushButton([self.width / 2 + 107, self.height / 2 + 5], [int(31*0.75), int(39*0.75)], down_arrow_button_sprites),
            'Play': PushButton([self.width / 2 - 75, self.height / 2 +80], [150, 40], grey_button_sprites, hint_text=Text('JOGAR', 18, Color.BLACK))
        }

        main_window_buttons['Close'].connect_function(self.close_game)
        main_window_buttons['PlayAI'].connect_function(self.change_active_window, Window.CONFIG)
        main_window_buttons['PlayHuman'].connect_function(self.start_match, )

        game_window_buttons['Close'].connect_function(self.close_game)
        game_window_buttons['Pause'].connect_function(self.pause_match)
        game_window_buttons['Resume'].connect_function(self.resume_match)
        game_window_buttons['Resume'].disable()

        config_window_buttons['Close'].connect_function(self.close_game)
        config_window_buttons['Return'].connect_function(self.change_active_window, Window.MENU)
        config_window_buttons['Increase'].connect_function(self.change_ai_depth_level, 1)
        config_window_buttons['Decrease'].connect_function(self.change_ai_depth_level, -1)
        config_window_buttons['Play'].connect_function(self.start_match, True)

        main_window_panels = {
            'Title': Panel([self.width / 2 - 100, 30], [200, 40], grey_panel, Border(0, Color.BLACK), Text('Trilha', 20, Color.BLACK))
        }

        game_window_panels = {
            'Move': Panel([self.width / 2 - 100, 10], [200, 30], grey_panel, Border(0, Color.BLACK), Text('Vez do Branco', 18, Color.BLACK))

        }

        config_window_panels = {
            'Title': Panel([self.width / 2 - 100, 30], [200, 40], grey_panel, Border(0, Color.BLACK), Text('Trilha', 20, Color.BLACK)),
            'Color': Panel([self.width / 2 - 165, self.height / 2 - 80], [175, 40], grey_panel, Border(0, Color.BLACK), Text('Escolha sua cor:', 20, Color.BLACK)),
            'Msg': Panel([self.width / 2 - 165, self.height / 2], [175, 40], grey_panel, Border(0, Color.BLACK), Text('Nível da AI:', 20, Color.BLACK)),
            'AiLevel': Panel([self.width / 2 + 65, self.height / 2 + 5], [30, 30], grey_panel, Border(0, Color.BLACK), Text('1', 20, Color.BLACK))
        }

        self.window_manager = [
            Window(main_window_buttons, main_window_panels),
            Window(game_window_buttons, game_window_panels),
            Window(config_window_buttons, config_window_panels)
        ]

        self.text_stage_2 = ['Preto come uma peça', 'Branco come uma peça']
        self.text_normal = ['Vez do Preto', 'Vez do Branco']
        self.text_game_over = ['Preto Venceu!', 'Branco Venceu!']

        self.ai_depth_level = 1
        self.playing_vs_ai = None
        self.player_color = Player.WHITE
Beispiel #25
0
	TRANSPARENCY = False
	TRANSPARENCY_VALUE = 1

COLOR_01="#282a2e"           # black
COLOR_02="#A54242"           # red
COLOR_03="#8C9440"           # green
COLOR_04="#de935f"           # yellow
COLOR_05="#5F819D"           # blue
COLOR_06="#85678F"           # magenta
COLOR_07="#5E8D87"           # cayn
COLOR_08="#969896"           # white



left = [
	Text(bgColor="#282a2e", fgColor="#969896", text=" User: "******"DOWN", decoreateImg="/home/daniil/mopag-master/widgets/icons/dec.png"),
	UserName(bgColor="#282a2e", fgColor="#969896", decoratePos="DOWN", decoreateImg="/home/daniil/mopag-master/widgets/icons/dec.png"), 
	#ProgressBar()
	#Text(bgColor=COLOR_01, fgColor=COLOR_02, text=" | "),
	#Text(text="2 label")
]
centr = [
	DateTime(fmt="%Y-%m-%d %H:%M:%S", bgColor="#282a2e", fgColor="#969896"), 
	#Text(text="4 label"), 
	#Text(text="3 label")
]
right = [
	Text(bgColor="#282a2e", fgColor="#969896", text="CPU: "),
	CpuUsage(fmt='%s %% ', percpu=True, bgColor="#282a2e", fgColor="#969896", decoratePos="DOWN", decoreateImg="/home/daniil/mopag-master/widgets/icons/dec.png"), 
	Text(bgColor="#282a2e", fgColor="#969896", text="Vol: ", decoratePos="DOWN", decoreateImg="/home/daniil/mopag-master/widgets/icons/dec.png"),
	VolumeBar(bgColor="#282a2e", fgColor="#969896"),