2012-06-21 20 views
0

我有一个包含两个按钮和一个框架的网页。在框架内显示网页。我试图让它如此按钮在鞋架中鞋子网址'/ AAA',而按钮B在鞋架中'鞋子'/'BBB'。我怎么能这样做?Pyjs /睡衣框架:如何使用按钮来更改框架中的url

以下是我有:

class ImageButton(SimplePanel): 
    def __init__(self, image_location): 
     '''(None, str) -> None''' 

     SimplePanel.__init__(self) 

     img = Image(image_location, StyleName='rangler') 
     img.addClickListener(getattr(self, "onImageClick")) 
     self.add(img) 


    def onImageClick(self, sender=None): 

     pass 
     #This is where I need help!? 

class QAFrame(SimplePanel): 
    def __init__(self, current_url): 
     SimplePanel.__init__(self) 

     frame = Frame(current_url, 
         Width="200%", 
         Height="650px") 
     self.add(frame) 


def caption(): 
    style_sheet = HTML("""<link rel='stylesheet' href='about_us.css'>""") 
    srah_pic = ImageButton("Steve.jpg") 
    fl_pic = ImageButton("Fraser.jpg") 

    horizontal = HorizontalPanel() 
    vertical = VerticalPanel() 

    vertical.add(srah_pic) 
    vertical.add(fl_pic) 
    horizontal.add(vertical) 

    QAFrame('Fraser_qa.htm') 
    QAFrame('Steve_qa.htm') 

    horizontal.add(QAFrame('Steve_qa.htm')) 



    RootPanel().add(horizontal) 

回答

1

基本上,

您需要.addClickListener你的按钮,作为一个参数,要在处理器来传递,将执行所需的任务点击按钮。

让我很困惑的一件事是,我无法将一个参数传递给我的处理程序。但是,对象“发件人”会自动传入处理程序。您可以尝试浏览发件人属性以查找所需的信息。

class ImageButton(SimplePanel): 

    def __init__(self, image_location, css_style): 
     '''(None, str, str) -> None''' 

     SimplePanel.__init__(self) 

     self.image_location = image_location 

     img = Image(self.image_location, StyleName= css_style) 
     img.addClickListener(Cool) # Cool is the name of my handler function 
     self.add(img) 

def Cool(sender): # You can do whatever you want in your handler function. 
        # I am changing the url of a frame 
        # It is a little-medium "Hacky" 

    if sender.getUrl()[-9:] == 'Steve.jpg': 
     iframe.setUrl('Fraser_qa.htm') 
    else: 
     iframe.setUrl('Steve_qa.htm') 
0

我会扩展我的ImageButton类以支持将URL传递到要显示的网页。在__init__函数中,可以将该URL存储在实例属性中。

您应该将clickhandler变成一个实例方法,该实例方法可以访问包含指向所需页面的URL的实例变量。

我缺乏明确的Python知识来提供代码示例。希望你仍然理解这个概念。