Ejemplo n.º 1
0
    def __init__(self, position, size=Vec2(100, 100), font=Font(color=Color.from_name("BLACK")), accepted=None, image=None):
        """
            Create TextEdit Wiget

            Parameters
            ----------
            position: Vec2
                Position of TextEdit
            size: Vec2
                Size of TextEdit
            font: Font
                Font of Label of TextEdit
            accepted: str
                String of accepted characters
            image: str or None
                Path of Background image of TextEdit or None
        """
        super().__init__(position)

        self.size = size
        self.image = image
        self.label = Label(Vec2.zero(), "", font)
        self.text = ""
        self.focus = False
        self.accepted = accepted

        self.render = None
        self.update_render()
Ejemplo n.º 2
0
    def __init__(self,
                 position,
                 width=100,
                 font=Font(color=Color.from_name("BLACK")),
                 accepted=None,
                 image=None):
        """
            Create Entry Wiget

            Parameters
            ----------
            position: Vec2
                Position of Entry
            width: int
                Width of Entry
            font: Font
                Font of Label of Entry
            accepted: sstr
                String of accepted characters
            image: str or None
                Background image of Entry (or None)
        """
        super().__init__(position)

        self.width = width
        self.image = image
        self.label = Label(Vec2.zero(), "", font)
        self.text = ""
        self.focus = False
        self.accepted = accepted

        self.render = None
        self.update_render()
Ejemplo n.º 3
0
    def __init__(self,
                 position,
                 text="",
                 command=None,
                 font=Font(),
                 size=Vec2(100, 40),
                 background=Color.from_name("GRAY").darker(5)):
        """
            Create Button Widget

            Parameters
            ----------
            position: Vec2
                Position of Button
            text: str
                Text of Button
            command: Function or None
                Click callback of Button
            font: Font
                Font of Button
            size: Vec2
                Size of Button
            background: Color or str
                Background of Button. May be a Color or a path to a image
        """
        super().__init__(position)
        self.text = text
        self.command = command
        self.font = font
        self.background = background
        self.size = size
        self.is_hover = False
        self.update_render()
Ejemplo n.º 4
0
    def __init__(self,
                 position,
                 size=Vec2(150, 10),
                 color=Color.from_name("GREEN"),
                 value=0):
        """
            Create ProgressBar Widget

            Parameters
            ----------
            position: Vec2
                Position of ProgressBar
            size: Vec2
                Size of ProgressBar
            color: Color
                Color of ProgressBar
            value: int
                Current value of ProgressBar. Between 1 and 100.
        """
        super().__init__(position)
        self.size = size
        self.color = color
        self.value = value
        self.render = None
        self.update_render()
Ejemplo n.º 5
0
    def __init__(self, position, size=Vec2(200, 150), color=None):
        """
            Create Frame Widget

            Parameters
            ----------
            position: Vec2
                Position of Frame
            size: Vec2
                Size of Frame
            color: Color or None
                Background Color of Frame (or None)
        """
        super().__init__(position)
        self.size = size
        self.color = color
        self.childrens = []
        self.render = None
        self.update_render()
Ejemplo n.º 6
0
    def __init__(self, position, size=Vec2.zero(), color=Color.from_name("BLACK"), width=0):
        """
            Create Ellipse Widget

            Parameters
            ----------
            position: Vec2
                Position of Ellipse
            size: Vec2
                Size of Ellipse
            color: Color
                Color of Ellipse
            width: int
                Width of Ellipse (0 fill Ellipse)
        """
        super().__init__(position)
        self.size = size
        self.color = color
        self.width = width
Ejemplo n.º 7
0
    def __init__(self,
                 size=Vec2(900, 700),
                 color=Color.from_name("BLACK"),
                 title="PGGUI",
                 fps=60,
                 centered=True,
                 debug=False):
        """
            Create Window

            Parameters
            ----------
            size: int
                Size of Window
            color: Color
                Color of background of Window
            title: str
                Title of Window
            fps: int or None
                Max FPS of Window (None if you don't want limit)
            centered: bool
                True if you want centered window, else False
            debug: bool
                True if you want some debug infos, else False
        """

        self.fps = fps
        self.debug = debug
        self.color = color
        self.size = size

        if centered:
            os.environ['SDL_VIDEO_CENTERED'] = '1'

        pygame.display.set_caption(title)
        self.screen = pygame.display.set_mode(size.coords())

        self.clock = pygame.time.Clock()
        self.is_running = False
        self.debug_font = Font(bold=True, color=Color.from_name("ORANGE"))
        self.keys_callback = {}

        self.widgets = []
Ejemplo n.º 8
0
    def update_render(self):
        """
            Update Render of Entry

            .. warning:: You must use this method after any change in Entry
        """
        if self.label.text != self.text:
            self.label.text = self.text
            text_size = self.label.font.rendered_size(self.text)
            self.label.position = Vec2(
                clamp(self.width - text_size.x - 10, maxi=0),
                self.render.get_rect().height / 2 - text_size.y / 2)
            self.label.update_render()

        if self.image:
            self.render = pygame.image.load(self.image).convert()
            self.render = pygame.transform.scale(self.render, (self.width, 35))
        else:
            self.render = pygame.Surface((self.width, 35), pygame.SRCALPHA,
                                         32).convert_alpha()
            self.render.fill((50, 50, 50))
            white = pygame.Surface((self.width - 8, 27))
            white.fill((255, 255, 255))
            self.render.blit(white, (4, 4))
Ejemplo n.º 9
0
from pggui import Window
from pggui.widgets import Selector
from pggui.utils import Vec2, Color, Font


window = Window(Vec2(150, 140), debug=True)
window.add_widget(Selector(Vec2(10, 10), "Ceci est", "un test"))
window.add_widget(Selector(Vec2(10, 50), "Ceci est", "un test", font=Font(size=20)))
window.add_widget(Selector(Vec2(10, 100), "Ceci est", "un test", color=Color.from_name("RED")))
window.run()
Ejemplo n.º 10
0
from pggui import Window
from pggui.widgets import Polygon
from pggui.utils import Vec2, Color

window = Window(Vec2(200, 200), debug=True)
window.add_widget(Polygon((Vec2(30, 30), Vec2(30, 40), Vec2(40, 30))))
window.add_widget(
    Polygon((Vec2(40, 60), Vec2(60, 60), Vec2(60, 40)),
            Color.from_name("RED")))
window.add_widget(
    Polygon((Vec2(100, 60), Vec2(100, 100), Vec2(60, 100), Vec2(120, 154)),
            Color.from_name("RED"), 5))
window.run()
Ejemplo n.º 11
0
from pggui import Window
from pggui.widgets import Entry
from pggui.utils import Vec2, Color, Font

import os

window = Window(Vec2(170, 260), debug=True)
file = os.path.join(os.path.dirname(__file__), "image.png")
window.add_widget(Entry(Vec2(10, 10)))
window.add_widget(Entry(Vec2(10, 60), 150))
window.add_widget(Entry(Vec2(10, 110),
                        font=Font(color=Color.from_name("RED"))))
window.add_widget(Entry(Vec2(10, 160), accepted="abc"))
window.add_widget(Entry(Vec2(10, 210), image=file))
window.run()
Ejemplo n.º 12
0
from pggui import Window
from pggui.widgets import ProgressBar
from pggui.utils import Vec2, Color, Font

from random import randint

window = Window(Vec2(220, 100), debug=True)
window.add_widget(ProgressBar(Vec2(10, 10)))
window.add_widget(ProgressBar(Vec2(10, 30), value=randint(10, 90)))
window.add_widget(
    ProgressBar(Vec2(10, 50), Vec2(200, 20), value=randint(10, 90)))
window.add_widget(
    ProgressBar(Vec2(10, 80),
                color=Color.from_name("RED"),
                value=randint(10, 90)))
window.run()
Ejemplo n.º 13
0
from pggui import Window
from pggui.widgets import Circle
from pggui.utils import Vec2, Color

window = Window(Vec2(200, 200), debug=True)
window.add_widget(Circle(Vec2(30, 30)))
window.add_widget(Circle(Vec2(80, 40), 30, Color.from_name("RED")))
window.add_widget(Circle(Vec2(30, 80), 20, Color.from_name("RED"), 3))
window.run()
Ejemplo n.º 14
0
from pggui import Window
from pggui.widgets import TextEdit
from pggui.utils import Vec2, Color, Font

import os

window = Window(Vec2(170, 510), debug=True)
file = os.path.join(os.path.dirname(__file__), "image.png")
window.add_widget(TextEdit(Vec2(10, 10)))
window.add_widget(TextEdit(Vec2(10, 120), Vec2(150, 50)))
window.add_widget(
    TextEdit(Vec2(10, 180), font=Font(color=Color.from_name("RED"))))
window.add_widget(TextEdit(Vec2(10, 290), accepted="abc"))
window.add_widget(TextEdit(Vec2(10, 400), image=file))
window.run()
Ejemplo n.º 15
0
from pggui import Window
from pggui.widgets import Image
from pggui.utils import Vec2, Color

import os

window = Window(Vec2(400, 400), debug=True)
file = os.path.join(os.path.dirname(__file__), "image.png")
window.add_widget(Image(Vec2(10, 10), file))
window.add_widget(Image(Vec2(250, 10), file, Vec2(100, 100), 127))
window.add_widget(Image(Vec2(10, 250), file, Vec2(100, 100), flipy=True))
window.add_widget(
    Image(Vec2(250, 250), file, Vec2(100, 100), flipx=True, flipy=True))
window.run()
Ejemplo n.º 16
0
from pggui import Window
from pggui.utils import Color, Vec2


window = Window(Vec2(550, 300), Color.from_name("WHITE"), "TESTING PGGUI", 50, debug = True)
window.run()
Ejemplo n.º 17
0
from pggui import Window
from pggui.widgets import Frame, Label
from pggui.utils import Vec2, Color

window = Window(Vec2(310, 410), debug=True)
frame1 = Frame(Vec2(10, 10))
frame1.add_widget(Label(Vec2(10, 10), "Ceci est un test"))
frame2 = Frame(Vec2(10, 200), Vec2(100, 200))
frame2.add_widget(Label(Vec2(10, 10), "Ceci est un test"))
frame3 = Frame(Vec2(200, 200), Vec2(100, 200), Color.from_name("RED"))
frame3.add_widget(Label(Vec2(10, 10), "Ceci est un test"))
window.add_widget(frame1)
window.add_widget(frame2)
window.add_widget(frame3)
window.run()
Ejemplo n.º 18
0
from pggui import Window
from pggui.widgets import Button
from pggui.utils import Vec2, Color, Font

import os


def click():
    print("clicked")


window = Window(Vec2(230, 110), debug=True)
file = os.path.join(os.path.dirname(__file__), "image.png")
window.add_widget(Button(Vec2(10, 10), "Click 1", click))
window.add_widget(Button(Vec2(120, 10), "Click 2", click, Font(size=20)))
window.add_widget(
    Button(Vec2(10, 60), "Click 3", click, background=Color.from_name("RED")))
window.add_widget(Button(Vec2(120, 60), "Click 4", click, background=file))
window.run()
Ejemplo n.º 19
0
from pggui import Window
from pggui.widgets import Rect
from pggui.utils import Vec2, Color

window = Window(Vec2(200, 200), debug=True)
window.add_widget(Rect(Vec2(10, 10), Vec2(120, 180), Color.from_name("WHITE")))
window.add_widget(Rect(Vec2(10, 10), Vec2(20, 124), Color.from_name("ORANGE")))
window.add_widget(Rect(Vec2(100, 32), Vec2(50, 100), Color.from_name("RED")))
window.add_widget(Rect(Vec2(20, 10), Vec2(50, 100), Color.from_name("RED"), 5))
window.run()
Ejemplo n.º 20
0
from pggui import Window
from pggui.widgets import Checkbox
from pggui.utils import Vec2, Color, Font

window = Window(Vec2(60, 150), debug=True)
window.add_widget(Checkbox(Vec2(10, 10), "Check 1"))
window.add_widget(Checkbox(Vec2(10, 40), "Check 2", font=Font(size=20)))
window.add_widget(Checkbox(Vec2(10, 70), "Check 3", checked=True))
window.add_widget(Checkbox(Vec2(10, 100), "Check 4", scale=2))
window.run()
Ejemplo n.º 21
0
from pggui import Window
from pggui.widgets import Line
from pggui.utils import Vec2, Color

window = Window(Vec2(200, 200), debug=True)
window.add_widget(
    Line(Vec2(10, 10), Vec2(120, 180), color=Color.from_name("WHITE")))
window.add_widget(
    Line(Vec2(10, 10), Vec2(2, 124), color=Color.from_name("ORANGE")))
window.add_widget(
    Line(Vec2(150, 32), Vec2(15, 184), 10, Color.from_name("RED")))
window.run()
Ejemplo n.º 22
0
from pggui import Window
from pggui.widgets import Label
from pggui.utils import Vec2, Color, Font

window = Window(Vec2(400, 400), debug=True)
window.add_widget(Label(Vec2(20, 30), "On y crois tous."))
window.add_widget(Label(Vec2(20, 50), "On y crois tous.", Font(size=20)))
window.add_widget(
    Label(Vec2(20, 80), "On y crois tous.", Font(size=20),
          Color.from_name("RED")))
window.add_widget(
    Label(Vec2(20, 110), "On y crois tous.\nOU PAS !", Font(size=20),
          Color.from_name("RED"), 0))
window.add_widget(
    Label(Vec2(20, 200), "On y crois pas tous.\nOU PAS PAS !", Font(size=20),
          Color.from_name("RED"), 10))
window.run()