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


Python Background.set_background_color方法代码示例

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


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

示例1: Header

# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import set_background_color [as 别名]
class Header(Gtk.DrawingArea):
    def __init__(self, cols=7):
        super(Header, self).__init__()
        self.labels = []
        self.background = Background(1, cols)
        self.sidebar = 0
        self.font = "Courier"
        self.font_size = 12
        self.font_color = (0.35, 0.31, 0.24)
        self.highlight_cell = (None, None)

        self.connect("draw", self.draw)

    def set_sidebar_size(self, size):
        self.sidebar = size

    def set_labels(self, labels):
        self.labels = labels

    def set_font(self, font):
        self.font = font

    def set_font_size(self, size):
        self.font_size = size

    def set_font_color(self, color):
        self.font_color = color

    def set_line_color(self, color):
        self.background.set_line_color(color)

    def set_background_color(self, color):
        self.background.set_background_color(color)

    def get_height(self):
        try:
            line_height = self.get_allocation().height / len(self.labels[0])
        except ZeroDivisionError:
            print("List of labels in object Header not initialized!")
            raise
        else:
            return line_height

    def get_col_width(self):
        try:
            col_width = (self.get_allocation().width - self.sidebar) \
                / float(len(self.labels))
        except ZeroDivisionError:
            print("List of labels in object Header not initialized!")
            raise
        else:
            return col_width

    def set_highlight_cell(self, row, col):
        if row == 0 and 0 <= col < len(self.labels):
            self.highlight_cell = (row, col)
        else:
            self.highlight_cell = (None, None)

    def draw(self, widget, ctx):
        """
        Draws the header according to the labels.

        @param ctx: a Cairo context
        """
        alloc = self.get_allocation()
        alloc.width -= self.sidebar
        # FIXME: look deeper into why x=5 and y=35 - both should start at 0
        # Whathever is happening has to do with spacing in vbox (glade file)
        # temporary fix:
        alloc.x = 0
        alloc.y = 0

        ctx.set_line_width(0.8)
        row, col = self.highlight_cell
        if row is not None and col is not None:
            # print "header", alloc.x, alloc.y, alloc.width, alloc.height
            self.background.highlight_cell(ctx, row, col, alloc)

        self.background.draw(ctx, alloc, vgrid=False, hgrid=True)

        color = self.font_color
        ctx.set_source_rgb(color[0], color[1], color[2])

        ctx.set_font_size(self.font_size)
        ctx.select_font_face(self.font, cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_NORMAL)

        # print labels: use multiple lines if necessary
        col_width = self.get_col_width()
        line_height = self.get_height()
        for i in range(0, len(self.labels)):
            for j in range(0, len(self.labels[i])):
                label, base_x, base_y = utils.center_text_on_rect(
                    ctx, self.labels[i][j],
                    (i * col_width), (j * line_height),
                    col_width, line_height)
                ctx.move_to(base_x, base_y)
                ctx.text_path(label)
                ctx.stroke()
开发者ID:sararibeiro,项目名称:calendar-plugin,代码行数:102,代码来源:header.py

示例2: AllDayTasks

# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import set_background_color [as 别名]
class AllDayTasks(Gtk.DrawingArea):
    def __init__(self, parent, rows=1, cols=7):
        super(Gtk.DrawingArea, self).__init__()

        self.par = parent
        self.num_rows = rows
        self.num_columns = cols
        self.background = Background(rows, cols)

        self.padding = 1.5
        self.font = "Courier"
        self.font_size = 12
        self.font_color = (0.35, 0.31, 0.24)
        self.link_color = (0, 0, 255, 0.5)  # default blue link color
        self.today_cell = (None, None)
        self.selected_task = None
        self.faded_cells = []
        self.cells = []
        self.labels = None
        self.label_height = self.font_size
        self.overflow_links = []

        self.connect("draw", self.draw)

        # drag-and-drop signals and events
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK
                        | Gdk.EventMask.BUTTON_RELEASE_MASK
                        | Gdk.EventMask.BUTTON1_MOTION_MASK
                        | Gdk.EventMask.POINTER_MOTION_MASK)

    def get_label_height(self):
        if self.labels:
          return self.label_height
        return 0

    def set_labels(self, labels):
        self.labels = labels

    def set_num_rows(self, rows):
        self.num_rows = rows
        self.background.set_num_rows(rows)

    def set_font(self, font):
        self.font = font

    def set_font_size(self, size):
        self.font_size = size

    def set_font_color(self, color):
        self.font_color = color

    def set_line_color(self, color):
        self.background.set_line_color(color)

    def set_background_color(self, color):
        self.background.set_background_color(color)

    def get_day_width(self):
        return self.get_allocation().width / float(self.num_columns)

    def get_week_height(self):
        return self.get_allocation().height / float(self.num_rows)

    def set_tasks_to_draw(self, drawtasks):
        self.drawtasks = drawtasks

    def highlight_cells(self, ctx, cells, color, alpha=0.5):
        alloc = self.get_allocation()
        for cell in cells:
            row, col = cell
            if 0 <= row < self.num_rows and 0 <= col < self.num_columns:
                ctx.save()
                self.background.highlight_cell(ctx, row, col, alloc,
                                               color, alpha)
                ctx.restore()

    def set_today_cell(self, row, col):
        if 0 <= row < self.num_rows and 0 <= col < self.num_columns:
            self.today_cell = (row, col)
        else:
            self.today_cell = (None, None)

    def draw(self, widget, ctx):
        ctx.set_line_width(0.8)
        ctx.set_font_size(self.font_size)
        ctx.select_font_face(self.font, cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_NORMAL)

        # first draw background
        ctx.save()
        alloc = self.get_allocation()
        self.set_line_color(color=(0.35, 0.31, 0.24, 0.15))
        row, col = self.today_cell
        if row is not None and col is not None and row >= 0 and col >= 0:
            self.background.highlight_cell(ctx, row, col, alloc)
        self.background.draw(ctx, alloc, vgrid=True, hgrid=True)
        ctx.restore()

        # then draw labels, if any (used only on month_view)
        if self.labels:
#.........这里部分代码省略.........
开发者ID:sararibeiro,项目名称:calendar-plugin,代码行数:103,代码来源:all_day_tasks.py


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