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

        # Our main layout is a horizontal layout
        main = HorizontalLayout()
        main.setMargin(True)
        main.setSpacing(True)
        self.setContent(main)

        # Tree to the left
        tree = Tree()
        tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)
        self.addComponent(tree)

        # vertically divide the right area
        left = VerticalLayout()
        left.setSpacing(True)
        self.addComponent(left)

        # table on top
        tbl = Table()
        tbl.setWidth('500px')
        tbl.setContainerDataSource(ExampleUtil.getISO3166Container())
        tbl.setSortDisabled(True)
        tbl.setPageLength(7)
        left.addComponent(tbl)

        # Label on bottom
        text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML)
        text.setWidth('500px')  # some limit is good for text
        left.addComponent(text)
Пример #2
0
class DragDropTableTreeExample(HorizontalLayout):
    """Demonstrate moving data back and forth between a table and a tree using
    drag and drop.

    The tree and the table use different data structures: The category is a
    separate node in the tree and each item just has a String, whereas the
    table contains items with both a name and a category. Data conversions
    between these representations are made during drop processing.
    """
    def __init__(self):
        super(DragDropTableTreeExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._tree = Tree('Drag from tree to table')
        self._table = Table('Drag from table to tree')
        self._table.setWidth('100%')

        # Populate the tree and set up drag & drop
        self.initializeTree(SourceIs(self._table))

        # Populate the table and set up drag & drop
        self.initializeTable(SourceIs(self._tree))

        # Add components
        self.addComponent(self._tree)
        self.addComponent(self._table)

    def initializeTree(self, acceptCriterion):
        self._tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)

        # Expand all nodes
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        self._tree.setDragMode(TreeDragMode.NODE)

        self._tree.setDropHandler(TreeDropHandler(self))

    def initializeTable(self, acceptCriterion):
        tableContainer = BeanItemContainer(Hardware)
        tableContainer.addItem(Hardware('Dell OptiPlex 380', 'Desktops'))
        tableContainer.addItem(Hardware('Benq T900HD', 'Monitors'))
        tableContainer.addItem(Hardware('Lenovo ThinkPad T500', 'Laptops'))
        self._table.setContainerDataSource(tableContainer)
        self._table.setVisibleColumns(['category', 'name'])

        # Handle drop in table: move hardware item or subtree to the table
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler(TableDropHandler(self))

    @classmethod
    def getTreeNodeName(cls, source, sourceId):
        return source.getItem(sourceId).getItemProperty(
            ExampleUtil.hw_PROPERTY_NAME).getValue()
Пример #3
0
    def __init__(self):
        super(SimpleAddressBook, self).__init__()

        self._contactList = Table()
        self._contactEditor = Form()
        self._bottomLeftCorner = HorizontalLayout()
        self._contactRemovalButton = None
        self._addressBookData = self.createDummyData()
Пример #4
0
    def __init__(self):
        super(WebLayoutWindow, self).__init__()

        # Our main layout is a horizontal layout
        main = HorizontalLayout()
        main.setMargin(True)
        main.setSpacing(True)
        self.setContent(main)

        # Tree to the left
        tree = Tree()
        tree.setContainerDataSource( ExampleUtil.getHardwareContainer() )
        tree.setItemCaptionPropertyId( ExampleUtil.hw_PROPERTY_NAME )
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)
        self.addComponent(tree)

        # vertically divide the right area
        left = VerticalLayout()
        left.setSpacing(True)
        self.addComponent(left)

        # table on top
        tbl = Table()
        tbl.setWidth('500px')
        tbl.setContainerDataSource( ExampleUtil.getISO3166Container() )
        tbl.setSortDisabled(True)
        tbl.setPageLength(7)
        left.addComponent(tbl)

        # Label on bottom
        text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML)
        text.setWidth('500px')  # some limit is good for text
        left.addComponent(text)
Пример #5
0
    def __init__(self):
        super(TableStylingExample, self).__init__()

        self.setSpacing(True)

        self._table = Table()
        self._markedRows = dict()
        self._markedCells = dict()

        self.addComponent(self._table)

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

        # size
        self._table.setWidth('100%')
        self._table.setPageLength(7)

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

        # Generate the email-link from firstname & lastname
        self._table.addGeneratedColumn('Email', TableColumnGenerator(self))

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

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

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

        # toggle cell 'marked' styling when double-clicked
        self._table.addListener(TableClickListener(self), IItemClickListener)

        # Editing

        # we don't want to update container before pressing 'save':
        self._table.setWriteThrough(False)

        # edit button
        editButton = Button('Edit')
        self.addComponent(editButton)

        editButton.addListener(EditListener(self, editButton),
                button.IClickListener)

        self.setComponentAlignment(editButton, Alignment.TOP_RIGHT)
    def __init__(self):
        super(ApplicationLayoutWindow, self).__init__()

        # Our main layout is a horizontal layout
        main = HorizontalLayout()
        main.setSizeFull()
        self.setContent(main)

        # Tree to the left
        treePanel = Panel()  # for scrollbars
        treePanel.setStyleName(Reindeer.PANEL_LIGHT)
        treePanel.setHeight('100%')
        treePanel.setWidth(None)
        treePanel.getContent().setSizeUndefined()
        self.addComponent(treePanel)

        tree = Tree()
        tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)
        treePanel.addComponent(tree)

        # vertically divide the right area
        left = VerticalLayout()
        left.setSizeFull()
        self.addComponent(left)
        main.setExpandRatio(left, 1.0)  # use all available space

        # table on top
        tbl = Table()
        tbl.setWidth('100%')
        tbl.setContainerDataSource(ExampleUtil.getISO3166Container())
        tbl.setSortDisabled(True)
        tbl.setPageLength(7)
        left.addComponent(tbl)

        # Label on bottom
        textPanel = Panel()  # for scrollbars
        textPanel.setStyleName(Reindeer.PANEL_LIGHT)
        textPanel.setSizeFull()
        left.addComponent(textPanel)
        left.setExpandRatio(textPanel, 1.0)  # use all available space

        text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML)
        text.setWidth('500px')  # some limit is good for text
        textPanel.addComponent(text)
Пример #7
0
    def __init__(self):
        super(SimpleAddressBook, self).__init__()

        self._contactList = Table()
        self._contactEditor = Form()
        self._bottomLeftCorner = HorizontalLayout()
        self._contactRemovalButton = None
        self._addressBookData = self.createDummyData()
Пример #8
0
    def __init__(self):
        super(DragDropServerValidationExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._table = Table('Drag persons onto their relatives')
        self._table.setWidth('100%')

        self._container = ExampleUtil.getPersonContainer()
        self._table.setContainerDataSource(self._container)

        # Drag and drop support
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler(TableDropHandler(self))
        self.addComponent(self._table)
Пример #9
0
    def __init__(self):
        super(ApplicationLayoutWindow, self).__init__()

        # Our main layout is a horizontal layout
        main = HorizontalLayout()
        main.setSizeFull()
        self.setContent(main)

        # Tree to the left
        treePanel = Panel()  # for scrollbars
        treePanel.setStyleName(Reindeer.PANEL_LIGHT)
        treePanel.setHeight('100%')
        treePanel.setWidth(None)
        treePanel.getContent().setSizeUndefined()
        self.addComponent(treePanel)

        tree = Tree()
        tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)
        for idd in tree.rootItemIds():
            tree.expandItemsRecursively(idd)
        treePanel.addComponent(tree)

        # vertically divide the right area
        left = VerticalLayout()
        left.setSizeFull()
        self.addComponent(left)
        main.setExpandRatio(left, 1.0)  # use all available space

        # table on top
        tbl = Table()
        tbl.setWidth('100%')
        tbl.setContainerDataSource(ExampleUtil.getISO3166Container())
        tbl.setSortDisabled(True)
        tbl.setPageLength(7)
        left.addComponent(tbl)

        # Label on bottom
        textPanel = Panel()  # for scrollbars
        textPanel.setStyleName(Reindeer.PANEL_LIGHT)
        textPanel.setSizeFull()
        left.addComponent(textPanel)
        left.setExpandRatio(textPanel, 1.0)  # use all available space

        text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML)
        text.setWidth('500px')  # some limit is good for text
        textPanel.addComponent(text)
Пример #10
0
    def __init__(self):
        super(DragDropTableTreeExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._tree = Tree('Drag from tree to table')
        self._table = Table('Drag from table to tree')
        self._table.setWidth('100%')

        # Populate the tree and set up drag & drop
        self.initializeTree(SourceIs(self._table))

        # Populate the table and set up drag & drop
        self.initializeTable(SourceIs(self._tree))

        # Add components
        self.addComponent(self._tree)
        self.addComponent(self._table)
Пример #11
0
    def __init__(self):
        super(TableStylingExample, self).__init__()

        self.setSpacing(True)

        self._table = Table()
        self._markedRows = dict()
        self._markedCells = dict()

        self.addComponent(self._table)

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

        # size
        self._table.setWidth('100%')
        self._table.setPageLength(7)

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

        # Generate the email-link from firstname & lastname
        self._table.addGeneratedColumn('Email', TableColumnGenerator(self))

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

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

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

        # toggle cell 'marked' styling when double-clicked
        self._table.addListener(TableClickListener(self), IItemClickListener)

        # Editing

        # we don't want to update container before pressing 'save':
        self._table.setWriteThrough(False)

        # edit button
        editButton = Button('Edit')
        self.addComponent(editButton)

        editButton.addListener(EditListener(self, editButton),
                button.IClickListener)

        self.setComponentAlignment(editButton, Alignment.TOP_RIGHT)
class DragDropServerValidationExample(HorizontalLayout):

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

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._table = Table('Drag persons onto their relatives')
        self._table.setWidth('100%')

        self._container = ExampleUtil.getPersonContainer()
        self._table.setContainerDataSource(self._container)

        # Drag and drop support
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler( TableDropHandler(self) )
        self.addComponent(self._table)


    def getFullName(self, itemId):
        item = self._container.getItem(itemId)
        if item is None:
            # should not happen in this example
            return None
        fn = item.getItemProperty(
                ExampleUtil.PERSON_PROPERTY_FIRSTNAME).getValue()
        ln = item.getItemProperty(
                ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue()
        return fn + ' ' + ln


    def getLastName(self, itemId):
        item = self._container.getItem(itemId)

        if item is None:
            # should not happen in this example
            return None

        return item.getItemProperty(
                ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue()
    def __init__(self):
        super(DragDropServerValidationExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._table = Table('Drag persons onto their relatives')
        self._table.setWidth('100%')

        self._container = ExampleUtil.getPersonContainer()
        self._table.setContainerDataSource(self._container)

        # Drag and drop support
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler( TableDropHandler(self) )
        self.addComponent(self._table)
Пример #14
0
class DragDropServerValidationExample(HorizontalLayout):
    def __init__(self):
        super(DragDropServerValidationExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._table = Table('Drag persons onto their relatives')
        self._table.setWidth('100%')

        self._container = ExampleUtil.getPersonContainer()
        self._table.setContainerDataSource(self._container)

        # Drag and drop support
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler(TableDropHandler(self))
        self.addComponent(self._table)

    def getFullName(self, itemId):
        item = self._container.getItem(itemId)
        if item is None:
            # should not happen in this example
            return None
        fn = item.getItemProperty(
            ExampleUtil.PERSON_PROPERTY_FIRSTNAME).getValue()
        ln = item.getItemProperty(
            ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue()
        return fn + ' ' + ln

    def getLastName(self, itemId):
        item = self._container.getItem(itemId)

        if item is None:
            # should not happen in this example
            return None

        return item.getItemProperty(
            ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue()
Пример #15
0
    def __init__(self):
        super(DragDropTableTreeExample, self).__init__()

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._tree = Tree('Drag from tree to table')
        self._table = Table('Drag from table to tree')
        self._table.setWidth('100%')

        # Populate the tree and set up drag & drop
        self.initializeTree(SourceIs(self._table))

        # Populate the table and set up drag & drop
        self.initializeTable(SourceIs(self._tree))

        # Add components
        self.addComponent(self._tree)
        self.addComponent(self._table)
    def __init__(self):
        super(TextFieldTextChangeEventExample, self).__init__()

        nameContainer = ExampleUtil.getNameContainer()
        filterField = TextField('Filter')
        filterField.setTextChangeEventMode(TextChangeEventMode.LAZY)
        filterField.setTextChangeTimeout(200)

        filterField.addListener(FilterListener(nameContainer),
                ITextChangeListener)
        table = Table(None, nameContainer)
        table.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN)

        self.setSpacing(False)

        self.addComponent(filterField)
        self.addComponent(table)

        filterField.setWidth('150px')
        table.setWidth('150px')
Пример #17
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')
        l = defaultLocale()
        fc = format_currency(totalSum, currency='USD', locale=l).encode('utf-8')
        table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID, fc)

        self.addComponent(table)
Пример #18
0
class DragDropTableTreeExample(HorizontalLayout):
    """Demonstrate moving data back and forth between a table and a tree using
    drag and drop.

    The tree and the table use different data structures: The category is a
    separate node in the tree and each item just has a String, whereas the
    table contains items with both a name and a category. Data conversions
    between these representations are made during drop processing.
    """

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

        self.setSpacing(True)

        # First create the components to be able to refer to them as allowed
        # drag sources
        self._tree = Tree('Drag from tree to table')
        self._table = Table('Drag from table to tree')
        self._table.setWidth('100%')

        # Populate the tree and set up drag & drop
        self.initializeTree(SourceIs(self._table))

        # Populate the table and set up drag & drop
        self.initializeTable(SourceIs(self._tree))

        # Add components
        self.addComponent(self._tree)
        self.addComponent(self._table)


    def initializeTree(self, acceptCriterion):
        self._tree.setContainerDataSource(ExampleUtil.getHardwareContainer())
        self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME)

        # Expand all nodes
        for idd in self._tree.rootItemIds():
            self._tree.expandItemsRecursively(idd)

        self._tree.setDragMode(TreeDragMode.NODE)

        self._tree.setDropHandler( TreeDropHandler(self) )


    def initializeTable(self, acceptCriterion):
        tableContainer = BeanItemContainer(Hardware)
        tableContainer.addItem(Hardware('Dell OptiPlex 380', 'Desktops'))
        tableContainer.addItem(Hardware('Benq T900HD', 'Monitors'))
        tableContainer.addItem(Hardware('Lenovo ThinkPad T500', 'Laptops'))
        self._table.setContainerDataSource(tableContainer)
        self._table.setVisibleColumns(['category', 'name'])

        # Handle drop in table: move hardware item or subtree to the table
        self._table.setDragMode(TableDragMode.ROW)

        self._table.setDropHandler( TableDropHandler(self) )


    @classmethod
    def getTreeNodeName(cls, source, sourceId):
        return source.getItem(sourceId).getItemProperty(
                ExampleUtil.hw_PROPERTY_NAME).getValue()
    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')
        table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID,
                locale.currency(totalSum, grouping=True))

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

        # Add a footer click handler
        table.addListener(FooterListener(self), IFooterClickListener)
        self.addComponent(table)
Пример #20
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)
Пример #21
0
    def init(self):
        # We'll build the whole UI here, since the application will not
        # contain any logic. Otherwise it would be more practical to
        # separate parts of the UI into different classes and methods.

        # Main (browser) window, needed in all Muntjac applications
        rootLayout = VerticalLayout()
        root = Window('MuntjacTunes', rootLayout)

        # We'll attach the window to the browser view already here, so
        # we won't forget it later.
        self.setMainWindow(root)

        root.showNotification(('This is an example of how you can do layouts '
                'in Muntjac.<br/>It is not a working sound player.'),
                Notification.TYPE_HUMANIZED_MESSAGE)

        # Our root window contains one VerticalLayout, let's make
        # sure it's 100% sized, and remove unwanted margins
        rootLayout.setSizeFull()
        rootLayout.setMargin(False)

        # Top area, containing playback and volume controls, play status,
        # view modes and search
        top = HorizontalLayout()
        top.setWidth('100%')
        top.setMargin(False, True, False, True)  # Enable horizontal margins
        top.setSpacing(True)

        # Let's attach that one straight away too
        root.addComponent(top)

        # Create the placeholders for all the components in the top area
        playback = HorizontalLayout()
        volume = HorizontalLayout()
        status = HorizontalLayout()
        viewmodes = HorizontalLayout()
        search = ComboBox()

        # Add the components and align them properly
        top.addComponent(playback)
        top.addComponent(volume)
        top.addComponent(status)
        top.addComponent(viewmodes)
        top.addComponent(search)
        top.setComponentAlignment(playback, Alignment.MIDDLE_LEFT)
        top.setComponentAlignment(volume, Alignment.MIDDLE_LEFT)
        top.setComponentAlignment(status, Alignment.MIDDLE_CENTER)
        top.setComponentAlignment(viewmodes, Alignment.MIDDLE_LEFT)
        top.setComponentAlignment(search, Alignment.MIDDLE_LEFT)

        # We want our status area to expand if the user resizes the root
        # window, and we want it to accommodate as much space as there is
        # available. All other components in the top layout should stay fixed
        # sized, so we don't need to specify any expand ratios for them (they
        # will automatically revert to zero after the following line).
        top.setExpandRatio(status, 1.0)

        # Playback controls
        prev = NativeButton('Previous')
        play = NativeButton('Play/pause')
        nextt = NativeButton('Next')
        playback.addComponent(prev)
        playback.addComponent(play)
        playback.addComponent(nextt)
        # Set spacing between the buttons
        playback.setSpacing(True)

        # Volume controls
        mute = NativeButton('mute')
        vol = Slider()
        vol.setOrientation(Slider.ORIENTATION_HORIZONTAL)
        vol.setWidth('100px')
        maxx = NativeButton('max')
        volume.addComponent(mute)
        volume.addComponent(vol)
        volume.addComponent(maxx)

        # Status area
        status.setWidth('80%')
        status.setSpacing(True)

        toggleVisualization = NativeButton('Mode')
        timeFromStart = Label('0:00')

        # We'll need another layout to show currently playing track and
        # progress
        trackDetails = VerticalLayout()
        trackDetails.setWidth('100%')
        track = Label('Track Name')
        album = Label('Album Name - Artist')
        track.setWidth(None)
        album.setWidth(None)
        progress = Slider()
        progress.setOrientation(Slider.ORIENTATION_HORIZONTAL)
        progress.setWidth('100%')
        trackDetails.addComponent(track)
        trackDetails.addComponent(album)
        trackDetails.addComponent(progress)
        trackDetails.setComponentAlignment(track, Alignment.TOP_CENTER)
        trackDetails.setComponentAlignment(album, Alignment.TOP_CENTER)

        timeToEnd = Label('-4:46')
        jumpToTrack = NativeButton('Show')

        # Place all components to the status layout and align them properly
        status.addComponent(toggleVisualization)
        status.setComponentAlignment(toggleVisualization,
                Alignment.MIDDLE_LEFT)
        status.addComponent(timeFromStart)
        status.setComponentAlignment(timeFromStart, Alignment.BOTTOM_LEFT)
        status.addComponent(trackDetails)
        status.addComponent(timeToEnd)
        status.setComponentAlignment(timeToEnd, Alignment.BOTTOM_LEFT)
        status.addComponent(jumpToTrack)
        status.setComponentAlignment(jumpToTrack, Alignment.MIDDLE_LEFT)

        # Then remember to specify the expand ratio
        status.setExpandRatio(trackDetails, 1.0)

        # View mode buttons
        viewAsTable = NativeButton('Table')
        viewAsGrid = NativeButton('Grid')
        coverflow = NativeButton('Coverflow')
        viewmodes.addComponent(viewAsTable)
        viewmodes.addComponent(viewAsGrid)
        viewmodes.addComponent(coverflow)

        # That covers the top bar. Now let's move on to the sidebar
        # and track listing

        # We'll need one splitpanel to separate the sidebar and track listing
        bottom = HorizontalSplitPanel()
        root.addComponent(bottom)

        # The splitpanel is by default 100% x 100%, but we'll need to
        # adjust our main window layout to accommodate the height
        root.getContent().setExpandRatio(bottom, 1.0)

        # Give the sidebar less space than the listing
        bottom.setSplitPosition(200, ISizeable.UNITS_PIXELS)

        # Let's add some content to the sidebar
        # First, we need a layout to but all components in
        sidebar = VerticalLayout()
        sidebar.setSizeFull()
        bottom.setFirstComponent(sidebar)

        # Then we need some labels and buttons, and an album cover image The
        # labels and buttons go into their own vertical layout, since we want
        # the 'sidebar' layout to be expanding (cover image in the bottom).
        # VerticalLayout is by default 100% wide.
        selections = VerticalLayout()
        library = Label('Library')
        music = NativeButton('Music')
        music.setWidth('100%')

        store = Label('Store')
        muntjacTunesStore = NativeButton('MuntjacTunes Store')
        muntjacTunesStore.setWidth('100%')
        purchased = NativeButton('Purchased')
        purchased.setWidth('100%')

        playlists = Label('Playlists')
        genius = NativeButton('Geniues')
        genius.setWidth('100%')
        recent = NativeButton('Recently Added')
        recent.setWidth('100%')

        # Lets add them to the 'selections' layout
        selections.addComponent(library)
        selections.addComponent(music)
        selections.addComponent(store)
        selections.addComponent(muntjacTunesStore)
        selections.addComponent(purchased)
        selections.addComponent(playlists)
        selections.addComponent(genius)
        selections.addComponent(recent)

        # Then add the selections to the sidebar, and set it expanding
        sidebar.addComponent(selections)
        sidebar.setExpandRatio(selections, 1.0)

        # Then comes the cover artwork (we'll add the actual image in the
        # themeing section)
        cover = Embedded('Currently Playing')
        sidebar.addComponent(cover)

        # And lastly, we need the track listing table It should fill the whole
        # left side of our bottom layout
        listing = Table()
        listing.setSizeFull()
        listing.setSelectable(True)
        bottom.setSecondComponent(listing)

        # Add the table headers
        listing.addContainerProperty('Name', str, '')
        listing.addContainerProperty('Time', str, '0:00')
        listing.addContainerProperty('Artist', str, '')
        listing.addContainerProperty('Album', str, '')
        listing.addContainerProperty('Genre', str, '')
        listing.addContainerProperty('Rating', NativeSelect, NativeSelect())

        # Lets populate the table with random data
        tracks = ['Red Flag', 'Millstone', 'Not The Sun', 'Breath',
                'Here We Are', 'Deep Heaven', 'Her Voice Resides',
                'Natural Tan', 'End It All', 'Kings', 'Daylight Slaving',
                'Mad Man', 'Resolve', 'Teargas', 'African Air', 'Passing Bird']
        times = ['4:12', '6:03', '5:43', '4:32', '3:42', '4:45', '2:56',
                '9:34', '2:10', '3:44', '5:49', '6:30', '5:18', '7:42',
                '3:13', '2:52']
        artists = ['Billy Talent', 'Brand New', 'Breaking Benjamin',
                'Becoming The Archetype', 'Bullet For My Valentine',
                'Chasing Victory', 'Chimaira', 'Danko Jones', 'Deadlock',
                'Deftones', 'From Autumn To Ashes', 'Haste The Day',
                'Four Year Strong', 'In Flames', 'Kemopetrol', 'John Legend']
        albums = ['Once Again', 'The Caitiff Choir', 'The Devil And God',
                'Light Grenades', 'Dicthonomy', 'Back In Black', 'Dreamer',
                'Come Clarity', 'Year Zero', 'Frames', 'Fortress', 'Phobia',
                'The Poison', 'Manifesto', 'White Pony', 'The Big Dirty']
        genres = ['Rock', 'Metal', 'Hardcore', 'Indie', 'Pop', 'Alternative',
                'Blues', 'Jazz', 'Hip Hop', 'Electronica', 'Punk', 'Hard Rock',
                'Dance', 'R\'n\'B', 'Gospel', 'Country']

        for i in range(100):
            s = NativeSelect()
            s.addItem('1 star')
            s.addItem('2 stars')
            s.addItem('3 stars')
            s.addItem('4 stars')
            s.addItem('5 stars')
            s.select('%d stars' % (i % 5))
            index = i % 16
            listing.addItem([tracks[index], times[index],
                    artists[index], albums[index], genres[index], s], i)

        # We'll align the track time column to right as well
        listing.setColumnAlignment('Time', Table.ALIGN_RIGHT)

        # TODO: the footer

        # Now what's left to do? Themeing of course.
        self.setTheme('vaadintunes')

        # Let's give a namespace to our application window. This way, if
        # someone uses the same theme for different applications, we don't
        # get unwanted style conflicts.
        root.setStyleName('tTunes')

        top.setStyleName('top')
        top.setHeight('75px')  # Same as the background image height

        playback.setStyleName('playback')
        playback.setMargin(False, True, False, False)  # Add right-side margin
        play.setStyleName('play')
        nextt.setStyleName('next')
        prev.setStyleName('prev')
        playback.setComponentAlignment(prev, Alignment.MIDDLE_LEFT)
        playback.setComponentAlignment(nextt, Alignment.MIDDLE_LEFT)

        volume.setStyleName('volume')
        mute.setStyleName('mute')
        maxx.setStyleName('max')
        vol.setWidth('78px')

        status.setStyleName('status')
        status.setMargin(True)
        status.setHeight('46px')  # Height of the background image

        toggleVisualization.setStyleName('toggle-vis')
        jumpToTrack.setStyleName('jump')

        viewAsTable.setStyleName('viewmode-table')
        viewAsGrid.setStyleName('viewmode-grid')
        coverflow.setStyleName('viewmode-coverflow')

        sidebar.setStyleName('sidebar')

        music.setStyleName('selected')

        cover.setSource(ThemeResource('images/album-cover.jpg'))
        # Because this is an image, it will retain it's aspect ratio
        cover.setWidth('100%')
Пример #22
0
    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)
Пример #23
0
class SimpleAddressBook(Application):

    _fields = ['First Name', 'Last Name', 'Company', 'Mobile Phone',
            'Work Phone', 'Home Phone', 'Work Email', 'Home Email',
            'Street', 'Zip', 'City', 'State', 'Country']

    _visibleCols = ['Last Name', 'First Name', 'Company']

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

        self._contactList = Table()
        self._contactEditor = Form()
        self._bottomLeftCorner = HorizontalLayout()
        self._contactRemovalButton = None
        self._addressBookData = self.createDummyData()


    def init(self):
        self.initLayout()
        self.initContactAddRemoveButtons()
        self.initAddressList()
        self.initFilteringControls()


    def initLayout(self):
        splitPanel = HorizontalSplitPanel()
        self.setMainWindow(Window('Address Book', splitPanel))
        left = VerticalLayout()
        left.setSizeFull()
        left.addComponent(self._contactList)
        self._contactList.setSizeFull()
        left.setExpandRatio(self._contactList, 1)
        splitPanel.addComponent(left)
        splitPanel.addComponent(self._contactEditor)
        self._contactEditor.setSizeFull()
        self._contactEditor.getLayout().setMargin(True)
        self._contactEditor.setImmediate(True)
        self._bottomLeftCorner.setWidth('100%')
        left.addComponent(self._bottomLeftCorner)


    def initContactAddRemoveButtons(self):
        # New item button
        newItem = Button('+')
        newItem.addCallback(onNew, ClickEvent, self)
        self._bottomLeftCorner.addComponent(newItem)

        # Remove item button
        self._contactRemovalButton = Button('-')
        self._contactRemovalButton.addCallback(onRemove, ClickEvent, self)
        self._contactRemovalButton.setVisible(False)
        self._bottomLeftCorner.addComponent(self._contactRemovalButton)


    def initAddressList(self):
        self._contactList.setContainerDataSource(self._addressBookData)
        self._contactList.setVisibleColumns(self._visibleCols)
        self._contactList.setSelectable(True)
        self._contactList.setImmediate(True)
        self._contactList.addCallback(onContactChange, field.ValueChangeEvent,
                self)
        return self._visibleCols


    def initFilteringControls(self):
        for pn in self._visibleCols:
            sf = TextField()
            self._bottomLeftCorner.addComponent(sf)
            sf.setWidth("100%")
            sf.setValue(pn)
            sf.setImmediate(True)
            self._bottomLeftCorner.setExpandRatio(sf, 1)
            sf.addCallback(onFilterChange, property.ValueChangeEvent,
                    pn, sf, self)


    @classmethod
    def createDummyData(cls):
        fnames = ['Peter', 'Alice', 'Joshua', 'Mike', 'Olivia', 'Nina', 'Alex',
                'Rita', 'Dan', 'Umberto', 'Henrik', 'Rene', 'Lisa', 'Marge']
        lnames = ['Smith', 'Gordon', 'Simpson', 'Brown', 'Clavel', 'Simons',
                'Verne', 'Scott', 'Allison', 'Gates', 'Rowling', 'Barks',
                'Ross', 'Schneider', 'Tate']

        ic = IndexedContainer()

        for p in cls._fields:
            ic.addContainerProperty(p, str, '')

        for _ in range(1000):
            idd = ic.addItem()
            fname = fnames[int( len(fnames) * random() )]
            ic.getContainerProperty(idd, 'First Name').setValue(fname)
            lname = lnames[int( len(lnames) * random() )]
            ic.getContainerProperty(idd, 'Last Name').setValue(lname)

        return ic
Пример #24
0
    def create(self, parent):
        """ Create the underlying Table control.

        """
        self.widget = Table()
        parent.addComponent(self.widget)
Пример #25
0
class SimpleAddressBook(Application):

    _fields = [
        'First Name', 'Last Name', 'Company', 'Mobile Phone', 'Work Phone',
        'Home Phone', 'Work Email', 'Home Email', 'Street', 'Zip', 'City',
        'State', 'Country'
    ]

    _visibleCols = ['Last Name', 'First Name', 'Company']

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

        self._contactList = Table()
        self._contactEditor = Form()
        self._bottomLeftCorner = HorizontalLayout()
        self._contactRemovalButton = None
        self._addressBookData = self.createDummyData()

    def init(self):
        self.initLayout()
        self.initContactAddRemoveButtons()
        self.initAddressList()
        self.initFilteringControls()

    def initLayout(self):
        splitPanel = HorizontalSplitPanel()
        self.setMainWindow(Window('Address Book', splitPanel))
        left = VerticalLayout()
        left.setSizeFull()
        left.addComponent(self._contactList)
        self._contactList.setSizeFull()
        left.setExpandRatio(self._contactList, 1)
        splitPanel.addComponent(left)
        splitPanel.addComponent(self._contactEditor)
        self._contactEditor.setSizeFull()
        self._contactEditor.getLayout().setMargin(True)
        self._contactEditor.setImmediate(True)
        self._bottomLeftCorner.setWidth('100%')
        left.addComponent(self._bottomLeftCorner)

    def initContactAddRemoveButtons(self):
        # New item button
        newItem = Button('+')
        newItem.addCallback(onNew, ClickEvent, self)
        self._bottomLeftCorner.addComponent(newItem)

        # Remove item button
        self._contactRemovalButton = Button('-')
        self._contactRemovalButton.addCallback(onRemove, ClickEvent, self)
        self._contactRemovalButton.setVisible(False)
        self._bottomLeftCorner.addComponent(self._contactRemovalButton)

    def initAddressList(self):
        self._contactList.setContainerDataSource(self._addressBookData)
        self._contactList.setVisibleColumns(self._visibleCols)
        self._contactList.setSelectable(True)
        self._contactList.setImmediate(True)
        self._contactList.addCallback(onContactChange, field.ValueChangeEvent,
                                      self)
        return self._visibleCols

    def initFilteringControls(self):
        for pn in self._visibleCols:
            sf = TextField()
            self._bottomLeftCorner.addComponent(sf)
            sf.setWidth("100%")
            sf.setValue(pn)
            sf.setImmediate(True)
            self._bottomLeftCorner.setExpandRatio(sf, 1)
            sf.addCallback(onFilterChange, property.ValueChangeEvent, pn, sf,
                           self)

    @classmethod
    def createDummyData(cls):
        fnames = [
            'Peter', 'Alice', 'Joshua', 'Mike', 'Olivia', 'Nina', 'Alex',
            'Rita', 'Dan', 'Umberto', 'Henrik', 'Rene', 'Lisa', 'Marge'
        ]
        lnames = [
            'Smith', 'Gordon', 'Simpson', 'Brown', 'Clavel', 'Simons', 'Verne',
            'Scott', 'Allison', 'Gates', 'Rowling', 'Barks', 'Ross',
            'Schneider', 'Tate'
        ]

        ic = IndexedContainer()

        for p in cls._fields:
            ic.addContainerProperty(p, str, '')

        for _ in range(1000):
            idd = ic.addItem()
            fname = fnames[int(len(fnames) * random())]
            ic.getContainerProperty(idd, 'First Name').setValue(fname)
            lname = lnames[int(len(lnames) * random())]
            ic.getContainerProperty(idd, 'Last Name').setValue(lname)

        return ic
    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)
Пример #27
0
    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)
Пример #28
0
class MuntjacTableView(MuntjacControl, AbstractTkTableView):
    """ A Muntjac implementation of TableView.

    See Also
    --------
    TableView

    """
    #: The underlying model.
    model_wrapper = None

    #--------------------------------------------------------------------------
    # Setup methods
    #--------------------------------------------------------------------------
    def create(self, parent):
        """ Create the underlying Table control.

        """
        self.widget = Table()
        parent.addComponent(self.widget)

    def initialize(self):
        """ Initialize the widget with the attributes of this instance.

        """
        super(MuntjacTableView, self).initialize()
        shell = self.shell_obj
        self.set_table_model(shell.item_model)
        self.set_vertical_header_vis(shell.vertical_header_visible)
        self.set_horizontal_header_vis(shell.horizontal_header_visible)

    #--------------------------------------------------------------------------
    # Implementation
    #--------------------------------------------------------------------------
    def shell_item_model_changed(self, item_model):
        """ The change handler for the 'item_model' attribute.

        """
        self.set_table_model(item_model)

    def shell_vertical_header_visible_changed(self, visible):
        self.set_vertical_header_vis(visible)

    def shell_horizontal_header_visible_changed(self, visible):
        self.set_horizontal_header_vis(visible)

    def set_table_model(self, model):
        """ Set the table view's model.

        """
        model_wrapper = AbstractItemModelWrapper(model)
        self.widget.setContainerDataSource(model_wrapper)
        self.model_wrapper = model_wrapper

    def set_vertical_header_vis(self, visible):
        if visible:
            self.widget.setRowHeaderMode(Table.ROW_HEADER_MODE_EXPLICIT)
        else:
            self.widget.setRowHeaderMode(Table.ROW_HEADER_MODE_HIDDEN)

    def set_horizontal_header_vis(self, visible):
        if visible:
            self.widget.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_EXPLICIT)
        else:
            self.widget.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN)