Beispiel #1
0
 def _drawAxes(self, canvas, xaxis, yaxis,
               bb1, bb2, scale, shift, xticks, yticks):
     dict = {'anchor': N, 'fill': 'black'}
     if self.font is not None:
         dict['font'] = self.font
     if xaxis is not None:
     #draw x - axis
         lower, upper = xaxis
         text = 1
         once = 1
         for y, d in [(bb1[1], -3), (bb2[1], 3)]:
         #d=.5 of tick - length
             p1 = (scale[0] * lower) + shift[0], (scale[1] * y) + shift[1]
             if once: pp1 = p1
             p2 = (scale[0] * upper) + shift[0], (scale[1] * y) + shift[1]
             if once: pp2 = p2
             once = 0
             Line(self.canvas, p1[0], p1[1], p2[0], p2[1],
                  fill = 'black', width = 1)
             if xticks:
                 for x, label in xticks:
                     p = (scale[0] * x) + shift[0], \
                         (scale[1] * y) + shift[1]
                     Line(self.canvas, p[0], p[1], p[0], p[1] + d,
                          fill = 'black', width = 1)
                     if text:
                         dict['text'] = label
                         CanvasText(self.canvas, p[0],
                                            p[1] + 2, **dict)    ##KGM 14 Aug 03
             text = 0
         #write x - axis title
         CanvasText(self.canvas,(pp2[0] - pp1[0]) / 2.+pp1[0],pp1[1] + 22, text = self.xtitle)
     #write graph title
     CanvasText(self.canvas,(pp2[0] - pp1[0]) / 2.+pp1[0],7, text = self.title)
     dict['anchor'] = E
     if yaxis is not None:
         #draw y - axis
         lower, upper = yaxis
         text = 1
         once = 1
         for x, d in [(bb1[0], -3), (bb2[0], 3)]:
             p1 = (scale[0] * x) + shift[0], (scale[1] * lower) + shift[1]
             p2 = (scale[0] * x) + shift[0], (scale[1] * upper) + shift[1]
             if once: pp1 = p1 ;pp2 = p2
             once = 0
             Line(self.canvas, p1[0], p1[1], p2[0], p2[1],
                  fill = 'black', width = 1)
             if yticks:
                 for y, label in yticks:
                     p = (scale[0] * x) + shift[0], \
                         (scale[1] * y) + shift[1]
                     Line(self.canvas, p[0], p[1], p[0] - d, p[1],
                          fill = 'black', width = 1)
                     if text:
                         dict['text'] = label
                         CanvasText(self.canvas,
                                           p[0] - 4, p[1] + 2, **dict)
             text = 0
         #write y - axis title
         CanvasText(self.canvas, pp2[0],pp2[1] - 10, text = self.ytitle)
Beispiel #2
0
    def __init__(self, suit, value, canvas):
	"""Card constructor.

	Arguments are the card's suit and value, and the canvas widget.

	The card is created at position (0, 0), with its face down
	(adding it to a stack will position it according to that
	stack's rules).

	"""
	self.suit = suit
	self.value = value
	self.color = COLOR[suit]
	self.face_shown = 0

	self.x = self.y = 0
	self.group = Group(canvas)

	text = "%s  %s" % (VALNAMES[value], suit)
	self.__text = CanvasText(canvas, CARDWIDTH/2, 0,
			       anchor=N, fill=self.color, text=text)
	self.group.addtag_withtag(self.__text)

	self.__rect = Rectangle(canvas, 0, 0, CARDWIDTH, CARDHEIGHT,
			      outline='black', fill='white')
	self.group.addtag_withtag(self.__rect)

	self.__back = Rectangle(canvas, MARGIN, MARGIN,
			      CARDWIDTH-MARGIN, CARDHEIGHT-MARGIN,
			      outline='black', fill='blue')
	self.group.addtag_withtag(self.__back)
Beispiel #3
0
 def createitems(self, fill, text):
     self.__oval = Oval(self.canvas,
                        self.x-20, self.y-10, self.x+20, self.y+10,
                        fill=fill, width=3)
     self.group.addtag_withtag(self.__oval)
     self.__text = CanvasText(self.canvas,
                        self.x, self.y, text=text)
     self.group.addtag_withtag(self.__text)
Beispiel #4
0
 def _textBoundingBox(self, text):
     bg = self.canvas.cget('background')
     dict = {'anchor': NW, 'text': text, 'fill': bg}
     if self.font is not None:
         dict['font'] = self.font
     item = CanvasText(self.canvas, 0., 0., **dict)
     bb = self.canvas.bbox(item)
     self.canvas.delete(item)
     return bb
Beispiel #5
0
 def _testFont(self, font):
     if font is not None:
         bg = self.canvas.cget('background')
         try:
             item = CanvasText(self.canvas, 0, 0, anchor=Tkinter.NW,
                               text='0', fill=bg, font=font)
             self.canvas.delete(item)
         except Tkinter.TclError:
             font = None
     return font
Beispiel #6
0
 def xTicks(xMin,xMax,Ax,Bx):
     # Plot ticks and labels for x-axis
     dx = tickSpace(xMin,xMax,px)
     yp = topMargin + height
     if xMin < 0.0: 
         x = 0.0
         while x >= xMin:
             if x <= xMax:
                 xp = Ax + Bx*x    
                 Line(cv,xp,yp,xp,yp - 8)
                 label = str(round(x,4))
                 CanvasText(cv,xp,yp+20,text=label)
             x = x - dx    
     if xMax > 0.0:
         x = 0.0
         while x <= xMax:
             if x >= xMin:
                 xp = Ax + Bx*x             
                 Line(cv,xp,yp,xp,yp - 8)
                 label = str(round(x,4))
                 CanvasText(cv,xp,yp+20,text=label)
             x = x + dx
Beispiel #7
0
 def yTicks(yMin,yMax,Ay,By):
     # Plot ticks and labels for y-axis
     dy = tickSpace(yMin,yMax,py)
     xp = leftMargin
     if yMin < 0.0: 
         y = 0.0
         while y >= yMin:
             if y <= yMax:
                 yp = Ay + By*y
                 Line(cv,xp,yp,xp+8,yp)
                 label = str(round(y,4))
                 xxp = xp-10-len(label)*3
                 CanvasText(cv,xxp,yp,text=label)
             y = y - dy 
     if yMax > 0.0:
         y = 0.0
         while y <= yMax:
             if y >= yMin:
                 yp = Ay + By*y
                 Line(cv,xp,yp,xp+8,yp)
                 label = str(round(y,4))
                 xxp = xp-10-len(label)*3
                 CanvasText(cv,xxp,yp,text=label)
             y = y + dy
Beispiel #8
0
#! /usr/bin/env python
Beispiel #9
0
#! /usr/bin/env python
 def _drawAxes(self, canvas, xaxis, yaxis, bb1, bb2, scale, shift, xticks,
               yticks):
     dict = {'anchor': tkinter.N, 'fill': 'black'}
     if self.font is not None:
         dict['font'] = self.font
     if xaxis is not None:
         lower, upper = xaxis
         text = 1
         for y, d in [(bb1[1], -3), (bb2[1], 3)]:
             p1 = (scale[0] * lower) + shift[0], (scale[1] * y) + shift[1]
             p2 = (scale[0] * upper) + shift[0], (scale[1] * y) + shift[1]
             Line(self.draw,
                  p1[0],
                  p1[1],
                  p2[0],
                  p2[1],
                  fill='black',
                  width=1)
             if xticks:
                 for x, label in xticks:
                     p = (scale[0]*x)+shift[0], \
                         (scale[1]*y)+shift[1]
                     Line(self.draw,
                          p[0],
                          p[1],
                          p[0],
                          p[1] + d,
                          fill='black',
                          width=1)
                     if text:
                         dict['text'] = label
                         CanvasText(*(self.draw, p[0], p[1]), **dict)
             text = 0
     dict['anchor'] = tkinter.E
     if yaxis is not None:
         lower, upper = yaxis
         text = 1
         for x, d in [(bb1[0], -3), (bb2[0], 3)]:
             p1 = (scale[0] * x) + shift[0], (scale[1] * lower) + shift[1]
             p2 = (scale[0] * x) + shift[0], (scale[1] * upper) + shift[1]
             Line(self.draw,
                  p1[0],
                  p1[1],
                  p2[0],
                  p2[1],
                  fill='black',
                  width=1)
             if yticks:
                 for y, label in yticks:
                     p = (scale[0]*x)+shift[0], \
                         (scale[1]*y)+shift[1]
                     Line(self.draw,
                          p[0],
                          p[1],
                          p[0] - d,
                          p[1],
                          fill='black',
                          width=1)
                     if text:
                         dict['text'] = label
                         CanvasText(*(self.draw, p[0] - 2, p[1]), **dict)
             text = 0