views:

54

answers:

1

I am trying to make a web browser using pygame. I am using PGU for html rendering. It works fine when I visit simple sites, like example.com, but when I try and load anything more complex that uses an html form, like google, I get this error:

UnboundLocalError: local variable 'e' referenced before assignment

I looked in the PGU html rendering file and found this code segment:

def start_input(self,attrs):
    r = self.attrs_to_map(attrs)
    params = self.map_to_params(r) #why bother
    #params = {}

    type_,name,value = r.get('type','text'),r.get('name',None),r.get('value',None)
    f = self.form
    if type_ == 'text':
        e = gui.Input(**params)
        self.map_to_connects(e,r)
        self.item.add(e)
    elif type_ == 'radio':
        if name not in f.groups:
            f.groups[name] = gui.Group(name=name)
        g = f.groups[name]
        del params['name']
        e = gui.Radio(group=g,**params)
        self.map_to_connects(e,r)
        self.item.add(e)
        if 'checked' in r: g.value = value
    elif type_ == 'checkbox':
        if name not in f.groups:
            f.groups[name] = gui.Group(name=name)
        g = f.groups[name]
        del params['name']
        e = gui.Checkbox(group=g,**params)
        self.map_to_connects(e,r)
        self.item.add(e)
        if 'checked' in r: g.value = value

    elif type_ == 'button':
        e = gui.Button(**params)
        self.map_to_connects(e,r)
        self.item.add(e)
    elif type_ == 'submit':
        e = gui.Button(**params)
        self.map_to_connects(e,r)
        self.item.add(e)
    elif type_ == 'file':
        e = gui.Input(**params)
        self.map_to_connects(e,r)
        self.item.add(e)
        b = gui.Button(value='Browse...')
        self.item.add(b)
        def _browse(value):
            d = gui.FileDialog();
            d.connect(gui.CHANGE,gui.action_setvalue,(d,e))
            d.open();
        b.connect(gui.CLICK,_browse,None)

    self._locals[r.get('id',None)] = e

I got the error in the last line, because e wasn't defined. I am guessing the reason for this is that the if statement that checks the type of the input and creates the e variable didn't match anything. I added a line to print the _type variable and I got 'hidden' when i tried google and apple. Is there any way to render form items that have the type 'hidden' with PGU?

Edit:
If I added a section to the if statement to check if type_ was equal to 'hidden', what would I put in it?
Edit 2:
I have realized that the html rendering is not very good (it even shows javascript code) for PGU and so I would like to know if there is any other way of rendering html in a pygame window.

A: 

I think it's possible to embed PyGame in a PyQT window. That's more of a work around than an elegant solution though.

Luke Stanley