#!/usr/bin/env python
# coding:utf-8 vi:et:ts=2

# PyUser menu widget for Tkinter backend.
# Copyright 2013 Grigory Petrov
# See LICENSE for details.

import Tkinter

from support_widget import Widget
from support_grow   import Grow
import pyuser as pu


class Menu( Widget ):


  def __init__( self, s_name = None, o_parent = 'auto' ):
    Widget.__init__( self, s_name = s_name, o_parent = o_parent )
    assert self.dparent.isMenuBar()
    self._context_o = Tkinter.Menu( self.dparent.context() )


  def context( self ):
    return self._context_o


  ##x Overloads |Whoami|.
  def isMenu( self ):
    return True


  ##x Overloads |Widget|.
  def dadd( self, o_widget ):
    Widget.dadd( self, o_widget )
    sLabel = o_widget.text()
    if o_widget.isMenu():
      oContext = o_widget.context()
      self._context_o.add_cascade( menu = oContext, label = sLabel )
    elif o_widget.isMenuItem():
      self._context_o.add_command( label = sLabel, command = o_widget.cmd )


  def setText( self, s_text ):
    ##  Will be used by parent menu to add this one as submenu.
    self._text_s = s_text


  def text( self ):
    return self._text_s

