[go: up one dir, main page]

Menu

[r5]: / ExerciseWindow.py  Maximize  Restore  History

Download this file

161 lines (143 with data), 5.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#Copyright 2009 - Ram Gupta
#This program is distributed under the terms of GNU General Public Licence(GPL)
#
# -*- coding: cp1252 -*-
import wx
from array import array
import random
import AnswerWindow
import MinFrame
class MyWindow(wx.ScrolledWindow):
def __init__(self,parent,ops,kind,count):
self.parent = parent
id = -1
wx.ScrolledWindow.__init__(self, parent,id)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
self.SetScrollbars(1, 1, 1000, 40*count, 0, 0)
self.SetBackgroundColour("WHITE")
self.scroller = wx.lib.dragscroller.DragScroller(self)
self.SetOps(ops)
parent.SetTitle(self.oper_str +" Worksheet")
self.SetOpsType(kind)
self.count = count
self.num_first = array('i')
self.num_sec = array('i')
self.answer = array('i')
self.d = {}
for i in range(self.count):
num1 = random.randint(self.start1,self.end1)
num2 = random.randint(self.start2,self.end2)
if num1 < num2:
temp = num1
num1 = num2
num2 = temp
if self.ops == 3:
if num2 ==0:
num2 =1
self.num_first.append(num1*num2)
else:
self.num_first.append(num1)
self.num_sec.append(num2)
for i in range(self.count/5):
for column in range(5):
text = wx.TextCtrl(self,10+5*i +column,"",wx.Point( column*200+10,100*i +150),wx.Size(40,20))
self.d[10+5*i +column] = text
self.answer = wx.Button(self, 12, "Get Answers", wx.Point(410 , 20*self.count +100))
self.close = wx.Button(self, 13, "Close", wx.Point(410 , 20*self.count +140))
wx.EVT_BUTTON(self, 12, self.OnAnswer)
wx.EVT_BUTTON(self,13,self.OnClose)
def OnAnswer(self,event):
frame2 = MinFrame.MinFrame(self,-1,(720,620))
frame2.mywindow = self
#for i in range
self.d[16].Disable()
panel1 = AnswerWindow.AnswerWindow(frame2,self.count)
frame2.Show(1)
def OnClose(self,event):
self.parent.Destroy()
def SetOps(self,ops):
self.ops = ops
if ops == 0:
self.oper = "+"
self.oper_str = "Addition"
if ops == 1:
self.oper = "-"
self.oper_str = "Subtraction"
if ops == 2:
self.oper = "x"
self.oper_str = "Multiplication"
if ops == 3:
#self.oper = "/"
self.oper = u"÷"
self.oper_str = "Division"
def SetOpsType(self,kind):
if kind == 0:
self.start1 = 0
self.start2 = 0
self.end1 = 12
self.end2 = 12
elif kind == 1:
self.start1 = 10
self.start2 = 0
self.end1 = 99
self.end2 = 9
elif kind == 2:
self.start1 = 10
self.start2 = 10
self.end1 = 99
self.end2 = 99
elif kind == 3:
self.start2 = 0
self.start1 = 100
self.end1 = 999
self.end2 = 9
elif kind == 4:
self.start1 = 100
self.start2 = 10
self.end1 = 999
self.end2 = 99
else:
self.start1 = 100
self.start2 = 100
self.end1 = 999
self.end2 = 999
def OnPaint(self,event):
dc = wx.PaintDC(self)
self.DoPrepareDC(dc)
pen = wx.Pen(wx.BLACK, 1)
dc.SetPen(pen)
dc.Clear()
te = dc.GetTextExtent(self.oper_str+" WorkSheet")
w,h = self.GetSize()
dc.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
dc.DrawText(self.oper_str+" WorkSheet",(w - te[0])/2,20)
dc.DrawLine(20, 40, w -20, 40)
for i in range(self.count/5):
for column in range(5):
index = i*5 + column
num1 = self.num_first[index]
num2 = self.num_sec[index]
len_diff = len(str(num1)) -len(str(num2))
if len_diff > 0:
sec = " "*len_diff + str(num2)
first =str(num1)
space = len_diff
else:
first = " "+str(num1)
sec = str(num2)
space =2
pen = wx.Pen(wx.BLACK, 1)
dc.SetPen(pen)
dc.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
dc.DrawText(str(i*5 + column +1)+".",( column*200 +10),100*i +80)
dc.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL))
dc.DrawText(first,(30 + column*200) ,100*i +100)
dc.DrawText(self.oper+sec,(column*200 +30-1-space),100*i +120)
dc.SetTextForeground(wx.BLACK)
dc.DrawLine(10+column*200,100*i +140,50 + column*200,100*i +140)
def OnRightDown(self, event):
self.scroller.Start(event.GetPosition())
def OnRightUp(self, event):
self.scroller.Stop()