Hi,

I need to dynamically hide (and show) a widget or a panel at runtime.

Looking at the API documentation, it seams that the correct method is 
setVisible.
However any kind of tests I made failed with an exception raised: 
"AttributeError: 'Button' object has no attribute 'style'.

Attached you'll find a simple example that I wrote (for Pyjamas 0.8, Python 
2.6.4).
There are two buttons and a label; clicking on one button hides itself and 
shows the other one, and viceversa.

Please, can you give me any suggestion on how to make it work?

Thanks
Cesare

-- 



import pyjd # dummy in pyjs

from pyjamas.ui.Button import Button
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from pyjamas.ui.Label import Label
from pyjamas.ui.RootPanel import RootPanel



class HideWidgets:

  def onModuleLoad(self):

    Panel = HorizontalPanel(BorderWidth=1, Spacing=8)

    self.OnLoginButton = Button('Login', self.OnLogin)
    Panel.add(self.OnLoginButton)
    self.OnRegisterButton = Button('Register', self.OnRegister)
    Panel.add(self.OnRegisterButton)
    self.Status = Label()
    Panel.add(self.Status)

    RootPanel().add(Panel)


  def OnLogin(self, sender):

    self.Status.setText('Called Login! Hiding Login, showing Register...')
    self.OnLoginButton.setVisible(self.OnLoginButton, False)
    self.OnRegisterButton.setVisible(self.OnRegisterButton, True)


  def OnRegister(self, sender):

    self.Status.setText('Called Register! Hiding Register, showing Login...')
    self.OnRegisterButton.setVisible(self.OnRegisterButton, False)
    self.OnLoginButton.setVisible(self.OnLoginButton, True)



if __name__ == '__main__':
  # for pyjd, set up a web server and load the HTML from there:
  # this convinces the browser engine that the AJAX will be loaded
  # from the same URI base as the URL, it's all a bit messy...
  pyjd.setup('http://127.0.0.1:8080/WSGI/')
  
  App = HideWidgets()
  App.onModuleLoad()

  pyjd.run()

Reply via email to