Пример #1
0
    def __init__(self):
        super(TableFooterExample, self).__init__()

        # Create our data source
        dataSource = ExampleUtil.getOrderContainer()

        # Calculate total sum
        totalSum = 0.0
        for i in range(len(dataSource)):
            item = dataSource.getItem(dataSource.getIdByIndex(i))
            value = item.getItemProperty(
                ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID).getValue()

            match = re.search(self.CURRENCY_PATTERN, str(value))
            if match is not None:
                amount = match.groups()[1]
                totalSum += float(amount)

        # Create a table to show the data in
        table = Table('Order table', dataSource)
        table.setPageLength(6)
        table.setWidth('100%')

        # Set alignments
        table.setColumnAlignments([
            Table.ALIGN_LEFT, Table.ALIGN_RIGHT, Table.ALIGN_RIGHT,
            Table.ALIGN_RIGHT
        ])

        # Set column widths
        table.setColumnExpandRatio(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID,
                                   1)

        # Enable footer
        table.setFooterVisible(True)

        # Add some total sum and description to footer
        table.setColumnFooter(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID,
                              'Total Price')
        l = defaultLocale()
        fc = format_currency(totalSum, currency='USD',
                             locale=l).encode('utf-8')
        table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID, fc)

        self.addComponent(table)
Пример #2
0
    def __init__(self):
        super(TableClickListenersExample, self).__init__()

        # Create our data source
        dataSource = ExampleUtil.getOrderContainer()

        # Calculate total sum
        totalSum = 0.0
        for i in range(len(dataSource)):
            item = dataSource.getItem(dataSource.getIdByIndex(i))
            value = item.getItemProperty(
                    ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID).getValue()

            #amount = NumberFormat.getCurrencyInstance().parse(str(value))
            amount = re.search(u'([\u00A3\u0024\u20AC])(\d+(?:\.\d{2})?)',
                    str(value)).groups()[1]

            totalSum += float(amount)

        # Create table
        table = Table('', ExampleUtil.getOrderContainer())
        table.setColumnExpandRatio(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 1)
        table.setSortDisabled(True)
        table.setWidth('100%')
        table.setPageLength(6)
        table.setFooterVisible(True)
        table.setImmediate(True)

        # Add some total sum and description to footer
        table.setColumnFooter(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID,
                'Total Price')
        l = defaultLocale()
        fc = format_currency(totalSum, currency='USD', locale=l).encode('utf-8')
        table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID, fc)

        # Add a header click handler
        table.addListener(HeaderListener(self), IHeaderClickListener)

        # Add a footer click handler
        table.addListener(FooterListener(self), IFooterClickListener)
        self.addComponent(table)
Пример #3
0
    def __init__(self):
        super(TableFooterExample, self).__init__()

        # Create our data source
        dataSource = ExampleUtil.getOrderContainer()

        # Calculate total sum
        totalSum = 0.0
        for i in range(len(dataSource)):
            item = dataSource.getItem(dataSource.getIdByIndex(i))
            value = item.getItemProperty(
                    ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID).getValue()

            match = re.search(self.CURRENCY_PATTERN, str(value))
            if match is not None:
                amount = match.groups()[1]
                totalSum += float(amount)

        # Create a table to show the data in
        table = Table('Order table', dataSource)
        table.setPageLength(6)
        table.setWidth('100%')

        # Set alignments
        table.setColumnAlignments([Table.ALIGN_LEFT, Table.ALIGN_RIGHT,
                Table.ALIGN_RIGHT, Table.ALIGN_RIGHT])

        # Set column widths
        table.setColumnExpandRatio(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 1)

        # Enable footer
        table.setFooterVisible(True)

        # Add some total sum and description to footer
        table.setColumnFooter(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID,
                'Total Price')
        l = defaultLocale()
        fc = format_currency(totalSum, currency='USD', locale=l).encode('utf-8')
        table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID, fc)

        self.addComponent(table)
    def __init__(self):
        super(TableClickListenersExample, self).__init__()

        # Create our data source
        dataSource = ExampleUtil.getOrderContainer()

        # Calculate total sum
        totalSum = 0.0
        for i in range(len(dataSource)):
            item = dataSource.getItem(dataSource.getIdByIndex(i))
            value = item.getItemProperty(
                    ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID).getValue()

            match = re.search(self.CURRENCY_PATTERN, str(value))
            if match is not None:
                amount = match.groups()[1]
                totalSum += float(amount)

        # Create table
        table = Table('', ExampleUtil.getOrderContainer())
        table.setColumnExpandRatio(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 1)
        table.setSortDisabled(True)
        table.setWidth('100%')
        table.setPageLength(6)
        table.setFooterVisible(True)
        table.setImmediate(True)

        # Add some total sum and description to footer
        table.setColumnFooter(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID,
                'Total Price')
        l = defaultLocale()
        fc = format_currency(totalSum, currency='USD', locale=l).encode('utf-8')
        table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID, fc)

        # Add a header click handler
        table.addListener(HeaderListener(self), IHeaderClickListener)

        # Add a footer click handler
        table.addListener(FooterListener(self), IFooterClickListener)
        self.addComponent(table)
Пример #5
0
    def __init__(self):
        super(TableFooterExample, self).__init__()

        # Create our data source
        dataSource = ExampleUtil.getOrderContainer()

        # Calculate total sum
        totalSum = 0.0
        for i in range(len(dataSource)):
            item = dataSource.getItem(dataSource.getIdByIndex(i))
            value = item.getItemProperty(
                    ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID).getValue()

            amount = re.search(u'([\u00A3\u0024\u20AC])(\d+(?:\.\d{2})?)',
                    str(value)).groups()[1]
            totalSum += float(amount)

        # Create a table to show the data in
        table = Table('Order table', dataSource)
        table.setPageLength(6)
        table.setWidth('100%')

        # Set alignments
        table.setColumnAlignments([Table.ALIGN_LEFT, Table.ALIGN_RIGHT,
                Table.ALIGN_RIGHT, Table.ALIGN_RIGHT])

        # Set column widths
        table.setColumnExpandRatio(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 1)

        # Enable footer
        table.setFooterVisible(True)

        # Add some total sum and description to footer
        table.setColumnFooter(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID,
                'Total Price')
        table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID,
                locale.currency(totalSum, grouping=True))  # FIXME: babel

        self.addComponent(table)
class TableMainFeaturesExample(VerticalLayout):

    def __init__(self):
        super(TableMainFeaturesExample, self).__init__()

        self._markedRows = set()

        self._table = Table('ISO-3166 Country Codes and flags')
        self.addComponent(self._table)

        # Label to indicate current selection
        selected = Label('No selection')
        self.addComponent(selected)

        # set a style name, so we can style rows and cells
        self._table.setStyleName('iso3166')

        # size
        self._table.setWidth('100%')
        self._table.setHeight('170px')

        # selectable
        self._table.setSelectable(True)
        self._table.setMultiSelect(True)
        # react at once when something is selected
        self._table.setImmediate(True)

        # connect data source
        self._table.setContainerDataSource(ExampleUtil.getISO3166Container())

        # turn on column reordering and collapsing
        self._table.setColumnReorderingAllowed(True)
        self._table.setColumnCollapsingAllowed(True)

        # set column headers
        self._table.setColumnHeaders(['Country', 'Code', 'Icon file'])

        # Icons for column headers
        self._table.setColumnIcon(ExampleUtil.iso3166_PROPERTY_FLAG,
                ThemeResource('../sampler/icons/action_save.gif'))
        self._table.setColumnIcon(ExampleUtil.iso3166_PROPERTY_NAME,
                ThemeResource('../sampler/icons/icon_get_world.gif'))
        self._table.setColumnIcon(ExampleUtil.iso3166_PROPERTY_SHORT,
                ThemeResource('../sampler/icons/page_code.gif'))

        # Column alignment
        self._table.setColumnAlignment(ExampleUtil.iso3166_PROPERTY_SHORT,
                Table.ALIGN_CENTER)

        # Column width
        self._table.setColumnExpandRatio(ExampleUtil.iso3166_PROPERTY_NAME, 1)
        self._table.setColumnWidth(ExampleUtil.iso3166_PROPERTY_SHORT, 70)

        # Collapse one column - the user can make it visible again
        self._table.setColumnCollapsed(ExampleUtil.iso3166_PROPERTY_FLAG, True)

        # show row header w/ icon
        self._table.setRowHeaderMode(Table.ROW_HEADER_MODE_ICON_ONLY)
        self._table.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG)

        # Actions (a.k.a context menu)
        self._table.addActionHandler( TableActionHandler(self) )

        # style generator
        self._table.setCellStyleGenerator( TableStyleGenerator(self) )

        # listen for valueChange, a.k.a 'select' and update the label
        self._table.addListener(TableChangeListener(self, selected),
                IValueChangeListener)
Пример #7
0
class TableMainFeaturesExample(VerticalLayout):
    def __init__(self):
        super(TableMainFeaturesExample, self).__init__()

        self._markedRows = set()

        self._table = Table('ISO-3166 Country Codes and flags')
        self.addComponent(self._table)

        # Label to indicate current selection
        selected = Label('No selection')
        self.addComponent(selected)

        # set a style name, so we can style rows and cells
        self._table.setStyleName('iso3166')

        # size
        self._table.setWidth('100%')
        self._table.setHeight('170px')

        # selectable
        self._table.setSelectable(True)
        self._table.setMultiSelect(True)
        # react at once when something is selected
        self._table.setImmediate(True)

        # connect data source
        self._table.setContainerDataSource(ExampleUtil.getISO3166Container())

        # turn on column reordering and collapsing
        self._table.setColumnReorderingAllowed(True)
        self._table.setColumnCollapsingAllowed(True)

        # set column headers
        self._table.setColumnHeaders(['Country', 'Code', 'Icon file'])

        # Icons for column headers
        self._table.setColumnIcon(
            ExampleUtil.iso3166_PROPERTY_FLAG,
            ThemeResource('../sampler/icons/action_save.gif'))
        self._table.setColumnIcon(
            ExampleUtil.iso3166_PROPERTY_NAME,
            ThemeResource('../sampler/icons/icon_get_world.gif'))
        self._table.setColumnIcon(
            ExampleUtil.iso3166_PROPERTY_SHORT,
            ThemeResource('../sampler/icons/page_code.gif'))

        # Column alignment
        self._table.setColumnAlignment(ExampleUtil.iso3166_PROPERTY_SHORT,
                                       Table.ALIGN_CENTER)

        # Column width
        self._table.setColumnExpandRatio(ExampleUtil.iso3166_PROPERTY_NAME, 1)
        self._table.setColumnWidth(ExampleUtil.iso3166_PROPERTY_SHORT, 70)

        # Collapse one column - the user can make it visible again
        self._table.setColumnCollapsed(ExampleUtil.iso3166_PROPERTY_FLAG, True)

        # show row header w/ icon
        self._table.setRowHeaderMode(Table.ROW_HEADER_MODE_ICON_ONLY)
        self._table.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG)

        # Actions (a.k.a context menu)
        self._table.addActionHandler(TableActionHandler(self))

        # style generator
        self._table.setCellStyleGenerator(TableStyleGenerator(self))

        # listen for valueChange, a.k.a 'select' and update the label
        self._table.addListener(TableChangeListener(self, selected),
                                IValueChangeListener)