Esempio n. 1
0
    def get_display(self):
        if self.redirect:
            return self.redirect.get_display()


        self.add_class("spt_button_top")
        # no need to define top
        #self.add(top)

        self.add_style("margin: 0px 3px", override=False)

        opacity = self.kwargs.get("opacity")
        if not opacity:
            opacity = 1.0 
        self.add_style("opacity: %s" % opacity)

        base = "%s/%s" % (BASE, self.get_theme() )

        self.add(self.table)
        td = self.td
        td.add_style("text-align: center")

        size = self.kwargs.get("size")
        if not size:
            size = 'medium'
        size = size[:1]


        width = self.kwargs.get("width")
        if width:
            top_width = int(width)
            self.add_style("width: %s"%top_width)
        else:
            top_width = 40
            if size == 'm':
                top_width = 83
                self.add_style("width: %spx"%top_width)
            if size == 'l':
                top_width = 127
                self.add_style("width: %spx"%top_width)
            if size == 'b':
                top_width = "100%"
                self.add_style("width: %spx"%top_width)
                self.table.add_style("width: 100%")


        



        #request_top_wdg = Container.get("request_top_wdg")
        #if not request_top_wdg:
        #    request_top_wdg = self.table
        request_top_wdg = self.table

        try:
            button_bvr = request_top_wdg.has_class("spt_button_behaviors")
            if not button_bvr:
                self.add_top_behaviors(request_top_wdg)
                request_top_wdg.add_class("spt_button_behaviors")
        except Exception as e:
            print "WARNING: ", e


        title = self.kwargs.get("title")
        if not title:
            title = "No Title"

        # stretch it wider in case the text is longer, 
        # don't make it too long though
        if len(title) > 10:
            width = len(title)/8.0 * 60
            if width < top_width:
                width = top_width
            td.add_style('width', width)
            td.add_style('height', '28px')
        if not title:
            title = "(No title)"

        #title = "Search"
        tip = self.kwargs.get("tip")
        if not tip:
            tip = title
        self.add_attr("title", tip)

        
        title2 = self.kwargs.get("title2")
        if title2:
            td.add_behavior( {
            'type': 'click_up',
            'title1': title,
            'title2': title2,
            'cbjs_action': '''
            var label_el = bvr.src_el.getElement(".spt_label");
            var label1 = bvr.title1;
            var label2 = bvr.title2;
            if (label_el.value == label1) {
                label_el.value = label2;
            }
            else {
                label_el.value = label1;
            }
            '''
            } )


        from pyasm.widget import ButtonWdg
        button = ButtonWdg()
        button.add_style("width: %s" % top_width)
        button.add_class('spt_label')

        icon = self.kwargs.get("icon")
        if icon:
            icon_div = DivWdg() 
            icon = IconWdg(title, icon, width=16 )
            icon_div.add(icon)
            button.add(icon_div)
            self.table.add_style("position: relative")
            icon_div.add_style("position: absolute")
            icon_div.add_style("left: 5px")
            icon_div.add_style("top: 6px")
            title = " &nbsp; &nbsp; %s" % title
            button.add_style("padding: 2px")

        button.set_name(title)

        td.add(button)
        #button.add_border()
        #button.set_box_shadow("0px 0px 1px", color=button.get_color("shadow"))



        if self.browser == 'Qt' and os.name != 'nt':
            button.add_style("top: 8px")
        else:
            button.add_style("top: 6px")

        # BOOTSTRAP
        color = self.kwargs.get("color")
        button.add_class('btn')
        if color:
            if color.startswith("#"):
                button.add_style("background", color)
            else:
                button.add_class('btn-%s' % color)
        else:
            button.add_class('btn-default')

        if size == 'b':
            button.add_class('btn-block')
        else:
            button.add_class('btn-sm')
        button.add_style("top: 0px")


        button.add_attr('spt_text_label', title)
        td.add_class("spt_action_button_hit")
        button.add_class("hand")

        return super(ActionButtonWdg,self).get_display()
    def get_display(my):

        top = my.top

        #top.add_gradient("background", "background", 5, -20)
        top.add_color("background", "background", -5)
        #top.add_style("padding-top: 10px")

        #title = "Sample Chart"
        title = my.kwargs.get("title")
        if title:
            date = "@FORMAT(@STRING($TODAY),'Dec 31, 1999')"
            date = Search.eval(date, single=True)

            title_wdg = DivWdg()
            top.add(title_wdg)
            title_wdg.add(title)
            title_wdg.add(" [%s]" % date)
            title_wdg.add_style("font-size: 1.1em")
            title_wdg.add_color("background", "background3")
            title_wdg.add_color("color", "color3")
            title_wdg.add_style("padding: 10px")
            title_wdg.add_style("font-weight: bold")
            title_wdg.add_style("text-align: center")

        colors = [
            'rgba(255,0,0,0.5)',
            'rgba(0,255,0,0.5)',
            'rgba(0,0,255,0.5)',
            'rgba(128,0,255,0.5)',
            'rgba(0,128,255,0.5)',
            'rgba(255,0,255,0.5)',
        ]

        # draw a legend
        legend = None
        from chart2_wdg import ChartLegend

        #import pdb; pdb.set_trace();

        labels = my.kwargs.get("labels")
        my.user = my.kwargs.get("user")

        if labels:
            legend = ChartLegend()
            labels = labels.split("|")
            legend.set_labels(labels)
            top.add(legend)
            legend.add_style("width: %s" % str(len(labels)*200))
            legend.add_style("margin-left: auto")
            legend.add_style("margin-right: auto")

            #legend.add_style("width: 200px")
            #legend.add_style("position: absolute")
            #legend.add_style("top: 40px")
            #legend.add_style("left: 300px")


        if legend:
            legend.set_colors(colors)


        #############
        # table for start-end date
        search_table = Table()
        search_table.add_style("margin-left: auto")
        search_table.add_style("margin-right: auto")
        search_table.add_style("margin-top: 35px")
        search_table.add_style("margin-bottom: 45px")
        top.add(search_table)
 
        search_table.add_row()

        td = search_table.add_cell()
        start_date = DivWdg("Start Date")
        td.add(start_date)
        start_date.add_style("margin-left: 5px")
        #td = table.add_cell()
        #op = DivWdg(" between&nbsp;&nbsp;&nbsp;")
        #op.add_style("margin-left: 5px")
        #td.add(op)

        from tactic.ui.widget import CalendarInputWdg
        td = search_table.add_cell()
        cal1 = CalendarInputWdg("start_date")
        td.add(cal1)

        search_table.add_row()
        end_date = DivWdg("End Date")
        end_date.add_style("margin-left: 5px")
        td = search_table.add_cell()
        td.add(end_date)
        #td.add(spacing)

        td = search_table.add_cell()
        cal2 = CalendarInputWdg("end_date")
        td.add(cal2)

        search_table.add_row()
        td = search_table.add_cell()

        from pyasm.widget import ButtonWdg
        button = ButtonWdg()
        #button.add_style("width: %s" % top_width)
        button.add_class('spt_label')

        icon = my.kwargs.get("icon")
        if icon:
            icon_div = DivWdg()
            icon = IconWdg(title, icon, width=16 )
            icon_div.add(icon)
            button.add(icon_div)
            my.table.add_style("position: relative")
            icon_div.add_style("position: absolute")
            icon_div.add_style("left: 5px")
            icon_div.add_style("top: 6px")
            title = " &nbsp; &nbsp; %s" % title
            button.add_style("padding: 2px")

        button.set_name("Reload")

        td.add(button)
        #############


        task_data = my.get_task_data()
        
        labels = [label[0] for label in task_data.get(task_data.keys()[0])]

        #labels = ['chr001', 'chr002', 'chr003', 'chr004', 'prop001', 'prop002', 'cow001']
        #labels = ['week 1', 'week 2', 'week 3', 'week 4', 'week 5', 'week 6', 'week 7', 'week 8']
        #values = [1,2,4,5,6,7,8]
        values = [i+1 for i in range(len(labels))]

        width = my.kwargs.get("width")
        if not width:
            width = '1600px'
        height = my.kwargs.get("height")
        if not height:
            height = '1000px'


        chart_div = DivWdg()
        top.add(chart_div)
        chart_div.add_style("text-align: center")

        chart = ChartWdg(
            height=height,
            width=width,
            chart_type='bar',
            labels=labels
        )
        chart_div.add(chart)

        data = ChartData(
            color=colors[0], #"rgba(255, 0, 0, 1.0)",
            #data=[task_data['Pending'], 5.5, 7.5, 14.3, 10.2, 1.1, 3.3],
            data = [data[1] for data in task_data.get('Pending')]
        )
        chart.add(data)

        data = ChartData(
            color=colors[1], #"rgba(0, 255, 0, 1.0)",
            #data=[task_data['Assignment'], 4.3, 8.4, 6.2, 8.4, 2.2],
            data = [data[1] for data in task_data.get('Assignment')]
        )
        chart.add(data)


        data = ChartData(
            color=colors[2], #"rgba(0, 0, 255, 1.0)",
            #data=[task_data['In Progress'], 3.5, 2.2, 6.6, 1.3, 9.4],
            data = [data[1] for data in task_data.get('In Progress')]
        )
        chart.add(data)


        #data = [task_data['Approved'], 17, 15.5, -3, 17, 16.8, 11.4]
        data = [data[1] for data in task_data.get('Approved')]
        data = ChartData(data=data, color=colors[3]) #"rgba(128, 0, 255, 1.0)")
        chart.add(data)


        data = [data[1] for data in task_data.get('Review')] 
        data = ChartData(data=data, color=colors[4]) #"rgba(0, 128, 255, 1.0)")
        chart.add(data)

        table = Table()
        table.add_color("color", "color")
        top.add(table)
        table.add_row()
        table.center()
        table.add_style("width: 1%")


        x_title = my.kwargs.get("x_title")
        y_title = my.kwargs.get("y_title")

        if y_title:
            y_title = y_title.replace(" ", "&nbsp;")

            y_axis_div = DivWdg()
            td = table.add_cell(y_axis_div)
            td.add_style("vertical-align: middle")
            td.add_style("width: 1%")
            y_axis_div.add(y_title)
            y_axis_div.add_style("-moz-transform: rotate(-90deg)")
            y_axis_div.add_style("-webkit-transform: rotate(-90deg)")
            y_axis_div.add_style("font-size: 1.33em")
            y_axis_div.add_style("height: 100%")
            y_axis_div.add_style("width: 30px")

        table.add_row()

        # add the x-axis title
        if x_title:
            x_title = x_title.replace(" ", "&nbsp;")

            x_axis_div = DivWdg()
            td = table.add_cell(x_axis_div)
            td.add_style("text-align: center")
            td.add_style("width: 1%")
            x_axis_div.add(x_title)
            x_axis_div.add_style("font-size: 1.33em")
            x_axis_div.add_style("width: 100%")
            x_axis_div.add_style("height: 30px")

        return top
    def get_display(my):
        div = DivWdg()

        table = Table()
        div.add(table)
        table.add_row()

        if my.title:
            title_div = DivWdg()

            table.add_cell(title_div)

            name = "Ym"

            title = my.title
            if not title:
                title = name
            title = Common.get_display_title(title)
            title_div.add("%s:" % title )
            title_div.add_style("width: 80px")
            title_div.add_style("font-weight: bold")
            title_div.add_style("margin-left: 15px")
            title_div.add_style("padding-top: 2px")

        td = table.add_cell()
        start_date = DivWdg("Start Date")
        td.add(start_date)
        start_date.add_style("margin-left: 5px")
        #td = table.add_cell()
        #op = DivWdg(" between&nbsp;&nbsp;&nbsp;")
        #op.add_style("margin-left: 5px")
        #td.add(op)

        from tactic.ui.widget import CalendarInputWdg
        td = table.add_cell()
        cal1 = CalendarInputWdg("start_date")
        td.add(cal1)

        table.add_row()
        end_date = DivWdg("End Date")
        end_date.add_style("margin-left: 5px")
        td = table.add_cell()
        td.add(end_date)
        #td.add(spacing)

        td = table.add_cell()
        cal2 = CalendarInputWdg("end_date")
        td.add(cal2)

        table.add_row()
        td = table.add_cell()

        from pyasm.widget import ButtonWdg
        button = ButtonWdg()
        #button.add_style("width: %s" % top_width)
        button.add_class('spt_label')

        icon = my.kwargs.get("icon")
        if icon:
            icon_div = DivWdg()
            icon = IconWdg(title, icon, width=16 )
            icon_div.add(icon)
            button.add(icon_div)
            my.table.add_style("position: relative")
            icon_div.add_style("position: absolute")
            icon_div.add_style("left: 5px")
            icon_div.add_style("top: 6px")
            title = " &nbsp; &nbsp; %s" % title
            button.add_style("padding: 2px")

        button.set_name("Reload")

        td.add(button)

        return div
Esempio n. 4
0
    def get_display(self):
        if self.redirect:
            return self.redirect.get_display()

        self.add_class("spt_button_top")
        # no need to define top
        #self.add(top)

        self.add_style("margin: 0px 3px", override=False)

        opacity = self.kwargs.get("opacity")
        if not opacity:
            opacity = 1.0
        self.add_style("opacity: %s" % opacity)

        base = "%s/%s" % (BASE, self.get_theme())

        self.add(self.table)
        td = self.td
        td.add_style("text-align: center")

        size = self.kwargs.get("size")
        if not size:
            size = 'medium'
        size = size[:1]

        width = self.kwargs.get("width")
        if width:
            top_width = int(width)
            self.add_style("width: %s" % top_width)
        else:
            top_width = 40
            if size == 'm':
                top_width = 83
                self.add_style("width: %spx" % top_width)
            if size == 'l':
                top_width = 127
                self.add_style("width: %spx" % top_width)
            if size == 'b':
                top_width = "100%"
                self.add_style("width: %spx" % top_width)
                self.table.add_style("width: 100%")

        #request_top_wdg = Container.get("request_top_wdg")
        #if not request_top_wdg:
        #    request_top_wdg = self.table
        request_top_wdg = self.table

        try:
            button_bvr = request_top_wdg.has_class("spt_button_behaviors")
            if not button_bvr:
                self.add_top_behaviors(request_top_wdg)
                request_top_wdg.add_class("spt_button_behaviors")
        except Exception as e:
            print "WARNING: ", e

        title = self.kwargs.get("title")
        if not title:
            title = "No Title"

        # stretch it wider in case the text is longer,
        # don't make it too long though
        if len(title) > 10:
            width = len(title) / 8.0 * 60
            if width < top_width:
                width = top_width
            td.add_style('width', width)
            td.add_style('height', '28px')
        if not title:
            title = "(No title)"

        #title = "Search"
        tip = self.kwargs.get("tip")
        if not tip:
            tip = title
        self.add_attr("title", tip)

        title2 = self.kwargs.get("title2")
        if title2:
            td.add_behavior({
                'type':
                'click_up',
                'title1':
                title,
                'title2':
                title2,
                'cbjs_action':
                '''
            var label_el = bvr.src_el.getElement(".spt_label");
            var label1 = bvr.title1;
            var label2 = bvr.title2;
            if (label_el.value == label1) {
                label_el.value = label2;
            }
            else {
                label_el.value = label1;
            }
            '''
            })

        from pyasm.widget import ButtonWdg
        button = ButtonWdg()
        button.add_style("width: %s" % top_width)
        button.add_class('spt_label')

        icon = self.kwargs.get("icon")
        if icon:
            icon_div = DivWdg()
            icon = IconWdg(title, icon, width=16)
            icon_div.add(icon)
            button.add(icon_div)
            self.table.add_style("position: relative")
            icon_div.add_style("position: absolute")
            icon_div.add_style("left: 5px")
            icon_div.add_style("top: 6px")
            title = " &nbsp; &nbsp; %s" % title
            button.add_style("padding: 2px")

        button.set_name(title)

        td.add(button)
        #button.add_border()
        #button.set_box_shadow("0px 0px 1px", color=button.get_color("shadow"))

        if self.browser == 'Qt' and os.name != 'nt':
            button.add_style("top: 8px")
        else:
            button.add_style("top: 6px")

        # BOOTSTRAP
        color = self.kwargs.get("color")
        button.add_class('btn')
        if color:
            if color.startswith("#"):
                button.add_style("background", color)
            else:
                button.add_class('btn-%s' % color)
        else:
            button.add_class('btn-default')

        if size == 'b':
            button.add_class('btn-block')
        else:
            button.add_class('btn-sm')
        button.add_style("top: 0px")

        button.add_attr('spt_text_label', title)
        td.add_class("spt_action_button_hit")
        button.add_class("hand")

        return super(ActionButtonWdg, self).get_display()