Пример #1
0
def test_gui():
    pygame.init()
    pygame.display.set_caption('Menu 2')
    window_surface = pygame.display.set_mode((320, 240))
    Btn_size = (150, 50)
    UI_e_folder = "UI_elements/"
    UI_elements = {
        "connected": f"{UI_e_folder}Connected_dark.png",
        "disconnected": f"{UI_e_folder}Disconnected_dark.png"
    }
    background = pygame.Surface((320, 240))
    background.fill(pygame.Color(11, 12, 27))
    manager = pygame_gui.UIManager((320, 240))
    is_running = True
    htm_text_block_2 = pygame_gui.elements.UITextBox(
        '<font face=fira_code size=4 color=#ffffff><b>Hey, What the heck!</b>',
        pygame.Rect((0, 0), (200, 150)),
        manager=manager)
    htm_text_block_2.set_active_effect('fade_in')
    clock = pygame.time.Clock()
    while is_running:
        Connected = pygame.image.load(UI_elements[adapter.connection()])
        Connected = pygame.transform.scale(Connected,
                                           (int(320 / 3), int(90 / 3)))
        time_delta = clock.tick(60) / 1000.0
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                is_running = False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    return ()
        manager.update(time_delta)
        window_surface.blit(background, (0, 0))
        window_surface.blit(Connected, (0, 205))
        manager.draw_ui(window_surface)
        pygame.display.update()


#test_gui()
Пример #2
0
def Gui():

    pygame.init()
    pygame.display.set_caption('Options')
    window_surface = pygame.display.set_mode((320, 240))
    Btn_size = (150, 50)
    UI_e_folder = "UI_elements/"
    UI_elements = {
        "connected": f"{UI_e_folder}Connected_dark.png",
        "disconnected": f"{UI_e_folder}Disconnected_dark.png"
    }
    background = pygame.Surface((320, 240))
    background.fill(pygame.Color("#a493bf"))
    manager = pygame_gui.UIManager((320, 240))

    clock = pygame.time.Clock()
    is_running = True

    But1 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((25, 0),
                                                                  Btn_size),
                                        text='Display',
                                        manager=manager)

    But2 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((25, 75),
                                                                  Btn_size),
                                        text='Interfaces',
                                        manager=manager)

    But3 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((25, 150),
                                                                  Btn_size),
                                        text='N/a',
                                        manager=manager)

    Prev_Button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect(
        (220, 190), (50, 50)),
                                               text='<',
                                               manager=manager)

    while is_running:
        Connected = pygame.image.load(UI_elements[adapter.connection()])
        Connected = pygame.transform.scale(Connected,
                                           (int(320 / 3), int(90 / 3)))
        time_delta = clock.tick(60) / 1000.0
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    quit()
            if event.type == pygame.QUIT:
                is_running = False
            manager.process_events(event)
            if event.type == pygame.USEREVENT:
                if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                    if event.ui_element == But1:
                        print("This Is Display ")
                    if event.ui_element == But2:
                        print("This Is Interface")
                        interface()
                    if event.ui_element == But3:
                        print("N/A")
                    if event.ui_element == Prev_Button:
                        return None
        manager.update(time_delta)
        window_surface.blit(background, (0, 0))
        window_surface.blit(Connected, (0, 205))
        manager.draw_ui(window_surface)
        pygame.display.update()
Пример #3
0
def interface():
    interfaces = adapter.Adapters()
    pygame.init()
    pygame.display.set_caption('Inter Faces')
    window_surface = pygame.display.set_mode((320, 240))
    Btn_size = (150, 50)
    UI_e_folder = "UI_elements/"
    UI_elements = {
        "connected": f"{UI_e_folder}Connected_dark.png",
        "disconnected": f"{UI_e_folder}Disconnected_dark.png"
    }
    background = pygame.Surface((320, 240))
    background.fill(pygame.Color("#b593bf"))

    manager = pygame_gui.UIManager((320, 240), "theme.json")
    oof = "   s"
    if len(interfaces) <= 4:
        for i in interfaces:
            locals()[i + "But"] = pygame_gui.elements.UIButton(
                relative_rect=pygame.Rect((300, 50 * interfaces.index(i)),
                                          Btn_size),
                text=i,
                manager=manager)
    elif len(interfaces) <= 8:
        for i in interfaces:
            if interfaces.index(i) <= 3:
                print(i)
                locals()[i + "But"] = pygame_gui.elements.UIButton(
                    relative_rect=pygame.Rect((10, 50 * interfaces.index(i)),
                                              Btn_size),
                    text=i + oof,
                    manager=manager)
            elif interfaces.index(i) > 3 and interfaces.index(i) <= 6:
                locals()[i + "But"] = pygame_gui.elements.UIButton(
                    relative_rect=pygame.Rect(
                        (160, 50 * (interfaces.index(i) - 4)), Btn_size),
                    text=i + oof,
                    manager=manager,
                    object_id=pygame_gui.core.ObjectID(f"color-button-{i}"))
    Prev_Button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect(
        (220, 190), (50, 50)),
                                               text='<',
                                               manager=manager)
    Reset = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((170, 190),
                                                                   (50, 50)),
                                         text="Reset",
                                         manager=manager)
    off_ = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((270, 190),
                                                                  (50, 50)),
                                        text="off",
                                        manager=manager)

    clock = pygame.time.Clock()
    is_running = True
    for i in interfaces:
        locals()[f"{i}But"].colours["normal_text"] = pygame.Color(26, 25, 28)
        locals()[f"{i}But"].rebuild()

    with open(os.getcwd() + "/Interfaces.json", "r+") as Adapters_status_get:
        Adapters_status = json.load(Adapters_status_get)

    for i in interfaces:
        status = Adapters_status[i]
        if status == True:
            locals()[f"{i}But"].colours["normal_bg"] = pygame.Color(
                120, 204, 126)
            locals()[f"{i}But"].rebuild()
            print("green")
            continue
        elif status == False:
            locals()[f"{i}But"].colours["normal_bg"] = pygame.Color(
                224, 99, 99)
            locals()[f"{i}But"].rebuild()
            print("red")

    def colour_update(obj, col):
        obj.colours["normal_bg"] = pygame.Color((col))
        obj.rebuild()
        print()

    while is_running:
        Connected = pygame.image.load(UI_elements[adapter.connection()])
        Connected = pygame.transform.scale(Connected,
                                           (int(320 / 3), int(90 / 3)))
        time_delta = clock.tick(60) / 1000.0
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                is_running = False
            manager.process_events(event)
            if event.type == pygame.USEREVENT:
                if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                    if event.ui_element == Prev_Button:

                        return ()
                    if event.ui_element == Reset:
                        adapter.adapter_reset()
                        for i in interfaces:
                            status_adap = adapter.get_cur_status(i)
                            if status_adap == True:

                                colour_update(locals()[f"{i}But"],
                                              (120, 204, 126))
                            else:

                                colour_update(locals()[f"{i}But"],
                                              (224, 99, 99))
                    if event.ui_element == off_:
                        for i in interfaces:
                            adapter.adapter_stop(i)
                            colour_update(locals()[f"{i}But"], (224, 99, 99))

                    for i in interfaces:
                        if event.ui_element == locals()[i + "But"]:
                            status = adapter.toggle(i)

                            if status == True:
                                locals()[f"{i}But"].colours[
                                    "normal_bg"] = pygame.Color(120, 204, 126)
                                locals()[f"{i}But"].rebuild()
                                print("green")
                                for ii in interfaces:
                                    if ii != i:
                                        adapter.adapter_stop(ii)
                                        locals()[f"{ii}But"].colours[
                                            "normal_bg"] = pygame.Color(
                                                224, 99, 99)
                                        locals()[f"{ii}But"].rebuild()
                                        print("red")
                            elif status == False:
                                locals()[f"{i}But"].colours[
                                    "normal_bg"] = pygame.Color(224, 99, 99)
                                locals()[f"{i}But"].rebuild()
                                print("red")
        manager.update(time_delta)
        window_surface.blit(background, (0, 0))
        window_surface.blit(Connected, (0, 205))

        manager.draw_ui(window_surface)
        pygame.display.update()


#Gui()
Пример #4
0
                                           manager=manager)

#MENU2
#
#
#
#

clock = pygame.time.Clock()
is_running = True

process = psutil.Process(os.getpid())
print(process.memory_info().rss)  # in bytes
while is_running:

    Connected = pygame.image.load(UI_elements[adapter.connection()])
    Connected = pygame.transform.scale(Connected, (int(320 / 3), int(90 / 3)))

    time_delta = clock.tick(60) / 1000.0
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                quit()
        manager.process_events(event)
        if event.type == pygame.USEREVENT:
            if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                if event.ui_element == Speedtest_Button:
                    print("This Is Speedtest")
                    Speedtest_Menu.Gui()
Пример #5
0
def Upload(g):
    os.environ["SDL_FBDEV"] = "/dev/fb1"

    pygame.init()
    pygame.display.set_caption('Menu 2')
    window_surface = pygame.display.set_mode((320, 240))

    UI_e_folder = "UI_elements/"
    UI_elements = {
        "connected": f"{UI_e_folder}Connected_dark.png",
        "disconnected": f"{UI_e_folder}Disconnected_dark.png"
    }
    background = pygame.Surface((320, 240))
    background.fill(pygame.Color(11, 12, 27))
    manager = pygame_gui.UIManager((320, 240))

    speed_text_block_2 = pygame_gui.elements.UITextBox(
        f'<font face=fira_code size=4 color= #ffffff>SpeedTest Is running...<b></b>',
        pygame.Rect((0, 0), (230, 50)),
        manager=manager)
    speed_text_block_2.set_active_effect('fade_in')

    Prev_Button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect(
        (220, 190), (50, 50)),
                                               text='<',
                                               manager=manager)
    restart_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect(
        (120, 190), (100, 50)),
                                                  text="restart",
                                                  manager=manager)

    clock = pygame.time.Clock()
    is_running = True
    test_running = False
    while is_running:

        Connected = pygame.image.load(UI_elements[adapter.connection()])
        Connected = pygame.transform.scale(Connected,
                                           (int(320 / 3), int(90 / 3)))
        time_delta = clock.tick(60) / 1000.0
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    quit()
            if event.type == pygame.QUIT:
                is_running = False
            manager.process_events(event)
            if event.type == pygame.USEREVENT:
                if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                    if event.ui_element == Prev_Button:
                        return None
                    if event.ui_element == restart_button:
                        upload = 0
                        test_running = False
                        speed_text_block_2 = pygame_gui.elements.UITextBox(
                            f'<font face=fira_code size=4 color= #ffffff>SpeedTest Is running...<b></b>',
                            pygame.Rect((0, 0), (230, 50)),
                            manager=manager)
                        speed_text_block_2.set_active_effect('fade_in')

        manager.update(time_delta)

        window_surface.blit(background, (0, 0))
        window_surface.blit(Connected, (0, 205))
        # window_surface.blit(img, (20, 20))

        manager.draw_ui(window_surface)
        pygame.display.update()
        if not test_running and g == True:
            upload = Networking.speedtest_upload()
            test_running = True
        if upload > 0:
            speed_text_block_2 = pygame_gui.elements.UITextBox(
                f'<font face=fira_code size=4 color= #ffffff>Upload: {upload} mbps<b></b>',
                pygame.Rect((0, 0), (230, 50)),
                manager=manager)
            speed_text_block_2.set_active_effect('fade_in')
Пример #6
0
def Gui():

    pygame.init()
    pygame.display.set_caption('Menu 2')
    window_surface = pygame.display.set_mode((320, 240))
    Btn_size = (150, 50)
    UI_e_folder = "UI_elements/"
    UI_elements = {
        "connected": f"{UI_e_folder}Connected_dark.png",
        "disconnected": f"{UI_e_folder}Disconnected_dark.png"
    }
    background = pygame.Surface((320, 240))
    background.fill(pygame.Color(11, 12, 27))
    manager = pygame_gui.UIManager((320, 240))

    clock = pygame.time.Clock()
    is_running = True

    But1 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((5, 0),
                                                                  Btn_size),
                                        text='Download',
                                        manager=manager)

    But2 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((5, 75),
                                                                  Btn_size),
                                        text='Upload',
                                        manager=manager)

    But3 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((5, 150),
                                                                  Btn_size),
                                        text='Ping',
                                        manager=manager)
    But4 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((165, 0),
                                                                  Btn_size),
                                        text='Up & Down',
                                        manager=manager)
    Prev_Button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect(
        (220, 190), (50, 50)),
                                               text='<',
                                               manager=manager)
    Buttons = (But1, But2, But3, But4)
    for i in Buttons:
        i.colours["normal_border"] = pygame.Color(28, 191, 255)
        i.colours["normal_text"] = pygame.Color(28, 191, 255)
        i.rebuild()

    while is_running:
        Connected = pygame.image.load(UI_elements[adapter.connection()])
        Connected = pygame.transform.scale(Connected,
                                           (int(320 / 3), int(90 / 3)))
        time_delta = clock.tick(60) / 1000.0
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    quit()
            if event.type == pygame.QUIT:
                is_running = False
            manager.process_events(event)
            if event.type == pygame.USEREVENT:
                if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                    if event.ui_element == But1:
                        Download(True)
                    if event.ui_element == But2:
                        Upload(True)
                    if event.ui_element == But3:
                        ping(True)
                    if event.ui_element == Prev_Button:
                        return None
        manager.update(time_delta)
        window_surface.blit(background, (0, 0))
        window_surface.blit(Connected, (0, 205))
        manager.draw_ui(window_surface)
        pygame.display.update()