コード例 #1
0
 def __init__(self, orientation=Gtk.Orientation.VERTICAL,
              spacing=0,
              padding=0,
              show_spinner=False):
     FramedBox.__init__(self, Gtk.Orientation.VERTICAL, spacing, padding)
     # make the header
     self.header = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, spacing)
     self.header_alignment = Gtk.Alignment()
     self.header_alignment.add(self.header)
     self.box.pack_start(self.header_alignment, False, False, 0)
     # make the content box
     self.content_box = Gtk.Box.new(orientation, spacing)
     self.content_box.show()
     # finally, a notebook for the spinner and the content box to share
     self.spinner_notebook = SpinnerNotebook(self.content_box,
                                             spinner_size=SpinnerView.SMALL)
     self.box.add(self.spinner_notebook)
     # make the "More" button, but don't add it to the header unless/until
     # we get a header_implements_more_button
     self.more = MoreLink()
コード例 #2
0
ファイル: containers.py プロジェクト: cs2c/AppStream
 def header_implements_more_button(self):
     if not hasattr(self, "more"):
         self.more = MoreLink()
         self.header.pack_end(self.more, False, False, 0)
コード例 #3
0
ファイル: containers.py プロジェクト: cs2c/AppStream
class FramedHeaderBox(FramedBox):

    MARKUP = '<b>%s</b>'

    # pages for the spinner notebook
    (CONTENT,
     SPINNER) = range(2)

    def __init__(self, orientation=Gtk.Orientation.VERTICAL,
                 spacing=0,
                 padding=0,
                 show_spinner=False):
        FramedBox.__init__(self, Gtk.Orientation.VERTICAL, spacing, padding)
        # make the header
        self.header = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, spacing)
        self.header_alignment = Gtk.Alignment()
        self.header_alignment.add(self.header)
        self.box.pack_start(self.header_alignment, False, False, 0)
        # make the content box
        self.content_box = Gtk.Box.new(orientation, spacing)
        self.content_box.show()
        # finally, a notebook for the spinner and the content box to share
        self.spinner_notebook = SpinnerNotebook(self.content_box)
        self.box.add(self.spinner_notebook)

    def on_draw(self, cr):
        a = self.get_allocation()
        self.render_frame(cr, a, Frame.BORDER_RADIUS, _frame_asset_cache)
        a = self.header_alignment.get_allocation()
        self.render_header(cr, a, Frame.BORDER_RADIUS, _frame_asset_cache)

        for child in self:
            self.propagate_draw(child, cr)

    def add(self, *args, **kwargs):
        return self.content_box.add(*args, **kwargs)

    def pack_start(self, *args, **kwargs):
        return self.content_box.pack_start(*args, **kwargs)

    def pack_end(self, *args, **kwargs):
        return self.content_box.pack_end(*args, **kwargs)

    # XXX: non-functional with current code...
    #~ def set_header_expand(self, expand):
        #~ alignment = self.header_alignment
        #~ if expand:
            #~ expand = 1.0
        #~ else:
            #~ expand = 0.0
        #~ alignment.set(alignment.get_property("xalign"),
                      #~ alignment.get_property("yalign"),
                      #~ expand, 1.0)

    def set_header_position(self, position):
        alignment = self.header_alignment
        alignment.set(position, 0.5,
                      alignment.get_property("xscale"),
                      alignment.get_property("yscale"))

    def set_header_label(self, label):
        if not hasattr(self, "title"):
            self.title = Gtk.Label()
            self.title.set_padding(StockEms.MEDIUM, StockEms.SMALL)
            context = self.title.get_style_context()
            context.add_class("frame-header-title")
            self.header.pack_start(self.title, False, False, 0)
            self.title.show()

        self.title.set_markup(self.MARKUP % label)

    def header_implements_more_button(self):
        if not hasattr(self, "more"):
            self.more = MoreLink()
            self.header.pack_end(self.more, False, False, 0)

    def render_header(self, cr, a, border_radius, assets):

        if hasattr(self, "more"):
            context = self.get_style_context()

            # set the arrow fill color
            context = self.more.get_style_context()
            cr.save()

            bg = context.get_background_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bg)

            # the arrow shape stuff
            r = Frame.BORDER_RADIUS - 1
            ta = self.more.get_allocation()

            y = ta.y - a.y + 2
            h = ta.height - 2

            if self.get_direction() == Gtk.TextDirection.RTL:
                x = ta.x - a.x + 3
                w = ta.width + StockEms.MEDIUM

                cr.new_sub_path()
                cr.arc(r + x, r + y, r, PI, 270 * PI_OVER_180)
                cr.line_to(x + w, y)
                cr.line_to(x + w - StockEms.MEDIUM, y + h / 2)
                cr.line_to(x + w, y + h)
                cr.line_to(x, y + h)
                cr.close_path()

                cr.fill()

                cr.move_to(x + w, y)
                cr.line_to(x + w - StockEms.MEDIUM, y + h / 2)
                cr.line_to(x + w, y + h)

            else:
                x = ta.x - a.x - StockEms.MEDIUM
                w = ta.width + StockEms.MEDIUM - 1

                cr.move_to(x, y)
                cr.arc(x + w - r, y + r, r, 270 * PI_OVER_180, 0)
                cr.line_to(x + w, y + h)
                cr.line_to(x, y + h)
                cr.line_to(x + StockEms.MEDIUM, y + h / 2)
                cr.close_path()

                cr.fill()

                cr.move_to(x, y)
                cr.line_to(x + StockEms.MEDIUM, y + h / 2)
                cr.line_to(x, y + h)

            bc = context.get_border_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bc)
            cr.set_line_width(1)
            cr.stroke()

            cr.restore()

        # paint the containers children
        for child in self:
            self.propagate_draw(child, cr)
コード例 #4
0
 def header_implements_more_button(self):
     if not hasattr(self, "more"):
         self.more = MoreLink()
         self.header.pack_end(self.more, False, False, 0)
コード例 #5
0
class FramedHeaderBox(FramedBox):

    MARKUP = '<b>%s</b>'

    # pages for the spinner notebook
    (CONTENT, SPINNER) = range(2)

    def __init__(self,
                 orientation=Gtk.Orientation.VERTICAL,
                 spacing=0,
                 padding=0,
                 show_spinner=False):
        FramedBox.__init__(self, Gtk.Orientation.VERTICAL, spacing, padding)
        # make the header
        self.header = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, spacing)
        self.header_alignment = Gtk.Alignment()
        self.header_alignment.add(self.header)
        self.box.pack_start(self.header_alignment, False, False, 0)
        # make the content box
        self.content_box = Gtk.Box.new(orientation, spacing)
        self.content_box.show()
        # finally, a notebook for the spinner and the content box to share
        self.spinner_notebook = SpinnerNotebook(self.content_box)
        self.box.add(self.spinner_notebook)

    def on_draw(self, cr):
        a = self.get_allocation()
        self.render_frame(cr, a, Frame.BORDER_RADIUS, _frame_asset_cache)
        a = self.header_alignment.get_allocation()
        self.render_header(cr, a, Frame.BORDER_RADIUS, _frame_asset_cache)

        for child in self:
            self.propagate_draw(child, cr)

    def add(self, *args, **kwargs):
        return self.content_box.add(*args, **kwargs)

    def pack_start(self, *args, **kwargs):
        return self.content_box.pack_start(*args, **kwargs)

    def pack_end(self, *args, **kwargs):
        return self.content_box.pack_end(*args, **kwargs)

    # XXX: non-functional with current code...
    #~ def set_header_expand(self, expand):
    #~ alignment = self.header_alignment
    #~ if expand:
    #~ expand = 1.0
    #~ else:
    #~ expand = 0.0
    #~ alignment.set(alignment.get_property("xalign"),
    #~ alignment.get_property("yalign"),
    #~ expand, 1.0)

    def set_header_position(self, position):
        alignment = self.header_alignment
        alignment.set(position, 0.5, alignment.get_property("xscale"),
                      alignment.get_property("yscale"))

    def set_header_label(self, label):
        if not hasattr(self, "title"):
            self.title = Gtk.Label()
            self.title.set_padding(StockEms.MEDIUM, StockEms.SMALL)
            context = self.title.get_style_context()
            context.add_class("frame-header-title")
            self.header.pack_start(self.title, False, False, 0)
            self.title.show()

        self.title.set_markup(self.MARKUP % label)

    def header_implements_more_button(self):
        if not hasattr(self, "more"):
            self.more = MoreLink()
            self.header.pack_end(self.more, False, False, 0)

    def remove_more_button(self):
        if hasattr(self, "more"):
            self.header.remove(self.more)
            del self.more

    def render_header(self, cr, a, border_radius, assets):

        if hasattr(self, "more"):
            context = self.get_style_context()

            # set the arrow fill color
            context = self.more.get_style_context()
            cr.save()

            bg = context.get_background_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bg)

            # the arrow shape stuff
            r = Frame.BORDER_RADIUS - 1
            ta = self.more.get_allocation()

            y = ta.y - a.y + 2
            h = ta.height - 2

            if self.get_direction() == Gtk.TextDirection.RTL:
                x = ta.x - a.x + 3
                w = ta.width + StockEms.MEDIUM

                cr.new_sub_path()
                cr.arc(r + x, r + y, r, PI, 270 * PI_OVER_180)
                cr.line_to(x + w, y)
                cr.line_to(x + w - StockEms.MEDIUM, y + h / 2)
                cr.line_to(x + w, y + h)
                cr.line_to(x, y + h)
                cr.close_path()

                cr.fill()

                cr.move_to(x + w, y)
                cr.line_to(x + w - StockEms.MEDIUM, y + h / 2)
                cr.line_to(x + w, y + h)

            else:
                x = ta.x - a.x - StockEms.MEDIUM
                w = ta.width + StockEms.MEDIUM - 1

                cr.move_to(x, y)
                cr.arc(x + w - r, y + r, r, 270 * PI_OVER_180, 0)
                cr.line_to(x + w, y + h)
                cr.line_to(x, y + h)
                cr.line_to(x + StockEms.MEDIUM, y + h / 2)
                cr.close_path()

                cr.fill()

                cr.move_to(x, y)
                cr.line_to(x + StockEms.MEDIUM, y + h / 2)
                cr.line_to(x, y + h)

            bc = context.get_border_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bc)
            cr.set_line_width(1)
            cr.stroke()

            cr.restore()

        # paint the containers children
        for child in self:
            self.propagate_draw(child, cr)
コード例 #6
0
ファイル: containers.py プロジェクト: Alberto-Beralix/Beralix
class FramedHeaderBox(FramedBox):

    MARKUP = '<b>%s</b>'

    def __init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=0, padding=0):
        FramedBox.__init__(self, Gtk.Orientation.VERTICAL, spacing, padding)
        self.header = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, spacing)
        self.header_alignment = Gtk.Alignment()
        self.header_alignment.add(self.header)
        self.box.pack_start(self.header_alignment, False, False, 0)
        self.content_box = Gtk.Box.new(orientation, spacing)
        self.box.add(self.content_box)
        return

    def on_draw(self, cr):
        a = self.get_allocation()
        self.render_frame(cr, a, Frame.BORDER_RADIUS, _frame_asset_cache)
        a = self.header_alignment.get_allocation()
        self.render_header(cr, a, Frame.BORDER_RADIUS, _frame_asset_cache)

        for child in self: self.propagate_draw(child, cr)
        return

    def add(self, *args, **kwargs):
        return self.content_box.add(*args, **kwargs)

    def pack_start(self, *args, **kwargs):
        return self.content_box.pack_start(*args, **kwargs)

    def pack_end(self, *args, **kwargs):
        return self.content_box.pack_end(*args, **kwargs)

    # XXX: non-functional with current code...
    #~ def set_header_expand(self, expand):
        #~ alignment = self.header_alignment
        #~ if expand:
            #~ expand = 1.0
        #~ else:
            #~ expand = 0.0
        #~ alignment.set(alignment.get_property("xalign"),
                      #~ alignment.get_property("yalign"),
                      #~ expand, 1.0)

    def set_header_position(self, position):
        alignment = self.header_alignment
        alignment.set(position, 0.5,
                      alignment.get_property("xscale"),
                      alignment.get_property("yscale"))

    def set_header_label(self, label):
        if not hasattr(self, "title"):
            self.title = Gtk.Label()
            self.title.set_padding(StockEms.MEDIUM, StockEms.SMALL)
            context = self.title.get_style_context()
            context.add_class("frame-header-title")
            self.header.pack_start(self.title, False, False, 0)
            self.title.show()

        self.title.set_markup(self.MARKUP % label)
        return

    def header_implements_more_button(self, callback=None):
        if not hasattr(self, "more"):
            self.more = MoreLink()
            self.header.pack_end(self.more, False, False, 0)
        return
    
    def render_header(self, cr, a, border_radius, assets):
        context = self.get_style_context()
        Gtk.render_background(context, cr,
                              0, 0, a.width, a.height)

        cr.save()
        lin = cairo.LinearGradient(0, 0, 0, a.height)
        lin.add_color_stop_rgba(0, 1,1,1, 0.5)
        lin.add_color_stop_rgba(1, 1,1,1, 0.0)
        cr.set_source(lin)
        cr.rectangle(0, 0, a.width, a.height)
        cr.fill()

        # gridline color
        context.save()
        context.add_class("grid-lines")
        bc = context.get_border_color(self.get_state_flags())
        Gdk.cairo_set_source_rgba(cr, bc)
        context.restore()

        cr.move_to(0, a.height-0.5)
        cr.rel_line_to(a.width, 0)
        cr.set_line_width(1)
        cr.stroke()
        cr.restore()

        if hasattr(self, "more"):
            # set the arrow fill color
            context = self.more.get_style_context()
            cr.save()

            bg = context.get_background_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bg)

            # the arrow shape stuff
            ta = self.more.get_allocation()
            cr.move_to(ta.x-a.x-StockEms.MEDIUM, 0)
            cr.rel_line_to(ta.width+StockEms.MEDIUM, 0)
            cr.rel_line_to(0, a.height)
            cr.rel_line_to(-(ta.width+StockEms.MEDIUM), 0)
            cr.rel_line_to(StockEms.MEDIUM, -(a.height)*0.5)
            cr.close_path()
            cr.clip_preserve()
            cr.fill_preserve()

            bc = context.get_border_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bc)
            cr.stroke()

            cr.restore()

        # paint the containers children
        for child in self: self.propagate_draw(child, cr)
        return