Esempio n. 1
0
    def __init__(self, title, description, is_plug=False, back_btn=False):
        self.back_button = None
        css_path = os.path.join(css_dir, "heading.css")
        apply_styling_to_screen(css_path)
        title_hbox = None

        if is_plug:
            title_hbox = Gtk.Box()
            close_button = Gtk.Button()
            close_button.set_image(set_from_name('cross'))
            close_button.get_style_context().add_class('back_button')
            close_button.connect('clicked', Gtk.main_quit)
            close_button.set_margin_top(15)
            attach_cursor_events(close_button)
            title_hbox.pack_end(close_button, True, True, 0)

            if back_btn:
                self.back_button = Gtk.Button()
                attach_cursor_events(self.back_button)
                self.back_button.get_style_context().add_class('back_button')
                # TODO: get better back icon
                self.back_button.set_image(set_from_name('dark_left_arrow'))
                self.back_button.set_margin_top(15)
                title_hbox.pack_start(self.back_button, True, False, 0)

            else:
                empty_button = Gtk.Button(" ")
                empty_button.get_style_context().add_class('transparent')
                title_hbox.pack_start(empty_button, True, True, 0)

        self.title = Gtk.Label(title)
        self.title.get_style_context().add_class('title')
        self.title.set_justify(Gtk.Justification.CENTER)
        self.container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                                 spacing=10)

        if is_plug:
            title_hbox.pack_start(self.title, True, True, 0)
            self.container.pack_start(title_hbox, False, False, 0)
        else:
            self.container.pack_start(self.title, False, False, 0)

        if description != "":
            self.description = Gtk.Label(description)
            self.description.set_justify(Gtk.Justification.CENTER)
            self.description.set_line_wrap(True)
            self.description_style = self.description.get_style_context()
            self.description_style.add_class('description')

            self.container.pack_start(self.description, False, False, 0)
Esempio n. 2
0
    def __init__(self, title, window_width=-1, has_buttons=True):

        Gtk.EventBox.__init__(self)

        self.has_buttons = has_buttons

        # Styling
        self.cssProvider = Gtk.CssProvider()
        top_bar_css = os.path.join(common_css_dir, 'top_bar.css')
        if not os.path.exists(top_bar_css):
            sys.exit('CSS file missing!')
        self.cssProvider.load_from_path(top_bar_css)
        styleContext = self.get_style_context()
        styleContext.add_provider(self.cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)

        self.set_size_request(window_width, TOP_BAR_HEIGHT)

        self.height = TOP_BAR_HEIGHT

        self.header = Gtk.Label(title, halign=Gtk.Align.CENTER)
        self.align_header = Gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0, yscale=0)
        self.align_header.add(self.header)

        self.cross = icons.set_from_name("cross")

        # Close button
        self.close_button = Gtk.Button()
        self.close_button.set_image(self.cross)
        self.close_button.set_size_request(TOP_BAR_HEIGHT, TOP_BAR_HEIGHT)
        self.close_button.set_can_focus(False)
        self.add_style(self.close_button, "top_bar_button")

        # Container to mimic a button, so we can centre the header
        invisible = Gtk.Box()
        invisible.set_size_request(44, 44)

        # Main container holding everything
        self.box = Gtk.Box()

        if has_buttons:

            # Icons of the buttons
            self.pale_prev_arrow = icons.set_from_name("pale_left_arrow")
            self.pale_next_arrow = icons.set_from_name("pale_right_arrow")
            self.dark_prev_arrow = icons.set_from_name("dark_left_arrow")
            self.dark_next_arrow = icons.set_from_name("dark_right_arrow")

            # Prev Button
            self.prev_button = Gtk.Button()
            self.prev_button.set_size_request(TOP_BAR_HEIGHT, TOP_BAR_HEIGHT)
            self.prev_button.set_can_focus(False)
            self.prev_button.set_image(self.pale_prev_arrow)

            # Next button
            self.next_button = Gtk.Button()
            self.next_button.set_size_request(TOP_BAR_HEIGHT, TOP_BAR_HEIGHT)
            self.next_button.set_can_focus(False)
            self.next_button.set_image(self.pale_next_arrow)

            self.box.pack_start(self.prev_button, False, False, 0)
            self.box.pack_start(self.next_button, False, False, 0)

            self.add_style(self.prev_button, "top_bar_button")
            self.add_style(self.next_button, "top_bar_button")

            # On start, disable the prev and next buttons
            self.disable_prev()
            self.disable_next()

            attach_cursor_events(self.prev_button)
            attach_cursor_events(self.next_button)

        attach_cursor_events(self.close_button)

        if has_buttons:
            self.box.pack_start(self.align_header, True, True, 0)
            self.box.pack_end(self.close_button, False, False, 0)
            self.box.pack_end(invisible, False, False, 0)
        else:
            self.box.pack_start(invisible, False, False, 0)
            self.box.pack_start(self.align_header, True, True, 0)
            self.box.pack_end(self.close_button, False, False, 0)

        self.box.set_size_request(window_width, 44)

        self.add(self.box)

        styleContext.add_class('top_bar_container')
        self.add_style(self.header, "top_bar_title")
Esempio n. 3
0
    def __init__(self, title, window_width=-1, has_buttons=True):

        Gtk.EventBox.__init__(self)

        self.has_buttons = has_buttons

        # Styling
        self.cssProvider = Gtk.CssProvider()
        top_bar_css = os.path.join(common_css_dir, 'top_bar.css')
        if not os.path.exists(top_bar_css):
            sys.exit('CSS file missing!')
        self.cssProvider.load_from_path(top_bar_css)
        styleContext = self.get_style_context()
        styleContext.add_provider(self.cssProvider,
                                  Gtk.STYLE_PROVIDER_PRIORITY_USER)

        self.set_size_request(window_width, TOP_BAR_HEIGHT)

        self.height = TOP_BAR_HEIGHT

        self.header = Gtk.Label(title, halign=Gtk.Align.CENTER)
        self.align_header = Gtk.Alignment(xalign=0.5,
                                          yalign=0.5,
                                          xscale=0,
                                          yscale=0)
        self.align_header.add(self.header)

        self.cross = icons.set_from_name("cross")

        # Close button
        self.close_button = Gtk.Button()
        self.close_button.set_image(self.cross)
        self.close_button.set_size_request(TOP_BAR_HEIGHT, TOP_BAR_HEIGHT)
        self.close_button.set_can_focus(False)
        self.add_style(self.close_button, "top_bar_button")

        # Container to mimic a button, so we can centre the header
        invisible = Gtk.Box()
        invisible.set_size_request(44, 44)

        # Main container holding everything
        self.box = Gtk.Box()

        if has_buttons:

            # Icons of the buttons
            self.pale_prev_arrow = icons.set_from_name("pale_left_arrow")
            self.pale_next_arrow = icons.set_from_name("pale_right_arrow")
            self.dark_prev_arrow = icons.set_from_name("dark_left_arrow")
            self.dark_next_arrow = icons.set_from_name("dark_right_arrow")

            # Prev Button
            self.prev_button = Gtk.Button()
            self.prev_button.set_size_request(TOP_BAR_HEIGHT, TOP_BAR_HEIGHT)
            self.prev_button.set_can_focus(False)
            self.prev_button.set_image(self.pale_prev_arrow)

            # Next button
            self.next_button = Gtk.Button()
            self.next_button.set_size_request(TOP_BAR_HEIGHT, TOP_BAR_HEIGHT)
            self.next_button.set_can_focus(False)
            self.next_button.set_image(self.pale_next_arrow)

            self.box.pack_start(self.prev_button, False, False, 0)
            self.box.pack_start(self.next_button, False, False, 0)

            self.add_style(self.prev_button, "top_bar_button")
            self.add_style(self.next_button, "top_bar_button")

            # On start, disable the prev and next buttons
            self.disable_prev()
            self.disable_next()

            attach_cursor_events(self.prev_button)
            attach_cursor_events(self.next_button)

        attach_cursor_events(self.close_button)

        if has_buttons:
            self.box.pack_start(self.align_header, True, True, 0)
            self.box.pack_end(self.close_button, False, False, 0)
            self.box.pack_end(invisible, False, False, 0)
        else:
            self.box.pack_start(invisible, False, False, 0)
            self.box.pack_start(self.align_header, True, True, 0)
            self.box.pack_end(self.close_button, False, False, 0)

        self.box.set_size_request(window_width, 44)

        self.add(self.box)

        styleContext.add_class('top_bar_container')
        self.add_style(self.header, "top_bar_title")