Ejemplo n.º 1
0
 def callback_clip(self,clipboard, text, data):
     if text is None:
         self.entry_word.set_text("NO TEXT SELECTED")
     else:
         means = define.get_meaning(text)
         self.entry_word.set_text(text)
        
         text_buffer = self.textview_meaning.get_buffer()
         #Creating tag
         heading_tag = text_buffer.create_tag( "h", size_points=16, weight=pango.WEIGHT_BOLD)
         italics_tag = text_buffer.create_tag( "i", style=pango.STYLE_ITALIC)
         ex_tag = text_buffer.create_tag( "colored", foreground="#FFFF00", background="#FFFFFF")
         color1_tag = text_buffer.create_tag( "colored1", foreground="#060E68", background="#CFD3FC")
         color2_tag = text_buffer.create_tag( "colored2", foreground="#344633", background="#EAF8C3")
             
         position = text_buffer.get_end_iter()
         for sec in means['primaries'].keys():
             meanings = means['primaries'][sec]
             text_buffer.insert_with_tags(position, "\n" + sec , heading_tag)
             position = text_buffer.get_end_iter()
             text_buffer.insert_with_tags(position, "\n---------------")
             for index, m in enumerate(meanings):
                 position = text_buffer.get_end_iter()
                 text_buffer.insert_with_tags(position, "\n" + str(index+1) + ".\t"+ sanitize(m[0]), color1_tag)
                 try:
                     for index, e in enumerate(m[1]): 
                         position = text_buffer.get_end_iter()
                         text_buffer.insert_with_tags(position, "\n" + "\t\t" + str(index + 1) + ". "  + sanitize(e), ex_tag, color2_tag)
                 except: pass
         
         position = text_buffer.get_end_iter()
         text_buffer.insert_with_tags(position, "\nWeb Definitions", heading_tag)
         text_buffer.insert_with_tags(text_buffer.get_end_iter(), "\n---------------")
         for index, defs in enumerate(means['webDefinitions']):
             position = text_buffer.get_end_iter()
             text_buffer.insert_with_tags(position, "\n" + str(index+1) + ".\t" + sanitize(defs) + "\n", color1_tag)
Ejemplo n.º 2
0
#!/usr/bin/python2

import define
import sys
import httplib
import xml.dom.minidom

fname = sys.argv[1]
fdata=open(fname).readlines()
#print fdata
for word in fdata:
     word=word.rstrip('\n')
     means = define.get_meaning(word)

     if means is not None:
    #Short Summary
#    for sec in means['primaries'].keys():
         try:
            sec= means['primaries'].keys()
            meanings = means['primaries'][sec[0]]
            print word,' : ',meanings[0][0]

         except:
            pass
#              print means['webDefinitions'][0]



#       print sec, "\n---------------"
#        for m in meanings:
#             print word,' : ',m[0]
Ejemplo n.º 3
0
import define
import sys
import httplib
import xml.dom.minidom
from HTMLParser import HTMLParser


class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'

means = define.get_meaning(sys.argv[1])
bold = "\033[1m"
reset = "\033[0;0m"


def sanitize(text):
    #text = text.replace("<em>", bold).replace("</em>", reset)
    text = text.replace("<em>", bcolors.OKGREEN).replace("</em>", bcolors.ENDC)
    text = HTMLParser.unescape.__func__(HTMLParser, text)
    return text

if means is not None:
    #Short Summary
    for sec in means['primaries'].keys():
        meanings = means['primaries'][sec]
        print sanitize(sec), "\n---------------"