示例#1
0
 def _get_textview(self):
     textview = super(RichTextBox, self)._get_textview()
     text_buffer = textview.get_buffer()
     setup_tags(text_buffer)
     text_buffer.register_serialize_format(str(MIME), serialize, None)
     text_buffer.register_deserialize_format(str(MIME), deserialize, None)
     text_buffer.connect_after(
         'insert-text', self.insert_text_style, textview)
     textview.connect_after('move-cursor', self.detect_style)
     textview.connect('button-release-event', self.detect_style)
     return textview
示例#2
0
    def __init__(self, view, attrs):
        super(RichTextBox, self).__init__(view, attrs)
        self.text_buffer = gtk.TextBuffer()
        setup_tags(self.text_buffer)
        self.text_buffer.register_serialize_format(str(MIME), serialize, None)
        self.text_buffer.register_deserialize_format(str(MIME), deserialize,
                                                     None)
        self.text_buffer.connect_after('insert-text', self.insert_text_style)
        self.textview.set_buffer(self.text_buffer)
        self.textview.connect_after('move-cursor', self.detect_style)
        self.textview.connect('button-release-event', self.detect_style)

        self.toolbar = None
        self.tag_widgets = {}
        self.tags = {}
        self.colors = {}
        if int(self.attrs.get('toolbar', 1)):
            self.toolbar = self.get_toolbar()
示例#3
0
def register_format(textview):
    buffer_ = textview.get_buffer()
    setup_tags(buffer_)
    buffer_.register_serialize_format(str(MIME), serialize, None)
    buffer_.register_deserialize_format(str(MIME), deserialize, None)
示例#4
0
    def __init__(self, view, attrs):
        super(RichTextBox, self).__init__(view, attrs)
        self.text_buffer = gtk.TextBuffer()
        setup_tags(self.text_buffer)
        self.text_buffer.register_serialize_format(MIME, serialize, None)
        self.text_buffer.register_deserialize_format(MIME, deserialize, None)
        self.text_buffer.connect_after('insert-text', self.insert_text_style)
        self.textview.set_buffer(self.text_buffer)
        self.textview.connect_after('move-cursor', self.detect_style)
        self.textview.connect('button-release-event', self.detect_style)

        self.toolbar = gtk.Toolbar()
        self.toolbar.set_style({
            'default': False,
            'both': gtk.TOOLBAR_BOTH,
            'text': gtk.TOOLBAR_TEXT,
            'icons': gtk.TOOLBAR_ICONS
        }[CONFIG['client.toolbar']])

        self.widget.pack_start(self.toolbar, expand=False, fill=True)
        self.tag_widgets = {}
        self.tags = {}

        for icon in ['bold', 'italic', 'underline']:
            button = gtk.ToggleToolButton('gtk-%s' % icon)
            button.connect('toggled', self.toggle_props, icon)
            self.toolbar.insert(button, -1)
            self.tag_widgets[icon] = button

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        for name, options, active in [
            ('family', FAMILIES, FAMILIES.index('normal')),
            ('size', SIZES, SIZES.index('4')),
        ]:
            try:
                combobox = gtk.ComboBoxText()
            except AttributeError:
                combobox = gtk.combo_box_new_text()
            for option in options:
                combobox.append_text(option)
            combobox.set_active(active)
            combobox.set_focus_on_click(False)
            combobox.connect('changed', self.change_props, name)
            tool = gtk.ToolItem()
            tool.add(combobox)
            self.toolbar.insert(tool, -1)
            self.tag_widgets[name] = combobox

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        button = None
        for icon in ['left', 'center', 'right', 'fill']:
            name = icon
            if icon == 'fill':
                name = 'justify'
            button = gtk.RadioToolButton(button, 'gtk-justify-%s' % icon)
            button.set_active(icon == 'left')
            button.connect('toggled', self.toggle_justification, name)
            self.toolbar.insert(button, -1)
            self.tag_widgets[name] = button

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        self.colors = {}
        for icon, label in [
            ('foreground', _('Foreground')),
                # TODO ('background', _('Background')),
        ]:
            button = gtk.ToolButton('tryton-text-%s' % icon)
            button.set_label(label)
            button.connect('clicked', self.toggle_color, icon)
            self.toolbar.insert(button, -1)
            self.tag_widgets[icon] = button
示例#5
0
    def __init__(self, view, attrs):
        super(RichTextBox, self).__init__(view, attrs)
        self.text_buffer = gtk.TextBuffer()
        setup_tags(self.text_buffer)
        self.text_buffer.register_serialize_format(
            MIME, serialize, None)
        self.text_buffer.register_deserialize_format(
            MIME, deserialize, None)
        self.text_buffer.connect_after('insert-text', self.insert_text_style)
        self.textview.set_buffer(self.text_buffer)
        self.textview.connect_after('move-cursor', self.detect_style)
        self.textview.connect('button-release-event', self.detect_style)

        self.toolbar = gtk.Toolbar()
        self.toolbar.set_style({
                'default': False,
                'both': gtk.TOOLBAR_BOTH,
                'text': gtk.TOOLBAR_TEXT,
                'icons': gtk.TOOLBAR_ICONS}[CONFIG['client.toolbar']])

        self.widget.pack_start(self.toolbar, expand=False, fill=True)
        self.tag_widgets = {}
        self.tags = {}

        for icon in ['bold', 'italic', 'underline']:
            button = gtk.ToggleToolButton('gtk-%s' % icon)
            button.connect('toggled', self.toggle_props, icon)
            self.toolbar.insert(button, -1)
            self.tag_widgets[icon] = button

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        for name, options, active in [
                ('family', FAMILIES, FAMILIES.index('normal')),
                ('size', SIZES, SIZES.index('4')),
                ]:
            try:
                combobox = gtk.ComboBoxText()
            except AttributeError:
                combobox = gtk.combo_box_new_text()
            for option in options:
                combobox.append_text(option)
            combobox.set_active(active)
            combobox.set_focus_on_click(False)
            combobox.connect('changed', self.change_props, name)
            tool = gtk.ToolItem()
            tool.add(combobox)
            self.toolbar.insert(tool, -1)
            self.tag_widgets[name] = combobox

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        button = None
        for icon in ['left', 'center', 'right', 'fill']:
            name = icon
            if icon == 'fill':
                name = 'justify'
            button = gtk.RadioToolButton(button, 'gtk-justify-%s' % icon)
            button.set_active(icon == 'left')
            button.connect('toggled', self.toggle_justification, name)
            self.toolbar.insert(button, -1)
            self.tag_widgets[name] = button

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        self.colors = {}
        for icon, label in [
                ('foreground', _('Foreground')),
                # TODO ('background', _('Background')),
                ]:
            button = gtk.ToolButton('tryton-text-%s' % icon)
            button.set_label(label)
            button.connect('clicked', self.toggle_color, icon)
            self.toolbar.insert(button, -1)
            self.tag_widgets[icon] = button