New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot decorate class method #410

Open
pyjsorg opened this Issue Apr 27, 2012 · 8 comments

Comments

Projects
None yet
1 participant
@pyjsorg
Contributor

pyjsorg commented Apr 27, 2012

Here is the code: http://pastebin.com/f326f4759

What is the expected output? What do you see instead?

I'm hoping that all Buttons will have the alternate style instead of the
default style. The decorator works fine when I tested it with separate
non-class functions, but does not work with the Button init class
method.

Traceback:

Module MemorizeApp at line 15 :
TypeError: Cannot call method 'setitem' of undefined
MemorizeApp.py, line 108:
app.onModuleLoad()
MemorizeApp.py, line 46:
showButton = Button('Show Answer',self.showAnswer)
MemorizeApp.py, line 15:
kwargs['StyleName']='fg-button ui-state-default ui-corner-all

What version of Pyjamas are you using? which svn revision number?
On what operating system?

r2015 on Linux

If using PyJS, what compiler options did you use?
-d --bound-methods

Original issue: http://code.google.com/p/pyjamas/issues/detail?id=309 (October 21, 2009 05:50:53)

@pyjsorg

This comment has been minimized.

Show comment
Hide comment
@pyjsorg

pyjsorg Apr 27, 2012

Contributor

From gdwar...@gmail.com on October 21, 2009 05:52:22:
PS. The reason I'm trying to do this is so I can use unmodified .css files from
jquery's theme roller. I thought this would be a cool solution to change the default
css class name for all Buttons.

Contributor

pyjsorg commented Apr 27, 2012

From gdwar...@gmail.com on October 21, 2009 05:52:22:
PS. The reason I'm trying to do this is so I can use unmodified .css files from
jquery's theme roller. I thought this would be a cool solution to change the default
css class name for all Buttons.

@pyjsorg

This comment has been minimized.

Show comment
Hide comment
@pyjsorg

pyjsorg Apr 27, 2012

Contributor

From luke.lei...@gmail.com on October 21, 2009 09:08:58:
good idea greg.
however you can now use a kwarg of StyleName in the constructor.

Contributor

pyjsorg commented Apr 27, 2012

From luke.lei...@gmail.com on October 21, 2009 09:08:58:
good idea greg.
however you can now use a kwarg of StyleName in the constructor.

@pyjsorg

This comment has been minimized.

Show comment
Hide comment
@pyjsorg

pyjsorg Apr 27, 2012

Contributor

From cornelis...@gmail.com on October 21, 2009 12:50:45:
jfyi, afaik: Decorators need --descriptors

Contributor

pyjsorg commented Apr 27, 2012

From cornelis...@gmail.com on October 21, 2009 12:50:45:
jfyi, afaik: Decorators need --descriptors

@pyjsorg

This comment has been minimized.

Show comment
Hide comment
@pyjsorg

pyjsorg Apr 27, 2012

Contributor

From gdwar...@gmail.com on October 21, 2009 13:54:55:
@luke: That's exactly what I'm trying to do. I'm trying to decorate the constructor
of Button. That way, if I have 50 buttons, I don't have to pass in the same
StyleName argument for each of them.

@kees: Thanks for the suggestion. It didn't seem to change anything. I have got
decorators of regular functions to work just fine - it's just class-methods.


That said, I have found another way to do what I'm trying to do (though this
decorator issue still remains):

from pyjamas.ui.Button import Button as plainButton
class Button(plainButton):
def init(self, _args,__kwargs):
plainButton.init(self, *args, StyleName='fg-button ui-state-default ui-
corner-all', *_kwargs)

Contributor

pyjsorg commented Apr 27, 2012

From gdwar...@gmail.com on October 21, 2009 13:54:55:
@luke: That's exactly what I'm trying to do. I'm trying to decorate the constructor
of Button. That way, if I have 50 buttons, I don't have to pass in the same
StyleName argument for each of them.

@kees: Thanks for the suggestion. It didn't seem to change anything. I have got
decorators of regular functions to work just fine - it's just class-methods.


That said, I have found another way to do what I'm trying to do (though this
decorator issue still remains):

from pyjamas.ui.Button import Button as plainButton
class Button(plainButton):
def init(self, _args,__kwargs):
plainButton.init(self, *args, StyleName='fg-button ui-state-default ui-
corner-all', *_kwargs)

@pyjsorg

This comment has been minimized.

Show comment
Hide comment
@pyjsorg

pyjsorg Apr 27, 2012

Contributor

From luke.lei...@gmail.com on October 30, 2009 09:18:10:
greg, make that:

class Button(...)
init...

if not kwargs.has_key('StyleName'):
kwargs['StyleName'] = 'fg-button .....'

and then you'll have a more versatile widget.

Contributor

pyjsorg commented Apr 27, 2012

From luke.lei...@gmail.com on October 30, 2009 09:18:10:
greg, make that:

class Button(...)
init...

if not kwargs.has_key('StyleName'):
kwargs['StyleName'] = 'fg-button .....'

and then you'll have a more versatile widget.

@pyjsorg

This comment has been minimized.

Show comment
Hide comment
@pyjsorg

pyjsorg Apr 27, 2012

Contributor

From luke.lei...@gmail.com on October 30, 2009 09:18:29:
1.
import pyjd # this is dummy in pyjs.
2.
from pyjamas.ui.RootPanel import RootPanel
3.
from pyjamas.ui.Button import Button
4.

  1. def deco(fn):

  2. def newFn(_args, *_kwargs):

  3. kwargs['StyleName']='fg-button ui-state-default ui-corner-all'
    
  4. res = fn(_args,_*kwargs)
    
  5. return res
    
  6. return newFn

  7. Button.init = deco(Button.init)

  8. class MemorizeApp:

  9. def onModuleLoad(self):

  10. showButton = Button('Show Answer',self.showAnswer)
    
  11. RootPanel().add(showButton)
    
  12. self.remote.getCard(self)
    
  13. if name == 'main':

  14. app = MemorizeApp()

  15. app.onModuleLoad()

Contributor

pyjsorg commented Apr 27, 2012

From luke.lei...@gmail.com on October 30, 2009 09:18:29:
1.
import pyjd # this is dummy in pyjs.
2.
from pyjamas.ui.RootPanel import RootPanel
3.
from pyjamas.ui.Button import Button
4.

  1. def deco(fn):

  2. def newFn(_args, *_kwargs):

  3. kwargs['StyleName']='fg-button ui-state-default ui-corner-all'
    
  4. res = fn(_args,_*kwargs)
    
  5. return res
    
  6. return newFn

  7. Button.init = deco(Button.init)

  8. class MemorizeApp:

  9. def onModuleLoad(self):

  10. showButton = Button('Show Answer',self.showAnswer)
    
  11. RootPanel().add(showButton)
    
  12. self.remote.getCard(self)
    
  13. if name == 'main':

  14. app = MemorizeApp()

  15. app.onModuleLoad()

@pyjsorg

This comment has been minimized.

Show comment
Hide comment
@pyjsorg

pyjsorg Apr 27, 2012

Contributor

From i...@dasir.cz on November 01, 2009 21:42:12:
try r2151 and newer

Contributor

pyjsorg commented Apr 27, 2012

From i...@dasir.cz on November 01, 2009 21:42:12:
try r2151 and newer

@pyjsorg

This comment has been minimized.

Show comment
Hide comment
@pyjsorg

pyjsorg Apr 27, 2012

Contributor

From luke.lei...@gmail.com on November 09, 2009 19:52:43:
nope - it throws an error "kwargs has no properties"

Contributor

pyjsorg commented Apr 27, 2012

From luke.lei...@gmail.com on November 09, 2009 19:52:43:
nope - it throws an error "kwargs has no properties"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment