PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/dynamictable/SchoolCalendarWidget.py

http://pyjamas.googlecode.com/
Python | 84 lines | 63 code | 21 blank | 0 comment | 5 complexity | 7854799a385ef9bc518c8f9164352acd MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. from ui import Composite
  2. from DeferredCommand import DeferredCommand
  3. from SchoolCalendarService import SchoolCalendarService
  4. from DynaTableWidget import DynaTableWidget
  5. from Person import Person
  6. from Student import Student
  7. from Professor import Professor
  8. class CalendarProvider:
  9. def __init__(self, owner):
  10. self.owner = owner
  11. self.calService = SchoolCalendarService()
  12. self.lastStartRow = -1
  13. self.lastMaxRows = -1
  14. self.lastPeople = []
  15. def updateRowData(self, startRow, maxRows, acceptor):
  16. if startRow == self.lastStartRow:
  17. if maxRows == self.lastMaxRows:
  18. self.pushResults(acceptor, startRow, self.lastPeople)
  19. return
  20. self.calService.getPeople(startRow, maxRows, CalendarProviderHandler(self, acceptor, startRow, maxRows))
  21. def pushResults(self, acceptor, startRow, people):
  22. rows = []
  23. for person in people:
  24. rows.append([person.getName(), person.getDescription(), person.getSchedule(self.owner.daysFilter)])
  25. acceptor.accept(startRow, rows)
  26. class CalendarProviderHandler:
  27. def __init__(self, owner, acceptor, startRow, maxRows):
  28. self.owner = owner
  29. self.acceptor = acceptor
  30. self.startRow = startRow
  31. self.maxRows = maxRows
  32. def onRemoteResponse(self, response, requestInfo):
  33. people = response
  34. self.owner.lastStartRow = self.startRow
  35. self.owner.lastMaxRows = self.maxRows
  36. self.owner.lastPeople = people
  37. self.owner.pushResults(self.acceptor, self.startRow, people)
  38. def onRemoteError(self, code, message, request):
  39. self.acceptor.failed(message)
  40. class SchoolCalendarWidget(Composite):
  41. def __init__(self, visibleRows):
  42. Composite.__init__(self)
  43. columns = ["Name", "Description", "Schedule"]
  44. styles = ["name", "desc", "sched"]
  45. self.calProvider = CalendarProvider(self)
  46. self.daysFilter = [True, True, True, True, True, True, True]
  47. self.pendingRefresh = False
  48. self.dynaTable = DynaTableWidget(self.calProvider, columns, styles, visibleRows)
  49. self.initWidget(self.dynaTable)
  50. def getDayIncluded(self, day):
  51. return self.daysFilter[day]
  52. def onLoad(self):
  53. self.dynaTable.refresh()
  54. def setDayIncluded(self, day, included):
  55. if (self.daysFilter[day] == included):
  56. return
  57. self.daysFilter[day] = included
  58. if not self.pendingRefresh:
  59. self.pendingRefresh = True
  60. DeferredCommand().add(self)
  61. def execute(self):
  62. self.pendingRefresh = False
  63. self.dynaTable.refresh()