Beispiel #1
0
    def __init__(self, word, theme_index, star_state=False):
        self.scroll = gtk.ScrolledWindow()
        self.scroll.set_size_request(500, 400)
        self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        v_box = gtk.VBox()
        self.__block_list = []
        string = (
            '<span font_desc="Sans Bold 17" font_family="Serif">%s</s\
pan>'
            % (word.query)
        )
        (attr, default_text, unused_char) = pango.parse_markup(string, accel_marker=u"\x00")
        label = gtk.Label()
        alignment = gtk.Alignment(xalign=0.0, yalign=0.0, xscale=0.0, yscale=0.0)
        h_box = gtk.HBox(spacing=10)
        label.set_attributes(attr)
        label.set_text(default_text)
        unused = gtk.Label("")
        unused.set_selectable(True)
        label.set_selectable(True)
        height = width = not theme_index and 60 or 32
        speaker = Speaker(theme_index, width, height)
        speaker.set_tooltip('<span font_desc="Sans 10">spell</span>')
        if word.sound_url:
            speaker_id = speaker.connect("speaker_on", self.play_text, "", word.sound_url)
        else:
            speaker_id = speaker.connect("speaker_on", self.play_text, word.query)
        self.__block_list.append((speaker, speaker_id))
        star = Star(star_state)
        star.connect("starred", self.__update_database, word)
        h_box.pack_start(unused)
        h_box.pack_start(star())
        h_box.pack_start(label)
        h_box.pack_start(speaker())
        alignment.add(h_box)
        v_box.pack_start(alignment)
        string = ""
        for meaning in word.meaning:
            string += u'<span font_desc="Sans 12" font_family="Serif">\n\t' + meaning + "</span>"
        if string:
            (attr, default_text, unused_char) = pango.parse_markup(string, accel_marker=u"\x00")
            label = gtk.Label()
            label.set_attributes(attr)
            label.set_text(default_text)
            label.set_selectable(True)
            alignment = gtk.Alignment(xalign=0.0, yalign=0.0, xscale=0.0, yscale=0.0)
            alignment.add(label)
            v_box.pack_start(alignment)
        if word.image or word.alt_image:
            fixed = gtk.Fixed()
            rms = 0.0
            if word.image and word.alt_image:
                path_1, path_2 = HOME_PATH + "/.plexicon/data/image1.gif", HOME_PATH + "/.plexicon/data/image2.gif"
                file_1, file_2 = open(path_1, "wb"), open(path_2, "wb")
                file_1.write(word.image)
                file_2.write(word.alt_image)
                file_1.close()
                file_2.close()
                import Image, math, operator

                hist1 = Image.open(path_1).histogram()
                hist2 = Image.open(path_2).histogram()
                rms = math.sqrt(reduce(operator.add, map(lambda a, b: (a - b) ** 2, hist1, hist2)) / len(hist1))
                if not rms:
                    word.alt_image = ""
            if rms != 0.0:
                image_1, image_2 = (
                    gtk.image_new_from_pixbuf(gtk.gdk.pixbuf_new_from_file(path_1)),
                    gtk.image_new_from_pixbuf(gtk.gdk.pixbuf_new_from_file(path_2)),
                )
                fixed.put(image_1, 20, 0)
                fixed.put(image_2, 40 + image_1.requisition.width, 0)
            else:
                cur = word.image == "" and [word.alt_image] or [word.image]
                path = HOME_PATH + "/.plexicon/data/image.gif"
                image_file = open(path, "wb")
                image_file.write(cur[0])
                image_file.close()
                image = gtk.image_new_from_pixbuf(gtk.gdk.pixbuf_new_from_file(path))
                x_coordinate = 500 >= image.requisition.width and (500 - image.requisition.width) / 2 or 0
                fixed.put(image, x_coordinate, 0)
            v_box.pack_start(gtk.Label(""), True, True)
            expander = gtk.Expander()
            expander.set_use_markup(True)
            expander.set_use_underline(True)
            expander.set_tooltip_markup(
                '<span font_desc="Sans 10"><sub>click \
to expand</sub></span>'
            )
            expander.set_label(
                '<span font_desc="Sans 10" foreground="#ff0000">\
'
                + u"\u2605" * 12
                + '  <span font_desc="Sans 10" foreground="#0000ff">_More De\
finitions</span>  '
                + u"\u2605" * 14
                + "</span>"
            )
            expander.set_spacing(10)
            expander.add(fixed)
            v_box.pack_start(expander)
        alignment = gtk.Alignment(xalign=0.0, yalign=0.0, xscale=0.0, yscale=0.0)
        alignment.add(v_box)
        self.scroll.add_with_viewport(alignment)
        self.scroll.get_child().modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff"))
Beispiel #2
0
    def __init__(self, word, theme_index, star_state = False):
        self.scroll = gtk.ScrolledWindow()
        self.scroll.set_size_request(500, 400)
        self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        v_box = gtk.VBox()
        self.__block_list = []
        for part in word.parts_of_speeches:
            string = '<span font_desc="Sans Bold 17" font_family="Serif">%s\
</span><span font_desc="Sans 12" font_family="Serif" foreground="#666666">  %s\
</span><span font_desc="Ubuntu 15" font_family="Ubuntu">' % (part.word,
                                                           part.part_of_speech)
            for text in part.phonetic:
                string += '  ' + text
            string += '</span>'
            (attr, default_text, unused_char) = pango.parse_markup(string,
                                                        accel_marker = u'\x00')
            label = gtk.Label()
            alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0, xscale = 0.0,
                                      yscale = 0.0)
            h_box = gtk.HBox(spacing = 10)
            label.set_attributes(attr)
            unused = gtk.Label('')
            unused.set_selectable(True)
            label.set_selectable(True)
            label.set_text(default_text)
            height = width = not theme_index and 60 or 32
            speaker = Speaker(theme_index, width, height)
            speaker.set_tooltip('<span font_desc="Sans 10">spell</span>')
            if part.sound_url:
                speaker_id = speaker.connect("speaker_on", self.play_text, '',
                                             part.sound_url)
            else:
                speaker_id = speaker.connect("speaker_on", self.play_text,
                                             part.word)
            self.__block_list.append((speaker, speaker_id))
            star = Star(star_state)
            star.connect("starred", self.__update_database, word)
            h_box.pack_start(unused)
            h_box.pack_start(star())
            h_box.pack_start(label)
            h_box.pack_start(speaker())
            alignment.add(h_box)
            v_box.pack_start(alignment)
            string = ''
            if len(part.synonym):
                string += '\n<span font_desc="Sans Bold 10" font_family="Serif\
">Synonym : </span><span font_desc="Sans 10" foreground="#006B33" font_family=\
"Serif">'
                count = 0
                for syn in part.synonym:
                    count += 1
                    if count > 8:
                        count -= 8
                        string = string[:-2]
                        string += '\n                     '
                    string += syn + ', '
                string = string[:-2]
                string += '</span>'
            if len(part.antonym):
                string += '\n<span font_desc="Sans Bold 10" font_family="Serif\
">Antonym : </span><span font_desc="Sans 10" foreground="#ff0000" font_family=\
"Serif">'
                count = 0
                for ant in part.antonym:
                    count += 1
                    if count > 8:
                        count -= 8
                        string = string[:-2]
                        string += '\n                     '
                    string += ant + ', '
                string = string[:-2]
                string += '</span>'
            if len(part.related):
                string += '\n<span font_desc="Sans Bold 10" font_family="Serif\
">Related : </span>'
                count = 0
                for tense, default_text in part.related:
                    count += 1
                    if count > 4:
                        count -= 4
                        string = string[:-4]
                        string += '\n                        '
                    string += '<span font_desc="Sans 10" foreground="#0082FF" \
font_family="Serif"><b>' + default_text + '</b><span foreground="#666666"><i><\
sub> ' + tense + '</sub></i></span></span>    '
                string = string[:-4]
            if string:
                (attr, default_text, unused_char) = pango.parse_markup(string,
                                                        accel_marker = u'\x00')
                label = gtk.Label()
                label.set_attributes(attr)
                label.set_selectable(True)
                label.set_text(default_text)
                alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
                                          xscale = 0.0, yscale = 0.0)
                alignment.add(label)
                v_box.pack_start(alignment)
            if part.meaning:
                index = 0
                for key in part.meaning.keys():
                    index += 1
                    string = ''
                    meaning = key.replace("<em>", '<i><u>').replace('</em>',
                                                                    '</u></i>')
                    string += '<span font_desc="Sans 11" font_family="Serif">\
\t%d.  %s</span>\n' % (index, meaning)
                    (attr, default_text, unused_char) = pango.parse_markup(
                                                string, accel_marker = u'\x00')
                    label = gtk.Label()
                    alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
                                              xscale = 0.0, yscale = 0.0)
                    label.set_attributes(attr)
                    label.set_selectable(True)
                    label.set_text(default_text)
                    height = width = not theme_index and 28 or 18
                    speaker = Speaker(theme_index, width, height, 0, 0)
                    speaker.set_tooltip('<span font_desc="Sans 10">spell</span\
>')
                    speaker_id = speaker.connect("speaker_on", self.play_text,
                                                 default_text[5:])
                    self.__block_list.append((speaker, speaker_id))
                    h_box = gtk.HBox(spacing = 10)
                    h_box.pack_start(label)
                    h_box.pack_start(speaker())
                    alignment.add(h_box)
                    v_box.pack_start(alignment)
                    string = ''
                    for default_text in part.meaning[key]:
                        default_text = default_text.replace("<em>", '<i><u><sp\
an  foreground="#984BE2">').replace('</em>', '</span></u></i>')
                        if default_text:
                            string += u'<span font_desc="Sans 10" foreground="\
#FF6A00"font_family="Serif">\t\t\u00BB ' + default_text + '</span>\n'
                    if string:
                        (attr, default_text, unused_char) = pango.parse_markup(
                                                string, accel_marker = u'\x00')
                        label = gtk.Label()
                        label.set_attributes(attr)
                        label.set_selectable(True)
                        label.set_text(default_text)
                        alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
                                                  xscale = 0.0, yscale = 0.0)
                        alignment.add(label)
                        v_box.pack_start(alignment)
            if part.example:
                string = '<span font_desc="Sans 10" foreground="#FF6A00">'
                for example in part.example:
                    example = example.replace(part.word.lower(), '<i><u><span \
foreground="#984BE2">' + part.word.lower() + '</span></u></i>')
                    string += u'\n\t\t<span foreground="#0000ff">\u2666</span>\
    ' + example
                string += '</span>\n\n'
                (attr, default_text, unused_char) = pango.parse_markup(string,
                                                        accel_marker = u'\x00')
                label = gtk.Label()
                label.set_attributes(attr)
                label.set_selectable(True)
                label.set_text(default_text)
                alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
                                          xscale = 0.0, yscale = 0.0)
                alignment.add(label)
                expander = gtk.Expander()
                expander.set_use_markup(True)
                expander.set_use_underline(True)
                expander.set_tooltip_markup('<span font_desc="Sans 10"><sub>cl\
ick to expand</sub></span>')
                expander.set_label('<span font_desc="Sans 10" foreground="#FF0\
000">_More Examples</span>')
                expander.set_spacing(0)
                expander.add(alignment)
                v_box.pack_start(expander)
        alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
                                  xscale = 1.0, yscale = 0.0)
        alignment.add(v_box)
        self.scroll.add_with_viewport(alignment)
        self.scroll.get_child().modify_bg(gtk.STATE_NORMAL,
                                          gtk.gdk.color_parse('#ffffff'))
Beispiel #3
0
    def __init__(self, word, theme_index, star_state=False):
        self.scroll = gtk.ScrolledWindow()
        self.scroll.set_size_request(500, 400)
        self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        v_box = gtk.VBox()
        self.__block_list = []
        for part in word.parts_of_speeches:
            string = '<span font_desc="Sans Bold 17" font_family="Serif">%s\
</span><span font_desc="Sans 12" font_family="Serif" foreground="#666666">  %s\
</span><span font_desc="Ubuntu 15" font_family="Ubuntu">' % (
                part.word, part.part_of_speech)
            for text in part.phonetic:
                string += '  ' + text
            string += '</span>'
            (attr, default_text,
             unused_char) = pango.parse_markup(string, accel_marker=u'\x00')
            label = gtk.Label()
            alignment = gtk.Alignment(xalign=0.0,
                                      yalign=0.0,
                                      xscale=0.0,
                                      yscale=0.0)
            h_box = gtk.HBox(spacing=10)
            label.set_attributes(attr)
            unused = gtk.Label('')
            unused.set_selectable(True)
            label.set_selectable(True)
            label.set_text(default_text)
            height = width = not theme_index and 60 or 32
            speaker = Speaker(theme_index, width, height)
            speaker.set_tooltip('<span font_desc="Sans 10">spell</span>')
            if part.sound_url:
                speaker_id = speaker.connect("speaker_on", self.play_text, '',
                                             part.sound_url)
            else:
                speaker_id = speaker.connect("speaker_on", self.play_text,
                                             part.word)
            self.__block_list.append((speaker, speaker_id))
            star = Star(star_state)
            star.connect("starred", self.__update_database, word)
            h_box.pack_start(unused)
            h_box.pack_start(star())
            h_box.pack_start(label)
            h_box.pack_start(speaker())
            alignment.add(h_box)
            v_box.pack_start(alignment)
            string = ''
            if len(part.synonym):
                string += '\n<span font_desc="Sans Bold 10" font_family="Serif\
">Synonym : </span><span font_desc="Sans 10" foreground="#006B33" font_family=\
"Serif">'

                count = 0
                for syn in part.synonym:
                    count += 1
                    if count > 8:
                        count -= 8
                        string = string[:-2]
                        string += '\n                     '
                    string += syn + ', '
                string = string[:-2]
                string += '</span>'
            if len(part.antonym):
                string += '\n<span font_desc="Sans Bold 10" font_family="Serif\
">Antonym : </span><span font_desc="Sans 10" foreground="#ff0000" font_family=\
"Serif">'

                count = 0
                for ant in part.antonym:
                    count += 1
                    if count > 8:
                        count -= 8
                        string = string[:-2]
                        string += '\n                     '
                    string += ant + ', '
                string = string[:-2]
                string += '</span>'
            if len(part.related):
                string += '\n<span font_desc="Sans Bold 10" font_family="Serif\
">Related : </span>'

                count = 0
                for tense, default_text in part.related:
                    count += 1
                    if count > 4:
                        count -= 4
                        string = string[:-4]
                        string += '\n                        '
                    string += '<span font_desc="Sans 10" foreground="#0082FF" \
font_family="Serif"><b>' + default_text + '</b><span foreground="#666666"><i><\
sub> ' + tense + '</sub></i></span></span>    '
                string = string[:-4]
            if string:
                (attr, default_text,
                 unused_char) = pango.parse_markup(string,
                                                   accel_marker=u'\x00')
                label = gtk.Label()
                label.set_attributes(attr)
                label.set_selectable(True)
                label.set_text(default_text)
                alignment = gtk.Alignment(xalign=0.0,
                                          yalign=0.0,
                                          xscale=0.0,
                                          yscale=0.0)
                alignment.add(label)
                v_box.pack_start(alignment)
            if part.meaning:
                index = 0
                for key in part.meaning.keys():
                    index += 1
                    string = ''
                    meaning = key.replace("<em>", '<i><u>').replace(
                        '</em>', '</u></i>')
                    string += '<span font_desc="Sans 11" font_family="Serif">\
\t%d.  %s</span>\n' % (index, meaning)
                    (attr, default_text,
                     unused_char) = pango.parse_markup(string,
                                                       accel_marker=u'\x00')
                    label = gtk.Label()
                    alignment = gtk.Alignment(xalign=0.0,
                                              yalign=0.5,
                                              xscale=0.0,
                                              yscale=0.0)
                    label.set_attributes(attr)
                    label.set_selectable(True)
                    label.set_text(default_text)
                    height = width = not theme_index and 28 or 18
                    speaker = Speaker(theme_index, width, height, 0, 0)
                    speaker.set_tooltip('<span font_desc="Sans 10">spell</span\
>')
                    speaker_id = speaker.connect("speaker_on", self.play_text,
                                                 default_text[5:])
                    self.__block_list.append((speaker, speaker_id))
                    h_box = gtk.HBox(spacing=10)
                    h_box.pack_start(label)
                    h_box.pack_start(speaker())
                    alignment.add(h_box)
                    v_box.pack_start(alignment)
                    string = ''
                    for default_text in part.meaning[key]:
                        default_text = default_text.replace(
                            "<em>", '<i><u><sp\
an  foreground="#984BE2">').replace('</em>', '</span></u></i>')
                        if default_text:
                            string += u'<span font_desc="Sans 10" foreground="\
#FF6A00"font_family="Serif">\t\t\u00BB ' + default_text + '</span>\n'
                    if string:
                        (attr, default_text, unused_char) = pango.parse_markup(
                            string, accel_marker=u'\x00')
                        label = gtk.Label()
                        label.set_attributes(attr)
                        label.set_selectable(True)
                        label.set_text(default_text)
                        alignment = gtk.Alignment(xalign=0.0,
                                                  yalign=0.0,
                                                  xscale=0.0,
                                                  yscale=0.0)
                        alignment.add(label)
                        v_box.pack_start(alignment)
            if part.example:
                string = '<span font_desc="Sans 10" foreground="#FF6A00">'
                for example in part.example:
                    example = example.replace(
                        part.word.lower(), '<i><u><span \
foreground="#984BE2">' + part.word.lower() + '</span></u></i>')
                    string += u'\n\t\t<span foreground="#0000ff">\u2666</span>\
    ' + example
                string += '</span>\n\n'
                (attr, default_text,
                 unused_char) = pango.parse_markup(string,
                                                   accel_marker=u'\x00')
                label = gtk.Label()
                label.set_attributes(attr)
                label.set_selectable(True)
                label.set_text(default_text)
                alignment = gtk.Alignment(xalign=0.0,
                                          yalign=0.0,
                                          xscale=0.0,
                                          yscale=0.0)
                alignment.add(label)
                expander = gtk.Expander()
                expander.set_use_markup(True)
                expander.set_use_underline(True)
                expander.set_tooltip_markup('<span font_desc="Sans 10"><sub>cl\
ick to expand</sub></span>')
                expander.set_label('<span font_desc="Sans 10" foreground="#FF0\
000">_More Examples</span>')
                expander.set_spacing(0)
                expander.add(alignment)
                v_box.pack_start(expander)
        alignment = gtk.Alignment(xalign=0.0,
                                  yalign=0.0,
                                  xscale=1.0,
                                  yscale=0.0)
        alignment.add(v_box)
        self.scroll.add_with_viewport(alignment)
        self.scroll.get_child().modify_bg(gtk.STATE_NORMAL,
                                          gtk.gdk.color_parse('#ffffff'))
Beispiel #4
0
    def __init__(self, word, theme_index, star_state=False):
        self.scroll = gtk.ScrolledWindow()
        self.scroll.set_size_request(500, 400)
        self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        v_box = gtk.VBox()
        self.__block_list = []
        string = '<span font_desc="Sans Bold 17" font_family="Serif">%s</s\
pan>' % (word.query)
        (attr, default_text,
         unused_char) = pango.parse_markup(string, accel_marker=u'\x00')
        label = gtk.Label()
        alignment = gtk.Alignment(xalign=0.0,
                                  yalign=0.0,
                                  xscale=0.0,
                                  yscale=0.0)
        h_box = gtk.HBox(spacing=10)
        label.set_attributes(attr)
        label.set_text(default_text)
        unused = gtk.Label('')
        unused.set_selectable(True)
        label.set_selectable(True)
        height = width = not theme_index and 60 or 32
        speaker = Speaker(theme_index, width, height)
        speaker.set_tooltip('<span font_desc="Sans 10">spell</span>')
        if word.sound_url:
            speaker_id = speaker.connect("speaker_on", self.play_text, '',
                                         word.sound_url)
        else:
            speaker_id = speaker.connect("speaker_on", self.play_text,
                                         word.query)
        self.__block_list.append((speaker, speaker_id))
        star = Star(star_state)
        star.connect("starred", self.__update_database, word)
        h_box.pack_start(unused)
        h_box.pack_start(star())
        h_box.pack_start(label)
        h_box.pack_start(speaker())
        alignment.add(h_box)
        v_box.pack_start(alignment)
        string = ''
        for meaning in word.meaning:
            string += u'<span font_desc="Sans 12" font_family="Serif">\n\t'\
            + meaning + '</span>'
        if string:
            (attr, default_text,
             unused_char) = pango.parse_markup(string, accel_marker=u'\x00')
            label = gtk.Label()
            label.set_attributes(attr)
            label.set_text(default_text)
            label.set_selectable(True)
            alignment = gtk.Alignment(xalign=0.0,
                                      yalign=0.0,
                                      xscale=0.0,
                                      yscale=0.0)
            alignment.add(label)
            v_box.pack_start(alignment)
        if word.image or word.alt_image:
            fixed = gtk.Fixed()
            rms = 0.0
            if word.image and word.alt_image:
                path_1, path_2 = HOME_PATH + '/.plexicon/data/image1.gif', \
                                 HOME_PATH + '/.plexicon/data/image2.gif'
                file_1, file_2 = open(path_1, 'wb'), \
                                 open(path_2, 'wb')
                file_1.write(word.image)
                file_2.write(word.alt_image)
                file_1.close()
                file_2.close()
                import Image, math, operator
                hist1 = Image.open(path_1).histogram()
                hist2 = Image.open(path_2).histogram()
                rms = math.sqrt(
                    reduce(operator.add,
                           map(lambda a, b:
                               (a - b)**2, hist1, hist2)) / len(hist1))
                if not rms:
                    word.alt_image = ''
            if rms != 0.0:
                image_1, image_2 = gtk.image_new_from_pixbuf(gtk.gdk. \
                                       pixbuf_new_from_file(path_1)), \
                                   gtk.image_new_from_pixbuf(gtk.gdk. \
                                       pixbuf_new_from_file(path_2))
                fixed.put(image_1, 20, 0)
                fixed.put(image_2, 40 + image_1.requisition.width, 0)
            else:
                cur = word.image == '' and [word.alt_image] or [word.image]
                path = HOME_PATH + '/.plexicon/data/image.gif'
                image_file = open(path, 'wb')
                image_file.write(cur[0])
                image_file.close()
                image = gtk.image_new_from_pixbuf(
                    gtk.gdk.pixbuf_new_from_file(path))
                x_coordinate = 500 >= image.requisition.width and (500 - \
                                              image.requisition.width) / 2 or 0
                fixed.put(image, x_coordinate, 0)
            v_box.pack_start(gtk.Label(''), True, True)
            expander = gtk.Expander()
            expander.set_use_markup(True)
            expander.set_use_underline(True)
            expander.set_tooltip_markup('<span font_desc="Sans 10"><sub>click \
to expand</sub></span>')
            expander.set_label(
                '<span font_desc="Sans 10" foreground="#ff0000">\
' + u'\u2605' * 12 +
                '  <span font_desc="Sans 10" foreground="#0000ff">_More De\
finitions</span>  ' + u'\u2605' * 14 + '</span>')
            expander.set_spacing(10)
            expander.add(fixed)
            v_box.pack_start(expander)
        alignment = gtk.Alignment(xalign=0.0,
                                  yalign=0.0,
                                  xscale=0.0,
                                  yscale=0.0)
        alignment.add(v_box)
        self.scroll.add_with_viewport(alignment)
        self.scroll.get_child().modify_bg(gtk.STATE_NORMAL,
                                          gtk.gdk.color_parse('#ffffff'))