Exemple #1
0
    def add_header_context_menu(my, widget):
        from menu_wdg import Menu, MenuItem
        menu = Menu(width=180)
        menu.set_allow_icons(False)
        menu.set_setup_cbfn('spt.dg_table.smenu_ctx.setup_cbk')

        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Reload')
        menu.add(menu_item)
        menu_item.add_behavior({
            'cbjs_action':
            '''
            var header = spt.smenu.get_activator(bvr);
            var top = header.getParent(".spt_popup");
            var content_top = top.getElement(".spt_popup_content");
            var content = content_top.getElement(".spt_panel");
            spt.panel.refresh(content);
            '''
        })

        menu_item = MenuItem(type='separator')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Dock Window')
        menu_item.add_behavior({
            'cbjs_action':
            '''
            var header = spt.smenu.get_activator(bvr);
            var top = header.getParent(".spt_popup");
            var content = top.getElement(".spt_popup_content");
            var title = top.getElement(".spt_popup_title")
            var title = title.innerHTML;
            //var element_name = header.getAttribute("spt_element_name");

            spt.tab.set_main_body_tab();

            var html = content.innerHTML;

            spt.tab.add_new(title, title);
            spt.tab.load_html(title, html);

            spt.popup.close(top);
            '''
        })
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Open in Browser')
        menu.add(menu_item)
        menu_item.add_behavior({
            'cbjs_action':
            '''
            var header = spt.smenu.get_activator(bvr);
            var top = header.getParent(".spt_popup");
            var content = top.getElement(".spt_popup_content");

            var html = content.innerHTML;
            var url = spt.Environment.get().get_server_url();
            var project = spt.Environment.get().get_project();
            var url = url + "/tactic/"+project+"/#//widget/tactic.ui.container.EmptyWdg";

            spt.app_busy.show("Copying to new browser window");
            var win = window.open(url);
            setTimeout( function() {
                var empty_el = $(win.document).getElement(".spt_empty_top");
                spt.behavior.replace_inner_html(empty_el, html);
                spt.app_busy.hide();
            }, 2000 );

            //spt.popup.close(top);
            '''
        })

        menus = [menu.get_data()]
        menus_in = {
            'HEADER_CTX': menus,
        }
        from tactic.ui.container.smart_menu_wdg import SmartMenu
        SmartMenu.attach_smart_context_menu(widget, menus_in, False)
    def add_header_context_menu(my, widget):
        from menu_wdg import Menu, MenuItem
        menu = Menu(width=180)
        menu.set_allow_icons(False)
        menu.set_setup_cbfn( 'spt.dg_table.smenu_ctx.setup_cbk' )


        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Reload')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'cbjs_action': '''
            var header = spt.smenu.get_activator(bvr);
            var top = header.getParent(".spt_popup");
            var content_top = top.getElement(".spt_popup_content");
            var content = content_top.getElement(".spt_panel");
            spt.panel.refresh(content);
            '''
        } )


        menu_item = MenuItem(type='separator')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Dock Window')
        menu_item.add_behavior( {
            'cbjs_action': '''
            var header = spt.smenu.get_activator(bvr);
            var top = header.getParent(".spt_popup");
            var content = top.getElement(".spt_popup_content");
            var title = top.getElement(".spt_popup_title")
            var title = title.innerHTML;
            //var element_name = header.getAttribute("spt_element_name");

            spt.tab.set_main_body_tab();

            var html = content.innerHTML;

            spt.tab.add_new(title, title);
            spt.tab.load_html(title, html);

            spt.popup.close(top);
            '''
        } )
        menu.add(menu_item)


        menu_item = MenuItem(type='action', label='Open in Browser')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'cbjs_action': '''
            var header = spt.smenu.get_activator(bvr);
            var top = header.getParent(".spt_popup");
            var content = top.getElement(".spt_popup_content");

            var html = content.innerHTML;
            var url = spt.Environment.get().get_server_url();
            var project = spt.Environment.get().get_project();
            var url = url + "/tactic/"+project+"/#//widget/tactic.ui.container.EmptyWdg";

            spt.app_busy.show("Copying to new browser window");
            var win = window.open(url);
            setTimeout( function() {
                var empty_el = $(win.document).getElement(".spt_empty_top");
                spt.behavior.replace_inner_html(empty_el, html);
                spt.app_busy.hide();
            }, 2000 );

            //spt.popup.close(top);
            '''
        } )







        menus = [menu.get_data()]
        menus_in = {
            'HEADER_CTX': menus,
        }
        from tactic.ui.container.smart_menu_wdg import SmartMenu
        SmartMenu.attach_smart_context_menu( widget, menus_in, False )
Exemple #3
0
    def get_display(my):

        div = DivWdg()

        if not Container.get_dict("JSLibraries", "spt_popup"):
            div.add_style("position: fixed")
            div.add_style("top: 0px")
            div.add_style("left: 0px")
            div.add_style("opacity: 0.4")
            div.add_style("background", "#000")
            div.add_style("padding: 100px")
            div.add_style("height: 100%")
            div.add_style("width: 100%")
            div.add_class("spt_popup_background")
            div.add_style("display: none")
            div.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                spt.hide(bvr.src_el);
                '''
            })

        Container.put("PopupWdg:background", True)

        # This is the absolute outside of a popup, including the drop shadow
        widget = DivWdg()
        div.add(widget)
        widget.add_class("spt_popup")

        if not Container.get_dict("JSLibraries", "spt_popup"):
            widget.add_behavior({
                'type': 'load',
                'cbjs_action': my.get_onload_js()
            })

        width = my.kwargs.get("width")
        if not width:
            width = 10

        #widget.add_behavior( {
        #    'type': 'load',
        #    'cbjs_action': 'bvr.src_el.makeResizable({handle:bvr.src_el.getElement(".spt_popup_resize")})'
        #} )

        web = WebContainer.get_web()

        widget.set_id(my.name)
        if my.kwargs.get("display") == "true":
            pass
        else:
            widget.add_style("display: none")

        widget.add_style("position: absolute")
        widget.add_style("left: 400px")
        widget.add_style("top: 100px")

        widget.add_border()
        widget.add_color("background", "background")

        #widget.set_box_shadow(color="#000")
        widget.set_box_shadow()

        table = Table()
        table.add_behavior({
            'type':
            'load',
            'width':
            width,
            'cbjs_action':
            '''
        bvr.src_el.setStyle("width", bvr.width)

        var popup = bvr.src_el.getParent(".spt_popup");
        var window_size = $(window).getSize();
        var size = bvr.src_el.getSize();
        var left = window_size.x/2 - size.x/2;
        var top = window_size.y/2 - size.y/2;
        popup.setStyle("left", left);
        //popup.setStyle("top", top);

        '''
        })

        table.add_row()
        """
        # Qt doesn't support shadows very well
        if web.get_browser() == 'Qtx':
            # dynamically add css files

            table.add_class("css_shadow_table")
            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top_left SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top_right SPT_POPUP_SHADOW")


            # Middle (Content) Row of Shadow table ...
            table.add_row()

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_left SPT_POPUP_SHADOW")
        """

        content_td = table.add_cell()
        content_td.add_class("css_shadow_td")
        """
        if web.get_browser() == 'Qtx':
            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_right SPT_POPUP_SHADOW")


            # Bottom Row of Shadow table ...
            table.add_row()

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom_left SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom_right SPT_POPUP_SHADOW")
        """

        drag_div = DivWdg()

        #from tactic.ui.container import ArrowWdg
        #arrow = ArrowWdg()
        #drag_div.add(arrow)

        # FIXME: for some reason, this causes popups to stop functioning after
        # close a couple of times
        my.add_header_context_menu(drag_div)

        # create the 'close' button ...
        if my.allow_close:
            close_wdg = SpanWdg()
            #close_wdg.add( IconWdg("Close", IconWdg.POPUP_WIN_CLOSE) )
            close_wdg.add(IconWdg("Close", "BS_REMOVE"))
            close_wdg.add_style("margin: 5px 1px 3px 1px")
            close_wdg.add_style("float: right")
            close_wdg.add_class("hand")

            close_wdg.add_behavior({
                'type': 'click_up',
                'cbjs_action': my.get_cancel_script()
            })

            drag_div.add(close_wdg)

            # create the 'minimize' button ...
            minimize_wdg = SpanWdg()
            minimize_wdg.add_style("margin: 5px 1px 3px 1px")
            #minimize_wdg.add( IconWdg("Minimize", IconWdg.POPUP_WIN_MINIMIZE) )
            minimize_wdg.add(IconWdg("Minimize", "BS_MINUS"))
            minimize_wdg.add_style("float: right")
            minimize_wdg.add_class("hand")
            behavior = {
                'type': 'click_up',
                'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );"
            }
            minimize_wdg.add_behavior(behavior)
            drag_div.add(minimize_wdg)

        #-- TO ADD SOON -- create the 'refresh' button ...
        #   refresh_wdg = SpanWdg()
        #   refresh_wdg.add( IconWdg("Refresh Popup", IconWdg.POPUP_WIN_REFRESH) )
        #   refresh_wdg.add_style("float: right")
        #   refresh_wdg.add_class("hand")
        #   behavior = {
        #       'type': 'click_up',
        #       'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );"
        #   }
        #   refresh_wdg.add_behavior( behavior );
        #   drag_div.add(refresh_wdg)

        width = my.kwargs.get("width")

        # style
        drag_div.add_style("font-size: 1.1em")

        drag_div.add_style("text-align: left")
        drag_div.add_class("spt_popup_width")

        drag_handle_div = DivWdg(id='%s_title' % my.name)
        drag_handle_div.add_style("padding: 12px;")
        #drag_handle_div.add_gradient("background", "background", +10)
        drag_handle_div.add_color("background", "background", -5)
        drag_handle_div.add_color("color", "color")
        drag_handle_div.add_style("font-weight", "bold")
        drag_handle_div.add_style("font-size", "12px")

        # add the drag capability.
        # NOTE: need to use getParent because spt.popup has not yet been
        # initialized when this is processed
        shadow_color = drag_div.get_color("shadow")
        drag_div.add_behavior({
            'type': 'smart_drag',
            'shadow_color': shadow_color,
            'drag_el': "@.getParent('.spt_popup')",
            'bvr_match_class': 'spt_popup_title',
            'options': {
                'z_sort': 'bring_forward'
            },
            'ignore_default_motion': 'true',
            "cbjs_setup": '''
              if (spt.popup.is_background_visible) {
                  spt.popup.offset_x = document.body.scrollLeft;
                  spt.popup.offset_y = document.body.scrollTop;
                  spt.popup.hide_background();
                  var parent = bvr.src_el.getParent(".spt_popup");
                  parent.setStyle("box-shadow","0px 0px 20px " + bvr.shadow_color);
              }
              else {
                  spt.popup.offset_x = 0;
                  spt.popup.offset_y = 0;
              }
            ''',
            "cbjs_motion": '''
              mouse_411.curr_x += spt.popup.offset_x;
              mouse_411.curr_y += spt.popup.offset_y;
              spt.mouse.default_drag_motion(evt, bvr, mouse_411);
            ''',
            "cbjs_action": ''
        })

        title_wdg = my.title_wdg
        if not title_wdg:
            title_wdg = "No Title"
        #else:
        #    title_wdg = title_wdg

        drag_handle_div.add_behavior({
            'type': 'double_click',
            'cbjs_action': my.get_cancel_script()
        })

        drag_handle_div.add(title_wdg)
        drag_handle_div.add_class("spt_popup_title")

        # add a context menu
        from tactic.ui.container.smart_menu_wdg import SmartMenu
        SmartMenu.assign_as_local_activator(drag_handle_div, 'HEADER_CTX')
        drag_handle_div.add_attr("spt_element_name", "Test Dock")

        # add the content
        content_div = DivWdg()
        content_div.add_color("color", "color2")
        #content_div.add_color("background", "background2")
        from pyasm.web.palette import Palette
        palette = Palette.get()
        content_div.add_color("color", "color2")
        content_div.add_color("background", "background2")

        content_div.add_style("margin", "0px, -1px -0px -1px")

        content_div.set_id("%s_content" % my.name)
        content_div.add_class("spt_popup_content")
        content_div.add_style("overflow: hidden")
        content_div.add_style("display: block")
        #content_div.add_style("padding: 10px")
        if not my.content_wdg:
            my.content_wdg = "No Content"

        content_div.add(my.content_wdg)

        drag_div.add(drag_handle_div)
        my.position_aux_div(drag_div, content_div)
        content_td.add(drag_div)
        widget.add(table)

        # ALWAYS make the Popup a Page Utility Widget (now processed client side)
        widget.add_class("SPT_PUW")

        if my.z_start:
            widget.set_z_start(my.z_start)
            widget.add_style("z-index: %s" % my.z_start)
        else:
            widget.add_style("z-index: 102")

        # add the resize icon
        icon = IconWdg("Resize", IconWdg.RESIZE_CORNER)
        icon.add_style("cursor: nw-resize")
        icon.add_style("z-index: 1000")
        icon.add_class("spt_popup_resize")
        icon.add_style("float: right")
        icon.add_style("margin-top: -15px")
        icon.add_behavior({
            'type': 'drag',
            "drag_el": '@',
            "cb_set_prefix": 'spt.popup.resize_drag'
        })
        content_td.add(icon)

        #return widget
        return div
    def get_display(my):

        div = DivWdg()

        if not Container.get_dict("JSLibraries", "spt_popup"):
            div.add_style("position: fixed")
            div.add_style("top: 0px")
            div.add_style("left: 0px")
            div.add_style("opacity: 0.4")
            div.add_style("background", "#000")
            div.add_style("padding: 100px")
            div.add_style("height: 100%")
            div.add_style("width: 100%")
            div.add_class("spt_popup_background")
            div.add_style("display: none")
            div.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                spt.hide(bvr.src_el);
                '''
            } ) 

        Container.put("PopupWdg:background", True)



        # This is the absolute outside of a popup, including the drop shadow
        widget = DivWdg()
        div.add(widget)
        widget.add_class("spt_popup")



        if not Container.get_dict("JSLibraries", "spt_popup"):
            widget.add_behavior( {
                'type': 'load',
                'cbjs_action': my.get_onload_js()
            } )


        width = my.kwargs.get("width")
        if not width:
            width = 10

        #widget.add_behavior( {
        #    'type': 'load',
        #    'cbjs_action': 'bvr.src_el.makeResizable({handle:bvr.src_el.getElement(".spt_popup_resize")})'
        #} )


        web = WebContainer.get_web()


        widget.set_id(my.name)
        if my.kwargs.get("display") == "true":
            pass
        else:
            widget.add_style("display: none")

        widget.add_style("position: absolute")
        widget.add_style("left: 400px")
        widget.add_style("top: 100px")

        widget.add_border()
        widget.add_color("background", "background")

        #widget.set_box_shadow(color="#000")
        widget.set_box_shadow()


        table = Table()
        table.add_behavior( {
        'type': 'load',
        'width': width,
        'cbjs_action': '''
        bvr.src_el.setStyle("width", bvr.width)

        var popup = bvr.src_el.getParent(".spt_popup");
        var window_size = $(window).getSize();
        var size = bvr.src_el.getSize();
        var left = window_size.x/2 - size.x/2;
        var top = window_size.y/2 - size.y/2;
        popup.setStyle("left", left);
        //popup.setStyle("top", top);

        '''
        } )



        table.add_row()

        """
        # Qt doesn't support shadows very well
        if web.get_browser() == 'Qtx':
            # dynamically add css files

            table.add_class("css_shadow_table")
            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top_left SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top_right SPT_POPUP_SHADOW")


            # Middle (Content) Row of Shadow table ...
            table.add_row()

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_left SPT_POPUP_SHADOW")
        """

        content_td = table.add_cell()
        content_td.add_class("css_shadow_td")

        """
        if web.get_browser() == 'Qtx':
            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_right SPT_POPUP_SHADOW")


            # Bottom Row of Shadow table ...
            table.add_row()

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom_left SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom_right SPT_POPUP_SHADOW")
        """


        drag_div = DivWdg()

        #from tactic.ui.container import ArrowWdg
        #arrow = ArrowWdg()
        #drag_div.add(arrow)


        # FIXME: for some reason, this causes popups to stop functioning after
        # close a couple of times
        my.add_header_context_menu(drag_div)


        # create the 'close' button ...
        if my.allow_close:
            close_wdg = SpanWdg(css='spt_popup_close')
            #close_wdg.add( IconWdg("Close", IconWdg.POPUP_WIN_CLOSE) )
            close_wdg.add( IconWdg("Close", "BS_REMOVE") )
            close_wdg.add_style("margin: 5px 1px 3px 1px")
            close_wdg.add_style("float: right")
            close_wdg.add_class("hand")

            close_wdg.add_behavior({
                'type': 'click_up',
                'cbjs_action': my.get_cancel_script()
            })

            drag_div.add(close_wdg)


            # create the 'minimize' button ...
            minimize_wdg = SpanWdg(css='spt_popup_min')
            minimize_wdg.add_style("margin: 5px 1px 3px 1px")
            #minimize_wdg.add( IconWdg("Minimize", IconWdg.POPUP_WIN_MINIMIZE) )
            minimize_wdg.add( IconWdg("Minimize", "BS_MINUS") )
            minimize_wdg.add_style("float: right")
            minimize_wdg.add_class("hand")
            behavior = {
                'type': 'click_up',
                'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );"
            }
            minimize_wdg.add_behavior( behavior );
            drag_div.add(minimize_wdg)

        #-- TO ADD SOON -- create the 'refresh' button ...
        #   refresh_wdg = SpanWdg()
        #   refresh_wdg.add( IconWdg("Refresh Popup", IconWdg.POPUP_WIN_REFRESH) )
        #   refresh_wdg.add_style("float: right")
        #   refresh_wdg.add_class("hand")
        #   behavior = {
        #       'type': 'click_up',
        #       'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );"
        #   }
        #   refresh_wdg.add_behavior( behavior );
        #   drag_div.add(refresh_wdg)

        width = my.kwargs.get("width")

        # style
        drag_div.add_style("font-size: 1.1em")

        drag_div.add_style("text-align: left")
        drag_div.add_class("spt_popup_width")

        drag_handle_div = DivWdg(id='%s_title' %my.name)
        drag_handle_div.add_style("padding: 12px;")
        #drag_handle_div.add_gradient("background", "background", +10)
        drag_handle_div.add_color("background", "background", -5)
        drag_handle_div.add_color("color", "color")
        drag_handle_div.add_style("font-weight", "bold")
        drag_handle_div.add_style("font-size", "12px")


        # add the drag capability.
        # NOTE: need to use getParent because spt.popup has not yet been
        # initialized when this is processed
        shadow_color = drag_div.get_color("shadow")
        drag_div.add_behavior( {
            'type':'smart_drag',
            'shadow_color': shadow_color,
            'drag_el': "@.getParent('.spt_popup')",
            'bvr_match_class': 'spt_popup_title',
            'options': {'z_sort': 'bring_forward'},
            'ignore_default_motion': 'true',
            "cbjs_setup": '''
              if (spt.popup.is_background_visible) {
                  spt.popup.offset_x = document.body.scrollLeft;
                  spt.popup.offset_y = document.body.scrollTop;
                  spt.popup.hide_background();
                  var parent = bvr.src_el.getParent(".spt_popup");
                  parent.setStyle("box-shadow","0px 0px 20px " + bvr.shadow_color);
              }
              else {
                  spt.popup.offset_x = 0;
                  spt.popup.offset_y = 0;
              }
            ''',
            "cbjs_motion": '''
              mouse_411.curr_x += spt.popup.offset_x;
              mouse_411.curr_y += spt.popup.offset_y;
              spt.mouse.default_drag_motion(evt, bvr, mouse_411);
            ''',
            "cbjs_action": ''
        } )


        
        title_wdg = my.title_wdg
        if not title_wdg:
            title_wdg = "No Title"
        #else:
        #    title_wdg = title_wdg

        drag_handle_div.add_behavior({
            'type': 'double_click',
            'cbjs_action': my.get_cancel_script()
        })


        drag_handle_div.add(title_wdg)
        drag_handle_div.add_class("spt_popup_title")


        # add a context menu
        from tactic.ui.container.smart_menu_wdg import SmartMenu
        SmartMenu.assign_as_local_activator( drag_handle_div, 'HEADER_CTX' )
        drag_handle_div.add_attr("spt_element_name", "Test Dock")



        # add the content
        content_div = DivWdg()
        content_div.add_color("color", "color2")
        #content_div.add_color("background", "background2")
        from pyasm.web.palette import Palette
        palette = Palette.get()
        content_div.add_color("color", "color2")
        content_div.add_color("background", "background2")

        content_div.add_style("margin", "0px, -1px -0px -1px")

        content_div.set_id("%s_content" % my.name)
        content_div.add_class("spt_popup_content")
        content_div.add_style("overflow: hidden")
        content_div.add_style("display: block")
        #content_div.add_style("padding: 10px")
        if not my.content_wdg:
            my.content_wdg = "No Content"

        content_div.add(my.content_wdg)

        drag_div.add( drag_handle_div )
        my.position_aux_div(drag_div, content_div)
        content_td.add(drag_div)
        widget.add(table)

        # ALWAYS make the Popup a Page Utility Widget (now processed client side)
        widget.add_class( "SPT_PUW" )

        if my.z_start:
            widget.set_z_start( my.z_start )
            widget.add_style("z-index: %s" % my.z_start)
        else:
            widget.add_style("z-index: 102")


        # add the resize icon
        icon = IconWdg( "Resize", IconWdg.RESIZE_CORNER )
        icon.add_style("cursor: nw-resize")
        icon.add_style("z-index: 1000")
        icon.add_class("spt_popup_resize")
        icon.add_style("float: right")
        icon.add_style("margin-top: -15px")
        icon.add_behavior( {
        'type': 'drag',
        "drag_el": '@',
        "cb_set_prefix": 'spt.popup.resize_drag'
        } )
        content_td.add(icon)

        #return widget
        return div