当前位置: 首页>>代码示例>>Python>>正文


Python Label.draw方法代码示例

本文整理汇总了Python中label.Label.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Label.draw方法的具体用法?Python Label.draw怎么用?Python Label.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在label.Label的用法示例。


在下文中一共展示了Label.draw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _draw_title

# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import draw [as 别名]
    def _draw_title(self, gc, label=None, axis_offset=None):
        """ Draws the title for the axis.
        """
        if label is None:
            title_label = Label(text=self.title,
                                font=self.title_font,
                                color=self.title_color,
                                rotate_angle=self.title_angle)
        else:
            title_label = label

        # get the _rotated_ bounding box of the label
        tl_bounds = array(title_label.get_bounding_box(gc), float64)
        text_center_to_corner = -tl_bounds/2.0
        # which axis are we moving away from the axis line along?
        axis_index = self._major_axis.argmin()

        if self.title_spacing != 'auto':
            axis_offset = self.title_spacing

        if (self.title_spacing) and (axis_offset is None ):
            if not self.ticklabel_cache:
                axis_offset = 25
            else:
                axis_offset = max([l._bounding_box[axis_index] for l in self.ticklabel_cache]) * 1.3

        offset = (self._origin_point+self._end_axis_point)/2
        axis_dist = self.tick_out + tl_bounds[axis_index]/2.0 + axis_offset
        offset -= self._inside_vector * axis_dist
        offset += text_center_to_corner

        gc.translate_ctm(*offset)
        title_label.draw(gc)
        gc.translate_ctm(*(-offset))
        return
开发者ID:,项目名称:,代码行数:37,代码来源:

示例2: __init__

# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import draw [as 别名]
class List:
  def __init__(self, x, y, w, title, entries=None):
    self.x = x
    self.y = y
    self.w = w
    self.h = len(entries) + 2
    x += 2
    w -= 4
    self.tlabel = Label(x,y,w,title, align=Label.ALIGN_CENTER, fg=COLOR_LIGHT_GREY)
    self.labels = []
    y += 1
    self.lx = x
    self.ly = y
    self.lw = w
    if entries != None:
      self.add_entries(entries)
    
  def add_entries(self, entries):
    y = self.ly
    for e in entries:
      l = Label(self.lx,y,self.lw,e)
      self.labels.append(l)
      y += 1
    self.ly = y
  
  def add_entry(self, entry):
    l = Label(self.lx,self.ly,self.lw,entry)
    self.ly += 1
  
  def draw(self, gc):
    gc.set_color_fg(COLOR_LIGHT_GREY)
    gc.draw_border(1, self.x, self.y, self.w-2, self.h-2)
    self.tlabel.draw(gc)
    for l in self.labels:
      l.draw(gc)
  
  def get_label(self, i):
    return self.labels[i]
开发者ID:cnvogelg,项目名称:knobterm,代码行数:40,代码来源:list.py

示例3: SpecialistPanel

# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import draw [as 别名]
class SpecialistPanel(Clickable):
    def __init__(self, x, y, specialist_instance, selectable=False):
        self.surface = Surface((200, 60))
        self.specialist = specialist_instance
        self.s_type = Label(0, 0, specialist.mapping[specialist_instance.s_type])
        self.s_exp = Label(0, 40, "")
        self.s_level = Label(0, 20, "")
        self.selectable = selectable
        self.selected = False
        self.x = x
        self.y = y
        self.w = 200
        self.h = 60

    def draw(self, screen):
        self.surface.fill(0x000000)
        pygame.draw.rect(self.surface, 0xb7f315 if self.selected else 0xffffff, Rect(0, 0, 198, 58), 2)
        self.s_exp.set_text("Exp: %s/%s" % (self.specialist.experience, self.specialist.level_up_exp))
        self.s_level.set_text("Level: %s" % self.specialist.level)
        self.s_type.draw(self.surface)
        self.s_exp.draw(self.surface)
        self.s_level.draw(self.surface)
        screen.blit(self.surface, (self.x, self.y))

    def is_pressed(self, x, y, button):
        if not self.selectable:
            return False
        if x < self.x:
            return False
        elif x > self.x + self.w:
            return False
        elif y < self.y:
            return False
        elif y > self.y + self.h:
            return False

        self.selected = not self.selected
        return True
开发者ID:trid,项目名称:anticivilization,代码行数:40,代码来源:specialist_panel.py

示例4: overlay

# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import draw [as 别名]
    def overlay(self, component, gc, view_bounds=None, mode="normal"):
        """ Draws the box overlaid on another component.

        Overrides AbstractOverlay.
        """

        if not self.visible:
            return

        # draw the label on a transparent box. This allows us to draw
        # different shapes and put the text inside it without the label
        # filling a rectangle on top of it
        label = Label(text=self.text, font=self.font, bgcolor="transparent",
                      margin=5)
        width, height = label.get_width_height(gc)

        valign, halign = self.align

        if self.alternate_position:
            x, y = self.alternate_position
            if valign == "u":
                y += self.padding
            else:
                y -= self.padding + height

            if halign == "r":
                x += self.padding
            else:
                x -= self.padding + width
        else:
            if valign == "u":
                y = component.y2 - self.padding - height
            else:
                y = component.y + self.padding

            if halign == "r":
                x = component.x2 - self.padding - width
            else:
                x = component.x + self.padding

        # attempt to get the box entirely within the component
        if x + width > component.width:
            x = max(0, component.width-width)
        if y + height > component.height:
            y = max(0, component.height - height)
        elif y < 0:
            y = 0

        # apply the alpha channel
        color = self.bgcolor_
        if self.bgcolor != "transparent":
            if self.alpha:
                color = list(self.bgcolor_)
                if len(color) == 4:
                    color[3] = self.alpha
                else:
                    color += [self.alpha]

        with gc:
            gc.translate_ctm(x, y)

            gc.set_line_width(self.border_size)
            gc.set_stroke_color(self.border_color_)
            gc.set_fill_color(color)

            # draw a rounded rectangle
            x = y = 0
            end_radius = 8.0
            gc.begin_path()
            gc.move_to(x + end_radius, y)
            gc.arc_to(x + width, y,
                    x + width,
                    y + end_radius, end_radius)
            gc.arc_to(x + width,
                    y + height,
                    x + width - end_radius,
                    y + height, end_radius)
            gc.arc_to(x, y + height,
                    x, y,
                    end_radius)
            gc.arc_to(x, y,
                    x + width + end_radius,
                    y, end_radius)
            gc.draw_path()

            label.draw(gc)
开发者ID:brycehendrix,项目名称:chaco,代码行数:88,代码来源:text_box_overlay.py


注:本文中的label.Label.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。