Esempio n. 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)
Esempio n. 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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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
Esempio n. 8
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
Esempio n. 9
0
class Card:

    """A playing card.

    A card doesn't record to which stack it belongs; only the stack
    records this (it turns out that we always know this from the
    context, and this saves a ``double update'' with potential for
    inconsistencies).

    Public methods:

    moveto(x, y) -- move the card to an absolute position
    moveby(dx, dy) -- move the card by a relative offset
    tkraise() -- raise the card to the top of its stack
    showface(), showback() -- turn the card face up or down & raise it

    Public read-only instance variables:

    suit, value, color -- the card's suit, value and color
    face_shown -- true when the card is shown face up, else false

    Semi-public read-only instance variables (XXX should be made
    private):

    group -- the Canvas.Group representing the card
    x, y -- the position of the card's top left corner

    Private instance variables:

    __back, __rect, __text -- the canvas items making up the card

    (To show the card face up, the text item is placed in front of
    rect and the back is placed behind it.  To show it face down, this
    is reversed.  The card is created face down.)

    """

    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)

    def __repr__(self):
        """Return a string for debug print statements."""
        return "Card(%r, %r)" % (self.suit, self.value)

    def moveto(self, x, y):
        """Move the card to absolute position (x, y)."""
        self.moveby(x - self.x, y - self.y)

    def moveby(self, dx, dy):
        """Move the card by (dx, dy)."""
        self.x = self.x + dx
        self.y = self.y + dy
        self.group.move(dx, dy)

    def tkraise(self):
        """Raise the card above all other objects in its canvas."""
        self.group.tkraise()

    def showface(self):
        """Turn the card's face up."""
        self.tkraise()
        self.__rect.tkraise()
        self.__text.tkraise()
        self.face_shown = 1

    def showback(self):
        """Turn the card's face down."""
        self.tkraise()
        self.__rect.tkraise()
        self.__back.tkraise()
        self.face_shown = 0
Esempio n. 10
0
#! /usr/bin/env python
Esempio n. 11
0
class Card:
    """A playing card.

    A card doesn't record to which stack it belongs; only the stack
    records this (it turns out that we always know this from the
    context, and this saves a ``double update'' with potential for
    inconsistencies).

    Public methods:

    moveto(x, y) -- move the card to an absolute position
    moveby(dx, dy) -- move the card by a relative offset
    tkraise() -- raise the card to the top of its stack
    showface(), showback() -- turn the card face up or down & raise it

    Public read-only instance variables:

    suit, value, color -- the card's suit, value and color
    face_shown -- true when the card is shown face up, else false

    Semi-public read-only instance variables (XXX should be made
    private):

    group -- the Canvas.Group representing the card
    x, y -- the position of the card's top left corner

    Private instance variables:

    __back, __rect, __text -- the canvas items making up the card

    (To show the card face up, the text item is placed in front of
    rect and the back is placed behind it.  To show it face down, this
    is reversed.  The card is created face down.)

    """
    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)

    def __repr__(self):
        """Return a string for debug print statements."""
        return "Card(%r, %r)" % (self.suit, self.value)

    def moveto(self, x, y):
        """Move the card to absolute position (x, y)."""
        self.moveby(x - self.x, y - self.y)

    def moveby(self, dx, dy):
        """Move the card by (dx, dy)."""
        self.x = self.x + dx
        self.y = self.y + dy
        self.group.move(dx, dy)

    def tkraise(self):
        """Raise the card above all other objects in its canvas."""
        self.group.tkraise()

    def showface(self):
        """Turn the card's face up."""
        self.tkraise()
        self.__rect.tkraise()
        self.__text.tkraise()
        self.face_shown = 1

    def showback(self):
        """Turn the card's face down."""
        self.tkraise()
        self.__rect.tkraise()
        self.__back.tkraise()
        self.face_shown = 0
Esempio n. 12
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