#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()