Esempio n. 1
0
 def test_if_open():
     # Abrimos la ventana y comprobamos si se ha abierto el error del perfil
     Window().while_active_not_name(test_win,
                                    'Se ha producido un error del perfil')
     ventana = Window().while_active_not_name(
         test_win, 'Se ha producido un error del perfil')
     if ventana == 'Se ha producido un error del perfil':
         Window().close_active()
Esempio n. 2
0
File: app.py Progetto: thp/pyweek15
class App(object):
    def __init__(self, title, width, height, entry):
        self.window = Window(width, height, title)

        self.running = True
        self.accumulator = TimeAccumulator(30)
        self.renderer = Renderer(self)
        self.screen = Screen(self, width, height)
        self.resman = ResourceManager(self)
        self.player = Player(self)
        self.renderer.resize(width, height)

        self._scenes = {'Game': Game(self)}
        for name, filedata in self.resman.intermissions.items():
            self._scenes[name] = Intermission(self, name, filedata)
        self._scenes['Game'].reset(hard=True)
        self.go_to_scene(entry)

    def go_to_scene(self, name):
        if name == "GoodBye":
            self.running = False
        else:
            self.scene_transition = 0.
            self.scene = self._scenes[name]
            self.scene.resume()

    def run(self):
        while self.running:
            self.scene_transition += .05
            if self.scene_transition >= .95:
                self.scene_transition = 1.0
                event, args = self.window.next_event()
                if event == 0:
                    ...  # No event
                elif event == 1:
                    self.running = False
                elif event == 2:
                    self.screen.touch = False
                    pressed, key = args
                    if pressed and key == 'esc':
                        self.running = False
                    else:
                        self.scene.process_input(pressed, key)
                elif event == 3:
                    event, x, y, finger = args
                    self.scene.process_touch(event, x, y, finger)
                self.accumulator.update(self.scene.process)

            self.renderer.begin()
            self.renderer.global_tint = (self.scene_transition, ) * 3
            self.scene.draw()
            self.renderer.finish()
            self.window.swap_buffers()
            yield
Esempio n. 3
0
def abrir_chromium(exp=30,
                   url='https://www.google.es',
                   test_img='google/google',
                   test_win='Google - Chromium'):
    ''' Abrimos Chromium con un testeo de ventana y otro por imagen '''
    from shlex import split
    import threading as t
    from core import Window, Screen
    from medium_level import Chromium
    from timeout import timeout
    from xdo import xdo
    from time import sleep

    #xdo.xdo.XdoException: Function xdo_get_active_window returned error code 1

    def op():
        # Este será el demonio, se terminará cuando nos hayamos
        # asegurado de que chromium está abierto con la otra función
        Chromium().start(url=url)

    @timeout(exp)
    def test_if_open():
        # Abrimos la ventana y comprobamos si se ha abierto el error del perfil
        Window().while_active_not_name(test_win,
                                       'Se ha producido un error del perfil')
        ventana = Window().while_active_not_name(
            test_win, 'Se ha producido un error del perfil')
        if ventana == 'Se ha producido un error del perfil':
            Window().close_active()

    op = t.Thread(target=op, daemon=True, name='Abrir Chromium')
    test = t.Thread(target=test_if_open, name='Test Abrir Chromium')
    try:
        op.start()
        test.start()
        ''' Comprobamos si están abiertos los hilos '''
        alive = True
        while alive == True:
            alive = test.is_alive()
        Window().maximize()
    except timeout.TimeoutError:
        print(
            'El tiempo de abertura de Chromium ha sido superior a %s segundos'
            % exp)
    except xdo.XdoException:
        print(
            'Excepción en la biblioteca Xdo: Function xdo_get_active_window returned error code 1'
        )
        Window().maximize()
    if test_img:
        Screen().while_not_found(test_img)
Esempio n. 4
0
 def start_run(self, command):
     ''' Abrir la consola run y ejecutar un programa pasado como arg'''
     from core import Window, Keyboard
     self.open_run()
     Window().while_active_not_name('Ejecutar')
     self.paste_save(command)
     Keyboard().enter()
Esempio n. 5
0
File: app.py Progetto: thp/pyweek15
    def __init__(self, title, width, height, entry):
        self.window = Window(width, height, title)

        self.running = True
        self.accumulator = TimeAccumulator(30)
        self.renderer = Renderer(self)
        self.screen = Screen(self, width, height)
        self.resman = ResourceManager(self)
        self.player = Player(self)
        self.renderer.resize(width, height)

        self._scenes = {'Game': Game(self)}
        for name, filedata in self.resman.intermissions.items():
            self._scenes[name] = Intermission(self, name, filedata)
        self._scenes['Game'].reset(hard=True)
        self.go_to_scene(entry)
Esempio n. 6
0
 def test(self, img, win):
     ''' Asegurarnos de que hemos entrado a un contexto
     comprobando mediante una imagen en pantalla y el nombre
     de la ventana activa. Toma dos cadenas con el nombre
     de la ventana y de la imagen que esperamos.
     Devuelve True si el testeo es correcto y False si no'''
     from core import Window, Screen
     im_name = Screen().where(img)
     win_name = Window().active_name()
     if img == im_name and win == win_name:
         return True
     else:
         return False
Esempio n. 7
0
 def window(self):
     """Return window, which is the source of the event."""
     return Window(self.window_id)
Esempio n. 8
0
 def atom_name(self):
     """Return event's atom name."""
     return Window.atom_name(self.atom)
Esempio n. 9
0
 def __init__(self, *args, **kwds):
     Window.__init__(self, *args, **kwds)
Esempio n. 10
0
 def atom_name(self):
     """Return event's atom name."""
     return Window.atom_name(self.atom)
Esempio n. 11
0
import time

from core import Window, Keyboard, Board, ScoreBoard

window = Window(1200, 800, 'Welcome to Reversi AI',
                'resources/images/background_100x100.png')
keyboard = Keyboard()
board      = Board(window, 2, [0], ['Black', 'White'], 8, 8, 1, ('resources/images/black_82x82.png',         \
                  'resources/images/white_82x82.png', 'resources/images/board_82x82_b1.png'),                \
                  'resources/images/cursor_82x82.png')
scoreboard = ScoreBoard(window, 2, board, ('resources/images/black_82x82.png',                               \
                        'resources/images/white_82x82.png', 'resources/images/background_100x100.png'))


def main():
    while True:
        if not keyboard.monitor(onkeydown_callback=board.update):
            window.quit()
            exit(0)

        if board.is_locked():
            time.sleep(2)
            board.reset_lock()
        if board.is_ending():
            break

        board.action(callbacks=(scoreboard.update, ))
        if not window.done_background:
            window.draw_background()
            board.draw_self()
            scoreboard.draw_self()
Esempio n. 12
0
        self.vertical_velocity += self.accel
        self.vertical_velocity = max(self.vertical_velocity, MAX_VERTICAL_VEL)
        self.vertical_velocity = min(self.vertical_velocity, MIN_VERTICAL_VEL)
        self.rect.y += self.vertical_velocity

        if self.rect.y < 0 or self.rect.y >= win_height - self.rect.h:
            self.kill()
        self.accel = GRAVITY


# !SECTION

# SECTION Main functionality

win = Window(1280, 720, "Flappy Bird - PyJawan")
win_rect = Rect(0, 0, 1280, 720)

heights = [random_height(win.height) for i in range(win_rect.w // PIPE_SEP)]
pipes = [
    Pipe(win_rect.w - i * PIPE_SEP + 100, h[0], h[1], SPEED, win.height)
    for i, h in enumerate(heights)
]

bird = Bird(
    100,
    360,
    "./assets/bird_up.png",
    "./assets/bird_down.png",
)
Esempio n. 13
0
import sys
from PyQt5.QtWidgets import QApplication

from core import Window


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())