Exemple #1
0
 def _align_label(self, side=None, padx=None, pady=None):
     """Returns x,y of label (for canvas coords()/create(). side is like
     in labelconfigure() - N, NW, CENTER... Use args or current label_style,
     which is always available (after __init__() with defaults values)
     """
     side = self.label_styles["side"] if side is None else side
     padx = self.label_styles["padx"] if padx is None else padx
     pady = self.label_styles["pady"] if pady is None else pady
     bx0, by0, bx1, by1 = self.c.bbox(self.tag)
     bx0 += padx
     by0 += pady
     return tkutils.anchor_coords(bx0, by0, bx1, by1, side)
Exemple #2
0
    def place(self, x=None, y=None, relx=None, rely=None,
            width=None, height=None, relwidth=None, relheight=None, anchor=CENTER, widthscale=False):
        """Like place in Tk but on canvas
        """
        canw = float(self.c.winfo_width())
        canh = float(self.c.winfo_height())
        if relx is not None:
            x = canw * relx
        if rely is not None:
            y = canh * rely
        if relwidth is not None:
            width = canw * relwidth
        if relheight is not None:
            height = canh * relheight

        bx0, by0, bx1, by1 = self.c.bbox(self.tag)

        # first, change size

        if width:
            oldw = abs(bx1-bx0) or 1.
            self.xscale(factor=width/oldw, axe_point=LEFT, widthscale=widthscale)
        if height:
            oldh = abs(by1-by0) or 1.
            self.yscale(factor=height/oldh, axe_point=TOP, widthscale=widthscale)

        # second, move

        # Anchor coords: anchor is point inside this bound-box. Moving needs
        # shifting by the anchor coords (inside bbox) after usual movement.
        ax,ay = tkutils.anchor_coords(0, 0, bx1-bx0, by1-by0, anchor)

        if x is not None and x != bx0:
            xoff = x - bx0 - ax
        else:
            xoff = 0

        if y is not None and y != by0:
            yoff = y - by0 - ay
        else:
            yoff = 0

        #print "[%s] bx0: %d ax: %d xoff: %d canw: %d" % (self.tag, bx0, ax, xoff, canw)
        if xoff or yoff:
            self.move(xoff, yoff)
Exemple #3
0
 def __create_background(self, filename):
     """Create background of scheme
     """
     if self._bgcolor:
         self.c["bg"] = self._bgcolor
     im = Image.open(filename).convert("RGBA")
     self._imwidth, self._imheight = im.size
     self._cw = self.c.winfo_width()
     self._ch = self.c.winfo_height()
     if self._bgscale and (self._imwidth > self._cw or self._imheight > self._ch):
         # need increasing of image
         im = im.resize((min(self._imwidth, self._cw), min(self._imheight, self._ch)))
     self._im = ImageTk.PhotoImage(im)
     self._im.im = im
     x, y = tkutils.anchor_coords(0, 0, self._cw, self._ch, self._bganchor)
     self.tag = self.c.create_image(x, y, image=self._im, anchor=self._bganchor)
     self.c.tag_lower(self.tag, ALL) # or some symbol tag instead of ALL???
     # size of scheme
     self.width, self.height = im.size