def render_string(string, font, size):
    """
    This is a helper function to render strings as an image widget
    to be processed in the GUI.
    """
    text = String.draw_string(string, font, size, 1, (0,0,0))
    text = ImageLabel(text)
    return text
Beispiel #2
0
# String.create_font () usage example.
import pygame
from ocempgui.draw import String

def check (font, name):
    bold = "not bold"
    if font.get_bold ():
        bold = "bold"
    print "%s at %s is %s" % (name, font, bold)

# Initialize the pygame engine.
pygame.init ()

# Create a font from the ttf located in the current directory.
font = String.create_font ("tuffy.ttf", 14)
check (font, "font")

# Now create a second font and manipulate it.
# NOTE: Due to the caching we are using the same font object as above!
font_mod = String.create_font ("tuffy.ttf", 14)
font_mod.set_bold (True)

# Output the bold state of both fonts.
check (font, "font")
check (font_mod, "font_mod")
Beispiel #3
0
 def drawString(self,x,y):
     # string drawing shenanigans
     text = String.draw_string (self.value, "Times",14,1,(255,0,0))
     window.blit (text, (x, y))
Beispiel #4
0
# String.create_system_font () usage example.
import pygame
from ocempgui.draw import String

# Initialize the pygame engine.
pygame.init ()

# Create some fonts.
fonts = {}
names = ( "Arial", "Helvetica", "Sans", "Serif", "Times" )
for name in names:
    fonts[name] = String.create_system_font (name, 14)

# Output the fonts as well as their object address.
for name in fonts:
    print "Loaded: %s at %s" % (name, fonts[name])
Beispiel #5
0
# String.draw_string_with_bg () usage example.
import pygame, pygame.locals
from ocempgui.draw import String

# Initialize the drawing window.
pygame.init ()
screen = pygame.display.set_mode ((100, 100))
screen.fill ((250, 250, 250))
pygame.display.set_caption ('String.draw_string_with_bg ()')

# Create texts using the 'Times' system font and different background
# colors.
text = String.draw_string_with_bg ("This is Times", "Times", 16, 1, (0, 0, 0),
                                   (200, 200, 200))
screen.blit (text, (5, 5))

text = String.draw_string_with_bg ("This is Times", "Times", 16, 1, (0, 0, 0),
                                   (0, 200, 0))
screen.blit (text, (5, 60))

# Show anything.
pygame.display.flip ()

# Wait for input.
while not pygame.event.get ([pygame.locals.QUIT]):
    pass
Beispiel #6
0
# String.draw_string () usage example.
import pygame, pygame.locals
from ocempgui.draw import String

# Initialize the drawing window.
pygame.init ()
screen = pygame.display.set_mode ((400, 100))
screen.fill ((250, 250, 250))
pygame.display.set_caption ('String.draw_string ()')

# Create a text using the ttf located in the current directory.
text = String.draw_string ("This is tuffy.ttf", "tuffy.ttf", 16, 1, (0, 0, 0))
screen.blit (text, (5, 5))

# Create a text using the 'Times' system font
text = String.draw_string ("This is Times", "Times", 16, 1, (255, 0, 0))
screen.blit (text, (5, 35))

# Create a text using the fallback python font by specifying a wrong
# font name (hopefully ;-).
text = String.draw_string ("This is the fallback", "invalid_font_name_here",
                           16, 1, (0, 0, 255))
screen.blit (text, (5, 60))

# Now the same again without antialiasing.
text = String.draw_string ("This is tuffy.ttf (no aa)", "tuffy.ttf",
                           16, 0, (0, 0, 0))
screen.blit (text, (200, 5))

text = String.draw_string ("This is Times (no aa)", "Times",
                           16, 0, (255, 0, 0))