You've already forked pygconsole
very first commit
This commit is contained in:
7
tests/resources/LICENCES.txt
Normal file
7
tests/resources/LICENCES.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
Background image
|
||||
----------------
|
||||
Licence: Free
|
||||
https://www.pexels.com/fr-fr/photo/paysage-nature-ciel-sable-8092914/
|
||||
Location: Oljato-Monument Valley, United States
|
||||
Date: 13th May 2014
|
||||
Photographer: Karl MPhotography
|
BIN
tests/resources/background.jpg
Normal file
BIN
tests/resources/background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 469 KiB |
140
tests/test0.py
Normal file
140
tests/test0.py
Normal file
@@ -0,0 +1,140 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 0 : import pygconsole module and display a blank console (with default parameters)
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 0: display a blank console with default parameters.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
142
tests/test1.py
Normal file
142
tests/test1.py
Normal file
@@ -0,0 +1,142 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 1 : import pygconsole module and display a console with `Hello world !` written (with default parameters)
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 1: display a console with default parameters.",
|
||||
"press 'A' to write `Hello world !` at the cursor position.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a: console.add_char("Hello world !")
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
161
tests/test10.py
Normal file
161
tests/test10.py
Normal file
@@ -0,0 +1,161 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 10 : Write a long text on the console with normal characters colorized randomly (foreground / background).
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import random
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 10 : Write a long text on the console with normal characters colorized randomly",
|
||||
"(foreground / background).",
|
||||
"Press 'A' to write the 'Lorem ipsum' text",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae nunc dictum, sagittis elit venenatis, efficitur justo. Etiam suscipit, ipsum accumsan aliquam elementum, massa tellus pellentesque lacus, ut porttitor ligula tortor at urna. Duis eu felis non tortor bibendum ultrices. Aliquam tortor velit, suscipit faucibus nunc quis, blandit posuere leo. Donec dignissim aliquam lectus, vitae lacinia risus feugiat non. Curabitur dapibus, massa quis eleifend lobortis, nulla sem ullamcorper turpis, vel sodales risus orci non velit. Nam ac neque faucibus, consequat eros eu, viverra neque. Nulla vel blandit lorem. Nam interdum nisl non sem pretium dictum. Phasellus id sapien vitae ipsum efficitur fringilla. Quisque suscipit consequat erat quis commodo. Aenean tristique felis libero, et ultrices justo porttitor eget. Vivamus sit amet urna nibh. Ut ultrices nulla et dui eleifend, ut sagittis ipsum condimentum. Mauris nec dolor eget augue gravida lacinia. "
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# random initialization
|
||||
random.seed()
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a:
|
||||
for word in LONG_TEXT.split():
|
||||
console.background_colour = random.choice(list(console.STANDARD_COLOURS.keys()))
|
||||
console.foreground_colour = random.choice(list(console.STANDARD_COLOURS.keys()))
|
||||
if console.background_colour == console.foreground_colour:
|
||||
if console.background_colour in ('black','red','green','yellow','blue','magenta','cyan','white'):
|
||||
console.foreground_colour = 'bright_white'
|
||||
else:
|
||||
console.foreground_colour = 'black'
|
||||
console.add_char(word)
|
||||
console.background_colour = 'black'
|
||||
console.foreground_colour = 'bright_white'
|
||||
console.add_char(' ')
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
147
tests/test100.py
Normal file
147
tests/test100.py
Normal file
@@ -0,0 +1,147 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'io' test set : tests regarding the pygconsole.io submodule
|
||||
Test 100 : Print characters typed on the keyboard, on a console initialized with the default parameters.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 100: Print characters typed on the keyboard,",
|
||||
"on a console initialized with the default parameters.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(name="pygame_console",logger = log)
|
||||
iotextstream = pygconsole.io.TextIOConsoleWrapper(console_name="pygame_console", newline='\r\n', line_buffering=True)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE:
|
||||
sys.exit()
|
||||
elif event.key == K_RETURN:
|
||||
print("", file=iotextstream, flush=True) # New line
|
||||
if event.type == TEXTINPUT: # When typing a key with a writable character...
|
||||
print(event.text, end='', file=iotextstream, flush=True) # Display the character
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
147
tests/test101.py
Normal file
147
tests/test101.py
Normal file
@@ -0,0 +1,147 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'io' test set : tests regarding the pygconsole.io submodule
|
||||
Test 101 : Display a message in red coloured characters.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 101: Display a message in red coloured characters.",
|
||||
"press 'A' to write `Hello world !` at the cursor position.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(name="pygame_console",logger = log)
|
||||
iotextstream = pygconsole.io.TextIOConsoleWrapper(console_name="pygame_console", newline='\r\n', line_buffering=True)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE:
|
||||
sys.exit()
|
||||
elif event.key == K_RETURN:
|
||||
print("", file=iotextstream, flush=True) # New line
|
||||
elif event.key == K_a:
|
||||
print("\x1b[31mHello world !", file=iotextstream, flush=True) # Print 'Hello World !' in red
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
155
tests/test102.py
Normal file
155
tests/test102.py
Normal file
@@ -0,0 +1,155 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'io' test set : tests regarding the pygconsole.io submodule
|
||||
Test 102 : Display a message in all supported colours.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 102: Display a message in coloured characters.",
|
||||
"press 'A' to write `Hello world !` at the cursor position,",
|
||||
"with a colour changing cyclicly.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
COLOUR_LIST = ['\x1b[30m','\x1b[31m','\x1b[32m','\x1b[33m','\x1b[34m','\x1b[35m','\x1b[36m','\x1b[37m',
|
||||
'\x1b[90m','\x1b[91m','\x1b[92m','\x1b[93m','\x1b[94m','\x1b[95m','\x1b[96m','\x1b[97m']
|
||||
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(name="pygame_console",logger = log)
|
||||
iotextstream = pygconsole.io.TextIOConsoleWrapper(console_name="pygame_console", newline='\r\n', line_buffering=True)
|
||||
coloured_index = 0
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE:
|
||||
sys.exit()
|
||||
elif event.key == K_RETURN:
|
||||
print("", file=iotextstream, flush=True) # New line
|
||||
elif event.key == K_a:
|
||||
print(COLOUR_LIST[coloured_index] + "Hello world !", file=iotextstream, flush=True) # Print 'Hello World !' in colour
|
||||
coloured_index += 1
|
||||
if coloured_index >= len(COLOUR_LIST): coloured_index = 0
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
155
tests/test103.py
Normal file
155
tests/test103.py
Normal file
@@ -0,0 +1,155 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'io' test set : tests regarding the pygconsole.io submodule
|
||||
Test 103 : Display a message with a background in all supported colours.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 103: Display a message in coloured background.",
|
||||
"press 'A' to write `Hello world !` at the cursor position,",
|
||||
"with a colour background changing cyclicly.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
COLOUR_LIST = ['\x1b[40m','\x1b[41m','\x1b[42m','\x1b[43m','\x1b[44m','\x1b[45m','\x1b[46m','\x1b[47m',
|
||||
'\x1b[100m','\x1b[101m','\x1b[102m','\x1b[103m','\x1b[104m','\x1b[105m','\x1b[106m','\x1b[107m']
|
||||
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(name="pygame_console",logger = log)
|
||||
iotextstream = pygconsole.io.TextIOConsoleWrapper(console_name="pygame_console", newline='\r\n', line_buffering=True)
|
||||
coloured_index = 0
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE:
|
||||
sys.exit()
|
||||
elif event.key == K_RETURN:
|
||||
print("", file=iotextstream, flush=True) # New line
|
||||
elif event.key == K_a:
|
||||
print(COLOUR_LIST[coloured_index] + "Hello world !", file=iotextstream, flush=True) # Print 'Hello World !' in colour
|
||||
coloured_index += 1
|
||||
if coloured_index >= len(COLOUR_LIST): coloured_index = 0
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
163
tests/test10_bis.py
Normal file
163
tests/test10_bis.py
Normal file
@@ -0,0 +1,163 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 10_bis : Write a long text on the console with normal characters colorized randomly (foreground / background).
|
||||
ESCAPE Key to exit.
|
||||
** USE the pygconsole package installed with `pip` **
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import random
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
# if __name__ == '__main__':
|
||||
# sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
# import pygconsole
|
||||
# else:
|
||||
# from .. import pygconsole
|
||||
import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 10 : Write a long text on the console with normal characters colorized randomly",
|
||||
"(foreground / background).",
|
||||
"Press 'A' to write the 'Lorem ipsum' text",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae nunc dictum, sagittis elit venenatis, efficitur justo. Etiam suscipit, ipsum accumsan aliquam elementum, massa tellus pellentesque lacus, ut porttitor ligula tortor at urna. Duis eu felis non tortor bibendum ultrices. Aliquam tortor velit, suscipit faucibus nunc quis, blandit posuere leo. Donec dignissim aliquam lectus, vitae lacinia risus feugiat non. Curabitur dapibus, massa quis eleifend lobortis, nulla sem ullamcorper turpis, vel sodales risus orci non velit. Nam ac neque faucibus, consequat eros eu, viverra neque. Nulla vel blandit lorem. Nam interdum nisl non sem pretium dictum. Phasellus id sapien vitae ipsum efficitur fringilla. Quisque suscipit consequat erat quis commodo. Aenean tristique felis libero, et ultrices justo porttitor eget. Vivamus sit amet urna nibh. Ut ultrices nulla et dui eleifend, ut sagittis ipsum condimentum. Mauris nec dolor eget augue gravida lacinia. "
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# random initialization
|
||||
random.seed()
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a:
|
||||
for word in LONG_TEXT.split():
|
||||
console.background_colour = random.choice(list(console.STANDARD_COLOURS.keys()))
|
||||
console.foreground_colour = random.choice(list(console.STANDARD_COLOURS.keys()))
|
||||
if console.background_colour == console.foreground_colour:
|
||||
if console.background_colour in ('black','red','green','yellow','blue','magenta','cyan','white'):
|
||||
console.foreground_colour = 'bright_white'
|
||||
else:
|
||||
console.foreground_colour = 'black'
|
||||
console.add_char(word)
|
||||
console.background_colour = 'black'
|
||||
console.foreground_colour = 'bright_white'
|
||||
console.add_char(' ')
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
146
tests/test1_1.py
Normal file
146
tests/test1_1.py
Normal file
@@ -0,0 +1,146 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 1_1 : display a console with `Hello world !` written (with default parameters), and test the carriage return and the line field functions.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 1_1: display a console with default parameters.",
|
||||
"press 'A' to write `Hello world !` at the cursor position.",
|
||||
"press 'ENTER' to move the cursor to the first position of the next line.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a: console.add_char("Hello world !")
|
||||
elif event.key == K_RETURN:
|
||||
console.carriage_return()
|
||||
console.line_field()
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
154
tests/test2.py
Normal file
154
tests/test2.py
Normal file
@@ -0,0 +1,154 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 2 : Write several 'Hello world !' on a console with the different standard colours.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 2: Write several `Hello world !` on a console with the 16 different standard colours.",
|
||||
"Press 'A' to write the 16 lines at the cursor position.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a:
|
||||
for font_colour in console.STANDARD_COLOURS:
|
||||
console.foreground_colour = 'bright_white'
|
||||
console.background_colour = 'black'
|
||||
console.add_char(f"{font_colour}: ")
|
||||
console.foreground_colour = font_colour
|
||||
if font_colour == 'black':
|
||||
console.background_colour = 'bright_white'
|
||||
else:
|
||||
console.background_colour = 'black'
|
||||
console.add_char("Hello world !")
|
||||
console.line_field()
|
||||
console.carriage_return()
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
154
tests/test3.py
Normal file
154
tests/test3.py
Normal file
@@ -0,0 +1,154 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 3 : Write several 'Hello world !' on a console with a background of the different standard colours.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 3: Write several `Hello world !` on a console with a background of the 16 different standard colours.",
|
||||
"Press 'A' to write the 16 lines at the cursor position.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a:
|
||||
for background_colour in console.STANDARD_COLOURS:
|
||||
console.foreground_colour = 'bright_white'
|
||||
console.background_colour = 'black'
|
||||
console.add_char(f"{background_colour}: ")
|
||||
console.background_colour = background_colour
|
||||
if background_colour == 'bright_white':
|
||||
console.foreground_colour = 'black'
|
||||
else:
|
||||
console.foreground_colour = 'bright_white'
|
||||
console.add_char("Hello world !")
|
||||
console.line_field()
|
||||
console.carriage_return()
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
144
tests/test4.py
Normal file
144
tests/test4.py
Normal file
@@ -0,0 +1,144 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 4 : Write a long text on the console with the default parameters.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 4: Write a long text on the console with the default parameters.",
|
||||
"Press 'A' to write the 'Lorem ipsum' text",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae nunc dictum, sagittis elit venenatis, efficitur justo. Etiam suscipit, ipsum accumsan aliquam elementum, massa tellus pellentesque lacus, ut porttitor ligula tortor at urna. Duis eu felis non tortor bibendum ultrices. Aliquam tortor velit, suscipit faucibus nunc quis, blandit posuere leo. Donec dignissim aliquam lectus, vitae lacinia risus feugiat non. Curabitur dapibus, massa quis eleifend lobortis, nulla sem ullamcorper turpis, vel sodales risus orci non velit. Nam ac neque faucibus, consequat eros eu, viverra neque. Nulla vel blandit lorem. Nam interdum nisl non sem pretium dictum. Phasellus id sapien vitae ipsum efficitur fringilla. Quisque suscipit consequat erat quis commodo. Aenean tristique felis libero, et ultrices justo porttitor eget. Vivamus sit amet urna nibh. Ut ultrices nulla et dui eleifend, ut sagittis ipsum condimentum. Mauris nec dolor eget augue gravida lacinia. "
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a: console.add_char(LONG_TEXT)
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
146
tests/test4_1.py
Normal file
146
tests/test4_1.py
Normal file
@@ -0,0 +1,146 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 4_1 : Write a long text on the console with the default parameters, and test the clear function.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 4: Write a long text on the console with the default parameters.",
|
||||
"Press 'A' to write the 'Lorem ipsum' text.",
|
||||
"Press 'ENTER' to clear the console.",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae nunc dictum, sagittis elit venenatis, efficitur justo. Etiam suscipit, ipsum accumsan aliquam elementum, massa tellus pellentesque lacus, ut porttitor ligula tortor at urna. Duis eu felis non tortor bibendum ultrices. Aliquam tortor velit, suscipit faucibus nunc quis, blandit posuere leo. Donec dignissim aliquam lectus, vitae lacinia risus feugiat non. Curabitur dapibus, massa quis eleifend lobortis, nulla sem ullamcorper turpis, vel sodales risus orci non velit. Nam ac neque faucibus, consequat eros eu, viverra neque. Nulla vel blandit lorem. Nam interdum nisl non sem pretium dictum. Phasellus id sapien vitae ipsum efficitur fringilla. Quisque suscipit consequat erat quis commodo. Aenean tristique felis libero, et ultrices justo porttitor eget. Vivamus sit amet urna nibh. Ut ultrices nulla et dui eleifend, ut sagittis ipsum condimentum. Mauris nec dolor eget augue gravida lacinia. "
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a: console.add_char(LONG_TEXT)
|
||||
elif event.key == K_RETURN: console.clear()
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
146
tests/test5.py
Normal file
146
tests/test5.py
Normal file
@@ -0,0 +1,146 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 5 : Write a long text on the console in bold characters.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 5: Write a long text on the console in bold characters.",
|
||||
"Press 'A' to write the 'Lorem ipsum' text",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae nunc dictum, sagittis elit venenatis, efficitur justo. Etiam suscipit, ipsum accumsan aliquam elementum, massa tellus pellentesque lacus, ut porttitor ligula tortor at urna. Duis eu felis non tortor bibendum ultrices. Aliquam tortor velit, suscipit faucibus nunc quis, blandit posuere leo. Donec dignissim aliquam lectus, vitae lacinia risus feugiat non. Curabitur dapibus, massa quis eleifend lobortis, nulla sem ullamcorper turpis, vel sodales risus orci non velit. Nam ac neque faucibus, consequat eros eu, viverra neque. Nulla vel blandit lorem. Nam interdum nisl non sem pretium dictum. Phasellus id sapien vitae ipsum efficitur fringilla. Quisque suscipit consequat erat quis commodo. Aenean tristique felis libero, et ultrices justo porttitor eget. Vivamus sit amet urna nibh. Ut ultrices nulla et dui eleifend, ut sagittis ipsum condimentum. Mauris nec dolor eget augue gravida lacinia. "
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a:
|
||||
console.bold = True
|
||||
console.add_char(LONG_TEXT)
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
146
tests/test6.py
Normal file
146
tests/test6.py
Normal file
@@ -0,0 +1,146 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 6 : Write a long text on the console in underlined, normal characters.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 6: Write a long text on the console in underlined, normal characters.",
|
||||
"Press 'A' to write the 'Lorem ipsum' text",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae nunc dictum, sagittis elit venenatis, efficitur justo. Etiam suscipit, ipsum accumsan aliquam elementum, massa tellus pellentesque lacus, ut porttitor ligula tortor at urna. Duis eu felis non tortor bibendum ultrices. Aliquam tortor velit, suscipit faucibus nunc quis, blandit posuere leo. Donec dignissim aliquam lectus, vitae lacinia risus feugiat non. Curabitur dapibus, massa quis eleifend lobortis, nulla sem ullamcorper turpis, vel sodales risus orci non velit. Nam ac neque faucibus, consequat eros eu, viverra neque. Nulla vel blandit lorem. Nam interdum nisl non sem pretium dictum. Phasellus id sapien vitae ipsum efficitur fringilla. Quisque suscipit consequat erat quis commodo. Aenean tristique felis libero, et ultrices justo porttitor eget. Vivamus sit amet urna nibh. Ut ultrices nulla et dui eleifend, ut sagittis ipsum condimentum. Mauris nec dolor eget augue gravida lacinia. "
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a:
|
||||
console.underline = True
|
||||
console.add_char(LONG_TEXT)
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
146
tests/test7.py
Normal file
146
tests/test7.py
Normal file
@@ -0,0 +1,146 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 7 : Write a long text on the console in italic characters.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 7: Write a long text on the console in italic characters.",
|
||||
"Press 'A' to write the 'Lorem ipsum' text",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae nunc dictum, sagittis elit venenatis, efficitur justo. Etiam suscipit, ipsum accumsan aliquam elementum, massa tellus pellentesque lacus, ut porttitor ligula tortor at urna. Duis eu felis non tortor bibendum ultrices. Aliquam tortor velit, suscipit faucibus nunc quis, blandit posuere leo. Donec dignissim aliquam lectus, vitae lacinia risus feugiat non. Curabitur dapibus, massa quis eleifend lobortis, nulla sem ullamcorper turpis, vel sodales risus orci non velit. Nam ac neque faucibus, consequat eros eu, viverra neque. Nulla vel blandit lorem. Nam interdum nisl non sem pretium dictum. Phasellus id sapien vitae ipsum efficitur fringilla. Quisque suscipit consequat erat quis commodo. Aenean tristique felis libero, et ultrices justo porttitor eget. Vivamus sit amet urna nibh. Ut ultrices nulla et dui eleifend, ut sagittis ipsum condimentum. Mauris nec dolor eget augue gravida lacinia. "
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a:
|
||||
console.italic = True
|
||||
console.add_char(LONG_TEXT)
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
147
tests/test8.py
Normal file
147
tests/test8.py
Normal file
@@ -0,0 +1,147 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 8 : Write a long text on the console in bold, italic characters.
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 8: Write a long text on the console in bold, italic characters.",
|
||||
"Press 'A' to write the 'Lorem ipsum' text",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae nunc dictum, sagittis elit venenatis, efficitur justo. Etiam suscipit, ipsum accumsan aliquam elementum, massa tellus pellentesque lacus, ut porttitor ligula tortor at urna. Duis eu felis non tortor bibendum ultrices. Aliquam tortor velit, suscipit faucibus nunc quis, blandit posuere leo. Donec dignissim aliquam lectus, vitae lacinia risus feugiat non. Curabitur dapibus, massa quis eleifend lobortis, nulla sem ullamcorper turpis, vel sodales risus orci non velit. Nam ac neque faucibus, consequat eros eu, viverra neque. Nulla vel blandit lorem. Nam interdum nisl non sem pretium dictum. Phasellus id sapien vitae ipsum efficitur fringilla. Quisque suscipit consequat erat quis commodo. Aenean tristique felis libero, et ultrices justo porttitor eget. Vivamus sit amet urna nibh. Ut ultrices nulla et dui eleifend, ut sagittis ipsum condimentum. Mauris nec dolor eget augue gravida lacinia. "
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a:
|
||||
console.bold = True
|
||||
console.italic = True
|
||||
console.add_char(LONG_TEXT)
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
154
tests/test9.py
Normal file
154
tests/test9.py
Normal file
@@ -0,0 +1,154 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
'console' test set : tests regarding only the pygconsole.console submodule
|
||||
Test 9 : Write a long text on the console in characters parametered randomly (bold / underline / italic), but with the default colours (foreground in bright white, background in black).
|
||||
ESCAPE Key to exit.
|
||||
"""
|
||||
|
||||
|
||||
# Standard modules
|
||||
#-----------------
|
||||
import sys
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import random
|
||||
|
||||
# Third party modules
|
||||
#--------------------
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
# Internal modules
|
||||
#-----------------
|
||||
if __name__ == '__main__':
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
|
||||
import pygconsole
|
||||
else:
|
||||
from .. import pygconsole
|
||||
|
||||
# namedtuples
|
||||
#------------
|
||||
Coordinates = namedtuple("Coordinates", "x y")
|
||||
Colour = namedtuple("Colour", "red green blue alpha")
|
||||
|
||||
# Global constants
|
||||
#-----------------
|
||||
RESOURCE_DIR = os.path.join(os.path.dirname(__file__),"resources") # directory where graphical resources are stored
|
||||
BACKGROUND_IMAGE = os.path.join(RESOURCE_DIR,"background.jpg") # Background image
|
||||
FONT = None # Font displayed outside of the console (None = default pygame font)
|
||||
|
||||
DISPLAY_SIZE = Coordinates(1920,1080) # screen resolution
|
||||
CONSOLE_COORDINATES = Coordinates(1000,620) # upper left corner coordinates of the console
|
||||
FRAMERATE = 50 # Maximum number of displaying loops per second
|
||||
|
||||
FONT_SIZE = 40 # size of the font displayed on the screen, but out of the console
|
||||
FONT_COLOUR = Colour(255,0,0,255) # Colour of the font displayed outside of the console
|
||||
TEXT_COORDINATES = Coordinates(50,50) # Coordinates of the first line of the text displayed outside of the console
|
||||
|
||||
TEXT_LIST = [
|
||||
"Test 9 : Write a long text on the console in characters parametered randomly (bold / underline / italic), but with the default colours (foreground in bright white, background in black).",
|
||||
"Press 'A' to write the 'Lorem ipsum' text",
|
||||
"ESCAPE key to exit."
|
||||
]
|
||||
|
||||
LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae nunc dictum, sagittis elit venenatis, efficitur justo. Etiam suscipit, ipsum accumsan aliquam elementum, massa tellus pellentesque lacus, ut porttitor ligula tortor at urna. Duis eu felis non tortor bibendum ultrices. Aliquam tortor velit, suscipit faucibus nunc quis, blandit posuere leo. Donec dignissim aliquam lectus, vitae lacinia risus feugiat non. Curabitur dapibus, massa quis eleifend lobortis, nulla sem ullamcorper turpis, vel sodales risus orci non velit. Nam ac neque faucibus, consequat eros eu, viverra neque. Nulla vel blandit lorem. Nam interdum nisl non sem pretium dictum. Phasellus id sapien vitae ipsum efficitur fringilla. Quisque suscipit consequat erat quis commodo. Aenean tristique felis libero, et ultrices justo porttitor eget. Vivamus sit amet urna nibh. Ut ultrices nulla et dui eleifend, ut sagittis ipsum condimentum. Mauris nec dolor eget augue gravida lacinia. "
|
||||
|
||||
# Dataclasses
|
||||
#------------
|
||||
|
||||
# Classes
|
||||
#--------
|
||||
|
||||
|
||||
# Functions
|
||||
#----------
|
||||
|
||||
|
||||
# Main function
|
||||
#--------------
|
||||
def main():
|
||||
""" Main program execution"""
|
||||
|
||||
# random initialization
|
||||
random.seed()
|
||||
|
||||
# Logging initialization
|
||||
formatter = ColoredFormatter(
|
||||
'%(log_color)s[%(asctime)s][%(levelname)s][%(name)s]:%(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
reset=True,
|
||||
log_colors={
|
||||
'DEBUG': 'cyan',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white'
|
||||
},
|
||||
secondary_log_colors={},
|
||||
style='%'
|
||||
)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('display')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(handler)
|
||||
|
||||
|
||||
# screen initialization
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock() # timer to control framerate
|
||||
flags = FULLSCREEN|SCALED|DOUBLEBUF
|
||||
screen_surface = pygame.display.set_mode(size=DISPLAY_SIZE,flags=flags)
|
||||
background_surface = pygame.image.load(BACKGROUND_IMAGE)
|
||||
|
||||
# Font initialization
|
||||
font = pygame.font.Font(FONT,FONT_SIZE)
|
||||
line_space = font.get_linesize()
|
||||
|
||||
# console initialization
|
||||
console = pygconsole.console.Console.get_console(logger = log)
|
||||
|
||||
# Displaying loop
|
||||
while True:
|
||||
clock.tick(FRAMERATE)
|
||||
|
||||
# Events
|
||||
for event in pygame.event.get():
|
||||
if event.type == QUIT: sys.exit()
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE: sys.exit()
|
||||
elif event.key == K_a:
|
||||
for word in LONG_TEXT.split():
|
||||
console.bold = random.choice((True, False))
|
||||
console.italic = random.choice((True, False))
|
||||
console.underline = random.choice((True, False))
|
||||
console.add_char(word)
|
||||
console.add_char(' ')
|
||||
|
||||
# Background display
|
||||
screen_surface.blit(background_surface,(0,0))
|
||||
|
||||
# Text display
|
||||
text_line_coordinates = TEXT_COORDINATES
|
||||
for text_line in TEXT_LIST:
|
||||
text_surface = font.render(text_line,True,FONT_COLOUR)
|
||||
screen_surface.blit(text_surface,text_line_coordinates)
|
||||
text_line_coordinates = text_line_coordinates._replace(y=text_line_coordinates.y+line_space)
|
||||
|
||||
# Console display
|
||||
screen_surface.blit(console.surface,CONSOLE_COORDINATES)
|
||||
|
||||
# Screen rendering
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# Main program,
|
||||
# running only if the module is NOT imported (but directly executed)
|
||||
#-------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user