0

I have a web page that contains two buttons and a frame. Within the frame, a web page is displayed. I am trying to make it so button A shoes url '/AAA' in the frame while button B shoes url '/BBB' in the frame. How the heck can I do that?

Here is what I have:

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)

2 Answers2

1

Basically,

You need to .addClickListener to your button and, as a parameter, you want to pass in the handler that will perform your desired task on button click.

The one thing that really confused me was, I could not pass an argument through to my handler. But, the object "sender" is automatically passed in with the handler. You can try to fish through the senders attributes to find information that you need.

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

I would extend my ImageButton class to support passing in the URL to the webpage you want to show. In the __init__ function, you can store that URL in an instance property.

You should make the clickhandler into an instance method, which can access the instance variable which holds the URL to the desired page.

I lack the definitive Python knowledge to supply code examples. Hope you still understand the concept.

Symen Timmermans
  • 877
  • 1
  • 8
  • 18