Exemplo n.º 1
0
    def make_toolbar(self, toolbar, tips, use_stock_icons):

        # bold tool
        self.bold = self._make_toggle_button(
            toolbar, tips, "Bold", "bold.png", gtk.STOCK_BOLD,
            lambda: self._editor.get_textview().toggle_font_mod("bold"),
            use_stock_icons)

        # italic tool
        self.italic = self._make_toggle_button(
            toolbar, tips, "Italic", "italic.png", gtk.STOCK_ITALIC,
            lambda: self._editor.get_textview().toggle_font_mod("italic"),
            use_stock_icons)

        # underline tool
        self.underline = self._make_toggle_button(
            toolbar, tips, "Underline", "underline.png", gtk.STOCK_UNDERLINE,
            lambda: self._editor.get_textview().toggle_font_mod("underline"),
            use_stock_icons)

        # strikethrough
        self.strike = self._make_toggle_button(
            toolbar, tips, "Strike", "strike.png", gtk.STOCK_STRIKETHROUGH,
            lambda: self._editor.get_textview().toggle_font_mod("strike"),
            use_stock_icons)

        # fixed-width tool
        self.fixed_width = self._make_toggle_button(
            toolbar, tips, "Monospace", "fixed-width.png", None,
            lambda: self._editor.get_textview().toggle_font_mod("tt"),
            use_stock_icons)

        # link
        self.link = self._make_toggle_button(toolbar, tips, "Make Link",
                                             "link.png", None,
                                             self.on_toggle_link,
                                             use_stock_icons)

        # no wrap tool
        self.no_wrap = self._make_toggle_button(
            toolbar, tips, "No Wrapping", "no-wrap.png", None,
            lambda: self._editor.get_textview().toggle_font_mod("nowrap"),
            use_stock_icons)

        # family combo
        self.font_family_combo = FontSelector()
        self.font_family_combo.set_size_request(150, 25)
        item = gtk.ToolItem()
        item.add(self.font_family_combo)
        tips.set_tip(item, "Font Family")
        toolbar.insert(item, -1)
        self.font_family_id = self.font_family_combo.connect(
            "changed", lambda w: self.on_family_set())
        self._font_ui_signals.append(
            FontUI(self.font_family_combo, self.font_family_id))

        # font size
        DEFAULT_FONT_SIZE = 10
        self.font_size_button = gtk.SpinButton(
            gtk.Adjustment(value=DEFAULT_FONT_SIZE,
                           lower=2,
                           upper=500,
                           step_incr=1))
        self.font_size_button.set_size_request(-1, 25)
        #self.font_size_button.set_range(2, 100)
        self.font_size_button.set_value(DEFAULT_FONT_SIZE)
        self.font_size_button.set_editable(False)
        item = gtk.ToolItem()
        item.add(self.font_size_button)
        tips.set_tip(item, "Font Size")
        toolbar.insert(item, -1)
        self.font_size_id = self.font_size_button.connect(
            "value-changed",
            lambda w: self.on_font_size_change(self.font_size_button.get_value(
            )))
        self._font_ui_signals.append(
            FontUI(self.font_size_button, self.font_size_id))

        # font fg color
        # TODO: code in proper default color
        self.fg_color_button = FgColorTool(14, 15, (0, 0, 0))
        self.fg_color_button.connect(
            "set-color", lambda w, color: self.on_color_set("fg", color))
        tips.set_tip(self.fg_color_button, "Set Text Color")
        toolbar.insert(self.fg_color_button, -1)

        # font bg color
        self.bg_color_button = BgColorTool(14, 15, (65535, 65535, 65535))
        self.bg_color_button.connect(
            "set-color", lambda w, color: self.on_color_set("bg", color))
        tips.set_tip(self.bg_color_button, "Set Background Color")
        toolbar.insert(self.bg_color_button, -1)

        # separator
        toolbar.insert(gtk.SeparatorToolItem(), -1)

        # left tool
        self.left_align = self._make_toggle_button(
            toolbar, tips, "Left Align", "alignleft.png",
            gtk.STOCK_JUSTIFY_LEFT, lambda: self.on_justify("left"),
            use_stock_icons)

        # center tool
        self.center_align = self._make_toggle_button(
            toolbar, tips, "Center Align", "aligncenter.png",
            gtk.STOCK_JUSTIFY_CENTER, lambda: self.on_justify("center"),
            use_stock_icons)

        # right tool
        self.right_align = self._make_toggle_button(
            toolbar, tips, "Right Align", "alignright.png",
            gtk.STOCK_JUSTIFY_RIGHT, lambda: self.on_justify("right"),
            use_stock_icons)

        # justify tool
        self.fill_align = self._make_toggle_button(
            toolbar, tips, "Justify Align", "alignjustify.png",
            gtk.STOCK_JUSTIFY_FILL, lambda: self.on_justify("fill"),
            use_stock_icons)

        # bullet list tool
        self.bullet = self._make_toggle_button(toolbar, tips, "Bullet List",
                                               "bullet.png", None,
                                               lambda: self.on_bullet_list(),
                                               use_stock_icons)