PageRenderTime 105ms CodeModel.GetById 100ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/gridtest/GridTest.py

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