def get_display(my):

        smenu_div = DivWdg()
        smenu_div.add_class( "SPT_SMENU" )
        smenu_div.add_class( "SPT_SMENU_%s" % my.menu_tag_suffix )
        smenu_div.set_box_shadow()
        smenu_div.add_border()
        smenu_div.add_color("background", "background")
        smenu_div.add_color("color", "color")

        smenu_div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            spt.dom.load_js( ["ctx_menu.js"], function() {
                    spt.dom.load_js( ["smart_menu.js"], function() {
                } )
            } );
            '''
        } )

        if my.setup_cbfn:
            smenu_div.set_attr( "SPT_SMENU_SETUP_CBFN", my.setup_cbfn )

        smenu_div.set_z_start( 300 )
        #smenu_div.add_looks( "smenu border curs_default" )
        # smenu_div.add_styles( "padding-top: 3px; padding-bottom: 5px;" )

        m_width = my.width - 2
        smenu_div.add_style( ("width: %spx" % m_width) )

        smenu_div.add_style("overflow-x: hidden")

        icon_width = 16
        icon_col_width = 0
        if my.allow_icons:
            icon_col_width = icon_width + 2
        label_width = m_width - icon_col_width - icon_width

        menu_table = Table()
        menu_table.add_styles( "text-align: left; text-indent: 3px; border-collapse: collapse;" )
        #menu_table.add_color("background", "background")
        menu_table.add_color("color", "color")

        options = my.opt_spec_list
        opt_count = 0

        if options[0].get('type') != 'title':
            my._add_spacer_row(menu_table, 3, icon_width, icon_col_width, label_width)


        """
        menu_table.add_relay_behavior( {
            'type': 'mouseenter',
            'bvr_match_class': 'SPT_SMENU_ENTRY',
            'bgcolor': menu_table.get_color("side_bar_title", -15, default="background3"),
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", bvr.bgcolor);
            bvr.src_el.setStyle("color", bvr.bgcolor);
            spt.smenu.entry_over( evt, bvr );
            '''
        } )

        menu_table.add_relay_behavior( {
            'type': 'mouseleave',
            'bvr_match_class': 'SPT_SMENU_ENTRY',
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", "");
            spt.smenu.entry_out( evt, bvr );
            '''
        } )
        """


        for opt in options:

            # if entry is a title, then add a spacer before
            if opt.get('type') == 'title' and opt_count:
                my._add_spacer_row(menu_table, 6, icon_width, icon_col_width, label_width)

            tbody = menu_table.add_tbody()
            tbody.add_style("display","table-row-group")

            tr = menu_table.add_row()
            #tr.add_looks( "smenu" )

            tr.add_class( "SPT_SMENU_ENTRY" )
            tr.add_class( "SPT_SMENU_ENTRY_%s" % opt['type'].upper() )

            if opt.has_key('enabled_check_setup_key'):
                tr.set_attr( "SPT_ENABLED_CHECK_SETUP_KEY", opt.get('enabled_check_setup_key') )

            if opt.has_key('hide_when_disabled') and opt.get('hide_when_disabled'):
                tr.set_attr( "SPT_HIDE_WHEN_DISABLED", "true" )

            if opt['type'] in [ 'action', 'toggle' ]:

                hover_bvr = {'type':'hover', 'add_looks': 'smenu_hilite',
                             'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );',
                             'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );' }
                if opt.has_key('hover_bvr_cb'):
                    hover_bvr.update( opt.get('hover_bvr_cb') )
                tr.add_behavior( hover_bvr )
                tr.add_class("hand")

            if opt['type'] == 'action':
                if opt.has_key('bvr_cb') and type(opt['bvr_cb']) == dict:
                    bvr = {}
                    bvr.update( opt['bvr_cb'] )
                    bvr['cbjs_action_for_menu_item'] = bvr['cbjs_action']
                    bvr['cbjs_action'] = 'spt.smenu.cbjs_action_wrapper( evt, bvr );'
                    bvr.update( { 'type': 'click_up' } )
                    tr.add_behavior( bvr )

            if opt['type'] == 'submenu':
                hover_bvr = { 'type': 'hover', 'add_looks': 'smenu_hilite',
                              'cbjs_action_over': 'spt.smenu.submenu_entry_over( evt, bvr );',
                              'cbjs_action_out': 'spt.smenu.submenu_entry_out( evt, bvr );',
                              'submenu_tag': "SPT_SMENU_%s" % opt['submenu_tag_suffix'],
                            }
                if opt.has_key('hover_bvr_cb'):
                    hover_bvr.update( opt.get('hover_bvr_cb') )
                tr.add_behavior( hover_bvr )
                # now trap click on submenu, so that it doesn't make the current menu disappear ...
                tr.add_behavior( { 'type': 'click', 'cbjs_action': ';', 'activator_type': 'smart_menu' } )

            tr.add_looks( "curs_default" )

            # Left icon cell ...
            if my.allow_icons:
                td = menu_table.add_cell()
                td.add_styles("text-align: center; vertical-align: middle; width: %spx;" % icon_col_width)
                #td.add_looks("smenu_icon_column")
                td.add_color("color", "color3")
                td.add_color("background", "background3")

                if opt.has_key( 'icon' ):
                    icon_wdg = IconWdg("", opt['icon'])
                    icon_wdg.add_class("SPT_ENABLED_ICON_LOOK")
                    td.add( icon_wdg )
                    #   if disabled:
                    #       icon_wdg.add_style( "opacity: .4" )
                    #       icon_wdg.add_style( "filter: alpha(opacity=40)" )

            # Menu option label cell ...
            td = menu_table.add_cell()
            td.add_style("width", ("%spx" % label_width))
            td.add_style("height", ("%spx" % icon_col_width))
            #if opt.get('type') != 'title':
            #    td.add_style( "padding-left: 6px" )
            #td.add_style( "padding-top: 2px" )
            td.add_style("padding: 6px 4px")

            if opt.has_key( 'label' ):
                label_str = opt.get('label').replace('"','"')
                td.add_class("SPT_LABEL")
                td.add( label_str )
                td.set_attr( "SPT_ORIG_LABEL", label_str )
                #td.add_looks("fnt_text")
                td.add_style("font-size: 1.0em")
                if opt.get('type') == 'title':
                    #td.add_looks("smenu_title")
                    td.add_color("background", "background2")
                    td.add_color("color", "color2")
                    td.add_style("font-weight", "bold")
                    td.add_style("padding", "3px")
            elif opt.get('type') == 'separator':
                hr = HtmlElement("hr")
                hr.add_looks( "smenu_separator" )
                td.add( hr )

            td.add_class("SPT_ENABLED_LOOK")

            #   if disabled:
            #       td.add_style( "opacity: .2" )
            #       td.add_style( "filter: alpha(opacity=20)" )

            # Submenu arrow icon cell ...
            td = menu_table.add_cell()
            td.add_style("width", ("%spx" % icon_width))

            if opt['type'] == 'submenu':
                icon_wdg = IconWdg("", IconWdg.ARROWHEAD_DARK_RIGHT)
                td.add(icon_wdg)
                td.add_class("SPT_ENABLED_ICON_LOOK")

            # extend title entry styling into the submenu arrow cell and add some spacing after
            if opt.get('type') == 'title':
                #td.add_looks("smenu_title")
                td.add_color("background", "background2")
                td.add_color("color", "color2")
                td.add_style("font-weight", "bold")
                td.add_style("padding", "3px")
                my._add_spacer_row(menu_table, 3, icon_width, icon_col_width, label_width)

            #   if disabled:
            #       td.add_style( "opacity: .4" )
            #       td.add_style( "filter: alpha(opacity=40)" )

            opt_count += 1


        my._add_spacer_row(menu_table, 5, icon_width, icon_col_width, label_width)

        smenu_div.add( menu_table )
        smenu_div.add_style( "display: none" )
        smenu_div.add_style( "position: absolute" )
        return smenu_div
Exemple #2
0
    def get_display(my):

        smenu_div = DivWdg()
        smenu_div.add_class("SPT_SMENU")
        smenu_div.add_class("SPT_SMENU_%s" % my.menu_tag_suffix)
        smenu_div.set_box_shadow()
        smenu_div.add_border()
        smenu_div.add_color("background", "background")
        smenu_div.add_color("color", "color")

        smenu_div.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
            spt.dom.load_js( ["ctx_menu.js"], function() {
                    spt.dom.load_js( ["smart_menu.js"], function() {
                } )
            } );
            '''
        })

        if my.setup_cbfn:
            smenu_div.set_attr("SPT_SMENU_SETUP_CBFN", my.setup_cbfn)

        smenu_div.set_z_start(300)
        #smenu_div.add_looks( "smenu border curs_default" )
        # smenu_div.add_styles( "padding-top: 3px; padding-bottom: 5px;" )

        m_width = my.width - 2
        smenu_div.add_style(("width: %spx" % m_width))

        smenu_div.add_style("overflow-x: hidden")

        icon_width = 16
        icon_col_width = 0
        if my.allow_icons:
            icon_col_width = icon_width + 2
        label_width = m_width - icon_col_width - icon_width

        menu_table = Table()
        menu_table.add_styles(
            "text-align: left; text-indent: 3px; border-collapse: collapse;")
        #menu_table.add_color("background", "background")
        menu_table.add_color("color", "color")

        options = my.opt_spec_list
        opt_count = 0

        if options[0].get('type') != 'title':
            my._add_spacer_row(menu_table, 3, icon_width, icon_col_width,
                               label_width)
        """
        menu_table.add_relay_behavior( {
            'type': 'mouseenter',
            'bvr_match_class': 'SPT_SMENU_ENTRY',
            'bgcolor': menu_table.get_color("side_bar_title", -15, default="background3"),
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", bvr.bgcolor);
            bvr.src_el.setStyle("color", bvr.bgcolor);
            spt.smenu.entry_over( evt, bvr );
            '''
        } )

        menu_table.add_relay_behavior( {
            'type': 'mouseleave',
            'bvr_match_class': 'SPT_SMENU_ENTRY',
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", "");
            spt.smenu.entry_out( evt, bvr );
            '''
        } )
        """

        for opt in options:

            # if entry is a title, then add a spacer before
            if opt.get('type') == 'title' and opt_count:
                my._add_spacer_row(menu_table, 6, icon_width, icon_col_width,
                                   label_width)

            tbody = menu_table.add_tbody()
            tbody.add_style("display", "table-row-group")

            tr = menu_table.add_row()
            #tr.add_looks( "smenu" )

            tr.add_class("SPT_SMENU_ENTRY")
            tr.add_class("SPT_SMENU_ENTRY_%s" % opt['type'].upper())

            if opt.has_key('enabled_check_setup_key'):
                tr.set_attr("SPT_ENABLED_CHECK_SETUP_KEY",
                            opt.get('enabled_check_setup_key'))

            if opt.has_key('hide_when_disabled') and opt.get(
                    'hide_when_disabled'):
                tr.set_attr("SPT_HIDE_WHEN_DISABLED", "true")

            if opt['type'] in ['action', 'toggle']:

                hover_bvr = {
                    'type': 'hover',
                    'add_looks': 'smenu_hilite',
                    'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );',
                    'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );'
                }
                if opt.has_key('hover_bvr_cb'):
                    hover_bvr.update(opt.get('hover_bvr_cb'))
                tr.add_behavior(hover_bvr)
                tr.add_class("hand")

            if opt['type'] == 'action':
                if opt.has_key('bvr_cb') and type(opt['bvr_cb']) == dict:
                    bvr = {}
                    bvr.update(opt['bvr_cb'])
                    bvr['cbjs_action_for_menu_item'] = bvr['cbjs_action']
                    bvr['cbjs_action'] = 'spt.smenu.cbjs_action_wrapper( evt, bvr );'
                    bvr.update({'type': 'click_up'})
                    tr.add_behavior(bvr)

            if opt['type'] == 'submenu':
                hover_bvr = {
                    'type': 'hover',
                    'add_looks': 'smenu_hilite',
                    'cbjs_action_over':
                    'spt.smenu.submenu_entry_over( evt, bvr );',
                    'cbjs_action_out':
                    'spt.smenu.submenu_entry_out( evt, bvr );',
                    'submenu_tag': "SPT_SMENU_%s" % opt['submenu_tag_suffix'],
                }
                if opt.has_key('hover_bvr_cb'):
                    hover_bvr.update(opt.get('hover_bvr_cb'))
                tr.add_behavior(hover_bvr)
                # now trap click on submenu, so that it doesn't make the current menu disappear ...
                tr.add_behavior({
                    'type': 'click',
                    'cbjs_action': ';',
                    'activator_type': 'smart_menu'
                })

            tr.add_looks("curs_default")

            # Left icon cell ...
            if my.allow_icons:
                td = menu_table.add_cell()
                td.add_styles(
                    "text-align: center; vertical-align: middle; width: %spx;"
                    % icon_col_width)
                #td.add_looks("smenu_icon_column")
                td.add_color("color", "color3")
                td.add_color("background", "background3")

                if opt.has_key('icon'):
                    icon_wdg = IconWdg("", opt['icon'])
                    icon_wdg.add_class("SPT_ENABLED_ICON_LOOK")
                    td.add(icon_wdg)
                    #   if disabled:
                    #       icon_wdg.add_style( "opacity: .4" )
                    #       icon_wdg.add_style( "filter: alpha(opacity=40)" )

            # Menu option label cell ...
            td = menu_table.add_cell()
            td.add_style("width", ("%spx" % label_width))
            td.add_style("height", ("%spx" % icon_col_width))
            if opt.get('type') != 'title':
                td.add_style("padding-left: 6px")
            td.add_style("padding-top: 2px")

            if opt.has_key('label'):
                label_str = opt.get('label').replace('"', '"')
                td.add_class("SPT_LABEL")
                td.add(label_str)
                td.set_attr("SPT_ORIG_LABEL", label_str)
                #td.add_looks("fnt_text")
                td.add_style("font-size: 11px")
                if opt.get('type') == 'title':
                    #td.add_looks("smenu_title")
                    td.add_color("background", "background2")
                    td.add_color("color", "color2")
                    td.add_style("font-weight", "bold")
                    td.add_style("padding", "3px")
            elif opt.get('type') == 'separator':
                hr = HtmlElement("hr")
                hr.add_looks("smenu_separator")
                td.add(hr)

            td.add_class("SPT_ENABLED_LOOK")

            #   if disabled:
            #       td.add_style( "opacity: .2" )
            #       td.add_style( "filter: alpha(opacity=20)" )

            # Submenu arrow icon cell ...
            td = menu_table.add_cell()
            td.add_style("width", ("%spx" % icon_width))

            if opt['type'] == 'submenu':
                icon_wdg = IconWdg("", IconWdg.ARROWHEAD_DARK_RIGHT)
                td.add(icon_wdg)
                td.add_class("SPT_ENABLED_ICON_LOOK")

            # extend title entry styling into the submenu arrow cell and add some spacing after
            if opt.get('type') == 'title':
                #td.add_looks("smenu_title")
                td.add_color("background", "background2")
                td.add_color("color", "color2")
                td.add_style("font-weight", "bold")
                td.add_style("padding", "3px")
                my._add_spacer_row(menu_table, 3, icon_width, icon_col_width,
                                   label_width)

            #   if disabled:
            #       td.add_style( "opacity: .4" )
            #       td.add_style( "filter: alpha(opacity=40)" )

            opt_count += 1

        my._add_spacer_row(menu_table, 5, icon_width, icon_col_width,
                           label_width)

        smenu_div.add(menu_table)
        smenu_div.add_style("display: none")
        smenu_div.add_style("position: absolute")
        return smenu_div