Exemplo n.º 1
0
def custom_insert_markup(buff,  markup):
    tagText = cTagText()
    tagText.parse_markup(markup)
    tagText.replace_parsed('&lt;i&gt;', '<i>')
    tagText.replace_parsed('&lt;/i&gt;', '</i>')
    buff.set_property('text', tagText.text)

    # Setup Color Tags (if any)
    color_tags = set()
    for tag in tagText.tags:
        if 'foreground' in tag.attributes and 'background' in tag.attributes:
            buff.create_tag(tag.id, foreground=tag.attributes['foreground'], background=tag.attributes['background'])
            color_tags.add(tag.id)
        if 'foreground' in tag.attributes and not 'background' in tag.attributes:
            buff.create_tag(tag.id, foreground=tag.attributes['foreground'])
            color_tags.add(tag.id)
        if 'background' in tag.attributes and not 'foreground' in tag.attributes:
            buff.create_tag(tag.id, background=tag.attributes['background'])
            color_tags.add(tag.id)

    # Apply Tags
    for tag in tagText.tags:
        if tag.name == 'i':
            buff.apply_tag_by_name('italics', buff.get_iter_at_offset(tag.start), buff.get_iter_at_offset(tag.stop))
        if tag.name == 'b':
            buff.apply_tag_by_name('bold', buff.get_iter_at_offset(tag.start), buff.get_iter_at_offset(tag.stop))
        if tag.name == 'span' and tag.id in color_tags:
                buff.apply_tag_by_name(tag.id, buff.get_iter_at_offset(tag.start), buff.get_iter_at_offset(tag.stop))
Exemplo n.º 2
0
def custom_insert_markup(buff,  markup):
    tagText = cTagText()
    tagText.parse_markup(markup)
    tagText.replace_parsed('&lt;i&gt;', '<i>')
    tagText.replace_parsed('&lt;/i&gt;', '</i>')
    buff.set_property('text', tagText.text)

    # Setup Color Tags (if any)
    color_tags = set()
    for tag in tagText.tags:
        if 'foreground' in tag.attributes and 'background' in tag.attributes:
            buff.create_tag(tag.id, foreground=tag.attributes['foreground'], background=tag.attributes['background'])
            color_tags.add(tag.id)
        if 'foreground' in tag.attributes and not 'background' in tag.attributes:
            buff.create_tag(tag.id, foreground=tag.attributes['foreground'])
            color_tags.add(tag.id)
        if 'background' in tag.attributes and not 'foreground' in tag.attributes:
            buff.create_tag(tag.id, background=tag.attributes['background'])
            color_tags.add(tag.id)

    # Apply Tags
    for tag in tagText.tags:
        if tag.name == 'i':
            buff.apply_tag_by_name('italics', buff.get_iter_at_offset(tag.start), buff.get_iter_at_offset(tag.stop))
        if tag.name == 'b':
            buff.apply_tag_by_name('bold', buff.get_iter_at_offset(tag.start), buff.get_iter_at_offset(tag.stop))
        if tag.name == 'span' and tag.id in color_tags:
                buff.apply_tag_by_name(tag.id, buff.get_iter_at_offset(tag.start), buff.get_iter_at_offset(tag.stop))
Exemplo n.º 3
0
    def __init__(self, parent, sub, info_type, thesaurus):
        super(cTextEditDialog, self).__init__('Subtitle Text Editor', None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, ("_Cancel", Gtk.ResponseType.CANCEL, "_OK", Gtk.ResponseType.OK))
        self.set_transient_for(parent)
        self.set_default_size(500, 240)
        self.char_count = Gtk.TextView()
        self.char_count.set_property('width-request', 30)
        self.char_count.set_sensitive(False)
        self.thesaurus = thesaurus
        
        self.hbox = Gtk.HBox(spacing = 1)
        self.text_view_box = Gtk.VBox(spacing = 1)
        self.text_view = Gtk.TextView()
        self.text_view.set_size_request(-1, 50)
        self.helper_text_view = Gtk.TextView()
        self.helper_text_view.set_property('editable', False)
        self.helper_text_view.set_property('can-focus', False)
        self.text_view_box.add(self.text_view)
        self.text_view_box.add(self.helper_text_view)

        if info_type == 'info':
            color_list = [(sub.info[key][1], sub.info[key][2]) for key in sub.info if key.startswith('Text')]
            tagText = cTagText()
            tagText.text = sub.text
            for color in color_list:
                for pos in color[0]:
                    tagText.add_tag(Tag('span', pos[0], pos[1], {'background': color[1]}))
            tagText.replace_parsed('<i>', '&lt;i&gt;')
            tagText.replace_parsed('</i>', '&lt;/i&gt;')
            custom_insert_markup(self.text_view.get_buffer(), tagText.markup)
            custom_insert_markup(self.helper_text_view.get_buffer(), sub.info_text_str)
        elif info_type == 'vo':
            self.text_view.get_buffer().set_text(sub.text)
            self.helper_text_view.get_buffer().set_text(sub.vo)

        self.rs_text_label = Gtk.Label('Reading Speed: ')
        self.rs_value_label = Gtk.Label('')
        self.rs_dummylabel = Gtk.Label('\t\t\t\t')
        self.rs_box = Gtk.HBox(spacing = 1)
        self.rs_box.pack_start(self.rs_text_label, False, False, 0)
        self.rs_box.pack_start(self.rs_value_label, False, False, 0)
        self.rs_box.pack_start(self.rs_dummylabel, True, True, 0)

        self.history = cHistory(self.text_view.get_buffer())
        self.text_view.history = self.history

        self.spell = GtkSpell.Checker()
        self.spell.attach(self.text_view)
        self.spell.set_language('el_GR')

        self.hbox.pack_start(self.char_count, False, False, 0)
        self.hbox.pack_end(self.text_view_box, True, True, 0)
        self.vbox.pack_start(self.hbox,True, True, 0)
        self.action_area.pack_start(self.rs_box, False, False, 0)
        self.action_area.reorder_child(self.rs_box, 0)

        self.sub = subtitles.subRec(int(sub.startTime), int(sub.stopTime),  sub.text)
        self.update_count()

        self.vbox.show_all()
        self.set_default_response(Gtk.ResponseType.OK)
        self.changed_handler = self.text_view.get_buffer().connect('changed', self.buffer_changed)
        self.text_view.connect("key-release-event", self.key_release)
        self.text_view.connect("key-press-event", self.key_press)
        self.connect('destroy-event', self.on_destroy)
        self.text = sub.text

        self.text_view.connect('populate-popup',  self.on_tv_populate_popup)
        self.text_view.connect('button-press-event', self.on_tv_button_press)
        self.helper_text_view.connect('populate-popup',  self.on_hp_populate_popup)
        self.helper_text_view.connect('button-press-event', self.on_hp_button_press)
        self.helper_text_view.last_mouse_x = 0
        self.helper_text_view.last_mouse_y = 0
        self.text_view.last_mouse_x  = 0
        self.text_view.last_mouse_y = 0
        self.spell.on_buffer_changed(self.text_view.get_buffer())
Exemplo n.º 4
0
    def __init__(self, parent, sub, info_type, thesaurus):
        super(cTextEditDialog, self).__init__('Subtitle Text Editor', None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, ("_Cancel", Gtk.ResponseType.CANCEL, "_OK", Gtk.ResponseType.OK))
        self.set_transient_for(parent)
        self.set_default_size(500, 240)
        self.char_count = Gtk.TextView()
        self.char_count.set_property('width-request', 30)
        self.char_count.set_sensitive(False)
        self.thesaurus = thesaurus

        self.hbox = Gtk.HBox(spacing = 1)
        self.text_view_box = Gtk.VBox(spacing = 1)
        self.text_view = Gtk.TextView()
        self.text_view.set_size_request(-1, 50)
        self.helper_text_view = Gtk.TextView()
        self.helper_text_view.set_property('editable', False)
        #self.helper_text_view.set_property('can-focus', False)
        self.text_view_box.add(self.text_view)
        self.text_view_box.add(self.helper_text_view)
        self.info_resp_button = None
        self.info_type = info_type

        if info_type == 'info':
            color_list = [(sub.info[key][1], sub.info[key][2]) for key in sub.info if key.startswith('Text')]
            tagText = cTagText()
            tagText.text = sub.text
            for color in color_list:
                for pos in color[0]:
                    tagText.add_tag(Tag('span', pos[0], pos[1], {'background': color[1]}))
            tagText.replace_parsed('<i>', '&lt;i&gt;')
            tagText.replace_parsed('</i>', '&lt;/i&gt;')
            custom_insert_markup(self.text_view.get_buffer(), tagText.markup)
            custom_insert_markup(self.helper_text_view.get_buffer(), sub.info_text_str)
        elif info_type == 'vo':
            self.text_view.get_buffer().set_text(sub.text)
            if sub.vo != '':
                self.helper_text_view.get_buffer().set_text(sub.vo)
            else:
                self.helper_text_view.get_buffer().set_text(sub.text)
        elif info_type == 'copy':
            self.text_view.get_buffer().set_text(sub.text)
            self.helper_text_view.get_buffer().set_text(sub.text)

        self.rs_text_label = Gtk.Label('Reading Speed: ')
        self.rs_value_label = Gtk.Label('')
        self.rs_dummylabel = Gtk.Label('\t\t\t\t')
        self.rs_box = Gtk.HBox(spacing = 1)
        self.rs_box.pack_start(self.rs_text_label, False, False, 0)
        self.rs_box.pack_start(self.rs_value_label, False, False, 0)
        self.rs_box.pack_start(self.rs_dummylabel, True, True, 0)

        self.history = cHistory(self.text_view.get_buffer())
        self.text_view.history = self.history

        self.spell = GtkSpell.Checker()
        self.spell.attach(self.text_view)
        self.spell.set_language('el_GR')

        if info_type == 'info':
            button_next = Gtk.Button('>')
            button_prev = Gtk.Button('<')
            self.hbox.pack_start(button_prev, False, False, 1)
            self.hbox.pack_end(button_next, False, False, 1)
            button_next.connect('clicked', self.on_nav_button, 'next')
            button_prev.connect('clicked', self.on_nav_button, 'prev')

        self.hbox.pack_start(self.char_count, False, False, 0)
        self.hbox.pack_end(self.text_view_box, True, True, 0)
        self.vbox.pack_start(self.hbox,True, True, 0)

        self.action_area.pack_start(self.rs_box, False, False, 0)
        self.action_area.reorder_child(self.rs_box, 0)

        self.sub = subtitles.subRec(int(sub.startTime), int(sub.stopTime),  sub.text)
        self.update_count()

        self.vbox.show_all()

        self.set_default_response(Gtk.ResponseType.OK)
        self.changed_handler = self.text_view.get_buffer().connect('changed', self.buffer_changed)
        self.text_view.connect("key-release-event", self.key_release)
        self.text_view.connect("key-press-event", self.key_press)
        self.connect('destroy-event', self.on_destroy)
        self.text = sub.text

        self.text_view.connect('populate-popup',  self.on_tv_populate_popup)
        self.text_view.connect('button-press-event', self.on_tv_button_press)
        self.helper_text_view.connect('populate-popup',  self.on_hp_populate_popup)
        self.helper_text_view.connect('button-press-event', self.on_hp_button_press)
        self.helper_text_view.last_mouse_x = 0
        self.helper_text_view.last_mouse_y = 0
        self.text_view.last_mouse_x  = 0
        self.text_view.last_mouse_y = 0
        self.spell.on_buffer_changed(self.text_view.get_buffer())
        self.text_view.grab_focus()