calendarvobtest.py from gzz at Krugle
Show calendarvobtest.py syntax highlighted
#
# Copyright (c) 2003, Matti Katila
#
# This file is part of Gzz.
#
# Gzz is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Gzz is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
# Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with Gzz; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#
import gzz
from gzz.view import View
from test.tools import tools
style_date = GraphicsAPI.getInstance().getTextStyle("serif", 0, 14)
style_n = GraphicsAPI.getInstance().getTextStyle("serif", 0, 14)
class ViewScene:
def __init__(self):
self.scale = 0.10;
self.ty = -3000;
self.tx = 50;
self.rotate = 0;
def scene(self, vs):
size = vs.getSize()
w = .5 * size.width
h = .5 * size.height
self.bgcolor = (0.6, 0.7, 0.8)
putnoc(vs, background(self.bgcolor))
angle = 0
if self.rotate:
angle = 0.81 * self.rotate
print "ROTATE: ", angle
# Coordinate systems:
cs_home = vs.coords.affineCoordsys(0,0,
w/2 + self.tx*self.scale,
h/2 + self.ty*self.scale,
w*self.scale, 0,0, h*self.scale)
vs.matcher.add(cs_home, "koti")
#home = vs.matcher.add(cs_home, "cs_home")
cs_rot = vs.coords.rotate(cs_home, angle)
vs.matcher.add(cs_rot, "cs_koti_rot")
cs_text = vs.coords.affineCoordsys(0, 0, 0, 0,w*self.scale, 0,0, h*self.scale)
vs.matcher.add(cs_text, "cs_text")
# cs_text_match = vs.matcher.add(cs_text, "cs_text"+str(i))
cs_text_rot = vs.coords.rotate(cs_text, angle)
vs.matcher.add(cs_text_rot, "cs_textrot")
# these don't efect
gzz.vob.vobs.CalendarVob.setStatics(style_date, style_n, 0.04)
# week number width, weekday height, month name height
gzz.vob.vobs.CalendarVob.setBounds(0.37, 0.5, 1.0)
# scales: date, weeknum, weekday, month
gzz.vob.vobs.CalendarVob.setScales(1.4, 0.5, 0.34, 1.4)
# shift(something(x,y)): date, weeknum, weekday, month
gzz.vob.vobs.CalendarVob.setShifting(0.37, 0.85, 0.2, 0.1)
# annual calendar
for i in range(1, 13):
cs_cal = vs.coords.affineCoordsys(cs_rot , 0, 0 , i*9, 1.5, 0, 0, 1.15)
vs.matcher.add(cs_cal, "cs_cal"+str(i))
vs.matcher.add(cs_text_rot, "cs_text_rot"+str(i))
vs.map.put(gzz.vob.vobs.CalendarVob(2002, i), cs_cal, cs_text_rot)
if 0:
cs_cal = vs.coords.affineCoordsys(0, 0, w/2 - ((w/3 + self.tx) * (self.scale -1) ) ,
h/2 - ((h/3.5 + self.ty) *(self.scale-1)),
w/6 * self.scale, 0, 0, h/5 * self.scale)
vs.matcher.add(cs_cal, "cs_cal")
gzz.vob.CalendarVob.setBounds(0.9, 1.1, 0.8)
vs.map.put(gzz.vob.vobs.CalendarVob(2002, 12), cs_cal)
# help text
colchars = 60
tscale = min(size.width*1.0, size.height*4.0/3) / colchars
cs1 = vs.coords.affineCoordsys(0, 10, 0, 0, tscale, 0, 0, tscale)
vs.matcher.add(cs1, "1")
putText(vs, cs1, ' Use keys: +, -, Left, Right, Up, Down,', color=(0,0,0), h=4, y = 3)
putText(vs, cs1, ' Z, z, PageUp, and PageDown', color=(0,0,0), h=4, y = 6)
def key(self, k):
if k == "+": self.scale *= 1.5
if k == "-": self.scale *= 0.5
if k == "Right": self.tx -= 50 / self.scale
if k == "Left": self.tx += 50 / self.scale
if k == "Up": self.ty += 50 / self.scale
if k == "Down": self.ty -= 50 / self.scale
if k == "Next": self.ty -= 500 / self.scale
if k == "Prior": self.ty += 500 / self.scale
if k == "z": self.rotate += 15;
if k == "Z": self.rotate -= 15;
currentScene = ViewScene()
See more files for this project here