hey, i was just trying out pyglet and i noticed that the font
rendering for the file browsing is laggy and i have no idea why (well
my comp is a few years old, but it should be able to handle this):

##############################
###############################
###############################
###############################
#!/usr/bin/env python

from pyglet import font
from pyglet.gl import *
from pyglet import window
from pyglet.window import Window
from pyglet.window import key
from pyglet import media
from pyglet import image
import os, psyco, locale
psyco.full()
active_state=1
locale.setlocale(locale.LC_ALL, '')
win = window.Window(fullscreen=True)
#config is a set which will contain all the info needed for this page
#config[main menu fontsize, screen_height, screen_width, menu_items,
folder font size]
config = [72, win.height, win.width, ["music", "video", "games",
"news", "zune"],36]
#key config will hold all the key presses which corrospond with what
you do:
#key_config[up, down, right, left, stop, play]
key_config = [key.UP, key.DOWN, key.RIGHT, key.LEFT, key.SPACE,
key.RETURN]
active=1
height_of_entry=config[0]*1.5
y1= (config[1]/2)-config[0]/4
x2=config[2]/2-((config[2]-config[1]/2)-config[2]/2)
def hide_hidden_folders(directory):
        folders = os.listdir(directory)
        folders2=[]
        for i in folders:
                if i[0] != "." and i[len(i)-1] != "~":
                        if len(i)>100:
                                i=i[:9]+"..."
                        folders2.append(i)
        folders2.sort(key=locale.strxfrm)
        return folders2
base_dir="/home/user"
super_text=hide_hidden_folders(base_dir)
font.add_file("SegoeBd.ttf")
ft_menu=font.load('Segoe', config[0])
wallpaper=image.load("wallpaper.png")
def render_menu(y1,x2,x3,text,up=True):
        global win, config, active,ft_menu,wallpaper
        wallpaper.texture.blit(0,0,0,config[2],config[1])
        menu=text
        y2= (config[1]/2)-config[0]/4
        for a in range(len(menu)):
                if abs(a-active) < 5:
                        text = font.Text(ft_menu, menu[a], x2,y1,0, (1,1,1,(1-.
9*(abs((config[1]/2-config[0]/4)-y1))/256)))
                        text.draw()
                y1 += config[0]*1.5
ft_browser=font.load('Segoe', config[4])
def render_files(y1,x2,x3,text,up=True):
        global win, config, active,ft_browser,wallpaper
        wallpaper.blit(0,0,0,config[2],config[1])
        menu=text
        for a in range(0,len(menu)):
                if abs(a-active+1) <= 3:
                        text = font.Text(ft_browser, menu[a], x2,y1,0, 
(1,1,1,(1-.
99*(abs((config[1]/2-config[4]/4)-y1))/256)))
                        text.draw()
                y1 += -config[4]*1.5
y1= (config[1]/2)-config[0]/4
def control_menu(text):
        global win, y1,x2
        render_menu(y1,x2,x2,text)
        @win.event
        def on_key_press(symbol, modifiers):
            global y1, active, x2, key_config, config, active_state
            x3=x2
            if symbol == key_config[1] and active != len(text): #if down is
pressed, move the menu down
                for i in range(0, int((config[0]*1.5)/2)):
                        y1+=-2
                        win.clear()
                        render_menu(y1,x2,x3,text)
                        win.flip()
                active+=1
            if symbol == key_config[0] and active != 1: #if up is pressed,
move it up son
                for i in range(0, int((config[0]*1.5)/2)):
                        y1+=2
                        win.clear()
                        render_menu(y1,x2,x3,text,0)
                        win.flip()
                active+=-1
            if symbol == key_config[5] and active==2:
                active=1
                active_state=2
                y1= config[1]/2-config[4]/2

            elif symbol == key.ESCAPE: #might be a good idea... idk
                win.has_exit = True
def browse_files(text):
        global win, y1,x2
        render_files(y1,x2,x2,text)
        @win.event
        def on_key_press(symbol, modifiers):
            global y1, active, x2, key_config, config, super_text, base_dir
            x3=x2
            height_to_move=int((config[4]*1.5)/6)
            if symbol == key_config[1] and active != len(text): #if down is
pressed, move the menu down
                #x2=400
                for i in range(0, height_to_move):
                        y1+=6
                        win.clear()
                        render_files(y1,x2,x3,text)
                        win.flip()
                active+=1
            if symbol == key_config[0] and active != 1: #if up is pressed,
move it up son
                x2=config[2]/2-((config[2]-config[1]/2)-config[2]/2)
                for i in range(0, height_to_move):
                        y1+=-6
                        win.clear()
                        render_files(y1,x2,x3,text,0)
                        win.flip()
                active+=-1
            if symbol == key_config[5]:
                base_dir=base_dir+"/"+text[active-1]
                super_text = hide_hidden_folders(base_dir)
                for i in range(0, 
((config[2]/2)+len(text[active-1])*config[4])/25):
                        x2+=-25
                        x3+=-25
                        win.clear()
                        render_files(y1,x2,x3,text)
                        win.flip()
                y1= (config[1]/2)-config[4]/4
                active=1
                for i in range(0, 
((config[2]/2)+len(text[active-1])*config[4])/25):
                        x2+=25
                        x3+=25
                        win.clear()
                        render_files(y1,x2,x3,super_text)
                        win.flip()
                x2=config[2]/2-((config[2]-config[1]/2)-config[2]/2)
                x3=x2
            elif symbol == key.ESCAPE: #might be a good idea... idk
                win.has_exit = True

while not win.has_exit:
    win.dispatch_events()
    win.clear()
    if active_state==1:
        control_menu(config[3])
    elif active_state==2:
        browse_files(super_text)
    win.flip()
###########################################
###########################################

this is the first time using pyglet, so please spare me a beating lol
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to