【问题标题】:PGU HTML Renderer can't render most sitesPGU HTML 渲染器无法渲染大多数网站
【发布时间】:2010-06-05 20:39:24
【问题描述】:

我正在尝试使用 pygame 制作网络浏览器。我正在使用 PGU 进行 html 渲染。当我访问简单的网站时它工作正常,比如example.com,但是当我尝试加载使用html表单的更复杂的东西时,比如google,我得到这个错误:

UnboundLocalError: local variable 'e' referenced before assignment

我查看了 PGU html 渲染文件,发现了这段代码:

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

我在最后一行得到了错误,因为 e 没有定义。我猜这是因为检查输入类型并创建 e 变量的 if 语句不匹配任何内容。我添加了一行来打印 _type 变量,当我尝试 googleapple 时,我得到了“隐藏”。有什么方法可以使用 PGU 呈现类型为“隐藏”的表单项?

编辑:
如果我在 if 语句中添加一个部分来检查 type_ 是否等于“隐藏”,我会在其中添加什么?
编辑 2:
我已经意识到 PGU 的 html 渲染不是很好(它甚至显示 javascript 代码),所以我想知道是否有任何其他方式可以在 pygame 窗口中渲染 html。

【问题讨论】:

    标签: python pygame html-rendering


    【解决方案1】:

    我认为在 PyQT 窗口中嵌入 PyGame 是可能的。不过,这更像是一种解决方法,而不是一种优雅的解决方案。

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多