コード例 #1
0
    def drawGrid(self, month, year):
        # draw the grid in the middle of the calendar

        daysInMonth = self.getDaysInMonth(month, year)
        secs = time.mktime((year, month, 1, 0, 0, 0, 0, 0,
                            -1))  # first day of the month & year
        struct = time.localtime(secs)
        startPos = (
            struct.tm_wday +
            1) % 7  # 0 - sunday for our needs instead 0 = monday in tm_wday
        slots = startPos + daysInMonth - 1
        rows = int(slots / 7) + 1
        grid = Grid(rows + 1, 7)  # extra row for the days in the week
        grid.setWidth("100%")
        grid.addTableListener(self)
        self.middlePanel.setWidget(grid)
        #
        # put some content into the grid cells
        #
        for i in range(7):
            grid.setText(0, i, self.getDaysOfWeek()[i])
            grid.cellFormatter.addStyleName(0, i, "calendar-header")
        #
        # draw cells which are empty first
        #
        day = 0
        pos = 0
        while pos < startPos:
            grid.setText(1, pos, " ")
            grid.cellFormatter.setStyleAttr(1, pos, "background", "#f3f3f3")
            grid.cellFormatter.addStyleName(1, pos, "calendar-blank-cell")
            pos += 1
        # now for days of the month
        row = 1
        day = 1
        col = startPos
        while day <= daysInMonth:
            if pos % 7 == 0 and day <> 1:
                row += 1
            col = pos % 7
            grid.setText(row, col, str(day))
            if self.currentYear == self.todayYear and self.currentMonth == self.todayMonth and day == self.todayDay:
                grid.cellFormatter.addStyleName(row, col,
                                                "calendar-cell-today")
            else:
                grid.cellFormatter.addStyleName(row, col, "calendar-day-cell")
            day += 1
            pos += 1
        #
        # now blank lines on the last row
        #
        col += 1
        while col < 7:
            grid.setText(row, col, " ")
            grid.cellFormatter.setStyleAttr(row, col, "background", "#f3f3f3")
            grid.cellFormatter.addStyleName(row, col, "calendar-blank-cell")
            col += 1

        return grid
コード例 #2
0
ファイル: Calendar.py プロジェクト: FreakTheMighty/pyjamas
    def drawGrid(self,month,year):
        # draw the grid in the middle of the calendar

        daysInMonth = self.getDaysInMonth(month, year)
        secs = time.mktime( (year,month,1,0,0,0,0,0,-1) ) # first day of the month & year
        struct = time.localtime(secs)
        startPos = (struct.tm_wday + 1 ) % 7 # 0 - sunday for our needs instead 0 = monday in tm_wday
        slots = startPos + daysInMonth - 1
        rows = int(slots/7) + 1
        grid = Grid(rows+1, 7) # extra row for the days in the week
        grid.setWidth("100%")
        grid.addTableListener(self)
        self.middlePanel.setWidget(grid)
        #
        # put some content into the grid cells
        #
        for i in range(7):
            grid.setText(0, i, self.daysOfWeek[i] )
            grid.cellFormatter.addStyleName(0,i,"calendar-header")
        #
        # draw cells which are empty first
        #
        day =0
        pos = 0
        while pos < startPos:
            grid.setText(1, pos , " ")
            grid.cellFormatter.setStyleAttr(1,pos,"background","#f3f3f3")
            grid.cellFormatter.addStyleName(1,pos,"calendar-blank-cell")
            pos += 1
        # now for days of the month
        row = 1
        day = 1
        col = startPos
        while day <= daysInMonth:
            if pos % 7 == 0 and day <> 1:
                row += 1
            col = pos % 7
            grid.setText(row,col, str(day) )
            if self.currentYear == self.todayYear and self.currentMonth == self.todayMonth and day == self.todayDay:
                grid.cellFormatter.addStyleName(row,col,"calendar-cell-today")
            else:
                grid.cellFormatter.addStyleName(row,col,"calendar-day-cell")
            day += 1
            pos += 1
        #
        # now blank lines on the last row
        #
        col += 1
        while col < 7:
            grid.setText(row,col," ")
            grid.cellFormatter.setStyleAttr(row,col,"background","#f3f3f3")
            grid.cellFormatter.addStyleName(row,col,"calendar-blank-cell")
            col += 1

        return grid
コード例 #3
0
ファイル: components.py プロジェクト: Afey/pyjs
class UserList(AbsolutePanel):

    userGrid = None
    newBtn = None
    deleteBtn = None

    users = None
    selectedUser = None

    def __init__(self,parent):
        AbsolutePanel.__init__(self)
        self.userGrid = Grid()
        self.userGrid.createGrid(6, 6)
        self.userGrid.addTableListener(self)

        self.userGrid.setBorderWidth(2)
        self.userGrid.setCellPadding(4)
        self.userGrid.setCellSpacing(1)
        self.userGrid.setColLabelValue(0,"Username")
        self.userGrid.setColLabelValue(1,"First Name")
        self.userGrid.setColLabelValue(2,"Last Name")
        self.userGrid.setColLabelValue(3,"Email")
        self.userGrid.setColLabelValue(4,"Department")
        self.userGrid.setColLabelValue(5,"Password")

        self.newBtn = Button("New")
        self.deleteBtn = Button("Delete")
        self.deleteBtn.setEnabled(False)

        self.add(self.userGrid)
        self.add(self.newBtn)
        self.add(self.deleteBtn)

        return

    def updateUserGrid(self, users):
        self.userGrid.clearGrid()
        self.users = users
        for i in range(len(users)):
            self.userGrid.setCellValue(i, 0, users[i].username)
            self.userGrid.setCellValue(i, 1, users[i].fname)
            self.userGrid.setCellValue(i, 2, users[i].lname)
            self.userGrid.setCellValue(i, 3, users[i].email)
            self.userGrid.setCellValue(i, 4, users[i].department)
            self.userGrid.setCellValue(i, 5, users[i].password)

    def onCellClicked(self, sender, row, col):
        try:
            if row > 0 and row <= len(self.users):
                self.selectedUser = self.users[row-1]
                self.userGrid.selectRow(row)
                self.deleteBtn.setEnabled(True)
            else:
                self.userGrid.selectRow(-1)
                self.selectedUser = None
                self.deleteBtn.setEnabled(False)
        except IndexError:
            pass

    def deSelect(self):
        self.userGrid.selectRow(-1)
コード例 #4
0
ファイル: components.py プロジェクト: wkornewald/pyjs
class UserList(AbsolutePanel):

    userGrid = None
    newBtn = None
    deleteBtn = None

    users = None
    selectedUser = None

    def __init__(self, parent):
        AbsolutePanel.__init__(self)
        self.userGrid = Grid()
        self.userGrid.createGrid(6, 6)
        self.userGrid.addTableListener(self)

        self.userGrid.setBorderWidth(2)
        self.userGrid.setCellPadding(4)
        self.userGrid.setCellSpacing(1)
        self.userGrid.setColLabelValue(0, "Username")
        self.userGrid.setColLabelValue(1, "First Name")
        self.userGrid.setColLabelValue(2, "Last Name")
        self.userGrid.setColLabelValue(3, "Email")
        self.userGrid.setColLabelValue(4, "Department")
        self.userGrid.setColLabelValue(5, "Password")

        self.newBtn = Button("New")
        self.deleteBtn = Button("Delete")
        self.deleteBtn.setEnabled(False)

        self.add(self.userGrid)
        self.add(self.newBtn)
        self.add(self.deleteBtn)

        return

    def updateUserGrid(self, users):
        self.userGrid.clearGrid()
        self.users = users
        for i in range(len(users)):
            self.userGrid.setCellValue(i, 0, users[i].username)
            self.userGrid.setCellValue(i, 1, users[i].fname)
            self.userGrid.setCellValue(i, 2, users[i].lname)
            self.userGrid.setCellValue(i, 3, users[i].email)
            self.userGrid.setCellValue(i, 4, users[i].department)
            self.userGrid.setCellValue(i, 5, users[i].password)

    def onCellClicked(self, sender, row, col):
        try:
            if row > 0 and row <= len(self.users):
                self.selectedUser = self.users[row - 1]
                self.userGrid.selectRow(row)
                self.deleteBtn.setEnabled(True)
            else:
                self.userGrid.selectRow(-1)
                self.selectedUser = None
                self.deleteBtn.setEnabled(False)
        except IndexError:
            pass

    def deSelect(self):
        self.userGrid.selectRow(-1)