Well, running the code shows nothing for me.
I totally expect that because you define some classes but instantiate
anything :-)

I suppose that you forgot to paste some more lines.

Adding

if __name__ == '__main__':
      client = Client()
      client.run()

at the end of your script I got a visual of a live widget: it displays, can
be dragged, reacts visually and in console to mouse clicks.
Snapshot attached.

Your code looks right [0]

If you can confirm that adding the two lines you don't see a widget, then I
would suspect you need to set some gl state (expected by pywidget) just
before calling draw.
As a blind and easy stab,  you can try adding
     glColor4ub(255, 255, 255, 255)

just before the line
    self.dialog.on_draw()



[0]nitpick: you are not calling super in the overrided methods on_enter and
on_exit, which in general will stop the propagation of on_enter on_exit to
childs.
Is not a problem with this particular script because the node has no
childs, but is better to be consistent in the code.





On Sun, Apr 7, 2013 at 2:29 AM, Doug Linder <[email protected]>wrote:

> Example code:
> http://pastebin.com/8pbrJ9xJ
>
> When I add print('Draw') to the draw function, I get no terminal output.
>
> Can you see what's wrong with it?
>
> ~
> Doug.
>
> On Sunday, April 7, 2013 2:26:00 AM UTC+8, Claudio Canepa wrote:
>
>>
>> On Sat, Apr 6, 2013 at 12:30 PM, Doug Linder <[email protected]>wrote:
>>
>>> Hey there,
>>>
>>> I've been using pywidget 
>>> (https://pywidget.googlecode.**com/svn/trunk<https://pywidget.googlecode.com/svn/trunk>)
>>> with cocos2d quite successfully as a GUI, but in order to do so I've had to
>>> hack the cocos director class.
>>>
>>> Basically, modifying Director::on_draw to read, at the end:
>>>
>>>        # Draw the GUI
>>>         if self.gui != None:
>>>           self.gui.on_draw()
>>>
>>> Where you pass in the appropriate pywidget gui object by assigning it to
>>> the director:
>>>
>>> class Client:
>>>   def run(self):
>>>
>>>     cocos.director.director.init()
>>>     cocos.director.director.gui = dialog
>>>     cocos.director.director.**window.push_handlers(dialog)
>>>
>>>     ui = rpg.ui.Test()
>>>     main_scene = cocos.scene.Scene (ui)
>>>     cocos.director.director.run (main_scene)
>>>
>>> This seems fairly successful in that the cocos event handlers still
>>> work, and the event bindings for the UI work, so all in all, pretty good.
>>>
>>> However, it's annoying having to patch the cocos source to do this.
>>>
>>> I feel like I should just be able to extend CocosNode and override the
>>> draw() method, then add the object to the scene, but my draw() function
>>> never seems to get called when I do this.
>>>
>>>
>> If you subclass CocosNode , instantiate your subclass and adds to an
>> active scene, then his visit and draw methods will be called [0].
>>
>> If you show code for your CocosNode attempt that is not working for you
>> maybe a fix can be suggested.
>>
>>
>>> Is there some special magic I need to do?
>>>
>>>
>> I don't think so
>>
>>
>>> I'd prefer not to hack up the source just to have a gui if I can avoid
>>> it.
>>>
>>>
>> Yeah.
>> Pastebin your original attemp (not modifyng director) , or a simplified
>> one and w'ill see.
>>
>>
>>
>> [0] Technically your overriden visit can decide to skip calls to draw,
>> drawing the node and childs with custom code, presumably for performance
>> reasons.
>>
>>
>>   --
> You received this message because you are subscribed to the Google Groups
> "cocos2d discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/cocos-discuss?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


<<attachment: pywidget_in_cocos.png>>

Reply via email to