PageRenderTime 41ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/gridtest/GridTest.py

http://pyjamas.googlecode.com/
Python | 59 lines | 43 code | 16 blank | 0 comment | 10 complexity | f299590a38ede4375b6105af54202322 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. from ui import Button, RootPanel
  2. from ui import Label, Grid, CellFormatter, RowFormatter
  3. from ui import HTMLTable, CheckBox
  4. import Window
  5. class GridTest:
  6. def onModuleLoad(self):
  7. self.page=0
  8. self.min_page=1
  9. self.max_page=10
  10. self.add=Button("Next >", self)
  11. self.sub=Button("< Prev", self)
  12. self.g=Grid()
  13. self.g.resize(5, 5)
  14. self.g.setHTML(0, 0, "<b>Grid Test</b>")
  15. self.g.setBorderWidth(2)
  16. self.g.setCellPadding(4)
  17. self.g.setCellSpacing(1)
  18. self.updatePageDisplay()
  19. RootPanel().add(self.sub)
  20. RootPanel().add(self.add)
  21. RootPanel().add(self.g)
  22. def onClick(self, sender):
  23. if sender==self.add:
  24. self.page+=1
  25. elif sender==self.sub:
  26. self.page-=1
  27. self.updatePageDisplay()
  28. def updatePageDisplay(self):
  29. if self.page<self.min_page: self.page=self.min_page
  30. elif self.page>self.max_page: self.page=self.max_page
  31. total_pages=(self.max_page-self.min_page) + 1
  32. self.g.setHTML(0, 4, "<b>page " + self.page + ' of ' + total_pages + "</b>")
  33. if self.page>=self.max_page:
  34. self.add.setEnabled(False)
  35. else:
  36. self.add.setEnabled(True)
  37. if self.page<=self.min_page:
  38. self.sub.setEnabled(False)
  39. else:
  40. self.sub.setEnabled(True)
  41. for y in range(1, 5):
  42. for x in range(5):
  43. self.g.setText(y, x, self.page + ' (' + y + ',' + x + ')')