示例#1
0
def show_info(item, title=""):
    """
    Muestra una ventana con la información del item (movie, tvshow, season, episode) en caso de que
    el item sea un list con varios, permite elegir uno y devuelve el index del item seleccionado
    :param item:
    :param title:
    :return:
    """
    from info_window import InfoWindow
    skin = 'Estuary' if xbmc.getSkinDir() == 'skin.estuary' else 'Default'
    return InfoWindow("InfoWindow.xml", sysinfo.runtime_path,
                      skin).start(item, title=title)
示例#2
0
 def show_success(self, success_text):
     success_window = InfoWindow(self.root, "Success Window!", success_text)
示例#3
0
 def get_help(self, *args):
     help_window = InfoWindow(self.root,
                              "Help Window",
                              "help.txt",
                              file=True)
示例#4
0
 def show_error(self, error_text):
     error_window = InfoWindow(self.root, "Error Window!", error_text)
示例#5
0
 def show_program_info(self):
     self.window = InfoWindow()
     self.window.show()
示例#6
0
 def add_method(self):
     self.window = AddReference()
     self.window.show()
示例#7
0
class MainWindow(QMainWindow):
    def __init__(self):
        languages = load(open("../static/languages.json", mode="r", encoding="utf-8"))
        settings_file = load(open("../data/settings.json", mode="r", encoding="utf-8"))

        self.active_language = languages[settings_file["active_language"]]["main_window"]
        self.active_language_for_dialogs = languages[settings_file["active_language"]]["error_windowses"]

        try:
            self.references_list = load(open("../data/references.json", mode="r", encoding="utf-8"))
        except FileNotFoundError:
            self.references_list = load(open("../data/references.json", mode="w", encoding="utf-8"))
        except PermissionError:
            message_box = QMessageBox.question(self, self.active_language_for_dialogs\
                                               ["window_title"], self.active_language_for_dialogs\
                                               ["permission_error"], QMessageBox.Yes)

        print("Program is launched!")
        super().__init__()
        self.initUI()

    def initUI(self):
        uic.loadUi("../ui_templates/main_window.ui", self)
        program_info = load(open("../static/program_info.json"))

        self.setFixedSize(500, 415)
        self.setStyleSheet(window)
        self.setWindowTitle(self.active_language["window_title"].format(program_info["program_name"]))

        self.referencesList.setStyleSheet(widget)
        self.update_references()

        self.initilise_button(self.deleteButton, "delete_button", self.delete_method)
        self.initilise_button(self.addButton, "add_button", self.add_method)
        self.initilise_button(self.openButton, "open_button", self.open_method)
        self.initilise_button(self.showInfoButton, "show_program_info", self.show_program_info)
        self.initilise_button(self.updateButton, "update_button", self.update_references)


    def initilise_button(self, object, key_in_language_file, function):
        object.setStyleSheet(button)
        object.setText(self.active_language[key_in_language_file])
        object.clicked.connect(function)

    def update_references(self):
        self.references_list = load(open("../data/references.json", mode="r", encoding="utf-8"))
        self.referencesList.clear()

        for reference_title in sorted(self.references_list.keys()):
            self.referencesList.addItem(f"{reference_title} ({self.references_list[reference_title]})")

        print("References list is updated.")

    def delete_method(self):
        del self.references_list[sorted(self.references_list.keys())[self.referencesList.currentRow()]]

        open("../data/references.json", "w", encoding="utf-8").\
            write(dumps(self.references_list, sort_keys=True,
                        indent=2, separators=(",", ": ")))

        self.update_references()

    def add_method(self):
        self.window = AddReference()
        self.window.show()



    def open_method(self):
        open_new_tab(self.references_list[sorted(self.references_list.keys())[self.referencesList.currentRow()]])

        print(f"\"{sorted(self.references_list.keys())[self.referencesList.currentRow()]}\" is opened!")

    def show_program_info(self):
        self.window = InfoWindow()
        self.window.show()
示例#8
0
def main():
    window.addToParent()
    window.setBackground('white')
    window.clear()
    window.resetView()
    secondary_window.addToParent()
    secondary_window.setBackground('white')
    secondary_window.clear()
    road_info_window.setBackground('white')
    road_info_window.clear()

    config_data = main_menu.config_data
    map_data = config_data["map_data"]

    S = map_data["coords_south"]
    W = map_data["coords_west"]
    N = map_data["coords_north"]
    E = map_data["coords_east"]
    llc = LatLonConverter(window, S, W, N, E)

    graph = Graph()
    graph.load_open_street_map_data(map_data["filename"], llc)

    road_map = RoadMap(graph, window)
    road_map.draw()
    road_map.draw_road_names()

    gps = GPS(graph, road_map)

    cars = []
    car_shapes = []
    car_factory = CarFactory(window, gps, cars, car_shapes)

    num_cars = config_data["num_cars"]
    for _ in range(num_cars):
        car_factory.create()

    # collision_system = GridCollisionSystem(window, cars)
    collision_system = QuadTreeCollisionSystem(window, cars)

    info = InfoWindow(secondary_window)
    info.set_selected_car(cars[0])
    info.initialize_table()
    car_shapes[info.selected_car.index].shape.setFill("yellow")

    road_info = RoadInfoWindow(road_info_window)

    for car_shape in car_shapes:
        car_shape.draw()

    # initialize simulation variables
    simTime = 0.0
    limit = 10000
    TICKS_PER_SECOND = 30
    TIME_PER_TICK = 1.0 / TICKS_PER_SECOND
    nextLogicTick = TIME_PER_TICK
    lastFrameTime = time.time()
    lag = 0.0

    # Main Simulation Loop
    while simTime < limit:
        currentTime = time.time()
        elapsed = currentTime - lastFrameTime
        lastFrameTime = currentTime
        lag += elapsed
        simTime += elapsed

        # process events
        window.update()
        secondary_window.update()
        road_info_window.update()
        frame.update()
        last_pressed_key = (window.checkKey() or secondary_window.checkKey()
                            or road_info_window.checkKey())
        if last_pressed_key is not None:
            if last_pressed_key == "space":
                pause()
                lastFrameTime = time.time()
            elif last_pressed_key == "p":
                window.zoomIn()
            elif last_pressed_key == "o":
                window.zoomOut()
            elif last_pressed_key == "d":
                print(road_map.get_roads_within_view())

        last_clicked_pt = window.checkMouse()
        if last_clicked_pt is not None:
            car_clicked = False
            map_obj_clicked = False

            for car_shape in car_shapes:
                if car_shape.clicked(last_clicked_pt):
                    car_shapes[info.selected_car.index].shape.setFill("white")
                    info.set_selected_car(cars[car_shape.index])
                    car_shapes[info.selected_car.index].shape.setFill("yellow")
                    car_clicked = True
                    break

            if not car_clicked:
                nearby_object_ids = road_map.get_nearby_object_ids(
                    last_clicked_pt.x, last_clicked_pt.y)
                for map_obj_id in nearby_object_ids:
                    map_obj = road_map.get_obj_by_id(map_obj_id)
                    if map_obj.clicked(last_clicked_pt):
                        relx, rely = window.getRelativeScreenPos(
                            last_clicked_pt.x, last_clicked_pt.y)
                        road_info_window_options = {
                            "place": {
                                "relx": relx,
                                "rely": rely
                            }
                        }
                        road_info_window.addToParent(road_info_window_options)
                        road_info.set_selected_item(map_obj)
                        map_obj_clicked = True
                        break

            if not map_obj_clicked:
                road_info_window.forget()

        last_clicked_pt = secondary_window.checkMouse()
        if last_clicked_pt is not None:
            secondary_window.update()
            for button in info.buttons:
                button.clicked(last_clicked_pt)
                continue

        # update simulation logic
        while lag > TIME_PER_TICK:
            collision_system.process_collisions(cars)
            for car in cars:
                car.move_towards_dest(TIME_PER_TICK)
                car_shape = car_shapes[car.index]
                car_shape.x = cars[car.index].x
                car_shape.y = cars[car.index].y
            collision_system.update_objects(cars)

            nextLogicTick += TIME_PER_TICK
            lag -= TIME_PER_TICK

        # render updates to window
        for car_shape in car_shapes:
            car_shape.render()

        info.update_table()
        if info.follow_car:
            window.centerScreenOnPoint(info.selected_car.x,
                                       info.selected_car.y)
        road_info.update_table()

        road_map.draw_route(info.selected_car, info.show_route)

        _root.update_idletasks()

    cleanup()
示例#9
0
def main():
    with open('ClientSettings.txt') as f:
        data = ast.literal_eval(f.read())

    colors = data['Colors']

    figure_colors = [Color([color]) for color in colors['FigureColors']]
    background = Color([colors['FontColors'][0], colors['FontColors'][1]])
    border = Color([colors['BorderColors'][0], colors['BorderColors'][1]])

    cell_size = 43

    x, y = data['Resolution']
    left, top = 10, 10

    size = 2 * left + x * (cell_size + 1) + 1, 2 * top + y * (cell_size + 1) + 1

    figure_x, figure_y = 4, 4
    figure_left, figure_top = size[0], top

    size = size[0] + left + figure_x * (cell_size + 1) + 1, size[1]

    buttons_x, buttons_y = 4, 1
    buttons_left, buttons_top = figure_left, figure_top + top + figure_y * (cell_size + 1)

    pygame.init()
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption('TETRIS')

    main_board = MainBoard(x, y, screen, left, top, cell_size, background, border)
    figure_board = FigureBoard(figure_x, figure_y, screen, figure_left, figure_top, cell_size,
                               background, border, figure_colors)
    buttons_board = ButtonsBoard(buttons_x, buttons_y, screen, buttons_left, buttons_top, cell_size, background, border)

    points_x, points_y = figure_x * (cell_size + 1) + 1, 55
    points_left, points_top = figure_left, figure_top + top + figure_y * (cell_size + 1) + top + buttons_y * (
                cell_size + 1)

    timer_x, timer_y = points_x, 55
    timer_left, timer_top = figure_left, figure_top + top + figure_y * (cell_size + 1) + top + buttons_y * (
            cell_size + 1) + points_y + top

    status_x, status_y = points_x, 55
    status_left, status_top = figure_left, figure_top + top + figure_y * (cell_size + 1) + top + buttons_y * (
            cell_size + 1) + points_y + top + timer_y + top

    points_info = InfoWindow(points_x, points_y, screen, points_left, points_top, border, border, border, 'points:')
    timer = InfoWindow(timer_x, timer_y, screen, timer_left, timer_top, border, border, border, 'timer:')
    status_bar = InfoWindow(status_x, status_y, screen, status_left, status_top, border, border, border, 'status:')

    running = True
    buttons_board.game_running = False

    clock = pygame.time.Clock()
    delta_t = 0
    lock = data['Speed']
    timer_t = 0

    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                cell = buttons_board.get_cell(event.pos)
                if cell is None:
                    pass
                else:
                    cell = cell[0]
                    if cell == 0:
                        if not buttons_board.game_running:
                            buttons_board.game_running = True
                        restart(main_board, figure_board)
                        timer_t = 0
                    elif cell == 1:
                        if buttons_board.game_running:
                            buttons_board.game_running = False
                    elif cell == 2:
                        ex = SettingsWindow()
                        ex.show()
                    elif cell == 3:
                        background.switch_color()
                        border.switch_color()
            if event.type == pygame.KEYDOWN and main_board.figure and buttons_board.game_running:
                if event.key == pygame.K_LEFT and main_board.can_move(x=-1):
                    main_board.x -= 1
                if event.key == pygame.K_RIGHT and main_board.can_move(x=1):
                    main_board.x += 1
                if event.key == pygame.K_UP:
                    figure = transpose(main_board.figure)
                    if main_board.can_move(figure=figure):
                        main_board.figure = figure
                if event.key == pygame.K_DOWN:
                    if main_board.can_move(y=1):
                        main_board.y += 1
                main_board.update()

        t = clock.tick()
        if buttons_board.game_running:
            delta_t += t
            timer_t += t
            if delta_t > lock:
                delta_t = 0
                if main_board.figure and main_board.can_move(y=1):
                    main_board.y += 1
                    main_board.update()
                else:
                    next_figure(main_board, figure_board)
                    if main_board.can_move():
                        main_board.update()
                    else:
                        buttons_board.game_running = False

        screen.fill(background.color)
        main_board.render()
        figure_board.render()
        buttons_board.render()

        points_info.draw(str(main_board.points))
        timer.draw(str(timer_t // 1000))
        status_bar.draw({True: 'on', False: 'off'}[buttons_board.game_running])
        pygame.display.flip()
    pygame.quit()