Skip to content
Snippets Groups Projects
Commit b9bbf763 authored by Benoit Favre's avatar Benoit Favre
Browse files

improve slu synchronization

parent d813dc2b
No related branches found
No related tags found
No related merge requests found
slu: 1
slu: 0
xml_filename: data/homeostasis_25nov.xml
osc_host: 127.0.0.1
osc_port: 1234
asr_model: asr/mika-fred-2.cfg
asr_model: asr/mika-fred-1.cfg
......@@ -60,7 +60,10 @@ class ScriptedASR(Gtk.Window):
found = re.search('section(\d+)\.fst$', section_fst)
if found:
section_id = int(found.group(1))
self.slu[section_id - 1] = slu.SLU(prefix % 'dico_word.txt', prefix % 'dico_action.txt', section_fst, prefix % 'clean_tail.fst', library=library)
self.slu[section_id - 1] = slu.SLU(prefix % 'dico_word.txt', prefix % 'dico_action.txt', section_fst, prefix % 'clean_tail.fst', 'slu/homeostasis_25nov.action', library=library)
if slu_type == 0:
for keyword in self.xmlview.keywords:
keyword.add_listener(self.set_slu_history)
import alternate_slu
self.slu2 = alternate_slu.SLU(xml_filename)
......@@ -124,7 +127,8 @@ class ScriptedASR(Gtk.Window):
self.xmlview.set_section(section_id)
def slu_finished(self, model, slu_output):
slu_output = str(slu_output)
#slu_output = str(slu_output)
#print slu_output
self.slu_actions = model.get_actions().split()
self.slu_output = slu_output
print 'SLU output: "%s", actions: "%s"' % (self.slu_output, ' '.join(self.slu_actions))
......@@ -133,22 +137,22 @@ class ScriptedASR(Gtk.Window):
for action_id in range(len(self.kept_actions), len(self.slu_actions)):
print 'NEW ACTION:', action_id, self.slu_actions[action_id]
action = actions.parse_slu_action(self.slu_actions[action_id])
print action.text
if action.text.startswith('#ENDSEQUENCE('):
pass
elif action.text.startswith('#ENDSECTION('):
new_section = self.xmlview.get_section() + 1
self.confirmer.confirm('Go to section %d?' % (new_section + 1), 3, lambda: self.set_section(new_section))
else:
self.xmlview.highlight(action)
actions.perform_action(action, False)
self.kept_history = self.slu_output
self.kept_actions = self.slu_actions
def hyp_changed(self, hyp):
#hyp = ' '.join(hyp).replace('[noise]', ' ').split()
if len(hyp) > len(self.current_section_history):
self.current_section_history.append('')
self.kept_history = self.slu_output
self.kept_actions = self.slu_actions
#self.kept_history = self.slu_output
#self.kept_actions = self.slu_actions
words = hyp[-1].strip().replace('_', ' ').split()
if len(words) == 0:
......@@ -172,6 +176,17 @@ class ScriptedASR(Gtk.Window):
model.process(words, self.kept_history, self.slu_finished, False)
self.current_section_history[-1] = ' '.join(words)
def set_slu_history(self, keyword, uri, num):
for keyword in self.xmlview.keywords[:num + 1]:
keyword.highlight()
for keyword in self.xmlview.keywords[num + 1:]:
keyword.highlight(False)
self.kept_actions = [x.action for x in self.xmlview.keywords[:num + 1]]
self.kept_history = self.slu[self.current_section].get_action_history(num)
print 'SLU set history: history="%s", actions="%s"' % (self.kept_history, ' '.join(self.kept_actions))
self.slu_output = ''
self.slu_actions = []
def hyp_changed2(self, hyp):
section_id = self.xmlview.get_section()
if self.slu2_last_section != section_id:
......
......@@ -7,7 +7,7 @@ _semaphore = None
class SLU:
#/src.new/rocio_slu -word "$prefix"_dico_word.txt -action "$prefix"_dico_action.txt -fstmodel "$prefix".fst -fstclean "$prefix"_clean_tail.fst
def __init__(self, word_lexicon, action_lexicon, model_fst, cleaner_fst, library='slu/src/librocio_slu.so'):
def __init__(self, word_lexicon, action_lexicon, model_fst, cleaner_fst, action_history, library='slu/src/librocio_slu.so'):
global _backend, _semaphore
if _backend == None:
_backend = cdll.LoadLibrary(library)
......@@ -45,11 +45,23 @@ class SLU:
_backend.free.restype = None
_semaphore = threading.Semaphore()
self.load_action_history(action_history)
_semaphore.acquire()
thread = threading.Thread(target=self._init_thread, args=[word_lexicon, action_lexicon, model_fst, cleaner_fst])
thread.daemon = True
thread.start()
def load_action_history(self, action_history):
self.action_history = []
with open(action_history) as fp:
for line in fp:
action, history = line.strip().split('\t')
if not('#ENDSEQUENCE' in action or '#ENDSECTION' in action):
self.action_history.append([action, history])
def get_action_history(self, action_num):
return self.action_history[action_num][1]
def _init_thread(self, word_lexicon, action_lexicon, model_fst, cleaner_fst):
global _backend, _semaphore
self.slu = _backend.init_slu(word_lexicon, action_lexicon, model_fst, cleaner_fst)
......@@ -69,7 +81,7 @@ class SLU:
_semaphore.acquire()
c_output = _backend.run_slu(self.slu, c_words, len(words), -1, old_words)
_semaphore.release()
output = cast(c_output, c_char_p).value
output = str(cast(c_output, c_char_p).value)
_backend.free(c_output)
GLib.idle_add(callback, self, output)
......
action(1,1,"start_scene1","uno") uno
action(1,1,"#ENDSEQUENCE(1)","") uno
action(1,1,"#ENDSECTION(1)","") uno
action(2,1,"open_scene2","dos") dos
action(2,1,"open_2A","open_system") dos open system
action(2,1,"#ENDSEQUENCE(1)","") dos open system
action(2,2,"start_system_voice","tell_me") dos open system tell me
action(2,2,"open_2B","open_technical_characteristics") dos open system tell me open technical characteristics
action(2,2,"open_2B1","read") dos open system tell me open technical characteristics read
action(2,2,"open_2B2","next") dos open system tell me open technical characteristics read next
action(2,2,"open_2B3","yes") dos open system tell me open technical characteristics read next yes
action(2,2,"open_2B4","read") dos open system tell me open technical characteristics read next yes read
action(2,2,"open_2B5","download") dos open system tell me open technical characteristics read next yes read download
action(2,2,"open_2C","open_the_terms_and_conditions_of_use_of_body_x_epsilon_system_three_point_zero") dos open system tell me open technical characteristics read next yes read download open the terms and conditions of use of body x epsilon system three point zero
action(2,2,"open_2C1","accept_terms_and_conditions_of_use") dos open system tell me open technical characteristics read next yes read download open the terms and conditions of use of body x epsilon system three point zero accept terms and conditions of use
action(2,2,"open_2C2","next") dos open system tell me open technical characteristics read next yes read download open the terms and conditions of use of body x epsilon system three point zero accept terms and conditions of use next
action(2,2,"open_2D","install_the_new_version_of_me") dos open system tell me open technical characteristics read next yes read download open the terms and conditions of use of body x epsilon system three point zero accept terms and conditions of use next install the new version of me
action(2,2,"#end","give_me_my_data") dos open system tell me open technical characteristics read next yes read download open the terms and conditions of use of body x epsilon system three point zero accept terms and conditions of use next install the new version of me give me my data
action(2,2,"#ENDSEQUENCE(2)","") dos open system tell me open technical characteristics read next yes read download open the terms and conditions of use of body x epsilon system three point zero accept terms and conditions of use next install the new version of me give me my data
action(2,2,"#ENDSECTION(2)","") dos open system tell me open technical characteristics read next yes read download open the terms and conditions of use of body x epsilon system three point zero accept terms and conditions of use next install the new version of me give me my data
action(3,1,"open_scene3","tres") tres
action(3,1,"#end","open_access_to_body_data") tres open access to body data
action(3,1,"#ENDSEQUENCE(1)","") tres open access to body data
action(3,2,"open3_A","import_body_data") tres open access to body data import body data
action(3,2,"open3_A1","import_organic_matter_data") tres open access to body data import body data import organic matter data
action(3,2,"open3_A2","import_temperature") tres open access to body data import body data import organic matter data import temperature
action(3,2,"open3_A3","import_time") tres open access to body data import body data import organic matter data import temperature import time
action(3,2,"open3_A4","import_space_data") tres open access to body data import body data import organic matter data import temperature import time import space data
action(3,2,"open3_A5","import_position") tres open access to body data import body data import organic matter data import temperature import time import space data import position
action(3,2,"open3_A6","import_body_subsystems") tres open access to body data import body data import organic matter data import temperature import time import space data import position import body subsystems
action(3,2,"open3_A7","import_estate") tres open access to body data import body data import organic matter data import temperature import time import space data import position import body subsystems import estate
action(3,2,"#end","give_me_my_data") tres open access to body data import body data import organic matter data import temperature import time import space data import position import body subsystems import estate give me my data
action(3,2,"#ENDSEQUENCE(2)","") tres open access to body data import body data import organic matter data import temperature import time import space data import position import body subsystems import estate give me my data
action(3,2,"#ENDSECTION(3)","") tres open access to body data import body data import organic matter data import temperature import time import space data import position import body subsystems import estate give me my data
action(4,1,"open_scene4","quatro") quatro
action(4,1,"#end","open_access_to_body_functions") quatro open access to body functions
action(4,1,"#ENDSEQUENCE(1)","") quatro open access to body functions
action(4,2,"open_4A","import_body_functions_space_localization") quatro open access to body functions import body functions space localization
action(4,2,"open_4A1","import_body_functions_sensations") quatro open access to body functions import body functions space localization import body functions sensations
action(4,2,"open_4A2","import_body_functions_passion") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion
action(4,2,"open_4A3","import_body_functions_concentration") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration
action(4,2,"open_4A4","import_body_functions_perception") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception
action(4,2,"open_4A5","import_body_functions_formal_force") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force
action(4,2,"open_4A6","import_body_functions_logics") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force import body functions logics
action(4,2,"open_4A7","import_body_functions_imagination") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force import body functions logics import body functions imagination
action(4,2,"open_4A8","import_body_functions_effort") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force import body functions logics import body functions imagination import body functions effort
action(4,2,"open_4A9","import_body_functions_nervous_system") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force import body functions logics import body functions imagination import body functions effort import body functions nervous system
action(4,2,"open_4A10","import_body_functions_internal_network") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force import body functions logics import body functions imagination import body functions effort import body functions nervous system import body functions internal network
action(4,2,"#end","upload") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force import body functions logics import body functions imagination import body functions effort import body functions nervous system import body functions internal network upload
action(4,2,"#end","give_me_my_data") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force import body functions logics import body functions imagination import body functions effort import body functions nervous system import body functions internal network upload give me my data
action(4,2,"#ENDSEQUENCE(2)","") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force import body functions logics import body functions imagination import body functions effort import body functions nervous system import body functions internal network upload
action(4,2,"#ENDSECTION(4)","") quatro open access to body functions import body functions space localization import body functions sensations import body functions passion import body functions concentration import body functions perception import body functions formal force import body functions logics import body functions imagination import body functions effort import body functions nervous system import body functions internal network upload
action(5,1,"open_scene5","cinco") cinco
action(5,1,"#ENDSEQUENCE(1)","") cinco
action(5,2,"#end","import_memory") cinco import memory
action(5,2,"#end","give_me_my_data") cinco import memory give me my data
action(5,2,"stop_system_voice","silence") cinco import memory give me my data silence
action(5,2,"#ENDSEQUENCE(2)","") cinco import memory
action(5,2,"#ENDSECTION(5)","") cinco import memory
action(6,1,"#end","open_network") open network
action(6,1,"#ENDSEQUENCE(1)","") open network
action(6,2,"constellation","clouds") open network clouds
action(6,2,"constellation","beautiful") open network beautiful
action(6,2,"constellation","data") open network data
action(6,2,"amplification1","clouds") open network clouds
action(6,2,"constellation","rain_of_identities") open network rain of identities
action(6,2,"constellation","storm_of_possibilities") open network storm of possibilities
action(6,2,"constellation","body") open network body
action(6,2,"constellation","wifi") open network wifi
action(6,2,"constellation","search") open network search
action(6,2,"constellation","and_redo") open network and redo
action(6,2,"constellation","connection") open network connection
action(6,2,"constellation","connect_me_to_this_network") open network connect me to this network
action(6,2,"constellation","function") open network function
action(6,2,"constellation","looking_for") open network looking for
action(6,2,"amplification1","something") open network something
action(6,2,"constellation","must") open network must
action(6,2,"constellation","stay") open network stay
action(6,2,"amplification1","must") open network must
action(6,2,"constellation","exist") open network exist
action(6,2,"constellation","a") open network a
action(6,2,"constellation","thread") open network thread
action(6,2,"amplification2","something") open network something
action(6,2,"amplification1","exists") open network exists
action(6,2,"constellation","between_recollection_and_oblivion") open network between recollection and oblivion
action(6,2,"constellation","a_tension_an_echo_an_emptiness") open network a tension an echo an emptiness
action(6,2,"amplification3","something") open network something
action(6,2,"constellation","rare") open network rare
action(6,2,"amplification1","stays") open network stays
action(6,2,"constellation","through") open network through
action(6,2,"constellation","nothing_more_strange_than_this_exile") open network nothing more strange than this exile
action(6,2,"constellation","an_absolute_abyss") open network an absolute abyss
action(6,2,"constellation","a_creaking_of_the_bones") open network a creaking of the bones
action(6,2,"constellation","a_barbarian_invasion") open network a barbarian invasion
action(6,2,"constellation","the_carelessness_of_destinies") open network the carelessness of destinies
action(6,2,"constellation","wringing_out_the") open network wringing out the
action(6,2,"constellation","blood") open network blood
action(6,2,"amplification4","something") open network something
action(6,2,"constellation","should") open network should
action(6,2,"amplification2","must") open network must
action(6,2,"constellation","or") open network or
action(6,2,"constellation","not") open network not
action(6,2,"amplification5","something") open network something
action(6,2,"amplification2","stays") open network stays
action(6,2,"#end","try_with_functional_regulation") open network try with functional regulation
action(6,2,"#end","give_me_my_data") open network give me my data
action(6,2,"#ENDSEQUENCE(2)","") open network try with functional regulation
action(6,3,"constellation","possible") open network try with functional regulation possible
action(6,3,"amplification1","function") open network try with functional regulation function
action(6,3,"constellation","erase_the") open network try with functional regulation erase the
action(6,3,"constellation","space") open network try with functional regulation space
action(6,3,"constellation","important") open network try with functional regulation important
action(6,3,"constellation","state") open network try with functional regulation state
action(6,3,"constellation","geolocalization") open network try with functional regulation geolocalization
action(6,3,"amplification1","important") open network try with functional regulation important
action(6,3,"constellation","encode") open network try with functional regulation encode
action(6,3,"constellation","passion") open network try with functional regulation passion
action(6,3,"constellation","for_located") open network try with functional regulation for located
action(6,3,"constellation","constellation") open network try with functional regulation constellation
action(6,3,"constellation","center") open network try with functional regulation center
action(6,3,"constellation","six_six_nine") open network try with functional regulation six six nine
action(6,3,"amplification2","important") open network try with functional regulation important
action(6,3,"constellation","some") open network try with functional regulation some
action(6,3,"amplification1","threads") open network try with functional regulation threads
action(6,3,"constellation","are_broken") open network try with functional regulation are broken
action(6,3,"constellation","remove") open network try with functional regulation remove
action(6,3,"constellation","memory") open network try with functional regulation memory
action(6,3,"constellation","love") open network try with functional regulation love
action(6,3,"amplification1","love") open network try with functional regulation love
action(6,3,"amplification1","memory") open network try with functional regulation memory
action(6,3,"amplification2","love") open network try with functional regulation love
action(6,3,"amplification1","errors") open network try with functional regulation errors
action(6,3,"constellation","a_identical") open network try with functional regulation a identical
action(6,3,"constellation","identity") open network try with functional regulation identity
action(6,3,"constellation","identifier") open network try with functional regulation identifier
action(6,3,"constellation","where") open network try with functional regulation where
action(6,3,"constellation","answer") open network try with functional regulation answer
action(6,3,"constellation","being") open network try with functional regulation being
action(6,3,"constellation","boing") open network try with functional regulation boing
action(6,3,"constellation","boot") open network try with functional regulation boot
action(6,3,"constellation","reboot") open network try with functional regulation reboot
action(6,3,"constellation","border_of") open network try with functional regulation border of
action(6,3,"amplification1","body") open network try with functional regulation body
action(6,3,"amplification2","body") open network try with functional regulation body
action(6,3,"amplification1","being") open network try with functional regulation being
action(6,3,"constellation","begun") open network try with functional regulation begun
action(6,3,"constellation","begin") open network try with functional regulation begin
action(6,3,"constellation","win") open network try with functional regulation win
action(6,3,"amplification1","border_of") open network try with functional regulation border of
action(6,3,"amplification2","being") open network try with functional regulation being
action(6,3,"constellation","actions") open network try with functional regulation actions
action(6,3,"amplification1","search") open network try with functional regulation search
action(6,3,"constellation","the") open network try with functional regulation the
action(6,3,"amplification1","answer") open network try with functional regulation answer
action(6,3,"constellation","of") open network try with functional regulation of
action(6,3,"amplification1","the") open network try with functional regulation the
action(6,3,"constellation","there_is") open network try with functional regulation there is
action(6,3,"amplification1","there_is") open network try with functional regulation there is
action(6,3,"amplification6","something") open network try with functional regulation something
action(6,3,"amplification3","body") open network try with functional regulation body
action(6,3,"constellation","password") open network try with functional regulation password
action(6,3,"constellation","pancreas") open network try with functional regulation pancreas
action(6,3,"constellation","give") open network try with functional regulation give
action(6,3,"constellation","me") open network try with functional regulation me
action(6,3,"amplification1","data") open network try with functional regulation data
action(6,3,"amplification1","give") open network try with functional regulation give
action(6,3,"amplification1","me") open network try with functional regulation me
action(6,3,"amplification2","give") open network try with functional regulation give
action(6,3,"amplification2","me") open network try with functional regulation me
action(6,3,"constellation","you") open network try with functional regulation you
action(6,3,"constellation","your") open network try with functional regulation your
action(6,3,"amplification3","give") open network try with functional regulation give
action(6,3,"amplification3","me") open network try with functional regulation me
action(6,3,"amplification1","your") open network try with functional regulation your
action(6,3,"amplification2","data") open network try with functional regulation data
action(6,3,"amplification4","give") open network try with functional regulation give
action(6,3,"amplification4","me") open network try with functional regulation me
action(6,3,"amplification2","your") open network try with functional regulation your
action(6,3,"amplification5","give") open network try with functional regulation give
action(6,3,"amplification5","me") open network try with functional regulation me
action(6,3,"amplification3","your") open network try with functional regulation your
action(6,3,"amplification3","data") open network try with functional regulation data
action(6,3,"amplification1","begun") open network try with functional regulation begun
action(6,3,"amplification1","begin") open network try with functional regulation begin
action(6,3,"amplification1","wins") open network try with functional regulation wins
action(6,3,"amplification1","blood") open network try with functional regulation blood
action(6,3,"constellation","everywhere") open network try with functional regulation everywhere
action(6,3,"amplification6","give") open network try with functional regulation give
action(6,3,"amplification7","give") open network try with functional regulation give
action(6,3,"amplification4","your") open network try with functional regulation your
action(6,3,"amplification2","blood") open network try with functional regulation blood
action(6,3,"constellation","golden") open network try with functional regulation golden
action(6,3,"amplification1","golden") open network try with functional regulation golden
action(6,3,"amplification4","data") open network try with functional regulation data
action(6,3,"constellation","protein_protection_amino-acid") open network try with functional regulation protein protection amino-acid
action(6,3,"amplification1","where") open network try with functional regulation where
action(6,3,"constellation","bilar") open network try with functional regulation bilar
action(6,3,"constellation","violence_segment") open network try with functional regulation violence segment
action(6,3,"constellation","segregation") open network try with functional regulation segregation
action(6,3,"amplification2","memory") open network try with functional regulation memory
action(6,3,"amplification1","encode") open network try with functional regulation encode
action(6,3,"amplification2","where") open network try with functional regulation where
action(6,3,"amplification3","where") open network try with functional regulation where
action(6,3,"amplification4","body") open network try with functional regulation body
action(6,3,"amplification4","where") open network try with functional regulation where
action(6,3,"amplification5","body") open network try with functional regulation body
action(6,3,"amplification5","where") open network try with functional regulation where
action(6,3,"amplification6","where") open network try with functional regulation where
action(6,3,"amplification8","give") open network try with functional regulation give
action(6,3,"amplification5","data") open network try with functional regulation data
action(6,3,"amplification2","clouds") open network try with functional regulation clouds
action(6,3,"amplification7","something") open network try with functional regulation something
action(6,3,"amplification3","being") open network try with functional regulation being
action(6,3,"amplification7","where") open network try with functional regulation where
action(6,3,"amplification8","where") open network try with functional regulation where
action(6,3,"amplification9","give") open network try with functional regulation give
action(6,3,"amplification6","data") open network try with functional regulation data
action(6,3,"amplification2","functions") open network try with functional regulation functions
action(6,3,"#end","and_to_want") open network try with functional regulation and to want
action(6,3,"#end","give_me_my_data") open network try with functional regulation give me my data
action(6,3,"#ENDSEQUENCE(3)","") open network try with functional regulation give me my data
action(6,4,"#end","y_querer") open network try with functional regulation give me my data y querer
action(6,4,"#end","give_me_my_data") open network try with functional regulation give me my data give me my data
action(6,4,"#ENDSEQUENCE(4)","") open network try with functional regulation give me my data y querer
action(6,5,"#end","give_me_my_data") open network try with functional regulation give me my data y querer give me my data
action(6,5,"#ENDSEQUENCE(5)","") open network try with functional regulation give me my data y querer give me my data
action(6,5,"#ENDSECTION(6)","") open network try with functional regulation give me my data y querer give me my data
action(8,1,"#end","search_for_sequences_producing_significant_alignments_in_genetic_database") search for sequences producing significant alignments in genetic database
action(8,1,"#end","give_me_my_data") search for sequences producing significant alignments in genetic database give me my data
action(8,1,"#ENDSEQUENCE(1)","") search for sequences producing significant alignments in genetic database
action(8,2,"memorise_loop","record") search for sequences producing significant alignments in genetic database record
action(8,2,"#end","give_me_my_data") search for sequences producing significant alignments in genetic database give me my data
action(8,2,"#ENDSEQUENCE(2)","") search for sequences producing significant alignments in genetic database give me my data
action(8,2,"#ENDSECTION(8)","") search for sequences producing significant alignments in genetic database give me my data
......@@ -86,13 +86,13 @@ class Line(Gtk.HBox):
self.elements = elements
self.get_style_context().add_class('text-line')
def highlight(self, active=True, scrollable=None):
if active:
self.label.get_style_context().add_class('highlighted')
else:
self.label.get_style_context().remove_class('highlighted')
if scrollable != None:
animate.scroll_to(scrollable, self)
#def highlight(self, active=True, scrollable=None):
# if active:
# self.label.get_style_context().add_class('highlighted')
# else:
# self.label.get_style_context().remove_class('highlighted')
# if scrollable != None:
# animate.scroll_to(scrollable, self)
class Keyword(Gtk.Label):
def __init__(self, text, action, lang):
......@@ -103,15 +103,29 @@ class Keyword(Gtk.Label):
self.set_markup(text + ' [<a href="%s">%s</a>] ' % (action, action))
self.get_style_context().add_class('keyword')
self.connect('activate-link', self.link_clicked)
self.listeners = []
self.num = 0
def highlight(self, active=True, scrollable=None):
if active:
self.get_style_context().remove_class('keyword')
self.get_style_context().add_class('keyword-highlighted')
if scrollable != None:
animate.scroll_to(scrollable, self)
else:
self.get_style_context().add_class('keyword')
self.get_style_context().remove_class('keyword-highlighted')
def add_listener(self, listener):
self.listeners.append(listener)
def highlight(self, scrollable=None):
self.get_style_context().remove_class('keyword')
self.get_style_context().add_class('keyword-highlighted')
if scrollable != None:
animate.scroll_to(scrollable, self)
def set_num(self, num):
self.num = num
def link_clicked(self, widget, uri):
actions.perform_action(actions.Action(uri, keyword=widget), False)
for listener in self.listeners:
listener(self, uri, self.num)
return True
class Text(Gtk.Label):
......@@ -144,6 +158,7 @@ class XmlView(Gtk.ScrolledWindow):
for line in sequence.lines:
for element in line.elements:
if hasattr(element, 'action'):
element.set_num(len(self.keywords))
self.keywords.append(element)
self.last_highlighted = -1
......@@ -172,16 +187,19 @@ class XmlView(Gtk.ScrolledWindow):
def section_clicked(self, current):
self.set_section(int(current.name) - 1)
for keyword in self.keywords:
keyword.highlight(False)
def highlight(self, action):
if hasattr(action, 'keyword'):
action.keyword.highlight(self)
action.keyword.highlight(True, self)
else:
i = self.last_highlighted + 1
while i < len(self.keywords):
if self.keywords[i].action == action.text:
self.keywords[i].highlight(self)
self.keywords[i].highlight(True, self)
self.last_highlighted = i
#print 'HIGHLIGHT:', action.text, self.last_highlighted
break
i += 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment