コード例 #1
0
ファイル: Tables.py プロジェクト: pombredanne/pyjamas-desktop
    def __init__(self):
        Sink.__init__(self)
        inner = Grid(10, 5)
        outer = FlexTable()

        outer.setWidget(0, 0, Image(self.baseURL() + "rembrandt/LaMarcheNocturne.jpg"))
        outer.getFlexCellFormatter().setColSpan(0, 0, 2)
        outer.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER)

        outer.setHTML(1, 0, "Look to the right...<br>That's a nested table component ->")
        outer.setWidget(1, 1, inner)
        outer.getCellFormatter().setColSpan(1, 1, 2)
        
        for i in range(10):
            for j in range(5):
                inner.setText(i, j, "%d" % i + ",%d" % j)

        inner.setWidth("100%")
        outer.setWidth("100%")

        inner.setBorderWidth(1)
        outer.setBorderWidth(1)

        self.initWidget(outer)
コード例 #2
0
def section(title, classname, contents):
    """Format a section with a heading."""
    width=6
    prelude=''
    marginalia=None
    gap='&nbsp;'
    if marginalia is None:
        marginalia = '<tt>'
        for i in range(width):
            marginalia += '&nbsp;' 
        marginalia += '</tt>'
    result = FlexTable()
    result.setCellPadding(2)
    result.setCellSpacing(0)
    result.prepareRow(2)
    rf = result.getRowFormatter()
    cf = result.getFlexCellFormatter()


    result.prepareCell(0, 1)
    cf.setColSpan(0, 0, 3)
    result.setHTML(0, 0, '&nbsp;<br><font face="helvetica, arial">%s</font>' % title)
    cf.setStyleName(0, 0, "title%s" % classname)
    rf.setStyleName(0, "margin%s" % classname)

    if prelude:
        result.prepareRow(3)
        result.prepareCell(1, 2)
        result.prepareCell(2, 2)
        cf.setRowSpan(1, 0, 2)
        cf.setColSpan(1, 1, 2)
        result.setHTML(1, 0, marginalia)
        result.setHTML(1, 1, prelude)
        result.setHTML(2, 0, gap)
        result.setWidget(2, 1, contents)
        cf.setWidth(2, 1, "100%")

        rf.setStyleName(1, "margin%s" % classname)
    else:
        result.prepareCell(1, 2)
        result.setHTML(1, 0, marginalia)
        result.setHTML(1, 1, gap)
        result.setWidget(1, 2, contents)
        cf.setWidth(1, 2, "100%")

        cf.setStyleName(1, 0, "margin%s" % classname)
    return result
コード例 #3
0
class MailList(Composite):

    VISIBLE_EMAIL_COUNT = 10

    def __init__(self, mailObject):
        Composite.__init__(self)
        self.countLabel = HTML()
        self.newerButton = HTML("<a href='javascript:;'>&lt; newer</a>", True)
        self.olderButton = HTML("<a href='javascript:;'>older &gt;</a>", True)
        self.startIndex = 0
        self.selectedRow = -1
        self.table = FlexTable()
        self.navBar = HorizontalPanel()
        self.mailObject = mailObject

        # Setup the table.
        self.table.setCellSpacing(0)
        self.table.setCellPadding(2)
        self.table.setWidth("100%")

        # Hook up events.
        self.table.addTableListener(self)
        self.newerButton.addClickListener(self)
        self.olderButton.addClickListener(self)

        # Create the 'navigation' bar at the upper-right.
        innerNavBar = HorizontalPanel()
        innerNavBar.setStyleName("mail-ListNavBar")
        innerNavBar.setSpacing(8)
        innerNavBar.add(self.newerButton)
        innerNavBar.add(self.countLabel)
        innerNavBar.add(self.olderButton)

        self.navBar.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
        self.navBar.add(innerNavBar)
        self.navBar.setWidth("100%")

        self.initWidget(self.table)
        self.setStyleName("mail-List")

        self.initTable()
        self.update()

    def onCellClicked(self, sender, row, cell):
        # Select the row that was clicked (-1 to account for header row).
        if (row > 0):
            self.selectRow(row - 1)

    def onClick(self, sender, event):
        print "click", sender
        if (sender == self.olderButton):
            # Move forward a page.
            self.startIndex = self.startIndex + MailList.VISIBLE_EMAIL_COUNT
            if (self.startIndex >= MailItems().getMailItemCount()):
                self.startIndex = self.startIndex - MailList.VISIBLE_EMAIL_COUNT
            else:
                self.styleRow(self.selectedRow, False)
                self.selectedRow = -1
                self.update()
    
        elif (sender == self.newerButton):
            # Move back a page.
            self.startIndex = self.startIndex - MailList.VISIBLE_EMAIL_COUNT
            if (self.startIndex < 0):
                self.startIndex = 0
            else:
                self.styleRow(self.selectedRow, False)
                self.selectedRow = -1
                self.update()

    def initTable(self):
        # Create the header row.
        self.table.setText(0, 0, "sender")
        self.table.setText(0, 1, "email")
        self.table.setText(0, 2, "subject")
        self.table.setWidget(0, 3, self.navBar)
        self.table.getRowFormatter().setStyleName(0, "mail-ListHeader")

        # Initialize the rest of the rows.
        i = 0
        while i < MailList.VISIBLE_EMAIL_COUNT:
            self.table.setText(i + 1, 0, "")
            self.table.setText(i + 1, 1, "")
            self.table.setText(i + 1, 2, "")
            self.table.getCellFormatter().setWordWrap(i + 1, 0, False)
            self.table.getCellFormatter().setWordWrap(i + 1, 1, False)
            self.table.getCellFormatter().setWordWrap(i + 1, 2, False)
            self.table.getFlexCellFormatter().setColSpan(i + 1, 2, 2)
            i = i + 1


    def selectRow(self, row):
        # When a row (other than the first one, which is used as a header) is
        # selected, display its associated MailItem.
        item = MailItems().getMailItem(self.startIndex + row)
        if (item == None):
            return
                    
        self.styleRow(self.selectedRow, False)
        self.styleRow(row, True)

        item.read = True
        self.selectedRow = row
        self.mailObject.get().displayItem(item)


    def styleRow(self, row, selected):
        if (row != -1):
            if (selected):
                self.table.getRowFormatter().addStyleName(row + 1, "mail-SelectedRow")
            else:
                self.table.getRowFormatter().removeStyleName(row + 1, "mail-SelectedRow")

    def update(self):
        # Update the older/newer buttons & label.
        count = MailItems().getMailItemCount()
        max = self.startIndex + MailList.VISIBLE_EMAIL_COUNT
        if (max > count):
            max = count

        self.newerButton.setVisible(self.startIndex != 0)
        self.olderButton.setVisible(self.startIndex + MailList.VISIBLE_EMAIL_COUNT < count)
        startIndexPlusOne = self.startIndex + 1
        self.countLabel.setText("" + "%d" % startIndexPlusOne + " - " + "%d" % max + " of " + "%d" % count)

        # Show the selected emails.
        i = 0
        while (i < MailList.VISIBLE_EMAIL_COUNT):
            # Don't read past the end.
            if (self.startIndex + i >= MailItems().getMailItemCount()):
                break

            item = MailItems().getMailItem(self.startIndex + i)

            # Add a row to the table, then set each of its columns to the
            # email's sender and subject values.

            self.table.setText(i + 1, 0, item.sender)
            self.table.setText(i + 1, 1, item.email)
            self.table.setText(i + 1, 2, item.subject)

            i = i + 1

        # Clear any remaining slots.
        while (i < MailList.VISIBLE_EMAIL_COUNT):
            self.table.setHTML(i + 1, 0, "&nbsp;")
            self.table.setHTML(i + 1, 1, "&nbsp;")
            self.table.setHTML(i + 1, 2, "&nbsp;")
            i = i + 1

        # Select the first row if none is selected.
        if (self.selectedRow == -1):
            self.selectRow(0)
コード例 #4
0
    def section(self, title, fgcol, bgcol, contents, width=6,
                prelude='', marginalia=None, gap='&nbsp;'):
        """Format a section with a heading."""
        if marginalia is None:
            marginalia = '<tt>' + '&nbsp;' * width + '</tt>'
        result = FlexTable()
        result.setCellPadding(2)
        result.setCellSpacing(0)
        result.prepareRow(2)
        rf = result.getRowFormatter()
        cf = result.getCellFormatter()


        result.prepareCell(0, 1)
        result.setHTML(0, 0, """&nbsp;<br>
<font color="%s" face="helvetica, arial">%s</font>
    """ % (fgcol, title))
        cf.setColSpan(0, 0, 3)

        row = rf.getElement(0)
        DOM.setStyleAttribute(row, "background-color", bgcol) # TODO: add this to api

        if prelude:
            result.prepareRow(3)
            #result.prepareCell(1, 2)
            #result.prepareCell(2, 2)
            result.setHTML(1, 0, marginalia)
            cf.setRowSpan(1, 0, 2)
            result.setHTML(1, 1, prelude)
            cf.setColSpan(1, 1, 2)
            result.setHTML(2, 0, gap)

            #result.prepareCell(2, 1)
            result.setWidget(2, 1, contents)
            cf.setWidth(2, 1, "100%")

            row = rf.getElement(1)
            DOM.setStyleAttribute(row, "background-color", bgcol) # TODO: add this to api
        else:
            #result.prepareCell(1, 3)
            result.setHTML(1, 0, marginalia)
            result.setHTML(1, 1, gap)
            result.setWidget(1, 3, contents)
            cf.setWidth(1, 3, "100%")

            cell = cf.getElement(1, 0)
            DOM.setStyleAttribute(cell, "background-color", bgcol) # TODO: add this to api
        return result